1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use super::layout::vm_layout::*;
use crate::util::constants::*;
use crate::util::Address;

#[derive(Clone, Copy, Debug)]
pub enum VMRequest {
    Discontiguous,
    Fixed { start: Address, extent: usize },
    Extent { extent: usize, top: bool },
    Fraction { frac: f32, top: bool },
}

impl VMRequest {
    pub fn is_discontiguous(&self) -> bool {
        matches!(self, VMRequest::Discontiguous { .. })
    }

    pub fn common64bit(top: bool) -> Self {
        VMRequest::Extent {
            extent: vm_layout().max_space_extent(),
            top,
        }
    }

    pub fn discontiguous() -> Self {
        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
            return Self::common64bit(false);
        }
        VMRequest::Discontiguous
    }

    pub fn fixed_size(mb: usize) -> Self {
        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
            return Self::common64bit(false);
        }
        VMRequest::Extent {
            extent: mb << LOG_BYTES_IN_MBYTE,
            top: false,
        }
    }

    pub fn fraction(frac: f32) -> Self {
        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
            return Self::common64bit(false);
        }
        VMRequest::Fraction { frac, top: false }
    }

    pub fn high_fixed_size(mb: usize) -> Self {
        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
            return Self::common64bit(true);
        }
        VMRequest::Extent {
            extent: mb << LOG_BYTES_IN_MBYTE,
            top: true,
        }
    }

    pub fn fixed_extent(extent: usize, top: bool) -> Self {
        if cfg!(target_pointer_width = "64") && vm_layout().force_use_contiguous_spaces {
            return Self::common64bit(top);
        }
        VMRequest::Extent { extent, top }
    }

    pub fn fixed(start: Address, extent: usize) -> Self {
        VMRequest::Fixed { start, extent }
    }
}