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.
Currently
GcRefStorekeeps 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:
WasmStructandWasmArrayshould hold direct Java references to theWasmGcRefobjects they point to (in addition to integer IDs) and they should go on theMStackGlobalsandTablesshould keep strong Java references to GC refs (these act as roots).GcRefStoreshould useWeakReferencesso 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.