-
Notifications
You must be signed in to change notification settings - Fork 77
Choose Non-moving Policy based on features #1308
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
Changes from 12 commits
368a7e9
e885f63
de4d5f8
f45d87e
d15c475
89b934e
d98137f
9ef1cb7
98e9ed5
0763fb7
c541b2f
aa5b6ee
57624ad
bdf69fd
cf5c91d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ pub const GEN_CONSTRAINTS: PlanConstraints = PlanConstraints { | |
may_trace_duplicate_edges: ACTIVE_BARRIER.equals(BarrierSelector::ObjectBarrier), | ||
max_non_los_default_alloc_bytes: | ||
crate::plan::plan_constraints::MAX_NON_LOS_ALLOC_BYTES_COPYING_PLAN, | ||
needs_prepare_mutator: false, | ||
needs_prepare_mutator: false || PlanConstraints::default().needs_prepare_mutator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
..PlanConstraints::default() | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,7 +197,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. | ||
|
@@ -511,6 +511,10 @@ impl<VM: VMBinding> BasePlan<VM> { | |
self.vm_space.release(); | ||
} | ||
|
||
pub fn end_of_gc(&mut self, _tls: VMWorkerThread) { | ||
// Do nothing here. None of the spaces needs end_of_gc. | ||
} | ||
|
||
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( | ||
|
@@ -542,6 +546,17 @@ impl<VM: VMBinding> BasePlan<VM> { | |
} | ||
} | ||
|
||
cfg_if::cfg_if! { | ||
// Use immortal or mark sweep as the non moving space if the features are enabled. Otherwise use Immix. | ||
if #[cfg(feature = "immortal_as_nonmoving")] { | ||
pub type NonMovingSpace<VM> = crate::policy::immortalspace::ImmortalSpace<VM>; | ||
} else if #[cfg(feature = "marksweep_as_nonmoving")] { | ||
pub type NonMovingSpace<VM> = crate::policy::marksweepspace::native_ms::MarkSweepSpace<VM>; | ||
} else { | ||
pub type NonMovingSpace<VM> = crate::policy::immix::ImmixSpace<VM>; | ||
} | ||
} | ||
|
||
/** | ||
CommonPlan is for representing state and features used by _many_ plans, but that are not fundamental to _all_ plans. Examples include the Large Object Space and an Immortal space. Features that are fundamental to _all_ plans must be included in BasePlan. | ||
*/ | ||
|
@@ -551,9 +566,12 @@ 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>, | ||
#[cfg_attr( | ||
not(any(feature = "immortal_as_nonmoving", feature = "marksweep_as_nonmoving")), | ||
post_scan | ||
)] // Immix space needs post_scan | ||
pub nonmoving: NonMovingSpace<VM>, | ||
#[parent] | ||
pub base: BasePlan<VM>, | ||
} | ||
|
@@ -571,12 +589,7 @@ impl<VM: VMBinding> CommonPlan<VM> { | |
args.get_space_args("los", true, false, VMRequest::discontiguous()), | ||
false, | ||
), | ||
nonmoving: ImmortalSpace::new(args.get_space_args( | ||
"nonmoving", | ||
true, | ||
false, | ||
VMRequest::discontiguous(), | ||
)), | ||
nonmoving: Self::new_nonmoving_space(&mut args), | ||
base: BasePlan::new(args), | ||
} | ||
} | ||
|
@@ -591,17 +604,22 @@ impl<VM: VMBinding> CommonPlan<VM> { | |
pub fn prepare(&mut self, tls: VMWorkerThread, full_heap: bool) { | ||
self.immortal.prepare(); | ||
self.los.prepare(full_heap); | ||
self.nonmoving.prepare(); | ||
self.prepare_nonmoving_space(full_heap); | ||
self.base.prepare(tls, full_heap) | ||
} | ||
|
||
pub fn release(&mut self, tls: VMWorkerThread, full_heap: bool) { | ||
self.immortal.release(); | ||
self.los.release(full_heap); | ||
self.nonmoving.release(); | ||
self.release_nonmoving_space(full_heap); | ||
self.base.release(tls, full_heap) | ||
} | ||
|
||
pub fn end_of_gc(&mut self, tls: VMWorkerThread) { | ||
self.end_of_gc_nonmoving_space(); | ||
self.base.end_of_gc(tls); | ||
} | ||
|
||
pub fn get_immortal(&self) -> &ImmortalSpace<VM> { | ||
&self.immortal | ||
} | ||
|
@@ -610,9 +628,55 @@ impl<VM: VMBinding> CommonPlan<VM> { | |
&self.los | ||
} | ||
|
||
pub fn get_nonmoving(&self) -> &ImmortalSpace<VM> { | ||
pub fn get_nonmoving(&self) -> &NonMovingSpace<VM> { | ||
&self.nonmoving | ||
} | ||
|
||
fn new_nonmoving_space(args: &mut CreateSpecificPlanArgs<VM>) -> NonMovingSpace<VM> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And we can use |
||
let space_args = args.get_space_args("nonmoving", true, false, VMRequest::discontiguous()); | ||
cfg_if::cfg_if! { | ||
if #[cfg(any(feature = "immortal_as_nonmoving", feature = "marksweep_as_nonmoving"))] { | ||
NonMovingSpace::new(space_args) | ||
} else { | ||
// Immix requires extra args. | ||
NonMovingSpace::new( | ||
space_args, | ||
crate::policy::immix::ImmixSpaceArgs { | ||
unlog_object_when_traced: false, | ||
#[cfg(feature = "vo_bit")] | ||
mixed_age: false, | ||
never_move_objects: true, | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
fn prepare_nonmoving_space(&mut self, _full_heap: bool) { | ||
#[cfg(feature = "immortal_as_nonmoving")] | ||
self.nonmoving.prepare(); | ||
#[cfg(not(any(feature = "immortal_as_nonmoving", feature = "marksweep_as_nonmoving")))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a candidate for |
||
self.nonmoving.prepare(_full_heap, None); | ||
#[cfg(feature = "marksweep_as_nonmoving")] | ||
self.nonmoving.prepare(_full_heap); | ||
} | ||
|
||
fn release_nonmoving_space(&mut self, _full_heap: bool) { | ||
#[cfg(feature = "immortal_as_nonmoving")] | ||
self.nonmoving.release(); | ||
#[cfg(not(any(feature = "immortal_as_nonmoving", feature = "marksweep_as_nonmoving")))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a candidate for |
||
self.nonmoving.release(_full_heap); | ||
#[cfg(feature = "marksweep_as_nonmoving")] | ||
self.nonmoving.release(); | ||
} | ||
|
||
fn end_of_gc_nonmoving_space(&mut self) { | ||
// Only mark sweep and immix need end of GC. | ||
#[cfg(feature = "marksweep_as_nonmoving")] | ||
self.nonmoving.end_of_gc(); | ||
#[cfg(not(any(feature = "immortal_as_nonmoving", feature = "marksweep_as_nonmoving")))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a candidate for |
||
self.nonmoving.end_of_gc(); | ||
} | ||
} | ||
|
||
use crate::policy::gc_work::TraceKind; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ pub const IMMIX_CONSTRAINTS: PlanConstraints = PlanConstraints { | |
moves_objects: !cfg!(feature = "immix_non_moving"), | ||
// 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, | ||
needs_prepare_mutator: false || PlanConstraints::default().needs_prepare_mutator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
..PlanConstraints::default() | ||
}; | ||
|
||
|
@@ -88,7 +88,7 @@ impl<VM: VMBinding> Plan for Immix<VM> { | |
self.common.prepare(tls, true); | ||
self.immix_space.prepare( | ||
true, | ||
crate::policy::immix::defrag::StatsForDefrag::new(self), | ||
Some(crate::policy::immix::defrag::StatsForDefrag::new(self)), | ||
); | ||
} | ||
|
||
|
@@ -98,9 +98,10 @@ impl<VM: VMBinding> Plan for Immix<VM> { | |
self.immix_space.release(true); | ||
} | ||
|
||
fn end_of_gc(&mut self, _tls: VMWorkerThread) { | ||
fn end_of_gc(&mut self, tls: VMWorkerThread) { | ||
self.last_gc_was_defrag | ||
.store(self.immix_space.end_of_gc(), Ordering::Relaxed); | ||
self.common.end_of_gc(tls); | ||
} | ||
|
||
fn current_gc_may_move_object(&self) -> bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit awkward. Ideally, we should have 3 features
immix_as_nonmoving
,immortal_as_nonmoving
andmarksweep_as_nonmoving
, and we useimmix_as_nonmoving
as a default feature. But we need to ensure that for every build, exactly one feature from those 3 features is enabled. This also applies to the mark sweep features above, which should be 3 featureslazy_sweeping
,eager_sweeping
andmalloc_mark_sweep
, and we need to choose exactly one.So basically we need mutually exclusive features, and we need to make sure the features are mandatory that you need to use one of them. We cannot do this with cargo. In our test script, we try to achieve this when we cover all the builds with different features, but our test script only supports optional mutually exclusive features. So for now, we assume the default (without any feature to control it), and make the other two features optional and mutually exclusive.
I would like to do this refactoring in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do something like this: https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default features can be disabled (see https://doc.rust-lang.org/cargo/reference/features.html#the-default-feature). mmtk-core currently has one default feature:
builtin_env_logger
, and VM bindings that use their own logging frameworks (such as OpenJDK) could disable default features and wire Rust logs into their own.If the user disables default features, there will be neither
immix_as_nonmoving
,immortal_as_nonmoving
normarksweep_as_nonmoving
. So we need to consider the case that there is no non-moving space.Actually I think the default should be "no non-moving space". Not all VMs need that. Neither OpenJDK, JikesRVM nor Ruby need it. We can make all of them optional, and use the trick described in https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features to reject multiple non-moving spaces.