Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][MT] force memory views resize after loading assets and after VM start #110156

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mono/browser/runtime/pthreads/deputy-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function mono_wasm_start_deputy_thread_async () {

pthread_self.addEventListenerFromBrowser((message) => {
if (message.data.cmd == MainToWorkerMessageType.allAssetsLoaded) {
forceThreadMemoryViewRefresh();
runtimeHelpers.allAssetsInMemory.promise_control.resolve();
}
});
Expand All @@ -50,6 +51,8 @@ export function mono_wasm_start_deputy_thread_async () {

runtimeHelpers.proxyGCHandle = install_main_synchronization_context(runtimeHelpers.config.jsThreadBlockingMode!);

forceThreadMemoryViewRefresh();

postMessageToMain({
monoCmd: WorkerToMainMessageType.deputyReady,
info: monoThreadInfo,
Expand Down
2 changes: 2 additions & 0 deletions src/mono/browser/runtime/pthreads/ui-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MonoWorkerToMainMessage, monoThreadInfo, mono_wasm_pthread_ptr, update_
import { Module, ENVIRONMENT_IS_WORKER, createPromiseController, loaderHelpers, mono_assert, runtimeHelpers } from "../globals";
import { PThreadLibrary, MainToWorkerMessageType, MonoThreadMessage, PThreadInfo, PThreadPtr, PThreadPtrNull, PThreadWorker, PromiseController, Thread, WorkerToMainMessageType, monoMessageSymbol } from "../types/internal";
import { mono_log_info, mono_log_debug, mono_log_warn } from "../logging";
import { forceThreadMemoryViewRefresh } from "../memory";

const threadPromises: Map<PThreadPtr, PromiseController<Thread>[]> = new Map();

Expand Down Expand Up @@ -100,6 +101,7 @@ function monoWorkerMessageHandler (worker: PThreadWorker, ev: MessageEvent<any>)
runtimeHelpers.afterMonoStarted.promise_control.resolve();
break;
case WorkerToMainMessageType.deputyReady:
forceThreadMemoryViewRefresh();
runtimeHelpers.afterDeputyReady.promise_control.resolve(message.deputyProxyGCHandle);
break;
case WorkerToMainMessageType.ioStarted:
Expand Down
3 changes: 2 additions & 1 deletion src/mono/browser/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { populateEmscriptenPool, mono_wasm_init_threads } from "./pthreads";
import { currentWorkerThreadEvents, dotnetPthreadCreated, initWorkerThreadEvents, monoThreadInfo } from "./pthreads";
import { mono_wasm_pthread_ptr, update_thread_info } from "./pthreads";
import { jiterpreter_allocate_tables } from "./jiterpreter-support";
import { localHeapViewU8, malloc } from "./memory";
import { forceThreadMemoryViewRefresh, localHeapViewU8, malloc } from "./memory";
import { assertNoProxies } from "./gc-handles";
import { runtimeList } from "./exports";
import { nativeAbort, nativeExit } from "./run";
Expand Down Expand Up @@ -322,6 +322,7 @@ async function onRuntimeInitializedAsync (userOnRuntimeInitialized: (module:Emsc
await wait_for_all_assets();

if (WasmEnableThreads) {
forceThreadMemoryViewRefresh();
runtimeHelpers.deputyWorker.thread!.postMessageToWorker({
type:"deputyThread",
cmd: MainToWorkerMessageType.allAssetsLoaded,
Expand Down
Loading