Skip to content

Commit 339640f

Browse files
authored
Fix an issue that we did not throw OOM for Immix plans if DEFRAG is set to false (#500)
1 parent 1fc31f6 commit 339640f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/plan/generational/immix/global.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub struct GenImmix<VM: VMBinding> {
3939
/// An immix space as the mature space.
4040
pub immix: ImmixSpace<VM>,
4141
/// Whether the last GC was a defrag GC for the immix space.
42-
// This is not used. It should be used for last_collection_was_exhaustive.
43-
// TODO: We need to fix this.
4442
pub last_gc_was_defrag: AtomicBool,
43+
/// Whether the last GC was a full heap GC
44+
pub last_gc_was_full_heap: AtomicBool,
4545
}
4646

4747
pub const GENIMMIX_CONSTRAINTS: PlanConstraints = PlanConstraints {
@@ -76,7 +76,10 @@ impl<VM: VMBinding> Plan for GenImmix<VM> {
7676
}
7777

7878
fn last_collection_was_exhaustive(&self) -> bool {
79-
self.last_gc_was_defrag.load(Ordering::Relaxed)
79+
self.last_gc_was_full_heap.load(Ordering::Relaxed)
80+
&& ImmixSpace::<VM>::is_last_gc_exhaustive(
81+
self.last_gc_was_defrag.load(Ordering::Relaxed),
82+
)
8083
}
8184

8285
fn force_full_heap_collection(&self) {
@@ -163,6 +166,8 @@ impl<VM: VMBinding> Plan for GenImmix<VM> {
163166
} else {
164167
self.last_gc_was_defrag.store(false, Ordering::Relaxed);
165168
}
169+
self.last_gc_was_full_heap
170+
.store(full_heap, Ordering::Relaxed);
166171
}
167172

168173
fn get_collection_reserve(&self) -> usize {
@@ -227,6 +232,7 @@ impl<VM: VMBinding> GenImmix<VM> {
227232
),
228233
immix: immix_space,
229234
last_gc_was_defrag: AtomicBool::new(false),
235+
last_gc_was_full_heap: AtomicBool::new(false),
230236
};
231237

232238
// Use SideMetadataSanity to check if each spec is valid. This is also needed for check

src/plan/immix/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<VM: VMBinding> Plan for Immix<VM> {
5050
}
5151

5252
fn last_collection_was_exhaustive(&self) -> bool {
53-
self.last_gc_was_defrag.load(Ordering::Relaxed)
53+
ImmixSpace::<VM>::is_last_gc_exhaustive(self.last_gc_was_defrag.load(Ordering::Relaxed))
5454
}
5555

5656
fn constraints(&self) -> &'static PlanConstraints {

src/policy/immix/immixspace.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,15 @@ impl<VM: VMBinding> ImmixSpace<VM> {
499499
.all(|line| !line.is_marked(unavail_state) && !line.is_marked(current_state)));
500500
Some(start..end)
501501
}
502+
503+
pub fn is_last_gc_exhaustive(did_defrag_for_last_gc: bool) -> bool {
504+
if super::DEFRAG {
505+
did_defrag_for_last_gc
506+
} else {
507+
// If defrag is disabled, every GC is exhaustive.
508+
true
509+
}
510+
}
502511
}
503512

504513
/// A work packet to prepare each block for GC.

0 commit comments

Comments
 (0)