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:
Dániel Bátyai
2019-07-17 14:12:23 +02:00
committed by GitHub
parent a44d584842
commit ff22634e27
27 changed files with 297 additions and 538 deletions
+22 -8
View File
@@ -45,16 +45,11 @@
#endif /* ENABLED (JERRY_VALGRIND) */
/** @} */
#if ENABLED (JERRY_MEM_STATS)
void jmem_heap_stats_reset_peak (void);
void jmem_heap_stats_print (void);
#endif /* ENABLED (JERRY_MEM_STATS) */
void jmem_heap_init (void);
void jmem_heap_finalize (void);
bool jmem_is_heap_pointer (const void *pointer);
void jmem_run_free_unused_memory_callbacks (jmem_free_unused_memory_severity_t severity);
void *jmem_heap_alloc_block_internal (const size_t size);
void jmem_heap_free_block_internal (void *ptr, const size_t size);
/**
* \addtogroup poolman Memory pool manager
@@ -62,11 +57,30 @@ void jmem_run_free_unused_memory_callbacks (jmem_free_unused_memory_severity_t s
*/
void jmem_pools_finalize (void);
void jmem_pools_collect_empty (void);
/**
* @}
* @}
*/
/**
* @{
* Jerry mem-stat definitions
*/
#if ENABLED (JERRY_MEM_STATS)
void jmem_heap_stat_init (void);
void jmem_heap_stat_alloc (size_t num);
void jmem_heap_stat_free (size_t num);
#define JMEM_HEAP_STAT_INIT() jmem_heap_stat_init ()
#define JMEM_HEAP_STAT_ALLOC(v1) jmem_heap_stat_alloc (v1)
#define JMEM_HEAP_STAT_FREE(v1) jmem_heap_stat_free (v1)
#else /* !ENABLED (JERRY_MEM_STATS) */
#define JMEM_HEAP_STAT_INIT()
#define JMEM_HEAP_STAT_ALLOC(v1) JERRY_UNUSED (v1)
#define JMEM_HEAP_STAT_FREE(v1) JERRY_UNUSED (v1)
#endif /* ENABLED (JERRY_MEM_STATS) */
/** @} */
#endif /* !JMEM_ALLOCATOR_INTERNAL_H */