Skip to content

Conversation

@shipilev
Copy link
Member

@shipilev shipilev commented Apr 25, 2025

CDS cannot handle large number of classes, because ClassLoader data structures get too large for CDS archival. The new test captures such an occasion. We do clear()-s, but that is not enough to trim the backing storages for the affected collections.

In contrast with previous attempts to fix this (#21797 and my VM-side field overwrite), we can just reinitialize the fields using Unsafe, which bypasses normal final field write restriction. ClassLoader already does a similar thing nearby! This allows us to stay fully in Java, and makes the patch fairly straightforward.

Additional testing:

  • Linux x86_64 server fastdebug, new test reliably fails without the fix, passes with it
  • Linux x86_64 server fastdebug, runtime/cds

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-8342283: CDS cannot handle a large number of classes (Bug - P4)

Reviewers

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24877

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 25, 2025

👋 Welcome back shade! 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 Apr 25, 2025

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

8342283: CDS cannot handle a large number of classes

Co-authored-by: Ioi Lam <[email protected]>
Reviewed-by: iklam, lmesnik, ccheung

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

openjdk bot commented Apr 25, 2025

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

  • core-libs
  • hotspot

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.

@shipilev
Copy link
Member Author

@iklam -- I think neither of our previous solutions were as cute as this one :) No messing with final-s and @Stable-s, no messing with VM code!

@shipilev shipilev marked this pull request as ready for review April 25, 2025 14:57
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 25, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 25, 2025

Webrevs

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

LGTM. This does look a cleaner fix.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 25, 2025
Copy link
Member

@lmesnik lmesnik left a comment

Choose a reason for hiding this comment

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

Test changes looks good for me.

Copy link
Member

@calvinccheung calvinccheung left a comment

Choose a reason for hiding this comment

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

LGTM.

*
* @implNote This is done while the JVM is running in single-threaded mode,
* and at the very end of Java bytecode execution. We know that no more classes
* will be loaded and none of the fields modified by this method will be used again.
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a tiny technical debt here. If future AOT code generation uses a future aggressive constant folding of object fields (cf. TrustFinalNonStaticFields) and a constant CL reference ends up in optimized code and there is a constant-folded reference (and.. and…) it is remotely possible that the old value of the field will get wrongly embedded in AOT code.

If we arrange AOT code generation to occur after all of these fixups (in Java code) are done, then the problem will not occur. It's a delicate set of invariants. Your expanded comment is a good start at calling them out, but this is a long string we are pulling on.

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 borrowed this comment from the initial @iklam's PR, so I need to credit him as contributor.)

Yes, CDS does awkward state manipulations at dump time. Resetting the states of final/@Stable objects can run into issues that you described. I think this is one of the reasons why Leyden generates AOT code with -XX:-FoldStableValues:

https://github.com/openjdk/leyden/blob/885096a8b3194371cde6b96ce5554d89f99618d7/src/hotspot/share/code/aotCodeCache.cpp#L162

I would guess we need to do the same with TrustFinalNonStaticFields. The awkward part of current trust_final_non_static_fields() code is that it implicitly trusts things in java/lang, even with -TrustFinalNonStaticFields. That sounds like something we need to rectify for Leyden AOT code.

@shipilev
Copy link
Member Author

/contributor add @iklam

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 28, 2025
@openjdk
Copy link

openjdk bot commented Apr 28, 2025

@shipilev
Contributor Ioi Lam <[email protected]> successfully added.

@shipilev
Copy link
Member Author

Are we still good with this? Integration need a re-review :)

Copy link
Member

@iklam iklam 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 Apr 29, 2025
@shipilev
Copy link
Member Author

Thank you! I am running final tier{1,2,3} testing before integration, and will integrate when those turn green.

@shipilev
Copy link
Member Author

Testing is green. I am integrating.

/integrate

@openjdk
Copy link

openjdk bot commented Apr 29, 2025

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

openjdk bot commented Apr 29, 2025

@shipilev Pushed as commit ead6757.

💡 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

Development

Successfully merging this pull request may close these issues.

6 participants