Skip to content

Commit

Permalink
Merge pull request #20654 from luke-li-2003/ServerCacheUnresolvedInCP
Browse files Browse the repository at this point in the history
Cache unresolvedInCP at the JIT Server
  • Loading branch information
mpirvu authored Nov 22, 2024
2 parents 1f5ad00 + 2b95d24 commit 9de8d6b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 16 deletions.
7 changes: 5 additions & 2 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,8 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
std::vector<TR_OpaqueMethodBlock *> ramMethods(numMethods);
std::vector<uint32_t> vTableOffsets(numMethods);
std::vector<TR_ResolvedJ9JITServerMethodInfo> methodInfos(numMethods);
// vector<bool> does not seem to work
std::vector<char> unresolvedInCPs(numMethods);
for (int32_t i = 0; i < numMethods; ++i)
{
int32_t cpIndex = cpIndices[i];
Expand All @@ -1796,7 +1798,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
TR_OpaqueMethodBlock *ramMethod = NULL;
uint32_t vTableOffset = 0;
TR_ResolvedJ9JITServerMethodInfo methodInfo;
bool unresolvedInCP = false;
bool unresolvedInCP = true;
switch (type)
{
case TR_ResolvedMethodType::VirtualFromCP:
Expand Down Expand Up @@ -1834,8 +1836,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
ramMethods[i] = ramMethod;
vTableOffsets[i] = vTableOffset;
methodInfos[i] = methodInfo;
unresolvedInCPs[i] = unresolvedInCP;
}
client->write(response, ramMethods, vTableOffsets, methodInfos);
client->write(response, ramMethods, vTableOffsets, methodInfos, unresolvedInCPs);
}
break;
case MessageType::ResolvedMethod_getConstantDynamicTypeFromCP:
Expand Down
13 changes: 10 additions & 3 deletions runtime/compiler/control/JITServerCompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,18 @@ TR::CompilationInfoPerThreadRemote::getCachedIProfilerInfo(TR_OpaqueMethodBlock
* @param key Identifier used to identify a resolved method in resolved methods cache
* @param method The resolved method of interest
* @param vTableSlot The vTableSlot for the resolved method of interest
* @param isUnresolvedInCP The unresolvedInCP boolean value of interest
* @param methodInfo Additional method info about the resolved method of interest
* @return returns void
*/
void
TR::CompilationInfoPerThreadRemote::cacheResolvedMethod(TR_ResolvedMethodKey key, TR_OpaqueMethodBlock *method,
uint32_t vTableSlot, const TR_ResolvedJ9JITServerMethodInfo &methodInfo, int32_t ttlForUnresolved)
TR::CompilationInfoPerThreadRemote::cacheResolvedMethod(TR_ResolvedMethodKey key,
TR_OpaqueMethodBlock *method,
uint32_t vTableSlot,
const TR_ResolvedJ9JITServerMethodInfo
&methodInfo,
bool isUnresolvedInCP,
int32_t ttlForUnresolved)
{
static bool useCaching = !feGetEnv("TR_DisableResolvedMethodsCaching");
if (!useCaching)
Expand Down Expand Up @@ -1518,6 +1524,7 @@ TR::CompilationInfoPerThreadRemote::cacheResolvedMethod(TR_ResolvedMethodKey key
cacheEntry.persistentBodyInfo = bodyInfo;
cacheEntry.persistentMethodInfo = pMethodInfo;
cacheEntry.IPMethodInfo = entry;
cacheEntry.isUnresolvedInCP = isUnresolvedInCP;

// time-to-live for cached unresolved methods.
// Irrelevant for resolved methods.
Expand Down Expand Up @@ -1599,7 +1606,7 @@ TR::CompilationInfoPerThreadRemote::getCachedResolvedMethod(TR_ResolvedMethodKey
if (*resolvedMethod)
{
if (unresolvedInCP)
*unresolvedInCP = false;
*unresolvedInCP = methodCacheEntry.isUnresolvedInCP;
return true;
}
else
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 @@ -85,7 +85,7 @@ class CompilationInfoPerThreadRemote : public TR::CompilationInfoPerThread
bool cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, TR_IPBytecodeHashTableEntry *entry);
TR_IPBytecodeHashTableEntry *getCachedIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, bool *methodInfoPresent);

void cacheResolvedMethod(TR_ResolvedMethodKey key, TR_OpaqueMethodBlock *method, uint32_t vTableSlot, const TR_ResolvedJ9JITServerMethodInfo &methodInfo, int32_t ttlForUnresolved = 2);
void cacheResolvedMethod(TR_ResolvedMethodKey key, TR_OpaqueMethodBlock *method, uint32_t vTableSlot, const TR_ResolvedJ9JITServerMethodInfo &methodInfo, bool isUnresolvedInCP, int32_t ttlForUnresolved = 2);
bool getCachedResolvedMethod(TR_ResolvedMethodKey key, TR_ResolvedJ9JITServerMethod *owningMethod, TR_ResolvedMethod **resolvedMethod, bool *unresolvedInCP = NULL);
TR_ResolvedMethodKey getResolvedMethodKey(TR_ResolvedMethodType type, TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_OpaqueClassBlock *classObject = NULL);

Expand Down
62 changes: 53 additions & 9 deletions runtime/compiler/env/j9methodServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,14 @@ TR_ResolvedJ9JITServerMethod::getResolvedPossiblyPrivateVirtualMethod(TR::Compil
if (createResolvedMethod)
{
resolvedMethod = createResolvedMethodFromJ9Method(comp, cpIndex, vTableIndex, ramMethod, unresolvedInCP, aotStats, methodInfo);
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromCP, (TR_OpaqueClassBlock *) _ramClass, cpIndex), (TR_OpaqueMethodBlock *) ramMethod, (uint32_t) vTableIndex, methodInfo);
compInfoPT->cacheResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromCP,
(TR_OpaqueClassBlock *) _ramClass, cpIndex),
(TR_OpaqueMethodBlock *) ramMethod,
(uint32_t) vTableIndex,
methodInfo,
*unresolvedInCP
);
}
}
}
Expand Down Expand Up @@ -694,7 +701,14 @@ TR_ResolvedJ9JITServerMethod::getResolvedStaticMethod(TR::Compilation * comp, I_
}
else
{
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Static, (TR_OpaqueClassBlock *) _ramClass, cpIndex), (TR_OpaqueMethodBlock *) ramMethod, 0, methodInfo);
compInfoPT->cacheResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Static,
(TR_OpaqueClassBlock *) _ramClass, cpIndex),
(TR_OpaqueMethodBlock *) ramMethod,
0,
methodInfo,
*unresolvedInCP
);
}

