mmtk/util/heap/
vmrequest.rs

1use 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 {
9        start: Address,
10        extent: usize,
11    },
12    Extent {
13        extent: usize,
14        top: bool,
15    },
16    AlignedExtent {
17        align: usize,
18        extent: usize,
19        top: bool,
20    },
21    Fraction {
22        frac: f32,
23        top: bool,
24    },
25}
26
27impl VMRequest {
28    pub fn is_discontiguous(&self) -> bool {
29        matches!(self, VMRequest::Discontiguous)
30    }
31
32    pub fn common64bit(top: bool) -> Self {
33        VMRequest::AlignedExtent {
34            // A common64bit space need to be aligned. See Map64::is_space_start.
35            align: vm_layout().max_space_extent(),
36            extent: vm_layout().max_space_extent(),
37            top,
38        }
39    }
40
41    pub fn discontiguous() -> Self {
42        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
43            return Self::common64bit(false);
44        }
45        VMRequest::Discontiguous
46    }
47
48    pub fn fixed_size(mb: usize) -> Self {
49        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
50            return Self::common64bit(false);
51        }
52        VMRequest::Extent {
53            extent: mb << LOG_BYTES_IN_MBYTE,
54            top: false,
55        }
56    }
57
58    pub fn fraction(frac: f32) -> Self {
59        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
60            return Self::common64bit(false);
61        }
62        VMRequest::Fraction { frac, top: false }
63    }
64
65    pub fn high_fixed_size(mb: usize) -> Self {
66        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
67            return Self::common64bit(true);
68        }
69        VMRequest::Extent {
70            extent: mb << LOG_BYTES_IN_MBYTE,
71            top: true,
72        }
73    }
74
75    pub fn fixed_extent(extent: usize, top: bool) -> Self {
76        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
77            return Self::common64bit(top);
78        }
79        VMRequest::Extent { extent, top }
80    }
81
82    pub fn aligned_extent(align: usize, extent: usize, top: bool) -> Self {
83        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
84            return Self::common64bit(top);
85        }
86        VMRequest::AlignedExtent { align, extent, top }
87    }
88
89    pub fn fixed(start: Address, extent: usize) -> Self {
90        VMRequest::Fixed { start, extent }
91    }
92}