Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Up VM Accesses in Vector Expansion API for the JITServer #20807

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
{
vmInfo._arrayTypeClasses[i] = fe->getClassFromNewArrayTypeNonNull(i + 4);
}
vmInfo._byteArrayClass = fe->getByteArrayClass();
vmInfo._byteArrayOpaqueClass = fe->getByteArrayClass();
vmInfo._isIndexableDataAddrPresent = TR::Compiler->om.isIndexableDataAddrPresent();
vmInfo._contiguousIndexableHeaderSize = TR::Compiler->om.contiguousArrayHeaderSizeInBytes();
vmInfo._discontiguousIndexableHeaderSize = TR::Compiler->om.discontiguousArrayHeaderSizeInBytes();
Expand Down Expand Up @@ -562,6 +562,14 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
vmInfo._shortReflectClassPtr = javaVM->shortReflectClass;
vmInfo._intReflectClassPtr = javaVM->intReflectClass;
vmInfo._longReflectClassPtr = javaVM->longReflectClass;
vmInfo._booleanArrayClass = javaVM->booleanArrayClass;
vmInfo._charArrayClass = javaVM->charArrayClass;
vmInfo._floatArrayClass = javaVM->floatArrayClass;
vmInfo._doubleArrayClass = javaVM->doubleArrayClass;
vmInfo._byteArrayClass = javaVM->byteArrayClass;
vmInfo._shortArrayClass = javaVM->shortArrayClass;
vmInfo._intArrayClass = javaVM->intArrayClass;
vmInfo._longArrayClass = javaVM->longArrayClass;

client->write(response, vmInfo, listOfCacheDescriptors, comp->getPersistentInfo()->getJITServerAOTCacheName());
}
Expand Down
42 changes: 42 additions & 0 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,48 @@ TR_J9VMBase::getClassPrimitiveDataType(TR_OpaqueClassBlock* clazz)
return TR::NoType;
}

TR_OpaqueClassBlock *
TR_J9VMBase::getArrayClassFromDataType(TR::DataType type, bool booleanClass)
{
J9Class *j9class;
J9JavaVM *vm = getJ9JITConfig()->javaVM;


if (booleanClass)
mpirvu marked this conversation as resolved.
Show resolved Hide resolved
{
j9class = vm->booleanArrayClass;
}
else
{
switch (type)
{
case TR::Float:
j9class = vm->floatArrayClass;
break;
case TR::Double:
j9class = vm->doubleArrayClass;
break;
case TR::Int8:
j9class = vm->byteArrayClass;
break;
case TR::Int16:
j9class = vm->shortArrayClass;
break;
case TR::Int32:
j9class = vm->intArrayClass;
break;
case TR::Int64:
j9class = vm->longArrayClass;
break;
default:
TR_ASSERT_FATAL(false, "Incorrect array element type");
return NULL;
}
}

return convertClassPtrToClassOffset(j9class);
}

TR_OpaqueClassBlock *
TR_J9VMBase::getClassFromJavaLangClass(uintptr_t objectPointer)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ class TR_J9VMBase : public TR_FrontEnd
virtual TR_OpaqueClassBlock *getClassFromJavaLangClass(uintptr_t objectPointer);
virtual TR_arrayTypeCode getPrimitiveArrayTypeCode(TR_OpaqueClassBlock* clazz);
virtual TR::DataType getClassPrimitiveDataType(TR_OpaqueClassBlock* clazz);
virtual TR_OpaqueClassBlock *getArrayClassFromDataType(TR::DataType type, bool booleanClass);
virtual TR_OpaqueClassBlock * getSystemClassFromClassName(const char * name, int32_t length, bool callSiteVettedForAOT=false) { return 0; }
virtual TR_OpaqueClassBlock * getByteArrayClass();

Expand Down
43 changes: 42 additions & 1 deletion runtime/compiler/env/VMJ9Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ TR_J9ServerVM::getByteArrayClass()
{
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
auto *vmInfo = _compInfoPT->getClientData()->getOrCacheVMInfo(stream);
return vmInfo->_byteArrayClass;
return vmInfo->_byteArrayOpaqueClass;
}

