Skip to content

Commit 36e912b

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 fead712 commit 36e912b

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
@@ -411,7 +411,10 @@ impl GcState {
411411
}
412412

413413
if collecting.is_empty() {
414-
for i in 0..=generation {
414+
// Reset counts for generations whose objects were promoted away.
415+
// For gen2 (oldest), survivors stay in-place so don't reset gen2 count.
416+
let reset_end = if generation >= 2 { 2 } else { generation + 1 };
417+
for i in 0..reset_end {
415418
self.generations[i].count.store(0, Ordering::SeqCst);
416419
}
417420
let duration = start_time.elapsed().as_secs_f64();
@@ -521,7 +524,7 @@ impl GcState {
521524
if unreachable.is_empty() {
522525
drop(gen_locks);
523526
self.promote_survivors(generation, &survivor_refs);
524-
for i in 0..=generation {
527+
for i in 0..generation {
525528
self.generations[i].count.store(0, Ordering::SeqCst);
526529
}
527530
let duration = start_time.elapsed().as_secs_f64();
@@ -541,7 +544,7 @@ impl GcState {
541544

542545
if unreachable_refs.is_empty() {
543546
self.promote_survivors(generation, &survivor_refs);
544-
for i in 0..=generation {
547+
for i in 0..generation {
545548
self.generations[i].count.store(0, Ordering::SeqCst);
546549
}
547550
let duration = start_time.elapsed().as_secs_f64();
@@ -685,8 +688,10 @@ impl GcState {
685688
});
686689
}
687690

688-
// Reset counts for all collected generations
689-
for i in 0..=generation {
691+
// Reset counts for generations whose objects were promoted away.
692+
// For gen2 (oldest), survivors stay in-place so don't reset gen2 count.
693+
let reset_end = if generation >= 2 { 2 } else { generation + 1 };
694+
for i in 0..reset_end {
690695
self.generations[i].count.store(0, Ordering::SeqCst);
691696
}
692697

0 commit comments

Comments
 (0)