return resolvedMethod;
Expand Down Expand Up @@ -751,7 +765,13 @@ TR_ResolvedJ9JITServerMethod::getResolvedSpecialMethod(TR::Compilation * comp, I
}
else
{
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Special, clazz, cpIndex), (TR_OpaqueMethodBlock *) ramMethod, 0, methodInfo);
compInfoPT->cacheResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Special, clazz, cpIndex),
(TR_OpaqueMethodBlock *) ramMethod,
0,
methodInfo,
*unresolvedInCP
);
}

return resolvedMethod;
Expand Down Expand Up @@ -882,7 +902,14 @@ TR_ResolvedJ9JITServerMethod::getResolvedInterfaceMethod(TR::Compilation * comp,
// to uniquely identify it.
if (resolvedMethod)
{
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Interface, clazz, cpIndex, classObject), (TR_OpaqueMethodBlock *) ramMethod, 0, methodInfo);
compInfoPT->cacheResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Interface,
clazz, cpIndex, classObject),
(TR_OpaqueMethodBlock *) ramMethod,
0,
methodInfo,
true
);
return resolvedMethod;
}

Expand Down Expand Up @@ -932,8 +959,14 @@ TR_ResolvedJ9JITServerMethod::getResolvedImproperInterfaceMethod(TR::Compilation
j9method = NULL;
}

compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::ImproperInterface, (TR_OpaqueClassBlock *) _ramClass, cpIndex),
(TR_OpaqueMethodBlock *) j9method, vtableOffset, methodInfo);
compInfoPT->cacheResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::ImproperInterface,
(TR_OpaqueClassBlock *) _ramClass, cpIndex),
(TR_OpaqueMethodBlock *) j9method,
vtableOffset,
methodInfo,
true
);
if (j9method == NULL)
return NULL;
else
Expand Down Expand Up @@ -997,7 +1030,14 @@ TR_ResolvedJ9JITServerMethod::getResolvedVirtualMethod(TR::Compilation * comp, T
resolvedMethod = ramMethod ? new (comp->trHeapMemory()) TR_ResolvedJ9JITServerMethod((TR_OpaqueMethodBlock *) ramMethod, _fe, comp->trMemory(), methodInfo, this) : 0;
}
if (resolvedMethod)
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromOffset, clazz, virtualCallOffset, classObject), ramMethod, 0, methodInfo);
compInfoPT->cacheResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromOffset,
clazz, virtualCallOffset, classObject),
(TR_OpaqueMethodBlock *) ramMethod,
0,
methodInfo,
true
);
return resolvedMethod;
}

Expand Down Expand Up @@ -1664,12 +1704,13 @@ TR_ResolvedJ9JITServerMethod::cacheResolvedMethodsCallees(int32_t ttlForUnresolv

// 2. Send a remote query to mirror all uncached resolved methods
_stream->write(JITServer::MessageType::ResolvedMethod_getMultipleResolvedMethods, (TR_ResolvedJ9Method *) _remoteMirror, methodTypes, cpIndices);
auto recv = _stream->read<std::vector<TR_OpaqueMethodBlock *>, std::vector<uint32_t>, std::vector<TR_ResolvedJ9JITServerMethodInfo>>();
auto recv = _stream->read<std::vector<TR_OpaqueMethodBlock *>, std::vector<uint32_t>, std::vector<TR_ResolvedJ9JITServerMethodInfo>, std::vector<char>>();

// 3. Cache all received resolved methods
auto &ramMethods = std::get<0>(recv);
auto &vTableOffsets = std::get<1>(recv);
auto &methodInfos = std::get<2>(recv);
auto &unresolvedInCPs = std::get<3>(recv);
TR_ASSERT(numMethods == ramMethods.size(), "Number of received methods does not match the number of requested methods");
for (int32_t i = 0; i < numMethods; ++i)
{
Expand All @@ -1686,6 +1727,7 @@ TR_ResolvedJ9JITServerMethod::cacheResolvedMethodsCallees(int32_t ttlForUnresolv
ramMethods[i],
vTableOffsets[i],
methodInfos[i],
(bool) unresolvedInCPs[i],
ttlForUnresolved
);
}
Expand Down Expand Up @@ -1806,7 +1848,9 @@ TR_ResolvedJ9JITServerMethod::collectImplementorsCapped(
(TR_OpaqueMethodBlock *) ramMethods[i],
cpIndexOrOffset,
methodInfos[i],
0); // all received methods should be resolved
true,
0
); // all received methods should be resolved
success = compInfoPT->getCachedResolvedMethod(key, this, &resolvedMethod);
}

Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/env/j9methodServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ TR_ResolvedMethodCacheEntry
TR_PersistentMethodInfo *persistentMethodInfo;
TR_ContiguousIPMethodHashTableEntry *IPMethodInfo;
int32_t ttlForUnresolved;
bool isUnresolvedInCP;
};

using TR_ResolvedMethodInfoCache = UnorderedMap<TR_ResolvedMethodKey, TR_ResolvedMethodCacheEntry>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/net/CommunicationStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class CommunicationStream
// likely to lose an increment when merging/rebasing/etc.
//
static const uint8_t MAJOR_NUMBER = 1;
static const uint16_t MINOR_NUMBER = 72; // ID: PB545sJS3QOBXIIPV5JZ
static const uint16_t MINOR_NUMBER = 73; // ID: AwP1pJjbiAVBRCpcwuDt
static const uint8_t PATCH_NUMBER = 0;
static uint32_t CONFIGURATION_FLAGS;

Expand Down

0 comments on commit 9de8d6b

Please sign in to comment.