Skip to content

8357218: G1: Remove loop in G1CollectedHeap::try_collect_fullgc #25296

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

Closed

Conversation

albertnetymk
Copy link
Member

@albertnetymk albertnetymk commented May 19, 2025

Simple removing unnecessary loop in "caller" of VM_G1CollectFull, because an explicit full-gc always run-to-completion.

Test: tier1-3


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-8357218: G1: Remove loop in G1CollectedHeap::try_collect_fullgc (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25296/head:pull/25296
$ git checkout pull/25296

Update a local copy of the PR:
$ git checkout pull/25296
$ git pull https://git.openjdk.org/jdk.git pull/25296/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25296

View PR using the GUI difftool:
$ git pr show -t 25296

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25296.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 19, 2025

👋 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 19, 2025

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

8357218: G1: Remove loop in G1CollectedHeap::try_collect_fullgc

Reviewed-by: kbarrett, tschatzl

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 27 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this 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 8357218 8357218: G1: Remove loop in G1CollectedHeap::try_collect_fullgc May 19, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label May 19, 2025
@openjdk
Copy link

openjdk bot commented May 19, 2025

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

  • hotspot-gc

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented May 19, 2025

Webrevs


// Request is trivially finished.
if (!GCCause::is_explicit_full_gc(cause) || op.gc_succeeded()) {
return op.gc_succeeded();

Choose a reason for hiding this comment

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

Complete removal of this part isn't correct. The premise of this change, that "full-gc always
run-to-completion" is not correct. A _g1_periodic_collection may be cancelled:

bool VM_G1CollectFull::skip_operation() const {
// There is a race between the periodic collection task's checks for
// wanting a collection and processing its request. A collection in that
// gap should cancel the request.
if ((_gc_cause == GCCause::_g1_periodic_collection) &&
(G1CollectedHeap::heap()->total_collections() != _gc_count_before)) {
return true;
}
return VM_GC_Operation::skip_operation();
}

Such a collection is not an explicit full-gc, so that part of the test may be true, when this function
returns false because the gc did not succeed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the description. The overall result of !GCCause::is_explicit_full_gc(cause) || op.gc_succeeded() is always true.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Somehow comments seem to have disappeared, probably my fault. anyway:)

This method returns false if the VM op has not been executed (skipped). The new code always returns true, which is wrong afaict.

@@ -1864,24 +1864,12 @@ bool G1CollectedHeap::try_collect_fullgc(GCCause::Cause cause,
const G1GCCounters& counters_before) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There does not seem to be a reason to keep this helper method. It's the same complexity as the attempt to do a young collection in try_collect() now.

Or move the attempt to do a young collection to a helper method for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fwiw, there is G1CollectedHeap::do_collection_pause()that might fit exactly already.

counters_before.total_full_collections(),
cause);
VMThread::execute(&op);
return op.prologue_succeeded();

Choose a reason for hiding this comment

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

They might now be the same value, but gc_succeeded() seems like a better semantic fit here.
Looking around a little, it's not obvious why prologue_succeeded() is ever the right name for a
client-accessible test for what seems like gc-completion. But that's a separate issue.

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 introducing a local var to better reflect the semantics?

// GCs always run-to-completion once prologue succeeds.
bool is_gc_succeeded = op.prologue_succeeded();
return is_gc_succeeded;

This way we don't need to maintain a "redundant" field in VM_G1CollectFull.

(Thomas also asked whether the same field in VM_G1CollectForAllocation is actually needed -- seems that _gc_succeeded == prologue_succeeded() holds as well, so we can potential remove that one as well.)

If you dislike the suggestion, I will add back the removed field.

Copy link
Contributor

Choose a reason for hiding this comment

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

The field does not need to be re-added in the full gc VM op, just add an accessor gc_succeeded() that returns the internal prologue_succeeded().

I will file a bug for removing the _gc_succeeded field in VM_G1CollectForAllocation, because it is always true if doit ran.

Choose a reason for hiding this comment

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

I think the question that clients care about is whether the gc succeeded.
Whether the prologue succeeded or not might be used as part of the
implementation of that. That is, I think gc_succeeded ought to be part of the
public API for GC operations, and prologue_succeeded shouldn't be, with some
gc_succeeded operations being implemented as just a call to
prologue_succeeded.

That probably shouldn't be part of this change though. Instead, I'd prefer
this change maintain the status quo in this area. Or do what @tschatzl
suggested, which I saw as I was about to post this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added back the API.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the question that clients care about is whether the gc succeeded.
Whether the prologue succeeded or not might be used as part of the
implementation of that. That is, I think gc_succeeded ought to be part of the
public API for GC operations, and prologue_succeeded shouldn't be, with some
gc_succeeded operations being implemented as just a call to
prologue_succeeded.

Agree. Filed JDK-8357307.

counters_before.total_full_collections(),
cause);
VMThread::execute(&op);
return op.prologue_succeeded();

Choose a reason for hiding this comment

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

I think the question that clients care about is whether the gc succeeded.
Whether the prologue succeeded or not might be used as part of the
implementation of that. That is, I think gc_succeeded ought to be part of the
public API for GC operations, and prologue_succeeded shouldn't be, with some
gc_succeeded operations being implemented as just a call to
prologue_succeeded.

That probably shouldn't be part of this change though. Instead, I'd prefer
this change maintain the status quo in this area. Or do what @tschatzl
suggested, which I saw as I was about to post this.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 20, 2025
Copy link

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

@albertnetymk
Copy link
Member Author

Thanks for review.

/integrate

@openjdk
Copy link

openjdk bot commented May 20, 2025

Going to push as commit e6750a5.
Since your change was applied there have been 31 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 20, 2025

@albertnetymk Pushed as commit e6750a5.

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

@albertnetymk albertnetymk deleted the g1-remove-full-gc-loop branch May 20, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-gc [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants