-
Notifications
You must be signed in to change notification settings - Fork 684
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
fix bug in vm call_stack_size calculation #1345
Conversation
Wow, nice catch. I overlooked this. Thank you. LGTM |
It is a good question what would we gain if we would not add them together in the parser, since we could cover more functions in the "byte" range. Some statistics would be useful for that. |
@jiangzidong, we have an internal performance measurement tool with a dedicated device. Just update the PR and write a comment here or ping me on IRC and I will do it. |
4e227d1
to
a599e5b
Compare
@LaszloLango @zherczeg I updated the patch, and choose to add in the vm instead of parser.
|
I constructed the following case to show the benefits
The func1 context has 60 registers and 200 stacklimit, and the snapshot size (by save-snapshot) reduced from |
It seems the benefit is very little. We need quite a big function to have a gain, but the saving on the header is negligible on large functions. This proof makes me prefer the original patch. But I would like to hear others opinion (including you, @jiangzidong). What would you prefer? |
FYI:
Binary sizes (bytes) Runtime is not changed by this PR. |
@zherczeg I prefer the current one. Original patch: fix the bug Though the benefits of size is negligible in my case, it didn't bring any side effects. |
Both solution is good to me. If we choose snapshot header optimization, then the snapshot version should be increased. |
Oh, I forget the issue of snapshot version and compatibility. |
OK, lets use the current one. LGTM |
@@ -1450,7 +1450,7 @@ 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 |
There was a problem hiding this comment.
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.
And please also add the snapshot version number increase. |
a599e5b
to
70bc512
Compare
updated, thanks |
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 [email protected] JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang [email protected]
LGTM |
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 [email protected]
call_stack_size = args_p->register_end + args_p->stack_limit
While in
parser_post_processing
,it already has
args_p->stack_limit = (uint8_t) (context_p->register_count + context_p->stack_limit);
So
context_p->register_count
is added twice incall_stack_size
. I think it is a bug (leads vm easily choose vm_run_with_alloca )