Skip to content

Commit

Permalink
Add utility methods for null restricted arrays
Browse files Browse the repository at this point in the history
(1)
Add `getNullRestrictedArrayClassFromComponentClass`
to retrieve `nullRestrictedArrayClass` from J9Class

(2)
Add `isArrayNullRestricted` to check if an array class
is null restricted by checking `J9ClassArrayIsNullRestricted`

Signed-off-by: Annabelle Huo <[email protected]>
  • Loading branch information
a7ehuo committed Sep 4, 2024
1 parent 028a24e commit 1deceda
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 4 deletions.
6 changes: 6 additions & 0 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, fe->getArrayClassFromComponentClass(clazz));
}
break;
case MessageType::VM_getNullRestrictedArrayClassFromComponentClass:
{
auto clazz = std::get<0>(client->getRecvData<TR_OpaqueClassBlock *>());
client->write(response, fe->getNullRestrictedArrayClassFromComponentClass(clazz));
}
break;
case MessageType::VM_matchRAMclassFromROMclass:
{
J9ROMClass *clazz = std::get<0>(client->getRecvData<J9ROMClass *>());
Expand Down
7 changes: 6 additions & 1 deletion runtime/compiler/control/JITServerHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ JITServerHelpers::cacheRemoteROMClass(ClientSessionData *clientSessionData, J9Cl
classInfoStruct._classNameIdentifyingLoader = std::get<22>(classInfoTuple);
classInfoStruct._arrayElementSize = std::get<23>(classInfoTuple);
classInfoStruct._defaultValueSlotAddress = std::get<24>(classInfoTuple);
classInfoStruct._nullRestrictedArrayClass = std::get<26>(classInfoTuple);

auto result = clientSessionData->getROMClassMap().insert({ clazz, classInfoStruct });

Expand Down Expand Up @@ -1031,6 +1032,7 @@ JITServerHelpers::packRemoteROMClassInfo(J9Class *clazz, J9VMThread *vmThread, T
TR_OpaqueClassBlock *hostClass = fe->convertClassPtrToClassOffset(clazz->hostClass);
TR_OpaqueClassBlock *componentClass = fe->getComponentClassFromArrayClass((TR_OpaqueClassBlock *)clazz);
TR_OpaqueClassBlock *arrayClass = fe->getArrayClassFromComponentClass((TR_OpaqueClassBlock *)clazz);
TR_OpaqueClassBlock *nullRestrictedArrayClass = fe->getNullRestrictedArrayClassFromComponentClass((TR_OpaqueClassBlock *)clazz);
uintptr_t totalInstanceSize = clazz->totalInstanceSize;
uintptr_t cp = fe->getConstantPoolFromClass((TR_OpaqueClassBlock *)clazz);
uintptr_t classFlags = fe->getClassFlagsValue((TR_OpaqueClassBlock *)clazz);
Expand Down Expand Up @@ -1082,7 +1084,7 @@ JITServerHelpers::packRemoteROMClassInfo(J9Class *clazz, J9VMThread *vmThread, T
classHasFinalFields, classDepthAndFlags, classInitialized, byteOffsetToLockword, leafComponentClass,
classLoader, hostClass, componentClass, arrayClass, totalInstanceSize, clazz->romClass,
cp, classFlags, classChainOffsetIdentifyingLoader, origROMMethods, classNameIdentifyingLoader, arrayElementSize,
defaultValueSlotAddress, romClassHash
defaultValueSlotAddress, romClassHash, nullRestrictedArrayClass
);
}

Expand Down Expand Up @@ -1261,6 +1263,9 @@ JITServerHelpers::getROMClassData(const ClientSessionData::ClassInfo &classInfo,
case CLASSINFO_DEFAULT_VALUE_SLOT_ADDRESS:
*(j9object_t **)data = classInfo._defaultValueSlotAddress;
break;
case CLASSINFO_NULLRESTRICTED_ARRAY_CLASS :
*(TR_OpaqueClassBlock **)data = classInfo._nullRestrictedArrayClass;
break;
default:
TR_ASSERT(false, "Class Info not supported %u\n", dataType);
break;
Expand Down
4 changes: 3 additions & 1 deletion runtime/compiler/control/JITServerHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class JITServerHelpers
CLASSINFO_CLASS_CHAIN_OFFSET_IDENTIFYING_LOADER,
CLASSINFO_ARRAY_ELEMENT_SIZE,
CLASSINFO_DEFAULT_VALUE_SLOT_ADDRESS,
CLASSINFO_NULLRESTRICTED_ARRAY_CLASS,
};

// NOTE: when adding new elements to this tuple, add them to the end,
Expand Down Expand Up @@ -88,7 +89,8 @@ class JITServerHelpers
std::string, // 22: _classNameIdentifyingLoader
int32_t, // 23: _arrayElementSize
j9object_t *, // 24: _defaultValueSlotAddress
std::string // 25: optional hash of packedROMClass
std::string, // 25: optional hash of packedROMClass
TR_OpaqueClassBlock * // 26: _nullRestrictedArrayClass
>;

// Packs a ROMClass to be transferred to the server.
Expand Down
23 changes: 23 additions & 0 deletions runtime/compiler/env/J9ClassEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,29 @@ J9::ClassEnv::isValueBasedOrValueTypeClass(TR_OpaqueClassBlock *clazz)
return J9_ARE_ANY_BITS_SET(j9class->classFlags, J9_CLASS_DISALLOWS_LOCKING_FLAGS);
}

bool
J9::ClassEnv::isArrayNullRestricted(TR::Compilation *comp,TR_OpaqueClassBlock *arrayClass)
{
#if defined(J9VM_OPT_JITSERVER)
if (auto stream = comp->getStream())
{
uintptr_t classFlags = 0;
JITServerHelpers::getAndCacheRAMClassInfo((J9Class *)arrayClass, TR::compInfoPT->getClientData(), stream, JITServerHelpers::CLASSINFO_CLASS_FLAGS, (void *)&classFlags);
#ifdef DEBUG
stream->write(JITServer::MessageType::ClassEnv_classFlagsValue, clazz);
uintptr_t classFlagsRemote = std::get<0>(stream->read<uintptr_t>());
// Check that class flags from remote call is equal to the cached ones
classFlags = classFlags & J9ClassArrayIsNullRestricted;
classFlagsRemote = classFlagsRemote & J9ClassArrayIsNullRestricted;
TR_ASSERT_FATAL(classFlags == classFlagsRemote, "remote call class flags is not equal to cached class flags");
#endif
return J9_ARE_ALL_BITS_SET(classFlags, J9ClassArrayIsNullRestricted);
}
#endif /* defined(J9VM_OPT_JITSERVER) */
J9ArrayClass *j9class = reinterpret_cast<J9ArrayClass*>(arrayClass);
return J9_IS_J9ARRAYCLASS_NULL_RESTRICTED(j9class);
}

bool
J9::ClassEnv::classHasIdentity(TR_OpaqueClassBlock *clazz)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/J9ClassEnv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class OMR_EXTENSIBLE ClassEnv : public OMR::ClassEnvConnector
bool isPrimitiveValueTypeClass(TR_OpaqueClassBlock *);
bool isValueTypeClassFlattened(TR_OpaqueClassBlock *clazz);
bool isValueBasedOrValueTypeClass(TR_OpaqueClassBlock *);
bool isArrayNullRestricted(TR::Compilation *comp, TR_OpaqueClassBlock *arrayClass);

/** \brief
* Returns the size of the flattened array element
Expand Down
32 changes: 32 additions & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7050,6 +7050,13 @@ TR_J9VM::getArrayClassFromComponentClass(TR_OpaqueClassBlock * componentClass)
return convertClassPtrToClassOffset(TR::Compiler->cls.convertClassOffsetToClassPtr(componentClass)->arrayClass);
}

TR_OpaqueClassBlock *
TR_J9VM::getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock * componentClass)
{
J9Class *clazz = TR::Compiler->cls.convertClassOffsetToClassPtr(componentClass);
return convertClassPtrToClassOffset(J9CLASS_GET_NULLRESTRICTED_ARRAY(clazz));
}

TR_OpaqueClassBlock *
TR_J9VM::getLeafComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass)
{
Expand Down Expand Up @@ -9228,6 +9235,31 @@ TR_J9SharedCacheVM::getArrayClassFromComponentClass(TR_OpaqueClassBlock * compon
return NULL;
}

TR_OpaqueClassBlock *
TR_J9SharedCacheVM::getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock * componentClass)
{
TR::Compilation* comp = _compInfoPT->getCompilation();
TR_ASSERT(comp, "Should be called only within a compilation");

bool validated = false;
TR_OpaqueClassBlock *arrayClass = TR_J9VM::getNullRestrictedArrayClassFromComponentClass(componentClass);

if (comp->getOption(TR_UseSymbolValidationManager))
{
validated = comp->getSymbolValidationManager()->addArrayClassFromComponentClassRecord(arrayClass, componentClass);
}
else
{
if (((TR_ResolvedRelocatableJ9Method *) comp->getCurrentMethod())->validateArbitraryClass(comp, (J9Class *) componentClass))
validated = true;
}

if (validated)
return arrayClass;
else
return NULL;
}

TR_OpaqueClassBlock *
TR_J9SharedCacheVM::getLeafComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass)
{
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,7 @@ class TR_J9VM : public TR_J9VMBase

virtual TR_OpaqueClassBlock * getComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass);
virtual TR_OpaqueClassBlock * getArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass);
virtual TR_OpaqueClassBlock * getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass);
virtual TR_OpaqueClassBlock * getLeafComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass);
virtual int32_t getNewArrayTypeFromClass(TR_OpaqueClassBlock *clazz);
virtual TR_OpaqueClassBlock * getClassFromSignature(const char * sig, int32_t length, TR_ResolvedMethod *method, bool isVettedForAOT=false);
Expand Down Expand Up @@ -1670,6 +1671,7 @@ class TR_J9SharedCacheVM : public TR_J9VM
virtual bool isPrimitiveClass(TR_OpaqueClassBlock *clazz);
virtual TR_OpaqueClassBlock * getComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass);
virtual TR_OpaqueClassBlock * getArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass);
virtual TR_OpaqueClassBlock * getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass);
virtual TR_OpaqueClassBlock * getLeafComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass);
virtual TR_OpaqueClassBlock * getBaseComponentClass(TR_OpaqueClassBlock * clazz, int32_t & numDims);
virtual TR_OpaqueClassBlock * getClassFromNewArrayType(int32_t arrayType);
Expand Down
45 changes: 45 additions & 0 deletions runtime/compiler/env/VMJ9Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,30 @@ TR_J9ServerVM::getArrayClassFromComponentClass(TR_OpaqueClassBlock *componentCla
return arrayClass;
}

TR_OpaqueClassBlock *
TR_J9ServerVM::getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass)
{
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
TR_OpaqueClassBlock *arrayClass = NULL;
JITServerHelpers::getAndCacheRAMClassInfo((J9Class *)componentClass, _compInfoPT->getClientData(), stream, JITServerHelpers::CLASSINFO_NULLRESTRICTED_ARRAY_CLASS, (void *)&arrayClass);
if (!arrayClass)
{
stream->write(JITServer::MessageType::VM_getNullRestrictedArrayClassFromComponentClass, componentClass);
arrayClass = std::get<0>(stream->read<TR_OpaqueClassBlock *>());
if (arrayClass)
{
// if client initialized arrayClass, cache the new value
OMR::CriticalSection getRemoteROMClass(_compInfoPT->getClientData()->getROMMapMonitor());
auto it = _compInfoPT->getClientData()->getROMClassMap().find((J9Class*) componentClass);
if (it != _compInfoPT->getClientData()->getROMClassMap().end())
{
it->second._nullRestrictedArrayClass = arrayClass;
}
}
}
return arrayClass;
}

J9Class *
TR_J9ServerVM::matchRAMclassFromROMclass(J9ROMClass *clazz, TR::Compilation *comp)
{
Expand Down Expand Up @@ -3251,6 +3275,27 @@ TR_J9SharedCacheServerVM::getArrayClassFromComponentClass(TR_OpaqueClassBlock *
return validated ? arrayClass : NULL;
}

TR_OpaqueClassBlock *
TR_J9SharedCacheServerVM::getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock * componentClass)
{
TR::Compilation* comp = _compInfoPT->getCompilation();
TR_ASSERT(comp, "Should be called only within a compilation");

bool validated = false;
TR_OpaqueClassBlock *arrayClass = TR_J9ServerVM::getNullRestrictedArrayClassFromComponentClass(componentClass);

if (comp->getOption(TR_UseSymbolValidationManager))
{
validated = comp->getSymbolValidationManager()->addArrayClassFromComponentClassRecord(arrayClass, componentClass);
}
else
{
if (((TR_ResolvedRelocatableJ9JITServerMethod *) comp->getCurrentMethod())->validateArbitraryClass(comp, (J9Class *) componentClass))
validated = true;
}
return validated ? arrayClass : NULL;
}

TR_OpaqueClassBlock *
TR_J9SharedCacheServerVM::getLeafComponentClassFromArrayClass(TR_OpaqueClassBlock * arrayClass)
{
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/env/VMJ9Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class TR_J9ServerVM: public TR_J9VM
virtual bool isCloneable(TR_OpaqueClassBlock *clazzPointer) override;
virtual bool canAllocateInlineClass(TR_OpaqueClassBlock *clazz) override;
virtual TR_OpaqueClassBlock * getArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass) override;
virtual TR_OpaqueClassBlock * getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass) override;
virtual J9Class * matchRAMclassFromROMclass(J9ROMClass *clazz, TR::Compilation *comp) override;
virtual int32_t * getCurrentLocalsMapForDLT(TR::Compilation *comp) override;
virtual uintptr_t getReferenceFieldAt(uintptr_t objectPointer, uintptr_t offsetFromHeader) override;
Expand Down Expand Up @@ -342,6 +343,7 @@ class TR_J9SharedCacheServerVM: public TR_J9ServerVM
virtual bool isPrimitiveClass(TR_OpaqueClassBlock *clazzPointer) override;
virtual TR_OpaqueClassBlock *getComponentClassFromArrayClass(TR_OpaqueClassBlock *arrayClass) override;
virtual TR_OpaqueClassBlock *getArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass) override;
virtual TR_OpaqueClassBlock * getNullRestrictedArrayClassFromComponentClass(TR_OpaqueClassBlock *componentClass) override;
virtual TR_OpaqueClassBlock *getLeafComponentClassFromArrayClass(TR_OpaqueClassBlock *arrayClass) override;
virtual TR_OpaqueClassBlock *getBaseComponentClass(TR_OpaqueClassBlock *clazz, int32_t & numDims) override;
virtual TR_OpaqueClassBlock *getClassFromNewArrayType(int32_t arrayType) override;
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/net/CommunicationStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class CommunicationStream
// likely to lose an increment when merging/rebasing/etc.
//
static const uint8_t MAJOR_NUMBER = 1;
static const uint16_t MINOR_NUMBER = 65; // ID: YxVkiLqD7B1LhYMv58y8
static const uint16_t MINOR_NUMBER = 66; // ID: ouauIxMZuIHK9i6dz847
static const uint8_t PATCH_NUMBER = 0;
static uint32_t CONFIGURATION_FLAGS;

Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/net/MessageTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const char *messageNames[] =
"VM_classInitIsFinished",
"VM_getClassFromNewArrayType",
"VM_getArrayClassFromComponentClass",
"VM_getNullRestrictedArrayClassFromComponentClass",
"VM_matchRAMclassFromROMclass",
"VM_getInt32FieldAt",
"VM_getInt64FieldAt",
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/net/MessageTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ enum MessageType : uint16_t
VM_classInitIsFinished,
VM_getClassFromNewArrayType,
VM_getArrayClassFromComponentClass,
VM_getNullRestrictedArrayClassFromComponentClass,
VM_matchRAMclassFromROMclass,
VM_getInt32FieldAt,
VM_getInt64FieldAt,
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/runtime/JITClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ ClientSessionData::ClassInfo::ClassInfo(TR_PersistentMemory *persistentMemory) :
_aotCacheClassRecord(NULL),
_arrayElementSize(0),
_defaultValueSlotAddress(NULL),
_nullRestrictedArrayClass(NULL),
_classOfStaticCache(decltype(_classOfStaticCache)::allocator_type(persistentMemory->_persistentAllocator.get())),
_constantClassPoolCache(decltype(_constantClassPoolCache)::allocator_type(persistentMemory->_persistentAllocator.get())),
_fieldAttributesCache(decltype(_fieldAttributesCache)::allocator_type(persistentMemory->_persistentAllocator.get())),
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/runtime/JITClientSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class ClientSessionData
TR_OpaqueClassBlock *_hostClass;
TR_OpaqueClassBlock *_componentClass; // caching the componentType of the J9ArrayClass
TR_OpaqueClassBlock *_arrayClass;
TR_OpaqueClassBlock *_nullRestrictedArrayClass;
uintptr_t _totalInstanceSize;
J9ConstantPool *_constantPool;
uintptr_t _classFlags;
Expand Down
6 changes: 5 additions & 1 deletion runtime/compiler/runtime/SymbolValidationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,11 @@ TR::SymbolValidationManager::validateArrayClassFromComponentClassRecord(uint16_t
if (isDefinedID(componentClassID))
{
TR_OpaqueClassBlock *componentClass = getClassFromID(componentClassID);
return validateSymbol(arrayClassID, _fej9->getArrayClassFromComponentClass(componentClass));
if (validateSymbol(arrayClassID, _fej9->getArrayClassFromComponentClass(componentClass)))
return true;

TR_OpaqueClassBlock *nullRestrictedArray = _fej9->getNullRestrictedArrayClassFromComponentClass(componentClass);
return nullRestrictedArray ? validateSymbol(arrayClassID, nullRestrictedArray) : false;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/j9.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ static const struct { \
#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. */
#define J9CLASS_GET_NULLRESTRICTED_ARRAY(clazz) NULL
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
#define IS_REF_OR_VAL_SIGNATURE(firstChar) ('L' == (firstChar))

Expand Down

0 comments on commit 1deceda

Please sign in to comment.