Trait mmtk::scheduler::gc_work::ProcessEdgesWork
source · pub trait ProcessEdgesWork: Send + 'static + Sized + DerefMut + Deref<Target = ProcessEdgesBase<Self::VM>> {
type VM: VMBinding;
type ScanObjectsWorkType: ScanObjectsWork<Self::VM>;
const CAPACITY: usize = 4_096usize;
const OVERWRITE_REFERENCE: bool = true;
const SCAN_OBJECTS_IMMEDIATELY: bool = true;
// Required methods
fn new(
slots: Vec<<<Self as ProcessEdgesWork>::VM as VMBinding>::VMSlot>,
roots: bool,
mmtk: &'static MMTK<Self::VM>,
bucket: WorkBucketStage
) -> Self;
fn trace_object(&mut self, object: ObjectReference) -> ObjectReference;
fn create_scan_work(
&self,
nodes: Vec<ObjectReference>
) -> Self::ScanObjectsWorkType;
// Provided methods
fn cache_roots_for_sanity_gc(&mut self) { ... }
fn start_or_dispatch_scan_work(
&mut self,
work_packet: impl GCWork<Self::VM>
) { ... }
fn flush(&mut self) { ... }
fn process_slot(
&mut self,
slot: <<Self as ProcessEdgesWork>::VM as VMBinding>::VMSlot
) { ... }
fn process_slots(&mut self) { ... }
}
Expand description
An abstract trait for work packets that process object graph edges. Its method
ProcessEdgesWork::trace_object
traces an object and, upon first visit, enqueues it into an
internal queue inside the ProcessEdgesWork
instance. Each implementation of this trait
implement trace_object
differently. During Plan::schedule_collection
, plans select
(usually via GCWorkContext
) specialized implementations of this trait to be used during each
trace according the nature of each trace, such as whether it is a nursery collection, whether it
is a defrag collection, whether it pins objects, etc.
This trait was originally designed for work packets that process object graph edges represented
as slots. The constructor ProcessEdgesWork::new
takes a vector of slots, and the created
work packet will trace the objects pointed by the object reference in each slot using the
trace_object
method, and update the slot if the GC moves the target object when tracing.
This trait can also be used merely as a provider of the trace_object
method by giving it an
empty vector of slots. This is useful for node-enqueuing tracing
(Scanning::scan_object_and_trace_edges
) as well as weak reference processing
(Scanning::process_weak_refs
as well as ReferenceProcessor
and FinalizableProcessor
).
In those cases, the caller passes the reference to the target object to trace_object
, an the
caller is responsible for updating the slots according the return value of trace_object
.
TODO: We should refactor this trait to decouple it from slots. See: https://github.com/mmtk/mmtk-core/issues/599
Required Associated Types§
sourcetype ScanObjectsWorkType: ScanObjectsWork<Self::VM>
type ScanObjectsWorkType: ScanObjectsWork<Self::VM>
The work packet type for scanning objects when using this ProcessEdgesWork.
Provided Associated Constants§
sourceconst CAPACITY: usize = 4_096usize
const CAPACITY: usize = 4_096usize
The maximum number of slots that should be put to one of this work packets. The caller who creates a work packet of this trait should be responsible to comply with this capacity. Higher capacity means the packet will take longer to finish, and may lead to bad load balancing. On the other hand, lower capacity would lead to higher cost on scheduling many small work packets. It is important to find a proper capacity.
sourceconst OVERWRITE_REFERENCE: bool = true
const OVERWRITE_REFERENCE: bool = true
Do we update object reference? This has to be true for a moving GC.
sourceconst SCAN_OBJECTS_IMMEDIATELY: bool = true
const SCAN_OBJECTS_IMMEDIATELY: bool = true
If true, we do object scanning in this work packet with the same worker without scheduling overhead. If false, we will add object scanning work packets to the global queue and allow other workers to work on it.
Required Methods§
sourcefn new(
slots: Vec<<<Self as ProcessEdgesWork>::VM as VMBinding>::VMSlot>,
roots: bool,
mmtk: &'static MMTK<Self::VM>,
bucket: WorkBucketStage
) -> Self
fn new( slots: Vec<<<Self as ProcessEdgesWork>::VM as VMBinding>::VMSlot>, roots: bool, mmtk: &'static MMTK<Self::VM>, bucket: WorkBucketStage ) -> Self
Create a ProcessEdgesWork
.
Arguments:
slots
: a vector of slots.roots
: are the objects root reachable objects?mmtk
: a reference to the MMTK instance.bucket
: which work bucket this packet belongs to. Further work generated from this packet will also be put to the same bucket.
sourcefn trace_object(&mut self, object: ObjectReference) -> ObjectReference
fn trace_object(&mut self, object: ObjectReference) -> ObjectReference
Trace an MMTk object. The implementation should forward this call to the policy-specific
trace_object()
methods, depending on which space this object is in.
If the object is not in any MMTk space, the implementation should forward the call to
ActivePlan::vm_trace_object()
to let the binding handle the tracing.
sourcefn create_scan_work(
&self,
nodes: Vec<ObjectReference>
) -> Self::ScanObjectsWorkType
fn create_scan_work( &self, nodes: Vec<ObjectReference> ) -> Self::ScanObjectsWorkType
Create an object-scanning work packet to be used for this ProcessEdgesWork.
roots
indicates if we are creating a packet for root scanning. It is only true when this
method is called to handle RootsWorkFactory::create_process_pinning_roots_work
.
Provided Methods§
sourcefn cache_roots_for_sanity_gc(&mut self)
fn cache_roots_for_sanity_gc(&mut self)
If the work includes roots, we will store the roots somewhere so for sanity GC, we can do another transitive closure from the roots.
sourcefn start_or_dispatch_scan_work(&mut self, work_packet: impl GCWork<Self::VM>)
fn start_or_dispatch_scan_work(&mut self, work_packet: impl GCWork<Self::VM>)
Start the a scan work packet. If SCAN_OBJECTS_IMMEDIATELY, the work packet will be executed immediately, in this method. Otherwise, the work packet will be added the Closure work bucket and will be dispatched later by the scheduler.
sourcefn flush(&mut self)
fn flush(&mut self)
Flush the nodes in ProcessEdgesBase, and create a ScanObjects work packet for it. If the node set is empty, this method will simply return with no work packet created.
sourcefn process_slot(
&mut self,
slot: <<Self as ProcessEdgesWork>::VM as VMBinding>::VMSlot
)
fn process_slot( &mut self, slot: <<Self as ProcessEdgesWork>::VM as VMBinding>::VMSlot )
Process a slot, including loading the object reference from the memory slot, trace the object and store back the new object reference if necessary.
sourcefn process_slots(&mut self)
fn process_slots(&mut self)
Process all the slots in the work packet.