From 3d5c8a5b3b4fdd2a5a86d82063af9f2564c73422 Mon Sep 17 00:00:00 2001 From: zhenweijin Date: Fri, 18 Jul 2025 10:34:44 +0800 Subject: [PATCH] add a CL option to specify shared heap size --- product-mini/platforms/windows/main.c | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index 7537216dce..31680da8a8 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -53,6 +53,10 @@ print_help() printf(" --gc-heap-size=n Set maximum gc heap size in bytes,\n"); printf(" default is %u KB\n", GC_HEAP_SIZE_DEFAULT / 1024); #endif +#if WASM_ENABLE_SHARED_HEAP != 0 + printf(" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n"); + printf(" The size n will be adjusted to a minumum number aligned to page size\n"); +#endif #if WASM_ENABLE_JIT != 0 printf(" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n"); printf(" --llvm-jit-opt-level=n Set LLVM JIT optimization level, default is 3\n"); @@ -364,6 +368,13 @@ main(int argc, char *argv[]) gc_heap_size = atoi(argv[0] + 15); } #endif +#if WASM_ENABLE_SHARED_HEAP != 0 + else if (!strncmp(argv[0], "--shared-heap-size=", 19)) { + if (argv[0][19] == '\0') + return print_help(); + shared_heap_size = atoi(argv[0] + 19); + } +#endif #if WASM_ENABLE_JIT != 0 else if (!strncmp(argv[0], "--llvm-jit-size-level=", 22)) { if (argv[0][22] == '\0') @@ -551,6 +562,23 @@ main(int argc, char *argv[]) goto fail3; } +#if WASM_ENABLE_SHARED_HEAP != 0 + if (shared_heap_size > 0) { + memset(&shared_heap_init_args, 0, sizeof(shared_heap_init_args)); + shared_heap_init_args.size = shared_heap_size; + shared_heap = wasm_runtime_create_shared_heap(&shared_heap_init_args); + + if (!shared_heap) { + printf("Create shared heap failed.\n"); + goto fail5; + } + if (!wasm_runtime_attach_shared_heap(wasm_module_inst, shared_heap)) { + printf("Attach shared heap failed.\n"); + goto fail5; + } + } +#endif + #if WASM_ENABLE_DEBUG_INTERP != 0 if (ip_addr != NULL) { wasm_exec_env_t exec_env = @@ -598,6 +626,9 @@ main(int argc, char *argv[]) if (exception) printf("%s\n", exception); +#if WASM_ENABLE_SHARED_HEAP != 0 +fail5: +#endif #if WASM_ENABLE_DEBUG_INTERP != 0 fail4: #endif