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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use crate;
use Result;
// Used in doc comment.
use crateLOG_BYTES_IN_PAGE;
/// An `Mmapper` manages the mmap state of memory used by the heap and side metadata of MMTk.
///
/// For the efficiency of implementation, an `Mmapper` operates at the granularity of
/// [`Mmapper::granularity()`]. Methods that take memory ranges as arguments will round the range
/// to the overlapping chunks.
///
/// From the perspective of the `Mmapper`, each memory range can be in one of the three states:
/// Unmapped, Quarantined, and Mapped. The state transition graph is:
///
/// ```text
/// ┌────────┐ ensure_mapped / mark_as_mapped ┌──────┐
/// │Unmapped├────────────────────────────────────►Mapped│
/// └───┬────┘ └───▲──┘
/// │ ┌───────────┐ │
/// └───────────────►Quarantined├─────────────────┘
/// quarantine └───────────┘ ensure_mapped
/// ```
///
/// - **Unmapped** means the memory is not mapped by the `Mmapper`, and may be mapped by other
/// components of the process.
/// - **Quarantined** means the `Mmapper` has reserved the memory for MMTk, usually by using
/// `mmap` with `PROT_NONE`.
/// - **Mapped** means `Mmapper` has mapped the memory, and the memory can be read and written by
/// MMTk.