@@ -47,9 +47,7 @@ pub struct GCWorkerShared<VM: VMBinding> {
4747 /// objects, we increase the live bytes. We get this value from each worker
4848 /// at the end of a GC, and reset this counter.
4949 #[ cfg( feature = "count_live_bytes_in_gc" ) ]
50- live_bytes : AtomicUsize ,
51- #[ cfg( feature = "count_live_bytes_in_gc" ) ]
52- live_bytes_detailed : AtomicRefCell < HashMap < & ' static str , AtomicUsize > > ,
50+ live_bytes_per_space : AtomicRefCell < HashMap < & ' static str , AtomicUsize > > ,
5351 /// A queue of GCWork that can only be processed by the owned thread.
5452 pub designated_work : ArrayQueue < Box < dyn GCWork < VM > > > ,
5553 /// Handle for stealing packets from the current worker
@@ -61,9 +59,7 @@ impl<VM: VMBinding> GCWorkerShared<VM> {
6159 Self {
6260 stat : Default :: default ( ) ,
6361 #[ cfg( feature = "count_live_bytes_in_gc" ) ]
64- live_bytes : AtomicUsize :: new ( 0 ) ,
65- #[ cfg( feature = "count_live_bytes_in_gc" ) ]
66- live_bytes_detailed : AtomicRefCell :: new ( HashMap :: new ( ) ) ,
62+ live_bytes_per_space : AtomicRefCell :: new ( HashMap :: new ( ) ) ,
6763 designated_work : ArrayQueue :: new ( 16 ) ,
6864 stealer,
6965 }
@@ -75,9 +71,8 @@ impl<VM: VMBinding> GCWorkerShared<VM> {
7571 use crate :: vm:: object_model:: ObjectModel ;
7672
7773 let bytes = VM :: VMObjectModel :: get_current_size ( object) ;
78- self . live_bytes . fetch_add ( bytes, Ordering :: Relaxed ) ;
7974
80- let mut map = self . live_bytes_detailed . borrow_mut ( ) ;
75+ let mut map = self . live_bytes_per_space . borrow_mut ( ) ;
8176 let space_name = unsafe { SFT_MAP . get_unchecked ( object. to_raw_address ( ) ) } . name ( ) ;
8277 match map. get ( space_name) {
8378 Some ( v) => {
@@ -451,7 +446,8 @@ impl<VM: VMBinding> WorkerGroup<VM> {
451446 pub fn get_and_clear_worker_live_bytes ( & self ) -> HashMap < & ' static str , usize > {
452447 let mut ret = HashMap :: new ( ) ;
453448 self . workers_shared . iter ( ) . for_each ( |w| {
454- for ( space_name, atomic_val) in w. live_bytes_detailed . borrow ( ) . iter ( ) {
449+ let mut live_bytes_per_space = w. live_bytes_per_space . borrow_mut ( ) ;
450+ for ( space_name, atomic_val) in live_bytes_per_space. iter ( ) {
455451 let val = atomic_val. load ( Ordering :: Relaxed ) ;
456452 match ret. get_mut ( space_name) {
457453 Some ( sum) => {
@@ -462,6 +458,7 @@ impl<VM: VMBinding> WorkerGroup<VM> {
462458 }
463459 }
464460 }
461+ live_bytes_per_space. clear ( ) ;
465462 } ) ;
466463 return ret;
467464 }
0 commit comments