aboutsummaryrefslogtreecommitdiff
path: root/jerry-core
diff options
context:
space:
mode:
authorZoltan Herczeg <zherczeg.u-szeged@partner.samsung.com>2018-07-18 15:52:00 +0200
committerRobert Sipka <rsipka.uszeged@partner.samsung.com>2018-07-18 15:52:00 +0200
commit9513f3792dd0288569f2d4c9edef63ba804effea (patch)
tree90a3ecda691b5cca2eab52f69c24d6209a18f197 /jerry-core
parent5f4a220a6525593ff87076f64b9b78590118fbc4 (diff)
Reduce with stack consumption by 1. (#2430)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
Diffstat (limited to 'jerry-core')
-rw-r--r--jerry-core/parser/js/byte-code.h2
-rw-r--r--jerry-core/vm/vm-stack.c25
-rw-r--r--jerry-core/vm/vm.c8
3 files changed, 21 insertions, 14 deletions
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