From 7049c26bb0a2f4de31b2e4d1d35dd81e5bd48e78 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Mon, 15 Apr 2024 16:49:25 +0800 Subject: [PATCH 1/4] Rename associated types in GCWorkContext This PR renames `ProcessEdgesWorkType` to `NormalProcessEdges`, and renames `TPProcessEdges` to `PinningProcessEdges`. The old name `TPProcessEdges` was very confusing because the type alone is not sufficient to implement transitive pinning roots. We rename it to PinningProcessEdges, removing "transitive" from its name. We also renamed `ProcessEdgesWorkType` to `NormalProcessEdges` for symmetry. FYI, non-transitive and transitive pinning roots are implemented using a combination of `NormalProcessEdges` and `PinningProcessEdges`. - We use `PinningProcessEdges` for objects directly pointed from non-transitive pinning roots, but `NormalProcessEdges` for their descendents. - We use `PinningProcessEdges` to trace all objects reachable from transitive pinning roots. --- .../tutorial/code/mygc_semispace/gc_work.rs | 12 ++++----- .../src/tutorial/mygc/ss/collection.md | 4 +-- src/plan/generational/copying/gc_work.rs | 8 +++--- src/plan/generational/immix/gc_work.rs | 8 +++--- src/plan/immix/gc_work.rs | 4 +-- src/plan/markcompact/gc_work.rs | 8 +++--- src/plan/marksweep/gc_work.rs | 4 +-- src/plan/pageprotect/gc_work.rs | 4 +-- src/plan/semispace/gc_work.rs | 4 +-- src/plan/sticky/immix/gc_work.rs | 8 +++--- src/scheduler/gc_work.rs | 8 +++--- src/scheduler/scheduler.rs | 16 ++++++------ src/scheduler/work.rs | 26 ++++++++++++++++--- 13 files changed, 67 insertions(+), 47 deletions(-) diff --git a/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs b/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs index a4818fbbe4..8df5640af2 100644 --- a/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs +++ b/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs @@ -10,8 +10,8 @@ pub struct MyGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MyGCWorkContext { type VM = VM; type PlanType = MyGC; - type ProcessEdgesWorkType = SFTProcessEdges; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = SFTProcessEdges; + type PinningProcessEdges = UnsupportedProcessEdges; } // ANCHOR_END: workcontext_sft @@ -22,8 +22,8 @@ pub struct MyGCWorkContext2(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MyGCWorkContext2 { type VM = VM; type PlanType = MyGC; - type ProcessEdgesWorkType = PlanProcessEdges, DEFAULT_TRACE>; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type PinningProcessEdges = UnsupportedProcessEdges; } // ANCHOR_END: workcontext_plan @@ -104,7 +104,7 @@ pub struct MyGCWorkContext3(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MyGCWorkContext3 { type VM = VM; type PlanType = MyGC; - type ProcessEdgesWorkType = MyGCProcessEdges; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = MyGCProcessEdges; + type PinningProcessEdges = UnsupportedProcessEdges; } // ANCHOR: workcontext_mygc diff --git a/docs/userguide/src/tutorial/mygc/ss/collection.md b/docs/userguide/src/tutorial/mygc/ss/collection.md index c0a66256e1..e3fb4324ac 100644 --- a/docs/userguide/src/tutorial/mygc/ss/collection.md +++ b/docs/userguide/src/tutorial/mygc/ss/collection.md @@ -202,7 +202,7 @@ With the derive macro, your `MyGC` struct should look like this: {{#include ../../code/mygc_semispace/global.rs:plan_def}} ``` -Once this is done, you can specify `PlanProcessEdges` as the `ProcessEdgesWorkType` in your GC work context: +Once this is done, you can specify `PlanProcessEdges` as the `NormalProcessEdges` in your GC work context: ```rust {{#include ../../code/mygc_semispace/gc_work.rs:workcontext_plan}} ``` @@ -238,7 +238,7 @@ dereferenced as `ProcessEdgesBase`. {{#include ../../code/mygc_semispace/gc_work.rs:mygc_process_edges_deref}} ``` -In the end, use `MyGCProcessEdges` as `ProcessEdgesWorkType` in the `GCWorkContext`: +In the end, use `MyGCProcessEdges` as `NormalProcessEdges` in the `GCWorkContext`: ```rust {{#include ../../code/mygc_semispace/gc_work.rs:workcontext_mygc}} ``` diff --git a/src/plan/generational/copying/gc_work.rs b/src/plan/generational/copying/gc_work.rs index 226ddab715..f873b5e357 100644 --- a/src/plan/generational/copying/gc_work.rs +++ b/src/plan/generational/copying/gc_work.rs @@ -9,14 +9,14 @@ pub struct GenCopyNurseryGCWorkContext(std::marker::PhantomData crate::scheduler::GCWorkContext for GenCopyNurseryGCWorkContext { type VM = VM; type PlanType = GenCopy; - type ProcessEdgesWorkType = GenNurseryProcessEdges; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = GenNurseryProcessEdges; + type PinningProcessEdges = UnsupportedProcessEdges; } pub struct GenCopyGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for GenCopyGCWorkContext { type VM = VM; type PlanType = GenCopy; - type ProcessEdgesWorkType = PlanProcessEdges, DEFAULT_TRACE>; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/generational/immix/gc_work.rs b/src/plan/generational/immix/gc_work.rs index 14f46a0958..64e85bbe6f 100644 --- a/src/plan/generational/immix/gc_work.rs +++ b/src/plan/generational/immix/gc_work.rs @@ -9,8 +9,8 @@ pub struct GenImmixNurseryGCWorkContext(std::marker::PhantomData< impl crate::scheduler::GCWorkContext for GenImmixNurseryGCWorkContext { type VM = VM; type PlanType = GenImmix; - type ProcessEdgesWorkType = GenNurseryProcessEdges; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = GenNurseryProcessEdges; + type PinningProcessEdges = UnsupportedProcessEdges; } pub(super) struct GenImmixMatureGCWorkContext( @@ -21,6 +21,6 @@ impl crate::scheduler::GCWorkContext { type VM = VM; type PlanType = GenImmix; - type ProcessEdgesWorkType = PlanProcessEdges, KIND>; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = PlanProcessEdges, KIND>; + type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/immix/gc_work.rs b/src/plan/immix/gc_work.rs index e3200f8811..273b9c1273 100644 --- a/src/plan/immix/gc_work.rs +++ b/src/plan/immix/gc_work.rs @@ -12,6 +12,6 @@ impl crate::scheduler::GCWorkContext { type VM = VM; type PlanType = Immix; - type ProcessEdgesWorkType = PlanProcessEdges, KIND>; - type TPProcessEdges = PlanProcessEdges, TRACE_KIND_TRANSITIVE_PIN>; + type NormalProcessEdges = PlanProcessEdges, KIND>; + type PinningProcessEdges = PlanProcessEdges, TRACE_KIND_TRANSITIVE_PIN>; } diff --git a/src/plan/markcompact/gc_work.rs b/src/plan/markcompact/gc_work.rs index 4b60cafa9b..07fdaaf636 100644 --- a/src/plan/markcompact/gc_work.rs +++ b/src/plan/markcompact/gc_work.rs @@ -102,14 +102,14 @@ pub struct MarkCompactGCWorkContext(std::marker::PhantomData) impl crate::scheduler::GCWorkContext for MarkCompactGCWorkContext { type VM = VM; type PlanType = MarkCompact; - type ProcessEdgesWorkType = MarkingProcessEdges; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = MarkingProcessEdges; + type PinningProcessEdges = UnsupportedProcessEdges; } pub struct MarkCompactForwardingGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MarkCompactForwardingGCWorkContext { type VM = VM; type PlanType = MarkCompact; - type ProcessEdgesWorkType = ForwardingProcessEdges; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = ForwardingProcessEdges; + type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/marksweep/gc_work.rs b/src/plan/marksweep/gc_work.rs index 604e355759..e0038e76b1 100644 --- a/src/plan/marksweep/gc_work.rs +++ b/src/plan/marksweep/gc_work.rs @@ -7,6 +7,6 @@ pub struct MSGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MSGCWorkContext { type VM = VM; type PlanType = MarkSweep; - type ProcessEdgesWorkType = PlanProcessEdges, DEFAULT_TRACE>; - type TPProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type PinningProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; } diff --git a/src/plan/pageprotect/gc_work.rs b/src/plan/pageprotect/gc_work.rs index 4e68c4afb2..bdb3e4af2b 100644 --- a/src/plan/pageprotect/gc_work.rs +++ b/src/plan/pageprotect/gc_work.rs @@ -7,6 +7,6 @@ pub struct PPGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for PPGCWorkContext { type VM = VM; type PlanType = PageProtect; - type ProcessEdgesWorkType = PlanProcessEdges, DEFAULT_TRACE>; - type TPProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type PinningProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; } diff --git a/src/plan/semispace/gc_work.rs b/src/plan/semispace/gc_work.rs index 1d4e633c36..c62a8f1be1 100644 --- a/src/plan/semispace/gc_work.rs +++ b/src/plan/semispace/gc_work.rs @@ -7,6 +7,6 @@ pub struct SSGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for SSGCWorkContext { type VM = VM; type PlanType = SemiSpace; - type ProcessEdgesWorkType = PlanProcessEdges, DEFAULT_TRACE>; - type TPProcessEdges = UnsupportedProcessEdges; + type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/sticky/immix/gc_work.rs b/src/plan/sticky/immix/gc_work.rs index 3c7b6f973a..93dfefef08 100644 --- a/src/plan/sticky/immix/gc_work.rs +++ b/src/plan/sticky/immix/gc_work.rs @@ -9,8 +9,8 @@ pub struct StickyImmixNurseryGCWorkContext(std::marker::PhantomDa impl crate::scheduler::GCWorkContext for StickyImmixNurseryGCWorkContext { type VM = VM; type PlanType = StickyImmix; - type ProcessEdgesWorkType = GenNurseryProcessEdges; - type TPProcessEdges = GenNurseryProcessEdges; + type NormalProcessEdges = GenNurseryProcessEdges; + type PinningProcessEdges = GenNurseryProcessEdges; } pub struct StickyImmixMatureGCWorkContext( @@ -21,6 +21,6 @@ impl crate::scheduler::GCWorkContext { type VM = VM; type PlanType = StickyImmix; - type ProcessEdgesWorkType = PlanProcessEdges; - type TPProcessEdges = PlanProcessEdges; + type NormalProcessEdges = PlanProcessEdges; + type PinningProcessEdges = PlanProcessEdges; } diff --git a/src/scheduler/gc_work.rs b/src/scheduler/gc_work.rs index e12910a5fc..57d9b28cd7 100644 --- a/src/scheduler/gc_work.rs +++ b/src/scheduler/gc_work.rs @@ -401,8 +401,8 @@ impl GCWork for ScanMutatorRoots { let mutators = ::VMActivePlan::number_of_mutators(); let factory = ProcessEdgesWorkRootsWorkFactory::< C::VM, - C::ProcessEdgesWorkType, - C::TPProcessEdges, + C::NormalProcessEdges, + C::PinningProcessEdges, >::new(mmtk); ::VMScanning::scan_roots_in_mutator_thread( worker.tls, @@ -434,8 +434,8 @@ impl GCWork for ScanVMSpecificRoots { trace!("ScanStaticRoots"); let factory = ProcessEdgesWorkRootsWorkFactory::< C::VM, - C::ProcessEdgesWorkType, - C::TPProcessEdges, + C::NormalProcessEdges, + C::PinningProcessEdges, >::new(mmtk); ::VMScanning::scan_vm_specific_roots(worker.tls, factory); } diff --git a/src/scheduler/scheduler.rs b/src/scheduler/scheduler.rs index bc310bf482..19dc56e883 100644 --- a/src/scheduler/scheduler.rs +++ b/src/scheduler/scheduler.rs @@ -171,16 +171,16 @@ impl GCWorkScheduler { PhantomRefProcessing, SoftRefProcessing, WeakRefProcessing, }; self.work_buckets[WorkBucketStage::SoftRefClosure] - .add(SoftRefProcessing::::new()); + .add(SoftRefProcessing::::new()); self.work_buckets[WorkBucketStage::WeakRefClosure] - .add(WeakRefProcessing::::new()); + .add(WeakRefProcessing::::new()); self.work_buckets[WorkBucketStage::PhantomRefClosure] - .add(PhantomRefProcessing::::new()); + .add(PhantomRefProcessing::::new()); use crate::util::reference_processor::RefForwarding; if plan.constraints().needs_forward_after_liveness { self.work_buckets[WorkBucketStage::RefForwarding] - .add(RefForwarding::::new()); + .add(RefForwarding::::new()); } use crate::util::reference_processor::RefEnqueue; @@ -192,11 +192,11 @@ impl GCWorkScheduler { use crate::util::finalizable_processor::{Finalization, ForwardFinalization}; // finalization self.work_buckets[WorkBucketStage::FinalRefClosure] - .add(Finalization::::new()); + .add(Finalization::::new()); // forward refs if plan.constraints().needs_forward_after_liveness { self.work_buckets[WorkBucketStage::FinalizableForwarding] - .add(ForwardFinalization::::new()); + .add(ForwardFinalization::::new()); } } @@ -222,12 +222,12 @@ impl GCWorkScheduler { // because there are no other packets in the bucket. We set it as sentinel for // consistency. self.work_buckets[WorkBucketStage::VMRefClosure] - .set_sentinel(Box::new(VMProcessWeakRefs::::new())); + .set_sentinel(Box::new(VMProcessWeakRefs::::new())); if plan.constraints().needs_forward_after_liveness { // VM-specific weak ref forwarding self.work_buckets[WorkBucketStage::VMRefForwarding] - .add(VMForwardWeakRefs::::new()); + .add(VMForwardWeakRefs::::new()); } self.work_buckets[WorkBucketStage::Release].add(VMPostForwarding::::default()); diff --git a/src/scheduler/work.rs b/src/scheduler/work.rs index a866cd2230..04c35a7a40 100644 --- a/src/scheduler/work.rs +++ b/src/scheduler/work.rs @@ -74,8 +74,28 @@ use crate::plan::Plan; pub trait GCWorkContext: Send + 'static { type VM: VMBinding; type PlanType: Plan; - // We should use SFTProcessEdges as the default value for this associate type. However, this requires + + // FIXME: We should use `SFTProcessEdges` as the default value for `NormalProcessEdges`, and + // `UnsupportedProcessEdges` for `PinningProcessEdges`. However, this requires // `associated_type_defaults` which has not yet been stablized. - type ProcessEdgesWorkType: ProcessEdgesWork; - type TPProcessEdges: ProcessEdgesWork; + // See: https://github.com/rust-lang/rust/issues/29661 + + /// The `ProcessEdgesWork` implementation to use for tracing edges that do not have special + /// pinning requirements. Concrete plans and spaces may choose to move or not to move the + /// objects the traced edges point to. + type NormalProcessEdges: ProcessEdgesWork; + + /// The `ProcessEdgesWork` implementation to use for trcing edges that must not be updated + /// (i.e. the objects the traced edges pointed to must not be moved). This is used for + /// implementing pinning roots and transitive pinning roots. + /// + /// - For non-transitive pinning roots, `PinningProcessEdges` will be used to trace the edges + /// from roots to objects, but their descendents will be traced using `NormalProcessEdges`. + /// - For transitive pinning roots, `PinningProcessEdges` will be used to trace the edges + /// from roots to objects, and the outgoing edges of all objects reachable from transitive + /// pinning roots. + /// + /// If a plan does not support object pinning, it should use `UnsupportedProcessEdges` for this + /// type member. + type PinningProcessEdges: ProcessEdgesWork; } From 75060f3694ccbb6a4fe0ab58ef1e7067a57ed997 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Mon, 15 Apr 2024 17:31:01 +0800 Subject: [PATCH 2/4] Also update type parameters of some work packets. --- src/scheduler/gc_work.rs | 67 ++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/scheduler/gc_work.rs b/src/scheduler/gc_work.rs index 57d9b28cd7..41801d2fff 100644 --- a/src/scheduler/gc_work.rs +++ b/src/scheduler/gc_work.rs @@ -683,15 +683,15 @@ impl ProcessEdgesWork for SFTProcessEdges { } pub(crate) struct ProcessEdgesWorkRootsWorkFactory< VM: VMBinding, - E: ProcessEdgesWork, - I: ProcessEdgesWork, + NPE: ProcessEdgesWork, + PPE: ProcessEdgesWork, > { mmtk: &'static MMTK, - phantom: PhantomData<(E, I)>, + phantom: PhantomData<(NPE, PPE)>, } -impl, I: ProcessEdgesWork> Clone - for ProcessEdgesWorkRootsWorkFactory +impl, PPE: ProcessEdgesWork> Clone + for ProcessEdgesWorkRootsWorkFactory { fn clone(&self) -> Self { Self { @@ -701,14 +701,14 @@ impl, I: ProcessEdgesWork> } } -impl, I: ProcessEdgesWork> - RootsWorkFactory> for ProcessEdgesWorkRootsWorkFactory +impl, PPE: ProcessEdgesWork> + RootsWorkFactory for ProcessEdgesWorkRootsWorkFactory { - fn create_process_edge_roots_work(&mut self, edges: Vec>) { + fn create_process_edge_roots_work(&mut self, edges: Vec) { crate::memory_manager::add_work_packet( self.mmtk, WorkBucketStage::Closure, - E::new(edges, true, self.mmtk, WorkBucketStage::Closure), + NPE::new(edges, true, self.mmtk, WorkBucketStage::Closure), ); } @@ -718,7 +718,7 @@ impl, I: ProcessEdgesWork> crate::memory_manager::add_work_packet( self.mmtk, WorkBucketStage::PinningRootsTrace, - ProcessRootNode::::new(nodes, WorkBucketStage::Closure), + ProcessRootNode::::new(nodes, WorkBucketStage::Closure), ); } @@ -726,13 +726,13 @@ impl, I: ProcessEdgesWork> crate::memory_manager::add_work_packet( self.mmtk, WorkBucketStage::TPinningClosure, - ProcessRootNode::::new(nodes, WorkBucketStage::TPinningClosure), + ProcessRootNode::::new(nodes, WorkBucketStage::TPinningClosure), ); } } -impl, I: ProcessEdgesWork> - ProcessEdgesWorkRootsWorkFactory +impl, PPE: ProcessEdgesWork> + ProcessEdgesWorkRootsWorkFactory { fn new(mmtk: &'static MMTK) -> Self { Self { @@ -1015,22 +1015,37 @@ impl + PlanTraceObject> GCWork` work packet +/// will only pin the objects in `roots` (because `R2OPE` must not move objects anyway), but +/// not their descendents. pub(crate) struct ProcessRootNode< VM: VMBinding, - I: ProcessEdgesWork, - E: ProcessEdgesWork, + R2OPE: ProcessEdgesWork, + O2OPE: ProcessEdgesWork, > { - phantom: PhantomData<(VM, I, E)>, + phantom: PhantomData<(VM, R2OPE, O2OPE)>, roots: Vec, bucket: WorkBucketStage, } -impl, E: ProcessEdgesWork> - ProcessRootNode +impl, O2OPE: ProcessEdgesWork> + ProcessRootNode { pub fn new(nodes: Vec, bucket: WorkBucketStage) -> Self { Self { @@ -1041,8 +1056,8 @@ impl, E: ProcessEdgesWork> } } -impl, E: ProcessEdgesWork> GCWork - for ProcessRootNode +impl, O2OPE: ProcessEdgesWork> GCWork + for ProcessRootNode { fn do_work(&mut self, worker: &mut GCWorker, mmtk: &'static MMTK) { trace!("ProcessRootNode"); @@ -1069,7 +1084,7 @@ impl, E: ProcessEdgesWork> let scanned_root_objects = { // We create an instance of E to use its `trace_object` method and its object queue. let mut process_edges_work = - I::new(vec![], true, mmtk, WorkBucketStage::PinningRootsTrace); + R2OPE::new(vec![], true, mmtk, WorkBucketStage::PinningRootsTrace); process_edges_work.set_worker(worker); for object in self.roots.iter().copied() { @@ -1086,7 +1101,7 @@ impl, E: ProcessEdgesWork> process_edges_work.nodes.take() }; - let process_edges_work = E::new(vec![], false, mmtk, self.bucket); + let process_edges_work = O2OPE::new(vec![], false, mmtk, self.bucket); let work = process_edges_work.create_scan_work(scanned_root_objects); crate::memory_manager::add_work_packet(mmtk, self.bucket, work); From 263315cfb05d6e291cf0da7cdbebe48ae5fbb905 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Tue, 16 Apr 2024 12:28:51 +0800 Subject: [PATCH 3/4] NormalProcessEdges -> DefaultProcessEdges --- .../tutorial/code/mygc_semispace/gc_work.rs | 6 ++-- .../src/tutorial/mygc/ss/collection.md | 4 +-- src/plan/generational/copying/gc_work.rs | 4 +-- src/plan/generational/immix/gc_work.rs | 4 +-- src/plan/immix/gc_work.rs | 2 +- src/plan/markcompact/gc_work.rs | 4 +-- src/plan/marksweep/gc_work.rs | 2 +- src/plan/pageprotect/gc_work.rs | 2 +- src/plan/semispace/gc_work.rs | 2 +- src/plan/sticky/immix/gc_work.rs | 4 +-- src/scheduler/gc_work.rs | 29 +++++++++++-------- src/scheduler/scheduler.rs | 16 +++++----- src/scheduler/work.rs | 12 ++++---- 13 files changed, 48 insertions(+), 43 deletions(-) diff --git a/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs b/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs index 8df5640af2..4394bbd369 100644 --- a/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs +++ b/docs/userguide/src/tutorial/code/mygc_semispace/gc_work.rs @@ -10,7 +10,7 @@ pub struct MyGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MyGCWorkContext { type VM = VM; type PlanType = MyGC; - type NormalProcessEdges = SFTProcessEdges; + type DefaultProcessEdges = SFTProcessEdges; type PinningProcessEdges = UnsupportedProcessEdges; } // ANCHOR_END: workcontext_sft @@ -22,7 +22,7 @@ pub struct MyGCWorkContext2(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MyGCWorkContext2 { type VM = VM; type PlanType = MyGC; - type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type DefaultProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; type PinningProcessEdges = UnsupportedProcessEdges; } // ANCHOR_END: workcontext_plan @@ -104,7 +104,7 @@ pub struct MyGCWorkContext3(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MyGCWorkContext3 { type VM = VM; type PlanType = MyGC; - type NormalProcessEdges = MyGCProcessEdges; + type DefaultProcessEdges = MyGCProcessEdges; type PinningProcessEdges = UnsupportedProcessEdges; } // ANCHOR: workcontext_mygc diff --git a/docs/userguide/src/tutorial/mygc/ss/collection.md b/docs/userguide/src/tutorial/mygc/ss/collection.md index e3fb4324ac..758022349d 100644 --- a/docs/userguide/src/tutorial/mygc/ss/collection.md +++ b/docs/userguide/src/tutorial/mygc/ss/collection.md @@ -202,7 +202,7 @@ With the derive macro, your `MyGC` struct should look like this: {{#include ../../code/mygc_semispace/global.rs:plan_def}} ``` -Once this is done, you can specify `PlanProcessEdges` as the `NormalProcessEdges` in your GC work context: +Once this is done, you can specify `PlanProcessEdges` as the `DefaultProcessEdges` in your GC work context: ```rust {{#include ../../code/mygc_semispace/gc_work.rs:workcontext_plan}} ``` @@ -238,7 +238,7 @@ dereferenced as `ProcessEdgesBase`. {{#include ../../code/mygc_semispace/gc_work.rs:mygc_process_edges_deref}} ``` -In the end, use `MyGCProcessEdges` as `NormalProcessEdges` in the `GCWorkContext`: +In the end, use `MyGCProcessEdges` as `DefaultProcessEdges` in the `GCWorkContext`: ```rust {{#include ../../code/mygc_semispace/gc_work.rs:workcontext_mygc}} ``` diff --git a/src/plan/generational/copying/gc_work.rs b/src/plan/generational/copying/gc_work.rs index f873b5e357..d0a2fb7f4e 100644 --- a/src/plan/generational/copying/gc_work.rs +++ b/src/plan/generational/copying/gc_work.rs @@ -9,7 +9,7 @@ pub struct GenCopyNurseryGCWorkContext(std::marker::PhantomData crate::scheduler::GCWorkContext for GenCopyNurseryGCWorkContext { type VM = VM; type PlanType = GenCopy; - type NormalProcessEdges = GenNurseryProcessEdges; + type DefaultProcessEdges = GenNurseryProcessEdges; type PinningProcessEdges = UnsupportedProcessEdges; } @@ -17,6 +17,6 @@ pub struct GenCopyGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for GenCopyGCWorkContext { type VM = VM; type PlanType = GenCopy; - type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type DefaultProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/generational/immix/gc_work.rs b/src/plan/generational/immix/gc_work.rs index 64e85bbe6f..dd9a38c0b3 100644 --- a/src/plan/generational/immix/gc_work.rs +++ b/src/plan/generational/immix/gc_work.rs @@ -9,7 +9,7 @@ pub struct GenImmixNurseryGCWorkContext(std::marker::PhantomData< impl crate::scheduler::GCWorkContext for GenImmixNurseryGCWorkContext { type VM = VM; type PlanType = GenImmix; - type NormalProcessEdges = GenNurseryProcessEdges; + type DefaultProcessEdges = GenNurseryProcessEdges; type PinningProcessEdges = UnsupportedProcessEdges; } @@ -21,6 +21,6 @@ impl crate::scheduler::GCWorkContext { type VM = VM; type PlanType = GenImmix; - type NormalProcessEdges = PlanProcessEdges, KIND>; + type DefaultProcessEdges = PlanProcessEdges, KIND>; type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/immix/gc_work.rs b/src/plan/immix/gc_work.rs index 273b9c1273..2ac7a25382 100644 --- a/src/plan/immix/gc_work.rs +++ b/src/plan/immix/gc_work.rs @@ -12,6 +12,6 @@ impl crate::scheduler::GCWorkContext { type VM = VM; type PlanType = Immix; - type NormalProcessEdges = PlanProcessEdges, KIND>; + type DefaultProcessEdges = PlanProcessEdges, KIND>; type PinningProcessEdges = PlanProcessEdges, TRACE_KIND_TRANSITIVE_PIN>; } diff --git a/src/plan/markcompact/gc_work.rs b/src/plan/markcompact/gc_work.rs index 07fdaaf636..a6a6371548 100644 --- a/src/plan/markcompact/gc_work.rs +++ b/src/plan/markcompact/gc_work.rs @@ -102,7 +102,7 @@ pub struct MarkCompactGCWorkContext(std::marker::PhantomData) impl crate::scheduler::GCWorkContext for MarkCompactGCWorkContext { type VM = VM; type PlanType = MarkCompact; - type NormalProcessEdges = MarkingProcessEdges; + type DefaultProcessEdges = MarkingProcessEdges; type PinningProcessEdges = UnsupportedProcessEdges; } @@ -110,6 +110,6 @@ pub struct MarkCompactForwardingGCWorkContext(std::marker::Phanto impl crate::scheduler::GCWorkContext for MarkCompactForwardingGCWorkContext { type VM = VM; type PlanType = MarkCompact; - type NormalProcessEdges = ForwardingProcessEdges; + type DefaultProcessEdges = ForwardingProcessEdges; type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/marksweep/gc_work.rs b/src/plan/marksweep/gc_work.rs index e0038e76b1..57033759ba 100644 --- a/src/plan/marksweep/gc_work.rs +++ b/src/plan/marksweep/gc_work.rs @@ -7,6 +7,6 @@ pub struct MSGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for MSGCWorkContext { type VM = VM; type PlanType = MarkSweep; - type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type DefaultProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; type PinningProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; } diff --git a/src/plan/pageprotect/gc_work.rs b/src/plan/pageprotect/gc_work.rs index bdb3e4af2b..8b7e95dec6 100644 --- a/src/plan/pageprotect/gc_work.rs +++ b/src/plan/pageprotect/gc_work.rs @@ -7,6 +7,6 @@ pub struct PPGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for PPGCWorkContext { type VM = VM; type PlanType = PageProtect; - type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type DefaultProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; type PinningProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; } diff --git a/src/plan/semispace/gc_work.rs b/src/plan/semispace/gc_work.rs index c62a8f1be1..d5771279ce 100644 --- a/src/plan/semispace/gc_work.rs +++ b/src/plan/semispace/gc_work.rs @@ -7,6 +7,6 @@ pub struct SSGCWorkContext(std::marker::PhantomData); impl crate::scheduler::GCWorkContext for SSGCWorkContext { type VM = VM; type PlanType = SemiSpace; - type NormalProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; + type DefaultProcessEdges = PlanProcessEdges, DEFAULT_TRACE>; type PinningProcessEdges = UnsupportedProcessEdges; } diff --git a/src/plan/sticky/immix/gc_work.rs b/src/plan/sticky/immix/gc_work.rs index 93dfefef08..2964725297 100644 --- a/src/plan/sticky/immix/gc_work.rs +++ b/src/plan/sticky/immix/gc_work.rs @@ -9,7 +9,7 @@ pub struct StickyImmixNurseryGCWorkContext(std::marker::PhantomDa impl crate::scheduler::GCWorkContext for StickyImmixNurseryGCWorkContext { type VM = VM; type PlanType = StickyImmix; - type NormalProcessEdges = GenNurseryProcessEdges; + type DefaultProcessEdges = GenNurseryProcessEdges; type PinningProcessEdges = GenNurseryProcessEdges; } @@ -21,6 +21,6 @@ impl crate::scheduler::GCWorkContext { type VM = VM; type PlanType = StickyImmix; - type NormalProcessEdges = PlanProcessEdges; + type DefaultProcessEdges = PlanProcessEdges; type PinningProcessEdges = PlanProcessEdges; } diff --git a/src/scheduler/gc_work.rs b/src/scheduler/gc_work.rs index 41801d2fff..dd507b9d05 100644 --- a/src/scheduler/gc_work.rs +++ b/src/scheduler/gc_work.rs @@ -401,7 +401,7 @@ impl GCWork for ScanMutatorRoots { let mutators = ::VMActivePlan::number_of_mutators(); let factory = ProcessEdgesWorkRootsWorkFactory::< C::VM, - C::NormalProcessEdges, + C::DefaultProcessEdges, C::PinningProcessEdges, >::new(mmtk); ::VMScanning::scan_roots_in_mutator_thread( @@ -434,7 +434,7 @@ impl GCWork for ScanVMSpecificRoots { trace!("ScanStaticRoots"); let factory = ProcessEdgesWorkRootsWorkFactory::< C::VM, - C::NormalProcessEdges, + C::DefaultProcessEdges, C::PinningProcessEdges, >::new(mmtk); ::VMScanning::scan_vm_specific_roots(worker.tls, factory); @@ -681,17 +681,22 @@ impl ProcessEdgesWork for SFTProcessEdges { ScanObjects::::new(nodes, false, self.bucket) } } + +/// An implementation of `RootsWorkFactory` that creates work packets based on `ProcessEdgesWork` +/// for handling roots. The `DPE` and the `PPE` type parameters correspond to the +/// `DefaultProcessEdge` and the `PinningProcessEdges` type members of the +/// [`GCWorkContext`](crate::scheduler::work::GCWorkContext) trait. pub(crate) struct ProcessEdgesWorkRootsWorkFactory< VM: VMBinding, - NPE: ProcessEdgesWork, + DPE: ProcessEdgesWork, PPE: ProcessEdgesWork, > { mmtk: &'static MMTK, - phantom: PhantomData<(NPE, PPE)>, + phantom: PhantomData<(DPE, PPE)>, } -impl, PPE: ProcessEdgesWork> Clone - for ProcessEdgesWorkRootsWorkFactory +impl, PPE: ProcessEdgesWork> Clone + for ProcessEdgesWorkRootsWorkFactory { fn clone(&self) -> Self { Self { @@ -701,14 +706,14 @@ impl, PPE: ProcessEdgesWork, PPE: ProcessEdgesWork> - RootsWorkFactory for ProcessEdgesWorkRootsWorkFactory +impl, PPE: ProcessEdgesWork> + RootsWorkFactory for ProcessEdgesWorkRootsWorkFactory { fn create_process_edge_roots_work(&mut self, edges: Vec) { crate::memory_manager::add_work_packet( self.mmtk, WorkBucketStage::Closure, - NPE::new(edges, true, self.mmtk, WorkBucketStage::Closure), + DPE::new(edges, true, self.mmtk, WorkBucketStage::Closure), ); } @@ -718,7 +723,7 @@ impl, PPE: ProcessEdgesWork::new(nodes, WorkBucketStage::Closure), + ProcessRootNode::::new(nodes, WorkBucketStage::Closure), ); } @@ -731,8 +736,8 @@ impl, PPE: ProcessEdgesWork, PPE: ProcessEdgesWork> - ProcessEdgesWorkRootsWorkFactory +impl, PPE: ProcessEdgesWork> + ProcessEdgesWorkRootsWorkFactory { fn new(mmtk: &'static MMTK) -> Self { Self { diff --git a/src/scheduler/scheduler.rs b/src/scheduler/scheduler.rs index 19dc56e883..8c754d6696 100644 --- a/src/scheduler/scheduler.rs +++ b/src/scheduler/scheduler.rs @@ -171,16 +171,16 @@ impl GCWorkScheduler { PhantomRefProcessing, SoftRefProcessing, WeakRefProcessing, }; self.work_buckets[WorkBucketStage::SoftRefClosure] - .add(SoftRefProcessing::::new()); + .add(SoftRefProcessing::::new()); self.work_buckets[WorkBucketStage::WeakRefClosure] - .add(WeakRefProcessing::::new()); + .add(WeakRefProcessing::::new()); self.work_buckets[WorkBucketStage::PhantomRefClosure] - .add(PhantomRefProcessing::::new()); + .add(PhantomRefProcessing::::new()); use crate::util::reference_processor::RefForwarding; if plan.constraints().needs_forward_after_liveness { self.work_buckets[WorkBucketStage::RefForwarding] - .add(RefForwarding::::new()); + .add(RefForwarding::::new()); } use crate::util::reference_processor::RefEnqueue; @@ -192,11 +192,11 @@ impl GCWorkScheduler { use crate::util::finalizable_processor::{Finalization, ForwardFinalization}; // finalization self.work_buckets[WorkBucketStage::FinalRefClosure] - .add(Finalization::::new()); + .add(Finalization::::new()); // forward refs if plan.constraints().needs_forward_after_liveness { self.work_buckets[WorkBucketStage::FinalizableForwarding] - .add(ForwardFinalization::::new()); + .add(ForwardFinalization::::new()); } } @@ -222,12 +222,12 @@ impl GCWorkScheduler { // because there are no other packets in the bucket. We set it as sentinel for // consistency. self.work_buckets[WorkBucketStage::VMRefClosure] - .set_sentinel(Box::new(VMProcessWeakRefs::::new())); + .set_sentinel(Box::new(VMProcessWeakRefs::::new())); if plan.constraints().needs_forward_after_liveness { // VM-specific weak ref forwarding self.work_buckets[WorkBucketStage::VMRefForwarding] - .add(VMForwardWeakRefs::::new()); + .add(VMForwardWeakRefs::::new()); } self.work_buckets[WorkBucketStage::Release].add(VMPostForwarding::::default()); diff --git a/src/scheduler/work.rs b/src/scheduler/work.rs index 04c35a7a40..c74506cae6 100644 --- a/src/scheduler/work.rs +++ b/src/scheduler/work.rs @@ -75,7 +75,7 @@ pub trait GCWorkContext: Send + 'static { type VM: VMBinding; type PlanType: Plan; - // FIXME: We should use `SFTProcessEdges` as the default value for `NormalProcessEdges`, and + // FIXME: We should use `SFTProcessEdges` as the default value for `DefaultProcessEdges`, and // `UnsupportedProcessEdges` for `PinningProcessEdges`. However, this requires // `associated_type_defaults` which has not yet been stablized. // See: https://github.com/rust-lang/rust/issues/29661 @@ -83,17 +83,17 @@ pub trait GCWorkContext: Send + 'static { /// The `ProcessEdgesWork` implementation to use for tracing edges that do not have special /// pinning requirements. Concrete plans and spaces may choose to move or not to move the /// objects the traced edges point to. - type NormalProcessEdges: ProcessEdgesWork; + type DefaultProcessEdges: ProcessEdgesWork; - /// The `ProcessEdgesWork` implementation to use for trcing edges that must not be updated + /// The `ProcessEdgesWork` implementation to use for tracing edges that must not be updated /// (i.e. the objects the traced edges pointed to must not be moved). This is used for /// implementing pinning roots and transitive pinning roots. /// /// - For non-transitive pinning roots, `PinningProcessEdges` will be used to trace the edges - /// from roots to objects, but their descendents will be traced using `NormalProcessEdges`. + /// from roots to objects, but their descendents will be traced using `DefaultProcessEdges`. /// - For transitive pinning roots, `PinningProcessEdges` will be used to trace the edges - /// from roots to objects, and the outgoing edges of all objects reachable from transitive - /// pinning roots. + /// from roots to objects, and will also be used to trace the outgoing edges of all objects + /// reachable from transitive pinning roots. /// /// If a plan does not support object pinning, it should use `UnsupportedProcessEdges` for this /// type member. From cd8ef77147e20b2726c5cd7db81c404bde904647 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Tue, 16 Apr 2024 13:24:22 +0800 Subject: [PATCH 4/4] Remove explicit target --- src/scheduler/gc_work.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scheduler/gc_work.rs b/src/scheduler/gc_work.rs index dd507b9d05..45cfd13715 100644 --- a/src/scheduler/gc_work.rs +++ b/src/scheduler/gc_work.rs @@ -684,8 +684,7 @@ impl ProcessEdgesWork for SFTProcessEdges { /// An implementation of `RootsWorkFactory` that creates work packets based on `ProcessEdgesWork` /// for handling roots. The `DPE` and the `PPE` type parameters correspond to the -/// `DefaultProcessEdge` and the `PinningProcessEdges` type members of the -/// [`GCWorkContext`](crate::scheduler::work::GCWorkContext) trait. +/// `DefaultProcessEdge` and the `PinningProcessEdges` type members of the [`GCWorkContext`] trait. pub(crate) struct ProcessEdgesWorkRootsWorkFactory< VM: VMBinding, DPE: ProcessEdgesWork,