Repository navigation
Settle async WebAssembly on Linux JavaScriptCore - #2095
bkaradzic-microsoft wants to merge 2 commits into
Conversation
WebKitGTK's JavaScriptCore completes async WebAssembly.compile/instantiate through the GLib main context of the thread that created the VM. The AppRuntime thread never iterated that context, so the promises never settled on Linux. Give the JS thread its own GMainContext (pushed as thread default before the VM is created) and make RunDispatchLoop iterate it, using g_main_context_wakeup as the dispatcher waker. Iterating the context also fires JSC's GC timers. The full collection timer reaches WTF::MemoryPressureHandler, which needs WTF's main RunLoop; the JavaScriptCore C API never creates it, so the first full GC crashed. Call WTF::initializeMainThread (exported by libjavascriptcoregtk, not in its public headers) on the JS thread before creating the VM. Re-enable the WebAssembly unit tests and the 18 SPZ / CSG2 Playground validations on Linux JavaScriptCore, and link glib in the Linux install test. Fixes BabylonJS#2094 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bd57bfd-bbb3-4e86-8a17-9a44fb995d0f
There was a problem hiding this comment.
🟡 Changes recommended
Binding WTF’s process-global main loop to the first runtime’s disposable thread can cause a use-after-free when a later runtime triggers timer-driven full GC.
1 open issue
What changed in this PR
Extends the earlier Apple JavaScriptCore fix to Linux so asynchronous WebAssembly operations can settle, enabling SPZ Gaussian splatting and CSG2 scenes.
Changes:
- Pumps a thread-default GLib context alongside dispatcher work and initializes WTF’s main run loop for GC timers.
- Adds GLib linking to AppRuntime and the Linux install test.
- Enables Linux JavaScriptCore WebAssembly tests and 18 Playground validations, while retaining Android JavaScriptCore exclusions.
| File | Description |
|---|---|
| Install/Test/CMakeLists.txt | Links GLib in the Linux install test. |
| Dependencies/JsRuntimeHost/Tests/UnitTests/Source/Tests.AppRuntime.cpp | Adjusts Linux JavaScriptCore shutdown-test expectations. |
| Dependencies/JsRuntimeHost/Tests/UnitTests/Source/Scripts/tests.webAssembly.ts | Enables async WebAssembly tests on Linux JavaScriptCore. |
| Dependencies/JsRuntimeHost/Core/AppRuntime/Source/AppRuntime_JavaScriptCore.cpp | Adds GLib context lifecycle, dispatch-loop pumping, and WTF initialization. |
| Dependencies/JsRuntimeHost/Core/AppRuntime/CMakeLists.txt | Configures GLib dependencies for non-Apple, non-Android Unix JavaScriptCore builds. |
| Apps/Playground/Scripts/config.json | Removes Unix exclusions from 18 SPZ and CSG2 validations. |
Review effort: Balanced
…Core WTF::initializeMainThread is process-once and binds WTF's main RunLoop to the calling thread, whose thread-specific holder owns the only reference. Calling it on an AppRuntime thread left a dangling RunLoop::mainSingleton() once that runtime exited, so a later runtime's first timer-driven full collection (FullGCActivityCallback -> MemoryPressureHandler::singleton(), whose timer is created on the main RunLoop) used freed memory. Call it once from a dedicated detached thread that pushes a private GLib context and keeps it pumped for the rest of the process. Add AppRuntime.TimerDrivenCollectionAfterFirstRuntimeExits, which re-runs itself in a fresh process, destroys a runtime that never collects, then lets a second runtime run timer-driven full collections. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bd57bfd-bbb3-4e86-8a17-9a44fb995d0f
|
CI note (run 44434039032, attempt 1) Failed: This looks like the simulator's console capture losing output, not a test failure:
Job timings (queue wait → run time):
Total wall-clock: 37 min. The critical path is Win32_x64_V8_D3D11 (37m) and Ubuntu_Clang_JSC (33m). macOS runners queued 5–6 min, Windows 0–6 min. Rerunning failed jobs. |

Fixes #2094 (follow-up to #2068).
Problem
On Linux, WebKitGTK's JavaScriptCore completes async
WebAssembly.compile/WebAssembly.instantiateon the GLib main context of the thread that created the VM. The AppRuntime JS thread never iterated that context, so these promises never settled. As a result, SPZ (Gaussian splatting) and CSG2 (Manifold) scenes timed out.Fix
AppRuntime_JavaScriptCore.cpp(Linux JavaScriptCore only):GMainContextand pushes it as the thread default before the VM is created, so WTF's RunLoop adopts it.RunDispatchLoopalternates between running dispatcher work andg_main_context_iteration(ctx, TRUE).g_main_context_wakeupis the dispatcher waker.FullGCActivityCallbackreachesWTF::MemoryPressureHandler, which on Linux creates a timer onRunLoop::mainSingleton(). The JSC C API never creates that RunLoop, so the first full collection crashed.WTF::initializeMainThread()on the JS thread before creating the VM. libjavascriptcoregtk exports this function, but its public headers don't declare it, so this relies on an internal symbol. Thejscshell itself calls it.Install/Testadds glib to the Linux link.Tests
DestroyDoesNotDeadlockexpectations match Apple.UnixfromexcludedPlatformson the 18 SPZ / CSG2 validations. Android JavaScriptCore stays excluded because jsc-android has no WebAssembly.Local results (Ubuntu 24.04, clang, OpenGL, xvfb, libjavascriptcoregtk-4.1 2.52.6)
Install/Test): builds and links.