Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract set_collection_kind and set_gc_status #957

Merged
merged 4 commits into from
Oct 16, 2023
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
3 changes: 0 additions & 3 deletions docs/userguide/src/tutorial/code/mygc_semispace/global.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ANCHOR: imports_no_gc_work
use crate::plan::global::BasePlan; //Modify
use crate::plan::global::CommonPlan; // Add
use crate::plan::global::GcStatus; // Add
use crate::plan::global::{CreateGeneralPlanArgs, CreateSpecificPlanArgs};
use crate::plan::mygc::mutator::ALLOCATOR_MAPPING;
use crate::plan::mygc::gc_work::MyGCWorkContext;
Expand Down Expand Up @@ -77,8 +76,6 @@ impl<VM: VMBinding> Plan for MyGC<VM> {
// Modify
// ANCHOR: schedule_collection
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);
scheduler.schedule_common_work::<MyGCWorkContext<VM>>(self);
}
// ANCHOR_END: schedule_collection
Expand Down
3 changes: 0 additions & 3 deletions src/plan/generational/copying/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::plan::global::BasePlan;
use crate::plan::global::CommonPlan;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::global::GcStatus;
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
use crate::plan::PlanConstraints;
Expand Down Expand Up @@ -73,8 +72,6 @@ impl<VM: VMBinding> Plan for GenCopy<VM> {

fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
let is_full_heap = self.requires_full_heap_collection();
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);
if is_full_heap {
scheduler.schedule_common_work::<GenCopyGCWorkContext<VM>>(self);
} else {
Expand Down
5 changes: 0 additions & 5 deletions src/plan/generational/immix/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::plan::global::BasePlan;
use crate::plan::global::CommonPlan;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::global::GcStatus;
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
use crate::plan::PlanConstraints;
Expand Down Expand Up @@ -104,10 +103,6 @@ impl<VM: VMBinding> Plan for GenImmix<VM> {
#[allow(clippy::branches_sharing_code)]
fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<Self::VM>) {
let is_full_heap = self.requires_full_heap_collection();

self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);

if !is_full_heap {
debug!("Nursery GC");
scheduler.schedule_common_work::<GenImmixNurseryGCWorkContext<VM>>(self);
Expand Down
2 changes: 1 addition & 1 deletion src/plan/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ impl<VM: VMBinding> BasePlan<VM> {
self.vm_space.release();
}

pub fn set_collection_kind<P: Plan>(&self, plan: &P) {
pub fn set_collection_kind(&self, plan: &dyn Plan<VM = VM>) {
self.cur_collection_attempts.store(
if self.is_user_triggered_collection() {
1
Expand Down
3 changes: 0 additions & 3 deletions src/plan/immix/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::plan::global::BasePlan;
use crate::plan::global::CommonPlan;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::global::GcStatus;
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
use crate::plan::PlanConstraints;
Expand Down Expand Up @@ -73,8 +72,6 @@ impl<VM: VMBinding> Plan for Immix<VM> {
}

fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);
Self::schedule_immix_full_heap_collection::<
Immix<VM>,
ImmixGCWorkContext<VM, TRACE_KIND_FAST>,
Expand Down
4 changes: 0 additions & 4 deletions src/plan/markcompact/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::gc_work::{
UpdateReferences,
};
use crate::plan::global::CommonPlan;
use crate::plan::global::GcStatus;
use crate::plan::global::{BasePlan, CreateGeneralPlanArgs, CreateSpecificPlanArgs};
use crate::plan::markcompact::mutator::ALLOCATOR_MAPPING;
use crate::plan::AllocationSemantics;
Expand Down Expand Up @@ -80,9 +79,6 @@ impl<VM: VMBinding> Plan for MarkCompact<VM> {
}

fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);

// TODO use schedule_common once it can work with markcompact
// self.common()
// .schedule_common::<Self, MarkingProcessEdges<VM>, NoCopy<VM>>(
Expand Down
3 changes: 0 additions & 3 deletions src/plan/marksweep/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::plan::global::BasePlan;
use crate::plan::global::CommonPlan;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::global::GcStatus;
use crate::plan::marksweep::gc_work::MSGCWorkContext;
use crate::plan::marksweep::mutator::ALLOCATOR_MAPPING;
use crate::plan::AllocationSemantics;
Expand Down Expand Up @@ -50,8 +49,6 @@ pub const MS_CONSTRAINTS: PlanConstraints = PlanConstraints {

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

Expand Down
3 changes: 0 additions & 3 deletions src/plan/pageprotect/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::gc_work::PPGCWorkContext;
use super::mutator::ALLOCATOR_MAPPING;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::global::GcStatus;
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
use crate::plan::PlanConstraints;
Expand Down Expand Up @@ -40,8 +39,6 @@ impl<VM: VMBinding> Plan for PageProtect<VM> {
}

fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);
scheduler.schedule_common_work::<PPGCWorkContext<VM>>(self);
}

Expand Down
3 changes: 0 additions & 3 deletions src/plan/semispace/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::gc_work::SSGCWorkContext;
use crate::plan::global::CommonPlan;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::global::GcStatus;
use crate::plan::semispace::mutator::ALLOCATOR_MAPPING;
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
Expand Down Expand Up @@ -67,8 +66,6 @@ impl<VM: VMBinding> Plan for SemiSpace<VM> {
}

fn schedule_collection(&'static self, scheduler: &GCWorkScheduler<VM>) {
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);
scheduler.schedule_common_work::<SSGCWorkContext<VM>>(self);
}

Expand Down
4 changes: 0 additions & 4 deletions src/plan/sticky/immix/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::plan::global::CommonPlan;
use crate::plan::global::CreateGeneralPlanArgs;
use crate::plan::global::CreateSpecificPlanArgs;
use crate::plan::immix;
use crate::plan::GcStatus;
use crate::plan::PlanConstraints;
use crate::policy::immix::ImmixSpace;
use crate::policy::sft::SFT;
Expand Down Expand Up @@ -80,9 +79,6 @@ impl<VM: VMBinding> Plan for StickyImmix<VM> {
}

fn schedule_collection(&'static self, scheduler: &crate::scheduler::GCWorkScheduler<Self::VM>) {
self.base().set_collection_kind::<Self>(self);
self.base().set_gc_status(GcStatus::GcPrepare);

let is_full_heap = self.requires_full_heap_collection();
self.gc_full_heap.store(is_full_heap, Ordering::SeqCst);

Expand Down
14 changes: 7 additions & 7 deletions src/scheduler/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ pub struct ScheduleCollection;

impl<VM: VMBinding> GCWork<VM> for ScheduleCollection {
fn do_work(&mut self, worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM>) {
mmtk.get_plan().schedule_collection(worker.scheduler());

let plan = mmtk.get_plan();
// Tell GC trigger that GC started.
// We now know what kind of GC this is (e.g. nursery vs mature in gen copy, defrag vs fast in Immix)
// TODO: Depending on the OS scheduling, other workers can run so fast that they can finish
// everything in the `Unconstrained` and the `Prepare` buckets before we execute the next
// statement. Consider if there is a better place to call `on_gc_start`.
mmtk.get_plan().base().gc_trigger.policy.on_gc_start(mmtk);
plan.base().gc_trigger.policy.on_gc_start(mmtk);

plan.base().set_collection_kind(plan);
plan.base().set_gc_status(GcStatus::GcPrepare);

plan.schedule_collection(worker.scheduler());
}
}

Expand Down