Skip to content

Commit

Permalink
Add NULL restricted check
Browse files Browse the repository at this point in the history
Q type is going to be removed. Instead we should do null restricted
modifier check. 
In order for existing test to work, this change does not remove q type
checks from the existing code. NULL restricted check is appended to
places where Q type check is done.

issue eclipse-openj9#18157

Signed-off-by: Hang Shao <hangshao@ca.ibm.com>
  • Loading branch information
hangshao0 committed Oct 25, 2023
1 parent 3cad358 commit 25058c6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
6 changes: 4 additions & 2 deletions runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ initImpl(J9VMThread *currentThread, j9object_t membernameObject, j9object_t refO
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (vmFuncs->isNameOrSignatureQtype(J9ROMFIELDSHAPE_SIGNATURE(romField))
&& vmFuncs->isFlattenableFieldFlattened(fieldID->declaringClass, fieldID->field)
|| J9ROMFIELD_IS_NULL_RESTRICTED(romField)
) {
flags |= MN_FLATTENED;
if (vmFuncs->isFlattenableFieldFlattened(fieldID->declaringClass, fieldID->field)) {
flags |= MN_FLATTENED;
}
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */

Expand Down
5 changes: 4 additions & 1 deletion runtime/oti/j9.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ static const struct { \
#define J9CLASS_UNPADDED_INSTANCE_SIZE(clazz) J9_VALUETYPE_FLATTENED_SIZE(clazz)
#define J9_IS_J9CLASS_PRIMITIVE_VALUETYPE(clazz) J9_ARE_ALL_BITS_SET((clazz)->classFlags, J9ClassIsPrimitiveValueType)
#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)
/**
* Disable flattening of volatile field that is > 8 bytes for now, as the current implementation of copyObjectFields() will tear this field.
*/
Expand All @@ -341,7 +343,7 @@ static const struct { \
(J9_ARE_NO_BITS_SET((romFieldShape)->modifiers, J9AccVolatile) || (J9CLASS_UNPADDED_INSTANCE_SIZE(fieldClazz) <= sizeof(U_64))))
/* This will replace J9_IS_FIELD_FLATTENED when QTypes are removed. J9_IS_J9CLASS_FLATTENED will return false since the current check requires a primitive value type. */
#define J9_IS_NULL_RESTRICTED_FIELD_FLATTENED(fieldClazz, romFieldShape) \
(J9_ARE_ALL_BITS_SET((romFieldShape)->modifiers, J9FieldFlagIsNullRestricted) && \
(J9ROMFIELD_IS_NULL_RESTRICTED(romFieldShape) && \
J9_IS_J9CLASS_FLATTENED(fieldClazz) && \
(J9_ARE_NO_BITS_SET((romFieldShape)->modifiers, J9AccVolatile) || (J9CLASS_UNPADDED_INSTANCE_SIZE(fieldClazz) <= sizeof(U_64))))
#define J9_VALUETYPE_FLATTENED_SIZE(clazz) (J9CLASS_HAS_4BYTE_PREPADDING((clazz)) ? ((clazz)->totalInstanceSize - sizeof(U_32)) : (clazz)->totalInstanceSize)
Expand All @@ -351,6 +353,7 @@ static const struct { \
#define J9CLASS_UNPADDED_INSTANCE_SIZE(clazz) ((clazz)->totalInstanceSize)
#define J9_IS_J9CLASS_PRIMITIVE_VALUETYPE(clazz) FALSE
#define J9_IS_J9CLASS_FLATTENED(clazz) FALSE
#define J9ROMFIELD_IS_NULL_RESTRICTED(romField) FALSE
#define J9_IS_FIELD_FLATTENED(fieldClazz, romFieldShape) FALSE
#define J9_IS_NULL_RESTRICTED_FIELD_FLATTENED(fieldClazz, romFieldShape) FALSE
#define J9_VALUETYPE_FLATTENED_SIZE(clazz)((UDATA) 0) /* It is not possible for this macro to be used since we always check J9_IS_J9CLASS_FLATTENED before ever using it. */
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4353,7 +4353,7 @@ class INTERPRETER_CLASS
rc = GOTO_THROW_CURRENT_EXCEPTION;
} else {
I_32 result = false;
if (VM_ValueTypeHelpers::isNameOrSignatureQtype(J9ROMFIELDSHAPE_SIGNATURE(fieldID->field))) {
if (VM_ValueTypeHelpers::isNameOrSignatureQtype(J9ROMFIELDSHAPE_SIGNATURE(fieldID->field)) || J9ROMFIELD_IS_NULL_RESTRICTED(fieldID->field)) {
result = (I_32)isFlattenableFieldFlattened(fieldID->declaringClass, fieldID->field);
}
restoreInternalNativeStackFrame(REGISTER_ARGS);
Expand Down
4 changes: 3 additions & 1 deletion runtime/vm/ObjectFieldInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ ObjectFieldInfo::countInstanceFields(void)
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
J9UTF8 *fieldSig = J9ROMFIELDSHAPE_SIGNATURE(field);
U_8 *fieldSigBytes = J9UTF8_DATA(J9ROMFIELDSHAPE_SIGNATURE(field));
if ('Q' == *fieldSigBytes) {
if (('Q' == *fieldSigBytes)
|| J9_ARE_ALL_BITS_SET(modifiers, J9FieldFlagIsNullRestricted)
) {
J9Class *fieldClass = findJ9ClassInFlattenedClassCache(_flattenedClassCache, fieldSigBytes + 1, J9UTF8_LENGTH(fieldSig) - 2);
U_32 size = (U_32)fieldClass->totalInstanceSize;
if (!J9_IS_FIELD_FLATTENED(fieldClass, field)) {
Expand Down
22 changes: 17 additions & 5 deletions runtime/vm/ValueTypeHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,24 @@ class VM_ValueTypeHelpers {
}
break;
}
case 'L': { /* Nullable class type or interface type */
j9object_t lhsObject = objectAccessBarrier.inlineMixedObjectReadObject(currentThread, lhs, startOffset + result->offset);
j9object_t rhsObject = objectAccessBarrier.inlineMixedObjectReadObject(currentThread, rhs, startOffset + result->offset);
case 'L': {
bool flattened = false;
J9Class *fieldClass = NULL;
rc = false;
if (J9ROMFIELD_IS_NULL_RESTRICTED(result->field)) {
fieldClass = findJ9ClassInFlattenedClassCache(clazz->flattenedClassCache, sigChar + 1, J9UTF8_LENGTH(signature) - 2);
flattened = J9_IS_FIELD_FLATTENED(fieldClass, result->field);
}
if (flattened) {
rc = isSubstitutable(currentThread, objectAccessBarrier, lhs, rhs, startOffset + result->offset, fieldClass);
} else {
j9object_t lhsFieldObject = objectAccessBarrier.inlineMixedObjectReadObject(currentThread, lhs, startOffset + result->offset);
j9object_t rhsFieldObject = objectAccessBarrier.inlineMixedObjectReadObject(currentThread, rhs, startOffset + result->offset);

if (!VM_ValueTypeHelpers::acmp(currentThread, objectAccessBarrier, lhsObject, rhsObject)) {
rc = false;
/* When unflattened, we get our object from the specified offset, then increment past the header to the first field. */
rc = VM_ValueTypeHelpers::acmp(currentThread, objectAccessBarrier, lhsFieldObject, rhsFieldObject);
}
if (false == rc) {
goto done;
}
break;
Expand Down
4 changes: 3 additions & 1 deletion runtime/vm/description.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ calculateInstanceDescription( J9VMThread *vmThread, J9Class *ramClass, J9Class *
}

#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if ('Q' == *fieldSigBytes) {
if (('Q' == *fieldSigBytes)
|| J9ROMFIELD_IS_NULL_RESTRICTED(walkResult->field)
) {
J9Class *fieldClass = walkResult->flattenedClass;
if ((NULL != fieldClass)
&& J9_IS_FIELD_FLATTENED(fieldClass, walkResult->field)
Expand Down
4 changes: 3 additions & 1 deletion runtime/vm/resolvefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,9 @@ fieldOffsetsFindNext(J9ROMFieldOffsetWalkState *state, J9ROMFieldShape *field)
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
J9UTF8 *fieldSig = J9ROMFIELDSHAPE_SIGNATURE(field);
U_8 *fieldSigBytes = J9UTF8_DATA(fieldSig);
if ('Q' == *fieldSigBytes) {
if (('Q' == *fieldSigBytes)
|| J9_ARE_ALL_BITS_SET(modifiers, J9FieldFlagIsNullRestricted)
) {
J9Class *fieldClass = NULL;
fieldClass = findJ9ClassInFlattenedClassCache(state->flattenedClassCache, fieldSigBytes + 1, J9UTF8_LENGTH(fieldSig) - 2);
if (!J9_IS_FIELD_FLATTENED(fieldClass, field)) {
Expand Down
11 changes: 6 additions & 5 deletions runtime/vm/resolvesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,9 @@ resolveInstanceFieldRefInto(J9VMThread *vmStruct, J9Method *method, J9ConstantPo
*/
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (J9_IS_J9CLASS_VALUETYPE(resolvedClass)) {
if ('Q' == J9UTF8_DATA(signature)[0]) {
flattenedClassCache = resolvedClass->flattenedClassCache;
fieldIndex = findIndexInFlattenedClassCache(flattenedClassCache, nameAndSig);
Assert_VM_false(UDATA_MAX == fieldIndex);
flattenedClassCache = resolvedClass->flattenedClassCache;
fieldIndex = findIndexInFlattenedClassCache(flattenedClassCache, nameAndSig);
if (UDATA_MAX != fieldIndex) {
J9FlattenedClassCacheEntry * flattenedClassCacheEntry = J9_VM_FCC_ENTRY_FROM_FCC(flattenedClassCache, fieldIndex);
fieldOffset = flattenedClassCacheEntry->offset;
if (-1 != fieldOffset) {
Expand Down Expand Up @@ -1077,7 +1076,9 @@ resolveInstanceFieldRefInto(J9VMThread *vmStruct, J9Method *method, J9ConstantPo
if ((NULL != ramCPEntry) && J9_ARE_NO_BITS_SET(resolveFlags, J9_RESOLVE_FLAG_NO_CP_UPDATE)) {
UDATA valueOffset = fieldOffset;
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if ('Q' == J9UTF8_DATA(signature)[0]) {
if (('Q' == J9UTF8_DATA(signature)[0])
|| J9ROMFIELD_IS_NULL_RESTRICTED(field)
) {
if (fccEntryFieldNotSet) {
flattenedClassCache = definingClass->flattenedClassCache;
fieldIndex = findIndexInFlattenedClassCache(flattenedClassCache, nameAndSig);
Expand Down

0 comments on commit 25058c6

Please sign in to comment.