Skip to content

Commit

Permalink
Merge pull request #19101 from cjjdespres/deserializer-in-thread
Browse files Browse the repository at this point in the history
Cache compInfoPT in JITServer deserializer SCC interface
  • Loading branch information
mpirvu authored Mar 28, 2024
2 parents a9c32c6 + 51e54c8 commit d3d128a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 36 deletions.
4 changes: 0 additions & 4 deletions runtime/compiler/control/CompilationRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,6 @@ class CompilationInfo
JITServerAOTDeserializer *getJITServerAOTDeserializer() const { return _JITServerAOTDeserializer; }
void setJITServerAOTDeserializer(JITServerAOTDeserializer *deserializer) { _JITServerAOTDeserializer = deserializer; }

TR_J9DeserializerSharedCache *getDeserializerSharedCache() const { return _deserializerSharedCache; }
void setDeserializerSharedCache(TR_J9DeserializerSharedCache *deserializerSharedCache) { _deserializerSharedCache = deserializerSharedCache; }

bool methodCanBeJITServerAOTCacheStored(const char *methodSig, TR::Method::Type ty);
bool methodCanBeJITServerAOTCacheLoaded(const char *methodSig, TR::Method::Type ty);

Expand Down Expand Up @@ -1386,7 +1383,6 @@ class CompilationInfo
JITServerSharedROMClassCache *_sharedROMClassCache;
JITServerAOTCacheMap *_JITServerAOTCacheMap;
JITServerAOTDeserializer *_JITServerAOTDeserializer;
TR_J9DeserializerSharedCache *_deserializerSharedCache;
#endif /* defined(J9VM_OPT_JITSERVER) */

