Skip to content

Commit fad1b25

Browse files
committed
gc: fix count reset to preserve gen2 count for survivors
Don't reset the target generation's count when it's the oldest (gen2), since promote_survivors returns early and survivors remain in-place. Only reset younger generations whose objects were promoted away.
1 parent 8c82547 commit fad1b25

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/vm/src/gc_state.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ impl GcState {
417417
}
418418

419419
if collecting.is_empty() {
420-
for i in 0..=generation {
420+
// Reset counts for generations whose objects were promoted away.
421+
// For gen2 (oldest), survivors stay in-place so don't reset gen2 count.
422+
let reset_end = if generation >= 2 { 2 } else { generation + 1 };
423+
for i in 0..reset_end {
421424
self.generations[i].count.store(0, Ordering::SeqCst);
422425
}
423426
let duration = start_time.elapsed().as_secs_f64();
@@ -530,7 +533,7 @@ impl GcState {
530533
if unreachable.is_empty() {
531534
drop(gen_locks);
532535
self.promote_survivors(generation, &survivor_refs);
533-
for i in 0..=generation {
536+
for i in 0..generation {
534537
self.generations[i].count.store(0, Ordering::SeqCst);
535538
}
536539
let duration = start_time.elapsed().as_secs_f64();
@@ -550,7 +553,7 @@ impl GcState {
550553

551554
if unreachable_refs.is_empty() {
552555
self.promote_survivors(generation, &survivor_refs);
553-
for i in 0..=generation {
556+
for i in 0..generation {
554557
self.generations[i].count.store(0, Ordering::SeqCst);
555558
}
556559
let duration = start_time.elapsed().as_secs_f64();
@@ -694,8 +697,10 @@ impl GcState {
694697
});
695698
}
696699

697-
// Reset counts for all collected generations
698-
for i in 0..=generation {
700+
// Reset counts for generations whose objects were promoted away.
701+
// For gen2 (oldest), survivors stay in-place so don't reset gen2 count.
702+
let reset_end = if generation >= 2 { 2 } else { generation + 1 };
703+
for i in 0..reset_end {
699704
self.generations[i].count.store(0, Ordering::SeqCst);
700705
}
701706

0 commit comments

Comments
 (0)