@@ -26,6 +26,8 @@ use crate::util::statistics::stats::Stats;
2626use crate :: vm:: ReferenceGlue ;
2727use crate :: vm:: VMBinding ;
2828use std:: cell:: UnsafeCell ;
29+ #[ cfg( feature = "count_live_bytes_in_gc" ) ]
30+ use std:: collections:: HashMap ;
2931use std:: default:: Default ;
3032use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3133use std:: sync:: Arc ;
@@ -526,4 +528,34 @@ impl<VM: VMBinding> MMTK<VM> {
526528 space. enumerate_objects ( & mut enumerator) ;
527529 } )
528530 }
531+
532+ /// Aggregate a hash map of live bytes per space with the space stats to produce
533+ /// a map of [`crate::liveByteStats`] for the spaces.
534+ #[ cfg( feature = "count_live_bytes_in_gc" ) ]
535+ pub ( crate ) fn aggregate_live_bytes_in_last_gc (
536+ & self ,
537+ live_bytes_per_space : HashMap < & ' static str , usize > ,
538+ ) -> HashMap < & ' static str , crate :: LiveBytesStats > {
539+ use crate :: policy:: space:: Space ;
540+ let mut ret = HashMap :: new ( ) ;
541+ self . get_plan ( ) . for_each_space ( & mut |space : & dyn Space < VM > | {
542+ let space_name = space. get_name ( ) ;
543+ let used_pages = space. reserved_pages ( ) ;
544+ if used_pages != 0 {
545+ let used_bytes = space. reserved_pages ( ) << crate :: util:: constants:: LOG_BYTES_IN_PAGE ;
546+ let live_bytes = * live_bytes_per_space. get ( space_name) . unwrap_or ( & 0 ) ;
547+ debug_assert ! (
548+ live_bytes <= used_bytes,
549+ "Live bytes of objects in {} ({} bytes) is larger than used pages ({} bytes), something is wrong." ,
550+ space_name, live_bytes, used_bytes
551+ ) ;
552+ ret. insert ( space_name, crate :: LiveBytesStats {
553+ live_bytes,
554+ used_pages,
555+ used_bytes,
556+ } ) ;
557+ }
558+ } ) ;
559+ return ret;
560+ }
529561}
0 commit comments