bool
Expand Down Expand Up @@ -2689,6 +2689,47 @@ TR_J9ServerVM::getClassPrimitiveDataType(TR_OpaqueClassBlock* clazz)
return TR::NoType;
}

TR_OpaqueClassBlock *
TR_J9ServerVM::getArrayClassFromDataType(TR::DataType type, bool booleanClass)
{
J9Class *j9class;
auto vmInfo = _compInfoPT->getClientData()->getOrCacheVMInfo(_compInfoPT->getStream());

if (booleanClass)
{
j9class = (J9Class *) vmInfo->_booleanArrayClass;
}
else
{
switch (type)
{
case TR::Float:
j9class = (J9Class *) vmInfo->_floatArrayClass;
break;
case TR::Double:
j9class = (J9Class *) vmInfo->_doubleArrayClass;
break;
case TR::Int8:
j9class = (J9Class *) vmInfo->_byteArrayClass;
break;
case TR::Int16:
j9class = (J9Class *) vmInfo->_shortArrayClass;
break;
case TR::Int32:
j9class = (J9Class *) vmInfo->_intArrayClass;
break;
case TR::Int64:
j9class = (J9Class *) vmInfo->_longArrayClass;
break;
default:
TR_ASSERT_FATAL(false, "Incorrect array element type");
return NULL;
}
}


return convertClassPtrToClassOffset(j9class);
}

bool
TR_J9SharedCacheServerVM::isClassLibraryMethod(TR_OpaqueMethodBlock *method, bool vettedForAOT)
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/VMJ9Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class TR_J9ServerVM: public TR_J9VM

virtual TR_arrayTypeCode getPrimitiveArrayTypeCode(TR_OpaqueClassBlock* clazz) override;
virtual TR::DataType getClassPrimitiveDataType(TR_OpaqueClassBlock* clazz) override;
virtual TR_OpaqueClassBlock *getArrayClassFromDataType(TR::DataType type, bool booleanClass) override;

private:
bool instanceOfOrCheckCastHelper(J9Class *instanceClass, J9Class* castClass, bool cacheUpdate);
Expand Down
46 changes: 3 additions & 43 deletions runtime/compiler/optimizer/VectorAPIExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ TR_VectorAPIExpansion::getOpaqueClassBlockFromClassNode(TR::Compilation *comp, T
{
auto stream = comp->getStream();
stream->write(JITServer::MessageType::KnownObjectTable_getOpaqueClass,
symRef->getKnownObjectIndex());
knownObjectIndex);

clazz = (TR_OpaqueClassBlock *)std::get<0>(stream->read<uintptr_t>());
}
Expand Down Expand Up @@ -895,46 +895,6 @@ TR_VectorAPIExpansion::getDataTypeFromClassNode(TR::Compilation *comp, TR::Node
return fej9->getClassPrimitiveDataType(clazz);
}

TR_OpaqueClassBlock *
TR_VectorAPIExpansion::getArrayClassFromDataType(TR::Compilation *comp, TR::DataType type, bool booleanClass)
{
TR_J9VMBase *fej9 = comp->fej9();
J9JavaVM *vm = fej9->getJ9JITConfig()->javaVM;
J9Class *j9class;


switch (type)
{
case TR::Float:
j9class = vm->floatArrayClass;
break;
case TR::Double:
j9class = vm->doubleArrayClass;
break;
case TR::Int8:
j9class = vm->byteArrayClass;
break;
case TR::Int16:
j9class = vm->shortArrayClass;
break;
case TR::Int32:
j9class = vm->intArrayClass;
break;
case TR::Int64:
j9class = vm->longArrayClass;
break;
default:
TR_ASSERT_FATAL(false, "Incorrect array element type");
return NULL;
}

if (booleanClass)
j9class = vm->booleanArrayClass;

return fej9->convertClassPtrToClassOffset(j9class);
}


