Skip to content

Commit

Permalink
Merge pull request #21067 from mpirvu/jitserver_cpu_debug
Browse files Browse the repository at this point in the history
Reduce the number of VM_isStable messages
  • Loading branch information
dsouzai authored Feb 11, 2025
2 parents 361ff83 + bf518c3 commit 9b037f7
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 95 deletions.
2 changes: 1 addition & 1 deletion runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
{
auto recv = client->getRecvData<J9Class *, int>();
J9Class *fieldClass = std::get<0>(recv);
int cpIndex = std::get<1>(recv);
int32_t cpIndex = std::get<1>(recv);

bool isStable = fe->isStable(fieldClass, cpIndex);
client->write(response, isStable);
Expand Down
12 changes: 12 additions & 0 deletions runtime/compiler/control/JITServerHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,18 @@ JITServerHelpers::getROMClassData(const ClientSessionData::ClassInfo &classInfo,
}
}

ClientSessionData::ClassInfo &
JITServerHelpers::getJ9ClassInfo(TR::CompilationInfoPerThread *threadCompInfo, J9Class *clazz)
{
// This function assumes that you are inside of _romMapMonitor
// Do not use it otherwise
auto &classMap = threadCompInfo->getClientData()->getROMClassMap();
auto it = classMap.find(clazz);
TR_ASSERT_FATAL(it != classMap.end(),"compThreadID %d, ClientData %p, clazz %p: ClassInfo is not in the class map %p!!\n",
threadCompInfo->getCompThreadId(), threadCompInfo->getClientData(), clazz, &classMap);
return it->second;
}

J9ROMMethod *
JITServerHelpers::romMethodOfRamMethod(J9Method* method)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/control/JITServerHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class JITServerHelpers
static bool getAndCacheRAMClassInfo(J9Class *clazz, ClientSessionData *clientSessionData,
JITServer::ServerStream *stream, ClassInfoDataType dataType1, void *data1,
ClassInfoDataType dataType2, void *data2);
static ClientSessionData::ClassInfo &getJ9ClassInfo(TR::CompilationInfoPerThread *threadCompInfo, J9Class *clazz);
static J9ROMMethod *romMethodOfRamMethod(J9Method* method);

static void insertIntoOOSequenceEntryList(ClientSessionData *clientData, TR_MethodToBeCompiled *entry);
Expand Down
39 changes: 4 additions & 35 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,9 +1250,8 @@ TR_J9VMBase::getObjectClassInfoFromObjectReferenceLocation(TR::Compilation *comp
if (knot)
{
TR::VMAccessCriticalSection getObjectReferenceLocation(comp);
uintptr_t objectReference = getStaticReferenceFieldAtAddress
(objectReferenceLocation);
ci.clazz = getObjectClass(objectReference);
uintptr_t objectReference = getStaticReferenceFieldAtAddress(objectReferenceLocation);
ci.clazz = getObjectClass(objectReference);
ci.isString = isString(ci.clazz);
ci.jlClass = getClassClassPointer(ci.clazz);
ci.isFixedJavaLangClass = (ci.jlClass == ci.clazz);
Expand Down Expand Up @@ -3936,7 +3935,7 @@ TR_J9VMBase::canDereferenceAtCompileTimeWithFieldSymbol(TR::Symbol * fieldSymbol
{
TR::Compilation *comp = TR::comp();

if (isStable(cpIndex, owningMethod, comp))
if (owningMethod->isStable(cpIndex, comp))
return true;

switch (fieldSymbol->getRecognizedField())
Expand Down Expand Up @@ -4013,37 +4012,7 @@ TR_J9VMBase::canDereferenceAtCompileTime(TR::SymbolReference *fieldRef, TR::Comp
}

bool
TR_J9VMBase::isStable(int cpIndex, TR_ResolvedMethod *owningMethod, TR::Compilation *comp)
{
// NOTE: the field must be resolved!

if (comp->getOption(TR_DisableStableAnnotations))
return false;

if (cpIndex < 0)
return false;

J9Class *fieldClass = (J9Class*)owningMethod->classOfMethod();
if (!fieldClass)
return false;

bool isFieldStable = isStable(fieldClass, cpIndex);

if (isFieldStable && comp->getOption(TR_TraceOptDetails))
{
int classLen;
const char * className= owningMethod->classNameOfFieldOrStatic(cpIndex, classLen);
int fieldLen;
const char * fieldName = owningMethod->fieldNameChars(cpIndex, fieldLen);
traceMsg(comp, " Found stable field: %.*s.%.*s\n", classLen, className, fieldLen, fieldName);
}

// Not checking for JCL classes since @Stable annotation only visible inside JCL
return isFieldStable;
}

bool
TR_J9VMBase::isStable(J9Class *fieldClass, int cpIndex)
TR_J9VMBase::isStable(J9Class *fieldClass, int32_t cpIndex)
{
TR_ASSERT_FATAL(fieldClass, "fieldClass must not be NULL");
return jitIsFieldStable(vmThread(), fieldClass, cpIndex);
Expand Down
7 changes: 3 additions & 4 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,7 @@ class TR_J9VMBase : public TR_FrontEnd
* the method accessing the field
*
*/
virtual bool isStable(int cpIndex, TR_ResolvedMethod *owningMethod, TR::Compilation *comp);
virtual bool isStable(J9Class *fieldClass, int cpIndex);
virtual bool isStable(J9Class *fieldClass, int32_t cpIndex);

/*
* \brief
Expand Down Expand Up @@ -1671,8 +1670,8 @@ class TR_J9SharedCacheVM : public TR_J9VM
virtual bool supportsJitMethodEntryAlignment() { return false; }
virtual bool isBenefitInliningCheckIfFinalizeObject() { return true; }
virtual bool needsContiguousCodeAndDataCacheAllocation() { return true; }
virtual bool needRelocatableTarget() { return true; }
virtual bool isStable(int cpIndex, TR_ResolvedMethod *owningMethod, TR::Compilation *comp) { return false; }
virtual bool needRelocatableTarget() { return true; }
virtual bool isStable(J9Class *fieldClass, int32_t cpIndex) { return false; }

virtual bool isResolvedDirectDispatchGuaranteed(TR::Compilation *comp);
virtual bool isResolvedVirtualDispatchGuaranteed(TR::Compilation *comp);
Expand Down
30 changes: 28 additions & 2 deletions runtime/compiler/env/VMJ9Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2518,11 +2518,37 @@ TR_J9ServerVM::isLambdaFormGeneratedMethod(TR_ResolvedMethod *method)
}

bool
TR_J9ServerVM::isStable(J9Class *fieldClass, int cpIndex)
TR_J9ServerVM::isStable(J9Class *fieldClass, int32_t cpIndex)
{
// See if we cached the presence of the annotation for this class and cpIndex
{
OMR::CriticalSection getRemoteROMClass(_compInfoPT->getClientData()->getROMMapMonitor());
// The fieldClass is guaranteed to be cached at the server because this
// method is called from a ResolvedMethod
auto &cache = JITServerHelpers::getJ9ClassInfo(_compInfoPT, fieldClass)._isStableCache;
auto it = cache.find(cpIndex);
if (it != cache.end())
return it->second;
}
// At the moment, @Stable annotations are only used in bootstrap classes (this can change though).
// To limit the number of VM_isStable messages further and to reduce the number of values that
// are cached in "_isStableCache" cache, we return 'false' when the `fieldClass` is not a bootstrap class.
static char *dontIgnore = feGetEnv("TR_DontIgnoreStableAnnotationForUserClasses");
if (!dontIgnore && !isClassLibraryClass((TR_OpaqueClassBlock*)fieldClass))
return false;

// Not cached; send a message and obtain the value
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
stream->write(JITServer::MessageType::VM_isStable, fieldClass, cpIndex);
return std::get<0>(stream->read<bool>());
bool answer = std::get<0>(stream->read<bool>());

// Cache the answer
{
OMR::CriticalSection getRemoteROMClass(_compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = JITServerHelpers::getJ9ClassInfo(_compInfoPT, fieldClass)._isStableCache;
cache.insert({cpIndex, answer});
}
return answer;
}

bool
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/env/VMJ9Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class TR_J9ServerVM: public TR_J9VM
virtual uintptr_t getClassFlagsValue(TR_OpaqueClassBlock * clazz) override;
virtual TR_OpaqueMethodBlock *getMethodFromName(const char *className, const char *methodName, const char *signature) override;
virtual TR_OpaqueMethodBlock *getMethodFromClass(TR_OpaqueClassBlock *methodClass, const char *methodName, const char *signature, TR_OpaqueClassBlock *callingClass) override;
virtual bool isStable(J9Class *fieldClass, int cpIndex) override;
virtual bool isStable(J9Class *fieldClass, int32_t cpIndex) override;
virtual bool isForceInline(TR_ResolvedMethod *method) override;
virtual bool isIntrinsicCandidate(TR_ResolvedMethod *method) override;
virtual bool isDontInline(TR_ResolvedMethod *method) override;
Expand Down Expand Up @@ -333,7 +333,7 @@ class TR_J9SharedCacheServerVM: public TR_J9ServerVM
virtual bool isResolvedVirtualDispatchGuaranteed(TR::Compilation *comp) override;

virtual bool shouldDelayAotLoad() override { return true; }
virtual bool isStable(int cpIndex, TR_ResolvedMethod *owningMethod, TR::Compilation *comp) override { return false; }
virtual bool isStable(J9Class *fieldClass, int32_t cpIndex) override { return false; }
virtual bool isClassVisible(TR_OpaqueClassBlock *sourceClass, TR_OpaqueClassBlock *destClass) override;
virtual bool stackWalkerMaySkipFrames(TR_OpaqueMethodBlock *method, TR_OpaqueClassBlock *methodClass) override;
virtual bool isMethodTracingEnabled(TR_OpaqueMethodBlock *method) override;
Expand Down
27 changes: 27 additions & 0 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6449,6 +6449,33 @@ TR_ResolvedJ9Method::getClassFromCP(TR_J9VMBase *fej9, J9ConstantPool *cp, TR::C
return result;
}

bool
TR_ResolvedJ9Method::isStable(int32_t cpIndex, TR::Compilation *comp)
{
if (comp->getOption(TR_DisableStableAnnotations))
return false;

if (cpIndex < 0)
return false;

J9Class *fieldClass = (J9Class*)classOfMethod();
if (!fieldClass)
return false;

bool isFieldStable = fej9()->isStable(fieldClass, cpIndex);

if (isFieldStable && comp->getOption(TR_TraceOptDetails))
{
int classLen;
const char * className= classNameOfFieldOrStatic(cpIndex, classLen);
int fieldLen;
const char * fieldName = fieldNameChars(cpIndex, fieldLen);
traceMsg(comp, " Found stable field: %.*s.%.*s\n", classLen, className, fieldLen, fieldName);
}

return isFieldStable;
}

TR_OpaqueClassBlock *
TR_ResolvedJ9Method::getClassFromConstantPool(TR::Compilation * comp, uint32_t cpIndex, bool)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/j9method.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class TR_ResolvedJ9Method : public TR_J9Method, public TR_ResolvedJ9MethodBase
virtual void * callSiteTableEntryAddress(int32_t callSiteIndex);
virtual bool isUnresolvedMethodTypeTableEntry(int32_t cpIndex);
virtual void * methodTypeTableEntryAddress(int32_t cpIndex);
virtual bool isStable(int32_t cpIndex, TR::Compilation *comp) override;
#if defined(J9VM_OPT_METHOD_HANDLE)
virtual bool isUnresolvedVarHandleMethodTypeTableEntry(int32_t cpIndex);
virtual void * varHandleMethodTypeTableEntryAddress(int32_t cpIndex);
Expand Down
39 changes: 14 additions & 25 deletions runtime/compiler/env/j9methodServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@
#include "ilgen/J9ByteCodeIterator.hpp"
#include "net/ServerStream.hpp"

ClientSessionData::ClassInfo &
getJ9ClassInfo(TR::CompilationInfoPerThread *threadCompInfo, J9Class *clazz)
{
// This function assumes that you are inside of _romMapMonitor
// Do not use it otherwise
auto &classMap = threadCompInfo->getClientData()->getROMClassMap();
auto it = classMap.find(clazz);
TR_ASSERT_FATAL(it != classMap.end(),"compThreadID %d, ClientData %p, clazz %p: ClassInfo is not in the class map %p!!\n",
threadCompInfo->getCompThreadId(), threadCompInfo->getClientData(), clazz, &classMap);
return it->second;
}

static J9ROMMethod *
romMethodAtClassIndex(J9ROMClass *romClass, uint64_t methodIndex)
Expand Down Expand Up @@ -151,7 +140,7 @@ TR_ResolvedJ9JITServerMethod::definingClassFromCPFieldRef(TR::Compilation *comp,
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDefiningClassCache;
auto &cache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDefiningClassCache;
auto it = cache.find(cpIndex);
if (it != cache.end())
{
Expand All @@ -166,7 +155,7 @@ TR_ResolvedJ9JITServerMethod::definingClassFromCPFieldRef(TR::Compilation *comp,
if (resolvedClass)
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDefiningClassCache;
auto &cache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDefiningClassCache;
cache.insert({cpIndex, resolvedClass});
}
if (fromResolvedJ9Method != NULL)
Expand All @@ -193,7 +182,7 @@ TR_ResolvedJ9JITServerMethod::getClassFromConstantPool(TR::Compilation * comp, u
// This persistent cache must only be checked when doRuntimeResolve is false,
// otherwise a non method handle thunk compilation can return cached value, instead of NULL.
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &constantClassPoolCache = getJ9ClassInfo(compInfoPT, _ramClass)._constantClassPoolCache;
auto &constantClassPoolCache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._constantClassPoolCache;
auto it = constantClassPoolCache.find(cpIndex);
if (it != constantClassPoolCache.end())
return it->second;
Expand All @@ -204,7 +193,7 @@ TR_ResolvedJ9JITServerMethod::getClassFromConstantPool(TR::Compilation * comp, u
if (resolvedClass)
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &constantClassPoolCache = getJ9ClassInfo(compInfoPT, _ramClass)._constantClassPoolCache;
auto &constantClassPoolCache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._constantClassPoolCache;
constantClassPoolCache.insert({cpIndex, resolvedClass});
}
return resolvedClass;
Expand All @@ -216,7 +205,7 @@ TR_ResolvedJ9JITServerMethod::getDeclaringClassFromFieldOrStatic(TR::Compilation
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDeclaringClassCache;
auto &cache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDeclaringClassCache;
auto it = cache.find(cpIndex);
if (it != cache.end())
return it->second;
Expand All @@ -226,7 +215,7 @@ TR_ResolvedJ9JITServerMethod::getDeclaringClassFromFieldOrStatic(TR::Compilation
if (declaringClass)
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDeclaringClassCache;
auto &cache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDeclaringClassCache;
cache.insert({cpIndex, declaringClass});
}
return declaringClass;
Expand All @@ -242,7 +231,7 @@ TR_ResolvedJ9JITServerMethod::classOfStatic(I_32 cpIndex, bool returnClassForAOT
auto compInfoPT = static_cast<TR::CompilationInfoPerThreadRemote *>(_fe->_compInfoPT);
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &classOfStaticCache = getJ9ClassInfo(compInfoPT, _ramClass)._classOfStaticCache;
auto &classOfStaticCache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._classOfStaticCache;
auto it = classOfStaticCache.find(cpIndex);
if (it != classOfStaticCache.end())
return it->second;
Expand All @@ -260,7 +249,7 @@ TR_ResolvedJ9JITServerMethod::classOfStatic(I_32 cpIndex, bool returnClassForAOT
// if client returned NULL, don't cache, because class might not be fully initialized,
// so the result may change in the future
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &classOfStaticCache = getJ9ClassInfo(compInfoPT, _ramClass)._classOfStaticCache;
auto &classOfStaticCache = JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._classOfStaticCache;
classOfStaticCache.insert({cpIndex, classOfStatic});
}
else
Expand Down Expand Up @@ -534,8 +523,8 @@ TR_ResolvedJ9JITServerMethod::getAttributesCache(bool isStatic, bool unresolvedI
// Return a persistent attributes cache for regular JIT compilations
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
auto &attributesCache = isStatic ?
getJ9ClassInfo(compInfoPT, _ramClass)._staticAttributesCache :
getJ9ClassInfo(compInfoPT, _ramClass)._fieldAttributesCache;
JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._staticAttributesCache :
JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._fieldAttributesCache;
return attributesCache;
}

Expand Down Expand Up @@ -2738,8 +2727,8 @@ TR_ResolvedRelocatableJ9JITServerMethod::getAttributesCache(bool isStatic, bool
// Return persistent attributes cache for AOT compilations
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
auto &attributesCache = isStatic ?
getJ9ClassInfo(compInfoPT, _ramClass)._staticAttributesCacheAOT :
getJ9ClassInfo(compInfoPT, _ramClass)._fieldAttributesCacheAOT;
JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._staticAttributesCacheAOT :
JITServerHelpers::getJ9ClassInfo(compInfoPT, _ramClass)._fieldAttributesCacheAOT;
return attributesCache;
}

Expand Down Expand Up @@ -2775,7 +2764,7 @@ TR_J9ServerMethod::TR_J9ServerMethod(TR_FrontEnd * fe, TR_Memory * trMemory, J9C
{
// look up parameters for construction of this method in a cache first
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, aClazz)._J9MethodNameCache;
auto &cache = JITServerHelpers::getJ9ClassInfo(compInfoPT, aClazz)._J9MethodNameCache;
// search the cache for existing method parameters
auto it = cache.find(cpIndex);
if (it != cache.end())
Expand All @@ -2799,7 +2788,7 @@ TR_J9ServerMethod::TR_J9ServerMethod(TR_FrontEnd * fe, TR_Memory * trMemory, J9C
methodSignatureStr = std::get<2>(recv);

OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, aClazz)._J9MethodNameCache;
auto &cache = JITServerHelpers::getJ9ClassInfo(compInfoPT, aClazz)._J9MethodNameCache;
cache.insert({cpIndex, {classNameStr, methodNameStr, methodSignatureStr}});
}

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 @@ -129,7 +129,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 = 77; // ID: J440z7/ZN5+KF233VhGB
static const uint16_t MINOR_NUMBER = 78; // ID: DGwBSxx9FLiSwWTdQCIn
static const uint8_t PATCH_NUMBER = 0;
static uint32_t CONFIGURATION_FLAGS;

Expand Down
Loading

0 comments on commit 9b037f7

Please sign in to comment.