Skip to content

# of objects traced / moved #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ immix_non_moving = []
# if `immix_non_moving` is in use.
sticky_immix_non_moving_nursery = []

# Statistics about how many objects get moved in defrag GCs for Immix
objects_moved_stats = []

# Reduce block size for ImmixSpace. This mitigates fragmentation when defrag is disabled.
immix_smaller_block = []
Expand Down
8 changes: 8 additions & 0 deletions src/policy/immix/immixspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use super::line::*;
use super::{block::*, defrag::Defrag};
use crate::plan::VectorObjectQueue;
use crate::policy::gc_work::{TraceKind, TRACE_KIND_TRANSITIVE_PIN};
#[cfg(feature = "objects_moved_stats")]
use crate::policy::immix::IMMIXSPACE_OBJECTS_MARKED;
use crate::policy::sft::GCWorkerMutRef;
use crate::policy::sft::SFT;
use crate::policy::sft_map::SFTMap;
Expand All @@ -17,6 +19,7 @@ use crate::util::linear_scan::{Region, RegionIterator};
use crate::util::metadata::side_metadata::SideMetadataSpec;
#[cfg(feature = "vo_bit")]
use crate::util::metadata::vo_bit;

use crate::util::metadata::{self, MetadataSpec};
use crate::util::object_forwarding;
use crate::util::{Address, ObjectReference};
Expand Down Expand Up @@ -711,6 +714,11 @@ impl<VM: VMBinding> ImmixSpace<VM> {
break;
}
}

#[cfg(feature = "objects_moved_stats")]
unsafe {
IMMIXSPACE_OBJECTS_MARKED.fetch_add(1, Ordering::SeqCst);
}
true
}

Expand Down
5 changes: 5 additions & 0 deletions src/policy/immix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub use immixspace::*;

use crate::policy::immix::block::Block;
use crate::util::linear_scan::Region;
#[cfg(feature = "objects_moved_stats")]
use std::sync::atomic::AtomicUsize;

/// The max object size for immix: half of a block
pub const MAX_IMMIX_OBJECT_SIZE: usize = Block::BYTES >> 1;
Expand Down Expand Up @@ -38,6 +40,9 @@ pub const NEVER_MOVE_OBJECTS: bool = !DEFRAG && !PREFER_COPY_ON_NURSERY_GC;
/// Otherwise, do it at mark time.
pub const MARK_LINE_AT_SCAN_TIME: bool = true;

#[cfg(feature = "objects_moved_stats")]
pub static mut IMMIXSPACE_OBJECTS_MARKED: AtomicUsize = AtomicUsize::new(0);

