Skip to content

Commit 26ff9e1

Browse files
authored
Remove print!/println! code from mmtk-core (#655)
This pull request removes `print!` and `println!` from our code base. `print!/println!` are replaced with logging lines, `write!`, or `eprint!/eprintln!` if we really need to report errors. This closes #654.
1 parent 76131c4 commit 26ff9e1

File tree

4 files changed

+74
-63
lines changed

4 files changed

+74
-63
lines changed

src/plan/nogc/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<VM: VMBinding> Plan for NoGC<VM> {
8080
}
8181

8282
fn handle_user_collection_request(&self, _tls: VMMutatorThread, _force: bool) {
83-
println!("Warning: User attempted a collection request, but it is not supported in NoGC. The request is ignored.");
83+
warn!("User attempted a collection request, but it is not supported in NoGC. The request is ignored.");
8484
}
8585
}
8686

src/policy/space.rs

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
671686
impl_downcast!(Space<VM> where VM: VMBinding);
672687

673688
pub 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-
719731
impl<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
}

src/util/sanity/memory_scan.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::util::Address;
22
use crate::util::ObjectReference;
33

4+
// This is legacy code, and no one is using this. Using gdb can achieve the same thing for debugging.
5+
// The JikesRVM binding still declares this method and we need to remove it from JikesRVM.
6+
#[deprecated]
47
pub fn scan_region() {
58
loop {
69
let mut buf = String::new();

src/util/statistics/stats.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Stats {
162162
}
163163
self.shared.increment_phase();
164164
} else if !self.exceeded_phase_limit.load(Ordering::SeqCst) {
165-
println!("Warning: number of GC phases exceeds MAX_PHASES");
165+
eprintln!("Warning: number of GC phases exceeds MAX_PHASES");
166166
self.exceeded_phase_limit.store(true, Ordering::SeqCst);
167167
}
168168
}
@@ -178,7 +178,7 @@ impl Stats {
178178
}
179179
self.shared.increment_phase();
180180
} else if !self.exceeded_phase_limit.load(Ordering::SeqCst) {
181-
println!("Warning: number of GC phases exceeds MAX_PHASES");
181+
eprintln!("Warning: number of GC phases exceeds MAX_PHASES");
182182
self.exceeded_phase_limit.store(true, Ordering::SeqCst);
183183
}
184184
}
@@ -232,9 +232,7 @@ impl Stats {
232232
pub fn start_all(&self) {
233233
let counters = self.counters.lock().unwrap();
234234
if self.get_gathering_stats() {
235-
println!("Error: calling Stats.startAll() while stats running");
236-
println!(" verbosity > 0 and the harness mechanism may be conflicting");
237-
debug_assert!(false);
235+
panic!("calling Stats.startAll() while stats running");
238236
}
239237
self.shared.set_gathering_stats(true);
240238

0 commit comments

Comments
 (0)