Skip to content

Arithmetic Calculation Mismatch in OpenJ9 Leads to Unexpected RuntimeException #22145

@zhang-bokai

Description

@zhang-bokai

Java -version Output (OpenJ9)

openjdk 21.0.7 2025-04-15 LTS
IBM Semeru Runtime Open Edition 21.0.7.0 (build 21.0.7+6-LTS)
Eclipse OpenJ9 VM 21.0.7.0 (build openj9-0.51.0, JRE 21 Linux amd64-64-Bit Compressed References 20250415_458 (JIT enabled, AOT enabled)
OpenJ9   - 31cf5538b0
OMR      - 9bcff94a2
JCL      - 26c2dc3d801 based on jdk-21.0.7+6)

OS Version

Linux f90709baff56 5.15.0-67-generic #74~20.04.1-Ubuntu SMP Wed Feb 22 14:52:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Summary of Problem

When compiling and running the test case below with JDK21 using HotSpot, the program behaves as expected — it executes without any exceptions and prints results normally.

However, when using OpenJ9, the program throws an unexpected RuntimeException during execution, indicating that a logic assertion has failed (suma != sumb), which should not occur under correct JVM behavior.

This suggests a potential issue in how OpenJ9 handles specific operations within nested loops, exception handling blocks, or JIT optimizations.

Reproduce Steps

Source Code of Test.java

public class Test {

    public static long sumsuma = 0;

    public static void vMeth1() throws RuntimeException {
        int a = 51548;
        int b = a;
        int suma = 0;
        int sumb = suma;
        int count1 = 3930;
        do {
            for (float count2 = 4; 1 < count2; count2--) {
                try {
                    java.util.jar.JarFile jarFile = new java.util.jar.JarFile("example-mrjar.jar");
                    java.util.stream.Stream<java.util.jar.JarEntry> stream = jarFile.stream();
                    stream.filter(entry -> entry.getName().startsWith("META-INF/versions/")).forEach(entry -> {
                        System.out.println("Found version-specific entry: " + entry.getName());
                    });
                    stream = jarFile.stream();
                    stream.filter(entry -> !entry.getName().startsWith("META-INF/versions/")).forEach(entry -> {
                        System.out.println("Default entry: " + entry.getName());
                    });
                    jarFile.close();
                } catch (Exception e) {
                    
                }
                suma = a + (a++);
                sumb = b + b; b++;
            }
        } while (--count1 > 0);
        sumsuma += suma;
        if(suma != sumb) {
            System.out.println("Failed");
            throw new RuntimeException("suma != sumb");
        }
    }

    public static void main(String[] strArr) throws RuntimeException {
        for (int i = 0; i < 10; i++) {
            vMeth1();
            System.out.println("sumsuma: " + sumsuma);
        }
    }
}

Compilation Command

javac Test.java

Execution Using HotSpot (Expected Behavior)

/path/to/hotspot/bin/java Test

✅ Program runs successfully without exceptions and completes all iterations.

Execution Using OpenJ9 (Unexpected Behavior)

/path/to/openj9/bin/java Test

❌ Throws the following exception:

Exception in thread "main" java.lang.RuntimeException: suma != sumb
	at Test.vMeth1(Test.java:36)
	at Test.main(Test.java:45)

The exception is thrown because at some point during execution, suma != sumb, which should never happen given the logic in the loop. This indicates a possible bug in OpenJ9's JIT compiler or runtime optimization strategy.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions