Skip to content

Commit f294948

Browse files
committed
Adding assertion for live lines in immixspace; properly counting live bytes in los
1 parent 184822c commit f294948

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/plan/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ pub trait Plan: 'static + HasSpaces + Sync + Downcast {
316316
})
317317
}
318318

319-
// Dump memory stats for the plan
319+
/// Dump memory stats for the plan
320320
#[cfg(feature = "dump_memory_stats")]
321321
fn dump_memory_stats(&self) {}
322322
}

src/policy/immix/immixspace.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,15 @@ impl<VM: VMBinding> ImmixSpace<VM> {
481481

482482
#[cfg(feature = "dump_memory_stats")]
483483
pub(crate) fn dump_memory_stats(&self) {
484+
use std::time::{SystemTime, UNIX_EPOCH};
485+
484486
#[derive(Default)]
485487
struct Dist {
486488
live_blocks: usize,
487489
live_lines: usize,
488490
}
489491
let mut dist = Dist::default();
492+
490493
for chunk in self.chunk_map.all_chunks() {
491494
if !self.address_in_space(chunk.start()) {
492495
continue;
@@ -497,26 +500,43 @@ impl<VM: VMBinding> ImmixSpace<VM> {
497500
.filter(|b| b.get_state() != BlockState::Unallocated)
498501
{
499502
dist.live_blocks += 1;
503+
504+
let line_mark_state = self.line_mark_state.load(Ordering::Acquire);
505+
let mut live_lines_in_table = 0;
506+
let mut live_lines_from_block_state = 0;
507+
508+
for line in block.lines() {
509+
if line.is_marked(line_mark_state) {
510+
live_lines_in_table += 1;
511+
}
512+
}
513+
500514
match block.get_state() {
501515
BlockState::Marked => {
502516
panic!("At this point the block should have been swept already");
503517
}
504518
BlockState::Unmarked => {
505519
// Block is unmarked and cannot be reused (has no holes)
506520
dist.live_lines += Block::LINES;
521+
live_lines_from_block_state += Block::LINES;
507522
}
508523
BlockState::Reusable { unavailable_lines } => {
509524
dist.live_lines += unavailable_lines as usize;
525+
live_lines_from_block_state += unavailable_lines as usize;
510526
}
511527
BlockState::Unallocated => {}
512528
}
529+
530+
assert_eq!(live_lines_in_table, live_lines_from_block_state);
513531
}
514532
}
515533

516-
println!(
517-
"{} immixspace",
518-
chrono::offset::Local::now().format("%Y-%m-%d %H:%M:%S")
519-
);
534+
let start = SystemTime::now();
535+
let since_the_epoch = start
536+
.duration_since(UNIX_EPOCH)
537+
.expect("Time went backwards");
538+
539+
println!("{:?} immixspace", since_the_epoch.as_millis());
520540
println!("\tLive bytes = {}", self.get_live_bytes());
521541
println!("\tReserved pages = {}", self.reserved_pages());
522542
println!(

src/policy/largeobjectspace.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ impl<VM: VMBinding> crate::policy::gc_work::PolicyTraceObject<VM> for LargeObjec
143143
fn may_move_objects<const KIND: crate::policy::gc_work::TraceKind>() -> bool {
144144
false
145145
}
146-
147-
#[cfg(feature = "dump_memory_stats")]
148-
fn post_scan_object(&self, object: ObjectReference) {
149-
self.increase_live_bytes(VM::VMObjectModel::get_current_size(object));
150-
}
151146
}
152147

153148
impl<VM: VMBinding> LargeObjectSpace<VM> {
@@ -298,6 +293,8 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
298293
break;
299294
}
300295
}
296+
#[cfg(feature = "dump_memory_stats")]
297+
self.increase_live_bytes(VM::VMObjectModel::get_current_size(object));
301298
true
302299
}
303300

@@ -337,10 +334,14 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
337334

338335
#[cfg(feature = "dump_memory_stats")]
339336
pub(crate) fn dump_memory_stats(&self) {
340-
println!(
341-
"{} los",
342-
chrono::offset::Local::now().format("%Y-%m-%d %H:%M:%S")
343-
);
337+
use std::time::{SystemTime, UNIX_EPOCH};
338+
339+
let start = SystemTime::now();
340+
let since_the_epoch = start
341+
.duration_since(UNIX_EPOCH)
342+
.expect("Time went backwards");
343+
344+
println!("{} los", since_the_epoch.as_millis());
344345
println!("\tLive bytes = {}", self.get_live_bytes());
345346
println!("\tReserved pages = {}", self.reserved_pages());
346347
println!(

0 commit comments

Comments
 (0)