Skip to content

Conversation

@iklam
Copy link
Member

@iklam iklam commented May 21, 2025

Since JDK-8305895, interfaces and abstract classes are allocated outside of the class space. See here for the triggering condition

Theoretically such InstanceKlasses can have arbitrary addresses, so the "tie breaker test" of (uintptr_t(existing) < uintptr_t(klass)) in Klass::hash_insert() no longer produces a deterministic result across two JVM runs. As a result, we have seen several occurrence of non-deterministic CDS archives in our test pipeline for a short period after JDK-8305895 for pushed.

Thereafter, for some unknown reason, the problem disappears. However, we could just be lucky due to allocation policy changes in metaspace. The underlying cause still exists.

I wrote a proof of concept that shows the problem. See 3318570

(Without fix)

$ java -Xshare:dump -XX:+UseNewCode -XX:SharedArchiveFile=f1.jsa
$ java -Xshare:dump -XX:+UseNewCode2 -XX:SharedArchiveFile=f2.jsa
$ cksum f1.jsa f2.jsa
  2834014305 16105472 f1.jsa
  4126337207 16105472 f2.jsa

(With the fix in this PR)

$ java -Xshare:dump -XX:+UseNewCode -XX:+UseNewCode3 -XX:SharedArchiveFile=f1.jsa
$ java -Xshare:dump -XX:+UseNewCode2 -XX:+UseNewCode3 -XX:SharedArchiveFile=f2.jsa
$ cksum f1.jsa f2.jsa
  3637571299 16105472 f1.jsa
  3637571299 16105472 f2.jsa

With the fix, we re-hash the copy of the secondary_supers in the CDS archive. When InstanceKlasses are copied into the CDS archive, they are sorted by their names. This makes the (uintptr_t(existing) < uintptr_t(klass)) comparison produce deterministic results.

Unfortunately it's not possible to write a jtreg test for this problem.

Note: the "tie breaker test" was introduced in JDK-8180450. It adds an assumption that the address order of classes in the CDS archive buffer is the same as the classes in the class space, which can become invalid if the class space allocation algorithm changes.


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-8357525: Default CDS archive becomes non-deterministic after JDK-8305895 (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25373

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 21, 2025

👋 Welcome back iklam! 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 21, 2025

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

8357525: Default CDS archive becomes non-deterministic after JDK-8305895

Reviewed-by: shade, coleenp

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

openjdk bot commented May 21, 2025

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

  • hotspot

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 openjdk bot added the hotspot hotspot-dev@openjdk.org label May 21, 2025
@iklam iklam changed the title 8343892: Default CDS archive becomes non-deterministic after JDK-8305895 8357525: Default CDS archive becomes non-deterministic after JDK-8305895 May 22, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label May 22, 2025
@mlbridge
Copy link

mlbridge bot commented May 22, 2025

Webrevs

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

This looks fine.

Looks to me we mis-attributing the root cause a bit: it is not just about JDK-8305895 that made some IK-s allocated at more arbitrary locations outside of Class Space. Even in Class Space there is a positional randomness, right?

So I think the actual root cause is the the address-based tie-breaker introduced in JDK-8180450. Let's link those issues up and change the synopsis accordingly?

// output buffer, so they should have deterministic values. If we rehash
// _secondary_supers, its elements will appear in a deterministic order.
//
// Note that the bitmap is guatanteed to be deterministic, regardless of the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Note that the bitmap is guatanteed to be deterministic, regardless of the
// Note that the bitmap is guaranteed to be deterministic, regardless of the

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 22, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 27, 2025
@iklam
Copy link
Member Author

iklam commented May 27, 2025

This looks fine.

Looks to me we mis-attributing the root cause a bit: it is not just about JDK-8305895 that made some IK-s allocated at more arbitrary locations outside of Class Space. Even in Class Space there is a positional randomness, right?

So I think the actual root cause is the the address-based tie-breaker introduced in JDK-8180450. Let's link those issues up and change the synopsis accordingly?

I updated the PR and JBS synopsis to include JDK-8180450.

Determinism is required only when creating the default CDS archive during the JDK build, where we run a single thread to load the classes. As far as I know, the address order in the class space happens to be the same as in the CDS output buffer, but that's just a happy co-incidence and could change in the future. This RFE will guard against such changes.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

I don't see the bug synopsis update, but PR looks good.

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

coleenp commented May 27, 2025

It was actually JDK-8338526 this change that moved interface and abstract classes into non-class metaspace.

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

This looks good but I also think the synopsis should be updated. A bit disconcerting that now remove_unshareable_info() has side effects. Maybe it should be renamed to something like make_shareable() with some future RFE.

@iklam
Copy link
Member Author

iklam commented May 28, 2025

Thanks @shipilev @coleenp for the review
/integrate

@openjdk
Copy link

openjdk bot commented May 28, 2025

Going to push as commit 2ec6ab3.
Since your change was applied there have been 133 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 28, 2025
@openjdk openjdk bot closed this May 28, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 28, 2025
@openjdk
Copy link

openjdk bot commented May 28, 2025

@iklam Pushed as commit 2ec6ab3.

💡 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 hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants