@@ -608,51 +608,6 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
608608 panic ! ( "A copying space should override this method" )
609609 }
610610
611- fn print_vm_map ( & self ) {
612- let common = self . common ( ) ;
613- print ! ( "{} " , common. name) ;
614- if common. immortal {
615- print ! ( "I" ) ;
616- } else {
617- print ! ( " " ) ;
618- }
619- if common. movable {
620- print ! ( " " ) ;
621- } else {
622- print ! ( "N" ) ;
623- }
624- print ! ( " " ) ;
625- if common. contiguous {
626- print ! ( "{}->{}" , common. start, common. start + common. extent - 1 ) ;
627- match common. vmrequest {
628- VMRequest :: Extent { extent, .. } => {
629- print ! ( " E {}" , extent) ;
630- }
631- VMRequest :: Fraction { frac, .. } => {
632- print ! ( " F {}" , frac) ;
633- }
634- _ => { }
635- }
636- } else {
637- let mut a = self
638- . get_page_resource ( )
639- . common ( )
640- . get_head_discontiguous_region ( ) ;
641- while !a. is_zero ( ) {
642- print ! (
643- "{}->{}" ,
644- a,
645- a + self . common( ) . vm_map( ) . get_contiguous_region_size( a) - 1
646- ) ;
647- a = self . common ( ) . vm_map ( ) . get_next_contiguous_region ( a) ;
648- if !a. is_zero ( ) {
649- print ! ( " " ) ;
650- }
651- }
652- }
653- println ! ( ) ;
654- }
655-
656611 /// Ensure that the current space's metadata context does not have any issues.
657612 /// Panics with a suitable message if any issue is detected.
658613 /// It also initialises the sanity maps which will then be used if the `extreme_assertions` feature is active.
@@ -668,6 +623,66 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
668623 }
669624}
670625
626+ /// Print the VM map for a space.
627+ /// Space needs to be object-safe, so it cannot have methods that use extra generic type paramters. So this method is placed outside the Space trait.
628+ /// This method can be invoked on a &dyn Space (space.as_space() will return &dyn Space).
629+ #[ allow( unused) ]
630+ pub ( crate ) fn print_vm_map < VM : VMBinding > (
631+ space : & dyn Space < VM > ,
632+ out : & mut impl std:: fmt:: Write ,
633+ ) -> Result < ( ) , std:: fmt:: Error > {
634+ let common = space. common ( ) ;
635+ write ! ( out, "{} " , common. name) ?;
636+ if common. immortal {
637+ write ! ( out, "I" ) ?;
638+ } else {
639+ write ! ( out, " " ) ?;
640+ }
641+ if common. movable {
642+ write ! ( out, " " ) ?;
643+ } else {
644+ write ! ( out, "N" ) ?;
645+ }
646+ write ! ( out, " " ) ?;
647+ if common. contiguous {
648+ write ! (
649+ out,
650+ "{}->{}" ,
651+ common. start,
652+ common. start + common. extent - 1
653+ ) ?;
654+ match common. vmrequest {
655+ VMRequest :: Extent { extent, .. } => {
656+ write ! ( out, " E {}" , extent) ?;
657+ }
658+ VMRequest :: Fraction { frac, .. } => {
659+ write ! ( out, " F {}" , frac) ?;
660+ }
661+ _ => { }
662+ }
663+ } else {
664+ let mut a = space
665+ . get_page_resource ( )
666+ . common ( )
667+ . get_head_discontiguous_region ( ) ;
668+ while !a. is_zero ( ) {
669+ write ! (
670+ out,
671+ "{}->{}" ,
672+ a,
673+ a + space. common( ) . vm_map( ) . get_contiguous_region_size( a) - 1
674+ ) ?;
675+ a = space. common ( ) . vm_map ( ) . get_next_contiguous_region ( a) ;
676+ if !a. is_zero ( ) {
677+ write ! ( out, " " ) ?;
678+ }
679+ }
680+ }
681+ writeln ! ( out) ?;
682+
683+ Ok ( ( ) )
684+ }
685+
671686impl_downcast ! ( Space <VM > where VM : VMBinding ) ;
672687
673688pub struct CommonSpace < VM : VMBinding > {
@@ -713,9 +728,6 @@ pub struct SpaceOptions {
713728 pub side_metadata_specs : SideMetadataContext ,
714729}
715730
716- /// Print debug info for SFT. Should be false when committed.
717- const DEBUG_SPACE : bool = cfg ! ( debug_assertions) && false ;
718-
719731impl < VM : VMBinding > CommonSpace < VM > {
720732 pub fn new (
721733 opt : SpaceOptions ,
@@ -805,15 +817,13 @@ impl<VM: VMBinding> CommonSpace<VM> {
805817 panic ! ( "failed to mmap meta memory" ) ;
806818 }
807819
808- if DEBUG_SPACE {
809- println ! (
810- "Created space {} [{}, {}) for {} bytes" ,
811- rtn. name,
812- start,
813- start + extent,
814- extent
815- ) ;
816- }
820+ debug ! (
821+ "Created space {} [{}, {}) for {} bytes" ,
822+ rtn. name,
823+ start,
824+ start + extent,
825+ extent
826+ ) ;
817827
818828 rtn
819829 }
0 commit comments