From fdf38ab2eb918cc4a7f263ef66174d358bf46fa2 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Mon, 7 Sep 2015 20:10:16 +0300 Subject: [PATCH] Introduce GC stress testing mode (-mem_stress_test prefix; for example: debug.linux-mem_stress_test). JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com --- CMakeLists.txt | 4 ++++ Makefile | 2 +- jerry-core/CMakeLists.txt | 4 ++++ jerry-core/mem/mem-heap.cpp | 4 ++++ jerry-core/mem/mem-poolman.cpp | 9 +++++++-- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0db99038..116e81f08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,10 +154,14 @@ project (Jerry CXX C ASM) # Memory statistics set(MODIFIER_SUFFIX_MEMORY_STATISTICS -mem_stats) + # Memory management stress-test mode + set(MODIFIER_SUFFIX_MEM_STRESS_TEST -mem_stress_test) + # Modifier lists # Linux set(MODIFIERS_LISTS_LINUX "FULL_PROFILE" + "FULL_PROFILE MEM_STRESS_TEST" "COMPACT_PROFILE" "COMPACT_PROFILE_MINIMAL" "FULL_PROFILE MEMORY_STATISTICS" diff --git a/Makefile b/Makefile index f2f3881ea..1ba82dfa3 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ export TARGET_RELEASE_MODES = release export TARGET_PC_SYSTEMS = linux -export TARGET_PC_MODS = cp cp_minimal mem_stats +export TARGET_PC_MODS = cp cp_minimal mem_stats mem_stress_test export TARGET_MCU_MODS = cp cp_minimal diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 7e4d1ae1f..40dfc8989 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -70,6 +70,10 @@ project (JerryCore CXX C ASM) CONFIG_ECMA_COMPACT_PROFILE_DISABLE_MATH_BUILTIN CONFIG_ECMA_COMPACT_PROFILE_DISABLE_JSON_BUILTIN) + # Memory management stress-test mode + set(DEFINES_MEM_STRESS_TEST + MEM_GC_BEFORE_EACH_ALLOC) + # Memory statistics set(DEFINES_MEMORY_STATISTICS MEM_STATS) diff --git a/jerry-core/mem/mem-heap.cpp b/jerry-core/mem/mem-heap.cpp index e08529fef..8e6c61e1e 100644 --- a/jerry-core/mem/mem-heap.cpp +++ b/jerry-core/mem/mem-heap.cpp @@ -489,6 +489,10 @@ mem_heap_alloc_block_try_give_memory_back (size_t size_in_bytes, /**< size of re * (one-chunked or general) */ mem_heap_alloc_term_t alloc_term) /**< expected allocation term */ { +#ifdef MEM_GC_BEFORE_EACH_ALLOC + mem_run_try_to_give_memory_back_callbacks (MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_CRITICAL); +#endif /* MEM_GC_BEFORE_EACH_ALLOC */ + size_t chunks = mem_get_block_chunks_count_from_data_size (size_in_bytes); if ((mem_heap_allocated_chunks + chunks) * MEM_HEAP_CHUNK_SIZE >= mem_heap_limit) { diff --git a/jerry-core/mem/mem-poolman.cpp b/jerry-core/mem/mem-poolman.cpp index 09076f88d..96ff7ed29 100644 --- a/jerry-core/mem/mem-poolman.cpp +++ b/jerry-core/mem/mem-poolman.cpp @@ -24,14 +24,15 @@ * Memory pool manager implementation */ -#define JERRY_MEM_POOL_INTERNAL - #include "jrt.h" #include "jrt-libc-includes.h" #include "mem-allocator.h" #include "mem-heap.h" #include "mem-poolman.h" +#define MEM_ALLOCATOR_INTERNAL +#include "mem-allocator-internal.h" + /** * Size of a pool */ @@ -521,6 +522,10 @@ mem_pools_alloc_longpath (void) uint8_t* __attr_always_inline___ mem_pools_alloc (void) { +#ifdef MEM_GC_BEFORE_EACH_ALLOC + mem_run_try_to_give_memory_back_callbacks (MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_CRITICAL); +#endif /* MEM_GC_BEFORE_EACH_ALLOC */ + mem_check_pools (); do