Skip to content

Commit

Permalink
Allow arrayCopy between null-restricted and nullable
Browse files Browse the repository at this point in the history
Signed-off-by: Theresa Mammarella <Theresa.T.Mammarella@ibm.com>
  • Loading branch information
theresa-m committed Sep 30, 2024
1 parent ed75984 commit 56d07c6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
5 changes: 4 additions & 1 deletion runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,10 @@ class INTERPRETER_CLASS
J9Class *destComponentClass = ((J9ArrayClass *)destClazz)->componentType;

if (J9_IS_J9CLASS_FLATTENED(srcClazz) && J9_IS_J9CLASS_FLATTENED(destClazz) && J9_ARE_NO_BITS_SET(srcComponentClass->classFlags, J9ClassHasReferences) && J9_ARE_NO_BITS_SET(destComponentClass->classFlags, J9ClassHasReferences)) {
if (srcClazz == destClazz) {
if (srcClazz == destClazz
|| (J9_IS_J9ARRAYCLASS_NULL_RESTRICTED(srcClazz) && (((J9ArrayClass *)srcClazz)->companionArray == destClazz))
|| (J9_IS_J9ARRAYCLASS_NULL_RESTRICTED(destClazz) && (srcClazz == ((J9ArrayClass *)destClazz)->companionArray))
) {
UDATA elementSize = J9ARRAYCLASS_GET_STRIDE(srcClazz);
/* This only works for contiguous flattened arrays, since discontiguous flattened arrays are not supported by GC */
VM_ArrayCopyHelpers::primitiveArrayCopy(_currentThread, srcObject, srcStart * elementSize, destObject, destStart * elementSize, elementSize * elementCount, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;

import jdk.internal.value.NullRestrictedCheckedType;
import jdk.internal.value.ValueClass;
import jdk.internal.vm.annotation.ImplicitlyConstructible;
import jdk.internal.vm.annotation.NullRestricted;
Expand Down Expand Up @@ -60,6 +59,7 @@ public static class SomeIdentityClass2 implements SomeInterface {
}
}

@ImplicitlyConstructible
public value static class SomeValueClass implements SomeInterface {
double val1;
long val2;
Expand Down Expand Up @@ -117,12 +117,14 @@ public static value class SomePrimitiveValueClass2 implements SomeInterface {
public static SomeValueClass[] vtArrayDst = new SomeValueClass[ARRAY_SIZE];
public static SomeValueClass[] vtArraySrc = new SomeValueClass[ARRAY_SIZE];
public static SomePrimitiveValueClass[] primitiveVtArrayDst =
(SomePrimitiveValueClass[])ValueClass.newArrayInstance(
NullRestrictedCheckedType.of(SomePrimitiveValueClass.class), ARRAY_SIZE);
(SomePrimitiveValueClass[])ValueClass.newNullRestrictedArray(SomePrimitiveValueClass.class, ARRAY_SIZE);
public static SomePrimitiveValueClass[] primitiveVtArraySrc =
(SomePrimitiveValueClass[])ValueClass.newArrayInstance(
NullRestrictedCheckedType.of(SomePrimitiveValueClass.class), ARRAY_SIZE);

(SomePrimitiveValueClass[])ValueClass.newNullRestrictedArray(SomePrimitiveValueClass.class, ARRAY_SIZE);
/* These arrays should replace primitiveVTArrayDst/Src once javac supports null-restricted classes. */
public static SomeValueClass[] nullRestrictedVtArraySrc =
(SomeValueClass[])ValueClass.newNullRestrictedArray(SomeValueClass.class, ARRAY_SIZE);
public static SomeValueClass[] nullRestrictedVtArrayDst =
(SomeValueClass[])ValueClass.newNullRestrictedArray(SomeValueClass.class, ARRAY_SIZE);
public static SomeInterface[] ifIdArrayDst = new SomeIdentityClass[ARRAY_SIZE];
public static SomeInterface[] ifIdArraySrc = new SomeIdentityClass[ARRAY_SIZE];
public static SomeInterface[] ifVtArrayDst = new SomeValueClass[ARRAY_SIZE];
Expand All @@ -135,8 +137,7 @@ public static value class SomePrimitiveValueClass2 implements SomeInterface {

public static SomeIdentityClass[] idArrayDstCheckForException = new SomeIdentityClass[ARRAY_SIZE];
public static SomePrimitiveValueClass[] primitiveVtArrayDstCheckForException =
(SomePrimitiveValueClass[])ValueClass.newArrayInstance(
NullRestrictedCheckedType.of(SomePrimitiveValueClass.class), ARRAY_SIZE);
(SomePrimitiveValueClass[])ValueClass.newNullRestrictedArray(SomePrimitiveValueClass.class, ARRAY_SIZE);

static private void initArrays() {
for (int i=0; i < ARRAY_SIZE; i++) {
Expand All @@ -162,6 +163,9 @@ static private void initArrays() {
ifArray1[i] = new SomeIdentityClass(i*13);
ifArray2[i] = new SomeValueClass(i*14);
ifArray3[i] = new SomePrimitiveValueClass(i*15);

nullRestrictedVtArrayDst[i] = new SomeValueClass(i*16);
nullRestrictedVtArraySrc[i] = new SomeValueClass(i*17);
}
}

Expand Down Expand Up @@ -465,7 +469,7 @@ static public void testSystemArrayCopy8() throws Throwable {
checkResults(primitiveVtArraySrc, ifPrimitiveVtArrayDst);
}

@Test(priority=1)
@Test(priority=1) // TODO is this the same test?
static public void testSystemArrayCopy9() throws Throwable {

initArrays();
Expand Down Expand Up @@ -821,4 +825,16 @@ static public void testSystemArrayCopy26() throws Throwable {

Assert.fail("Expect a ArrayStoreException. No exception or wrong kind of exception thrown");
}

@Test(priority=1)
static public void testSystemArrayCopy27() throws Throwable {
initArrays();
testVTVT(vtArraySrc, nullRestrictedVtArrayDst);
}

@Test(priority=1)
static public void testSystemArrayCopy28() throws Throwable {
initArrays();
testVTVT(nullRestrictedVtArraySrc, vtArrayDst);
}
}

0 comments on commit 56d07c6

Please sign in to comment.