macro_rules! validate {
($x: expr) => { assert!($x, stringify!($x)) };
($x: expr => $y: expr) => { if $x { assert!($y, stringify!($x implies $y)) } };
Expand Down
7 changes: 7 additions & 0 deletions src/policy/markcompactspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use super::space::{CommonSpace, Space};
use crate::plan::VectorObjectQueue;
use crate::policy::gc_work::{TraceKind, TRACE_KIND_TRANSITIVE_PIN};
use crate::policy::sft::GCWorkerMutRef;
#[cfg(feature = "objects_moved_stats")]
use crate::policy::OBJECTS_COPIED;
use crate::scheduler::GCWorker;
use crate::util::alloc::allocator::align_allocation_no_fill;
use crate::util::constants::LOG_BYTES_IN_WORD;
Expand Down Expand Up @@ -398,6 +400,11 @@ impl<VM: VMBinding> MarkCompactSpace<VM> {
trace!(" copy from {} to {}", obj, new_object);
let end_of_new_object =
VM::VMObjectModel::copy_to(obj, new_object, Address::ZERO);

#[cfg(feature = "objects_moved_stats")]
unsafe {
OBJECTS_COPIED.fetch_add(1, Ordering::SeqCst);
}
// update VO bit,
vo_bit::set_vo_bit::<VM>(new_object);
to = new_object.to_object_start::<VM>() + copied_size;
Expand Down
8 changes: 8 additions & 0 deletions src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ pub mod markcompactspace;
pub mod marksweepspace;
#[cfg(feature = "vm_space")]
pub mod vmspace;

/// Keep track of stats about # of objects scanned and copied
#[cfg(feature = "objects_moved_stats")]
use std::sync::atomic::AtomicUsize;
#[cfg(feature = "objects_moved_stats")]
pub static mut OBJECTS_COPIED: AtomicUsize = AtomicUsize::new(0);
#[cfg(feature = "objects_moved_stats")]
pub static mut OBJECTS_SCANNED: AtomicUsize = AtomicUsize::new(0);
25 changes: 25 additions & 0 deletions src/scheduler/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ use super::*;
use crate::global_state::GcStatus;
use crate::plan::ObjectsClosure;
use crate::plan::VectorObjectQueue;
#[cfg(feature = "objects_moved_stats")]
use crate::policy::immix::IMMIXSPACE_OBJECTS_MARKED;
#[cfg(feature = "objects_moved_stats")]
use crate::policy::{OBJECTS_COPIED, OBJECTS_SCANNED};
use crate::util::*;
use crate::vm::edge_shape::Edge;
use crate::vm::*;
use crate::*;
#[cfg(feature = "objects_moved_stats")]
use atomic::Ordering;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};

Expand Down Expand Up @@ -226,6 +232,17 @@ impl<VM: VMBinding> GCWork<VM> for EndOfGC {
self.elapsed.as_millis()
);

#[cfg(feature = "objects_moved_stats")]
unsafe {
info!(
"# of objects scanned: {:?}; # of immixspace objects marked: {:?}, # of objects copied: {:?}",
OBJECTS_SCANNED, IMMIXSPACE_OBJECTS_MARKED, OBJECTS_COPIED
);
OBJECTS_SCANNED.store(0, Ordering::SeqCst);
OBJECTS_COPIED.store(0, Ordering::SeqCst);
IMMIXSPACE_OBJECTS_MARKED.store(0, Ordering::SeqCst);
}

#[cfg(feature = "count_live_bytes_in_gc")]
{
let live_bytes = mmtk.state.get_live_bytes_in_last_gc();
Expand Down Expand Up @@ -836,6 +853,10 @@ pub trait ScanObjectsWork<VM: VMBinding>: GCWork<VM> + Sized {
trace!("Scan object (edge) {}", object);
// If an object supports edge-enqueuing, we enqueue its edges.
<VM as VMBinding>::VMScanning::scan_object(tls, object, &mut closure);
#[cfg(feature = "objects_moved_stats")]
unsafe {
OBJECTS_SCANNED.fetch_add(1, Ordering::SeqCst);
}
self.post_scan_object(object);
} else {
// If an object does not support edge-enqueuing, we have to use
Expand Down Expand Up @@ -865,6 +886,10 @@ pub trait ScanObjectsWork<VM: VMBinding>: GCWork<VM> + Sized {
object,
object_tracer,
);
#[cfg(feature = "objects_moved_stats")]
unsafe {
OBJECTS_SCANNED.fetch_add(1, Ordering::SeqCst);
}
self.post_scan_object(object);
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/util/object_forwarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const FORWARDING_POINTER_MASK: usize = 0x00ff_ffff_ffff_fff8;
#[cfg(target_pointer_width = "32")]
const FORWARDING_POINTER_MASK: usize = 0xffff_fffc;

#[cfg(feature = "objects_moved_stats")]
use crate::policy::OBJECTS_COPIED;

/// Attempt to become the worker thread who will forward the object.
/// The successful worker will set the object forwarding bits to BEING_FORWARDED, preventing other workers from forwarding the same object.
pub fn attempt_to_forward<VM: VMBinding>(object: ObjectReference) -> u8 {
Expand Down Expand Up @@ -80,6 +83,10 @@ pub fn forward_object<VM: VMBinding>(
copy_context: &mut GCWorkerCopyContext<VM>,
) -> ObjectReference {
let new_object = VM::VMObjectModel::copy(object, semantics, copy_context);
#[cfg(feature = "objects_moved_stats")]
unsafe {
OBJECTS_COPIED.fetch_add(1, Ordering::SeqCst);
}
if let Some(shift) = forwarding_bits_offset_in_forwarding_pointer::<VM>() {
VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC.store_atomic::<VM, usize>(
object,
Expand Down