Enable host JVM GC to collect unreachable WasmGC references
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Currently `GcRefStore` keeps strong references and runs its own mark-sweep every 1024 allocations. The JVM GC can’t collect unreachable Wasm objects because the Wasm reference graph is encoded as integer IDs (struct fields and array elements), not Java object references.
To let the JVM handle collection, we need to mirror the Wasm graph with real Java references so JVM reachability matches Wasm reachability:
- `WasmStruct` and `WasmArray` should hold direct Java references to the `WasmGcRef` objects they point to (in addition to integer IDs) and they should go on the `MStack`
- `Globals` and `Tables` should keep strong Java references to GC refs (these act as roots).
- `GcRefStore` should use `WeakReferences` so entries are collectible once no root-reachable Java chain exists.
This would remove the periodic sweep and allow the JVM to collect unreachable Wasm GC subgraphs naturally.
Contributor guide
Research direction
Start by tracing how GcRefStore, WasmStruct, WasmArray, Globals, Tables, and MStack currently represent references and roots. Verify how the integer-ID graph is maintained and where the periodic mark-sweep runs. Done means unreachable Wasm subgraphs can be reclaimed by JVM GC, while root-reachable references remain available and periodic sweeping is removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, wasm
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100