Skip to content
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

Change pool-based allocation to heap-based allocation in jerry.c #936

Merged
merged 1 commit into from
Mar 7, 2016

Conversation

akosthekiss
Copy link
Member

There was an abuse of memory pools in jerry.c: compiled_code_map_entry_t
is not an ECMA data model object but was still alocated/freed via
mem pool functions. Changed the appropriate calls to heap-related
functions.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]

@akosthekiss akosthekiss added bug Undesired behaviour minor memory management Related to memory management or garbage collection labels Mar 7, 2016
@@ -1848,7 +1848,8 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled

snapshot_last_compiled_code_offset = snapshot_buffer_write_offset;

compiled_code_map_entry_t *new_entry = (compiled_code_map_entry_t *) mem_pools_alloc ();
compiled_code_map_entry_t *new_entry =
(compiled_code_map_entry_t *) mem_heap_alloc_block (sizeof (compiled_code_map_entry_t));
Copy link
Member

Choose a reason for hiding this comment

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

I think this is an incorrect style. A temporary variable could help.

Copy link
Member Author

Choose a reason for hiding this comment

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

No. Seriously. I - will - not - add - extra - statements, - temporaries, - assignments - just - because - of - a - style - checker.

Style checkers should promote readability. Nicer style. But as soon as they force you to write different (not differently styled!) code than you think it's optimal, then there is something terribly wrong.

(And the other issue is: the temp should be of type compiled_code_map_entry_t *, I guess. But then, there is no way to get that line under the 120 chars limit. Even a one-character temp would make a 121 chars line. So, that line should be broken somewhere too, which causes the same issue as we have now.)

Copy link
Member

Choose a reason for hiding this comment

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

But the proposed solution looks ugly. Introduce a two parameter macro for allocating, or improve the style checker.

Copy link
Contributor

Choose a reason for hiding this comment

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

compiled_code_map_entry_t *new_entry;
new_entry = (compiled_code_map_entry_t *) mem_heap_alloc_block (sizeof (compiled_code_map_entry_t));

There was an abuse of memory pools in jerry.c: `compiled_code_map_entry_t`
is not an ECMA data model object but was still alocated/freed via
mem pool functions. Changed the appropriate calls to heap-related
functions.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
@akosthekiss
Copy link
Member Author

Updated.
@LaszloLango thanks for the idea.

@zherczeg
Copy link
Member

zherczeg commented Mar 7, 2016

LGTM

1 similar comment
@LaszloLango
Copy link
Contributor

LGTM

@akosthekiss akosthekiss merged commit d4650bc into jerryscript-project:master Mar 7, 2016
@akosthekiss akosthekiss deleted the jerry-alloc branch March 7, 2016 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour memory management Related to memory management or garbage collection minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants