Skip to content

Remove the unpleasant <VM as VMBinding>::Foo::bar code #652

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 6 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: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const DEBUG_MACRO_OUTPUT: bool = false;
/// For example, `GenImmix` is composed with `Gen`, `Gen` is composed with `CommonPlan`, `CommonPlan` is composed
/// with `BasePlan`.
/// * add `#[post_scan]` to any space field that has some policy-specific post_scan_object(). For objects in those spaces,
/// `post_scan_object()` in the policy will be called after `VM::VMScanning::scan_object()`.
/// `post_scan_object()` in the policy will be called after `VM::scan_object()`.
#[proc_macro_error]
#[proc_macro_derive(PlanTraceObject, attributes(trace, post_scan, fallback_trace))]
pub fn derive_plan_trace_object(input: TokenStream) -> TokenStream {
Expand Down
2 changes: 1 addition & 1 deletion macros/src/plan_trace_object_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) fn generate_trace_object<'a>(
}
} else {
quote! {
<VM::VMActivePlan as crate::vm::ActivePlan<VM>>::vm_trace_object::<Q>(__mmtk_queue, __mmtk_objref, __mmtk_worker)
VM::vm_trace_object::<Q>(__mmtk_queue, __mmtk_objref, __mmtk_worker)
}
};

Expand Down
21 changes: 6 additions & 15 deletions src/memory_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::util::heap::layout::vm_layout_constants::HEAP_END;
use crate::util::heap::layout::vm_layout_constants::HEAP_START;
use crate::util::opaque_pointer::*;
use crate::util::{Address, ObjectReference};
use crate::vm::ReferenceGlue;
use crate::vm::VMBinding;
use std::sync::atomic::Ordering;

