JDK-8329536 : Mis-compilation in jdk17, jdk21 and jdk23
  • Type: Bug
  • Component: hotspot
  • Affected Version: 23
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2024-03-29
  • Updated: 2024-04-02
Description
ADDITIONAL SYSTEM INFORMATION :
```bash
$ cat /etc/os-release
VERSION="22.04.4 LTS (Jammy Jellyfish)"

$ oracle-jdk-21.0.2/bin/java -version
java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)

$ oracle-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)

$ jdk23u/bin/java -version
openjdk version "23-internal" 2024-09-17
OpenJDK Runtime Environment (fastdebug build 23-internal-adhoc.jdk23u)
OpenJDK 64-Bit Server VM (fastdebug build 23-internal-adhoc.jdk23u, mixed mode)
```

A DESCRIPTION OF THE PROBLEM :
When I compile and run the following code with JDK, I sometimes get incorrect results. The JDK versions involved include:
- jdk17u (source code from github jdk17u repo)
- oracle-jdk-17 (binary download from Oracle website)
- jdk21u (source code from github jdk21u repo)
- oracle-jdk-21 (binary download from Oracle website)
- jdk23u (source code from github jdk repo)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java Test

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
6528000
13056000
19584000
26112000
32640000
39168000
45696000
52224000
58752000
65280000

ACTUAL -
6528000
13056000
19584000
26112000
32640000
38743680
44814720
50885760
56956800
63027840


---------- BEGIN SOURCE ----------
class Test {
    int N = 256;
    long instanceCount;
    int[] iArrFld = new int[N];
    long vMeth_check_sum = 0;

    void vMeth() {
        int[] iArr = new int[N];
        for (int i12 = 1; i12 < 3; ++i12) {
            i12 <<= instanceCount;
            for (int i = 0; i < iArr.length; ++i)
                vMeth_check_sum += i;
        }
    }

    void mainTest(String[] strArr1) {
        int i = 6, i2;
        for (int i1 = 6; i1 < 149; ++i1) {
            try {
                i2 = i / iArrFld[i1 - 1];
                i = i1;
            } catch (ArithmeticException a_e) {
            }
            vMeth();
            instanceCount -= 8;
            for (int i28 = i1; i28 < 35; i28++) {
                instanceCount *= i;
                iArrFld[i1] <<= 11;
                synchronized (new Test()) {
                }
            }
        }
        for (int i30 = 5; i30 < 134; ++i30) {
            int var46 = 0;
            do var46++; while (var46 < 20000);
            iArrFld[i30] = 11;
        }
        System.out.println(vMeth_check_sum);
    }

    public static void main(String[] strArr) {
        Test _instance = new Test();
        for (int i = 0; i < 10; i++) _instance.mainTest(strArr);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use -Xint to disable JIT