Skip to content

Commit

Permalink
Remove flattening flag from nullable arrays
Browse files Browse the repository at this point in the history
Update ValueTypeUnsafeTests  tests to use flattenable array.
Update ValueTypeSystemArraycopyTests to test System.arrayCopy
between nullable and null-restricted arrays.

Signed-off-by: Theresa Mammarella <Theresa.T.Mammarella@ibm.com>
  • Loading branch information
theresa-m committed Oct 2, 2024
1 parent b279a6d commit 958f427
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
4 changes: 4 additions & 0 deletions runtime/oti/j9.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ static const struct { \
#define J9CLASS_UNPADDED_INSTANCE_SIZE(clazz) J9_VALUETYPE_FLATTENED_SIZE(clazz)
#define J9_IS_J9CLASS_ALLOW_DEFAULT_VALUE(clazz) J9_ARE_ALL_BITS_SET((clazz)->classFlags, J9ClassAllowsInitialDefaultValue)
#define J9_IS_J9CLASS_PRIMITIVE_VALUETYPE(clazz) J9_ARE_ALL_BITS_SET((clazz)->classFlags, J9ClassIsPrimitiveValueType)
/**
* This macro can only be used to determine vm flattening for a J9ArrayClass.
* For non-array classes use J9_IS_FIELD_FLATTENED.
*/
#define J9_IS_J9CLASS_FLATTENED(clazz) J9_ARE_ALL_BITS_SET((clazz)->classFlags, J9ClassIsFlattened)

#define J9ROMFIELD_IS_NULL_RESTRICTED(romField) J9_ARE_ALL_BITS_SET((romField)->modifiers, J9FieldFlagIsNullRestricted)
Expand Down
8 changes: 6 additions & 2 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,9 +1234,13 @@ class INTERPRETER_CLASS
}
} else if (J9_IS_J9CLASS_FLATTENED(srcClazz)
|| J9_IS_J9CLASS_FLATTENED(destClazz)
|| J9_IS_J9CLASS_ALLOW_DEFAULT_VALUE(destComponentClass)
|| J9_IS_J9ARRAYCLASS_NULL_RESTRICTED(destClazz)
) {
/* VM_ArrayCopyHelpers::referenceArrayCopy cannot handle flattened arrays or null elements being copied into arrays of primitive value types, so for those cases use copyFlattenableArray instead */
/* VM_ArrayCopyHelpers::referenceArrayCopy cannot handle
* flattened arrays or null elements being copied into
* arrays of null-restricted value types, so for those
* cases use copyFlattenableArray instead.
*/
updateVMStruct(REGISTER_ARGS);
I_32 value = VM_ValueTypeHelpers::copyFlattenableArray(_currentThread, _objectAccessBarrier, _objectAllocate, srcObject, destObject, srcStart, destStart, elementCount);
VMStructHasBeenUpdated(REGISTER_ARGS);
Expand Down
11 changes: 4 additions & 7 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3451,16 +3451,13 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas
* elements may be flattened arrays.
*/
U_32 arrayFlags = J9ClassLargestAlignmentConstraintReference | J9ClassLargestAlignmentConstraintDouble;
if (J9_ARE_ALL_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_VT_ARRAY_FLATTENING)) {
/* TODO restrict this flag to be set only for null-restricted
* arrays once value type command line tests are updated.
*/
arrayFlags |= J9ClassIsFlattened;
}
ramArrayClass->classFlags |= (elementClass->classFlags & arrayFlags);
if (J9_ARE_ALL_BITS_SET(options, J9_FINDCLASS_FLAG_CLASS_OPTION_NULL_RESTRICTED_ARRAY)) {
if (J9_ARE_ALL_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_VT_ARRAY_FLATTENING)) {
arrayFlags |= J9ClassIsFlattened;
}
ramArrayClass->classFlags |= J9ClassArrayIsNullRestricted;
}
ramArrayClass->classFlags |= (elementClass->classFlags & arrayFlags);
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
arity = 1;
leafComponentType = elementClass;
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 be used instead of 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 @@ -197,6 +201,13 @@ static private void initArraysForArrayStoreChkExceptionTest() {
}
}

static private void initArraysToCopyNullToNullRestrictedArray() {
for (int i=0; i < ARRAY_SIZE; i++) {
vtArraySrc[i] = null;
nullRestrictedVtArrayDst[i] = new SomeValueClass(i);
}
}

static private void checkResults(Object[] arr1, Object[] arr2) {
for (int i=0; i < arr1.length; ++i) {
assertEquals(arr1[i], arr2[i]);
Expand Down Expand Up @@ -821,4 +832,22 @@ 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);
}

@Test(priority=1, expectedExceptions=ArrayStoreException.class)
static public void testSystemArrayCopy29() throws Throwable {
initArraysToCopyNullToNullRestrictedArray();
testVTVT(vtArraySrc, nullRestrictedVtArrayDst);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


import jdk.internal.misc.Unsafe;
import jdk.internal.value.ValueClass;
import jdk.internal.vm.annotation.ImplicitlyConstructible;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -93,10 +94,11 @@ static private <T> long arrayElementSize(T[] array) {
@BeforeMethod
static public void setUp() {
vtPoint = new ValueTypePoint2D(new ValueTypeInt(7), new ValueTypeInt(8));
vtPointAry = new ValueTypePoint2D[] {
new ValueTypePoint2D(new ValueTypeInt(5), new ValueTypeInt(10)),
new ValueTypePoint2D(new ValueTypeInt(10), new ValueTypeInt(20))
};

vtPointAry = (ValueTypePoint2D[])ValueClass.newNullRestrictedArray(ValueTypePoint2D.class, 2);
vtPointAry[0] = new ValueTypePoint2D(new ValueTypeInt(5), new ValueTypeInt(10));
vtPointAry[1] = new ValueTypePoint2D(new ValueTypeInt(10), new ValueTypeInt(20));

vtPointAryOffset1 = vtPointAryOffset0 + arrayElementSize(vtPointAry);
vtIntAry = new ValueTypeInt[] { new ValueTypeInt(1), new ValueTypeInt(2) };
vtIntAryOffset1 = vtIntAryOffset0 + arrayElementSize(vtIntAry);
Expand Down

0 comments on commit 958f427

Please sign in to comment.