mmtk/plan/plan_constraints.rs
1//! Plan-specific constraints.
2
3use crate::plan::barriers::BarrierSelector;
4use crate::util::constants::*;
5
6/// This struct defines plan-specific constraints.
7/// Most of the constraints are constants. Each plan should declare a constant of this struct,
8/// and use the constant wherever possible. However, for plan-neutral implementations,
9/// these constraints are not constant.
10pub struct PlanConstraints {
11 /// Does the plan collect garbage? Obviously most plans do, but NoGC does not collect.
12 pub collects_garbage: bool,
13 /// True if the plan moves objects.
14 pub moves_objects: bool,
15 /// Size (in bytes) beyond which new regular objects must be allocated to the LOS.
16 /// This usually depends on the restriction of the default allocator, e.g. block size for Immix,
17 /// nursery size, max possible cell for freelist, etc.
18 pub max_non_los_default_alloc_bytes: usize,
19 /// Size (in bytes) beyond which copied objects must be copied to the LOS.
20 /// This depends on the copy allocator.
21 pub max_non_los_copy_bytes: usize,
22 /// Does this plan use the log bit? See vm::ObjectModel::GLOBAL_LOG_BIT_SPEC.
23 pub needs_log_bit: bool,
24 /// Some plans may allow benign race for testing mark bit, and this will lead to trace the same
25 /// edge multiple times. If a plan allows tracing duplicated edges, we will not run duplicate
26 /// edge check in extreme_assertions.
27 ///
28 /// Note: Both [`crate::vm::Scanning::scan_object`] (which enqueues slots) and
29 /// [`crate::vm::Scanning::scan_object_and_trace_edges`] (which traces the targets directly) are
30 /// affected by such benign races. But our current duplicate edge check in extreme_assertions
31 /// only identifies duplicated slots.
32 pub may_trace_duplicate_edges: bool,
33 /// The barrier this plan uses. A binding may check this and know what kind of write barrier is in use
34 /// if they would like to implement the barrier fast path in the binding side.
35 pub barrier: BarrierSelector,
36 // the following seems unused for now
37 /// True if this plan requires linear scanning. This is unused and may be incorrect.
38 pub needs_linear_scan: bool,
39 /// True if this plan requires concurrent worker threads. This is unused and may be incorrect.
40 pub needs_concurrent_workers: bool,
41 /// Some policies do object forwarding after the first liveness transitive closure, such as mark compact.
42 /// For plans that use those policies, they should set this as true.
43 pub needs_forward_after_liveness: bool,
44 /// Some (in fact, most) plans do nothing when preparing mutators before tracing (i.e. in
45 /// `MutatorConfig::prepare_func`). Those plans can set this to `false` so that the
46 /// `PrepareMutator` work packets will not be created at all.
47 pub needs_prepare_mutator: bool,
48 /// Is this plan generational?
49 pub generational: bool,
50}
51
52impl PlanConstraints {
53 /// A const function to create the default plan constraints.
54 pub const fn default() -> Self {
55 PlanConstraints {
56 collects_garbage: true,
57 moves_objects: false,
58 max_non_los_default_alloc_bytes: MAX_INT,
59 max_non_los_copy_bytes: MAX_INT,
60 // As `LAZY_SWEEP` is true, needs_linear_scan is true for all the plans. This is strange.
61 // https://github.com/mmtk/mmtk-core/issues/1027 tracks the issue.
62 needs_linear_scan: crate::util::constants::SUPPORT_CARD_SCANNING
63 || crate::util::constants::LAZY_SWEEP,
64 needs_concurrent_workers: false,
65 // We may trace duplicate edges in mark sweep. If we use mark sweep as the non moving policy, it will be included in every
66 may_trace_duplicate_edges: cfg!(feature = "marksweep_as_nonmoving"),
67 needs_forward_after_liveness: false,
68 needs_log_bit: false,
69 barrier: BarrierSelector::NoBarrier,
70 // If we use mark sweep as non moving space, we need to prepare mutator. See [`common_prepare_func`].
71 needs_prepare_mutator: cfg!(feature = "marksweep_as_nonmoving"),
72 generational: false,
73 }
74 }
75}
76
77/// The default plan constraints. Each plan should define their own plan constraints.
78/// They can start from the default constraints and explicitly set some of the fields.
79pub(crate) const DEFAULT_PLAN_CONSTRAINTS: PlanConstraints = PlanConstraints::default();
80
81// Use two pages as the size limit for non-LOS objects to avoid copying large objects
82pub const MAX_NON_LOS_ALLOC_BYTES_COPYING_PLAN: usize = 2 << LOG_BYTES_IN_PAGE;