1+ use atomic_refcell:: AtomicRefCell ;
2+ #[ cfg( feature = "count_live_bytes_in_gc" ) ]
3+ use std:: collections:: HashMap ;
14use std:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
25use std:: sync:: Mutex ;
36use std:: time:: Instant ;
47
5- use atomic_refcell:: AtomicRefCell ;
6-
78/// This stores some global states for an MMTK instance.
89/// Some MMTK components like plans and allocators may keep an reference to the struct, and can access it.
910// This used to be a part of the `BasePlan`. In that case, any component that accesses
@@ -47,7 +48,7 @@ pub struct GlobalState {
4748 pub ( crate ) malloc_bytes : AtomicUsize ,
4849 /// This stores the size in bytes for all the live objects in last GC. This counter is only updated in the GC release phase.
4950 #[ cfg( feature = "count_live_bytes_in_gc" ) ]
50- pub ( crate ) live_bytes_in_last_gc : AtomicUsize ,
51+ pub ( crate ) live_bytes_in_last_gc : AtomicRefCell < HashMap < & ' static str , usize > > ,
5152}
5253
5354impl GlobalState {
@@ -183,16 +184,6 @@ impl GlobalState {
183184 pub ( crate ) fn decrease_malloc_bytes_by ( & self , size : usize ) {
184185 self . malloc_bytes . fetch_sub ( size, Ordering :: SeqCst ) ;
185186 }
186-
187- #[ cfg( feature = "count_live_bytes_in_gc" ) ]
188- pub fn get_live_bytes_in_last_gc ( & self ) -> usize {
189- self . live_bytes_in_last_gc . load ( Ordering :: SeqCst )
190- }
191-
192- #[ cfg( feature = "count_live_bytes_in_gc" ) ]
193- pub fn set_live_bytes_in_last_gc ( & self , size : usize ) {
194- self . live_bytes_in_last_gc . store ( size, Ordering :: SeqCst ) ;
195- }
196187}
197188
198189impl Default for GlobalState {
@@ -214,7 +205,7 @@ impl Default for GlobalState {
214205 #[ cfg( feature = "malloc_counted_size" ) ]
215206 malloc_bytes : AtomicUsize :: new ( 0 ) ,
216207 #[ cfg( feature = "count_live_bytes_in_gc" ) ]
217- live_bytes_in_last_gc : AtomicUsize :: new ( 0 ) ,
208+ live_bytes_in_last_gc : AtomicRefCell :: new ( HashMap :: new ( ) ) ,
218209 }
219210 }
220211}
0 commit comments