Skip to content
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
12 changes: 10 additions & 2 deletions runtime/compiler/compile/Compilation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class OMR_EXTENSIBLE Compilation : public J9::CompilationConnector
TR_Memory *memory,
TR_OptimizationPlan *optimizationPlan,
TR_RelocationRuntime *reloRuntime,
TR::Environment *target = NULL) :
TR::Environment *target
#if defined(J9VM_OPT_JITSERVER)
, size_t numPermanentLoaders
#endif
) :
J9::CompilationConnector(
compThreadId,
j9vmThread,
Expand All @@ -62,7 +66,11 @@ class OMR_EXTENSIBLE Compilation : public J9::CompilationConnector
memory,
optimizationPlan,
reloRuntime,
target)
target
#if defined(J9VM_OPT_JITSERVER)
, numPermanentLoaders
#endif
)
{}

~Compilation() {}
Expand Down
13 changes: 11 additions & 2 deletions runtime/compiler/compile/J9Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ J9::Compilation::Compilation(int32_t id,
TR_Memory *m,
TR_OptimizationPlan *optimizationPlan,
TR_RelocationRuntime *reloRuntime,
TR::Environment *target)
TR::Environment *target
#if defined(J9VM_OPT_JITSERVER)
, size_t numPermanentLoaders
#endif
)
: OMR::CompilationConnector(
id,
j9vmThread->omrVMThread,
Expand Down Expand Up @@ -208,6 +212,7 @@ J9::Compilation::Compilation(int32_t id,
_ignoringLocalSCC(false),
_serializationRecords(decltype(_serializationRecords)::allocator_type(heapMemoryRegion)),
_thunkRecords(decltype(_thunkRecords)::allocator_type(heapMemoryRegion)),
_numPermanentLoaders(numPermanentLoaders),
#endif /* defined(J9VM_OPT_JITSERVER) */
#if !defined(PERSISTENT_COLLECTIONS_UNSUPPORTED)
_aotMethodDependencies(decltype(_aotMethodDependencies)::allocator_type(heapMemoryRegion)),
Expand Down Expand Up @@ -1612,8 +1617,12 @@ J9::Compilation::permanentLoaders()
#if defined(J9VM_OPT_JITSERVER)
if (self()->isOutOfProcessCompilation())
{
TR_ASSERT_FATAL(
_numPermanentLoaders != SIZE_MAX, "missing _numPermanentLoaders");

ClientSessionData *clientData = self()->getClientData();
clientData->getPermanentLoaders(_permanentLoaders);
clientData->getPermanentLoaders(
_permanentLoaders, _numPermanentLoaders, getStream());
}
else
#endif
Expand Down
9 changes: 8 additions & 1 deletion runtime/compiler/compile/J9Compilation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
TR_Memory *,
TR_OptimizationPlan *optimizationPlan,
TR_RelocationRuntime *reloRuntime,
TR::Environment *target = NULL);
TR::Environment *target
#if defined(J9VM_OPT_JITSERVER)
, size_t numPermanentLoaders
#endif
);

~Compilation();

Expand Down Expand Up @@ -629,6 +633,9 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
Vector<std::pair<const AOTCacheRecord *, uintptr_t>> _serializationRecords;
// Set of AOT cache thunk records that this compilation depends on; always empty at the client
UnorderedSet<const AOTCacheThunkRecord *> _thunkRecords;
// For the server, the number of permanent loaders the client has specified
// we must use for this compilation.
size_t _numPermanentLoaders;
#endif /* defined(J9VM_OPT_JITSERVER) */

#if !defined(PERSISTENT_COLLECTIONS_UNSUPPORTED)
Expand Down
9 changes: 8 additions & 1 deletion runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8375,6 +8375,9 @@ TR::CompilationInfoPerThreadBase::compile(J9VMThread * vmThread,
trMemory,
TR::CompileIlGenRequest(entry->getMethodDetails()),
entry->_checkpointInProgress
#if defined(J9VM_OPT_JITSERVER)
, entry->_numPermanentLoaders
#endif
);
if (TR::Options::getVerboseOption(TR_VerboseCompilationDispatch))
TR_VerboseLog::writeLineLocked(TR_Vlog_DISPATCH,
Expand Down Expand Up @@ -9254,7 +9257,11 @@ TR::CompilationInfoPerThreadBase::wrappedCompile(J9PortLibrary *portLib, void *
p->trMemory(),
p->_optimizationPlan,
reloRuntime,
&target);
&target
#if defined(J9VM_OPT_JITSERVER)
, p->_numPermanentLoaders
#endif
);

#if defined(J9VM_OPT_JITSERVER)
// JITServer TODO: put info in optPlan so that compilation constructor can do this
Expand Down
10 changes: 10 additions & 0 deletions runtime/compiler/control/CompilationThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ struct CompileParameters
TR_Memory &trMemory,
const TR::CompileIlGenRequest &ilGenRequest,
bool checkpointInProgress
#if defined(J9VM_OPT_JITSERVER)
, size_t numPermanentLoaders
#endif
) :
_compilationInfo(compilationInfo),
_vm(vm),
Expand All @@ -114,6 +117,9 @@ struct CompileParameters
_trMemory(trMemory),
_ilGenRequest(ilGenRequest),
_checkpointInProgress(checkpointInProgress)
#if defined(J9VM_OPT_JITSERVER)
, _numPermanentLoaders(numPermanentLoaders)
#endif
{}

TR_Memory *trMemory() { return &_trMemory; }
Expand All @@ -128,6 +134,10 @@ struct CompileParameters
TR_Memory &_trMemory;
TR::CompileIlGenRequest _ilGenRequest;
bool _checkpointInProgress;

#if defined(J9VM_OPT_JITSERVER)
size_t _numPermanentLoaders;
#endif
};

#if defined(TR_HOST_S390)
Expand Down
66 changes: 38 additions & 28 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
// Do not forbid AOT cache stores or loads (this server might be able to fulfill them)
compInfo->getPersistentInfo()->setDoNotRequestJITServerAOTCacheLoad(false);
compInfo->getPersistentInfo()->setDoNotRequestJITServerAOTCacheStore(false);

auto loaderTable = compInfo->getPersistentInfo()->getPersistentClassLoaderTable();
OMR::CriticalSection lock(compInfo->getSequencingMonitor());
loaderTable->resetPermanentLoadersSentToServer(compInfo);
}

