eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.27k stars 721 forks source link

Value Types: java.lang.ArrayStoreException with null-restricted array with -Xint #20223

Open a7ehuo opened 4 hours ago

a7ehuo commented 4 hours ago

I'm running the following test with the latest openj9-openjdk-jdk.valuetypes with -Xint

public class TestNullRestrictedArray {

    public static int ARRAY_SIZE = 100;

    static private void test1(int x) {
       SomeValueClass1[] array1 = (SomeValueClass1[])ValueClass.newArrayInstance(NullRestrictedCheckedType.of(SomeValueClass1.class), ARRAY_SIZE);
       SomeValueClass1[] array2 = new SomeValueClass1[ARRAY_SIZE];

        for (int i=0; i < ARRAY_SIZE; i++) {
            array1[i] = new SomeValueClass1(i*x);
            array2[i] = new SomeValueClass1(i*x);
        }

        System.arraycopy(array2, 0, array1, 0, ARRAY_SIZE);
    }

    static private void test2(int x) {
       SomeValueClass1[] array1 = (SomeValueClass1[])ValueClass.newArrayInstance(NullRestrictedCheckedType.of(SomeValueClass1.class), ARRAY_SIZE);
       SomeValueClass1[] array2 = new SomeValueClass1[ARRAY_SIZE];

        for (int i=0; i < ARRAY_SIZE; i++) {
            array1[i] = new SomeValueClass1(i*x);
            array2[i] = new SomeValueClass1(i*x);
        }

        System.arraycopy(array1, 0, array2, 0, ARRAY_SIZE);
    }

   public static void main(String[] args) {
     test1(1);
     test2(1);
   }
}

java.lang.ArrayStoreException happens with both test1 and test2. These two tests copy between a null-restricted array and a regular array with array flattening enabled.

java --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/jdk.internal.value=ALL-UNNAMED --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED --enable-preview -XX:ValueTypeFlatteningThreshold=99999 -XX:+EnableArrayFlattening -Xint TestNullRestrictedArray 
Exception in thread "main" java.lang.ArrayStoreException
    at java.base/java.lang.System.arraycopy(Native Method)
    at TestNullRestrictedArray.test1(TestNullRestrictedArray.java:32)
    at TestNullRestrictedArray.main(TestNullRestrictedArray.java:54)
java --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/jdk.internal.value=ALL-UNNAMED --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED --enable-preview -XX:ValueTypeFlatteningThreshold=99999 -XX:+EnableArrayFlattening -Xint TestNullRestrictedArray 
Exception in thread "main" java.lang.ArrayStoreException
    at java.base/java.lang.System.arraycopy(Native Method)
    at TestNullRestrictedArray.test2(TestNullRestrictedArray.java:46)
    at TestNullRestrictedArray.main(TestNullRestrictedArray.java:56)
a7ehuo commented 4 hours ago

@hangshao0 @theresa-m If I'm not mistaken, I'm under the impression that null restricted array should work with the latest code with the interpreter. Could you take a look? Thank you!

@hzongaro fyi

hangshao0 commented 3 hours ago

Once fixed, the test cases here should be added into https://github.com/eclipse-openj9/openj9/blob/master/test/functional/Valhalla/src_qtypes/org/openj9/test/lworld/ValueTypeSystemArraycopyTests.java.