mmtk/util/
constants.rs

1/// log2 of the number of bytes in a byte
2pub const LOG_BYTES_IN_BYTE: u8 = 0;
3/// The number of bytes in a byte
4pub const BYTES_IN_BYTE: usize = 1;
5/// log2 of the number of bits in a byte
6pub const LOG_BITS_IN_BYTE: u8 = 3;
7/// The number of bits in a byte
8pub const BITS_IN_BYTE: usize = 1 << LOG_BITS_IN_BYTE;
9
10/// log2 of the number of bytes in a gigabyte
11pub const LOG_BYTES_IN_GBYTE: u8 = 30;
12/// The number of bytes in a gigabyte
13pub const BYTES_IN_GBYTE: usize = 1 << LOG_BYTES_IN_GBYTE;
14
15/// log2 of the number of bytes in a megabyte
16pub const LOG_BYTES_IN_MBYTE: u8 = 20;
17/// The number of bytes in a megabyte
18pub const BYTES_IN_MBYTE: usize = 1 << LOG_BYTES_IN_MBYTE;
19
20/// log2 of the number of bytes in a kilobyte
21pub const LOG_BYTES_IN_KBYTE: u8 = 10;
22/// The number of bytes in a kilobyte
23pub const BYTES_IN_KBYTE: usize = 1 << LOG_BYTES_IN_KBYTE;
24
25/// Some card scanning constants ported from Java MMTK.
26/// As we haven't implemented card scanning, these are not used at the moment.
27mod card_scanning {
28    use crate::util::alloc::embedded_meta_data::LOG_BYTES_IN_REGION;
29
30    pub const SUPPORT_CARD_SCANNING: bool = false;
31    /// each card consumes four bytes of metadata
32    pub const LOG_CARD_META_SIZE: usize = 2;
33    /// number of units tracked per card
34    pub const LOG_CARD_UNITS: usize = 10;
35    /// track at byte grain, save shifting
36    pub const LOG_CARD_GRAIN: usize = 0;
37    pub const LOG_CARD_BYTES: usize = LOG_CARD_UNITS + LOG_CARD_GRAIN;
38    pub const LOG_CARD_META_BYTES: usize =
39        LOG_BYTES_IN_REGION - LOG_CARD_BYTES + LOG_CARD_META_SIZE;
40    pub const LOG_CARD_META_PAGES: usize = LOG_CARD_META_BYTES - super::LOG_BYTES_IN_PAGE as usize;
41    // FIXME: Card scanning is not supported at the moment. Move this to side-metadata in the future.
42    pub const CARD_META_PAGES_PER_REGION: usize = if SUPPORT_CARD_SCANNING {
43        1 << LOG_CARD_META_PAGES
44    } else {
45        0
46    };
47    pub const CARD_MASK: usize = (1 << LOG_CARD_BYTES) - 1;
48}
49pub(crate) use card_scanning::*;
50
51/// Lazy sweeping - controlled from here because PlanConstraints needs to
52/// tell the VM that we need to support linear scan.
53// FIXME: we are not really using this constant to decide lazy sweep or not.
54pub(crate) const LAZY_SWEEP: bool = true;
55
56// Java-specific sizes currently used by MMTk
57// TODO: MMTk should really become independent of these Java types: https://github.com/mmtk/mmtk-core/issues/922
58mod java_specific_constants {
59    use super::LOG_BITS_IN_BYTE;
60
61    pub const LOG_BYTES_IN_CHAR: u8 = 1;
62    pub const BYTES_IN_CHAR: usize = 1 << LOG_BYTES_IN_CHAR;
63    pub const LOG_BITS_IN_CHAR: u8 = LOG_BITS_IN_BYTE + LOG_BYTES_IN_CHAR;
64    pub const BITS_IN_CHAR: usize = 1 << LOG_BITS_IN_CHAR;
65
66    pub const LOG_BYTES_IN_SHORT: u8 = 1;
67    pub const BYTES_IN_SHORT: usize = 1 << LOG_BYTES_IN_SHORT;
68    pub const LOG_BITS_IN_SHORT: u8 = LOG_BITS_IN_BYTE + LOG_BYTES_IN_SHORT;
69    pub const BITS_IN_SHORT: usize = 1 << LOG_BITS_IN_SHORT;
70
71    pub const LOG_BYTES_IN_INT: u8 = 2;
72    pub const BYTES_IN_INT: usize = 1 << LOG_BYTES_IN_INT;
73    pub const LOG_BITS_IN_INT: u8 = LOG_BITS_IN_BYTE + LOG_BYTES_IN_INT;
74    pub const BITS_IN_INT: usize = 1 << LOG_BITS_IN_INT;
75
76    pub const LOG_BYTES_IN_LONG: u8 = 3;
77    pub const BYTES_IN_LONG: usize = 1 << LOG_BYTES_IN_LONG;
78    pub const LOG_BITS_IN_LONG: u8 = LOG_BITS_IN_BYTE + LOG_BYTES_IN_LONG;
79    pub const BITS_IN_LONG: usize = 1 << LOG_BITS_IN_LONG;
80
81    pub const MAX_INT: usize = i32::MAX as usize; // 0x7fff_ffff
82    pub const MIN_INT: usize = i32::MIN as u32 as usize; // 0x8000_0000
83}
84pub(crate) use java_specific_constants::*;
85
86#[cfg(target_pointer_width = "32")]
87/// log2 of the number of bytes in an address
88pub const LOG_BYTES_IN_ADDRESS: u8 = 2;
89#[cfg(target_pointer_width = "64")]
90/// log2 of the number of bytes in an address
91pub const LOG_BYTES_IN_ADDRESS: u8 = 3;
92/// The number of bytes in an address
93pub const BYTES_IN_ADDRESS: usize = 1 << LOG_BYTES_IN_ADDRESS;
94/// log2 of the number of bits in an address
95pub const LOG_BITS_IN_ADDRESS: usize = LOG_BITS_IN_BYTE as usize + LOG_BYTES_IN_ADDRESS as usize;
96/// The number of bits in an address
97pub const BITS_IN_ADDRESS: usize = 1 << LOG_BITS_IN_ADDRESS;
98
99/// log2 of the number of bytes in a word
100pub const LOG_BYTES_IN_WORD: u8 = LOG_BYTES_IN_ADDRESS;
101/// The number of bytes in a word
102pub const BYTES_IN_WORD: usize = 1 << LOG_BYTES_IN_WORD;
103/// log2 of the number of bits in a word
104pub const LOG_BITS_IN_WORD: usize = LOG_BITS_IN_BYTE as usize + LOG_BYTES_IN_WORD as usize;
105/// The number of bits in a word
106pub const BITS_IN_WORD: usize = 1 << LOG_BITS_IN_WORD;
107
108/// log2 of the number of bytes in a page
109pub const LOG_BYTES_IN_PAGE: u8 = 12;
110/// The number of bytes in a page
111pub const BYTES_IN_PAGE: usize = 1 << LOG_BYTES_IN_PAGE;
112/// log2 of the number of bits in a page
113pub const LOG_BITS_IN_PAGE: usize = LOG_BITS_IN_BYTE as usize + LOG_BYTES_IN_PAGE as usize;
114/// The number of bits in a page
115pub const BITS_IN_PAGE: usize = 1 << LOG_BITS_IN_PAGE;
116
117/// log2 of the number of bytes in the address space
118pub const LOG_BYTES_IN_ADDRESS_SPACE: u8 = BITS_IN_ADDRESS as u8;
119
120/// log2 of the minimal object size in bytes.
121// TODO: this should be VM specific.
122pub const LOG_MIN_OBJECT_SIZE: u8 = LOG_BYTES_IN_WORD;
123/// The minimal object size in bytes
124pub const MIN_OBJECT_SIZE: usize = 1 << LOG_MIN_OBJECT_SIZE;