Skip to content

fix bug in vm call_stack_size calculation #1345

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
Sep 15, 2016
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/jerry-snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ typedef struct
/**
* Jerry snapshot format version
*/
#define JERRY_SNAPSHOT_VERSION (5u)
#define JERRY_SNAPSHOT_VERSION (6u)

#endif /* !JERRY_SNAPSHOT_H */
9 changes: 5 additions & 4 deletions jerry-core/parser/js/js-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

I just realized we should check the register_count as well:

|| context_p->register_count > CBC_MAXIMUM_BYTE_VALUE

It is true that PARSER_MAXIMUM_NUMBER_OF_REGISTERS is 256 at this moment, but it can be changed.

|| context_p->register_count > CBC_MAXIMUM_BYTE_VALUE
|| context_p->literal_count > CBC_MAXIMUM_BYTE_VALUE)
{
needs_uint16_arguments = true;
Expand All @@ -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;
Expand All @@ -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;
Expand Down