@@ -3,7 +3,7 @@ use libc::c_void;
3
3
use libc:: c_char;
4
4
5
5
use std:: ffi:: CStr ;
6
- use std:: str;
6
+ use std:: { str, thread } ;
7
7
8
8
use std:: sync:: atomic:: Ordering ;
9
9
@@ -12,7 +12,6 @@ use ::plan::MutatorContext;
12
12
use :: plan:: TraceLocal ;
13
13
use :: plan:: CollectorContext ;
14
14
use :: plan:: ParallelCollectorGroup ;
15
- use :: plan:: plan:: CONTROL_COLLECTOR_CONTEXT ;
16
15
17
16
use :: vm:: { Collection , VMCollection } ;
18
17
@@ -31,7 +30,6 @@ use ::plan::Allocator;
31
30
use util:: constants:: LOG_BYTES_IN_PAGE ;
32
31
use util:: heap:: layout:: vm_layout_constants:: HEAP_START ;
33
32
use util:: heap:: layout:: vm_layout_constants:: HEAP_END ;
34
- use :: util:: sanity:: sanity_checker:: { INSIDE_SANITY , SanityChecker } ;
35
33
use util:: OpaquePointer ;
36
34
use crate :: mmtk:: SINGLETON ;
37
35
@@ -77,7 +75,7 @@ pub unsafe extern fn openjdk_gc_init(calls: *const OpenJDK_Upcalls, heap_size: u
77
75
#[ no_mangle]
78
76
#[ cfg( any( feature = "jikesrvm" , feature = "openjdk" ) ) ]
79
77
pub extern fn start_control_collector ( tls : OpaquePointer ) {
80
- CONTROL_COLLECTOR_CONTEXT . run ( tls) ;
78
+ SINGLETON . plan . common ( ) . control_collector_context . run ( tls) ;
81
79
}
82
80
83
81
#[ no_mangle]
@@ -96,7 +94,10 @@ pub unsafe extern fn gc_init(heap_size: usize) {
96
94
}
97
95
:: util:: logger:: init ( ) . unwrap ( ) ;
98
96
SINGLETON . plan . gc_init ( heap_size, & SINGLETON . vm_map ) ;
99
- :: plan:: plan:: INITIALIZED . store ( true , Ordering :: SeqCst ) ;
97
+ SINGLETON . plan . common ( ) . initialized . store ( true , Ordering :: SeqCst ) ;
98
+ thread:: spawn ( || {
99
+ SINGLETON . plan . common ( ) . control_collector_context . run ( OpaquePointer :: UNINITIALIZED )
100
+ } ) ;
100
101
}
101
102
102
103
#[ no_mangle]
@@ -145,48 +146,72 @@ pub unsafe extern fn is_valid_ref(val: ObjectReference) -> bool {
145
146
}
146
147
147
148
#[ no_mangle]
149
+ #[ cfg( feature = "sanity" ) ]
148
150
pub unsafe extern fn report_delayed_root_edge ( trace_local : * mut c_void , addr : * mut c_void ) {
149
- trace ! ( "JikesRVM called report_delayed_root_edge with trace_local={:?}" , trace_local) ;
150
- if cfg ! ( feature = "sanity" ) && INSIDE_SANITY . load ( Ordering :: Relaxed ) {
151
- let local = & mut * ( trace_local as * mut SanityChecker ) ;
152
- local. report_delayed_root_edge ( Address :: from_usize ( addr as usize ) ) ;
151
+ use :: util:: sanity:: sanity_checker:: SanityChecker ;
152
+ if SINGLETON . plan . common ( ) . is_in_sanity ( ) {
153
+ report_delayed_root_edge_inner :: < SanityChecker > ( trace_local, addr)
153
154
} else {
154
- let local = & mut * ( trace_local as * mut <SelectedPlan as Plan >:: TraceLocalT ) ;
155
- local. report_delayed_root_edge ( Address :: from_usize ( addr as usize ) ) ;
155
+ report_delayed_root_edge_inner :: < <SelectedPlan as Plan >:: TraceLocalT > ( trace_local, addr)
156
156
}
157
+ }
158
+ #[ no_mangle]
159
+ #[ cfg( not( feature = "sanity" ) ) ]
160
+ pub unsafe extern fn report_delayed_root_edge ( trace_local : * mut c_void , addr : * mut c_void ) {
161
+ report_delayed_root_edge_inner :: < <SelectedPlan as Plan >:: TraceLocalT > ( trace_local, addr)
162
+ }
163
+ unsafe fn report_delayed_root_edge_inner < T : TraceLocal > ( trace_local : * mut c_void , addr : * mut c_void ) {
164
+ trace ! ( "report_delayed_root_edge with trace_local={:?}" , trace_local) ;
165
+ let local = & mut * ( trace_local as * mut T ) ;
166
+ local. report_delayed_root_edge ( Address :: from_usize ( addr as usize ) ) ;
157
167
trace ! ( "report_delayed_root_edge returned with trace_local={:?}" , trace_local) ;
158
168
}
159
169
160
170
#[ no_mangle]
171
+ #[ cfg( feature = "sanity" ) ]
161
172
pub unsafe extern fn will_not_move_in_current_collection ( trace_local : * mut c_void , obj : * mut c_void ) -> bool {
162
- trace ! ( "will_not_move_in_current_collection({:?}, {:?})" , trace_local, obj) ;
163
- if cfg ! ( feature = "sanity" ) && INSIDE_SANITY . load ( Ordering :: Relaxed ) {
164
- let local = & mut * ( trace_local as * mut SanityChecker ) ;
165
- let ret = local. will_not_move_in_current_collection ( Address :: from_usize ( obj as usize ) . to_object_reference ( ) ) ;
166
- trace ! ( "will_not_move_in_current_collection returned with trace_local={:?}" , trace_local) ;
167
- ret
173
+ use :: util:: sanity:: sanity_checker:: SanityChecker ;
174
+ if SINGLETON . plan . common ( ) . is_in_sanity ( ) {
175
+ will_not_move_in_current_collection_inner :: < SanityChecker > ( trace_local, obj)
168
176
} else {
169
- let local = & mut * ( trace_local as * mut <SelectedPlan as Plan >:: TraceLocalT ) ;
170
- let ret = local. will_not_move_in_current_collection ( Address :: from_usize ( obj as usize ) . to_object_reference ( ) ) ;
171
- trace ! ( "will_not_move_in_current_collection returned with trace_local={:?}" , trace_local) ;
172
- ret
177
+ will_not_move_in_current_collection_inner :: < <SelectedPlan as Plan >:: TraceLocalT > ( trace_local, obj)
173
178
}
174
179
}
180
+ #[ no_mangle]
181
+ #[ cfg( not( feature = "sanity" ) ) ]
182
+ pub unsafe extern fn will_not_move_in_current_collection ( trace_local : * mut c_void , obj : * mut c_void ) -> bool {
183
+ will_not_move_in_current_collection_inner :: < <SelectedPlan as Plan >:: TraceLocalT > ( trace_local, obj)
184
+ }
185
+ unsafe fn will_not_move_in_current_collection_inner < T : TraceLocal > ( trace_local : * mut c_void , obj : * mut c_void ) -> bool {
186
+ trace ! ( "will_not_move_in_current_collection({:?}, {:?})" , trace_local, obj) ;
187
+ let local = & mut * ( trace_local as * mut T ) ;
188
+ let ret = local. will_not_move_in_current_collection ( Address :: from_usize ( obj as usize ) . to_object_reference ( ) ) ;
189
+ trace ! ( "will_not_move_in_current_collection returned with trace_local={:?}" , trace_local) ;
190
+ ret
191
+ }
175
192
176
193
#[ no_mangle]
194
+ #[ cfg( feature = "sanity" ) ]
177
195
pub unsafe extern fn process_interior_edge ( trace_local : * mut c_void , target : * mut c_void , slot : * mut c_void , root : bool ) {
178
- trace ! ( "JikesRVM called process_interior_edge with trace_local={:?}" , trace_local) ;
179
- if cfg ! ( feature = "sanity" ) && INSIDE_SANITY . load ( Ordering :: Relaxed ) {
180
- let local = & mut * ( trace_local as * mut SanityChecker ) ;
181
- local. process_interior_edge ( Address :: from_usize ( target as usize ) . to_object_reference ( ) ,
182
- Address :: from_usize ( slot as usize ) , root) ;
196
+ use :: util:: sanity:: sanity_checker:: SanityChecker ;
197
+ if SINGLETON . plan . common ( ) . is_in_sanity ( ) {
198
+ process_interior_edge_inner :: < SanityChecker > ( trace_local, target, slot, root)
183
199
} else {
184
- let local = & mut * ( trace_local as * mut <SelectedPlan as Plan >:: TraceLocalT ) ;
185
- local. process_interior_edge ( Address :: from_usize ( target as usize ) . to_object_reference ( ) ,
186
- Address :: from_usize ( slot as usize ) , root) ;
200
+ process_interior_edge_inner :: < <SelectedPlan as Plan >:: TraceLocalT > ( trace_local, target, slot, root)
187
201
}
188
202
trace ! ( "process_interior_root_edge returned with trace_local={:?}" , trace_local) ;
189
-
203
+ }
204
+ #[ no_mangle]
205
+ #[ cfg( not( feature = "sanity" ) ) ]
206
+ pub unsafe extern fn process_interior_edge ( trace_local : * mut c_void , target : * mut c_void , slot : * mut c_void , root : bool ) {
207
+ process_interior_edge_inner :: < <SelectedPlan as Plan >:: TraceLocalT > ( trace_local, target, slot, root)
208
+ }
209
+ unsafe fn process_interior_edge_inner < T : TraceLocal > ( trace_local : * mut c_void , target : * mut c_void , slot : * mut c_void , root : bool ) {
210
+ trace ! ( "process_interior_edge with trace_local={:?}" , trace_local) ;
211
+ let local = & mut * ( trace_local as * mut T ) ;
212
+ local. process_interior_edge ( Address :: from_usize ( target as usize ) . to_object_reference ( ) ,
213
+ Address :: from_usize ( slot as usize ) , root) ;
214
+ trace ! ( "process_interior_root_edge returned with trace_local={:?}" , trace_local) ;
190
215
}
191
216
192
217
#[ no_mangle]
@@ -199,9 +224,9 @@ pub unsafe extern fn start_worker(tls: OpaquePointer, worker: *mut c_void) {
199
224
#[ no_mangle]
200
225
#[ cfg( feature = "jikesrvm" ) ]
201
226
pub unsafe extern fn enable_collection ( tls : OpaquePointer ) {
202
- ( & mut * CONTROL_COLLECTOR_CONTEXT . workers . get ( ) ) . init_group ( & SINGLETON , tls) ;
227
+ ( & mut * SINGLETON . plan . common ( ) . control_collector_context . workers . get ( ) ) . init_group ( & SINGLETON , tls) ;
203
228
VMCollection :: spawn_worker_thread :: < <SelectedPlan as Plan >:: CollectorT > ( tls, null_mut ( ) ) ; // spawn controller thread
204
- :: plan:: plan :: INITIALIZED . store ( true , Ordering :: SeqCst ) ;
229
+ SINGLETON . plan . common ( ) . initialized . store ( true , Ordering :: SeqCst ) ;
205
230
}
206
231
207
232
#[ no_mangle]
@@ -279,6 +304,7 @@ pub extern fn executable() -> bool {
279
304
}
280
305
281
306
#[ no_mangle]
307
+ #[ cfg( feature = "sanity" ) ]
282
308
pub unsafe extern fn scan_region ( ) {
283
309
:: util:: sanity:: memory_scan:: scan_region ( & SINGLETON . plan ) ;
284
310
}
0 commit comments