-
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
Open
qinsoon
wants to merge
15
commits into
mmtk:master
Choose a base branch
from
qinsoon:nonmoving-space-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
368a7e9
Squashed commit of the following:
qinsoon e885f63
Squashed commit of the following:
qinsoon de4d5f8
Use Immix as non moving space
qinsoon f45d87e
Choose nonmoving policy based on the feature
qinsoon d15c475
Merge branch 'master' into nonmoving-space-options
qinsoon 89b934e
Make sure prepare, release, end_of_gc is properly called
qinsoon d98137f
Work around an issue about trace kind
qinsoon 9ef1cb7
Fix doc
qinsoon 98e9ed5
Update immixspace.rs
qinsoon 0763fb7
Immix needs post_scan. Fix style check
qinsoon c541b2f
Fix the leftover FIXMEs
qinsoon aa5b6ee
Address reviews about cfg_if
qinsoon 57624ad
Use cfg_if where we can. Remove unnecessary needs_mutator_prepare.
qinsoon bdf69fd
Minor refactoring
qinsoon cf5c91d
Merge branch 'master' into nonmoving-space-options
qinsoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,65 @@ 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_if::cfg_if! { | ||
if #[cfg(feature = "immortal_as_nonmoving")] { | ||
self.nonmoving.prepare(); | ||
} else if #[cfg(feature = "marksweep_as_nonmoving")] { | ||
self.nonmoving.prepare(_full_heap); | ||
} else { | ||
self.nonmoving.prepare(_full_heap, None); | ||
} | ||
} | ||
} | ||
|
||
fn release_nonmoving_space(&mut self, _full_heap: bool) { | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "immortal_as_nonmoving")] { | ||
self.nonmoving.release(); | ||
} else if #[cfg(feature = "marksweep_as_nonmoving")] { | ||
self.nonmoving.prepare(_full_heap); | ||
} else { | ||
self.nonmoving.release(_full_heap); | ||
} | ||
} | ||
} | ||
|
||
fn end_of_gc_nonmoving_space(&mut self) { | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "immortal_as_nonmoving")] { | ||
// Nothing we need to do for immortal space. | ||
} else if #[cfg(feature = "marksweep_as_nonmoving")] { | ||
self.nonmoving.end_of_gc(); | ||
} else { | ||
self.nonmoving.end_of_gc(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
use crate::policy::gc_work::TraceKind; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.