MMTk-to-VM interface: the VMBinding trait.
This module provides VM-specific traits that serve as MMTK-to-VM interfaces.
Each VM binding needs to provide an implementation for each of the traits.
MMTk requires the interfaces to be efficient, as some of the methods are called frequently
during collection (e.g. the methods for
ObjectModel). We rely on cross-crate link-time-optimization
to remove the overhead of MMTk invoking methods on those traits.
It is recommended for a VM binding that uses mmtk-core to do the following to ensure LTO is enabled for performance.
- Add the following section in the manifest file of a VM binding (
Cargo.toml). This enables LTO for the release build:
[profile.release] lto = true
- Make sure that the crate type for a VM binding supports LTO. To our knowledge,
cdylibsupport LTO, and
rlibdoes not support LTO.
- Allows MMTk to access edges in a VM-defined way.
- scanning 🔒
- 1-bit global metadata to log an object.
- 2-bit local metadata for spaces that store a forwarding state for objects. If this spec is defined in the header, it can be defined with a position of the lowest 2 bits in the forwarding pointer.
- 1-word local metadata for spaces that may copy objects. This metadata has to be stored in the header. This metadata can be defined at a position within the object payload. As a forwarding pointer is only stored in dead objects which is not accessible by the language, it is okay that store a forwarding pointer overwrites object payload
- 2-bits local metadata for the large object space. The two bits serve as the mark bit and the nursery bit.
- 1-bit local metadata for spaces that need to mark an object.
- 1-bit local metadata for spaces that support pinning.
- Thread context for the spawned GC thread. It is used by spawn_gc_thread.
- Default max alignment 8 bytes
- Default min alignment 4 bytes
- VM-specific methods for the current plan.
- VM-specific methods for garbage collection.
- Callback trait of scanning functions that report edges.
- A finalizable object for MMTk. MMTk needs to know the actual object reference in the type, while a binding can use this type to store some runtime information about finalizable objects. For example, for bindings that allows multiple finalizer methods with one object, they can define the type as a tuple of
(object, finalize method), and register different finalizer methods to MMTk for the same object. The implementation should mark theird method implementations as inline for performance.
- VM-specific methods for object model.
- Callback trait of scanning functions that directly trace through edges.
ObjectTracerContextgives a GC worker temporary access to an
ObjectTracer, allowing the GC worker to trace objects. This trait is intended to abstract out the implementation details of tracing objects, enqueuing objects, and creating work packets that expand the transitive closure, allowing the VM binding to focus on VM-specific parts.
- VM-specific methods for reference processing, including weak references, and finalizers. We handle weak references and finalizers differently:
- Root-scanning methods use this trait to create work packets for processing roots.
- VM-specific methods for scanning roots/objects.
VMBindingtrait associates with each trait, and provides VM-specific constants.