pub trait GCWork<VM: VMBinding>: 'static + Send {
// Required method
fn do_work(&mut self, worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM>);
// Provided methods
fn do_work_with_stat(
&mut self,
worker: &mut GCWorker<VM>,
mmtk: &'static MMTK<VM>
) { ... }
fn get_type_name(&self) -> &'static str { ... }
}
Expand description
This defines a GC work packet which are assigned to the GCWorker
s by the scheduler.
Work packets carry payloads that indicate the work to be done. For example, a work packet may
contain a pointer to a stack that must be scanned, or it may contain a large buffer of pointers
that need to be traced, or it might contain a range of static variables to be scanned, etc. The size
of the work packet will need to consider at least two points of tension: the work packet must be large
enough to ensure that the costs of managing the work packets do not dominate, and the packet must be
small enough that good load balancing is achieved.
Required Methods§
sourcefn do_work(&mut self, worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM>)
fn do_work(&mut self, worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM>)
Define the work for this packet. However, this is not supposed to be called directly.
Usually do_work_with_stat()
should be used.
Most work packets are polled and executed in the worker’s main loop (GCWorker::run
)
using do_work_with_stat
. If do_work
is called directly during the execution of another
work packet, bypassing do_work_with_stat()
, this work packet will not be counted into the
number of work packets executed, and the execution time of this work packet will be counted
as part of the execution time of the other work packet. Only call this method directly if
this is what you intend. But you should always consider adding the work packet
into a bucket so that other GC workers can execute it in parallel, unless the context-
switching overhead is a problem.
Provided Methods§
sourcefn do_work_with_stat(
&mut self,
worker: &mut GCWorker<VM>,
mmtk: &'static MMTK<VM>
)
fn do_work_with_stat( &mut self, worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM> )
Do work and collect statistics. This internally calls do_work()
. In most cases,
this should be called rather than do_work()
so that MMTk can correctly collect
statistics for the work packets.
If the feature “work_packet_stats” is not enabled, this call simply forwards the call
to do_work()
.
sourcefn get_type_name(&self) -> &'static str
fn get_type_name(&self) -> &'static str
Get the compile-time static type name for the work packet.