Skip to content

Support ignoring the client's local SCC when compiling a JITServer AOT cache store #18937

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

Merged
merged 5 commits into from
Feb 14, 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
15 changes: 15 additions & 0 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ J9::AheadOfTimeCompile::offsetInSharedCacheFromPointer(TR_SharedCache *sharedCac
uintptr_t
J9::AheadOfTimeCompile::offsetInSharedCacheFromWellKnownClasses(TR_SharedCache *sharedCache, void *wellKnownClassesPtr)
{
#if defined(J9VM_OPT_JITSERVER)
TR::Compilation *comp = self()->comp();
ClientSessionData *clientData = comp->getClientData();
// This is a server compilation that is ignoring the client's SCC, so just return the
// idAndType of the cached AOT cache well-known classes serialization record.
if (clientData && clientData->useServerOffsets(comp->getStream()) && comp->isAOTCacheStore())
{
auto record = comp->getSymbolValidationManager()->aotCacheWellKnownClassesRecord();
if (record)
return record->data().idAndType();
else
comp->failCompilation<J9::ClassChainPersistenceFailure>("Failed to find cached well-known classes record in SVM");
}
#endif /* defined(J9VM_OPT_JITSERVER) */

return offsetInSharedCacheFromPointer(sharedCache, wellKnownClassesPtr);
}

Expand Down
27 changes: 25 additions & 2 deletions runtime/compiler/compile/J9Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "env/VMAccessCriticalSection.hpp"
#include "env/KnownObjectTable.hpp"
#include "env/VerboseLog.hpp"
#include "exceptions/PersistenceFailure.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "ilgen/IlGenRequest.hpp"
Expand Down Expand Up @@ -1579,9 +1580,22 @@ J9::Compilation::addSerializationRecord(const AOTCacheRecord *record, uintptr_t
{
TR_ASSERT_FATAL(_aotCacheStore, "Trying to add serialization record for compilation that is not an AOT cache store");
if (record)
{
_serializationRecords.push_back({ record, reloDataOffset });
}
else
_aotCacheStore = false;// Serialization failed; method won't be stored in AOT cache
{
ClientSessionData *clientData = getClientData();
bool useServerOffsets = clientData->useServerOffsets(getStream());
// If we're ignoring the client's SCC then this compilation must succeed as an AOT store, because
// this method must go through the client's deserializer before relocation.
// Otherwise, we can simply stop maintaining AOT cache records for this compilation and continue
// with the compilation without subsequently storing it in the AOT cache.
if (useServerOffsets)
failCompilation<J9::PersistenceFailure>("Serialization record at offset %zu must not be NULL", reloDataOffset);
else
_aotCacheStore = false;
}
}

void
Expand All @@ -1600,7 +1614,16 @@ J9::Compilation::addThunkRecord(const AOTCacheThunkRecord *record)
}
else
{
_aotCacheStore = false;// Serialization failed; method won't be stored in AOT cache
ClientSessionData *clientData = getClientData();
bool useServerOffsets = clientData->useServerOffsets(getStream());
// If we're ignoring the client's SCC then this compilation must succeed as an AOT store, because
// this method must go through the client's deserializer before relocation.
// Otherwise, we can simply stop maintaining AOT cache records for this compilation and continue
// with the compilation without subsequently storing it in the AOT cache.
if (useServerOffsets)
failCompilation<J9::PersistenceFailure>("Thunk record must not be NULL");
else
_aotCacheStore = false;
}
}
#endif /* defined(J9VM_OPT_JITSERVER) */
6 changes: 4 additions & 2 deletions runtime/compiler/compile/J9Compilation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,15 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
Vector<std::pair<const AOTCacheRecord *, uintptr_t>> &getSerializationRecords() { return _serializationRecords; }
// Adds an AOT cache record and the corresponding offset into AOT relocation data to the list that
// will be used when the result of this out-of-process compilation is serialized and stored in
// JITServer AOT cache. If record is NULL, fails serialization by setting _aotCacheStore to false.
// JITServer AOT cache. If record is NULL, fails serialization by setting _aotCacheStore to false if we are not
// ignoring the client's SCC, and otherwise fails the compilation entirely.
void addSerializationRecord(const AOTCacheRecord *record, uintptr_t reloDataOffset);

UnorderedSet<const AOTCacheThunkRecord *> &getThunkRecords() { return _thunkRecords; }
// Adds an AOT cache thunk record to the set of thunks that this compilation depends on, and also adds it
// to the list of records that this compilation depends on if the thunk record is new. If the record is NULL,
// fails serialization by setting _aotCacheStore to false.
// fails serialization by setting _aotCacheStore to false if we are not ignoring the client's SCC, and otherwise
// fails the compilation entirely.
void addThunkRecord(const AOTCacheThunkRecord *record);
#endif /* defined(J9VM_OPT_JITSERVER) */

Expand Down
24 changes: 15 additions & 9 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "control/CompilationThread.hpp"
#include "control/JITServerHelpers.hpp"
#include "control/MethodToBeCompiled.hpp"
#include "env/ClassLoaderTable.hpp"
#include "env/ClassTableCriticalSection.hpp"
#include "env/J2IThunk.hpp"
#include "env/j9methodServer.hpp"
Expand Down Expand Up @@ -533,6 +534,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
TR_RelocationRuntime::fillAOTHeader(javaVM, fe, &vmInfo._aotHeader);
}
}
vmInfo._useServerOffsets = false;
vmInfo._inSnapshotMode = fe->inSnapshotMode();
vmInfo._isPortableRestoreMode = fe->isPortableRestoreModeEnabled();
vmInfo._isSnapshotModeEnabled = fe->isSnapshotModeEnabled();
Expand Down Expand Up @@ -1904,7 +1906,8 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
// Collect AOT stats
TR_ResolvedJ9Method *resolvedMethod = std::get<0>(methodInfo).remoteMirror;