TR_VectorAPIExpansion::vapiObjType
TR_VectorAPIExpansion::getObjectTypeFromClassNode(TR::Compilation *comp, TR::Node *classNode)
{
Expand Down Expand Up @@ -1480,7 +1440,8 @@ TR_VectorAPIExpansion::boxChild(TR::TreeTop *treeTop, TR::Node *node, uint32_t i
TR_ASSERT_FATAL(vecClass, "vecClass is NULL when boxing %p\n", child);

// generate "newarray jitNewArray"
TR_OpaqueClassBlock *j9arrayClass = getArrayClassFromDataType(comp(), elementType, objectType == Mask);
TR_OpaqueClassBlock *j9arrayClass = comp()->fej9()->getArrayClassFromDataType(elementType,
objectType == Mask);

int32_t elementSize = OMR::DataType::getSize(elementType);
int32_t numLanes = bitsLength/8/elementSize;
Expand Down Expand Up @@ -1519,7 +1480,6 @@ TR_VectorAPIExpansion::boxChild(TR::TreeTop *treeTop, TR::Node *node, uint32_t i
newObject->setSymbolReference(comp()->getSymRefTab()->findOrCreateNewObjectSymbolRef(comp()->getMethodSymbol()));

TR_J9VMBase *fej9 = comp()->fej9();
TR::VMAccessCriticalSection getClassFromSignature(fej9);
TR::SymbolReference *j9class = comp()->getSymRefTab()->findOrCreateClassSymbol(comp()->getMethodSymbol(), -1, vecClass);

TR_ASSERT_FATAL(j9class, "J9Class symbol reference should not be null");
Expand Down
17 changes: 0 additions & 17 deletions runtime/compiler/optimizer/VectorAPIExpansion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,23 +693,6 @@ class TR_VectorAPIExpansion : public TR::Optimization
static TR_OpaqueClassBlock *getOpaqueClassBlockFromClassNode(TR::Compilation *comp,
TR::Node *classNode);

/** \brief
* Returns TR_OpaqueClassBlock for ann array class given element type
*
* \param comp
* Compilation
*
* \param type
* Data type
*
* \param booleanClass
* true if array of boolean values is needed
*
* \return
* TR_OpaqueClassBlock
*/
static TR_OpaqueClassBlock *getArrayClassFromDataType(TR::Compilation *comp, TR::DataType type, bool booleanClass);

/** \brief
* Returns corresponding \c vapiObjType for a known object being loaded by node
*
Expand Down
12 changes: 10 additions & 2 deletions runtime/compiler/runtime/JITClientSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class ClientSessionData
bool _elgibleForPersistIprofileInfo;
bool _reportByteCodeInfoAtCatchBlock;
TR_OpaqueClassBlock *_arrayTypeClasses[8];
TR_OpaqueClassBlock *_byteArrayClass;
TR_OpaqueClassBlock *_byteArrayOpaqueClass;
bool _isIndexableDataAddrPresent;
uintptr_t _contiguousIndexableHeaderSize;
uintptr_t _discontiguousIndexableHeaderSize;
Expand Down Expand Up @@ -335,7 +335,7 @@ class ClientSessionData
bool _isPortableRestoreMode;
bool _isSnapshotModeEnabled;
bool _isNonPortableRestoreMode;
// The reflect class pointers for the server to identify the classes
// The reflect and array class pointers for the server to identify the classes
void *_voidReflectClassPtr;
void *_booleanReflectClassPtr;
void *_charReflectClassPtr;
Expand All @@ -345,6 +345,14 @@ class ClientSessionData
void *_shortReflectClassPtr;
void *_intReflectClassPtr;
void *_longReflectClassPtr;
void *_booleanArrayClass;
void *_charArrayClass;
void *_floatArrayClass;
void *_doubleArrayClass;
void *_byteArrayClass;
void *_shortArrayClass;
void *_intArrayClass;
void *_longArrayClass;
}; // struct VMInfo

/**
Expand Down