Skip to content

Commit dc12596

Browse files
committed
Remove live_bytes, rename live_bytes_detailed to live_bytes_per_space
1 parent 4d8c288 commit dc12596

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/scheduler/scheduler.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -560,20 +560,22 @@ impl<VM: VMBinding> GCWorkScheduler<VM> {
560560
mmtk.get_plan().for_each_space(&mut |space: &dyn Space<VM>| {
561561
let space_name = space.get_name();
562562
let used_pages = space.reserved_pages();
563-
let used_bytes = space.reserved_pages() << crate::util::constants::LOG_BYTES_IN_PAGE;
564-
let live_bytes = *live_bytes_per_space.get(space_name).unwrap_or(&0);
565-
debug_assert!(
566-
live_bytes <= used_bytes,
567-
"Live bytes of objects in {} ({} bytes) is larger than used pages ({} bytes), something is wrong.",
568-
space_name, live_bytes, used_bytes
569-
);
570-
info!(
571-
"{} = {} bytes ({:04.1}% of {} used pages)",
572-
space_name,
573-
live_bytes,
574-
live_bytes as f64 * 100.0 / used_bytes as f64,
575-
used_pages
576-
);
563+
if used_pages != 0 {
564+
let used_bytes = space.reserved_pages() << crate::util::constants::LOG_BYTES_IN_PAGE;
565+
let live_bytes = *live_bytes_per_space.get(space_name).unwrap_or(&0);
566+
debug_assert!(
567+
live_bytes <= used_bytes,
568+
"Live bytes of objects in {} ({} bytes) is larger than used pages ({} bytes), something is wrong.",
569+
space_name, live_bytes, used_bytes
570+
);
571+
info!(
572+
"{} = {} bytes ({:.1}% of {} used pages)",
573+
space_name,
574+
live_bytes,
575+
live_bytes as f64 * 100.0 / used_bytes as f64,
576+
used_pages
577+
);
578+
}
577579
})
578580
}
579581

src/scheduler/worker.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ pub struct GCWorkerShared<VM: VMBinding> {
4747
/// objects, we increase the live bytes. We get this value from each worker
4848
/// at the end of a GC, and reset this counter.
4949
#[cfg(feature = "count_live_bytes_in_gc")]
50-
live_bytes: AtomicUsize,
51-
#[cfg(feature = "count_live_bytes_in_gc")]
52-
live_bytes_detailed: AtomicRefCell<HashMap<&'static str, AtomicUsize>>,
50+
live_bytes_per_space: AtomicRefCell<HashMap<&'static str, AtomicUsize>>,
5351
/// A queue of GCWork that can only be processed by the owned thread.
5452
pub designated_work: ArrayQueue<Box<dyn GCWork<VM>>>,
5553
/// Handle for stealing packets from the current worker
@@ -61,9 +59,7 @@ impl<VM: VMBinding> GCWorkerShared<VM> {
6159
Self {
6260
stat: Default::default(),
6361
#[cfg(feature = "count_live_bytes_in_gc")]
64-
live_bytes: AtomicUsize::new(0),
65-
#[cfg(feature = "count_live_bytes_in_gc")]
66-
live_bytes_detailed: AtomicRefCell::new(HashMap::new()),
62+
live_bytes_per_space: AtomicRefCell::new(HashMap::new()),
6763
designated_work: ArrayQueue::new(16),
6864
stealer,
6965
}
@@ -75,9 +71,8 @@ impl<VM: VMBinding> GCWorkerShared<VM> {
7571
use crate::vm::object_model::ObjectModel;
7672

7773
let bytes = VM::VMObjectModel::get_current_size(object);
78-
self.live_bytes.fetch_add(bytes, Ordering::Relaxed);
7974

80-
let mut map = self.live_bytes_detailed.borrow_mut();
75+
let mut map = self.live_bytes_per_space.borrow_mut();
8176
let space_name = unsafe { SFT_MAP.get_unchecked(object.to_raw_address()) }.name();
8277
match map.get(space_name) {
8378
Some(v) => {
@@ -451,7 +446,8 @@ impl<VM: VMBinding> WorkerGroup<VM> {
451446
pub fn get_and_clear_worker_live_bytes(&self) -> HashMap<&'static str, usize> {
452447
let mut ret = HashMap::new();
453448
self.workers_shared.iter().for_each(|w| {
454-
for (space_name, atomic_val) in w.live_bytes_detailed.borrow().iter() {
449+
let mut live_bytes_per_space = w.live_bytes_per_space.borrow_mut();
450+
for (space_name, atomic_val) in live_bytes_per_space.iter() {
455451
let val = atomic_val.load(Ordering::Relaxed);
456452
match ret.get_mut(space_name) {
457453
Some(sum) => {
@@ -462,6 +458,7 @@ impl<VM: VMBinding> WorkerGroup<VM> {
462458
}
463459
}
464460
}
461+
live_bytes_per_space.clear();
465462
});
466463
return ret;
467464
}

0 commit comments

Comments
 (0)