-
Notifications
You must be signed in to change notification settings - Fork 683
More gc-friendly property hashmap allocation. #1195
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,13 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */ | |
|
||
size_t total_size = ECMA_PROPERTY_HASHMAP_GET_TOTAL_SIZE (max_property_count); | ||
|
||
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) jmem_heap_alloc_block (total_size); | ||
ecma_property_hashmap_t *hashmap_p = (ecma_property_hashmap_t *) jmem_heap_alloc_block_null_on_error (total_size); | ||
|
||
if (hashmap_p == NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we could think about a strategy what should happen if we are on low-memory conditions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: add a newline before the 'if'. |
||
{ | ||
return; | ||
} | ||
|
||
memset (hashmap_p, 0, total_size); | ||
|
||
hashmap_p->header.types[0].type_and_flags = ECMA_PROPERTY_TYPE_HASHMAP; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,12 +321,17 @@ void *jmem_heap_alloc_block_internal (const size_t size) | |
* Allocation of memory block, running 'try to give memory back' callbacks, if there is not enough memory. | ||
* | ||
* Note: | ||
* if after running the callbacks, there is still not enough memory, engine is terminated with ERR_OUT_OF_MEMORY. | ||
* if there is still not enough memory after running the callbacks | ||
* - NULL value will be returned if parmeter 'ret_null_on_error' is true | ||
* - the engine will terminate with ERR_OUT_OF_MEMORY if 'ret_null_on_error' is false | ||
* | ||
* @return pointer to allocated memory block | ||
* @return NULL, if the required memory size is 0 | ||
* also NULL, if 'ret_null_on_error' is true and the allocation fails because of there is not enough memory | ||
*/ | ||
void * __attribute__((hot)) | ||
jmem_heap_alloc_block (const size_t size) | ||
static void * | ||
jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size */ | ||
bool ret_null_on_error) /**< indicates whether return null or terminate | ||
with ERR_OUT_OF_MEMORY on out of memory */ | ||
{ | ||
if (unlikely (size == 0)) | ||
{ | ||
|
@@ -369,9 +374,46 @@ jmem_heap_alloc_block (const size_t size) | |
|
||
JERRY_ASSERT (data_space_p == NULL); | ||
|
||
jerry_fatal (ERR_OUT_OF_MEMORY); | ||
if (!ret_null_on_error) | ||
{ | ||
jerry_fatal (ERR_OUT_OF_MEMORY); | ||
} | ||
|
||
return data_space_p; | ||
} /* jmem_heap_gc_and_alloc_block */ | ||
|
||
/** | ||
* Allocation of memory block, running 'try to give memory back' callbacks, if there is not enough memory. | ||
* | ||
* Note: | ||
* If there is still not enough memory after running the callbacks, then the engine will be | ||
* terminated with ERR_OUT_OF_MEMORY. | ||
* | ||
* @return NULL, if the required memory is 0 | ||
* pointer to allocated memory block, otherwise | ||
*/ | ||
void * __attribute__((hot)) __attr_always_inline___ | ||
jmem_heap_alloc_block (const size_t size) /**< required memory size */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would implement this a bit differently. I would add a bool parameter to jmem_heap_gc_and_alloc_block to tell whether it should return with NULL or error, and make these functions a one-liner always inline functionsa, and just set that bool parameter. |
||
{ | ||
return jmem_heap_gc_and_alloc_block (size, false); | ||
} /* jmem_heap_alloc_block */ | ||
|
||
/** | ||
* Allocation of memory block, running 'try to give memory back' callbacks, if there is not enough memory. | ||
* | ||
* Note: | ||
* If there is still not enough memory after running the callbacks, NULL will be returned. | ||
* | ||
* @return NULL, if the required memory size is 0 | ||
* also NULL, if the allocation has failed | ||
* pointer to the allocated memory block, otherwise | ||
*/ | ||
void * __attribute__((hot)) __attr_always_inline___ | ||
jmem_heap_alloc_block_null_on_error (const size_t size) /**< required memory size */ | ||
{ | ||
return jmem_heap_gc_and_alloc_block (size, true); | ||
} /* jmem_heap_alloc_block_null_on_error */ | ||
|
||
/** | ||
* Allocate block and store block size. | ||
* | ||
|
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.
No need the newline above.