mmtk/util/heap/
vmrequest.rs1use super::layout::vm_layout::*;
2use crate::util::constants::*;
3use crate::util::Address;
4
5#[derive(Clone, Copy, Debug)]
6pub enum VMRequest {
7 Discontiguous,
8 Fixed { start: Address, extent: usize },
9 Extent { extent: usize, top: bool },
10 Fraction { frac: f32, top: bool },
11}
12
13impl VMRequest {
14 pub fn is_discontiguous(&self) -> bool {
15 matches!(self, VMRequest::Discontiguous)
16 }
17
18 pub fn common64bit(top: bool) -> Self {
19 VMRequest::Extent {
20 extent: vm_layout().max_space_extent(),
21 top,
22 }
23 }
24
25 pub fn discontiguous() -> Self {
26 if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
27 return Self::common64bit(false);
28 }
29 VMRequest::Discontiguous
30 }
31
32 pub fn fixed_size(mb: usize) -> Self {
33 if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
34 return Self::common64bit(false);
35 }
36 VMRequest::Extent {
37 extent: mb << LOG_BYTES_IN_MBYTE,
38 top: false,
39 }
40 }
41
42 pub fn fraction(frac: f32) -> Self {
43 if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
44 return Self::common64bit(false);
45 }
46 VMRequest::Fraction { frac, top: false }
47 }
48
49 pub fn high_fixed_size(mb: usize) -> Self {
50 if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
51 return Self::common64bit(true);
52 }
53 VMRequest::Extent {
54 extent: mb << LOG_BYTES_IN_MBYTE,
55 top: true,
56 }
57 }
58
59 pub fn fixed_extent(extent: usize, top: bool) -> Self {
60 if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
61 return Self::common64bit(top);
62 }
63 VMRequest::Extent { extent, top }
64 }
65
66 pub fn fixed(start: Address, extent: usize) -> Self {
67 VMRequest::Fixed { start, extent }
68 }
69}