From 974cdd6340ec74a2948c019db9d15bd1bbfefde1 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 11 Jul 2023 15:00:18 -0700 Subject: [PATCH] TESTING: Allocate a bunch of memory before exiting to see how close we are to the limit --- src/mono/wasm/runtime/loader/exit.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mono/wasm/runtime/loader/exit.ts b/src/mono/wasm/runtime/loader/exit.ts index 94a6bf8ba7fd80..d17e4076967b61 100644 --- a/src/mono/wasm/runtime/loader/exit.ts +++ b/src/mono/wasm/runtime/loader/exit.ts @@ -72,6 +72,19 @@ async function flush_node_streams() { } function set_exit_code_and_quit_now(exit_code: number, reason?: any): void { + let bytesAllocated = 0; + const allocationSize = 8 * 1024 * 1024, numAllocations = 20; + try { + const buffers : Uint8Array[] = []; + for (let i = 0; i < numAllocations; i++) { + buffers.push(new Uint8Array(allocationSize)); + bytesAllocated += allocationSize; + } + mono_log_info_no_prefix(`successfully allocated ${bytesAllocated} bytes of memory at exit`); + } catch (exc) { + mono_log_info_no_prefix(`allocating memory at exit failed after ${bytesAllocated} bytes`); + } + if (runtimeHelpers.ExitStatus) { if (reason && !(reason instanceof runtimeHelpers.ExitStatus)) { if (!loaderHelpers.config.logExitCode) {