mmtk/vm/mod.rs
1//! MMTk-to-VM interface: the VMBinding trait.
2//!
3//! This module provides VM-specific traits that serve as MMTK-to-VM interfaces.
4//! Each VM binding needs to provide an implementation for each of the traits.
5//! MMTk requires the interfaces to be efficient, as some of the methods are called frequently
6//! during collection (e.g. the methods for `ObjectModel`). We rely on cross-crate *link-time-optimization*
7//! to remove the overhead of MMTk invoking methods on those traits.
8//!
9//! It is recommended for a VM binding that uses mmtk-core to do the following to ensure LTO is enabled for performance.
10//! 1. Add the following section in the manifest file of a VM binding (`Cargo.toml`). This enables LTO for the release build:
11//! ```
12//! [profile.release]
13//! lto = true
14//! ```
15//! 2. Make sure that the crate type for a VM binding supports LTO. To our knowledge, `staticlib` and `cdylib` support LTO, and
16//! `rlib` does *not* support LTO.
17
18mod active_plan;
19mod collection;
20pub(crate) mod object_model;
21mod reference_glue;
22mod scanning;
23pub mod slot;
24pub use self::active_plan::ActivePlan;
25pub use self::collection::Collection;
26pub use self::collection::GCThreadContext;
27pub use self::object_model::specs::*;
28pub use self::object_model::ObjectModel;
29pub use self::reference_glue::Finalizable;
30pub use self::reference_glue::ReferenceGlue;
31pub use self::scanning::ObjectTracer;
32pub use self::scanning::ObjectTracerContext;
33pub use self::scanning::RootsWorkFactory;
34pub use self::scanning::Scanning;
35pub use self::scanning::SlotVisitor;
36
37#[cfg(test)]
38mod tests;
39
40/// Default min alignment 4 bytes
41const DEFAULT_LOG_MIN_ALIGNMENT: usize = 2;
42/// Default max alignment 8 bytes
43const DEFAULT_LOG_MAX_ALIGNMENT: usize = 3;
44
45/// The `VMBinding` trait associates with each trait, and provides VM-specific constants.
46pub trait VMBinding
47where
48 Self: Sized + 'static + Send + Sync + Default,
49{
50 /// The binding's implementation of [`crate::vm::ObjectModel`].
51 type VMObjectModel: ObjectModel<Self>;
52 /// The binding's implementation of [`crate::vm::Scanning`].
53 type VMScanning: Scanning<Self>;
54 /// The binding's implementation of [`crate::vm::Collection`].
55 type VMCollection: Collection<Self>;
56 /// The binding's implementation of [`crate::vm::ActivePlan`].
57 type VMActivePlan: ActivePlan<Self>;
58 /// The binding's implementation of [`crate::vm::ReferenceGlue`].
59 type VMReferenceGlue: ReferenceGlue<Self>;
60
61 /// The type of slots in this VM.
62 type VMSlot: slot::Slot;
63 /// The type of heap memory slice in this VM.
64 type VMMemorySlice: slot::MemorySlice<SlotType = Self::VMSlot>;
65
66 /// A value to fill in alignment gaps. This value can be used for debugging. Set this value to 0 to skip filling alignment gaps.
67 const ALIGNMENT_VALUE: u8 = 0xab;
68 /// Allowed minimal alignment in bytes.
69 const MIN_ALIGNMENT: usize = 1 << DEFAULT_LOG_MIN_ALIGNMENT;
70 /// Allowed maximum alignment in bytes.
71 const MAX_ALIGNMENT: usize = 1 << DEFAULT_LOG_MAX_ALIGNMENT;
72 /// Does the binding use a non-zero allocation offset? If this is false, we expect the binding
73 /// to always use offset === 0 for allocation, and we are able to do some optimization if we know
74 /// offset === 0.
75 const USE_ALLOCATION_OFFSET: bool = true;
76
77 /// This value is used to assert if the cursor is reasonable after allocations.
78 /// At the end of an allocation, the allocation cursor should be aligned to this value.
79 /// Note that MMTk does not attempt to do anything to align the cursor to this value, but
80 /// it merely asserts with this constant.
81 const ALLOC_END_ALIGNMENT: usize = 1;
82}