#if defined(J9VM_OPT_CRIU_SUPPORT)
Expand Down
8 changes: 7 additions & 1 deletion runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2949,7 +2949,13 @@ remoteCompilationEnd(J9VMThread *vmThread, TR::Compilation *comp, TR_ResolvedMet
TR_J9VMBase *fe = TR_J9VMBase::get(jitConfig, vmThread);
TR_J9SharedCache *cacheOverride = NULL;
if (comp->isDeserializedAOTMethod() && compInfo->getPersistentInfo()->getJITServerAOTCacheIgnoreLocalSCC())
cacheOverride = compInfo->getDeserializerSharedCache();
{
auto deserializerSCC = fe->deserializerSharedCache();
// This should be extremely rare
if (!deserializerSCC)
comp->failCompilation<TR::CompilationException>("Deserializer was not allocated in compilation thread");
cacheOverride = deserializerSCC;
}
metaData = entry->_compInfoPT->reloRuntime()->prepareRelocateAOTCodeAndData(
vmThread, fe, comp->cg()->getCodeCache(), (J9JITDataCacheHeader *)dataCacheStr.data(),
method, false, comp->getOptions(), comp, compilee, (uint8_t *)codeCacheStr.data(), cacheOverride
Expand Down
31 changes: 10 additions & 21 deletions runtime/compiler/control/rossa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2120,38 +2120,27 @@ aboutToBootstrap(J9JavaVM * javaVM, J9JITConfig * jitConfig)
// Create AOT deserializer at the client if using JITServer with AOT cache
if ((persistentInfo->getRemoteCompilationMode() == JITServer::CLIENT) && persistentInfo->getJITServerUseAOTCache())
{
JITServerAOTDeserializer *deserializer = NULL;
if (persistentInfo->getJITServerAOTCacheIgnoreLocalSCC())
{
auto deserializer = new (PERSISTENT_NEW) JITServerNoSCCAOTDeserializer(persistentInfo->getPersistentClassLoaderTable());
if (!deserializer)
{
fprintf(stderr, "Could not create JITServer AOT deserializer\n");
return -1;
}
compInfo->setJITServerAOTDeserializer(deserializer);
auto deserializerSharedCache = new (PERSISTENT_NEW) TR_J9DeserializerSharedCache(vm, deserializer);
if (!deserializerSharedCache)
{
fprintf(stderr, "Could not create JITServer AOT deserializer cache\n");
return -1;
}
compInfo->setDeserializerSharedCache(deserializerSharedCache);
deserializer = new (PERSISTENT_NEW) JITServerNoSCCAOTDeserializer(persistentInfo->getPersistentClassLoaderTable());
}
else if (TR::Options::sharedClassCache())
{
auto deserializer = new (PERSISTENT_NEW) JITServerLocalSCCAOTDeserializer(persistentInfo->getPersistentClassLoaderTable());
if (!deserializer)
{
fprintf(stderr, "Could not create JITServer AOT deserializer\n");
return -1;
}
compInfo->setJITServerAOTDeserializer(deserializer);
deserializer = new (PERSISTENT_NEW) JITServerLocalSCCAOTDeserializer(persistentInfo->getPersistentClassLoaderTable());
}
else
{
fprintf(stderr, "Disabling JITServer AOT cache since AOT compilation and JITServerAOTCacheIgnoreLocalSCC are disabled\n");
persistentInfo->setJITServerUseAOTCache(false);
}

if (persistentInfo->getJITServerUseAOTCache() && !deserializer)
{
fprintf(stderr, "Could not create JITServer AOT deserializer\n");
return -1;
}
compInfo->setJITServerAOTDeserializer(deserializer);
}
#endif /* defined(J9VM_OPT_JITSERVER) */

Expand Down
15 changes: 7 additions & 8 deletions runtime/compiler/env/J9SharedCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,16 +1652,15 @@ TR_J9JITServerSharedCache::storeSharedData(J9VMThread *vmThread, const char *key
return std::get<0>(_stream->read<const void *>());
}

TR_J9DeserializerSharedCache::TR_J9DeserializerSharedCache(TR_J9VMBase *fe, JITServerNoSCCAOTDeserializer *deserializer)
: TR_J9SharedCache(fe)
TR_J9DeserializerSharedCache::TR_J9DeserializerSharedCache(TR_J9VMBase *fe, JITServerNoSCCAOTDeserializer *deserializer, TR::CompilationInfoPerThread *compInfoPT)
: TR_J9SharedCache(fe), _deserializer(deserializer), _compInfoPT(compInfoPT)
{
_deserializer = deserializer;
}

J9ROMClass *
TR_J9DeserializerSharedCache::romClassFromOffsetInSharedCache(uintptr_t offset)
{
TR::Compilation *comp = TR::compInfoPT->getCompilation();
TR::Compilation *comp = _compInfoPT->getCompilation();
bool wasReset = false;
auto romClass = _deserializer->romClassFromOffsetInSharedCache(offset, comp, wasReset);
if (wasReset)
Expand All @@ -1677,7 +1676,7 @@ TR_J9DeserializerSharedCache::romClassFromOffsetInSharedCache(uintptr_t offset)
void *
TR_J9DeserializerSharedCache::pointerFromOffsetInSharedCache(uintptr_t offset)
{
TR::Compilation *comp = TR::compInfoPT->getCompilation();
TR::Compilation *comp = _compInfoPT->getCompilation();
bool wasReset = false;
auto ptr = _deserializer->pointerFromOffsetInSharedCache(offset, comp, wasReset);
if (wasReset)
Expand Down Expand Up @@ -1707,7 +1706,7 @@ TR_J9DeserializerSharedCache::classMatchesCachedVersion(J9Class *clazz, UDATA *c
// that TR_J9SharedCache::validateClassChain() does, which is what TR_J9SharedCache::validateClassChain()
// uses to verify that the given clazz matches chainData. Thus we only have to check that that cached J9Class
// is equal to the one we are trying to validate.
TR::Compilation *comp = TR::compInfoPT->getCompilation();
TR::Compilation *comp = _compInfoPT->getCompilation();
bool wasReset = false;
auto ramClass = _deserializer->classFromOffset(chainData[1], comp, wasReset);
if (wasReset)
Expand All @@ -1727,7 +1726,7 @@ TR_J9DeserializerSharedCache::lookupClassFromChainAndLoader(uintptr_t *chainData
// a J9Class correspoding to the first class in the chain. If one could be found, it then verifies that the class matches the cached version.
// We do not need to perform that checking here, because during deserialization we will have already resolved the first class in the chain to
// a J9Class and verified that it matches. Thus we can simply return that cached first J9Class.
TR::Compilation *comp = TR::compInfoPT->getCompilation();
TR::Compilation *comp = _compInfoPT->getCompilation();
bool wasReset = false;
auto clazz = _deserializer->classFromOffset(chainData[1], comp, wasReset);
if (wasReset)
Expand All @@ -1743,7 +1742,7 @@ TR_J9DeserializerSharedCache::lookupClassFromChainAndLoader(uintptr_t *chainData
J9ROMMethod *
TR_J9DeserializerSharedCache::romMethodFromOffsetInSharedCache(uintptr_t offset)
{
TR::Compilation *comp = TR::compInfoPT->getCompilation();
TR::Compilation *comp = _compInfoPT->getCompilation();
bool wasReset = false;
auto romMethod = _deserializer->romMethodFromOffsetInSharedCache(offset, comp, wasReset);
if (wasReset)
Expand Down
3 changes: 2 additions & 1 deletion runtime/compiler/env/J9SharedCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ class TR_J9DeserializerSharedCache : public TR_J9SharedCache
public:
TR_ALLOC(TR_Memory::SharedCache)

TR_J9DeserializerSharedCache(TR_J9VMBase *fe, JITServerNoSCCAOTDeserializer *deserializer);
TR_J9DeserializerSharedCache(TR_J9VMBase *fe, JITServerNoSCCAOTDeserializer *deserializer, TR::CompilationInfoPerThread *compInfoPT);

virtual void *pointerFromOffsetInSharedCache(uintptr_t offset) override;
virtual void *lookupClassLoaderAssociatedWithClassChain(void *chainData) override;
Expand Down Expand Up @@ -766,6 +766,7 @@ class TR_J9DeserializerSharedCache : public TR_J9SharedCache

private:
JITServerNoSCCAOTDeserializer *_deserializer;
TR::CompilationInfoPerThread *_compInfoPT;
};

#endif /* defined(J9VM_OPT_JITSERVER) */
Expand Down
30 changes: 29 additions & 1 deletion runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,24 @@ TR_J9VMBase::get(J9JITConfig * jitConfig, J9VMThread * vmThread, VM_TYPE vmType)
if (vmWithoutThreadInfo->_compInfo)
{
TR::CompilationInfoPerThread *compInfoPT = vmWithoutThreadInfo->_compInfo->getCompInfoForThread(vmThread);
vmWithThreadInfo->_vmThreadIsCompilationThread = (compInfoPT ? TR_yes : TR_no);
vmWithThreadInfo->_compInfoPT = compInfoPT;
if (compInfoPT)
{
vmWithThreadInfo->_vmThreadIsCompilationThread = TR_yes;
#if defined(J9VM_OPT_JITSERVER)
auto deserializer = vmWithoutThreadInfo->_compInfo->getJITServerAOTDeserializer();
if (deserializer && vmWithoutThreadInfo->_compInfo->getPersistentInfo()->getJITServerAOTCacheIgnoreLocalSCC())
{
vmWithThreadInfo->_deserializerSharedCache =
new (vmWithoutThreadInfo->_compInfo->persistentMemory())
TR_J9DeserializerSharedCache(vmWithThreadInfo, (JITServerNoSCCAOTDeserializer *)deserializer, compInfoPT);
}
#endif /* defined(J9VM_OPT_JITSERVER) */
}
else
{
vmWithThreadInfo->_vmThreadIsCompilationThread = TR_no;
}
}
}
else
Expand Down Expand Up @@ -783,6 +799,9 @@ TR_J9VMBase::TR_J9VMBase(
_vmThreadIsCompilationThread(TR_maybe),
_compInfoPT(NULL),
_shouldSleep(false)
#if defined(J9VM_OPT_JITSERVER)
,_deserializerSharedCache(NULL)
#endif /* defined(J9VM_OPT_JITSERVER) */
{
for (int32_t i = 0; i < UT_MODULE_INFO.count; ++i)
if (UT_ACTIVE[i])
Expand Down Expand Up @@ -842,6 +861,15 @@ TR_J9VMBase::freeSharedCache()
jitPersistentFree(_sharedCache);
_sharedCache = NULL;
}

#if defined(J9VM_OPT_JITSERVER)
if (_deserializerSharedCache)
{
jitPersistentFree(_deserializerSharedCache);
_deserializerSharedCache = NULL;
}
#endif /* defined(J9VM_OPT_JITSERVER) */

}

TR::CompilationInfo * getCompilationInfo(J9JITConfig * jitConfig)
Expand Down
8 changes: 8 additions & 0 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,10 @@ class TR_J9VMBase : public TR_FrontEnd

TR_J9SharedCache * _sharedCache;

#if defined(J9VM_OPT_JITSERVER)
TR_J9DeserializerSharedCache *_deserializerSharedCache;
#endif /* defined(J9VM_OPT_JITSERVER) */

static int32_t * staticDFPHWAvailField;
static bool cachedStaticDFPAvailField;

Expand Down Expand Up @@ -1385,6 +1389,10 @@ class TR_J9VMBase : public TR_FrontEnd
virtual void freeSharedCache();
virtual void setSharedCache(TR_J9SharedCache *sharedCache) { _sharedCache = sharedCache; }

#if defined(J9VM_OPT_JITSERVER)
TR_J9DeserializerSharedCache *deserializerSharedCache() const { return _deserializerSharedCache; }
#endif /* defined(J9VM_OPT_JITSERVER) */

const char *getByteCodeName(uint8_t opcode);

virtual int32_t maxInternalPlusPinningArrayPointers(TR::Compilation* comp);
Expand Down

0 comments on commit d3d128a

Please sign in to comment.