@@ -57,6 +57,11 @@ pub struct ImmixSpace<VM: VMBinding> {
57
57
/// Keeping track of live bytes
58
58
#[ cfg( feature = "dump_memory_stats" ) ]
59
59
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 ,
60
65
}
61
66
62
67
/// Some arguments for Immix Space.
@@ -221,9 +226,13 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for ImmixSpace
221
226
self . mark_lines ( object) ;
222
227
}
223
228
224
- // count the bytes for each object in immixspace
229
+ // count the bytes for each object
225
230
#[ cfg( feature = "dump_memory_stats" ) ]
226
231
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 ) ;
227
236
}
228
237
229
238
fn may_move_objects < const KIND : TraceKind > ( ) -> bool {
@@ -324,6 +333,10 @@ impl<VM: VMBinding> ImmixSpace<VM> {
324
333
space_args,
325
334
#[ cfg( feature = "dump_memory_stats" ) ]
326
335
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 ) ,
327
340
}
328
341
}
329
342
@@ -448,6 +461,10 @@ impl<VM: VMBinding> ImmixSpace<VM> {
448
461
449
462
#[ cfg( feature = "dump_memory_stats" ) ]
450
463
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 ) ;
451
468
}
452
469
453
470
/// Release for the immix space. This is called when a GC finished.
@@ -537,6 +554,8 @@ impl<VM: VMBinding> ImmixSpace<VM> {
537
554
. expect ( "Time went backwards" ) ;
538
555
539
556
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( ) ) ;
540
559
println ! ( "\t Live bytes = {}" , self . get_live_bytes( ) ) ;
541
560
println ! ( "\t Reserved pages = {}" , self . reserved_pages( ) ) ;
542
561
println ! (
@@ -727,6 +746,10 @@ impl<VM: VMBinding> ImmixSpace<VM> {
727
746
let new_object =
728
747
object_forwarding:: forward_object :: < VM > ( object, semantics, copy_context) ;
729
748
749
+ // increase the number of objects being moved
750
+ #[ cfg( feature = "dump_memory_stats" ) ]
751
+ self . increase_copied_objects ( 1 ) ;
752
+
730
753
#[ cfg( feature = "vo_bit" ) ]
731
754
vo_bit:: helper:: on_object_forwarded :: < VM > ( new_object) ;
732
755
@@ -910,6 +933,36 @@ impl<VM: VMBinding> ImmixSpace<VM> {
910
933
pub fn increase_live_bytes ( & self , size : usize ) {
911
934
self . live_bytes . fetch_add ( size, Ordering :: SeqCst ) ;
912
935
}
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
+ }
913
966
}
914
967
915
968
/// A work packet to prepare each block for a major GC.
0 commit comments