Expand Down Expand Up @@ -251,17 +250,16 @@ pub fn free_with_size<VM: VMBinding>(mmtk: &MMTK<VM>, addr: Address, old_size: u
/// However, if a binding uses counted malloc (which won't poll for GC), they may want to poll for GC manually.
/// This function should only be used by mutator threads.
pub fn gc_poll<VM: VMBinding>(mmtk: &MMTK<VM>, tls: VMMutatorThread) {
use crate::vm::{ActivePlan, Collection};
debug_assert!(
VM::VMActivePlan::is_mutator(tls.0),
VM::is_mutator(tls.0),
"gc_poll() can only be called by a mutator thread."
);

let plan = mmtk.get_plan();
if plan.should_trigger_gc_when_heap_is_full() && plan.poll(false, None) {
debug!("Collection required");
assert!(plan.is_initialized(), "GC is not allowed here: collection is not initialized (did you call initialize_collection()?).");
VM::VMCollection::block_for_gc(tls);
VM::block_for_gc(tls);
}
}

Expand Down Expand Up @@ -583,10 +581,7 @@ pub fn harness_end<VM: VMBinding>(mmtk: &'static MMTK<VM>) {
/// Arguments:
/// * `mmtk`: A reference to an MMTk instance
/// * `object`: The object that has a finalizer
pub fn add_finalizer<VM: VMBinding>(
mmtk: &'static MMTK<VM>,
object: <VM::VMReferenceGlue as ReferenceGlue<VM>>::FinalizableType,
) {
pub fn add_finalizer<VM: VMBinding>(mmtk: &'static MMTK<VM>, object: VM::FinalizableType) {
if *mmtk.options.no_finalizer {
warn!("add_finalizer() is called when no_finalizer = true");
}
Expand All @@ -602,9 +597,7 @@ pub fn add_finalizer<VM: VMBinding>(
///
/// Arguments:
/// * `mmtk`: A reference to an MMTk instance.
pub fn get_finalized_object<VM: VMBinding>(
mmtk: &'static MMTK<VM>,
) -> Option<<VM::VMReferenceGlue as ReferenceGlue<VM>>::FinalizableType> {
pub fn get_finalized_object<VM: VMBinding>(mmtk: &'static MMTK<VM>) -> Option<VM::FinalizableType> {
if *mmtk.options.no_finalizer {
warn!("get_finalized_object() is called when no_finalizer = true");
}
Expand All @@ -622,9 +615,7 @@ pub fn get_finalized_object<VM: VMBinding>(
///
/// Arguments:
/// * `mmtk`: A reference to an MMTk instance.
pub fn get_all_finalizers<VM: VMBinding>(
mmtk: &'static MMTK<VM>,
) -> Vec<<VM::VMReferenceGlue as ReferenceGlue<VM>>::FinalizableType> {
pub fn get_all_finalizers<VM: VMBinding>(mmtk: &'static MMTK<VM>) -> Vec<VM::FinalizableType> {
if *mmtk.options.no_finalizer {
warn!("get_all_finalizers() is called when no_finalizer = true");
}
Expand All @@ -644,7 +635,7 @@ pub fn get_all_finalizers<VM: VMBinding>(
pub fn get_finalizers_for<VM: VMBinding>(
mmtk: &'static MMTK<VM>,
object: ObjectReference,
) -> Vec<<VM::VMReferenceGlue as ReferenceGlue<VM>>::FinalizableType> {
) -> Vec<VM::FinalizableType> {
if *mmtk.options.no_finalizer {
warn!("get_finalizers() is called when no_finalizer = true");
}
Expand Down
8 changes: 2 additions & 6 deletions src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::util::options::Options;
use crate::util::reference_processor::ReferenceProcessors;
#[cfg(feature = "sanity")]
use crate::util::sanity::sanity_checker::SanityChecker;
use crate::vm::ReferenceGlue;
use crate::vm::VMBinding;
use std::default::Default;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -82,8 +81,7 @@ pub struct MMTK<VM: VMBinding> {
pub(crate) options: Arc<Options>,
pub(crate) plan: Box<dyn Plan<VM = VM>>,
pub(crate) reference_processors: ReferenceProcessors,
pub(crate) finalizable_processor:
Mutex<FinalizableProcessor<<VM::VMReferenceGlue as ReferenceGlue<VM>>::FinalizableType>>,
pub(crate) finalizable_processor: Mutex<FinalizableProcessor<VM::FinalizableType>>,
pub(crate) scheduler: Arc<GCWorkScheduler<VM>>,
#[cfg(feature = "sanity")]
pub(crate) sanity_checker: Mutex<SanityChecker>,
Expand Down Expand Up @@ -123,9 +121,7 @@ impl<VM: VMBinding> MMTK<VM> {
options,
plan,
reference_processors: ReferenceProcessors::new(),
finalizable_processor: Mutex::new(FinalizableProcessor::<
<VM::VMReferenceGlue as ReferenceGlue<VM>>::FinalizableType,
>::new()),
finalizable_processor: Mutex::new(FinalizableProcessor::<VM::FinalizableType>::new()),
scheduler,
#[cfg(feature = "sanity")]
sanity_checker: Mutex::new(SanityChecker::new()),
Expand Down
4 changes: 2 additions & 2 deletions src/plan/generational/copying/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::Allocators;
use crate::util::alloc::BumpAllocator;
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::{ObjectModel, VMBinding};
use crate::vm::VMBinding;
use crate::MMTK;

pub fn gencopy_mutator_prepare<VM: VMBinding>(_mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn create_gencopy_mutator<VM: VMBinding>(
allocators: Allocators::<VM>::new(mutator_tls, &*mmtk.plan, &config.space_mapping),
barrier: Box::new(ObjectRememberingBarrier::<GenNurseryProcessEdges<VM>>::new(
mmtk,
*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
*VM::GLOBAL_LOG_BIT_SPEC,
)),
mutator_tls,
config,
Expand Down
5 changes: 2 additions & 3 deletions src/plan/generational/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::util::options::Options;
use crate::util::statistics::counter::EventCounter;
use crate::util::ObjectReference;
use crate::util::VMWorkerThread;
use crate::vm::{ObjectModel, VMBinding};
use crate::vm::VMBinding;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -119,8 +119,7 @@ impl<VM: VMBinding> Gen<VM> {
/// Returns `true` if the nursery has grown to the extent that it may not be able to be copied
/// into the mature space.
fn virtual_memory_exhausted<P: Plan>(&self, plan: &P) -> bool {
((plan.get_collection_reserved_pages() as f64
* VM::VMObjectModel::VM_WORST_CASE_COPY_EXPANSION) as usize)
((plan.get_collection_reserved_pages() as f64 * VM::VM_WORST_CASE_COPY_EXPANSION) as usize)
> plan.get_mature_physical_pages_available()
}

Expand Down
4 changes: 2 additions & 2 deletions src/plan/generational/immix/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::Allocators;
use crate::util::alloc::BumpAllocator;
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::{ObjectModel, VMBinding};
use crate::vm::VMBinding;
use crate::MMTK;

pub fn genimmix_mutator_prepare<VM: VMBinding>(_mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {}
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn create_genimmix_mutator<VM: VMBinding>(
allocators: Allocators::<VM>::new(mutator_tls, &*mmtk.plan, &config.space_mapping),
barrier: Box::new(ObjectRememberingBarrier::<GenNurseryProcessEdges<VM>>::new(
mmtk,
*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
*VM::GLOBAL_LOG_BIT_SPEC,
)),
mutator_tls,
config,
Expand Down
3 changes: 1 addition & 2 deletions src/plan/generational/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::policy::space::Space;
use crate::util::alloc::AllocatorSelector;
use crate::util::metadata::side_metadata::SideMetadataContext;
use crate::util::metadata::side_metadata::SideMetadataSpec;
use crate::vm::ObjectModel;
use crate::vm::VMBinding;
use crate::Plan;

Expand Down Expand Up @@ -58,7 +57,7 @@ pub const GEN_CONSTRAINTS: PlanConstraints = PlanConstraints {
/// So if a plan calls this, it should not call SideMetadataContext::new_global_specs() again.
pub fn new_generational_global_metadata_specs<VM: VMBinding>() -> Vec<SideMetadataSpec> {
let specs = if ACTIVE_BARRIER == BarrierSelector::ObjectBarrier {
crate::util::metadata::extract_side_metadata(&[*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC])
crate::util::metadata::extract_side_metadata(&[*VM::GLOBAL_LOG_BIT_SPEC])
} else {
vec![]
};
Expand Down
9 changes: 4 additions & 5 deletions src/plan/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::util::options::PlanSelector;
use crate::util::statistics::stats::Stats;
use crate::util::ObjectReference;
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::*;
use downcast_rs::Downcast;
use enum_map::EnumMap;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
Expand Down Expand Up @@ -577,7 +576,7 @@ impl<VM: VMBinding> BasePlan<VM> {
self.user_triggered_collection
.store(true, Ordering::Relaxed);
self.gc_requester.request();
VM::VMCollection::block_for_gc(tls);
VM::block_for_gc(tls);
}
}

Expand Down Expand Up @@ -663,7 +662,7 @@ impl<VM: VMBinding> BasePlan<VM> {
return self.vm_space.trace_object(queue, object);
}

VM::VMActivePlan::vm_trace_object::<Q>(queue, object, worker)
VM::vm_trace_object::<Q>(queue, object, worker)
}

pub fn prepare(&mut self, _tls: VMWorkerThread, _full_heap: bool) {
Expand Down Expand Up @@ -1025,8 +1024,8 @@ pub trait PlanTraceObject<VM: VMBinding> {
worker: &mut GCWorker<VM>,
) -> ObjectReference;

/// Post-scan objects in the plan. Each object is scanned by `VM::VMScanning::scan_object()`, and this function
/// will be called after the `VM::VMScanning::scan_object()` as a hook to invoke possible policy post scan method.
/// Post-scan objects in the plan. Each object is scanned by `VM::scan_object()`, and this function
/// will be called after the `VM::scan_object()` as a hook to invoke possible policy post scan method.
/// If a plan does not have any policy that needs post scan, this method can be implemented as empty.
/// If a plan has a policy that has some policy specific behaviors for scanning (e.g. mark lines in Immix),
/// this method should also invoke those policy specific methods for objects in that space.
Expand Down
6 changes: 2 additions & 4 deletions src/plan/markcompact/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use crate::scheduler::gc_work::*;
use crate::scheduler::GCWork;
use crate::scheduler::GCWorker;
use crate::scheduler::WorkBucketStage;
use crate::vm::ActivePlan;
use crate::vm::Scanning;
use crate::vm::VMBinding;
use crate::MMTK;
use std::marker::PhantomData;
Expand Down Expand Up @@ -40,15 +38,15 @@ impl<VM: VMBinding> GCWork<VM> for UpdateReferences<VM> {
#[inline]
fn do_work(&mut self, _worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM>) {
// The following needs to be done right before the second round of root scanning
VM::VMScanning::prepare_for_roots_re_scanning();
VM::prepare_for_roots_re_scanning();
mmtk.plan.base().prepare_for_stack_scanning();
#[cfg(feature = "extreme_assertions")]
crate::util::edge_logger::reset();

// TODO investigate why the following will create duplicate edges
// scheduler.work_buckets[WorkBucketStage::RefForwarding]
// .add(ScanStackRoots::<ForwardingProcessEdges<VM>>::new());
for mutator in VM::VMActivePlan::mutators() {
for mutator in VM::mutators() {
mmtk.scheduler.work_buckets[WorkBucketStage::SecondRoots]
.add(ScanStackRoot::<ForwardingProcessEdges<VM>>(mutator));
}
Expand Down
7 changes: 3 additions & 4 deletions src/policy/copyspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ impl<VM: VMBinding> CopySpace<VM> {
heap: &mut HeapMeta,
) -> Self {
let local_specs = extract_side_metadata(&[
*VM::VMObjectModel::LOCAL_FORWARDING_BITS_SPEC,
*VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC,
*VM::LOCAL_FORWARDING_BITS_SPEC,
*VM::LOCAL_FORWARDING_POINTER_SPEC,
]);
let common = CommonSpace::new(
SpaceOptions {
Expand Down Expand Up @@ -179,8 +179,7 @@ impl<VM: VMBinding> CopySpace<VM> {
// Clear the metadata if we are using side forwarding status table. Otherwise
// objects may inherit forwarding status from the previous GC.
// TODO: Fix performance.
if let MetadataSpec::OnSide(side_forwarding_status_table) =
*<VM::VMObjectModel as ObjectModel<VM>>::LOCAL_FORWARDING_BITS_SPEC
if let MetadataSpec::OnSide(side_forwarding_status_table) = *VM::LOCAL_FORWARDING_BITS_SPEC
{
side_metadata::bzero_metadata(
&side_forwarding_status_table,
Expand Down
7 changes: 3 additions & 4 deletions src/policy/immix/defrag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ impl Defrag {

// Calculate available free space for defragmentation.

let mut available_clean_pages_for_defrag = VM::VMActivePlan::global().get_total_pages()
as isize
- VM::VMActivePlan::global().get_reserved_pages() as isize
let mut available_clean_pages_for_defrag = VM::global().get_total_pages() as isize
- VM::global().get_reserved_pages() as isize
+ self.defrag_headroom_pages(space) as isize;
if available_clean_pages_for_defrag < 0 {
available_clean_pages_for_defrag = 0
Expand All @@ -127,7 +126,7 @@ impl Defrag {

self.available_clean_pages_for_defrag.store(
available_clean_pages_for_defrag as usize
+ VM::VMActivePlan::global().get_collection_reserved_pages(),
+ VM::global().get_collection_reserved_pages(),
Ordering::Release,
);
}
Expand Down
16 changes: 8 additions & 8 deletions src/policy/immix/immixspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ impl<VM: VMBinding> ImmixSpace<VM> {
MetadataSpec::OnSide(Block::DEFRAG_STATE_TABLE),
MetadataSpec::OnSide(Block::MARK_TABLE),
MetadataSpec::OnSide(ChunkMap::ALLOC_TABLE),
*VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
*VM::LOCAL_MARK_BIT_SPEC,
]
} else {
vec![
MetadataSpec::OnSide(Line::MARK_TABLE),
MetadataSpec::OnSide(Block::DEFRAG_STATE_TABLE),
MetadataSpec::OnSide(Block::MARK_TABLE),
MetadataSpec::OnSide(ChunkMap::ALLOC_TABLE),
*VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
*VM::LOCAL_MARK_BIT_SPEC,
]
})
}
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
pub fn prepare(&mut self, major_gc: bool) {
if major_gc {
// Update mark_state
if VM::VMObjectModel::LOCAL_MARK_BIT_SPEC.is_on_side() {
if VM::LOCAL_MARK_BIT_SPEC.is_on_side() {
self.mark_state = Self::MARKED_STATE;
} else {
// For header metadata, we use cyclic mark bits.
Expand Down Expand Up @@ -503,7 +503,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
fn attempt_mark(&self, object: ObjectReference, mark_state: u8) -> bool {
loop {
let old_value = load_metadata::<VM>(
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::LOCAL_MARK_BIT_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand All @@ -513,7 +513,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
}

if compare_exchange_metadata::<VM>(
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::LOCAL_MARK_BIT_SPEC,
object,
old_value as usize,
mark_state as usize,
Expand All @@ -531,7 +531,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
#[inline(always)]
fn is_marked(&self, object: ObjectReference, mark_state: u8) -> bool {
let old_value = load_metadata::<VM>(
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::LOCAL_MARK_BIT_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand Down Expand Up @@ -610,7 +610,7 @@ impl<VM: VMBinding> PrepareBlockState<VM> {
/// Clear object mark table
#[inline(always)]
fn reset_object_mark(chunk: Chunk) {
if let MetadataSpec::OnSide(side) = *VM::VMObjectModel::LOCAL_MARK_BIT_SPEC {
if let MetadataSpec::OnSide(side) = *VM::LOCAL_MARK_BIT_SPEC {
side_metadata::bzero_metadata(&side, chunk.start(), Chunk::BYTES);
}
}
Expand Down Expand Up @@ -683,7 +683,7 @@ impl<VM: VMBinding> PolicyCopyContext for ImmixCopyContext<VM> {
fn post_copy(&mut self, obj: ObjectReference, _bytes: usize) {
// Mark the object
store_metadata::<VM>(
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::LOCAL_MARK_BIT_SPEC,
obj,
self.get_space().mark_state as usize,
None,
Expand Down
4 changes: 2 additions & 2 deletions src/policy/immix/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl Line {
#[inline]
pub fn mark_lines_for_object<VM: VMBinding>(object: ObjectReference, state: u8) -> usize {
debug_assert!(!super::BLOCK_ONLY);
let start = VM::VMObjectModel::object_start_ref(object);
let end = start + VM::VMObjectModel::get_current_size(object);
let start = VM::object_start_ref(object);
let end = start + VM::get_current_size(object);
let start_line = Line::from(Line::align(start));
let mut end_line = Line::from(Line::align(end));
if !Line::is_aligned(end) {
Expand Down
Loading