@@ -54,11 +54,9 @@ pub struct ImmixSpace<VM: VMBinding> {
54
54
scheduler : Arc < GCWorkScheduler < VM > > ,
55
55
/// Some settings for this space
56
56
space_args : ImmixSpaceArgs ,
57
- /// Keeping track of fragmentation rate
58
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
59
- live_bytes_in_immixspace : AtomicUsize ,
60
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
61
- occupation_rate : AtomicUsize ,
57
+ /// Keeping track of live bytes
58
+ #[ cfg( feature = "dump_memory_stats" ) ]
59
+ live_bytes : AtomicUsize ,
62
60
}
63
61
64
62
/// Some arguments for Immix Space.
@@ -223,9 +221,8 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for ImmixSpace
223
221
self . mark_lines ( object) ;
224
222
}
225
223
226
- // count the bytes for each object in immixspace to
227
- // check for fragmentation
228
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
224
+ // count the bytes for each object in immixspace
225
+ #[ cfg( feature = "dump_memory_stats" ) ]
229
226
self . increase_live_bytes ( VM :: VMObjectModel :: get_current_size ( object) ) ;
230
227
}
231
228
@@ -325,10 +322,8 @@ impl<VM: VMBinding> ImmixSpace<VM> {
325
322
mark_state : Self :: MARKED_STATE ,
326
323
scheduler : scheduler. clone ( ) ,
327
324
space_args,
328
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
329
- live_bytes_in_immixspace : AtomicUsize :: new ( 0 ) ,
330
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
331
- occupation_rate : AtomicUsize :: new ( 0 ) ,
325
+ #[ cfg( feature = "dump_memory_stats" ) ]
326
+ live_bytes : AtomicUsize :: new ( 0 ) ,
332
327
}
333
328
}
334
329
@@ -451,7 +446,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
451
446
}
452
447
}
453
448
454
- #[ cfg( feature = "count_live_bytes_immixspace " ) ]
449
+ #[ cfg( feature = "dump_memory_stats " ) ]
455
450
self . set_live_bytes ( 0 ) ;
456
451
}
457
452
@@ -481,14 +476,11 @@ impl<VM: VMBinding> ImmixSpace<VM> {
481
476
482
477
self . lines_consumed . store ( 0 , Ordering :: Relaxed ) ;
483
478
484
- // calculate the fragmentation rate
485
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
486
- self . dump_memory_stats ( ) ;
487
-
488
479
did_defrag
489
480
}
490
481
491
- fn dump_memory_stats ( & mut self ) {
482
+ #[ cfg( feature = "dump_memory_stats" ) ]
483
+ pub ( crate ) fn dump_memory_stats ( & self ) {
492
484
#[ derive( Default ) ]
493
485
struct Dist {
494
486
live_blocks : usize ,
@@ -505,11 +497,18 @@ impl<VM: VMBinding> ImmixSpace<VM> {
505
497
. filter ( |b| b. get_state ( ) != BlockState :: Unallocated )
506
498
{
507
499
dist. live_blocks += 1 ;
508
- for _line in block
509
- . lines ( )
510
- . filter ( |l| l. is_marked ( self . line_mark_state . load ( Ordering :: Acquire ) ) )
511
- {
512
- dist. live_lines = 1 ;
500
+ match block. get_state ( ) {
501
+ BlockState :: Marked => {
502
+ panic ! ( "At this point the block should have been swept already" ) ;
503
+ }
504
+ BlockState :: Unmarked => {
505
+ // Block is unmarked and cannot be reused (has no holes)
506
+ dist. live_lines += Block :: LINES ;
507
+ }
508
+ BlockState :: Reusable { unavailable_lines } => {
509
+ dist. live_lines += unavailable_lines as usize ;
510
+ }
511
+ BlockState :: Unallocated => { }
513
512
}
514
513
}
515
514
}
@@ -518,31 +517,22 @@ impl<VM: VMBinding> ImmixSpace<VM> {
518
517
"{} immixspace" ,
519
518
chrono:: offset:: Local :: now( ) . format( "%Y-%m-%d %H:%M:%S" )
520
519
) ;
521
- println ! ( "Live bytes = {}" , self . get_live_bytes( ) ) ;
522
- println ! ( "Reserved pages = {}" , self . reserved_pages( ) ) ;
520
+ println ! ( "\t Live bytes = {}" , self . get_live_bytes( ) ) ;
521
+ println ! ( "\t Reserved pages = {}" , self . reserved_pages( ) ) ;
523
522
println ! (
524
- "Reserved pages (bytes) = {}" ,
523
+ "\t Reserved pages (bytes) = {}" ,
525
524
self . reserved_pages( ) << LOG_BYTES_IN_PAGE
526
525
) ;
527
- println ! ( "Live blocks = {}" , dist. live_blocks) ;
526
+ println ! ( "\t Live blocks = {}" , dist. live_blocks) ;
528
527
println ! (
529
- "Live blocks (bytes) = {}" ,
528
+ "\t Live blocks (bytes) = {}" ,
530
529
dist. live_blocks << Block :: LOG_BYTES
531
530
) ;
532
- println ! ( "Live lines = {}" , dist. live_lines) ;
531
+ println ! ( "\t Live lines = {}" , dist. live_lines) ;
533
532
println ! (
534
- "Live lines (bytes) = {}" ,
533
+ "\t Live lines (bytes) = {}" ,
535
534
dist. live_lines << Line :: LOG_BYTES
536
535
) ;
537
-
538
- let o_rate: f64 =
539
- self . get_live_bytes ( ) as f64 / ( self . reserved_pages ( ) << LOG_BYTES_IN_PAGE ) as f64 ;
540
-
541
- let o_rate_usize: usize = ( o_rate * 10000.0 ) as usize ;
542
-
543
- debug_assert ! ( ( 0.0 ..=1.0 ) . contains( & o_rate) ) ;
544
-
545
- self . set_occupation_rate ( o_rate_usize) ;
546
536
}
547
537
548
538
/// Generate chunk sweep tasks
@@ -886,30 +876,19 @@ impl<VM: VMBinding> ImmixSpace<VM> {
886
876
}
887
877
}
888
878
889
- #[ cfg( feature = "count_live_bytes_immixspace " ) ]
879
+ #[ cfg( feature = "dump_memory_stats " ) ]
890
880
pub fn get_live_bytes ( & self ) -> usize {
891
- self . live_bytes_in_immixspace . load ( Ordering :: SeqCst )
881
+ self . live_bytes . load ( Ordering :: SeqCst )
892
882
}
893
883
894
- #[ cfg( feature = "count_live_bytes_immixspace " ) ]
884
+ #[ cfg( feature = "dump_memory_stats " ) ]
895
885
pub fn set_live_bytes ( & self , size : usize ) {
896
- self . live_bytes_in_immixspace . store ( size, Ordering :: SeqCst )
886
+ self . live_bytes . store ( size, Ordering :: SeqCst )
897
887
}
898
888
899
- #[ cfg( feature = "count_live_bytes_immixspace " ) ]
889
+ #[ cfg( feature = "dump_memory_stats " ) ]
900
890
pub fn increase_live_bytes ( & self , size : usize ) {
901
- self . live_bytes_in_immixspace
902
- . fetch_add ( size, Ordering :: SeqCst ) ;
903
- }
904
-
905
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
906
- pub fn get_occupation_rate ( & self ) -> usize {
907
- self . occupation_rate . load ( Ordering :: SeqCst )
908
- }
909
-
910
- #[ cfg( feature = "count_live_bytes_immixspace" ) ]
911
- pub fn set_occupation_rate ( & self , size : usize ) {
912
- self . occupation_rate . store ( size, Ordering :: SeqCst ) ;
891
+ self . live_bytes . fetch_add ( size, Ordering :: SeqCst ) ;
913
892
}
914
893
}
915
894
0 commit comments