@@ -58,7 +58,7 @@ pub struct ImmixSpace<VM: VMBinding> {
58
58
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
59
59
live_bytes_in_immixspace : AtomicUsize ,
60
60
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
61
- fragmentation_rate : AtomicUsize ,
61
+ occupation_rate : AtomicUsize ,
62
62
}
63
63
64
64
/// Some arguments for Immix Space.
@@ -328,7 +328,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
328
328
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
329
329
live_bytes_in_immixspace : AtomicUsize :: new ( 0 ) ,
330
330
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
331
- fragmentation_rate : AtomicUsize :: new ( 0 ) ,
331
+ occupation_rate : AtomicUsize :: new ( 0 ) ,
332
332
}
333
333
}
334
334
@@ -483,25 +483,66 @@ impl<VM: VMBinding> ImmixSpace<VM> {
483
483
484
484
// calculate the fragmentation rate
485
485
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
486
- {
487
- trace ! ( "Live bytes in immixspace = {}" , self . get_live_bytes( ) ) ;
488
- trace ! ( "Reserved pages in immixspace = {}" , self . reserved_pages( ) ) ;
489
-
490
- trace ! (
491
- "Reserved bytes in immixspace = {}" ,
492
- self . reserved_pages( ) << LOG_BYTES_IN_PAGE
493
- ) ;
494
- let f_rate: f64 =
495
- self . get_live_bytes ( ) as f64 / ( self . reserved_pages ( ) << LOG_BYTES_IN_PAGE ) as f64 ;
486
+ self . dump_memory_stats ( ) ;
496
487
497
- let f_rate_usize: usize = ( f_rate * 10000.0 ) as usize ;
488
+ did_defrag
489
+ }
498
490
499
- debug_assert ! ( ( 0.0 ..=1.0 ) . contains( & f_rate) ) ;
491
+ fn dump_memory_stats ( & mut self ) {
492
+ #[ derive( Default ) ]
493
+ struct Dist {
494
+ live_blocks : usize ,
495
+ live_lines : usize ,
496
+ }
497
+ let mut dist = Dist :: default ( ) ;
498
+ for chunk in self . chunk_map . all_chunks ( ) {
499
+ if !self . address_in_space ( chunk. start ( ) ) {
500
+ continue ;
501
+ }
500
502
501
- self . set_fragmentation_rate ( f_rate_usize) ;
503
+ for block in chunk
504
+ . iter_region :: < Block > ( )
505
+ . filter ( |b| b. get_state ( ) != BlockState :: Unallocated )
506
+ {
507
+ 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 ;
513
+ }
514
+ }
502
515
}
503
516
504
- did_defrag
517
+ println ! (
518
+ "{} immixspace" ,
519
+ chrono:: offset:: Local :: now( ) . format( "%Y-%m-%d %H:%M:%S" )
520
+ ) ;
521
+ println ! ( "Live bytes = {}" , self . get_live_bytes( ) ) ;
522
+ println ! ( "Reserved pages = {}" , self . reserved_pages( ) ) ;
523
+ println ! (
524
+ "Reserved pages (bytes) = {}" ,
525
+ self . reserved_pages( ) << LOG_BYTES_IN_PAGE
526
+ ) ;
527
+ println ! ( "Live blocks = {}" , dist. live_blocks) ;
528
+ println ! (
529
+ "Live blocks (bytes) = {}" ,
530
+ dist. live_blocks << Block :: LOG_BYTES
531
+ ) ;
532
+ println ! ( "Live lines = {}" , dist. live_lines) ;
533
+ println ! (
534
+ "Live lines (bytes) = {}" ,
535
+ dist. live_lines << Line :: LOG_BYTES
536
+ ) ;
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) ;
505
546
}
506
547
507
548
/// Generate chunk sweep tasks
@@ -862,13 +903,13 @@ impl<VM: VMBinding> ImmixSpace<VM> {
862
903
}
863
904
864
905
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
865
- pub fn get_fragmentation_rate ( & self ) -> usize {
866
- self . fragmentation_rate . load ( Ordering :: SeqCst )
906
+ pub fn get_occupation_rate ( & self ) -> usize {
907
+ self . occupation_rate . load ( Ordering :: SeqCst )
867
908
}
868
909
869
910
#[ cfg( feature = "count_live_bytes_immixspace" ) ]
870
- pub fn set_fragmentation_rate ( & self , size : usize ) {
871
- self . fragmentation_rate . store ( size, Ordering :: SeqCst ) ;
911
+ pub fn set_occupation_rate ( & self , size : usize ) {
912
+ self . occupation_rate . store ( size, Ordering :: SeqCst ) ;
872
913
}
873
914
}
874
915
0 commit comments