Skip to content

Commit

Permalink
Value class is indicated by missing ACC_IDENTITY
Browse files Browse the repository at this point in the history
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340 eclipse-openj9#19460
  • Loading branch information
theresa-m committed May 30, 2024
1 parent ef12769 commit 2bff083
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ J9FieldFlags.J9FieldFlagIsNullRestricted = 0
J9JavaAccessFlags.J9AccClassIsUnmodifiable = 0
J9JavaAccessFlags.J9AccRecord = 0
J9JavaAccessFlags.J9AccSealed = 0
J9JavaAccessFlags.J9AccValueType = 0
J9JavaAccessFlags.J9AccClassHasIdentity = 0
J9JavaAccessFlags.J9StaticFieldIsNullRestricted = 0
J9JavaAccessFlags.J9PutfieldNarrowing = 0
J9JavaAccessFlags.J9StaticFieldRefBaseType = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public J9ClassPointer findJ9ClassInFlattenedClassCacheWithSigName(J9ClassPointer

@Override
public boolean isRomClassAValueType(J9ROMClassPointer romClass) throws CorruptDataException {
return romClass.modifiers().allBitsIn(J9JavaAccessFlags.J9AccValueType);
return !romClass.modifiers().allBitsIn(J9JavaAccessFlags.J9AccClassHasIdentity);
}

@Override
Expand Down
11 changes: 3 additions & 8 deletions runtime/bcutil/ClassFileOracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,10 @@ ClassFileOracle::ClassFileOracle(BufferManager *bufferManager, J9CfrClassFile *c
_hasNonEmptyConstructor = true;
}

if (J9_ARE_ALL_BITS_SET(_classFile->accessFlags, CFR_ACC_VALUE_TYPE | CFR_ACC_IDENTITY)) {
_buildResult = InvalidValueType;
if (J9_ARE_ALL_BITS_SET(_classFile->accessFlags, CFR_ACC_IDENTITY)) {
_hasIdentityFlagSet = true;
} else {
if (J9_ARE_ALL_BITS_SET(_classFile->accessFlags, CFR_ACC_VALUE_TYPE)) {
_isValueType = true;
}
if (J9_ARE_ALL_BITS_SET(_classFile->accessFlags, CFR_ACC_IDENTITY)) {
_hasIdentityFlagSet = true;
}
_isValueType = true;
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */

Expand Down
2 changes: 1 addition & 1 deletion runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ JVM_IsImplicitlyConstructibleClass(JNIEnv *env, jclass cls)
JNIEXPORT jboolean JNICALL
JVM_IsNullRestrictedArray(JNIEnv *env, jobject obj)
{
assert(!"JVM_IsNullRestrictedArray unimplemented");
// TODO implement this with https://github.com/eclipse-openj9/openj9/issues/19460
return JNI_FALSE;
}

Expand Down
1 change: 0 additions & 1 deletion runtime/oti/j9javaaccessflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#define J9AccSuper 0x00000020 /* class */
#define J9AccClassHasIdentity 0x00000020 /* class */
#define J9AccSynchronized 0x00000020 /* method */
#define J9AccValueType 0x00000040 /* class(Valhalla) */
#define J9AccBridge 0x00000040 /* method */
#define J9AccVolatile 0x00000040 /* field */
#define J9AccVarArgs 0x00000080 /* method */
Expand Down
4 changes: 2 additions & 2 deletions runtime/oti/j9modifiers_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* TODO: Will need to modify this if ValObject/RefObject proposal goes through.
* Some exiting places using J9ROMCLASS_IS_VALUE() may need to check J9ROMCLASS_IS_PRIMITIVE_VALUE_TYPE().
*/
#define J9ROMCLASS_IS_VALUE(romClass) _J9ROMCLASS_SUNMODIFIER_IS_SET((romClass), J9AccValueType)
#define J9ROMCLASS_IS_VALUE(romClass) !_J9ROMCLASS_SUNMODIFIER_IS_SET((romClass), J9AccClassHasIdentity)
#else /* J9VM_OPT_VALHALLA_VALUE_TYPES */
#define J9ROMCLASS_IS_VALUE(romClass) FALSE
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
Expand Down Expand Up @@ -140,7 +140,7 @@

/* Class instances are allocated via the new bytecode */
#define J9ROMCLASS_ALLOCATES_VIA_NEW(romClass) \
J9_ARE_NO_BITS_SET((romClass)->modifiers, J9AccAbstract | J9AccInterface | J9AccClassArray | J9AccValueType)
J9_ARE_NO_BITS_SET((romClass)->modifiers, J9AccAbstract | J9AccInterface | J9AccClassArray)

/* Class instances are allocated via J9RAMClass->totalInstanceSize */
#define J9ROMCLASS_ALLOCATE_USES_TOTALINSTANCESIZE(romClass) \
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/ClassInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ classInitStateMachine(J9VMThread *currentThread, J9Class *clazz, J9ClassInitStat
/* A NullRestricted field must be in a value class with an
* ImplicitCreation attribute. The attribute must have the ACC_DEFAULT flag set.
*/
if (J9_ARE_NO_BITS_SET(entryRomClass->modifiers, J9AccValueType)
if (!J9ROMCLASS_IS_VALUE(entryRomClass)
|| J9_ARE_NO_BITS_SET(entryRomClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE)
|| J9_ARE_NO_BITS_SET(getImplicitCreationFlags(entryRomClass), J9AccImplicitCreateHasDefaultValue)
) {
Expand Down
32 changes: 11 additions & 21 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ loadFlattenableFieldValueClasses(J9VMThread *currentThread, J9ClassLoader *class
* ImplicitCreation attribute. The attribute must have the ACC_DEFAULT flag set.
* Static fields will be checked during class preparation.
*/
if (J9_ARE_NO_BITS_SET(valueROMClass->modifiers, J9AccValueType)
if (!J9ROMCLASS_IS_VALUE(valueROMClass)
|| J9_ARE_NO_BITS_SET(valueROMClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE)
|| J9_ARE_NO_BITS_SET(getImplicitCreationFlags(valueROMClass), J9AccImplicitCreateHasDefaultValue)
) {
Expand Down Expand Up @@ -2331,30 +2331,20 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C
}

#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
if (J9_ARE_ALL_BITS_SET(classFlags, J9ClassHasIdentity)) {
if (J9ROMCLASS_IS_VALUE(romClass)) {
J9UTF8* className = J9ROMCLASS_CLASSNAME(romClass);
J9UTF8 *superclassName = J9ROMCLASS_SUPERCLASSNAME(romClass);
setCurrentExceptionNLSWithArgs(vmThread, J9NLS_VM_VALUETYPE_HAS_WRONG_SUPERCLASS,
J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, J9UTF8_LENGTH(className),
J9UTF8_DATA(className), J9UTF8_LENGTH(superclassName), J9UTF8_DATA(superclassName));
}
} else {
if (J9ROMCLASS_HAS_IDENTITY(romClass)) {
classFlags |= J9ClassHasIdentity;
}
if (J9ROMCLASS_HAS_IDENTITY(romClass)) {
classFlags |= J9ClassHasIdentity;
}

#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (J9_ARE_ALL_BITS_SET(romClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE)) {
U_16 implicitCreationFlags = getImplicitCreationFlags(romClass);
if (J9_ARE_ALL_BITS_SET(implicitCreationFlags, J9AccImplicitCreateNonAtomic)) {
classFlags |= J9ClassAllowsNonAtomicCreation;
}
if (J9_ARE_ALL_BITS_SET(implicitCreationFlags, J9AccImplicitCreateHasDefaultValue)) {
classFlags |= J9ClassAllowsInitialDefaultValue;
if (J9_ARE_ALL_BITS_SET(romClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE)) {
U_16 implicitCreationFlags = getImplicitCreationFlags(romClass);
if (J9_ARE_ALL_BITS_SET(implicitCreationFlags, J9AccImplicitCreateNonAtomic)) {
classFlags |= J9ClassAllowsNonAtomicCreation;
}
if (J9_ARE_ALL_BITS_SET(implicitCreationFlags, J9AccImplicitCreateHasDefaultValue)) {
classFlags |= J9ClassAllowsInitialDefaultValue;
}
}
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

if (J9ROMCLASS_IS_VALUE(romClass)) {
Expand Down

0 comments on commit 2bff083

Please sign in to comment.