Skip to content

Commit

Permalink
Merge pull request #13907 from AlexeyKhrabrov/jitserver_aotcache_records
Browse files Browse the repository at this point in the history
  • Loading branch information
mpirvu committed Nov 18, 2021
2 parents 4a7c1cd + f3de5c7 commit 9a78143
Show file tree
Hide file tree
Showing 28 changed files with 1,012 additions and 434 deletions.
2 changes: 1 addition & 1 deletion runtime/compiler/arm/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ J9::ARM::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::I
// flags stored in data3 are currently unused
uintptr_t inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(symRef->getOwningMethod(comp)->constantPool(), recordInfo->data2);

uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(j9class);
uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(j9class);
uintptr_t classChainOffsetInSharedCache = self()->getClassChainOffset(j9class);

acaRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
Expand Down
12 changes: 6 additions & 6 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
uintptr_t romClassOffsetInSharedCache = self()->offsetInSharedCacheFromROMClass(sharedCache, romClass);
traceMsg(comp, "class is %p, romclass is %p, offset is %llu\n", inlinedCodeClass, romClass, romClassOffsetInSharedCache);

uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(inlinedCodeClass);
uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(inlinedCodeClass);

uintptr_t classChainOffsetInSharedCache = self()->getClassChainOffset(inlinedCodeClass);

Expand Down Expand Up @@ -540,7 +540,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal

TR_OpaqueClassBlock *j9class = fej9->getClassFromMethodBlock(j9method);

uintptr_t classChainOffsetOfCLInSharedCache = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(j9class);
uintptr_t classChainOffsetOfCLInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(j9class);
uintptr_t classChainForInlinedMethodOffsetInSharedCache = self()->getClassChainOffset(j9class);

uintptr_t vTableOffset = static_cast<uintptr_t>(fej9->getInterpreterVTableSlot(j9method, j9class));
Expand Down Expand Up @@ -580,7 +580,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
j9class = reinterpret_cast<TR_OpaqueClassBlock *>(aconstNode->getAddress());
}

uintptr_t classChainOffsetOfCLInSharedCache = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(j9class);
uintptr_t classChainOffsetOfCLInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(j9class);
uintptr_t classChainForInlinedMethodOffsetInSharedCache = self()->getClassChainOffset(j9class);

cpRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
Expand All @@ -596,7 +596,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
TR::AOTClassInfo *aotCI = reinterpret_cast<TR::AOTClassInfo*>(relocation->getTargetAddress2());
TR_OpaqueClassBlock *classToValidate = aotCI->_clazz;

uintptr_t classChainOffsetInSharedCacheForCL = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(classToValidate);
uintptr_t classChainOffsetInSharedCacheForCL = sharedCache->getClassChainOffsetIdentifyingLoader(classToValidate);

void *classChainForClassToValidate = aotCI->_classChain;
uintptr_t classChainOffsetInSharedCache = self()->offsetInSharedCacheFromPointer(sharedCache, classChainForClassToValidate);
Expand Down Expand Up @@ -642,7 +642,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
void *classChainForClassToValidate = svmRecord->_classChain;

//store the classchain's offset for the classloader for the class
uintptr_t classChainOffsetInSharedCacheForCL = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(classToValidate);
uintptr_t classChainOffsetInSharedCacheForCL = sharedCache->getClassChainOffsetIdentifyingLoader(classToValidate);

//store the classchain's offset for the class that needs to be validated in the second run
uintptr_t classChainOffsetInSharedCache = self()->offsetInSharedCacheFromPointer(sharedCache, classChainForClassToValidate);
Expand Down Expand Up @@ -1074,7 +1074,7 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
void *constantPool = symRef->getOwningMethod(comp)->constantPool();
inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(constantPool, inlinedSiteIndex);

uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(j9class);
uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(j9class);
uintptr_t classChainOffsetInSharedCache = self()->getClassChainOffset(j9class);

acaRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);
Expand Down
34 changes: 26 additions & 8 deletions runtime/compiler/compile/AOTClassInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -28,6 +28,8 @@
#include "env/jittypes.h"
#include "env/VMJ9.h"

class AOTCacheClassChainRecord;


// AOTClassInfo is a structure used to record assumptions on classes made by the
// current compilation. There are two types of validations: ones based on a
Expand All @@ -47,7 +49,7 @@ namespace TR

