mmtk/util/heap/layout/
map.rs

1use crate::util::freelist::FreeList;
2use crate::util::heap::space_descriptor::SpaceDescriptor;
3use crate::util::Address;
4
5/// The result of creating free list.
6///
7/// `VMMap` will select an implementation of `FreeList`.  If it is `RawMemoryFreeList`, it will
8/// occupy a portion of address range at the beginning of the space.  That will require the
9/// starting address of the space to be displaced.  This information is conveyed via the
10/// `space_displacement` field.
11pub struct CreateFreeListResult {
12    // The created free list.
13    pub free_list: Box<dyn FreeList>,
14    // The number of bytes to be added to the starting address of the space.  Zero if not needed.
15    // Always aligned to chunks.
16    pub space_displacement: usize,
17}
18
19pub trait VMMap: Sync {
20    fn insert(&self, start: Address, extent: usize, descriptor: SpaceDescriptor);
21
22    /// Create a free-list for a discontiguous space. Must only be called at boot time.
23    fn create_freelist(&self, start: Address) -> CreateFreeListResult;
24
25    /// Create a free-list for a contiguous space. Must only be called at boot time.
26    fn create_parent_freelist(
27        &self,
28        start: Address,
29        units: usize,
30        grain: i32,
31    ) -> CreateFreeListResult;
32
33    /// # Safety
34    ///
35    /// Caller must ensure that only one thread is calling this method.
36    unsafe fn allocate_contiguous_chunks(
37        &self,
38        descriptor: SpaceDescriptor,
39        chunks: usize,
40        head: Address,
41        maybe_freelist: Option<&mut dyn FreeList>,
42    ) -> Address;
43
44    fn get_next_contiguous_region(&self, start: Address) -> Address;
45
46    fn get_contiguous_region_chunks(&self, start: Address) -> usize;
47
48    fn get_contiguous_region_size(&self, start: Address) -> usize;
49
50    /// Return the total number of chunks available (unassigned) within the range of virtual memory
51    /// apportioned to discontiguous spaces.
52    fn get_available_discontiguous_chunks(&self) -> usize;
53
54    /// Return the total number of clients contending for chunks. This is useful when establishing
55    /// conservative bounds on the number of remaining chunks.
56    fn get_chunk_consumer_count(&self) -> usize;
57
58    fn free_all_chunks(&self, any_chunk: Address);
59
60    /// # Safety
61    ///
62    /// Caller must ensure that only one thread is calling this method.
63    unsafe fn free_contiguous_chunks(&self, start: Address) -> usize;
64
65    /// Finalize the globlal maps in the implementations of `VMMap`.  This should be called after
66    /// all spaces are created.
67    ///
68    /// Arguments:
69    /// -   `from`: the starting address of the heap
70    /// -   `to`: the address of the last byte within the heap
71    /// -   `on_discontig_start_determined`: Called when the address range of the discontiguous
72    ///     memory range is determined.  Will not be called if the `VMMap` implementation does not
73    ///     have a discontigous memory range.  The `Address` argument of the callback is the
74    ///     starting address of the discontiguous memory range.
75    fn finalize_static_space_map(
76        &self,
77        from: Address,
78        to: Address,
79        on_discontig_start_determined: &mut dyn FnMut(Address),
80    );
81
82    fn is_finalized(&self) -> bool;
83
84    /// Get the space descriptor for the given address. Return SpaceDescriptor::UNINITIALIZED if the
85    /// address is not within the MMTk heap range, or not within MMTk spaces.
86    fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor;
87}