runtime/wasm: preserve suspended goroutine GC roots (based on #2198, #2203) - #2207
Draft
cpunion wants to merge 49 commits into
Draft
runtime/wasm: preserve suspended goroutine GC roots (based on #2198, #2203)#2207cpunion wants to merge 49 commits into
cpunion wants to merge 49 commits into
Conversation
…/wasm-wasi-single-worker
…wasm-safepoints-roots-v2 # Conflicts: # .github/workflows/llgo.yml
…orker-asyncify-scheduler # Conflicts: # internal/build/source_patch_test.go
…/wasm-wasi-single-worker
# Conflicts: # .github/workflows/llgo.yml
…orker-asyncify-scheduler # Conflicts: # runtime/internal/runtime/z_default.go
…/wasm-wasi-single-worker
…nts-roots-v2 # Conflicts: # cl/compile.go
This was referenced Jul 29, 2026
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #2198 and #2203.
Part of #2152 (stage D).
Problem
The opt-in wasm collector from #2203 can scan globals and the active linear stack, but a live Go pointer may exist only in an SSA/wasm local. A goroutine suspended by the single-worker scheduler can also retain pointers in an inactive Asyncify context. Neither source is visible to the collector, so collection while another goroutine is suspended can reclaim live objects. Panic/longjmp unwinding adds the same risk unless the active root chain is restored with the defer frame.
Implementation
internal/gcrootplanSSA liveness planner. It publishes only pointer-bearing values live across GC safepoints, including aggregate pointer fields and closure contexts.{next, map, roots[N]}and link it throughllvm_gc_root_chain. Root access is a direct frame store; there is no heap allocation or per-access lookup.llvm.gcroot/shadow-stack lowering. LLVM 22 can move or inlinellvm.gcrootbefore backend lowering at optimized levels and crash CodeGenPrepare; the explicit frame ABI remains valid through-O0and optimized builds.Compiler analysis, LLVM frame emission, runtime chain ownership, and collector scanning are separate modules. The feature remains selected only with the internal
llgo_wasm_gctag; default wasm, native, embedded, and threaded WASI behavior is unchanged.Runtime flow
llvm_gc_root_chain.nextlinks, using each frame map to scan only pointer slots.Validation
The expanded wasm GC fixture covers pointers, slices, strings, interfaces, closures, aggregate fields, suspended goroutines, and panic/recover while collection and heap growth occur. It passes on:
GOOS=js GOARCH=wasmwasm gc okllgo build -target wasmwasm gc okGOOS=wasip1 GOARCH=wasm LLGO_WASI_THREADS=0wasm-tools validateand Wasmtime 39 with exceptions:wasm gc okLocal macOS checks used
GOMAXPROCS=2,GOMEMLIMIT=3GiB, and-p=1:./ssa: passcl, build-selection, planner, and runtime root-chain tests: passA root-wide
clrun reached the existingtestrt/namedsliceexecutable hang and the Go test process timed out after 10 minutes; the newcltests pass independently. Ubuntu validation is delegated to the bounded GitHub jobs.Cost and review scope
Earlier no-GC scheduler comparisons measured +1,604 bytes for J32 (+0.28%) and +1,644 bytes for P1 (+0.31%); no collector/root implementation was linked into those fixtures. Excluding the #2198/#2203 merge tree, this PR changes 37 files with 1,855 additions and 66 deletions, including the planner, compiler/runtime implementation, fixtures, and tests.