Skip to content

Use mark sweep space as the non moving space #1100

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 17 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
6 changes: 6 additions & 0 deletions docs/userguide/src/tutorial/code/mygc_semispace/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ impl<VM: VMBinding> Plan for MyGC<VM> {
}
// ANCHOR_END: release

// ANCHOR: end_of_gc
fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.common.end_of_gc(tls);
}
// ANCHOR_END: end_of_gc

// Modify
// ANCHOR: plan_get_collection_reserve
fn get_collection_reserved_pages(&self) -> usize {
Expand Down
10 changes: 6 additions & 4 deletions docs/userguide/src/tutorial/code/mygc_semispace/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ use enum_map::EnumMap;

// Add
pub fn mygc_mutator_prepare<VM: VMBinding>(
_mutator: &mut Mutator<VM>,
_tls: VMWorkerThread,
mutator: &mut Mutator<VM>,
tls: VMWorkerThread,
) {
// Do nothing
crate::plan::mutator_context::common_prepare_func::<VM>(mutator, tls);
}

// Add
// ANCHOR: release
pub fn mygc_mutator_release<VM: VMBinding>(
mutator: &mut Mutator<VM>,
_tls: VMWorkerThread,
tls: VMWorkerThread,
) {
// rebind the allocation bump pointer to the appropriate semispace
let bump_allocator = unsafe {
Expand All @@ -46,6 +46,8 @@ pub fn mygc_mutator_release<VM: VMBinding>(
.unwrap()
.tospace(),
);

crate::plan::mutator_context::common_release_func::<VM>(mutator, tls);
}
// ANCHOR_END: release

Expand Down
3 changes: 2 additions & 1 deletion src/plan/generational/copying/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ impl<VM: VMBinding> Plan for GenCopy<VM> {
}
}

fn end_of_gc(&mut self, _tls: VMWorkerThread) {
fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.gen
.set_next_gc_full_heap(CommonGenPlan::should_next_gc_be_full_heap(self));
self.gen.common.end_of_gc(tls);
}

fn get_collection_reserved_pages(&self) -> usize {
Expand Down
8 changes: 5 additions & 3 deletions src/plan/generational/copying/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use super::GenCopy;
use crate::plan::barriers::ObjectBarrier;
use crate::plan::generational::barrier::GenObjectBarrierSemantics;
use crate::plan::generational::create_gen_space_mapping;
use crate::plan::mutator_context::unreachable_prepare_func;
use crate::plan::mutator_context::Mutator;
use crate::plan::mutator_context::MutatorConfig;
use crate::plan::mutator_context::{common_prepare_func, common_release_func};
use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::Allocators;
use crate::util::alloc::BumpAllocator;
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::VMBinding;
use crate::MMTK;

pub fn gencopy_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
pub fn gencopy_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
// reset nursery allocator
let bump_allocator = unsafe {
mutator
Expand All @@ -23,6 +23,8 @@ pub fn gencopy_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: V
.downcast_mut::<BumpAllocator<VM>>()
.unwrap();
bump_allocator.reset();

common_release_func(mutator, tls);
}

pub fn create_gencopy_mutator<VM: VMBinding>(
Expand All @@ -36,7 +38,7 @@ pub fn create_gencopy_mutator<VM: VMBinding>(
mmtk.get_plan(),
&gencopy.gen.nursery,
)),
prepare_func: &unreachable_prepare_func,
prepare_func: &common_prepare_func,
release_func: &gencopy_mutator_release,
};

Expand Down
3 changes: 2 additions & 1 deletion src/plan/generational/immix/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ impl<VM: VMBinding> Plan for GenImmix<VM> {
.store(full_heap, Ordering::Relaxed);
}

fn end_of_gc(&mut self, _tls: VMWorkerThread) {
fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.gen
.set_next_gc_full_heap(CommonGenPlan::should_next_gc_be_full_heap(self));
self.gen.common.end_of_gc(tls);
}

fn get_collection_reserved_pages(&self) -> usize {
Expand Down
8 changes: 5 additions & 3 deletions src/plan/generational/immix/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use crate::plan::barriers::ObjectBarrier;
use crate::plan::generational::barrier::GenObjectBarrierSemantics;
use crate::plan::generational::create_gen_space_mapping;
use crate::plan::generational::immix::GenImmix;
use crate::plan::mutator_context::unreachable_prepare_func;
use crate::plan::mutator_context::Mutator;
use crate::plan::mutator_context::MutatorConfig;
use crate::plan::mutator_context::{common_prepare_func, common_release_func};
use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::Allocators;
use crate::util::alloc::BumpAllocator;
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::VMBinding;
use crate::MMTK;

pub fn genimmix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
pub fn genimmix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
// reset nursery allocator
let bump_allocator = unsafe {
mutator
Expand All @@ -23,6 +23,8 @@ pub fn genimmix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls:
.downcast_mut::<BumpAllocator<VM>>()
.unwrap();
bump_allocator.reset();

common_release_func(mutator, tls);
}

pub fn create_genimmix_mutator<VM: VMBinding>(
Expand All @@ -36,7 +38,7 @@ pub fn create_genimmix_mutator<VM: VMBinding>(
mmtk.get_plan(),
&genimmix.gen.nursery,
)),
prepare_func: &unreachable_prepare_func,
prepare_func: &common_prepare_func,
release_func: &genimmix_mutator_release,
};

Expand Down
19 changes: 14 additions & 5 deletions src/plan/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::plan::tracing::ObjectQueue;
use crate::plan::Mutator;
use crate::policy::immortalspace::ImmortalSpace;
use crate::policy::largeobjectspace::LargeObjectSpace;
use crate::policy::marksweepspace::native_ms::MarkSweepSpace;
use crate::policy::space::{PlanCreateSpaceArgs, Space};
#[cfg(feature = "vm_space")]
use crate::policy::vmspace::VMSpace;
Expand Down Expand Up @@ -197,7 +198,7 @@ pub trait Plan: 'static + HasSpaces + Sync + Downcast {

/// Inform the plan about the end of a GC. It is guaranteed that there is no further work for this GC.
/// This is invoked once per GC by one worker thread. `tls` is the worker thread that executes this method.
fn end_of_gc(&mut self, _tls: VMWorkerThread) {}
fn end_of_gc(&mut self, _tls: VMWorkerThread);

/// Notify the plan that an emergency collection will happen. The plan should try to free as much memory as possible.
/// The default implementation will force a full heap collection for generational plans.
Expand Down Expand Up @@ -521,6 +522,10 @@ impl<VM: VMBinding> BasePlan<VM> {
self.vm_space.release();
}

pub fn end_of_gc(&mut self, _tls: VMWorkerThread) {
// Not doing anything special here.
}

pub(crate) fn collection_required<P: Plan>(&self, plan: &P, space_full: bool) -> bool {
let stress_force_gc =
crate::util::heap::gc_trigger::GCTrigger::<VM>::should_do_stress_gc_inner(
Expand Down Expand Up @@ -561,9 +566,8 @@ pub struct CommonPlan<VM: VMBinding> {
pub immortal: ImmortalSpace<VM>,
#[space]
pub los: LargeObjectSpace<VM>,
// TODO: We should use a marksweep space for nonmoving.
#[space]
pub nonmoving: ImmortalSpace<VM>,
pub nonmoving: MarkSweepSpace<VM>,
#[parent]
pub base: BasePlan<VM>,
}
Expand All @@ -580,7 +584,7 @@ impl<VM: VMBinding> CommonPlan<VM> {
args.get_space_args("los", true, VMRequest::discontiguous()),
false,
),
nonmoving: ImmortalSpace::new(args.get_space_args(
nonmoving: MarkSweepSpace::new(args.get_space_args(
"nonmoving",
true,
VMRequest::discontiguous(),
Expand Down Expand Up @@ -631,6 +635,11 @@ impl<VM: VMBinding> CommonPlan<VM> {
self.base.release(tls, full_heap)
}

pub fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.nonmoving.end_of_gc();
self.base.end_of_gc(tls);
}

pub fn get_immortal(&self) -> &ImmortalSpace<VM> {
&self.immortal
}
Expand All @@ -639,7 +648,7 @@ impl<VM: VMBinding> CommonPlan<VM> {
&self.los
}

pub fn get_nonmoving(&self) -> &ImmortalSpace<VM> {
pub fn get_nonmoving(&self) -> &MarkSweepSpace<VM> {
&self.nonmoving
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/plan/immix/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub const IMMIX_CONSTRAINTS: PlanConstraints = PlanConstraints {
moves_objects: crate::policy::immix::DEFRAG,
// Max immix object size is half of a block.
max_non_los_default_alloc_bytes: crate::policy::immix::MAX_IMMIX_OBJECT_SIZE,
needs_prepare_mutator: false,
..PlanConstraints::default()
};

Expand Down Expand Up @@ -97,6 +96,10 @@ impl<VM: VMBinding> Plan for Immix<VM> {
.store(self.immix_space.release(true), Ordering::Relaxed);
}

fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.common.end_of_gc(tls);
}

fn get_collection_reserved_pages(&self) -> usize {
self.immix_space.defrag_headroom_pages()
}
Expand Down
8 changes: 5 additions & 3 deletions src/plan/immix/mutator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::Immix;
use crate::plan::mutator_context::create_allocator_mapping;
use crate::plan::mutator_context::create_space_mapping;
use crate::plan::mutator_context::unreachable_prepare_func;
use crate::plan::mutator_context::Mutator;
use crate::plan::mutator_context::MutatorConfig;
use crate::plan::mutator_context::ReservedAllocators;
use crate::plan::mutator_context::{common_prepare_func, common_release_func};
use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::{AllocatorSelector, Allocators};
use crate::util::alloc::ImmixAllocator;
Expand All @@ -16,7 +16,7 @@ use crate::{
};
use enum_map::EnumMap;

pub fn immix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
pub fn immix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
let immix_allocator = unsafe {
mutator
.allocators
Expand All @@ -25,6 +25,8 @@ pub fn immix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMW
.downcast_mut::<ImmixAllocator<VM>>()
.unwrap();
immix_allocator.reset();

common_release_func(mutator, tls)
}

pub(in crate::plan) const RESERVED_ALLOCATORS: ReservedAllocators = ReservedAllocators {
Expand Down Expand Up @@ -52,7 +54,7 @@ pub fn create_immix_mutator<VM: VMBinding>(
vec.push((AllocatorSelector::Immix(0), &immix.immix_space));
vec
}),
prepare_func: &unreachable_prepare_func,
prepare_func: &common_prepare_func,
release_func: &immix_mutator_release,
};

Expand Down
5 changes: 4 additions & 1 deletion src/plan/markcompact/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub const MARKCOMPACT_CONSTRAINTS: PlanConstraints = PlanConstraints {
needs_forward_after_liveness: true,
max_non_los_default_alloc_bytes:
crate::plan::plan_constraints::MAX_NON_LOS_ALLOC_BYTES_COPYING_PLAN,
needs_prepare_mutator: false,
..PlanConstraints::default()
};

Expand Down Expand Up @@ -73,6 +72,10 @@ impl<VM: VMBinding> Plan for MarkCompact<VM> {
self.mc_space.release();
}

fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.common.end_of_gc(tls);
}

fn get_allocator_mapping(&self) -> &'static EnumMap<AllocationSemantics, AllocatorSelector> {
&ALLOCATOR_MAPPING
}
Expand Down
15 changes: 7 additions & 8 deletions src/plan/markcompact/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::MarkCompact;
use crate::plan::barriers::NoBarrier;
use crate::plan::mutator_context::create_allocator_mapping;
use crate::plan::mutator_context::create_space_mapping;
use crate::plan::mutator_context::unreachable_prepare_func;
use crate::plan::mutator_context::Mutator;
use crate::plan::mutator_context::MutatorConfig;
use crate::plan::mutator_context::ReservedAllocators;
use crate::plan::mutator_context::{common_prepare_func, common_release_func};
use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::{AllocatorSelector, Allocators};
use crate::util::alloc::MarkCompactAllocator;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn create_markcompact_mutator<VM: VMBinding>(
vec.push((AllocatorSelector::MarkCompact(0), markcompact.mc_space()));
vec
}),
prepare_func: &unreachable_prepare_func,
prepare_func: &common_prepare_func,
release_func: &markcompact_mutator_release,
};

Expand All @@ -52,17 +52,16 @@ pub fn create_markcompact_mutator<VM: VMBinding>(
}
}

pub fn markcompact_mutator_release<VM: VMBinding>(
_mutator: &mut Mutator<VM>,
_tls: VMWorkerThread,
) {
pub fn markcompact_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
// reset the thread-local allocation bump pointer
let markcompact_allocator = unsafe {
_mutator
mutator
.allocators
.get_allocator_mut(_mutator.config.allocator_mapping[AllocationSemantics::Default])
.get_allocator_mut(mutator.config.allocator_mapping[AllocationSemantics::Default])
}
.downcast_mut::<MarkCompactAllocator<VM>>()
.unwrap();
markcompact_allocator.reset();

common_release_func(mutator, tls);
}
3 changes: 2 additions & 1 deletion src/plan/marksweep/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ impl<VM: VMBinding> Plan for MarkSweep<VM> {
self.common.release(tls, true);
}

fn end_of_gc(&mut self, _tls: VMWorkerThread) {
fn end_of_gc(&mut self, tls: VMWorkerThread) {
self.ms.end_of_gc();
self.common.end_of_gc(tls);
}

fn collection_required(&self, space_full: bool, _space: Option<SpaceStats<Self::VM>>) -> bool {
Expand Down
17 changes: 13 additions & 4 deletions src/plan/marksweep/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::plan::mutator_context::Mutator;
use crate::plan::mutator_context::MutatorConfig;
use crate::plan::mutator_context::ReservedAllocators;
use crate::plan::mutator_context::SpaceMapping;
use crate::plan::mutator_context::{common_prepare_func, common_release_func};
use crate::plan::AllocationSemantics;
use crate::plan::Plan;
use crate::util::alloc::allocators::{AllocatorSelector, Allocators};
Expand All @@ -20,8 +21,12 @@ mod malloc_mark_sweep {

// Do nothing for malloc mark sweep (malloc allocator)

pub fn ms_mutator_prepare<VM: VMBinding>(_mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {}
pub fn ms_mutator_release<VM: VMBinding>(_mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {}
pub fn ms_mutator_prepare<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
common_prepare_func(mutator, tls);
}
pub fn ms_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
common_release_func(mutator, tls);
}

// malloc mark sweep uses 1 malloc allocator

Expand Down Expand Up @@ -69,13 +74,17 @@ mod native_mark_sweep {
// We forward calls to the allocator prepare and release

#[cfg(not(feature = "malloc_mark_sweep"))]
pub fn ms_mutator_prepare<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
pub fn ms_mutator_prepare<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
get_freelist_allocator_mut::<VM>(mutator).prepare();

common_prepare_func(mutator, tls);
}

#[cfg(not(feature = "malloc_mark_sweep"))]
pub fn ms_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
pub fn ms_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, tls: VMWorkerThread) {
get_freelist_allocator_mut::<VM>(mutator).release();

common_release_func(mutator, tls);
}

// native mark sweep uses 1 free list allocator
Expand Down
Loading
Loading