From 70bc5123119175d7fd24ad4385c622755d3f731b Mon Sep 17 00:00:00 2001 From: Zidong Jiang Date: Tue, 13 Sep 2016 10:30:38 +0800 Subject: [PATCH] fix bug in vm call_stack_size calculation call_stack_size should be register_count + maximum stack depth *We don't add in the parser to save the size of snapshot header *jerry_snapshot_version 5 -> 6 JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com --- jerry-core/jerry-snapshot.h | 2 +- jerry-core/parser/js/js-parser.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/jerry-core/jerry-snapshot.h b/jerry-core/jerry-snapshot.h index b8caae741f..00618edcd1 100644 --- a/jerry-core/jerry-snapshot.h +++ b/jerry-core/jerry-snapshot.h @@ -37,6 +37,6 @@ typedef struct /** * Jerry snapshot format version */ -#define JERRY_SNAPSHOT_VERSION (5u) +#define JERRY_SNAPSHOT_VERSION (6u) #endif /* !JERRY_SNAPSHOT_H */ diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index 7dc6b08e0a..b8bacc1a60 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -1037,7 +1037,7 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code } JERRY_DEBUG_MSG ("\nFinal byte code dump:\n\n Maximum stack depth: %d\n Flags: [", - (int) stack_limit); + (int) (stack_limit + register_end)); if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING)) { @@ -1450,7 +1450,8 @@ parser_post_processing (parser_context_t *context_p) /**< context */ needs_uint16_arguments = false; total_size = sizeof (cbc_uint8_arguments_t); - if ((context_p->register_count + context_p->stack_limit) > CBC_MAXIMUM_BYTE_VALUE + if (context_p->stack_limit > CBC_MAXIMUM_BYTE_VALUE + || context_p->register_count > CBC_MAXIMUM_BYTE_VALUE || context_p->literal_count > CBC_MAXIMUM_BYTE_VALUE) { needs_uint16_arguments = true; @@ -1471,7 +1472,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ { cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p; - args_p->stack_limit = (uint16_t) (context_p->register_count + context_p->stack_limit); + args_p->stack_limit = context_p->stack_limit; args_p->argument_end = context_p->argument_count; args_p->register_end = context_p->register_count; args_p->ident_end = ident_end; @@ -1485,7 +1486,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */ { cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p; - args_p->stack_limit = (uint8_t) (context_p->register_count + context_p->stack_limit); + args_p->stack_limit = (uint8_t) context_p->stack_limit; args_p->argument_end = (uint8_t) context_p->argument_count; args_p->register_end = (uint8_t) context_p->register_count; args_p->ident_end = (uint8_t) ident_end;