Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Proxy recrusion check in their internal methods. #4568

Merged

Conversation

galpeter
Copy link
Contributor

@galpeter galpeter commented Feb 5, 2021

In some parts of Proxy internal methods the compiler can do a bit of
tail call optimalization which would be ok, but the current stack limit
check framework in Jerry uses the stack pointer to calculate the stack depth.
This way of stack depth calculation is affected by the tail call optimalization
(as the stack does not increase).

By disabling the tail call optimalization at given points the stack limit calculation
will work as expected. This causes a bit of stack overhead, but the Proxy in it self
is a fairly big chunk of code and this stack limit would only be relevant if the Proxy
already does recursion which already very edge case.

The stack limit (--stack-limit=..) should be enabled to correctly report such stack
depth errors.

@galpeter galpeter force-pushed the proxy_disable_tail_call branch from 4c629f4 to 172b643 Compare February 5, 2021 09:28
Copy link
Member

@akosthekiss akosthekiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general

jerry-core/ecma/operations/ecma-proxy-object.c Outdated Show resolved Hide resolved
jerry-core/ecma/operations/ecma-proxy-object.c Outdated Show resolved Hide resolved
@galpeter galpeter force-pushed the proxy_disable_tail_call branch from 172b643 to fe2b5aa Compare February 5, 2021 10:12
@lygstate
Copy link
Contributor

lygstate commented Feb 5, 2021

Maybe it's worth to contribute this testcase to test262

@lygstate
Copy link
Contributor

lygstate commented Feb 5, 2021

Also please update

# FIXME: regression-test-issue-3785.js currently are deadloop on OSX.
- run: $RUNNER -q --jerry-tests --skip-list=regression-test-issue-3785.js
- run: $RUNNER -q --unittests

@galpeter
Copy link
Contributor Author

galpeter commented Feb 5, 2021

Also please update

# FIXME: regression-test-issue-3785.js currently are deadloop on OSX.
- run: $RUNNER -q --jerry-tests --skip-list=regression-test-issue-3785.js
- run: $RUNNER -q --unittests

true, thanks

@galpeter galpeter force-pushed the proxy_disable_tail_call branch from fe2b5aa to b25bfa1 Compare February 5, 2021 15:28
@lygstate
Copy link
Contributor

lygstate commented Feb 6, 2021

Oh type in title Improve Proxy recrusion check in their internal methods
Should be Improve Proxy recursion check in their internal methods

@lygstate
Copy link
Contributor

lygstate commented Feb 6, 2021

For mark, fixes #4530

@galpeter galpeter force-pushed the proxy_disable_tail_call branch from b25bfa1 to 5031c0b Compare February 11, 2021 10:56
@rerobika rerobika requested a review from akosthekiss February 17, 2021 14:40
@galpeter galpeter force-pushed the proxy_disable_tail_call branch 2 times, most recently from 4f0b049 to 5e5d4dd Compare February 23, 2021 13:32
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor change

#else /* !defined(__clang__) && !defined(__GNUC__) */
/* On GCC 10.x this version also works. */
#define JERRY_BLOCK_TAIL_CALL_OPTIMIZATION() \
do { JERRY_CONTEXT (status_flags) |= ECMA_STATUS_API_AVAILABLE; } while (0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this syntax is allowed even in macros

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate? What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newlines

do \
{ \
  ... \
} \
while (0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh... true. I've updated the PR. thx!

@galpeter galpeter force-pushed the proxy_disable_tail_call branch 2 times, most recently from 3f6ecf0 to 3881c07 Compare March 2, 2021 09:25
@galpeter galpeter force-pushed the proxy_disable_tail_call branch from 3881c07 to 227f0fd Compare March 16, 2021 10:33
@galpeter galpeter force-pushed the proxy_disable_tail_call branch from 227f0fd to 7ff8580 Compare March 29, 2021 11:24
@galpeter galpeter force-pushed the proxy_disable_tail_call branch from 7ff8580 to 7665e2c Compare June 15, 2021 16:31
Copy link
Member

@akosthekiss akosthekiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

In some parts of Proxy internal methods the compiler can do a bit of
tail call optimalization which would be ok, but the current stack limit
check framework in Jerry uses the stack pointer to calculate the stack depth.
This way of stack depth calculation is affected by the tail call optimalization
(as the stack does not increase).

By disabling the tail call optimalization at given points the stack limit calculation
will work as expected. This causes a bit of stack overhead, but the Proxy in it self
is a fairly big chunk of code and this stack limit would only be relevant if the Proxy
already does recusion which already very edge case.

The stack limit (--stack-limit=..) should be enabled to correctly report such stack
depth errors.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
@galpeter galpeter force-pushed the proxy_disable_tail_call branch from 7665e2c to 1e164a6 Compare July 15, 2021 11:38
@zherczeg zherczeg merged commit d5a7839 into jerryscript-project:master Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants