Skip to content

Commit 747f86c

Browse files
authored
Merge pull request #19166 from cjjdespres/0.44-handle-cache-unavailability
(0.44) Enable per-connection JITServer AOT cache disabling
2 parents 69b8c29 + 7ff3c83 commit 747f86c

File tree

7 files changed

+88
-12
lines changed

7 files changed

+88
-12
lines changed

runtime/compiler/control/CompilationThread.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7940,6 +7940,7 @@ TR::CompilationInfoPerThreadBase::preCompilationTasks(J9VMThread * vmThread,
79407940
&& persistentInfo->getJITServerUseAOTCache() // Ideally we would check if the options allow us to use the AOT cache for this method
79417941
&& persistentInfo->getJITServerAOTCacheIgnoreLocalSCC() // Need to be using the new implementation
79427942
&& !entry->_doNotLoadFromJITServerAOTCache
7943+
&& !persistentInfo->doNotRequestJITServerAOTCacheStore()
79437944
&& !_compInfo.getLowCompDensityMode() // AOT req is sent to JITServer and we don't want to send JITServer any messages in this mode
79447945
&& !cannotDoRemoteCompilation; // Make sure remote compilations are possible (no strong guarantees)
79457946
#endif /* defined(J9VM_OPT_JITSERVER) */

runtime/compiler/control/JITClientCompilationThread.cpp

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
190190
if ((response != MessageType::compilationCode) &&
191191
(response != MessageType::compilationFailure) &&
192192
(response != MessageType::AOTCache_serializedAOTMethod) &&
193-
(response != MessageType::AOTCache_storedAOTMethod))
193+
(response != MessageType::AOTCache_storedAOTMethod) &&
194+
(response != MessageType::AOTCache_failure))
194195
client->writeError(JITServer::MessageType::compilationInterrupted, 0 /* placeholder */);
195196

196197
if (TR::Options::isAnyVerboseOptionSet(TR_VerboseJITServer, TR_VerboseCompilationDispatch))
@@ -210,6 +211,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
210211
case MessageType::compilationFailure:
211212
case MessageType::AOTCache_storedAOTMethod:
212213
case MessageType::AOTCache_serializedAOTMethod:
214+
case MessageType::AOTCache_failure:
213215
case MessageType::compilationThreadCrashed:
214216
done = true;
215217
break;
@@ -224,7 +226,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
224226
{
225227
uint64_t serverUID = std::get<0>(client->getRecvData<uint64_t>());
226228
uint64_t previousUID = compInfo->getPersistentInfo()->getServerUID();
229+
bool hasEverConnectedToServer = compInfo->getPersistentInfo()->hasEverConnectedToServer();
227230
compInfo->getPersistentInfo()->setServerUID(serverUID);
231+
compInfo->getPersistentInfo()->setHasEverConnectedToServer();
228232

229233
auto unloadedClasses = comp->getPersistentInfo()->getUnloadedClassAddresses();
230234
std::vector<TR_AddressRange> ranges;
@@ -242,11 +246,18 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
242246
compInfo->getclassesCachedAtServer().clear();
243247
}
244248

245-
auto deserializer = compInfo->getJITServerAOTDeserializer();
246-
// Reset AOT deserializer if connected to a new server (cached serialization records are now invalid),
247-
// except if this is the first server this client has connected to.
248-
if (deserializer && (0 != previousUID) && (previousUID != serverUID))
249-
deserializer->reset(compInfoPT);
249+
// This is a connection to a new server after a previous disconnection
250+
if (hasEverConnectedToServer && (previousUID != serverUID))
251+
{
252+
// Reset AOT deserializer (cached serialization records are now invalid)
253+
auto deserializer = compInfo->getJITServerAOTDeserializer();
254+
if (deserializer)
255+
deserializer->reset(compInfoPT);
256+
257+
// Do not forbid AOT cache stores or loads (this server might be able to fulfill them)
258+
compInfo->getPersistentInfo()->setDoNotRequestJITServerAOTCacheLoad(false);
259+
compInfo->getPersistentInfo()->setDoNotRequestJITServerAOTCacheStore(false);
260+
}
250261