client->write(response, ranges, unloadedClasses->getMaxRanges(), serializedCHTable, dltedMethods);
Expand All @@ -298,6 +294,21 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
}
}
break;
case MessageType::ClientSessionData_getPermanentLoaders:
{
auto recv = client->getRecvData<size_t>();
size_t serverCount = std::get<0>(recv);
auto permanentLoaders = comp->permanentLoaders();
std::vector<J9ClassLoader*> newPermanentLoaders;
newPermanentLoaders.reserve(permanentLoaders.size() - serverCount);
newPermanentLoaders.insert(
newPermanentLoaders.end(),
permanentLoaders.begin() + serverCount,
permanentLoaders.end());

client->write(response, newPermanentLoaders);
}
break;
case MessageType::VM_isClassLibraryMethod:
{
auto tup = client->getRecvData<TR_OpaqueMethodBlock*, bool>();
Expand Down Expand Up @@ -3454,11 +3465,9 @@ remoteCompile(J9VMThread *vmThread, TR::Compilation *compiler, TR_ResolvedMethod
std::vector<uintptr_t> newKnownIds = deserializer ? deserializer->getNewKnownIds(context) : std::vector<uintptr_t>();

auto chTable = (JITClientPersistentCHTable *)persistentInfo->getPersistentCHTable();
auto permanentLoaders = compiler->permanentLoaders();
std::vector<TR_OpaqueClassBlock *> unloadedClasses;
std::vector<TR_OpaqueClassBlock *> illegalModificationList;
std::pair<std::string, std::string> chtableUpdates("", "");
std::vector<J9ClassLoader *> newPermanentLoaders; // doesn't affect critical seq. no.
uint32_t seqNo = 0;
uint32_t lastCriticalSeqNo = 0;

Expand Down Expand Up @@ -3495,29 +3504,30 @@ remoteCompile(J9VMThread *vmThread, TR::Compilation *compiler, TR_ResolvedMethod
{
compInfo->setLastCriticalSeqNo(seqNo);
}

// Determine which permanent loaders (if any) to send to the server.
auto loaderTable = persistentInfo->getPersistentClassLoaderTable();
size_t numPermanentLoadersSent =
loaderTable->numPermanentLoadersSentToServer(compInfo);

// It's possible to have numPermanentLoadersSent > permanentLoaders.size()
// in some interleavings. Only send loaders if our permanentLoaders contains
// entries that haven't been sent yet. This also prevents the subtraction
// from overflowing.
if (numPermanentLoadersSent < permanentLoaders.size())
{
size_t n = permanentLoaders.size() - numPermanentLoadersSent;
newPermanentLoaders.reserve(n);
newPermanentLoaders.insert(
newPermanentLoaders.end(),
permanentLoaders.begin() + numPermanentLoadersSent,
permanentLoaders.end());

loaderTable->addPermanentLoadersSentToServer(n, compInfo);
}
}

// Determine the loaders to consider permanent for this compilation. From
// this point on, they are fixed.
//
// There will be at least two data structures that are sensitive to the
// set of permanent loaders. These could potentially allow the precise set
// of permanent loaders to vary between the client and server, but the
// reasoning needed to determine whether certain kinds of variation are
// allowed gets hairy very quickly. It's much simpler if there is only one
// set of permanent loaders that will be used for all purposes on both the
// client and the server.
//
// To ensure that for this compilation the server will use exactly the
// permanent loaders determined here, it suffices to tell the server how
// many there are, let's call it n. The server will know that this
// compilation is using the first n permanent loaders for this client. If it
// doesn't yet have all of the first n, then it will send a message to
// request the ones it's missing, and the response will preserve the
// ordering so that the first n on the server are the same as the first n on
// the client.
//
size_t numPermanentLoaders = compiler->permanentLoaders().size();

uint32_t statusCode = compilationFailure;
std::string codeCacheStr;
std::string dataCacheStr;
Expand Down Expand Up @@ -3549,7 +3559,7 @@ remoteCompile(J9VMThread *vmThread, TR::Compilation *compiler, TR_ResolvedMethod
detailsStr, details.getType(), unloadedClasses, illegalModificationList, classInfoTuple, optionsStr,
recompMethodInfoStr, chtableUpdates.first, chtableUpdates.second, useAotCompilation,
TR::Compiler->vm.isVMInStartupPhase(compInfoPT->getJitConfig()), aotCacheStore, aotCacheLoad, methodIndex,
classChainOffset, ramClassChain, uncachedRAMClasses, uncachedClassInfos, newKnownIds, newPermanentLoaders
classChainOffset, ramClassChain, uncachedRAMClasses, uncachedClassInfos, newKnownIds, numPermanentLoaders
);

JITServer::MessageType response;
Expand Down
5 changes: 2 additions & 3 deletions runtime/compiler/control/JITServerCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ TR::CompilationInfoPerThreadRemote::processCompilationRequest(CompilationRequest
auto &uncachedRAMClasses = std::get<22>(req);
auto &uncachedClassInfos = std::get<23>(req);
auto &newKnownIds = std::get<24>(req);
auto &newPermanentLoaders = std::get<25>(req);
size_t numPermanentLoaders = std::get<25>(req);

TR_ASSERT_FATAL(TR::Compiler->persistentMemory() == compInfo->persistentMemory(),
"per-client persistent memory must not be set at this point");
Expand Down Expand Up @@ -669,8 +669,6 @@ TR::CompilationInfoPerThreadRemote::processCompilationRequest(CompilationRequest
clientSession->getAOTCacheKnownIds().insert(newKnownIds.begin(), newKnownIds.end());
}

clientSession->addPermanentLoaders(newPermanentLoaders);

// We must process unloaded classes lists in the same order they were generated at the client
// Use a sequencing scheme to re-order compilation requests
//
Expand Down Expand Up @@ -909,6 +907,7 @@ TR::CompilationInfoPerThreadRemote::processCompilationRequest(CompilationRequest
// If we want something then we need to increaseQueueWeightBy(weight) while holding compilation monitor
entry._weight = 0;
entry._jitStateWhenQueued = compInfo->getPersistentInfo()->getJitState();
entry._numPermanentLoaders = numPermanentLoaders;
entry._stream = stream; // Add the stream to the entry

auto aotCache = clientSession->getOrCreateAOTCache(stream);
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/control/JITServerCompilationThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using CompilationRequest = std::tuple<
J9::IlGeneratorMethodDetailsType, std::vector<TR_OpaqueClassBlock *>, std::vector<TR_OpaqueClassBlock *>,
JITServerHelpers::ClassInfoTuple, std::string, std::string, std::string, std::string,
bool, bool, bool, bool, uint32_t, uintptr_t, std::vector<J9Class *>, std::vector<J9Class *>,
std::vector<JITServerHelpers::ClassInfoTuple>, std::vector<uintptr_t>, std::vector<J9ClassLoader *>
std::vector<JITServerHelpers::ClassInfoTuple>, std::vector<uintptr_t>, size_t
>;

void outOfProcessCompilationEnd(TR_MethodToBeCompiled *entry, TR::Compilation *comp);
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/control/MethodToBeCompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void TR_MethodToBeCompiled::initialize(TR::IlGeneratorMethodDetails &details, vo
_doNotLoadFromJITServerAOTCache = false;
_useAOTCacheCompilation = false;
_origOptLevel = unknownHotness;
_numPermanentLoaders = SIZE_MAX;
_stream = NULL;
#endif /* defined(J9VM_OPT_JITSERVER) */

Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/control/MethodToBeCompiled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ struct TR_MethodToBeCompiled
bool _useAOTCacheCompilation;
// Cache original optLevel when transforming a remote sync compilation to a local cheap one
TR_Hotness _origOptLevel;
// On the server, the number of permanent loaders specified by the client for this compilation.
size_t _numPermanentLoaders;
// A non-NULL field denotes an out-of-process compilation request
JITServer::ServerStream *_stream;
#endif /* defined(J9VM_OPT_JITSERVER) */
Expand Down
37 changes: 0 additions & 37 deletions runtime/compiler/env/ClassLoaderTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,40 +508,3 @@ TR_PersistentClassLoaderTable::getPermanentLoaders(

jitReleaseClassTableMutex(vmThread);
}

#if defined(J9VM_OPT_JITSERVER)

size_t
TR_PersistentClassLoaderTable::numPermanentLoadersSentToServer(
TR::CompilationInfo *compInfo) const
{
assertSequencingMonitorHeld(compInfo);
return _numPermanentLoadersSentToServer;
}

void
TR_PersistentClassLoaderTable::addPermanentLoadersSentToServer(
size_t n, TR::CompilationInfo *compInfo)
{
assertSequencingMonitorHeld(compInfo);
_numPermanentLoadersSentToServer += n;
}

void
TR_PersistentClassLoaderTable::resetPermanentLoadersSentToServer(
TR::CompilationInfo *compInfo)
{
assertSequencingMonitorHeld(compInfo);
_numPermanentLoadersSentToServer = 0;
}

void
TR_PersistentClassLoaderTable::assertSequencingMonitorHeld(
TR::CompilationInfo *compInfo) const
{
TR_ASSERT_FATAL(
compInfo->getSequencingMonitor()->owned_by_self(),
"caller must hold the sequencing monitor");
}

#endif // defined(J9VM_OPT_JITSERVER)
47 changes: 0 additions & 47 deletions runtime/compiler/env/ClassLoaderTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,51 +78,8 @@ class TR_PersistentClassLoaderTable
void getPermanentLoaders(
J9VMThread *vmThread, TR::vector<J9ClassLoader*, TR::Region&> &dest) const;

#if defined(J9VM_OPT_JITSERVER)
/**
* \brief Get the number of permanent loaders that have been sent to the server.
*
* Loaders are expected to be sent in the order in which they were added.
*
* The caller must hold the sequencing monitor.
*
* \param compInfo the compilation info object
* \return the number of loaders
*/
size_t numPermanentLoadersSentToServer(TR::CompilationInfo *compInfo) const;

/**
* \brief Add \p n to the number of permanent loaders sent to the server.
*
* The caller commits to send the next \p n loaders beyond those that were
* previously sent.
*
* The caller must hold the sequencing monitor.
*
* \param n the number of newly sent permanent loaders
* \param compInfo the compilation info object
*/
void addPermanentLoadersSentToServer(size_t n, TR::CompilationInfo *compInfo);

/**
* \brief Reset the number of permanent loaders sent to the server to zero.
*
* This will cause a future compilation to send the loaders again, which is
* useful after connecting to a new server.
*
* The caller must hold the sequencing monitor.
*
* \param compInfo the compilation info object
*/
void resetPermanentLoadersSentToServer(TR::CompilationInfo *compInfo);
#endif

private:

#if defined(J9VM_OPT_JITSERVER)
void assertSequencingMonitorHeld(TR::CompilationInfo *compInfo) const;
#endif

friend class TR_Debug;

TR_PersistentMemory *const _persistentMemory;
Expand All @@ -132,10 +89,6 @@ class TR_PersistentClassLoaderTable
typedef std::vector<J9ClassLoader*, ClassLoaderPtrAlloc> ClassLoaderPtrVec;
ClassLoaderPtrVec _permanentLoaders; // protected by the class table mutex

#if defined(J9VM_OPT_JITSERVER)
size_t _numPermanentLoadersSentToServer; // protected by the sequencing monitor
#endif

TR_ClassLoaderInfo *_loaderTable[CLASSLOADERTABLE_SIZE];
TR_ClassLoaderInfo *_chainTable[CLASSLOADERTABLE_SIZE];
#if defined(J9VM_OPT_JITSERVER)
Expand Down
Loading