ReviewOS

zig-utils/zig-js

GC: make same-VM replacement realms precisely collectable

#414
Closed chris opened this 9 days ago ·
9 days ago

Parent: #412 GC parent: #144 Profiles: #163, #164 Roadmap: #134

The exact private global lifecycle now creates clean same-VM replacement realms and retires the old realm from process lookup, but public C context groups are arena-backed. Unreachable cells from an isolated realm therefore remain physically allocated until the VM group is destroyed. Implement one shared precise-GC realm architecture so test isolation can reclaim the old global, module graph, jobs, and embedder roots without replacing the VM.

Acceptance:

  • Allow a precise-GC VM/group to own multiple independent realms with distinct globals, intrinsics, environments, shapes, module state, and microtask queues.
  • Trace every live realm as a VM root while allowing a retired realm to leave the root set atomically.
  • Keep same-VM value identity, Symbol registry behavior, pending-exception behavior, barriers, stable cell IDs, and relocation updates correct across sibling realms.
  • Make Zig__GlobalObject__create and Zig__GlobalObject__createForTestIsolation use the precise-GC group path while preserving the #412 ownership and execution-context contract.
  • Drop the old global, module registry, queued jobs, and embedding roots before a synchronous full collection; prove external-owner finalizers run once.
  • Cover retained old handles, sibling-realm reachability, concurrent lookup retirement, collection during/after replacement, compaction eligibility, and terminal VM teardown.
  • Add focused Debug, ReleaseSafe, TSan, and relocation evidence without weakening existing arena-backed public context-group behavior.
  • Update the #412 contract/docs and reconcile exact main CI before closing this dependency.

Child issue map

  • #415 — ownership-aware precise heap across sibling realms
  • #416 — migrate the private global lifecycle after #415
9 days ago

Complete through #415 and #416. Shared precise heaps now own independent sibling realms, route allocations/work by semantic realm, retire roots atomically, preserve stable IDs and VM-scoped identity, reclaim outgoing realm graphs, and pass relocation/TSan evidence. Exact main run 29801586207 is fully green.

Sign in to comment on this issue.