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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use crate::mmtk::MMTK;
use crate::plan::global::{BasePlan, NoCopy};
use crate::plan::nogc::mutator::ALLOCATOR_MAPPING;
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
use crate::plan::PlanConstraints;
use crate::policy::space::Space;
use crate::scheduler::GCWorkerLocal;
use crate::scheduler::GCWorkerLocalPtr;
use crate::scheduler::MMTkScheduler;
use crate::util::alloc::allocators::AllocatorSelector;
use crate::util::heap::layout::heap_layout::Mmapper;
use crate::util::heap::layout::heap_layout::VMMap;
use crate::util::heap::layout::vm_layout_constants::{HEAP_END, HEAP_START};
use crate::util::heap::HeapMeta;
#[allow(unused_imports)]
use crate::util::heap::VMRequest;
use crate::util::options::UnsafeOptionsWrapper;
use crate::util::OpaquePointer;
use crate::vm::VMBinding;
use enum_map::EnumMap;
use std::sync::Arc;
#[cfg(not(feature = "nogc_lock_free"))]
use crate::policy::immortalspace::ImmortalSpace as NoGCImmortalSpace;
#[cfg(feature = "nogc_lock_free")]
use crate::policy::lockfreeimmortalspace::LockFreeImmortalSpace as NoGCImmortalSpace;
pub struct NoGC<VM: VMBinding> {
pub base: BasePlan<VM>,
pub nogc_space: NoGCImmortalSpace<VM>,
}
unsafe impl<VM: VMBinding> Sync for NoGC<VM> {}
pub const NOGC_CONSTRAINTS: PlanConstraints = PlanConstraints::default();
impl<VM: VMBinding> Plan for NoGC<VM> {
type VM = VM;
fn constraints(&self) -> &'static PlanConstraints {
&NOGC_CONSTRAINTS
}
fn create_worker_local(
&self,
tls: OpaquePointer,
mmtk: &'static MMTK<Self::VM>,
) -> GCWorkerLocalPtr {
let mut c = NoCopy::new(mmtk);
c.init(tls);
GCWorkerLocalPtr::new(c)
}
fn gc_init(
&mut self,
heap_size: usize,
vm_map: &'static VMMap,
scheduler: &Arc<MMTkScheduler<VM>>,
) {
self.base.gc_init(heap_size, vm_map, scheduler);
self.nogc_space.init(&vm_map);
}
fn base(&self) -> &BasePlan<VM> {
&self.base
}
fn prepare(&self, _tls: OpaquePointer) {
unreachable!()
}
fn release(&self, _tls: OpaquePointer) {
unreachable!()
}
fn get_allocator_mapping(&self) -> &'static EnumMap<AllocationSemantics, AllocatorSelector> {
&*ALLOCATOR_MAPPING
}
fn schedule_collection(&'static self, _scheduler: &MMTkScheduler<VM>) {
unreachable!("GC triggered in nogc")
}
fn get_pages_used(&self) -> usize {
self.nogc_space.reserved_pages()
}
fn handle_user_collection_request(&self, _tls: OpaquePointer, _force: bool) {
println!("Warning: User attempted a collection request, but it is not supported in NoGC. The request is ignored.");
}
}
impl<VM: VMBinding> NoGC<VM> {
pub fn new(
vm_map: &'static VMMap,
mmapper: &'static Mmapper,
options: Arc<UnsafeOptionsWrapper>,
_scheduler: &'static MMTkScheduler<VM>,
) -> Self {
#[cfg(not(feature = "nogc_lock_free"))]
let mut heap = HeapMeta::new(HEAP_START, HEAP_END);
#[cfg(feature = "nogc_lock_free")]
let heap = HeapMeta::new(HEAP_START, HEAP_END);
#[cfg(feature = "nogc_lock_free")]
let nogc_space =
NoGCImmortalSpace::new("nogc_space", cfg!(not(feature = "nogc_no_zeroing")));
#[cfg(not(feature = "nogc_lock_free"))]
let nogc_space = NoGCImmortalSpace::new(
"nogc_space",
true,
VMRequest::discontiguous(),
vm_map,
mmapper,
&mut heap,
&NOGC_CONSTRAINTS,
);
NoGC {
nogc_space,
base: BasePlan::new(vm_map, mmapper, options, heap, &NOGC_CONSTRAINTS),
}
}
}