From beb34c3675312ab746b0bb37b8c146379379dd1b Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Sun, 2 Mar 2025 23:32:04 -0500 Subject: [PATCH 1/4] Expose WAMR_BUILD_GC_HEAP_SIZE_DEFAULT as a CMake option This is wired through to the GC_HEAP_SIZE_DEFAULT constant. Also honor this value when configuring the engine with the wasm_c_api. --- core/iwasm/common/wasm_c_api.c | 1 + core/shared/mem-alloc/mem_alloc.cmake | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index d5c45a441..0019b5eee 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -393,6 +393,7 @@ wasm_engine_new_internal(wasm_config_t *config) WASM_C_DUMP_PROC_MEM(); /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */ + init_args.gc_heap_size = GC_HEAP_SIZE_DEFAULT; init_args.mem_alloc_type = config->mem_alloc_type; memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option, sizeof(MemAllocOption)); diff --git a/core/shared/mem-alloc/mem_alloc.cmake b/core/shared/mem-alloc/mem_alloc.cmake index 5f47cce13..76d1706dc 100644 --- a/core/shared/mem-alloc/mem_alloc.cmake +++ b/core/shared/mem-alloc/mem_alloc.cmake @@ -24,6 +24,10 @@ if (WAMR_BUILD_GC_CORRUPTION_CHECK EQUAL 0) add_definitions (-DBH_ENABLE_GC_CORRUPTION_CHECK=0) endif () +if (DEFINED WAMR_BUILD_GC_HEAP_SIZE_DEFAULT) + add_definitions ("-DGC_HEAP_SIZE_DEFAULT=${WAMR_BUILD_GC_HEAP_SIZE_DEFAULT}") +endif () + file (GLOB_RECURSE source_all ${MEM_ALLOC_DIR}/ems/*.c ${MEM_ALLOC_DIR}/tlsf/*.c From de82d1946f8a215e529fca04268d096051a2b313 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 3 Mar 2025 20:45:59 -0500 Subject: [PATCH 2/4] Address code review feedback --- core/iwasm/common/wasm_c_api.c | 2 +- doc/build_wamr.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 0019b5eee..04ec4e383 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -392,8 +392,8 @@ wasm_engine_new_internal(wasm_config_t *config) WASM_C_DUMP_PROC_MEM(); - /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */ init_args.gc_heap_size = GC_HEAP_SIZE_DEFAULT; + /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */ init_args.mem_alloc_type = config->mem_alloc_type; memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option, sizeof(MemAllocOption)); diff --git a/doc/build_wamr.md b/doc/build_wamr.md index cde884457..64be528bd 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -141,6 +141,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM ### **Enable Garbage Collection** - **WAMR_BUILD_GC**=1/0, default to disable if not set +- **WAMR_BUILD_GC_HEAP_SIZE_DEFAULT**=n, default to 128 kB (131072) if not set ### **Configure Debug** From d609acf1eec336ec1ed078123b12016c70e878ac Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 4 Mar 2025 18:43:30 -0500 Subject: [PATCH 3/4] Move the default heap size initialization --- core/iwasm/common/wasm_c_api.c | 1 - core/iwasm/common/wasm_runtime_common.c | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 04ec4e383..d5c45a441 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -392,7 +392,6 @@ wasm_engine_new_internal(wasm_config_t *config) WASM_C_DUMP_PROC_MEM(); - init_args.gc_heap_size = GC_HEAP_SIZE_DEFAULT; /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */ init_args.mem_alloc_type = config->mem_alloc_type; memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option, diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 95cea7fe9..5a2206b6e 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -757,7 +757,10 @@ wasm_runtime_full_init_internal(RuntimeInitArgs *init_args) #endif #if WASM_ENABLE_GC != 0 - gc_heap_size_default = init_args->gc_heap_size; + uint32 gc_heap_size = init_args->gc_heap_size; + if (gc_heap_size > 0) { + gc_heap_size_default = gc_heap_size; + } #endif #if WASM_ENABLE_JIT != 0 From 9027b2dce27529d4216e5c8cc1dc973b4c21b543 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 4 Mar 2025 18:46:14 -0500 Subject: [PATCH 4/4] Restore the doc heading. --- doc/build_wamr.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 64be528bd..b8cfcc989 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -141,6 +141,8 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM ### **Enable Garbage Collection** - **WAMR_BUILD_GC**=1/0, default to disable if not set + +### **Set the Garbage Collection heap size** - **WAMR_BUILD_GC_HEAP_SIZE_DEFAULT**=n, default to 128 kB (131072) if not set ### **Configure Debug**