Skip to content

8385632: ZGC: Incorrect object undo in relocation race for relocation workers#31322

Closed
jsikstro wants to merge 1 commit into
openjdk:masterfrom
jsikstro:JDK-8385632_relocation_worker_lose_race_undo_fix
Closed

8385632: ZGC: Incorrect object undo in relocation race for relocation workers#31322
jsikstro wants to merge 1 commit into
openjdk:masterfrom
jsikstro:JDK-8385632_relocation_worker_lose_race_undo_fix

Conversation

@jsikstro
Copy link
Copy Markdown
Member

@jsikstro jsikstro commented May 29, 2026

Hello,

When a relocation worker races with a mutator and the relocation worker loses, it should attempt to undo its last allocation as a way to potentially save some space.

When the relocation worker loses the race, it passes on the object allocated by the mutator in its call to ZPage::undo_alloc_object, not the object the relocation worker just allocated.

Since relocation workers and mutators have totally separate target pages, we will never end up in a scenario where a mutator allocation can end up on a page that a relocation worker also allocates on. ZPage::undo_alloc_object only undos an allocation if it was the most recent one, by checking if the object's offset into the heap is the same offset as the page's top. This means the undo will never succeed if the object is not on the page also passed to undo_alloc_object. In practice this means that this bug is benign, resulting in one waste relocation worker allocation in the event of a race occurring.

On the mutator side, if the mutator loses the race it calls ZHeap::undo_alloc_object_for_relocation, which gets the correct page for an object via ZHeap::page, so we don't have the same issue there.

The fix is simple, we just make sure we pass the object allocated by the relocation worker in the call to undo_alloc_object.

This might be relevant to backport, so I suggest we add more robustness to the undo-paths in a follow-up RFE, making sure that we're not trying to undo object allocations in a page it doesn't belong to, so we can more easily catch bugs like this in the future.

Testing:

  • Running Oracle's tier1-4 ZGC tests


Progress

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

Issue

  • JDK-8385632: ZGC: Incorrect object undo in relocation race for relocation workers (Bug - P5)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 31322

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented May 29, 2026

👋 Welcome back jsikstro! 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
Copy Markdown

openjdk Bot commented May 29, 2026

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

8385632: ZGC: Incorrect object undo in relocation race for relocation workers

Reviewed-by: stefank, aboldtch, 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 26 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 added the hotspot-gc hotspot-gc-dev@openjdk.org label May 29, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented May 29, 2026

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

@openjdk
Copy link
Copy Markdown

openjdk Bot commented May 29, 2026

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-gc. This can be overridden with the /reviewers command.

Copy link
Copy Markdown
Member

@stefank stefank 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 fixing!

@openjdk openjdk Bot added the rfr Pull request is ready for review label May 29, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented May 29, 2026

Webrevs

Copy link
Copy Markdown
Member

@xmas92 xmas92 left a comment

Choose a reason for hiding this comment

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

lgtm.

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label May 29, 2026
@jsikstro
Copy link
Copy Markdown
Member Author

jsikstro commented Jun 1, 2026

Thank you for the reviews everyone!
/integrate

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Jun 1, 2026

Going to push as commit 64d6cba.
Since your change was applied there have been 29 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 Jun 1, 2026
@openjdk openjdk Bot closed this Jun 1, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 1, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Jun 1, 2026

@jsikstro Pushed as commit 64d6cba.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants