mmtk/util/heap/
heap_meta.rs

1use crate::util::heap::layout::vm_layout::vm_layout;
2use crate::util::Address;
3
4pub struct HeapMeta {
5    pub heap_cursor: Address,
6    pub heap_limit: Address,
7}
8
9impl HeapMeta {
10    pub fn new() -> Self {
11        HeapMeta {
12            heap_cursor: vm_layout().heap_start,
13            heap_limit: vm_layout().heap_end,
14        }
15    }
16
17    pub fn reserve(&mut self, extent: usize, top: bool) -> Address {
18        let ret = if top {
19            self.heap_limit -= extent;
20            self.heap_limit
21        } else {
22            let start = self.heap_cursor;
23            self.heap_cursor += extent;
24            start
25        };
26
27        assert!(
28            self.heap_cursor <= self.heap_limit,
29            "Out of virtual address space at {} ({} > {})",
30            self.heap_cursor - extent,
31            self.heap_cursor,
32            self.heap_limit
33        );
34
35        ret
36    }
37
38    pub fn get_discontig_start(&self) -> Address {
39        self.heap_cursor
40    }
41
42    pub fn get_discontig_end(&self) -> Address {
43        self.heap_limit - 1
44    }
45}
46
47// make clippy happy
48impl Default for HeapMeta {
49    fn default() -> Self {
50        Self::new()
51    }
52}