JDK-8324739 : Incorrect result of C2 compiled code
  • Type: Sub-task
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 15,17,21,23
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-01-18
  • Updated: 2024-03-12
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.
Other
tbdUnresolved
Description
ADDITIONAL SYSTEM INFORMATION :
$ java --version
java 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)

$ 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
UBUNTU_CODENAME=jammy

A DESCRIPTION OF THE PROBLEM :
Decription: We downloaded JDK 17 from [the official Oracle website](https://www.oracle.com/java/technologies/downloads/) and ran test code below, and discover that JDK 17 produces different results under default settings and when using the -Xcomp option. Further testing revealed that under default settings, JDK 17 might also produce incorrect results. Additionally, the same issue was observed with OpenJDK's JDK 17u.

ACTUAL -
$ pathToOracleJDK-17.0.10/bin/java -Xcomp Test
297439200
$ pathToOracleJDK-17.0.10/bin/java Test
313920000

# sometimes
$ pathToOracleJDK-17.0.10/bin/java Test
299750000

# jdk17u
$ pathToJDK17u/bin/java Test
301058000
$ pathToJDK17u/bin/java Test
300491200
$ pathToJDK17u/bin/java Test
313920000
$ pathToJDK17u/bin/java -Xcomp Test
297439200



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

    void mainTest(String[] strArr1) {
        for (int i0 = 0; i0 < N; ++i0) {
            long[] c = new long[N];
            for (int i9 = 169; 9 < i9; i9 -= 2)
                for (int i11 = 1; i11 < 19; i11++) {
                    c[i11] = 43600;
                    synchronized (new Test()) { }
                }
            for (int i = 0; i < N; i++) {
                a += c[i];
            }
        }
        System.out.println(a);
    }

    public static void main(String[] strArr) {
        Test _instance = new Test();
        _instance.mainTest(strArr);
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Very similar to other recent reports and most likely the same issue, converted to subtask of JDK-8327963.
12-03-2024

[~cslucas] Thank you for investigation. So it is different issue :(
09-02-2024

I attached a smaller test case that as far as I can tell has the same problem. I used the following flags to repro the problem in the new test case: `-XX:+UnlockExperimentalVMOptions -Xcomp -server -XX:-UseOnStackReplacement -XX:LoopMaxUnroll=2 -XX:-TieredCompilation -XX:-ReduceAllocationMerges -XX:CompileCommand=dontinline,*Test*::*test* -XX:CompileCommand=compileonly,*Test*::*test* -XX:+PrintEliminateAllocations TestIncorrectResult` [~kvn] I tried v00 of my patch for JDK-8322854 on Test.java and the error still happens.
09-02-2024

I tested latest JDK 17u with latest (v02) version of JDK-8322854 patch. It fails. When I used initial version (v00) of fix it passed. More investigation needed to see why adding `, /*io_use:*/false` disabled fix.
07-02-2024

Okay, thanks for the clarification, Vladimir.
06-02-2024

The fix for JDK-8322854 is general for EA: https://git.openjdk.org/jdk/pull/17562 and not specific for Allocations merge changes Cesar implemented. I did not test it with JDK 17 or 15. I leave this testing to Roberto.
06-02-2024

[~kvn], but JDK-8322854 only affects JDK 22 / 23 and this also reproduces with JDK 15.
05-02-2024

Original test also produce correct result with that fix.
01-02-2024

Test passed when I applied JDK-8322854 fix.
01-02-2024

It is not JDK-8322743, I checked. Something to do with EA eliminating array: NotUsed 286 AllocateArray === 988 991 250 8 1 (282 82 25 275 37 1 11 12 1 1 78 116 848 1 1 535 1 535 537 ) [[ 287 288 289 296 297 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, int, bool ) Test2::<init> @ bci:8 (line 2) Test2::test @ bci:38 (line 10) !jvms: Test2::<init> @ bci:8 (line 2) Test2::test @ bci:38 (line 10) ++++ Eliminated: 286 AllocateArray Incorrect value is found when going through memory in loop. So it could be JDK-8322854.
01-02-2024

ILW = Incorrect result with C2 compiled code, reproducible with targeted test but not a recent regression, disable compilation of affected method = HLM = P3
29-01-2024

I modified the test. Attached Test.java also reproduces with latest JDK 23 and back to JDK 15 (first after JDK-8239072 which seems to be unrelated).
29-01-2024

First reproduces after JDK-8219555 in JDK 17 b13 and does not reproduce anymore after JDK-8281429 in JDK 19 b22.
29-01-2024