class AOTClassInfo
{
public:
public:

TR_ALLOC(TR_Memory::AOTClassInfo)

Expand All @@ -57,27 +59,43 @@ class AOTClassInfo
void *classChain,
TR_OpaqueMethodBlock *method,
uint32_t cpIndex,
TR_ExternalRelocationTargetKind
reloKind) :
TR_ExternalRelocationTargetKind reloKind,
const AOTCacheClassChainRecord *aotCacheClassChainRecord = NULL
) :
_clazz(clazz),
_classChain(classChain),
_method(method),
_constantPool((void *) ((TR_J9VMBase *)fe)->getConstantPoolFromMethod(method)),
_cpIndex(cpIndex),
_reloKind(reloKind)
{}
{
#if defined(J9VM_OPT_JITSERVER)
TR_ASSERT(!aotCacheClassChainRecord || (fe->getPersistentInfo()->getRemoteCompilationMode() == JITServer::SERVER),
"Must always be NULL at JIT client");
_aotCacheClassChainRecord = aotCacheClassChainRecord;
#endif /* defined(J9VM_OPT_JITSERVER) */
}

TR_ExternalRelocationTargetKind _reloKind; // identifies validation needed (instance field, static field, class, arbitrary class)
#if defined(J9VM_OPT_JITSERVER)
const AOTCacheClassChainRecord *getAOTCacheClassChainRecord() { return _aotCacheClassChainRecord; }
#else /* defined(J9VM_OPT_JITSERVER) */
const AOTCacheClassChainRecord *getAOTCacheClassChainRecord() { return NULL; }
#endif /* defined(J9VM_OPT_JITSERVER) */

TR_ExternalRelocationTargetKind _reloKind; // identifies validation needed (instance field, static field, class, arbitrary class)
uint32_t _cpIndex; // cpindex identifying the cp entry if known otherwise -1
TR_OpaqueMethodBlock *_method; // inlined method owning the cp entry or to which assumption is attached
// _method must be compiled method or some method in the inlined site table
void *_constantPool; // constant pool owning the cp entry, initialized based on _method

uint32_t _cpIndex; // cpindex identifying the cp entry if known otherwise -1
TR_OpaqueClassBlock *_clazz; // class on which assumption is formed
void *_classChain; // class chain for clazz: captures the assumption
// == NULL for TR_ValidateStaticField validations
#if defined(J9VM_OPT_JITSERVER)
const AOTCacheClassChainRecord *_aotCacheClassChainRecord; // NULL at JITServer if compiled method won't be cached
// Always NULL at JIT client
#endif /* defined(J9VM_OPT_JITSERVER) */
};

}

#endif
1 change: 1 addition & 0 deletions runtime/compiler/compile/J9Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ J9::Compilation::Compilation(int32_t id,
_globalMemory(*::trPersistentMemory, heapMemoryRegion),
_perClientMemory(_trMemory),
_methodsRequiringTrampolines(getTypedAllocator<TR_OpaqueMethodBlock *>(self()->allocator())),
_aotCacheStore(false),
#endif /* defined(J9VM_OPT_JITSERVER) */
_osrProhibitedOverRangeOfTrees(false)
{
Expand Down
7 changes: 7 additions & 0 deletions runtime/compiler/compile/J9Compilation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
}

TR::list<TR_OpaqueMethodBlock *>& getMethodsRequiringTrampolines() { return _methodsRequiringTrampolines; }

bool isAOTCacheStore() const { return _aotCacheStore; }
void setAOTCacheStore(bool store) { _aotCacheStore = store; }
#endif /* defined(J9VM_OPT_JITSERVER) */

TR::SymbolValidationManager *getSymbolValidationManager() { return _symbolValidationManager; }
Expand Down Expand Up @@ -454,6 +457,10 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
// It needs to be sent to the client at the end of compilation
// so that trampolines can be reserved there.
TR::list<TR_OpaqueMethodBlock *> _methodsRequiringTrampolines;

// True if the result of this out-of-process compilation will be
// stored in JITServer AOT cache; always false at the client
bool _aotCacheStore;
#endif /* defined(J9VM_OPT_JITSERVER) */

TR::SymbolValidationManager *_symbolValidationManager;
Expand Down
7 changes: 3 additions & 4 deletions runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,14 @@ TR::CompilationInfoPerThread::getRemoteROMClassIfCached(J9Class *clazz)
}

