Skip to content

Enable host JVM GC to collect unreachable WasmGC references #1216

@andreaTP

Description

@andreaTP

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions