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

8331341: secondary_super_cache does not scale well: C1 and interpreter #19989

Closed
wants to merge 69 commits into from

Conversation

theRealAph
Copy link
Contributor

@theRealAph theRealAph commented Jul 2, 2024

This patch expands the use of a hash table for secondary superclasses
to the interpreter, C1, and runtime. It also adds a C2 implementation
of hashed lookup in cases where the superclass isn't known at compile
time.

HotSpot shared runtime

Building hashed secondary tables is now unconditional. It takes very
little time, and now that the shared runtime always has the tables, it
might as well take advantage of them. The shared code is easier to
follow now, I think.

There might be a performance issue with x86-64 in that we build
HotSpot for a default x86-64 target that does not support popcount.
This means that HotSpot C++ runtime on x86 always uses a software
emulation for popcount, even though the vast majority of machines made
for the past 20 years can do popcount in a single instruction. It
wouldn't be terribly hard to do something about that.

Having said that, the software popcount is really not bad.

x86

x86 is rather tricky, because we still support
-XX:-UseSecondarySupersTable and -XX:+UseSecondarySupersCache, as
well as 32- and 64-bit ports. There's some further complication in
that only RCX can be used as a shift count, so there's some register
shuffling to do. All of this makes the logic in macroAssembler_x86.cpp
rather gnarly, with multiple levels of conditionals at compile time
and runtime.

AArch64

AArch64 is considerably more straightforward. We always have a
popcount instruction and (thankfully) no 32-bit code to worry about.

Generally

I would dearly love simply to rip out the "old" secondary supers cache
support, but I've left it in just in case someone has a performance
regression.

The versions of MacroAssembler::lookup_secondary_supers_table that
work with variable superclasses don't take a fixed set of temp
registers, and neither do they call out to to a slow path subroutine.
Instead, the slow patch is expanded inline.

I don't think this is necessarily bad. Apart from the very rare cases
where C2 can't determine the superclass to search for at compile time,
this code is only used for generating stubs, and it seemed to me
ridiculous to have stubs calling other stubs.

I've followed the guidance from @iwanowww not to obsess too much about
the performance of C1-compiled secondary supers lookups, and to prefer
simplicity over absolute performance. Nonetheless, this is a
complicated patch that touches many areas.


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-8331341: secondary_super_cache does not scale well: C1 and interpreter (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19989

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@theRealAph theRealAph marked this pull request as draft July 2, 2024 14:52
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 2, 2024

👋 Welcome back aph! 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 Jul 2, 2024

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

8331341: secondary_super_cache does not scale well: C1 and interpreter

Reviewed-by: vlivanov, kvn, dlong

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

  • 714472d: 8341798: Fix ExceptionOccurred in jdk.jdwp.agent
  • 825ceb1: 8341796: Fix ExceptionOccurred in jdk.hotspot.agent
  • 8b47497: 8331682: Slow networks/Impatient clients can potentially send unencrypted TLSv1.3 alerts that won't parse on the server
  • 0668e18: 8343234: (bf) Move java/nio/Buffer/LimitDirectMemory.java from ProblemList.txt to ProblemList-Virtual.txt
  • 774de27: 8343497: Missing DEF_STATIC_JNI_OnLoad in libjimage and libsaproc native libraries
  • 1cc3586: 8343551: Missing copyright header update in Charset-X-Coder.java.template
  • 1c44834: 8333582: Update CLDR to Version 46.0
  • 23fa1a3: 8343484: Remove unnecessary @SuppressWarnings annotations (nio)
  • 7f8450c: 8343473: Update copyright year of AddmodsOption.java
  • b74652b: 8343167: Unnecessary define checks in InterpreterRuntime after JDK-8199809
  • ... and 296 more: https://git.openjdk.org/jdk/compare/1581508988141bfb420d97759138203f30926b35...master

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 Jul 2, 2024

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

@openjdk openjdk bot added hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jul 2, 2024
@openjdk
Copy link

openjdk bot commented Jul 4, 2024

⚠️ @theRealAph This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 14, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 15, 2024
@theRealAph
Copy link
Contributor Author

By the way, to see the performance benefit of this patch run the test case SecondarySuperCacheInterContention.java, like so:

/build/macosx-aarch64-server-fastdebug/jdk/bin/java -XX:-UseSecondarySupersTable -XX:+UseSecondarySupersCache -jar build/macosx-aarch64-server-fastdebug/images/test/micro/benchmarks.jar SecondarySuperCacheInterContention

Copy link
Member

@dean-long dean-long left a comment

Choose a reason for hiding this comment

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

Latest version looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 16, 2024
Copy link
Contributor

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

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

Testing results (hs-tier1 - hs-tier4) for latest version look good.


// This next instruction is equivalent to:
// mov(tmp_reg, (u1)(Klass::SECONDARY_SUPERS_TABLE_SIZE - 1));
// sub(temp2, r_array_index, tmp_reg);
Copy link
Member

@RealFYang RealFYang Oct 21, 2024

Choose a reason for hiding this comment

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

One minor question about the code comment. Should this line be: // sub(temp2, tmp_reg, slot);?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is. Good spot.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 21, 2024
@zifeihan
Copy link
Member

@theRealAph Hi, And here is the version for riscv: zifeihan@2c52968 . Do you want to have it in this PR? Or shall I create another one? Thanks. By the way, Already passed tier1-tier3 tests on the linux-riscv64 platform(SOPHON SG2042).

@theRealAph
Copy link
Contributor Author

@theRealAph Hi, And here is the version for riscv: zifeihan@2c52968 . Do you want to have it in this PR? Or shall I create another one? Thanks. By the way, Already passed tier1-tier3 tests on the linux-riscv64 platform(SOPHON SG2042).

There's no need to merge with this PR. It should be a simple enough thing to approve.

@theRealAph
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 4, 2024

@theRealAph This pull request has not yet been marked as ready for integration.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Re-approved after comment update.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 4, 2024
@theRealAph
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 6, 2024

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

  • 06d8216: 8318442: java/net/httpclient/ManyRequests2.java fails intermittently on Linux
  • bdd6816: 8343502: RISC-V: SIGBUS in updateBytesCRC32 after JDK-8339738
  • 4431852: 8342943: Replace predicate walking and cloning code for main/post loops with a predicate visitor
  • 1b0281d: 8333427: langtools/tools/javac/newlines/NewLineTest.java is failing on Japanese Windows
  • 471f112: 8342577: Clean up JVMTI breakpoint support
  • 69bc088: 8343071: Broken anchors to restricted method page and some redundant ids
  • d4d9831: 8340454: C2 EA asserts with "previous reducible Phi is no longer reducible before SUT"
  • 2a1ae0f: 8331008: Implement JEP 478: Key Derivation Function API (Preview)
  • 847cc5e: 8343173: Remove ZGC-specific non-JVMCI test groups
  • 3fab8e3: 8341903: Implementation of Scoped Values (Fourth Preview)
  • ... and 324 more: https://git.openjdk.org/jdk/compare/1581508988141bfb420d97759138203f30926b35...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 6, 2024

@theRealAph Pushed as commit ead0116.

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

10 participants