Commit 6f0ac74
committed
feat(gc): Phase C4b-α — forwarding-pointer infrastructure (v0.5.229)
Lays the data-structure foundation for cross-arena copying
evacuation. No actual evacuation logic yet — that's C4b-β + γ in
a focused next session.
crates/perry-runtime/src/gc.rs:
GC_FLAG_FORWARDED = 0x80 (last available bit in u8 gc_flags)
Convention: when GC_FLAG_FORWARDED is set, the user-payload's
first 8 bytes hold the new user pointer (the address returned
by arena_alloc_gc_old when the object was relocated). Every
Perry GC type starts its payload with a header of at least 8
bytes (StringHeader / ArrayHeader / ObjectHeader / ClosureHeader
/ etc.), so this storage location is universally available
without changing object layouts.
forwarding_address(header) -> *mut u8
Reads the new user-pointer from a forwarded header.
Debug-asserts the flag is set.
set_forwarding_address(header, new_user_addr)
Installs the forwarding pointer + sets GC_FLAG_FORWARDED while
preserving every other gc_flags bit.
3 new unit tests pin invariants:
test_forwarding_pointer_roundtrip
test_forwarding_does_not_disturb_other_flags
test_forwarding_pointer_value_is_8_bytes_at_user_offset_zero
docs/generational-gc-plan.md extended with the full C4b-β/γ design:
- Pinning policy via GC_FLAG_CONS_PINNED for objects discovered
by conservative stack scan (can't safely rewrite their
referencing words → don't move them)
- C4b-β = conservative-pinning + evacuation pass (gated
PERRY_GEN_GC_EVACUATE=1 initially)
- C4b-γ = reference rewriting via shadow stack + globals + 9
registered root scanners + heap walks
- Ship criterion: bench_json_roundtrip direct RSS ≤70 MB
Runtime tests 159 -> 162.
Regression clean: 10/10 test_json_*.ts match Node — no behavior
change because nothing calls the helpers yet.
Honest scoping: C4b-β + γ together are the architectural boss-
fight of the gen-GC plan (~3-5 days, significant correctness
surface around conservative-stack pinning + ref-rewrite walks
for the 9 registered root scanners). Shipping the infrastructure
layer here so the real evacuation can land cleanly without
having to also relitigate the data-structure design.1 parent 81b81ea commit 6f0ac74
5 files changed
Lines changed: 215 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
0 commit comments