Refactor memory management (#2954)
This PR is a general cleanup for garbage collection and memory
allocation code paths.
Changes:
* Removed an unnecesary local variable from 'ecma_gc_mark'.
* Refactored 'ecma_gc_run' to have an implicit list head during
iteration, which results in one less condition in the loops,
and changed the loops to use compressed pointers to reduce the
overall amount of compression/decompression.
* Renamed 'jmem_free_unused_memory_severity_t' to 'jmem_pressure_t',
and added additional values.
* Removed 'jmem_free_unused_memory_callback', instead
'ecma_free_unused_memory' is now called directly.
* Reworked 'ecma_free_unused_memory' to handle all code paths related
to 'jmem_pressure_t', and moved all relevant code paths into this
function. This simplifies the code paths in other places.
* Reworked 'jmem_heap_gc_and_alloc_block' to be more streamlined.
* Changed mem-stats to not report unused pool chunks as allocated
memory.
* Created an allocator internal API for allocating/freeing memory blocks
that are not reported as used memory in mem-stats.
* Removed iteration statistics for the jerry allocator from mem-stats,
as they don't provide any actually useful information.
Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu>
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
@@ -24,6 +24,10 @@
|
||||
#define JMEM_ALLOCATOR_INTERNAL
|
||||
#include "jmem-allocator-internal.h"
|
||||
|
||||
#if ENABLED (JERRY_MEM_GC_BEFORE_EACH_ALLOC)
|
||||
#include "ecma-gc.h"
|
||||
#endif /* ENABLED (JERRY_MEM_GC_BEFORE_EACH_ALLOC) */
|
||||
|
||||
/** \addtogroup mem Memory allocation
|
||||
* @{
|
||||
*
|
||||
@@ -55,7 +59,7 @@ inline void * JERRY_ATTR_HOT JERRY_ATTR_ALWAYS_INLINE
|
||||
jmem_pools_alloc (size_t size) /**< size of the chunk */
|
||||
{
|
||||
#if ENABLED (JERRY_MEM_GC_BEFORE_EACH_ALLOC)
|
||||
jmem_run_free_unused_memory_callbacks (JMEM_FREE_UNUSED_MEMORY_SEVERITY_HIGH);
|
||||
ecma_free_unused_memory (JMEM_PRESSURE_LOW);
|
||||
#endif /* ENABLED (JERRY_MEM_GC_BEFORE_EACH_ALLOC) */
|
||||
|
||||
#if ENABLED (JERRY_CPOINTER_32_BIT)
|
||||
@@ -70,16 +74,17 @@ jmem_pools_alloc (size_t size) /**< size of the chunk */
|
||||
const jmem_pools_chunk_t *const chunk_p = JERRY_CONTEXT (jmem_free_8_byte_chunk_p);
|
||||
|
||||
JMEM_VALGRIND_DEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t));
|
||||
|
||||
JERRY_CONTEXT (jmem_free_8_byte_chunk_p) = chunk_p->next_p;
|
||||
|
||||
JMEM_VALGRIND_UNDEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t));
|
||||
|
||||
JMEM_HEAP_STAT_ALLOC (8);
|
||||
return (void *) chunk_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (void *) jmem_heap_alloc_block (8);
|
||||
void *chunk_p = jmem_heap_alloc_block_internal (8);
|
||||
JMEM_HEAP_STAT_ALLOC (8);
|
||||
return chunk_p;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_CPOINTER_32_BIT)
|
||||
@@ -92,16 +97,17 @@ jmem_pools_alloc (size_t size) /**< size of the chunk */
|
||||
const jmem_pools_chunk_t *const chunk_p = JERRY_CONTEXT (jmem_free_16_byte_chunk_p);
|
||||
|
||||
JMEM_VALGRIND_DEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t));
|
||||
|
||||
JERRY_CONTEXT (jmem_free_16_byte_chunk_p) = chunk_p->next_p;
|
||||
|
||||
JMEM_VALGRIND_UNDEFINED_SPACE (chunk_p, sizeof (jmem_pools_chunk_t));
|
||||
|
||||
JMEM_HEAP_STAT_ALLOC (16);
|
||||
return (void *) chunk_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (void *) jmem_heap_alloc_block (16);
|
||||
void *chunk_p = jmem_heap_alloc_block_internal (16);
|
||||
JMEM_HEAP_STAT_ALLOC (16);
|
||||
return chunk_p;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
|
||||
} /* jmem_pools_alloc */
|
||||
@@ -114,6 +120,7 @@ jmem_pools_free (void *chunk_p, /**< pointer to the chunk */
|
||||
size_t size) /**< size of the chunk */
|
||||
{
|
||||
JERRY_ASSERT (chunk_p != NULL);
|
||||
JMEM_HEAP_STAT_FREE (size);
|
||||
|
||||
jmem_pools_chunk_t *const chunk_to_free_p = (jmem_pools_chunk_t *) chunk_p;
|
||||
|
||||
@@ -158,7 +165,7 @@ jmem_pools_collect_empty (void)
|
||||
jmem_pools_chunk_t *const next_p = chunk_p->next_p;
|
||||
JMEM_VALGRIND_NOACCESS_SPACE (chunk_p, sizeof (jmem_pools_chunk_t));
|
||||
|
||||
jmem_heap_free_block (chunk_p, 8);
|
||||
jmem_heap_free_block_internal (chunk_p, 8);
|
||||
chunk_p = next_p;
|
||||
}
|
||||
|
||||
@@ -172,7 +179,7 @@ jmem_pools_collect_empty (void)
|
||||
jmem_pools_chunk_t *const next_p = chunk_p->next_p;
|
||||
JMEM_VALGRIND_NOACCESS_SPACE (chunk_p, sizeof (jmem_pools_chunk_t));
|
||||
|
||||
jmem_heap_free_block (chunk_p, 16);
|
||||
jmem_heap_free_block_internal (chunk_p, 16);
|
||||
chunk_p = next_p;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
|
||||
|
||||
Reference in New Issue
Block a user