Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/perry-runtime/src/gc/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,17 @@ pub(crate) fn gc_moving_safepoint_enabled() -> bool {
pub(crate) fn gc_incremental_enabled() -> bool {
static CACHED: OnceLock<bool> = OnceLock::new();
*CACHED.get_or_init(|| {
matches!(
// DEFAULT ON (#6180 flip): ordinary allocation pressure is collected
// by the budgeted incremental stepper — debt-paced assists, sound
// across mutator windows (mark barrier + allocate-black + final
// remark + drain-before-synchronous), census-free, RSS-parity on
// realistic workloads with ~5x lower worst pause. Bounded pauses by
// default; the synchronous collector remains for manual gc(),
// emergency reclaim, and as the PERRY_GC_INCREMENTAL=0 escape hatch
// (bisection / max-throughput batch workloads).
!matches!(
std::env::var("PERRY_GC_INCREMENTAL").as_deref(),
Ok("1") | Ok("on") | Ok("true")
Ok("0") | Ok("off") | Ok("false")
)
})
}
Expand Down
16 changes: 11 additions & 5 deletions crates/perry-runtime/src/gc/tests/budgeted_step_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ fn arena_pressure_budgeted_step_starts_bounded_minor_cycle() {
}

#[test]
fn synchronous_only_registered_scanner_blocks_budgeted_step_start() {
fn synchronous_only_registered_scanner_runs_inline_under_default_incremental() {
// #6180 flip: incremental is the DEFAULT. Unbudgeted mutable scanners no
// longer block the budgeted stepper — they run synchronously inside the
// initial root-scan step (a bounded initial-mark pause). The meaningful
// contract is that the cycle starts, completes, and roots the scanner
// sees survive.
let _guard = CopyingNurseryTestGuard::new(1);
let trigger_guard = GcTriggerThresholdTestGuard::suppress_automatic_triggers();
reset_old_reclaim_pressure();
Expand All @@ -84,11 +89,12 @@ fn synchronous_only_registered_scanner_blocks_budgeted_step_start() {
let mut result = JsGcStepResult::default();
assert_eq!(
js_gc_step_work_units(1, &mut result),
JS_GC_STEP_STATUS_SKIPPED
JS_GC_STEP_STATUS_ACTIVE,
"budgeted stepper must start despite unbudgeted mutable scanners"
);
assert_eq!(result.active, 0);
assert_eq!(result.completed, 0);
assert_eq!(js_gc_step_status(&mut result), JS_GC_STEP_STATUS_IDLE);
let completed = complete_budgeted_gc_cycle();
assert_eq!(completed.status, JS_GC_STEP_STATUS_COMPLETED);
assert_eq!(js_shadow_slot_get(0) & POINTER_MASK, live as u64);
}

#[test]
Expand Down
17 changes: 10 additions & 7 deletions crates/perry-runtime/src/gc/tests/cycle_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ fn root_scan_slices_many_registered_tui_state_roots_with_tiny_budget() {
}

#[test]
fn normal_incremental_root_scan_pauses_before_synchronous_only_registered_scanner() {
fn normal_incremental_root_scan_runs_synchronous_only_scanner_inline() {
// #6180 flip: with incremental as the default, unbudgeted mutable
// scanners run synchronously inside the initial root-scan step instead
// of pausing the cycle before them.
let _guard = CopyingNurseryTestGuard::new(0);
let _trigger_guard = GcTriggerThresholdTestGuard::suppress_automatic_triggers();
SYNC_ONLY_SCANNER_CALLS.store(0, Ordering::Relaxed);
Expand All @@ -602,15 +605,15 @@ fn normal_incremental_root_scan_pauses_before_synchronous_only_registered_scanne
state.set_progress_kind(GcProgressKind::NormalIncremental);
run_cycle_until_phase(&mut state, GcCyclePhase::RootScan);

for _ in 0..8 {
let mut steps = 0usize;
while state.phase() == GcCyclePhase::RootScan && steps < 500_000 {
state.step(GcWorkBudget::bounded(1));
steps += 1;
}

assert_eq!(state.phase(), GcCyclePhase::RootScan);
assert_eq!(
SYNC_ONLY_SCANNER_CALLS.load(Ordering::Relaxed),
0,
"ordinary budgeted root scan must not invoke synchronous-only scanners"
assert!(
SYNC_ONLY_SCANNER_CALLS.load(Ordering::Relaxed) >= 1,
"default-incremental root scan must run synchronous-only scanners inline"
);
incremental_mark_barrier_disable();
clear_mark_seeds();
Expand Down
41 changes: 41 additions & 0 deletions crates/perry-runtime/src/gc/tests/debt_pacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,44 @@ fn atomic_finalize_remark_rescues_pointer_hidden_in_shadow_slot_after_root_scan(
"remark must keep the shadow-slot-only pointer off the sweep free list"
);
}

/// #6228: array growth installs a PERMANENT forwarding stub at the old
/// address; a stale pre-growth pointer held as the ONLY reference (the
/// deforestation pass manufactures exactly this for direct calls) must keep
/// the live post-growth array alive — the tracer hops the forwarding edge
/// and MARKS the target instead of treating the stub as zero-children.
#[test]
fn forwarded_array_stub_propagates_liveness_to_grown_array() {
let _guard = CopyingNurseryTestGuard::new(1);
let trigger_guard = GcTriggerThresholdTestGuard::suppress_automatic_triggers();
reset_old_reclaim_pressure();

let arr = crate::array::js_array_alloc(4);
let pre_growth = arr as usize;
// Push past capacity: js_array_grow reallocates and installs the
// forwarding stub at `pre_growth`.
for i in 0..64 {
crate::array::js_array_push(
pre_growth as *mut crate::array::ArrayHeader,
crate::JSValue::number(i as f64),
);
}
let header = unsafe { header_from_user_ptr(pre_growth as *const u8) };
assert!(
unsafe { (*header).gc_flags } & GC_FLAG_FORWARDED != 0,
"growth past capacity must leave a forwarding stub at the old address"
);

// The stale pre-growth pointer is the ONLY root.
js_shadow_slot_set(0, ptr_bits(pre_growth));

trigger_guard.make_arena_trigger_due();
gc_check_trigger();
let completed = complete_budgeted_gc_cycle();
assert_eq!(completed.status, JS_GC_STEP_STATUS_COMPLETED);

// Reads through the stale pointer must still see the full array.
let live = pre_growth as *const crate::array::ArrayHeader;
assert_eq!(crate::array::js_array_length(live), 64);
assert_eq!(crate::array::js_array_get_f64_unchecked(live, 63), 63.0);
}
21 changes: 21 additions & 0 deletions crates/perry-runtime/src/gc/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,27 @@ pub(super) fn trace_one_worklist_header(
) {
unsafe {
let user_ptr = (header as *mut u8).add(GC_HEADER_SIZE);
// #6228: a FORWARDED header (array growth installs PERMANENT
// forwarding stubs — types.rs set_forwarding_address — so stale
// pre-growth pointers keep resolving for reads) must propagate
// liveness to its target instead of tracing as zero-children. The
// deforestation pass manufactures exactly such a stale pointer as
// the ONLY reference (direct-call `var b = build(n)`), and without
// this hop the live post-growth array was swept: length 0 / NaN
// reads past 32 MiB. Mirrors the (previously dead-code) trace_array
// path, plus MARKING the target — worklist membership alone does
// not protect it from the sweep.
if (*header).gc_flags & GC_FLAG_FORWARDED != 0 {
let new_user = forwarding_address(header) as usize;
if new_user >= 0x1000 && valid_ptrs.contains(&new_user) {
let new_header = header_from_user_ptr(new_user as *const u8);
if (*new_header).gc_flags & GC_FLAG_MARKED == 0 {
(*new_header).gc_flags |= GC_FLAG_MARKED;
worklist.push(new_header);
}
}
return;
}
// C3b/C4 generational skip: in minor mode, an object
// is treated as a black leaf when it lives in OLD_ARENA
// (Phase B physical region) OR carries GC_FLAG_TENURED
Expand Down
19 changes: 13 additions & 6 deletions crates/perry-runtime/src/gc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,18 +499,25 @@ pub(super) static GC_TYPE_INFO_BY_ID: [Option<GcTypeInfo>; MALLOC_KIND_BUCKET_CO
true,
GcRewriteDescriptorKind::Leaf,
GcLayoutSlotKind::None,
// Non-movable: like Date, a Temporal value is referenced by a NaN-boxed
// pointer kept in a plain f64/DOUBLE local that codegen does NOT
// shadow-root. The conservative stack scan keeps it alive; a stable
// address means that un-rooted pointer never goes stale across a GC.
false,
// Movable (#6186, completing the Date change from #6214 — the
// non-movable rationale above it was disproven there): `movable`
// only gates OLD-PAGE DEFRAG, which runs solely inside moving
// collections at stack-unwound safepoints; the nursery copied-minor
// already relocates Temporal cells. The embedded `temporal_rs` value
// survives memcpy (its owned allocations live on the Rust heap and
// move by value); from-space bulk resets skip per-object finalizers,
// so a moved cell is never double-dropped — `TemporalCleanup` fires
// once, wherever the cell finally dies.
true,
GcExternalBytePolicy::None,
GcLargeObjectPolicy::NotApplicable,
// pointer_free: the embedded `temporal_rs` value is plain integers +
// `'static` calendar data, never a JSValue. Any Rust-heap it owns is
// released by the TemporalCleanup finalize hook, not GC tracing.
true,
GcMoveHookKind::None,
// Expando rekey on relocation, mirroring Date: no-op when the cell
// has no expando entry.
GcMoveHookKind::ExoticExpandoOwner,
Comment on lines +518 to +520

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the stale doc comment in exotic_expando.rs.

The doc comment on exotic_expando_owner_moved (lines 250-270 of crates/perry-runtime/src/object/exotic_expando.rs) states: "Date / RegExp / Temporal cells are non-movable so this never fires for them." With this PR marking Temporal movable (and the prior Date change in #6214), the function now fires for both. The stale comment could mislead future developers.

📝 Proposed doc update in exotic_expando.rs
 /// Rekey a movable exotic cell's expando entry after the GC relocates it from
 /// `old_addr` to `new_addr`. Date / RegExp / Temporal cells are non-movable so
-/// this never fires for them, but a `Promise` (`GC_TYPE_PROMISE`) is movable —
+/// this never fires for them, but a `Promise` (`GC_TYPE_PROMISE`),
+/// `Date` (`GC_TYPE_DATE_CELL`), and `Temporal` (`GC_TYPE_TEMPORAL`) are movable —
 /// without this, a `.then()`-chained thenable that survives a GC move would
 /// lose the `status`/`value` expandos it was gated on. Stored expando *values*
 /// are already rewritten by `scan_exotic_expando_roots_mut`; this migrates the
 /// owner *key*. Wired via `GcMoveHookKind::ExoticExpandoOwner`.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-runtime/src/gc/types.rs` around lines 518 - 520, Update the doc
comment for exotic_expando_owner_moved in exotic_expando.rs to remove the claim
that Date and Temporal cells are non-movable or that the hook never fires for
them; accurately state that the hook handles movable Date and Temporal cells,
along with RegExp as applicable.

GcRewriteHookKind::None,
GcFinalizeHookKind::TemporalCleanup,
)),
Expand Down
Loading