Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenJ9-11 Incorrect array optimizations #19014

Closed
TemporaryRepos opened this issue Feb 26, 2024 · 5 comments
Closed

OpenJ9-11 Incorrect array optimizations #19014

TemporaryRepos opened this issue Feb 26, 2024 · 5 comments

Comments

@TemporaryRepos
Copy link

Affected versions

We found a test case with execution problems. To facilitate analysis, we simplified the test case and the simplified class file can ben found at attachment.

Linux Ubuntu20.04

Java -version output under Linux

openjdk version "1.8.0_402"
IBM Semeru Runtime Open Edition (build 1.8.0_402-b06)
Eclipse OpenJ9 VM (build openj9-0.43.0, JRE 1.8.0 Linux amd64-64-Bit Compressed References 20240131_861 (JIT enabled, AOT enabled)
OpenJ9   - 2c3d78b48
OMR      - ea8124dbc
JCL      - 0fa9d9c532 based on jdk8u402-b06)
openjdk version "11.0.22" 2024-01-16
IBM Semeru Runtime Open Edition 11.0.22.0 (build 11.0.22+7)
Eclipse OpenJ9 VM 11.0.22.0 (build openj9-0.43.0, JRE 11 Linux amd64-64-Bit Compressed References 20240131_966 (JIT enabled, AOT enabled)
OpenJ9   - 2c3d78b48
OMR      - ea8124dbc
JCL      - 7876cac747 based on jdk-11.0.22+7)
openjdk version "17.0.10" 2024-01-16
IBM Semeru Runtime Open Edition 17.0.10.0 (build 17.0.10+7)
Eclipse OpenJ9 VM 17.0.10.0 (build openj9-0.43.0, JRE 17 Linux amd64-64-Bit Compressed References 20240116_670 (JIT enabled, AOT enabled)
OpenJ9   - 2c3d78b48
OMR      - ea8124dbc
JCL      - 2aad089841f based on jdk-17.0.10+7)

Problem summary

This test case mainly contains a 10000 times loop in the main function and a series of array operations inside the loop, which should not throw any Exception under normal circumstances, e.g. OpenJ9-8 and Hotspot can be executed correctly, but OpenJ9-11 and OpenJ9-17 will throw an ArrayIndexOutOfBoundsException. In addition to this, we also tried setting the parameter -Xint, which also does not throw an Exception.

public class TestArrayCopy {
    public TestArrayCopy() {
    }

    public static void main(String[] var0) {
        int var1 = Integer.MIN_VALUE;

        for(int var6 = 0; var6 < 1000000; ++var6) {
            int var3 = -1;
            float[] var4 = new float[100];
            float var5 = 1.0F;
            int var2;
            if (var1 * 2 < var4.length) {
                var4[var1 * 2] = var4[var1 * 2];
                var2 = var1 + 1;
            }

            while(var3 < 10) {
                ++var3;
            }

            int[] var10;
            int[] var10000 = var10 = new int[20];
            System.arraycopy(var10000, var3, var10, var3, 1);
            var2 = var1 * var3;
            boolean var9 = false;
            System.arraycopy(var10000, var2, var10, var2, 1);
        }

        short[] var8 = new short[0];
        boolean var7 = false;
    }
}

Steps to Reproduce

java-11/bin/java compiler.c1.TestArrayCopy

Expected Result

nothing

Actual Result

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
	at compiler.c1.TestArrayCopy.main(TestArrayCopy.java)

Attachment

202402261500.zip

@pshipton
Copy link
Member

@hzongaro fyi. I tagged 0.44 but pls move it forward if that is not appropriate.

@hzongaro
Copy link
Member

e.g. OpenJ9-8 and Hotspot can be executed correctly, but OpenJ9-11 and OpenJ9-17 will throw an ArrayIndexOutOfBoundsException.

I was able to reproduce the ArrayIndexOutOfBoundsException with a JDK 8 build of OpenJ9 as well. I can reproduce the failure using lastOptIndex=47 but not lastOptIndex=46. This appears to be a problem with Tree Simplification.

./openj9-openjdk-jdk8/build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/java -Xjit:limit={TestArrayCopy.main*},lastOptIndex=46,log=testarraycopy.main.idx46.log,optDetails TestArrayCopy
./openj9-openjdk-jdk8/build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/java -Xjit:limit={TestArrayCopy.main*},lastOptIndex=47,log=testarraycopy.main.idx47.log,optDetails TestArrayCopy
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
        at TestArrayCopy.main(TestArrayCopy.java:14)

I'm going to move this out of 0.45. The test involves an array bound check for an assignment that shouldn't be executed because of an overflow involving Integer.MIN_VALUE * 2, so it's a bit of an edge case.

@hzongaro
Copy link
Member

@nbhuiyan, may I ask you to look at this for the 0.45 release?

@nbhuiyan
Copy link
Member

There is a duplicate issue #19139 opened where the investigation and discussions will continue. Therefore, this issue can be closed.

@hzongaro
Copy link
Member

Duplicate of #19139

@hzongaro hzongaro marked this as a duplicate of #19139 May 16, 2024
@hzongaro hzongaro closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants