-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8331557: Serial: Refactor SerialHeap::do_collection #19056
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
Conversation
👋 Welcome back ayang! A progress list of the required criteria for merging this PR into |
@albertnetymk This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
@albertnetymk The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
/cc hotspot-gc |
@albertnetymk |
2521919
to
7375bfb
Compare
@albertnetymk Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
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.
Nice refactor.
|
||
gen->stat_record()->invocations++; | ||
gen->stat_record()->accumulated_time.start(); | ||
bool SerialHeap::do_young_gc(DefNewGeneration* young_gen, bool clear_soft_refs) { |
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.
The parameter DefNewGeneration* young_gen
is not necessary. We can use the field SerialHeap::_young_gen
directly.
update_gc_stats(young_gen, false); | ||
|
||
update_gc_stats(gen, full); |
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.
The method update_gc_stats
is only used by young-gen to sample the promoted size. It is good to rename and simplify the related code. I filed https://bugs.openjdk.org/browse/JDK-8331684 to follow up.
Universe::verify("Before GC"); | ||
} | ||
gc_prologue(false); |
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.
The parameter full
of the method SerialHeap::gc_prologue
doesn't been used. Seems a leftover of JDK-8323993.
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.
True; can probably fixed in a followup cleanup.
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.
Filed https://bugs.openjdk.org/browse/JDK-8331723 to follow up.
increment_total_collections(false); | ||
const bool should_verify = total_collections() >= VerifyGCStartAt; | ||
if (should_verify && VerifyBeforeGC) { | ||
prepare_for_verify(); | ||
Universe::verify("Before GC"); |
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.
May the prefix of the verification log be better to specify the minor or full GC? Such as Before Minor GC
here.
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.
Other Universe::verify("
seems to not distinguish minor/major.
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.
OK. If someone want to change all of them in the future, she/he can file another ticket to follow up.
void SerialHeap::collect_at_safepoint_no_gc_locker(bool full) { | ||
assert(!GCLocker::is_active(), "precondition"); | ||
bool clear_soft_refs = must_clear_all_soft_refs(); | ||
|
||
if (!full) { | ||
bool success = do_young_gc(_young_gen, clear_soft_refs); | ||
if (success) { | ||
return; | ||
} | ||
// Upgrade to Full-GC if young-gc fails | ||
} | ||
do_full_collection_no_gc_locker(clear_soft_refs); | ||
} |
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.
Please note the difference between the previous SerialHeap::do_collection
and SerialHeap::collect_at_safepoint_no_gc_locker
here. The previous SerialHeap::do_collection
may invoke full GC according to the method SerialHeap::should_do_full_collection
even the young GC succeeded. But SerialHeap::collect_at_safepoint_no_gc_locker
only invokes full GC when the young GC failed (because of failed promotion). Such change makes the SerialHeap::should_do_full_collection
has no user. If the behaviour of the SerialHeap::collect_at_safepoint_no_gc_locker
is your intention, I think it is good to remove SerialHeap::should_do_full_collection
.
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.
Removed should_do_full_collection
.
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.
Looks good. One suggestion, but not necessary.
void SerialHeap::collect_at_safepoint_no_gc_locker(bool full) { | ||
assert(!GCLocker::is_active(), "precondition"); | ||
bool clear_soft_refs = must_clear_all_soft_refs(); | ||
|
||
if (!full) { | ||
bool success = do_young_gc(clear_soft_refs); | ||
if (success) { | ||
return; | ||
} | ||
// Upgrade to Full-GC if young-gc fails | ||
} | ||
do_full_collection_no_gc_locker(clear_soft_refs); | ||
} | ||
|
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.
Maybe the method do_young_gc
can be renamed to do_young_collection
or do_young_collection_no_gc_locker
which is consistent with do_full_collection
or do_full_collection_no_gc_locker
.
assert(is_in_reserved(result), "result not in heap"); | ||
return result; | ||
} | ||
|
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.
Would be nice to add a comment here to indicate that the previous collection could have shrunk the heap.
void do_full_collection_no_gc_locker(bool clear_all_soft_refs); | ||
|
||
void collect_at_safepoint_no_gc_locker(bool full); |
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.
I am not very convinced by the naming of the methods with the "no_gc_locker" constraint. But I guess it is following same convention as "*at_safepoint" method naming.
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.
How about calling them try_x
and x
for the public and private API, respectively, e.g. try_do_full_collection
and do_full_collection
?
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.
I prefer that to the "no_gc_locker" emphasizing names
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.
I can do that for try_collect_at_safepoint
, but SerialHeap::do_full_collection
is an API from CollectedHeap
.
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.
yeah, i only meant change those that are not "override" and have the "no_gclocker" postfix.
false, // is_tlab | ||
OldGen); // last_generation | ||
void SerialHeap::do_full_collection_no_gc_locker(bool clear_all_soft_refs) { | ||
IsSTWGCActiveMark gc_active_mark; |
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.
IsSTWGCActiveMark active_gc_mark;
indo_young_collection_no_gc_locker
, just choose one and be consistent with it
_young_gen->print_summary_info_on(&lsh); | ||
_old_gen->print_summary_info_on(&lsh); | ||
} | ||
// Nothing |
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.
What is the Nothing
supposed to convey here?
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.
To emphasize that this empty method is intentional, inspired by ZCollectedHeap::print_tracing_info
.
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.
Then better to keep the verb in the comment // Does nothing
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.
Looks good! Thanks for the cleanup.
Thanks for review. /integrate |
@albertnetymk Pushed as commit f1ce9b0. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
It's probably easier to read the new code directly. The two classes in
serialVMOperations
serve as entrance points to invoke young/full GCs. Some previously hidden decisions are made more obvious, e.g. if a young-gc fails (or will probablly fail), fallback to full-gc.Additionally,
StatRecord
is removed, because this kind of info-aggregation should be done outsite VM (by third-party tool).Test: tier1-6
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19056/head:pull/19056
$ git checkout pull/19056
Update a local copy of the PR:
$ git checkout pull/19056
$ git pull https://git.openjdk.org/jdk.git pull/19056/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19056
View PR using the GUI difftool:
$ git pr show -t 19056
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19056.diff
Webrev
Link to Webrev Comment