J9ROMClass *
TR::CompilationInfoPerThread::getAndCacheRemoteROMClass(J9Class *clazz, TR_Memory *trMemory)
TR::CompilationInfoPerThread::getAndCacheRemoteROMClass(J9Class *clazz)
{
auto romClass = getRemoteROMClassIfCached(clazz);
if (romClass == NULL)
{
JITServerHelpers::ClassInfoTuple classInfoTuple;
TR_Memory *currentMemory = trMemory ? trMemory : TR::comp()->trMemory();
romClass = JITServerHelpers::getRemoteROMClass(clazz, getStream(), currentMemory, &classInfoTuple);
romClass = JITServerHelpers::cacheRemoteROMClassOrFreeIt(getClientData(), clazz, romClass, &classInfoTuple, currentMemory->trPersistentMemory());
romClass = JITServerHelpers::getRemoteROMClass(clazz, getStream(), getClientData()->persistentMemory(), classInfoTuple);
romClass = JITServerHelpers::cacheRemoteROMClassOrFreeIt(getClientData(), clazz, romClass, classInfoTuple);
TR_ASSERT_FATAL(romClass, "ROM class of J9Class=%p must be cached at this point", clazz);
}
return romClass;
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/control/CompilationThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase
TR_J9SharedCacheServerVM *getSharedCacheServerVM() const { return _sharedCacheServerVM; }
void setSharedCacheServerVM(TR_J9SharedCacheServerVM *vm) { _sharedCacheServerVM = vm; }
JITServer::ServerStream *getStream();
J9ROMClass *getAndCacheRemoteROMClass(J9Class *, TR_Memory *trMemory=NULL);
J9ROMClass *getRemoteROMClassIfCached(J9Class *);
J9ROMClass *getAndCacheRemoteROMClass(J9Class *clazz);
J9ROMClass *getRemoteROMClassIfCached(J9Class *clazz);
PersistentUnorderedSet<TR_OpaqueClassBlock*> *getClassesThatShouldNotBeNewlyExtended() const { return _classesThatShouldNotBeNewlyExtended; }
#endif /* defined(J9VM_OPT_JITSERVER) */

Expand Down
12 changes: 12 additions & 0 deletions runtime/compiler/control/J9Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@ static bool JITServerParseCommonOptions(J9JavaVM *vm, TR::CompilationInfo *compI

if (xxJITServerUseAOTCacheArgIndex > xxDisableJITServerUseAOTCacheArgIndex)
compInfo->getPersistentInfo()->setJITServerUseAOTCache(true);
else
compInfo->getPersistentInfo()->setJITServerUseAOTCache(false);

if (xxJITServerLogConnectionsArgIndex > xxDisableJITServerLogConnectionsArgIndex)
{
Expand Down Expand Up @@ -2051,6 +2053,16 @@ bool J9::Options::preProcessJitServer(J9JavaVM *vm, J9JITConfig *jitConfig)
{
compInfo->getPersistentInfo()->setLocalSyncCompiles(true);
}

const char *xxJITServerAOTCacheNameOption = "-XX:JITServerAOTCacheName=";
int32_t xxJITServerAOTCacheNameArgIndex = FIND_ARG_IN_VMARGS(STARTSWITH_MATCH, xxJITServerAOTCacheNameOption, 0);

if (xxJITServerAOTCacheNameArgIndex >= 0)
{
char *name = NULL;
GET_OPTION_VALUE(xxJITServerAOTCacheNameArgIndex, '=', &name);
compInfo->getPersistentInfo()->setJITServerAOTCacheName(name);
}
}
}
if (!JITServerParseCommonOptions(vm, compInfo))
Expand Down
61 changes: 54 additions & 7 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,15 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
vmInfo._staticObjectAllocateFlags = fe->getStaticObjectFlags();
vmInfo._referenceArrayCopyHelperAddress = fe->getReferenceArrayCopyHelperAddress();

client->write(response, vmInfo, listOfCacheDescriptors);
vmInfo._useAOTCache = comp->getPersistentInfo()->getJITServerUseAOTCache();
if (vmInfo._useAOTCache)
{
auto header = compInfoPT->reloRuntime()->getStoredAOTHeader(vmThread);
TR_ASSERT_FATAL(header, "Must have valid AOT header stored in SCC by now");
vmInfo._aotHeader = *header;
}

client->write(response, vmInfo, listOfCacheDescriptors, comp->getPersistentInfo()->getJITServerAOTCacheName());
}
break;
case MessageType::VM_getObjectClass:
Expand Down Expand Up @@ -2077,19 +2085,40 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, entries, fieldNames, typeSignatures);
}
break;
case MessageType::SharedCache_getClassChainOffsetInSharedCache:
case MessageType::SharedCache_getClassChainOffsetIdentifyingLoader:
{
auto j9class = std::get<0>(client->getRecvData<TR_OpaqueClassBlock *>());
uintptr_t classChainOffsetInSharedCache = fe->sharedCache()->getClassChainOffsetOfIdentifyingLoaderForClazzInSharedCache(j9class);
client->write(response, classChainOffsetInSharedCache);
auto recv = client->getRecvData<TR_OpaqueClassBlock *, bool>();
auto j9class = std::get<0>(recv);
bool getName = std::get<1>(recv);
auto sharedCache = fe->sharedCache();
uintptr_t *chain = NULL;
uintptr_t offset = sharedCache->getClassChainOffsetIdentifyingLoader(j9class, &chain);
std::string nameStr;
if (getName && chain)
{
const J9UTF8 *name = J9ROMCLASS_CLASSNAME(sharedCache->startingROMClassOfClassChain(chain));
nameStr = std::string((const char *)J9UTF8_DATA(name), J9UTF8_LENGTH(name));
}
client->write(response, offset, nameStr);
}
break;
case MessageType::SharedCache_rememberClass:
{
auto recv = client->getRecvData<J9Class *, bool>();
auto recv = client->getRecvData<J9Class *, bool, bool>();
auto clazz = std::get<0>(recv);
bool create = std::get<1>(recv);
client->write(response, fe->sharedCache()->rememberClass(clazz, create));
bool getClasses = std::get<2>(recv);
uintptr_t *classChain = fe->sharedCache()->rememberClass(clazz, NULL, create);
std::vector<J9Class *> ramClassChain;
std::vector<J9Class *> uncachedRAMClasses;
std::vector<JITServerHelpers::ClassInfoTuple> uncachedClassInfos;
if (create && getClasses && classChain)
{
uintptr_t len = classChain[0] / sizeof(classChain[0]) - 1;
ramClassChain = JITServerHelpers::getRAMClassChain(clazz, len, vmThread, trMemory, compInfo,
uncachedRAMClasses, uncachedClassInfos);
}
client->write(response, classChain, ramClassChain, uncachedRAMClasses, uncachedClassInfos);
}
break;
case MessageType::SharedCache_addHint:
Expand Down Expand Up @@ -2762,6 +2791,24 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
client->write(response, knownObjectTableDumpInfoList);
}
break;
case MessageType::AOTCache_getROMClassBatch:
{
auto recv = client->getRecvData<std::vector<J9Class *>>();
auto &ramClasses = std::get<0>(recv);
std::vector<JITServerHelpers::ClassInfoTuple> classInfos;
classInfos.reserve(ramClasses.size());

for (J9Class *ramClass : ramClasses)
classInfos.push_back(JITServerHelpers::packRemoteROMClassInfo(ramClass, fe->vmThread(), trMemory, true));

{
OMR::CriticalSection cs(compInfo->getclassesCachedAtServerMonitor());
compInfo->getclassesCachedAtServer().insert(ramClasses.begin(), ramClasses.end());
}

client->write(response, classInfos);
}
break;
default:
// It is vital that this remains a hard error during dev!
TR_ASSERT(false, "JITServer: handleServerMessage received an unknown message type: %d\n", response);
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/control/JITServerCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@ TR::CompilationInfoPerThreadRemote::processEntry(TR_MethodToBeCompiled &entry, J
// a previous request, info which the server is expected to cache. However, this
// could be a new JITServer instance.
// Send a message to the client to retrieve desired info.
romClass = JITServerHelpers::getRemoteROMClass(clazz, stream, clientSession->persistentMemory(), &classInfoTuple);
romClass = JITServerHelpers::getRemoteROMClass(clazz, stream, clientSession->persistentMemory(), classInfoTuple);
}
romClass = JITServerHelpers::cacheRemoteROMClassOrFreeIt(getClientData(), clazz, romClass, &classInfoTuple, clientSession->persistentMemory());
romClass = JITServerHelpers::cacheRemoteROMClassOrFreeIt(clientSession, clazz, romClass, classInfoTuple);
TR_ASSERT_FATAL(romClass, "ROM class of J9Class=%p must be cached at this point", clazz);
}

Expand Down
Loading

0 comments on commit 9a78143

Please sign in to comment.