ReviewOS

zig-utils/zig-js

GC relocation: compact at precise baseline-JIT safepoints

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

Parent: #336 Related: #133, #144, #146, #358

The current AArch64 baseline tier already has one precise moving-GC-safe checkpoint contract: before calling the runtime it publishes canonical Number words for every numeric local, spills live numeric operands, leaves non-numeric slots restricted to pointer-free primitives, publishes the exact instruction/step state, and holds only stable NativeFrame/runtime pointers plus numeric registers. The active interpreter and its Exec/frame roots are registered.

Implement explicit requested compaction at exactly that safepoint without weakening any other fail-closed boundary.

Scope:

  • add a Context request API with a pending bit that is serviced only at a declared precise interpreter/native safepoint;
  • mark the baseline native checkpoint precise for the duration of its runtime callback;
  • factor the compaction gate so exactly the current precise interpreter may move, while ordinary public compaction still requires a fully quiescent realm;
  • retain rejection for generic interpreter points, native host callbacks, conservative scans, running/parked peers, concurrent/parallel collectors, unsupported backends, and reentrant relocation;
  • prove a ready native loop requests movement, relocates a protected graph during execution, resumes from the exact checkpoint, returns the right result, and keeps using the same native tier;
  • machine-check the materialization and narrow activation contract; update concise README/JIT/relocation documentation.

Acceptance:

  • the request remains pending at imprecise checkpoints and clears only after a real supported attempt;
  • useful fragmented backing is compacted during a native execution rather than before/after it;
  • generated execution resumes correctly with exact result/step semantics and no stale managed pointer;
  • Debug, ReleaseSafe, TSan, C/Objective-C/public ABI, and relocation inventory evidence stays green.
9 days ago

Implemented and pushed in ca92af0. Context.requestGarbageCompaction now remains pending until a checkpoint declares both precise roots and movement-safe resumption. Only the current AArch64 baseline numeric checkpoint sets that stronger token after publishing canonical locals, spilling operands, and recording exact state. Public compactGarbage remains quiescent-only; marking-precise Zig helpers, host callbacks, generic VM paths, peers, conservative scans, and active collectors remain rejected. The witness moves the active Function/Object/protected graph, resumes the same native entry, returns the exact sum, and reaches a dense fixed point. Debug, ReleaseSafe, and TSan each passed 7/7 with zero leaks; C/Objective-C hosts, 117/117 C audit plus extension/private exports, 108/108 Objective-C audit, relocation inventory, and release matrix validation are green.

Sign in to comment on this issue.