Skip to content

Reduce "with" stack consumption by 1. #2430

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

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jerry-core/parser/js/byte-code.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
/* PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION must be <= 4 */
#define PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION 4
/* PARSER_WITH_CONTEXT_STACK_ALLOCATION must be <= 4 */
#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 2
#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 1
/* PARSER_TRY_CONTEXT_STACK_ALLOCATION must be <= 3 */
#define PARSER_TRY_CONTEXT_STACK_ALLOCATION 2

Expand Down
25 changes: 17 additions & 8 deletions jerry-core/vm/vm-stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,23 @@ vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
break;
}
case VM_CONTEXT_CATCH:
case VM_CONTEXT_WITH:
{
ecma_deref_object (frame_ctx_p->lex_env_p);
frame_ctx_p->lex_env_p = ecma_get_object_from_value (vm_stack_top_p[-2]);
JERRY_ASSERT (PARSER_TRY_CONTEXT_STACK_ALLOCATION > PARSER_WITH_CONTEXT_STACK_ALLOCATION);

JERRY_ASSERT (PARSER_TRY_CONTEXT_STACK_ALLOCATION == PARSER_WITH_CONTEXT_STACK_ALLOCATION);
const uint16_t size_diff = PARSER_TRY_CONTEXT_STACK_ALLOCATION - PARSER_WITH_CONTEXT_STACK_ALLOCATION;

VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_TRY_CONTEXT_STACK_ALLOCATION);
vm_stack_top_p -= PARSER_TRY_CONTEXT_STACK_ALLOCATION;
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, size_diff);
vm_stack_top_p -= size_diff;
/* FALLTHRU */
}
case VM_CONTEXT_WITH:
{
ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p;
frame_ctx_p->lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
ecma_deref_object (lex_env_p);

VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION);
vm_stack_top_p -= PARSER_WITH_CONTEXT_STACK_ALLOCATION;
break;
}
default:
Expand Down Expand Up @@ -218,8 +226,9 @@ vm_stack_find_finally (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
}
else
{
ecma_deref_object (frame_ctx_p->lex_env_p);
frame_ctx_p->lex_env_p = ecma_get_object_from_value (vm_stack_top_p[-2]);
ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p;
frame_ctx_p->lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
ecma_deref_object (lex_env_p);

if (byte_code_p[0] == CBC_CONTEXT_END)
{
Expand Down
8 changes: 3 additions & 5 deletions jerry-core/vm/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2314,14 +2314,12 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
object_p = ecma_get_object_from_value (result);

with_env_p = ecma_create_object_lex_env (frame_ctx_p->lex_env_p, object_p);

ecma_deref_object (object_p);

VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_WITH_CONTEXT_STACK_ALLOCATION);
stack_top_p += PARSER_WITH_CONTEXT_STACK_ALLOCATION;

stack_top_p[-1] = VM_CREATE_CONTEXT (VM_CONTEXT_WITH, branch_offset);
stack_top_p[-2] = ecma_make_object_value (frame_ctx_p->lex_env_p);

frame_ctx_p->lex_env_p = with_env_p;
continue;
Expand Down Expand Up @@ -2468,8 +2466,9 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */

if (VM_GET_CONTEXT_TYPE (stack_top_p[-1]) == VM_CONTEXT_CATCH)
{
ecma_deref_object (frame_ctx_p->lex_env_p);
frame_ctx_p->lex_env_p = ecma_get_object_from_value (stack_top_p[-2]);
ecma_object_t *lex_env_p = frame_ctx_p->lex_env_p;
frame_ctx_p->lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p);
ecma_deref_object (lex_env_p);
}

stack_top_p[-1] = (ecma_value_t) VM_CREATE_CONTEXT (VM_CONTEXT_FINALLY_JUMP, branch_offset);
Expand Down Expand Up @@ -2903,7 +2902,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
ecma_string_t *catch_name_p = ecma_get_string_from_value (literal_start_p[literal_index]);
ecma_op_create_mutable_binding (catch_env_p, catch_name_p, false);

stack_top_p[-2 - 1] = ecma_make_object_value (frame_ctx_p->lex_env_p);
frame_ctx_p->lex_env_p = catch_env_p;
}
else
Expand Down