Skip to content

Commit 29d482c

Browse files
authored
Extract set_collection_kind and set_gc_status (#957)
This PR extracts `set_collection_kind` and `set_gc_status` from each plan's `schedule_collection`, and calls them directly in the `ScheduleCollection` work packet. This removes duplicated code, and also makes our implementation consistent with Java MMTk. For generational plans, in `schedule_collection` in each plan, our current code calls `requires_full_heap_collection` first, and then call `set_collection_kind`. With the changes in the PR, `requires_full_heap_collection` is called after `set_collection_kind`, which is the same as in Java MMTk ([super.collectionPhase(phaseId);](https://github.com/JikesRVM/JikesRVM/blob/5072f19761115d987b6ee162f49a03522d36c697/MMTk/src/org/mmtk/plan/generational/Gen.java#L172-L173)). The implications are: 1. When `set_collection_kind` forces a full heap GC, and `set_collection_kind` is called before `requires_full_heap_collection`, we will do a full heap GC in the current GC (which is the expected behavior in Java MMTk). 2. `set_collection_kind` may increase `cur_collection_attempt`, which makes it more likely to trigger an emergency GC, and makes it more likely to trigger a full heap GC. In summary, we miss some opportunities where we should do a full heap GC. With the changes, we should properly trigger full heap GCs when we should.
1 parent 53df6a3 commit 29d482c

File tree

11 files changed

+8
-39
lines changed

11 files changed

+8
-39
lines changed

docs/userguide/src/tutorial/code/mygc_semispace/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ANCHOR: imports_no_gc_work
22
use crate::plan::global::BasePlan; //Modify
33
use crate::plan::global::CommonPlan; // Add
4-
use crate::plan::global::GcStatus; // Add
54
use crate::plan::global::{CreateGeneralPlanArgs, CreateSpecificPlanArgs};
65
use crate::plan::mygc::mutator::ALLOCATOR_MAPPING;
76
use crate::plan::mygc::gc_work::MyGCWorkContext;
@@ -77,8 +76,6 @@ impl<VM: VMBinding> Plan for MyGC<VM> {
7776
// Modify
7877
// ANCHOR: schedule_collection
7978
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
80-
self.base().set_collection_kind::<Self>(self);
81-
self.base().set_gc_status(GcStatus::GcPrepare);
8279
scheduler.schedule_common_work::<MyGCWorkContext<VM>>(self);
8380
}
8481
// ANCHOR_END: schedule_collection

src/plan/generational/copying/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::plan::global::BasePlan;
88
use crate::plan::global::CommonPlan;
99
use crate::plan::global::CreateGeneralPlanArgs;
1010
use crate::plan::global::CreateSpecificPlanArgs;
11-
use crate::plan::global::GcStatus;
1211
use crate::plan::AllocationSemantics;
1312
use crate::plan::Plan;
1413
use crate::plan::PlanConstraints;
@@ -73,8 +72,6 @@ impl<VM: VMBinding> Plan for GenCopy<VM> {
7372

7473
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
7574
let is_full_heap = self.requires_full_heap_collection();
76-
self.base().set_collection_kind::<Self>(self);
77-
self.base().set_gc_status(GcStatus::GcPrepare);
7875
if is_full_heap {
7976
scheduler.schedule_common_work::<GenCopyGCWorkContext<VM>>(self);
8077
} else {

src/plan/generational/immix/global.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::plan::global::BasePlan;
66
use crate::plan::global::CommonPlan;
77
use crate::plan::global::CreateGeneralPlanArgs;
88
use crate::plan::global::CreateSpecificPlanArgs;
9-
use crate::plan::global::GcStatus;
109
use crate::plan::AllocationSemantics;
1110
use crate::plan::Plan;
1211
use crate::plan::PlanConstraints;
@@ -104,10 +103,6 @@ impl<VM: VMBinding> Plan for GenImmix<VM> {
104103
#[allow(clippy::branches_sharing_code)]
105104
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<Self::VM>) {
106105
let is_full_heap = self.requires_full_heap_collection();
107-
108-
self.base().set_collection_kind::<Self>(self);
109-
self.base().set_gc_status(GcStatus::GcPrepare);
110-
111106
if !is_full_heap {
112107
debug!("Nursery GC");
113108
scheduler.schedule_common_work::<GenImmixNurseryGCWorkContext<VM>>(self);

src/plan/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<VM: VMBinding> BasePlan<VM> {
691691
self.vm_space.release();
692692
}
693693

694-
pub fn set_collection_kind<P: Plan>(&self, plan: &P) {
694+
pub fn set_collection_kind(&self, plan: &dyn Plan<VM = VM>) {
695695
self.cur_collection_attempts.store(
696696
if self.is_user_triggered_collection() {
697697
1

src/plan/immix/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::plan::global::BasePlan;
44
use crate::plan::global::CommonPlan;
55
use crate::plan::global::CreateGeneralPlanArgs;
66
use crate::plan::global::CreateSpecificPlanArgs;
7-
use crate::plan::global::GcStatus;
87
use crate::plan::AllocationSemantics;
98
use crate::plan::Plan;
109
use crate::plan::PlanConstraints;
@@ -73,8 +72,6 @@ impl<VM: VMBinding> Plan for Immix<VM> {
7372
}
7473

7574
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
76-
self.base().set_collection_kind::<Self>(self);
77-
self.base().set_gc_status(GcStatus::GcPrepare);
7875
Self::schedule_immix_full_heap_collection::<
7976
Immix<VM>,
8077
ImmixGCWorkContext<VM, TRACE_KIND_FAST>,

src/plan/markcompact/global.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::gc_work::{
44
UpdateReferences,
55
};
66
use crate::plan::global::CommonPlan;
7-
use crate::plan::global::GcStatus;
87
use crate::plan::global::{BasePlan, CreateGeneralPlanArgs, CreateSpecificPlanArgs};
98
use crate::plan::markcompact::mutator::ALLOCATOR_MAPPING;
109
use crate::plan::AllocationSemantics;
@@ -80,9 +79,6 @@ impl<VM: VMBinding> Plan for MarkCompact<VM> {
8079
}
8180

8281
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
83-
self.base().set_collection_kind::<Self>(self);
84-
self.base().set_gc_status(GcStatus::GcPrepare);
85-
8682
// TODO use schedule_common once it can work with markcompact
8783
// self.common()
8884
// .schedule_common::<Self, MarkingProcessEdges<VM>, NoCopy<VM>>(

src/plan/marksweep/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::plan::global::BasePlan;
22
use crate::plan::global::CommonPlan;
33
use crate::plan::global::CreateGeneralPlanArgs;
44
use crate::plan::global::CreateSpecificPlanArgs;
5-
use crate::plan::global::GcStatus;
65
use crate::plan::marksweep::gc_work::MSGCWorkContext;
76
use crate::plan::marksweep::mutator::ALLOCATOR_MAPPING;
87
use crate::plan::AllocationSemantics;
@@ -50,8 +49,6 @@ pub const MS_CONSTRAINTS: PlanConstraints = PlanConstraints {
5049

5150
impl<VM: VMBinding> Plan for MarkSweep<VM> {
5251
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
53-
self.base().set_collection_kind::<Self>(self);
54-
self.base().set_gc_status(GcStatus::GcPrepare);
5552
scheduler.schedule_common_work::<MSGCWorkContext<VM>>(self);
5653
}
5754

src/plan/pageprotect/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::gc_work::PPGCWorkContext;
22
use super::mutator::ALLOCATOR_MAPPING;
33
use crate::plan::global::CreateGeneralPlanArgs;
44
use crate::plan::global::CreateSpecificPlanArgs;
5-
use crate::plan::global::GcStatus;
65
use crate::plan::AllocationSemantics;
76
use crate::plan::Plan;
87
use crate::plan::PlanConstraints;
@@ -40,8 +39,6 @@ impl<VM: VMBinding> Plan for PageProtect<VM> {
4039
}
4140

4241
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
43-
self.base().set_collection_kind::<Self>(self);
44-
self.base().set_gc_status(GcStatus::GcPrepare);
4542
scheduler.schedule_common_work::<PPGCWorkContext<VM>>(self);
4643
}
4744

src/plan/semispace/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::gc_work::SSGCWorkContext;
22
use crate::plan::global::CommonPlan;
33
use crate::plan::global::CreateGeneralPlanArgs;
44
use crate::plan::global::CreateSpecificPlanArgs;
5-
use crate::plan::global::GcStatus;
65
use crate::plan::semispace::mutator::ALLOCATOR_MAPPING;
76
use crate::plan::AllocationSemantics;
87
use crate::plan::Plan;
@@ -67,8 +66,6 @@ impl<VM: VMBinding> Plan for SemiSpace<VM> {
6766
}
6867

6968
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
70-
self.base().set_collection_kind::<Self>(self);
71-
self.base().set_gc_status(GcStatus::GcPrepare);
7269
scheduler.schedule_common_work::<SSGCWorkContext<VM>>(self);
7370
}
7471

src/plan/sticky/immix/global.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::plan::global::CommonPlan;
33
use crate::plan::global::CreateGeneralPlanArgs;
44
use crate::plan::global::CreateSpecificPlanArgs;
55
use crate::plan::immix;
6-
use crate::plan::GcStatus;
76
use crate::plan::PlanConstraints;
87
use crate::policy::immix::ImmixSpace;
98
use crate::policy::sft::SFT;
@@ -80,9 +79,6 @@ impl<VM: VMBinding> Plan for StickyImmix<VM> {
8079
}
8180

8281
fn schedule_collection(&'static self, scheduler: &crate::scheduler::GCWorkScheduler<Self::VM>) {
83-
self.base().set_collection_kind::<Self>(self);
84-
self.base().set_gc_status(GcStatus::GcPrepare);
85-
8682
let is_full_heap = self.requires_full_heap_collection();
8783
self.gc_full_heap.store(is_full_heap, Ordering::SeqCst);
8884

0 commit comments

Comments
 (0)