isRomClassForMethodInSC = fe->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(j9method));
if (fe->sharedCache())
isRomClassForMethodInSC = fe->sharedCache()->isClassInSharedCache(J9_CLASS_FROM_METHOD(j9method));

J9Class *j9clazz = (J9Class *) J9_CLASS_FROM_CP(((J9RAMConstantPoolItem *) J9_CP_FROM_METHOD(((J9Method *)j9method))));
TR_OpaqueClassBlock *clazzOfInlinedMethod = fe->convertClassPtrToClassOffset(j9clazz);
Expand Down Expand Up @@ -2134,27 +2137,30 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
bool getName = std::get<1>(recv);
auto sharedCache = fe->sharedCache();
uintptr_t *chain = NULL;
uintptr_t offset = sharedCache->getClassChainOffsetIdentifyingLoader(j9class, &chain);
uintptr_t offset = sharedCache ? sharedCache->getClassChainOffsetIdentifyingLoader(j9class, &chain) : TR_SharedCache::INVALID_CLASS_CHAIN_OFFSET;
std::string nameStr;
if (getName && chain)
if (getName)
{
const J9UTF8 *name = J9ROMCLASS_CLASSNAME(sharedCache->startingROMClassOfClassChain(chain));
nameStr = std::string((const char *)J9UTF8_DATA(name), J9UTF8_LENGTH(name));
// We need to get the name even if chain lookup failed (perhaps due to a non-existent local SCC)
auto name = fe->getPersistentInfo()->getPersistentClassLoaderTable()->lookupClassNameAssociatedWithClassLoader(fe->getClassLoader(j9class));
if (name)
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, bool>();
auto recv = client->getRecvData<J9Class *, bool, bool, bool>();
auto clazz = std::get<0>(recv);
bool create = std::get<1>(recv);
bool getClasses = std::get<2>(recv);
uintptr_t classChainOffset = fe->sharedCache()->rememberClass(clazz, NULL, create);
bool needClientOffset = std::get<2>(recv);
bool getClasses = std::get<3>(recv);
uintptr_t classChainOffset = needClientOffset ? fe->sharedCache()->rememberClass(clazz, NULL, create) : TR_SharedCache::INVALID_CLASS_CHAIN_OFFSET;
std::vector<J9Class *> ramClassChain;
std::vector<J9Class *> uncachedRAMClasses;
std::vector<JITServerHelpers::ClassInfoTuple> uncachedClassInfos;
if (create && getClasses && (TR_SharedCache::INVALID_CLASS_CHAIN_OFFSET != classChainOffset))
if (create && getClasses)
{
// The first word of the class chain data stores the size of the whole record in bytes, so the number of classes
// is 1 less than the necessary class chain length.
Expand Down
4 changes: 4 additions & 0 deletions runtime/compiler/control/JITServerCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,14 @@ TR::CompilationInfoPerThreadRemote::processEntry(TR_MethodToBeCompiled &entry, J
}

if (_vm->sharedCache())
{
// Set/update stream pointer in shared cache.
// Note that if remote-AOT is enabled, even regular J9_SERVER_VM will have a shared cache
// This behaviour is consistent with non-JITServer
((TR_J9JITServerSharedCache *) _vm->sharedCache())->setStream(stream);
// Also cache this compilation thread
((TR_J9JITServerSharedCache *) _vm->sharedCache())->setCompInfoPT(this);
}

//if (seqNo == 501)
// throw JITServer::StreamFailure(); // stress testing
Expand Down
11 changes: 8 additions & 3 deletions runtime/compiler/control/JITServerHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "control/CompilationRuntime.hpp"
#include "control/JITServerCompilationThread.hpp"
#include "control/MethodToBeCompiled.hpp"
#include "env/ClassLoaderTable.hpp"
#include "env/StackMemoryRegion.hpp"
#include "infra/CriticalSection.hpp"
#include "infra/Statistics.hpp"
Expand Down Expand Up @@ -1013,10 +1014,14 @@ JITServerHelpers::packRemoteROMClassInfo(J9Class *clazz, J9VMThread *vmThread, T
sharedCache->getClassChainOffsetIdentifyingLoaderNoFail((TR_OpaqueClassBlock *)clazz, &classChainIdentifyingLoader) : 0;

std::string classNameIdentifyingLoader;
if (fe->getPersistentInfo()->getJITServerUseAOTCache() && classChainIdentifyingLoader)
if (fe->getPersistentInfo()->getJITServerUseAOTCache())
{
const J9UTF8 *name = J9ROMCLASS_CLASSNAME(sharedCache->startingROMClassOfClassChain(classChainIdentifyingLoader));
classNameIdentifyingLoader = std::string((const char *)J9UTF8_DATA(name), J9UTF8_LENGTH(name));
auto loader = fe->getClassLoader((TR_OpaqueClassBlock *)clazz);
auto nameInfo = fe->getPersistentInfo()->getPersistentClassLoaderTable()->lookupClassNameAssociatedWithClassLoader(loader);
if (nameInfo)
{
classNameIdentifyingLoader = std::string((const char *)J9UTF8_DATA(nameInfo), J9UTF8_LENGTH(nameInfo));
}
}

std::string packedROMClassStr;
Expand Down
Loading