251262
client->write(response, ranges, unloadedClasses->getMaxRanges(), serializedCHTable);
252263

@@ -3123,6 +3134,7 @@ remoteCompile(J9VMThread *vmThread, TR::Compilation *compiler, TR_ResolvedMethod
31233134
aotCacheStore = entry->_useAOTCacheCompilation &&
31243135
compInfo->methodCanBeJITServerAOTCacheStored(compiler->signature(), compilee->convertToMethod()->methodType());
31253136
aotCacheLoad = persistentInfo->getJITServerUseAOTCache() &&
3137+
!persistentInfo->doNotRequestJITServerAOTCacheLoad() &&
31263138
!TR::CompilationInfo::isCompiled(method) &&
31273139
!entry->_doNotLoadFromJITServerAOTCache &&
31283140
compInfo->methodCanBeJITServerAOTCacheLoaded(compiler->signature(), compilee->convertToMethod()->methodType());
@@ -3502,6 +3514,36 @@ remoteCompile(J9VMThread *vmThread, TR::Compilation *compiler, TR_ResolvedMethod
35023514
entry->_compErrCode = compilationFailure;
35033515
compiler->failCompilation<JITServer::ServerCompilationFailure>("JITServer compilation thread has crashed.");
35043516
}
3517+
else if (JITServer::MessageType::AOTCache_failure == response)
3518+
{
3519+
auto recv = client->getRecvData<bool, bool>();
3520+
bool aotCacheUnavailable = std::get<0>(recv);
3521+
bool aotCacheStoreUnavailable = std::get<1>(recv);
3522+
3523+
auto persistentInfo = compInfo->getPersistentInfo();
3524+
if (aotCacheUnavailable)
3525+
{
3526+
persistentInfo->setDoNotRequestJITServerAOTCacheLoad(true);
3527+
persistentInfo->setDoNotRequestJITServerAOTCacheStore(true);
3528+
if (TR::Options::getVerboseOption(TR_VerboseJITServer))
3529+
TR_VerboseLog::writeLineLocked(TR_Vlog_JITServer,
3530+
"Server AOT cache unavailable (serverUID=%llu). Disabling future AOT cache requests for this server.",
3531+
(unsigned long long)persistentInfo->getServerUID());
3532+
}
3533+
else if (aotCacheStoreUnavailable)
3534+
{
3535+
persistentInfo->setDoNotRequestJITServerAOTCacheStore(true);
3536+
if (TR::Options::getVerboseOption(TR_VerboseJITServer))
3537+
TR_VerboseLog::writeLineLocked(TR_Vlog_JITServer,
3538+
"Cannot store methods in server AOT cache (serverUID=%llu). Disabling future AOT cache store requests for this server.",
3539+
(unsigned long long)persistentInfo->getServerUID());
3540+
}
3541+
entry->_compErrCode = compilationFailure;
3542+
entry->_doNotLoadFromJITServerAOTCache = true;
3543+
if (entry->_compilationAttemptsLeft > 0)
3544+
entry->_tryCompilingAgain = true;
3545+
compiler->failCompilation<JITServer::ServerCompilationFailure>("JITServer compilation failed.");
3546+
}
35053547
else
35063548
{
35073549
TR_ASSERT(JITServer::MessageType::compilationFailure == response,

runtime/compiler/control/JITServerCompilationThread.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ TR::CompilationInfoPerThreadRemote::processEntry(TR_MethodToBeCompiled &entry, J
640640
auto &chtableMods = std::get<14>(req);
641641
useAotCompilation = std::get<15>(req);
642642
bool isInStartupPhase = std::get<16>(req);
643-
bool aotCacheStore = std::get<17>(req);
644-
bool aotCacheLoad = std::get<18>(req);
643+
bool requestedAOTCacheStore = std::get<17>(req);
644+
bool requestedAOTCacheLoad = std::get<18>(req);
645645
_methodIndex = std::get<19>(req);
646646
uintptr_t classChainOffset = std::get<20>(req);
647647
auto &ramClassChain = std::get<21>(req);
@@ -950,8 +950,8 @@ TR::CompilationInfoPerThreadRemote::processEntry(TR_MethodToBeCompiled &entry, J
950950
entry._stream = stream; // Add the stream to the entry
951951

952952
auto aotCache = clientSession->getOrCreateAOTCache(stream);
953-
_aotCacheStore = aotCacheStore && aotCache && JITServerAOTCacheMap::cacheHasSpace();
954-
aotCacheLoad = aotCacheLoad && aotCache;
953+
_aotCacheStore = requestedAOTCacheStore && aotCache && JITServerAOTCacheMap::cacheHasSpace();
954+
bool aotCacheLoad = requestedAOTCacheLoad && aotCache;
955955
if (aotCache && !aotCacheLoad)
956956
aotCache->incNumCacheBypasses();
957957

@@ -981,6 +981,23 @@ TR::CompilationInfoPerThreadRemote::processEntry(TR_MethodToBeCompiled &entry, J
981981

982982
if (aotCacheLoad)
983983
aotCacheHit = serveCachedAOTMethod(entry, ramMethod, clazz, &clientOptPlan, clientSession, scratchSegmentProvider);
984+
985+
// If the client requests that the server use AOT cache offsets during AOT cache compilations, then
986+
// the client will be ignoring its local SCC (if it even exists) for the duration of the compilation.
987+
// This means that if the client requests an AOT cache store in that scenario and the server
988+
// cannot fulfill that request, the server must abort the compilation.
989+
// If the client isn't requesting server offsets, then the compilation can still continue, albeit as
990+
// a regular AOT compilation.
991+
if (clientSession->useServerOffsets(stream) &&
992+
requestedAOTCacheStore &&
993+
!aotCacheHit &&
994+
!_aotCacheStore)
995+
{
996+
abortCompilation = true;
997+
bool aotCacheUnavailable = !aotCache;
998+
bool aotCacheStoreUnavailable = aotCacheUnavailable || !JITServerAOTCacheMap::cacheHasSpace();
999+
stream->write(JITServer::MessageType::AOTCache_failure, aotCacheUnavailable, aotCacheStoreUnavailable);
1000+
}
9841001
}
9851002
catch (const JITServer::StreamFailure &e)
9861003
{

runtime/compiler/env/J9PersistentInfo.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class PersistentInfo : public OMR::PersistentInfoConnector
165165
_socketTimeoutMs(0),
166166
_clientUID(0),
167167
_serverUID(0),
168+
_hasEverConnectedToServer(false),
168169
_JITServerMetricsPort(38500),
169170
_JITServerHealthPort(38600),
170171
_requireJITServer(false),
@@ -175,6 +176,8 @@ class PersistentInfo : public OMR::PersistentInfoConnector
175176
_JITServerAOTCacheDir(),
176177
_JITServerAOTCacheDelayMethodRelocation(false),
177178
_JITServerAOTCacheIgnoreLocalSCC(false),
179+
_doNotRequestJITServerAOTCacheLoad(false),
180+
_doNotRequestJITServerAOTCacheStore(false),
178181
#endif /* defined(J9VM_OPT_JITSERVER) */
179182
OMR::PersistentInfoConnector(pm)
180183
{}
@@ -353,6 +356,8 @@ class PersistentInfo : public OMR::PersistentInfoConnector
353356
void setClientUID(uint64_t val) { _clientUID = val; }
354357
uint64_t getServerUID() const { return _serverUID; }
355358
void setServerUID(uint64_t val) { _serverUID = val; }
359+
bool hasEverConnectedToServer() const { return _hasEverConnectedToServer; }
360+
void setHasEverConnectedToServer() { _hasEverConnectedToServer = true; }
356361
uint32_t getJITServerMetricsPort() const { return _JITServerMetricsPort; }
357362
void setJITServerMetricsPort(uint32_t port) { _JITServerMetricsPort = port; }
358363
uint32_t getJITServerHealthPort() const { return _JITServerHealthPort; }
@@ -373,6 +378,10 @@ class PersistentInfo : public OMR::PersistentInfoConnector
373378
void setJITServerAOTCacheDelayMethodRelocation(bool b) { _JITServerAOTCacheDelayMethodRelocation = b; }
374379
bool getJITServerAOTCacheIgnoreLocalSCC() const { return _JITServerAOTCacheIgnoreLocalSCC; }
375380
void setJITServerAOTCacheIgnoreLocalSCC(bool b) { _JITServerAOTCacheIgnoreLocalSCC = b; }
381+
bool doNotRequestJITServerAOTCacheLoad() const { return _doNotRequestJITServerAOTCacheLoad; }
382+
void setDoNotRequestJITServerAOTCacheLoad(bool b) { _doNotRequestJITServerAOTCacheLoad = b; }
383+
bool doNotRequestJITServerAOTCacheStore() const { return _doNotRequestJITServerAOTCacheStore; }
384+
void setDoNotRequestJITServerAOTCacheStore(bool b) { _doNotRequestJITServerAOTCacheStore = b; }
376385
#endif /* defined(J9VM_OPT_JITSERVER) */
377386

378387
private:
@@ -463,6 +472,7 @@ class PersistentInfo : public OMR::PersistentInfoConnector
463472
uint32_t _socketTimeoutMs; // timeout for communication sockets used in out-of-process JIT compilation
464473
uint64_t _clientUID;
465474
uint64_t _serverUID; // At the client, this represents the UID of the server the client is connected to
475+
bool _hasEverConnectedToServer; // At the client, true if the client has connected to a server at some point in the past
466476
uint32_t _JITServerMetricsPort; // Port for receiving http metrics requests from Prometheus; only used at server
467477
uint32_t _JITServerHealthPort; // Port for receiving readiness/liveness probes from Kubernetes; only used at server
468478
bool _requireJITServer;
@@ -472,8 +482,12 @@ class PersistentInfo : public OMR::PersistentInfoConnector
472482
bool _JITServerUseAOTCachePersistence; // Whether to persist the JITServer AOT caches at the server
473483
std::string _JITServerAOTCacheDir; // Directory where the JITServer persistent AOT caches are located
474484
bool _JITServerAOTCacheDelayMethodRelocation; // At the client, whether to delay deserialized method relocation or not
475-
// At the client, whether or not to use the new AOT cache implementation (with serialization record IDs as SCC offsets)
485+
// At the client, whether or not to use the new AOT cache implementation (with serialization record IDs as SCC offsets)
476486
bool _JITServerAOTCacheIgnoreLocalSCC;
487+
// True if the client should not request AOT cache loads during this server connection
488+
bool _doNotRequestJITServerAOTCacheLoad;
489+
// True if the client should not request AOT cache stores during this server connection
490+
bool _doNotRequestJITServerAOTCacheStore;
477491
#endif /* defined(J9VM_OPT_JITSERVER) */
478492
};
479493

runtime/compiler/net/CommunicationStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CommunicationStream
118118
// likely to lose an increment when merging/rebasing/etc.
119119
//
120120
static const uint8_t MAJOR_NUMBER = 1;
121-
static const uint16_t MINOR_NUMBER = 58; // ID: jdaegRYmBxGBJ/FG0fcY
121+
static const uint16_t MINOR_NUMBER = 59; // ID: h4Ihmr7j+jt8ie/rpCIX
122122
static const uint8_t PATCH_NUMBER = 0;
123123
static uint32_t CONFIGURATION_FLAGS;
124124

runtime/compiler/net/MessageTypes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const char *messageNames[] =
3030
"compilationFailure",
3131
"AOTCache_storedAOTMethod",
3232
"AOTCache_serializedAOTMethod",
33+
"AOTCache_failure",
3334
"mirrorResolvedJ9Method",
3435
"get_params_to_construct_TR_j9method",
3536
"getUnloadedClassRangesAndCHTable",

runtime/compiler/net/MessageTypes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum MessageType : uint16_t
3434
compilationFailure,
3535
AOTCache_storedAOTMethod, // Final response to a compilation request that was an AOT cache store that ignored the client SCC
3636
AOTCache_serializedAOTMethod,// Final response to a compilation request that was an AOT cache hit
37+
AOTCache_failure,// Final response to a compilation request that could not be completed due to AOT cache failure
3738
mirrorResolvedJ9Method,
3839
get_params_to_construct_TR_j9method,
3940
getUnloadedClassRangesAndCHTable,

0 commit comments

Comments
 (0)