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#[cfg(target_pointer_width = "32")]
57/// log2 of the number of bytes in an address
58pub const LOG_BYTES_IN_ADDRESS: u8 = 2;
59#[cfg(target_pointer_width = "64")]
60/// log2 of the number of bytes in an address
61pub const LOG_BYTES_IN_ADDRESS: u8 = 3;
62/// The number of bytes in an address
63pub const BYTES_IN_ADDRESS: usize = 1 << LOG_BYTES_IN_ADDRESS;
64/// log2 of the number of bits in an address
65pub const LOG_BITS_IN_ADDRESS: usize = LOG_BITS_IN_BYTE as usize + LOG_BYTES_IN_ADDRESS as usize;
66/// The number of bits in an address
67pub const BITS_IN_ADDRESS: usize = 1 << LOG_BITS_IN_ADDRESS;
68
69/// log2 of the number of bytes in a word
70pub const LOG_BYTES_IN_WORD: u8 = LOG_BYTES_IN_ADDRESS;
71/// The number of bytes in a word
72pub const BYTES_IN_WORD: usize = 1 << LOG_BYTES_IN_WORD;
73/// log2 of the number of bits in a word
74pub const LOG_BITS_IN_WORD: usize = LOG_BITS_IN_BYTE as usize + LOG_BYTES_IN_WORD as usize;
75/// The number of bits in a word
76pub const BITS_IN_WORD: usize = 1 << LOG_BITS_IN_WORD;
77
78/// log2 of the number of bytes in a page
79pub const LOG_BYTES_IN_PAGE: u8 = 12;
80/// The number of bytes in a page
81pub const BYTES_IN_PAGE: usize = 1 << LOG_BYTES_IN_PAGE;
82/// log2 of the number of bits in a page
83pub const LOG_BITS_IN_PAGE: usize = LOG_BITS_IN_BYTE as usize + LOG_BYTES_IN_PAGE as usize;
84/// The number of bits in a page
85pub const BITS_IN_PAGE: usize = 1 << LOG_BITS_IN_PAGE;
86
87/// log2 of the number of bytes in the address space
88pub const LOG_BYTES_IN_ADDRESS_SPACE: u8 = BITS_IN_ADDRESS as u8;
89
90/// log2 of the minimal object size in bytes.
91// TODO: this should be VM specific.
92pub const LOG_MIN_OBJECT_SIZE: u8 = LOG_BYTES_IN_WORD;
93/// The minimal object size in bytes
94pub const MIN_OBJECT_SIZE: usize = 1 << LOG_MIN_OBJECT_SIZE;