1
1
use std:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
2
2
use std:: sync:: Mutex ;
3
+ use std:: time:: Instant ;
4
+
5
+ use atomic_refcell:: AtomicRefCell ;
3
6
4
7
/// This stores some global states for an MMTK instance.
5
8
/// Some MMTK components like plans and allocators may keep an reference to the struct, and can access it.
@@ -15,6 +18,8 @@ pub struct GlobalState {
15
18
pub ( crate ) initialized : AtomicBool ,
16
19
/// The current GC status.
17
20
pub ( crate ) gc_status : Mutex < GcStatus > ,
21
+ /// When did the last GC start? Only accessed by the last parked worker.
22
+ pub ( crate ) gc_start_time : AtomicRefCell < Option < Instant > > ,
18
23
/// Is the current GC an emergency collection? Emergency means we may run out of memory soon, and we should
19
24
/// attempt to collect as much as we can.
20
25
pub ( crate ) emergency_collection : AtomicBool ,
@@ -195,6 +200,7 @@ impl Default for GlobalState {
195
200
Self {
196
201
initialized : AtomicBool :: new ( false ) ,
197
202
gc_status : Mutex :: new ( GcStatus :: NotInGC ) ,
203
+ gc_start_time : AtomicRefCell :: new ( None ) ,
198
204
stacks_prepared : AtomicBool :: new ( false ) ,
199
205
emergency_collection : AtomicBool :: new ( false ) ,
200
206
user_triggered_collection : AtomicBool :: new ( false ) ,
0 commit comments