JDK-8326992 : Incorrect result of C2 compiled code
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 15,17,19
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2024-02-27
  • Updated: 2024-03-01
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 23
23Unresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
```bash
$ ./release-jdk/jdk-17.0.10/bin/java -version
java version "17.0.10" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

$ ./jdk17u-dev/build/linux-x86_64-server-fastdebug/jdk/bin/java -version
openjdk version "17.0.11-internal" 2024-04-16
OpenJDK Runtime Environment (fastdebug build 17.0.11-internal+0-adhoc.user.jdk17u-dev)
OpenJDK 64-Bit Server VM (fastdebug build 17.0.11-internal+0-adhoc.user.jdk17u-dev, mixed mode)

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
```

A DESCRIPTION OF THE PROBLEM :
When I use JDK 17.0.10 and JDK compiled from the jdk17u-dev repository to run the testcase, the testcase outputs incorrect results.

There's a rather strange situation in the testcase: the array b is not used at all, but when I delete the definition of array b, the mis-compilation phenomenon disappears.

REGRESSION : Last worked in version 11.0.22

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java Test

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
160
320
480
640
800
960
1120
1280
1440
1600

ACTUAL -
160
320
480
625
770
915
1060
1205
1350
1495


---------- BEGIN SOURCE ----------
class Test {
  int a = 400;
  int[] b = new int[a];
  long c;

  void k() {
    int[] e = new int[a];
    for (int f = 0; f < 20000; ++f)
      for (int g = 0; g < 20000; g++)
        ;

    int d;
    d = 1;
    while (++d < 34) {
      e[d] = 5;
      synchronized (new Test()) {
      }
    }
    for (int g = 0; g < e.length; g++)
      c += e[g];
    System.out.println(c);
  }

  public static void main(String[] m) {
    Test o = new Test();
    for (int g = 0; g < 10; g++)
      o.k();
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Using -Xint.

FREQUENCY : always



Comments
LW = Incorrect result with C2 compiled code (old issue), reproducible with generated test, no known workaround but disable compilation of affected method = HLM = P3
29-02-2024

I can reproduce this since JDK-8237581 in JDK 15 and until JDK-8281429 in JDK 19 but that fix might just hide the issue. Might be related to JDK-8327012 which also only reproduces after JDK-8237581 in JDK 15.
29-02-2024

Verified in-house with Ubuntu cat /etc/os-release | grep VERSION VERSION_ID="22.04" VERSION="22.04.4 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy and 3 versions of JDK 17: Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240) : Failed Java(TM) SE Runtime Environment (fastdebug build 17.0.11+6-LTS-206) : Failed OpenJDK Runtime Environment OpenLogic-OpenJDK (build 17.0.10+7-adhoc.root.jdk17u) : Failed The WA fixed the issue. Moving to JDK for further analysis. ILW = Failing test that isn't affecting the overall testing, Consistent failures in a test, A workaround exists that is well defined, persistent once implemented and can be implemented at a minimal cost to the customer or end-user = HHL = P2
28-02-2024