Skip to content

8286190: Add test to verify constant folding for Enum fields #8551

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

shipilev
Copy link
Member

@shipilev shipilev commented May 5, 2022

There is the JDK-8161245 to make compilers trust Enum final fields. It was implicitly implemented by JDK-8234049, which added the wildcard trust for everything in java/lang:

holder->is_in_package("java/lang"))

It would be better to have the explicit test that verifies the constant folding of Enum fields indeed happens.

Additional testing:

  • Linux x86_64 fastdebug, new test passes
  • Linux x86_64 release, new test passes
  • Linux x86_32 fastdebug, new test passes

Progress

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

Issue

  • JDK-8286190: Add test to verify constant folding for Enum fields

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8551/head:pull/8551
$ git checkout pull/8551

Update a local copy of the PR:
$ git checkout pull/8551
$ git pull https://git.openjdk.java.net/jdk pull/8551/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8551

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8551.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 5, 2022

👋 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 openjdk bot added the rfr Pull request is ready for review label May 5, 2022
@openjdk
Copy link

openjdk bot commented May 5, 2022

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

  • hotspot-compiler

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-compiler hotspot-compiler-dev@openjdk.org label May 5, 2022
@mlbridge
Copy link

mlbridge bot commented May 5, 2022

Webrevs

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.

Nice find. So we are doing ENUM constant folding since JDK 14 and did not notice it ;)

Test is good. Thanks!

@openjdk
Copy link

openjdk bot commented May 5, 2022

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

8286190: Add test to verify constant folding for Enum fields

Reviewed-by: kvn, thartmann

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

  • 015cfda: 8262004: Classpath separator: Man page says semicolon; should be colon on Linux
  • 9425ab2: 8286153: Remove redundant casts and other cleanup
  • 7ebc4bc: 8286066: assert(k != __null) failed: klass not loaded caused by FillerObject_klass
  • 6a1b145: 8286029: Add classpath exemption to globals_vectorApiSupport_***.S.inc
  • 59ef76a: 8285497: Add system property for Java SE specification maintenance version
  • 6d7e446: 8283306: re-resolving indirect call to non-entrant nmethod can crash
  • 4957bc7: 8286056: AArch64: clarify uses of MacroAssembler::far_call/MacroAssembler::far_jump
  • e7adc28: 8284675: "jpackage.exe" creates application launcher without Windows Application Manfiest
  • 9644a31: 8285616: [macos] Incorrect path for launcher-as-service.txt in .cfg file
  • 2f995c8: 8286199: ProblemList jdk/jshell/ExternalEditorTest.java
  • ... and 23 more: https://git.openjdk.java.net/jdk/compare/497a94fead145788af6f196d2c7166efc46a9e9e...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 openjdk bot added the ready Pull request is ready to be integrated label May 5, 2022
@mlbridge
Copy link

mlbridge bot commented May 5, 2022

Mailing list message from John Rose on hotspot-compiler-dev:

This reminds me that our enum switches do not allow constant folding,
because of our translation strategy.

The root cause is that the T.S. open-codes the discrimination logic for
switches, and it happens to use Java arrays, which cannot be
constant-folded. There is a way to ?trust? an array element, called
`@Stable`, but it can only be used inside a JDK runtime support method,
not in a random classfile generated by javac.

So the T.S. should encapsulate switch discrimination logic so that a
runtime support routine can use appropriate technology, such as stable
arrays and/or perfect hashes and/or binary searches. It?s not really
javac?s job to build such things, and when it tries it just gets in
the way of doing a better job in the runtime.

https://bugs.openjdk.java.net/browse/JDK-8161250 tracks this general
issue.

These points relate to this bug only in that, if we had our ducks in a
row with translation of switch, we could test also for constant-folding
of switch logic.

On 5 May 2022, at 8:45, Vladimir Kozlov wrote:

Copy link
Member

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

@shipilev
Copy link
Member Author

shipilev commented May 6, 2022

Thanks!

/integrate

@openjdk
Copy link

openjdk bot commented May 6, 2022

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

  • 1277f5d: 8286154: Fix 3rd party notices in test files
  • 2dd4dfd: 8286291: G1: Remove unused segment allocator printouts
  • b9f4370: 8286189: G1: Change "wasted" memory to "unused" memory in reporting
  • c6eab98: 8285378: Remove unnecessary nop for C1 exception and deopt handler
  • 3cdedf1: 8248863: Add search landing page to API documentation
  • fa1ca98: 8281429: PhiNode::Value() is too conservative for tripcount of CountedLoop
  • dd06cc6: 8283807: Handle CompileThreshold the same as other thresholds when scaled with -XX:CompileThresholdScaling
  • 015cfda: 8262004: Classpath separator: Man page says semicolon; should be colon on Linux
  • 9425ab2: 8286153: Remove redundant casts and other cleanup
  • 7ebc4bc: 8286066: assert(k != __null) failed: klass not loaded caused by FillerObject_klass
  • ... and 30 more: https://git.openjdk.java.net/jdk/compare/497a94fead145788af6f196d2c7166efc46a9e9e...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 6, 2022

@shipilev Pushed as commit 080f3c5.

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

@shipilev shipilev deleted the JDK-8286190-enum-constant-fold branch May 19, 2022 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants