ReviewOS

zig-utils/zig-js

GC: retire and destroy precise sibling realms safely

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

Parent: #415 Depends on: #420, #421 GC parent: #144 Roadmap: #134

Complete the engine-core sibling lifecycle before #416 adopts it at the private ABI boundary.

Acceptance:

  • Stop realm jobs, timers, waiters, and threads before root retirement.
  • Remove the realm from the live root set atomically, run a synchronous full collection, and drain its deferred finalizers.
  • Release non-cell realm state and arena storage only after no owned cell can reference it.
  • Keep the heap owner alive until every sibling is retired and reject premature owner destruction.
  • Prove retained handles, shared Symbol identity, sibling reachability, exact finalization, relocation, and terminal teardown in Debug, ReleaseSafe, and TSan.
9 days ago

Completed on main by 34762f8, building on #420/#421.

Implemented:

  • a real createSharedPreciseRealm engine-core constructor with an independent non-cell arena, one shared precise heap/JIT, stable realm ID, failure-atomic bootstrap promotion, and VM-wide Symbol registry identity;
  • terminal retirement that rejects active interpreters/threads, stops terminal work, cancels timers, drops job/waiter/handle roots, atomically retires the realm, performs a synchronous full collection, drains deferred callbacks, and releases non-cell state only after hasRealmCells is false;
  • retryable RealmCellsRemain behavior when an owner-realm protected handle still reaches sibling cells;
  • an early all-build owner-destruction trap before any heap mutation while a live/bootstrapping/retiring sibling remains;
  • owner-only compaction with every live sibling quiescent.

Focused evidence exercises distinct globals/arenas, shared Symbol identity, protected-handle relocation, compaction refusal with sibling jobs, cross-realm reachability, exact finalizer accounting, one-shot external callback delivery, retryable retirement, and terminal teardown. Results: Debug 3/3, ReleaseSafe 3/3, TSan 3/3; all zero leaks.

9 days ago

All acceptance items are implemented and checked; private ABI adoption continues in #416.

Sign in to comment on this issue.