ReviewOS

zig-utils/zig-js

Bridge: add collection epochs and arena reachability for managed values

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

Parent: #159 Related: #138, #144

Implement correct JSManagedValue conditional clearing before shared precise-GC context groups are available, without pretending the arena reclaimed storage. The bridge must distinguish semantic reachability from physical VM-lifetime allocation.

Acceptance:

  • Add a quiescent, cycle-safe reachability walk over every realm root in one JSContextGroupRef, traversing all strong runtime cell kinds and ignoring WeakRef/weak-collection edges.
  • Publish a collection epoch for JSGarbageCollect so managed values clear only after an explicit collection point, not merely on property access.
  • Keep managed values alive while any registered owner relation exists; owner death and exact add/remove pairs must update this state without retain cycles.
  • Clear an unowned JSManagedValue after collection when unreachable, while preserving targets reachable from globals, closures, promises/microtasks, modules, and sibling realms.
  • Add focused C/Zig reachability tests plus Objective-C forced-GC/system-JSC differential rows and fault-injection rollback tests.
  • Document that semantic weak clearing is immediate at the collection epoch even though arena storage is physically reclaimed only at VM teardown.
9 days ago

Collection epoch foundation landed in 7bec415. Every realm in one JSContextGroupRef now observes the same saturating monotonic ZJSContextGetCollectionEpoch, incremented at explicit JSGarbageCollect boundaries. The 117-symbol public inventory remains complete and the extension count is now 18; focused context-group and real C/C++ host gates pass.

9 days ago

Core semantic clearing landed through c97b224. ZJSValueIsReachable walks all group realms and transitive strong cells (including closure environments), resolves ephemerons, ignores WeakRef edges, and rejects foreign groups. JSManagedValue now clears only after a new explicit collection epoch, stays live under owner/global/closure/sibling roots, and clears after owner death or root removal. The complete Objective-C evidence matrix passes ASan+UBSan and Apple leaks at 0 bytes. Remaining acceptance is focused fault-injection rollback plus additional promise/module reachability and system-JSC evidence rows.

9 days ago

Completed through f29ca38. Evidence: group-wide collection epochs; cycle-safe semantic reachability across sibling realms, closures/environments, promises, and ephemerons; WeakRef exclusion; owner-aware JSManagedValue clearing; focused C/Zig and Objective-C forced-GC coverage; 18-row system-JSC parity (360c1ad3ccf51d6b); deterministic C-allocation and host-registration fault injection with successful retry after every rollback; ASan+UBSan; and Apple leaks reporting 0 leaked bytes.

Sign in to comment on this issue.