Skip to content

feat(bex): complete garbage collector implementation - #3003

Merged
hellovai merged 2 commits into
canaryfrom
vbv/bex-gc-complete
Jan 20, 2026
Merged

feat(bex): complete garbage collector implementation#3003
hellovai merged 2 commits into
canaryfrom
vbv/bex-gc-complete

Conversation

@hellovai

@hellovai hellovai commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Complete the BEX garbage collector implementation by closing 5 identified gaps in the engine-level integration:

  • Gap 1: Parked VM roots now collected via VM pointer registry
  • Gap 2: VM stacks updated with forwarding pointers after GC
  • Gap 3: TLABs invalidated after GC space swap
  • Gap 6: Handle race condition fixed with EpochGuard

Key Changes

VM Pointer Registry (Phase 1-2)

  • Add parked_vms: Mutex<Vec<VmPtr>> to EpochState for tracking VMs at safepoints
  • VMs register pointers before parking, unregister after GC completes
  • GC collects roots from all parked VM stacks

Stack Updates & TLAB Invalidation (Phase 3)

  • Add collect_garbage_with_forwarding() that returns the forwarding map
  • Update parked VM stacks with new object indices after GC moves objects
  • Invalidate TLABs so VMs allocate from the new space

Handle Race Condition Fixes (Phase 4)

  • Remove cached ObjectIndex from Handle - always resolve through table
  • Add gc_in_progress flag to synchronize new calls with GC
  • New call_function invocations wait for in-progress GC before resolving handles

EpochGuard & Accessor API (Phase 6)

  • Add EpochGuard token type for compile-time epoch protection enforcement
  • Handle::object_index() now requires &EpochGuard<'_> parameter
  • Add heap accessor API (read_string, read_array, with_object) for safe external access

Documentation & Tests (Phase 5)

  • Add GC coordination documentation to module docs
  • Add e2e tests: test_gc_updates_forwarding_pointers, test_multiple_handles_survive_gc

Test plan

  • cargo build -p bex_engine -p bex_heap -p bex_external_types compiles
  • cargo test -p bex_engine - all tests pass (including 5 GC tests)
  • cargo test -p bex_heap - 28 tests pass
  • cargo test -p bex_external_types - all tests pass
  • cargo clippy passes
  • Compile-time enforcement: handle.object_index() without guard fails to compile

🤖 Generated with Claude Code

@vercel

vercel Bot commented Jan 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
beps Ready Ready Preview, Comment Jan 20, 2026 8:55am
promptfiddle Ready Ready Preview, Comment Jan 20, 2026 8:55am

Request Review

Complete the BEX garbage collector by closing 5 identified gaps:

- Gap 1: Parked VM roots now collected via VM pointer registry
- Gap 2: VM stacks updated with forwarding pointers after GC
- Gap 3: TLABs invalidated after GC space swap
- Gap 6: Handle race condition fixed with EpochGuard

Key changes:
- Add parked_vms registry to EpochState for tracking VMs at safepoints
- Collect roots from all parked VM stacks during GC
- Update parked VM stacks with forwarding pointers after copying
- Remove cached ObjectIndex from Handle (always resolve through table)
- Add gc_in_progress flag to synchronize new calls with GC
- Add EpochGuard token for compile-time epoch protection enforcement
- Add heap accessor API for safe external code access (read_string, etc.)
- Add GC coordination documentation to module docs
@hellovai
hellovai added this pull request to the merge queue Jan 20, 2026
Merged via the queue into canary with commit 6e051d6 Jan 20, 2026
35 checks passed
@hellovai
hellovai deleted the vbv/bex-gc-complete branch January 20, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant