@@ -57,6 +57,11 @@ pub struct ImmixSpace<VM: VMBinding> {
5757 /// Keeping track of live bytes
5858 #[ cfg( feature = "dump_memory_stats" ) ]
5959 live_bytes : AtomicUsize ,
60+ /// Keeping track of the number of traced/copied objects
61+ #[ cfg( feature = "dump_memory_stats" ) ]
62+ live_objects : AtomicUsize ,
63+ #[ cfg( feature = "dump_memory_stats" ) ]
64+ copied_objects : AtomicUsize ,
6065}
6166
6267/// Some arguments for Immix Space.
@@ -221,9 +226,13 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for ImmixSpace
221226 self . mark_lines ( object) ;
222227 }
223228
224- // count the bytes for each object in immixspace
229+ // count the bytes for each object
225230 #[ cfg( feature = "dump_memory_stats" ) ]
226231 self . increase_live_bytes ( VM :: VMObjectModel :: get_current_size ( object) ) ;
232+
233+ // increase the number of objects scanned
234+ #[ cfg( feature = "dump_memory_stats" ) ]
235+ self . increase_live_objects ( 1 ) ;
227236 }
228237
229238 fn may_move_objects < const KIND : TraceKind > ( ) -> bool {
@@ -324,6 +333,10 @@ impl<VM: VMBinding> ImmixSpace<VM> {
324333 space_args,
325334 #[ cfg( feature = "dump_memory_stats" ) ]
326335 live_bytes : AtomicUsize :: new ( 0 ) ,
336+ #[ cfg( feature = "dump_memory_stats" ) ]
337+ live_objects : AtomicUsize :: new ( 0 ) ,
338+ #[ cfg( feature = "dump_memory_stats" ) ]
339+ copied_objects : AtomicUsize :: new ( 0 ) ,
327340 }
328341 }
329342
@@ -448,6 +461,10 @@ impl<VM: VMBinding> ImmixSpace<VM> {
448461
449462 #[ cfg( feature = "dump_memory_stats" ) ]
450463 self . set_live_bytes ( 0 ) ;
464+ #[ cfg( feature = "dump_memory_stats" ) ]
465+ self . set_live_objects ( 0 ) ;
466+ #[ cfg( feature = "dump_memory_stats" ) ]
467+ self . set_copied_objects ( 0 ) ;
451468 }
452469
453470 /// Release for the immix space. This is called when a GC finished.
@@ -537,6 +554,8 @@ impl<VM: VMBinding> ImmixSpace<VM> {
537554 . expect ( "Time went backwards" ) ;
538555
539556 println ! ( "{:?} mmtk_immixspace" , since_the_epoch. as_millis( ) ) ;
557+ println ! ( "\t #Live objects = {}" , self . get_live_objects( ) ) ;
558+ println ! ( "\t #Copied objects = {}" , self . get_copied_objects( ) ) ;
540559 println ! ( "\t Live bytes = {}" , self . get_live_bytes( ) ) ;
541560 println ! ( "\t Reserved pages = {}" , self . reserved_pages( ) ) ;
542561 println ! (
@@ -727,6 +746,10 @@ impl<VM: VMBinding> ImmixSpace<VM> {
727746 let new_object =
728747 object_forwarding:: forward_object :: < VM > ( object, semantics, copy_context) ;
729748
749+ // increase the number of objects being moved
750+ #[ cfg( feature = "dump_memory_stats" ) ]
751+ self . increase_copied_objects ( 1 ) ;
752+
730753 #[ cfg( feature = "vo_bit" ) ]
731754 vo_bit:: helper:: on_object_forwarded :: < VM > ( new_object) ;
732755
@@ -910,6 +933,36 @@ impl<VM: VMBinding> ImmixSpace<VM> {
910933 pub fn increase_live_bytes ( & self , size : usize ) {
911934 self . live_bytes . fetch_add ( size, Ordering :: SeqCst ) ;
912935 }
936+
937+ #[ cfg( feature = "dump_memory_stats" ) ]
938+ pub fn get_live_objects ( & self ) -> usize {
939+ self . live_objects . load ( Ordering :: SeqCst )
940+ }
941+
942+ #[ cfg( feature = "dump_memory_stats" ) ]
943+ pub fn set_live_objects ( & self , size : usize ) {
944+ self . live_objects . store ( size, Ordering :: SeqCst )
945+ }
946+
947+ #[ cfg( feature = "dump_memory_stats" ) ]
948+ pub fn increase_live_objects ( & self , size : usize ) {
949+ self . live_objects . fetch_add ( size, Ordering :: SeqCst ) ;
950+ }
951+
952+ #[ cfg( feature = "dump_memory_stats" ) ]
953+ pub fn get_copied_objects ( & self ) -> usize {
954+ self . copied_objects . load ( Ordering :: SeqCst )
955+ }
956+
957+ #[ cfg( feature = "dump_memory_stats" ) ]
958+ pub fn set_copied_objects ( & self , size : usize ) {
959+ self . copied_objects . store ( size, Ordering :: SeqCst )
960+ }
961+
962+ #[ cfg( feature = "dump_memory_stats" ) ]
963+ pub fn increase_copied_objects ( & self , size : usize ) {
964+ self . copied_objects . fetch_add ( size, Ordering :: SeqCst ) ;
965+ }
913966}
914967
915968/// A work packet to prepare each block for a major GC.
0 commit comments