From 9513f3792dd0288569f2d4c9edef63ba804effea Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Wed, 18 Jul 2018 15:52:00 +0200 Subject: Reduce with stack consumption by 1. (#2430) JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- jerry-core/parser/js/byte-code.h | 2 +- jerry-core/vm/vm-stack.c | 25 +++++++++++++++++-------- jerry-core/vm/vm.c | 8 +++----- 3 files changed, 21 insertions(+), 14 deletions(-) (limited to 'jerry-core') diff --git a/jerry-core/parser/js/byte-code.h b/jerry-core/parser/js/byte-code.h index 0ce85f38..e3a68485 100644 --- a/jerry-core/parser/js/byte-code.h +++ b/jerry-core/parser/js/byte-code.h @@ -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 diff --git a/jerry-core/vm/vm-stack.c b/jerry-core/vm/vm-stack.c index 2de190a4..9b8400b1 100644 --- a/jerry-core/vm/vm-stack.c +++ b/jerry-core/vm/vm-stack.c @@ -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: @@ -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) { diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c index bb6061c8..978dd438 100644 --- a/jerry-core/vm/vm.c +++ b/jerry-core/vm/vm.c @@ -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; @@ -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); @@ -2903,7 +2902,6 @@ error: 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 -- cgit v1.2.3