From c344c10d1022fc27aeaa6f5249a8d56087ee79b2 Mon Sep 17 00:00:00 2001 From: Luke Li Date: Tue, 10 Dec 2024 15:10:29 -0500 Subject: [PATCH] Clean Up VM Accesses in Vector Expansion API for the JITServer Move the relevant VM Accesses in the Vector API to the frontend and remove unnecessary ones to ensure compatability with the JITServer. Signed-off-by: Luke Li --- .../control/JITClientCompilationThread.cpp | 10 +++- runtime/compiler/env/VMJ9.cpp | 42 +++++++++++++++++ runtime/compiler/env/VMJ9.h | 1 + runtime/compiler/env/VMJ9Server.cpp | 43 ++++++++++++++++- runtime/compiler/env/VMJ9Server.hpp | 1 + .../compiler/optimizer/VectorAPIExpansion.cpp | 46 ++----------------- .../compiler/optimizer/VectorAPIExpansion.hpp | 17 ------- runtime/compiler/runtime/JITClientSession.hpp | 12 ++++- 8 files changed, 108 insertions(+), 64 deletions(-) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index c6f0c1e4fa7..668db9361ef 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -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(); @@ -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()); } diff --git a/runtime/compiler/env/VMJ9.cpp b/runtime/compiler/env/VMJ9.cpp index 1aed8150c53..3aed0008149 100644 --- a/runtime/compiler/env/VMJ9.cpp +++ b/runtime/compiler/env/VMJ9.cpp @@ -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) + { + 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) { diff --git a/runtime/compiler/env/VMJ9.h b/runtime/compiler/env/VMJ9.h index b3e2fc6e378..1cb0a5a92e2 100644 --- a/runtime/compiler/env/VMJ9.h +++ b/runtime/compiler/env/VMJ9.h @@ -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(); diff --git a/runtime/compiler/env/VMJ9Server.cpp b/runtime/compiler/env/VMJ9Server.cpp index 7e802b0b967..e90136f306c 100644 --- a/runtime/compiler/env/VMJ9Server.cpp +++ b/runtime/compiler/env/VMJ9Server.cpp @@ -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 @@ -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) diff --git a/runtime/compiler/env/VMJ9Server.hpp b/runtime/compiler/env/VMJ9Server.hpp index 3d20990a165..966d91e0193 100644 --- a/runtime/compiler/env/VMJ9Server.hpp +++ b/runtime/compiler/env/VMJ9Server.hpp @@ -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); diff --git a/runtime/compiler/optimizer/VectorAPIExpansion.cpp b/runtime/compiler/optimizer/VectorAPIExpansion.cpp index ad5927d0d68..5f972402ec6 100644 --- a/runtime/compiler/optimizer/VectorAPIExpansion.cpp +++ b/runtime/compiler/optimizer/VectorAPIExpansion.cpp @@ -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()); } @@ -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) { @@ -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; @@ -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"); diff --git a/runtime/compiler/optimizer/VectorAPIExpansion.hpp b/runtime/compiler/optimizer/VectorAPIExpansion.hpp index 1732ffa7ea6..5e1aa9bbd6f 100644 --- a/runtime/compiler/optimizer/VectorAPIExpansion.hpp +++ b/runtime/compiler/optimizer/VectorAPIExpansion.hpp @@ -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 * diff --git a/runtime/compiler/runtime/JITClientSession.hpp b/runtime/compiler/runtime/JITClientSession.hpp index ad90105b93f..d3ffca20207 100644 --- a/runtime/compiler/runtime/JITClientSession.hpp +++ b/runtime/compiler/runtime/JITClientSession.hpp @@ -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; @@ -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; @@ -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 /**