jdk
jdk copied to clipboard
8359678: C2: assert(static_cast<T1>(result) == thing) caused by ReverseBytesNode::Value()
Fixes an assertion when passing an int larger than short/char to the corresponding reverseBytes method in a constant-folding scenario. By just using static_cast, we can ignore the upper bytes and just swap the lower bytes.
Using jasm, I added a test case that covers such inputs. It felt easier to test this way than the other scenarios mentioned in the bug report.
I also removed the redundant checked_cast calls from the int/long case; we already have the correct type there.
Please review. Thanks.
Progress
- [ ] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
Issue
- JDK-8359678: C2: assert(static_cast<T1>(result) == thing) caused by ReverseBytesNode::Value() (Bug - P3)(⚠️ The fixVersion in this issue is [25] but the fixVersion in .jcheck/conf is 26, a new backport will be created when this pr is integrated.)
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25988/head:pull/25988
$ git checkout pull/25988
Update a local copy of the PR:
$ git checkout pull/25988
$ git pull https://git.openjdk.org/jdk.git pull/25988/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25988
View PR using the GUI difftool:
$ git pr show -t 25988
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25988.diff
Using Webrev
:wave: Welcome back hgreule! 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.
@SirYwell 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:
8359678: C2: assert(static_cast<T1>(result) == thing) caused by ReverseBytesNode::Value()
Reviewed-by: mhaessig, dlong, 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 225 new commits pushed to the master branch:
- 18c2e40de75f974858aeb453892e4c7c8d5aa90e: 8354415: [Ubuntu25.04] api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode - setDisplayMode_REFRESH_RATE_UNKNOWN fails: Height is different on vnc
- 40d159d4a9718d8db0aadf66b322583cd5246d0c: 8362116: System.in.read() etc. don't accept input once immediate Ctrl+D pressed in JShell
- 25e509b0db4f35b3b8fbfeb7ec84cc0e0fed89d1: 8362097: JFR: Active Settings view broken
- ... and 222 more: https://git.openjdk.org/jdk/compare/f2ef809719cbb14f90a0a5f673e10e7c74fa0f45...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.
As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@eme64, @mhaessig, @dean-long, @TobiHartmann) but any other Committer may sponsor as well.
➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).
@SirYwell 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.
Webrevs
- 04: Full - Incremental (271d162a)
- 03: Full - Incremental (f8cc3496)
- 02: Full - Incremental (f352726e)
- 01: Full - Incremental (6822cca0)
- 00: Full (b0ff150b)
@iwanowww @eme64 as you reviewed the original change, could you have a look at this? Thank you very much.
You forgot to add the new tests to the array of tests in @Run:
stderr: Exception in thread "main" compiler.lib.ir_framework.shared.TestRunException:
Test Failures (1)
-----------------
Custom Run Test: @Run: runMethod - @Tests: {testI1,testI2,testI3,testL1,testL2,testL3,testS1,testS2,testS3,testUS1,testUS2,testUS3}:
compiler.lib.ir_framework.shared.TestRunException: There was an error while invoking @Run method public void ReverseBytesConstantsTests.runMethod()
at compiler.lib.ir_framework.test.CustomRunTest.invokeTest(CustomRunTest.java:162)
at compiler.lib.ir_framework.test.AbstractTest.run(AbstractTest.java:100)
at compiler.lib.ir_framework.test.CustomRunTest.run(CustomRunTest.java:89)
at compiler.lib.ir_framework.test.TestVM.runTests(TestVM.java:865)
at compiler.lib.ir_framework.test.TestVM.start(TestVM.java:255)
at compiler.lib.ir_framework.test.TestVM.main(TestVM.java:168)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at compiler.lib.ir_framework.test.CustomRunTest.invokeTest(CustomRunTest.java:159)
... 5 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -24674 out of bounds for length 128
at java.base/java.lang.Character.valueOf(Character.java:9284)
at ReverseBytesConstantsTests.assertResultUS(ReverseBytesConstantsTests.java:102)
at ReverseBytesConstantsTests.runMethod(ReverseBytesConstantsTests.java:66)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 7 more
at compiler.lib.ir_framework.test.TestVM.runTests(TestVM.java:901)
at compiler.lib.ir_framework.test.TestVM.start(TestVM.java:255)
at compiler.lib.ir_framework.test.TestVM.main(TestVM.java:168)
Thanks @mhaessig. It seems like the methods don't need to be added there, as other methods were missing too. I updated the list nonetheless.
Regarding the exception, I'm not sure what the expectations and guarantees are here. Does Java code have to expect inputs that are illegal in Java but legal in bytecode? I can work around this by casting the result to int explicitly (to compare Integer objects instead), but I feel like this is a deeper problem.
Oh I see, that explains why I didn't run into that problem testing on my x86 machine :) The Short.valueOf(short) case doesn't crash because the method checks the lower bound too, it's just that Character.valueOf(char) assumes that the given value is >= 0 and therefore accesses the array if the value actually is < 0.
I started a test run for the latest version. Please hold off on integrating until the results are in.
/integrate
Thank you all for your reviews and comments.
@SirYwell Your change (at version 271d162a6574e43bf2149fcff71193497cf5bef6) is now ready to be sponsored by a Committer.
/sponsor
Going to push as commit e5ab210713f76c5307287bd97ce63f9e22d0ab8e.
Since your change was applied there have been 225 commits pushed to the master branch:
- 18c2e40de75f974858aeb453892e4c7c8d5aa90e: 8354415: [Ubuntu25.04] api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode - setDisplayMode_REFRESH_RATE_UNKNOWN fails: Height is different on vnc
- 40d159d4a9718d8db0aadf66b322583cd5246d0c: 8362116: System.in.read() etc. don't accept input once immediate Ctrl+D pressed in JShell
- 25e509b0db4f35b3b8fbfeb7ec84cc0e0fed89d1: 8362097: JFR: Active Settings view broken
- ... and 222 more: https://git.openjdk.org/jdk/compare/f2ef809719cbb14f90a0a5f673e10e7c74fa0f45...master
Your commit was automatically rebased without conflicts.
@TobiHartmann @SirYwell Pushed as commit e5ab210713f76c5307287bd97ce63f9e22d0ab8e.
:bulb: You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.
/backport :jdk25
@TobiHartmann the backport was successfully created on the branch backport-TobiHartmann-e5ab2107-jdk25 in my personal fork of openjdk/jdk. To create a pull request with this backport targeting openjdk/jdk:jdk25, just click the following link:
:arrow_right: Create pull request
The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
Hi all,
This pull request contains a backport of commit e5ab2107 from the openjdk/jdk repository.
The commit being backported was authored by Hannes Greule on 15 Jul 2025 and was reviewed by Manuel Hässig, Dean Long and Tobias Hartmann.
Thanks!
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk:
$ git fetch https://github.com/openjdk-bots/jdk.git backport-TobiHartmann-e5ab2107-jdk25:backport-TobiHartmann-e5ab2107-jdk25
$ git checkout backport-TobiHartmann-e5ab2107-jdk25
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk.git backport-TobiHartmann-e5ab2107-jdk25