Skip to content

Commit a753093

Browse files
authored
Minor changes for debugging. (#1245)
Added `MMTK::debug_print_vm_map` which prints the memory ranges of spaces. `NullableObjectReference` now implements `Clone`, `Copy`, `Display` and `Debug`. This allows the binding to print its value like `Address` and `ObjectReference`, and is useful for logging API functions that involve `NullableObjectReference` parameters.
1 parent 8a398e0 commit a753093

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/mmtk.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,4 +558,30 @@ impl<VM: VMBinding> MMTK<VM> {
558558
});
559559
ret
560560
}
561+
562+
/// Print VM maps. It will print the memory ranges used by spaces as well as some attributes of
563+
/// the spaces.
564+
///
565+
/// - "I": The space is immortal. Its objects will never die.
566+
/// - "N": The space is non-movable. Its objects will never move.
567+
///
568+
/// Arguments:
569+
/// * `out`: the place to print the VM maps.
570+
/// * `space_name`: If `None`, print all spaces;
571+
/// if `Some(n)`, only print the space whose name is `n`.
572+
pub fn debug_print_vm_maps(
573+
&self,
574+
out: &mut impl std::fmt::Write,
575+
space_name: Option<&str>,
576+
) -> Result<(), std::fmt::Error> {
577+
let mut result_so_far = Ok(());
578+
self.get_plan().for_each_space(&mut |space| {
579+
if result_so_far.is_ok()
580+
&& (space_name.is_none() || space_name == Some(space.get_name()))
581+
{
582+
result_so_far = crate::policy::space::print_vm_map(space, out);
583+
}
584+
});
585+
result_so_far
586+
}
561587
}

src/util/api_util.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use super::{Address, ObjectReference};
1515
/// It is intended for passing an `Option<ObjectReference>` values to and from native programs
1616
/// (usually C or C++) that have null pointers.
1717
#[repr(transparent)]
18+
#[derive(Clone, Copy)]
1819
pub struct NullableObjectReference(usize);
1920

2021
impl From<NullableObjectReference> for Option<ObjectReference> {
@@ -31,3 +32,15 @@ impl From<Option<ObjectReference>> for NullableObjectReference {
3132
Self(encoded)
3233
}
3334
}
35+
36+
impl std::fmt::Display for NullableObjectReference {
37+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38+
write!(f, "{:#x}", self.0)
39+
}
40+
}
41+
42+
impl std::fmt::Debug for NullableObjectReference {
43+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44+
std::fmt::Display::fmt(self, f)
45+
}
46+
}

0 commit comments

Comments
 (0)