Skip to content

Commit c080aa8

Browse files
kylo5abyloganek
authored andcommitted
add a CL option to specify shared heap size
1 parent 8ae3bf7 commit c080aa8

File tree

1 file changed

+31
-0
lines changed
  • product-mini/platforms/windows

1 file changed

+31
-0
lines changed

product-mini/platforms/windows/main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ print_help()
5353
printf(" --gc-heap-size=n Set maximum gc heap size in bytes,\n");
5454
printf(" default is %u KB\n", GC_HEAP_SIZE_DEFAULT / 1024);
5555
#endif
56+
#if WASM_ENABLE_SHARED_HEAP != 0
57+
printf(" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n");
58+
printf(" The size n will be adjusted to a minumum number aligned to page size\n");
59+
#endif
5660
#if WASM_ENABLE_JIT != 0
5761
printf(" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n");
5862
printf(" --llvm-jit-opt-level=n Set LLVM JIT optimization level, default is 3\n");
@@ -364,6 +368,13 @@ main(int argc, char *argv[])
364368
gc_heap_size = atoi(argv[0] + 15);
365369
}
366370
#endif
371+
#if WASM_ENABLE_SHARED_HEAP != 0
372+
else if (!strncmp(argv[0], "--shared-heap-size=", 19)) {
373+
if (argv[0][19] == '\0')
374+
return print_help();
375+
shared_heap_size = atoi(argv[0] + 19);
376+
}
377+
#endif
367378
#if WASM_ENABLE_JIT != 0
368379
else if (!strncmp(argv[0], "--llvm-jit-size-level=", 22)) {
369380
if (argv[0][22] == '\0')
@@ -551,6 +562,23 @@ main(int argc, char *argv[])
551562
goto fail3;
552563
}
553564

565+
#if WASM_ENABLE_SHARED_HEAP != 0
566+
if (shared_heap_size > 0) {
567+
memset(&shared_heap_init_args, 0, sizeof(shared_heap_init_args));
568+
shared_heap_init_args.size = shared_heap_size;
569+
shared_heap = wasm_runtime_create_shared_heap(&shared_heap_init_args);
570+
571+
if (!shared_heap) {
572+
printf("Create shared heap failed.\n");
573+
goto fail5;
574+
}
575+
if (!wasm_runtime_attach_shared_heap(wasm_module_inst, shared_heap)) {
576+
printf("Attach shared heap failed.\n");
577+
goto fail5;
578+
}
579+
}
580+
#endif
581+
554582
#if WASM_ENABLE_DEBUG_INTERP != 0
555583
if (ip_addr != NULL) {
556584
wasm_exec_env_t exec_env =
@@ -598,6 +626,9 @@ main(int argc, char *argv[])
598626
if (exception)
599627
printf("%s\n", exception);
600628

629+
#if WASM_ENABLE_SHARED_HEAP != 0
630+
fail5:
631+
#endif
601632
#if WASM_ENABLE_DEBUG_INTERP != 0
602633
fail4:
603634
#endif

0 commit comments

Comments
 (0)