Skip to content
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

8331557: Serial: Refactor SerialHeap::do_collection #19056

Closed
wants to merge 9 commits into from

Conversation

albertnetymk
Copy link
Member

@albertnetymk albertnetymk commented May 2, 2024

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8331557: Serial: Refactor SerialHeap::do_collection (Enhancement - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented May 2, 2024

👋 Welcome back ayang! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 2, 2024

@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:

8331557: Serial: Refactor SerialHeap::do_collection

Reviewed-by: gli, iwalulya

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 master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8331557 8331557: Serial: Refactor SerialHeap::do_collection May 2, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label May 2, 2024
@openjdk
Copy link

openjdk bot commented May 2, 2024

@albertnetymk The following labels will be automatically applied to this pull request:

  • hotspot
  • serviceability

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.

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels May 2, 2024
@albertnetymk
Copy link
Member Author

/cc hotspot-gc

@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label May 2, 2024
@openjdk
Copy link

openjdk bot commented May 2, 2024

@albertnetymk
The hotspot-gc label was successfully added.

@mlbridge
Copy link

mlbridge bot commented May 2, 2024

Webrevs

@openjdk
Copy link

openjdk bot commented May 3, 2024

@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.

Copy link
Member

@lgxbslgx lgxbslgx left a 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) {
Copy link
Member

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.

Comment on lines 472 to 468
update_gc_stats(young_gen, false);

update_gc_stats(gen, full);
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

increment_total_collections(false);
const bool should_verify = total_collections() >= VerifyGCStartAt;
if (should_verify && VerifyBeforeGC) {
prepare_for_verify();
Universe::verify("Before GC");
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Comment on lines 648 to 660
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);
}
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@lgxbslgx lgxbslgx left a 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.

Comment on lines 643 to 656
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);
}

Copy link
Member

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;
}

Copy link
Member

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.

Comment on lines 115 to 117
void do_full_collection_no_gc_locker(bool clear_all_soft_refs);

void collect_at_safepoint_no_gc_locker(bool full);
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 17, 2024
Copy link
Member

@walulyai walulyai left a 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.

@albertnetymk
Copy link
Member Author

Thanks for review.

/integrate

@openjdk
Copy link

openjdk bot commented May 17, 2024

Going to push as commit f1ce9b0.
Since your change was applied there has been 1 commit pushed to the master branch:

  • 14198f5: 8329653: JLILaunchTest fails on AIX after JDK-8329131

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 17, 2024
@openjdk openjdk bot closed this May 17, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 17, 2024
@openjdk
Copy link

openjdk bot commented May 17, 2024

@albertnetymk Pushed as commit f1ce9b0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@albertnetymk albertnetymk deleted the s1-do-collect branch May 17, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
3 participants