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(crate) use self::scanning::RootsKind;
34pub use self::scanning::RootsWorkFactory;
35pub use self::scanning::Scanning;
36pub use self::scanning::SlotVisitor;
37
38#[cfg(test)]
39mod tests;
40
41/// Default min alignment 4 bytes
42const DEFAULT_LOG_MIN_ALIGNMENT: usize = 2;
43/// Default max alignment 8 bytes
44const DEFAULT_LOG_MAX_ALIGNMENT: usize = 3;
45
46/// The `VMBinding` trait associates with each trait, and provides VM-specific constants.
47pub trait VMBinding
48where
49    Self: Sized + 'static + Send + Sync + Default,
50{
51    /// The binding's implementation of [`crate::vm::ObjectModel`].
52    type VMObjectModel: ObjectModel<Self>;
53    /// The binding's implementation of [`crate::vm::Scanning`].
54    type VMScanning: Scanning<Self>;
55    /// The binding's implementation of [`crate::vm::Collection`].
56    type VMCollection: Collection<Self>;
57    /// The binding's implementation of [`crate::vm::ActivePlan`].
58    type VMActivePlan: ActivePlan<Self>;
59    /// The binding's implementation of [`crate::vm::ReferenceGlue`].
60    type VMReferenceGlue: ReferenceGlue<Self>;
61
62    /// The type of slots in this VM.
63    type VMSlot: slot::Slot;
64    /// The type of heap memory slice in this VM.
65    type VMMemorySlice: slot::MemorySlice<SlotType = Self::VMSlot>;
66
67    /// A value to fill in alignment gaps. This value can be used for debugging. Set this value to 0 to skip filling alignment gaps.
68    const ALIGNMENT_VALUE: u8 = 0xab;
69    /// Allowed minimal alignment in bytes.
70    const MIN_ALIGNMENT: usize = 1 << DEFAULT_LOG_MIN_ALIGNMENT;
71    /// Allowed maximum alignment in bytes.
72    const MAX_ALIGNMENT: usize = 1 << DEFAULT_LOG_MAX_ALIGNMENT;
73    /// Does the binding use a non-zero allocation offset? If this is false, we expect the binding
74    /// to always use offset === 0 for allocation, and we are able to do some optimization if we know
75    /// offset === 0.
76    const USE_ALLOCATION_OFFSET: bool = true;
77
78    /// This value is used to assert if the cursor is reasonable after allocations.
79    /// At the end of an allocation, the allocation cursor should be aligned to this value.
80    /// Note that MMTk does not attempt to do anything to align the cursor to this value, but
81    /// it merely asserts with this constant.
82    const ALLOC_END_ALIGNMENT: usize = 1;
83}