JDK-8297689 : Fix incorrect result of Short.reverseBytes() call in loops
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 19,20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-11-28
  • Updated: 2022-12-12
  • Resolved: 2022-12-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b27Fixed
Related Reports
Relates :  
Description
Recently, we find calling `Short.reverseBytes()` in loops may generate
incorrect result if the code is compiled by C2. Below is a simple case
to reproduce.


class Foo {
  static final int SIZE = 50;
  static int a[] = new int[SIZE];

  static void test() {
    for (int i = 0; i < SIZE; i++) {
      a[i] = Short.reverseBytes((short) a[i]);
    }
  }

  public static void main(String[] args) throws Exception {
    Class.forName("java.lang.Short");
    a[25] = 16;
    test();
    System.out.println(a[25]);
  }
}

// $ java -Xint Foo
// 4096
// $ java -Xcomp -XX:-TieredCompilation -XX:CompileOnly=Foo.test Foo
// 268435456
Comments
Changeset: a6139985 Author: Pengfei Li <pli@openjdk.org> Date: 2022-12-06 09:16:47 +0000 URL: https://git.openjdk.org/jdk/commit/a61399854a9db8e3c0cb3f391fa557cb37e02571
06-12-2022

Thank you!
30-11-2022

Sure, I have attached that. But I just modified that tentatively and randomly. I don't really understand all the configuration items of that.
30-11-2022

Interesting, could you share the exact changes that you did?
30-11-2022

I have updated the configuration yaml file and re-generated some test cases with more loops. I believe it's a useful tool to find loop optimization issues.
30-11-2022

Thanks for the information. Yes, we are running JavaFuzzer as well but haven't found that issue yet. I'll take a look at the PR.
30-11-2022

JavaFuzzer, IIRC, this tool is what you have introduced to me before. I just created a PR to fix. Could you help take a look?
30-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/11427 Date: 2022-11-30 07:20:11 +0000
30-11-2022

Just curious, what kind of test generator did you use to find this?
29-11-2022

Yes, this is found by a fuzzer test.
29-11-2022

ILW = Incorrect result with Short.reverseBytes(), single test case/low?, disable affected intrinsic: -XX:DisableIntrinsic=_reverseBytes_s = HLM = P3
28-11-2022