mmtk/policy/gc_work.rs
1/// Used to identify the trace if a policy has different kinds of traces. For example, defrag vs fast trace for Immix,
2/// mark vs forward trace for mark compact.
3pub(crate) type TraceKind = u8;
4
5pub const DEFAULT_TRACE: u8 = u8::MAX;
6pub const TRACE_KIND_TRANSITIVE_PIN: u8 = DEFAULT_TRACE - 1;
7
8use crate::plan::ObjectQueue;
9use crate::scheduler::GCWorker;
10use crate::util::copy::CopySemantics;
11
12use crate::util::ObjectReference;
13
14use crate::vm::VMBinding;
15
16/// This trait defines policy-specific behavior for tracing objects.
17/// The procedural macro #[derive(PlanTraceObject)] will generate code
18/// that uses this trait. We expect any policy to implement this trait.
19/// For the sake of performance, the implementation
20/// of this trait should mark methods as `[inline(always)]`.
21pub trait PolicyTraceObject<VM: VMBinding> {
22 /// Trace object in the policy. If the policy copies objects, we should
23 /// expect `copy` to be a `Some` value.
24 fn trace_object<Q: ObjectQueue, const KIND: TraceKind>(
25 &self,
26 queue: &mut Q,
27 object: ObjectReference,
28 copy: Option<CopySemantics>,
29 worker: &mut GCWorker<VM>,
30 ) -> ObjectReference;
31
32 /// Policy-specific post-scan-object hook. It is called after scanning
33 /// each object in this space.
34 fn post_scan_object(&self, _object: ObjectReference) {
35 // Do nothing.
36 }
37
38 /// Return whether the policy moves objects.
39 fn may_move_objects<const KIND: TraceKind>() -> bool;
40}