Skip to content

Commit

Permalink
Merge pull request #9160 from a7ehuo/reduce-iscompiled
Browse files Browse the repository at this point in the history
Reduce CompInfo_isCompiled message from the server
  • Loading branch information
mpirvu committed Apr 8, 2020
2 parents ef484e6 + 3a61eca commit 5c46748
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
11 changes: 6 additions & 5 deletions runtime/compiler/control/JITClientCompilationThread.cpp
Expand Up @@ -120,7 +120,7 @@ handler_IProfiler_profilingSample(JITServer::ClientStream *client, TR_J9VM *fe,
if (wholeMethodInfo)
{
// Serialize all the information related to this method
abort = iProfiler->serializeAndSendIProfileInfoForMethod(method, comp, client, usePersistentCache);
abort = iProfiler->serializeAndSendIProfileInfoForMethod(method, comp, client, usePersistentCache, isCompiled);
}
if (!wholeMethodInfo || abort) // Send information just for this entry
{
Expand All @@ -135,11 +135,11 @@ handler_IProfiler_profilingSample(JITServer::ClientStream *client, TR_J9VM *fe,
auto storage = (TR_IPBCDataStorageHeader*)&entryBytes[0];
uintptr_t methodStartAddress = (uintptr_t)TR::Compiler->mtd.bytecodeStart(method);
entry->serialize(methodStartAddress, storage, comp->getPersistentInfo());
client->write(JITServer::MessageType::IProfiler_profilingSample, entryBytes, false, usePersistentCache);
client->write(JITServer::MessageType::IProfiler_profilingSample, entryBytes, false, usePersistentCache, isCompiled);
}
else
{
client->write(JITServer::MessageType::IProfiler_profilingSample, std::string(), false, usePersistentCache);
client->write(JITServer::MessageType::IProfiler_profilingSample, std::string(), false, usePersistentCache, isCompiled);
}
// Unlock the entry
if (auto callGraphEntry = entry->asIPBCDataCallGraph())
Expand All @@ -148,7 +148,7 @@ handler_IProfiler_profilingSample(JITServer::ClientStream *client, TR_J9VM *fe,
}
else // No valid info for specified bytecode index
{
client->write(JITServer::MessageType::IProfiler_profilingSample, std::string(), false, usePersistentCache);
client->write(JITServer::MessageType::IProfiler_profilingSample, std::string(), false, usePersistentCache, isCompiled);
}
}
}
Expand Down Expand Up @@ -2597,7 +2597,8 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
auto count = std::get<2>(recv);
TR_IProfiler * iProfiler = fe->getIProfiler();
iProfiler->setCallCount(method, bcIndex, count, comp);
client->write(response, JITServer::Void());

client->write(response, TR::CompilationInfo::isCompiled((J9Method *)method));
}
break;
case MessageType::Recompilation_getExistingMethodInfo:
Expand Down
3 changes: 1 addition & 2 deletions runtime/compiler/runtime/JITClientSession.cpp
Expand Up @@ -228,7 +228,7 @@ ClientSessionData::getCachedIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t
}

bool
ClientSessionData::cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, TR_IPBytecodeHashTableEntry *entry)
ClientSessionData::cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, TR_IPBytecodeHashTableEntry *entry, bool isCompiled)
{
OMR::CriticalSection getRemoteROMClass(getROMMapMonitor());
// check whether info about j9method exists
Expand All @@ -240,7 +240,6 @@ ClientSessionData::cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byt
if (!iProfilerMap)
{
// Check and update if method is compiled when collecting profiling data
bool isCompiled = TR::CompilationInfo::isCompiled((J9Method*)method);
if (isCompiled)
it->second._isCompiledWhenProfiling = true;

Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/runtime/JITClientSession.hpp
Expand Up @@ -351,7 +351,7 @@ class ClientSessionData
TR::Monitor *getClassMapMonitor() { return _classMapMonitor; }
TR::Monitor *getClassChainDataMapMonitor() { return _classChainDataMapMonitor; }
TR_IPBytecodeHashTableEntry *getCachedIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, bool *methodInfoPresent);
bool cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, TR_IPBytecodeHashTableEntry *entry);
bool cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, TR_IPBytecodeHashTableEntry *entry, bool isCompiled);
VMInfo *getOrCacheVMInfo(JITServer::ServerStream *stream);
void clearCaches(); // destroys _chTableClassMap, _romClassMap and _J9MethodMap
TR_AddressSet& getUnloadedClassAddresses()
Expand Down
64 changes: 35 additions & 29 deletions runtime/compiler/runtime/JITServerIProfiler.cpp
Expand Up @@ -201,10 +201,11 @@ JITServerIProfiler::profilingSample(TR_OpaqueMethodBlock *method, uint32_t byteC
// Ask the client again and see if the two sources of information match
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::IProfiler_profilingSample, method, byteCodeIndex, (uintptr_t)1);
auto recv = stream->read<std::string, bool, bool>();
auto recv = stream->read<std::string, bool, bool, bool>();
const std::string ipdata = std::get<0>(recv);
bool wholeMethod = std::get<1>(recv); // indicates whether the client has sent info for entire method
bool usePersistentCache = std::get<2>(recv);
bool isCompiled = std::get<3>(recv);
TR_ASSERT(!wholeMethod, "Client should not have sent whole method info");
uintptr_t methodStart = TR::Compiler->mtd.bytecodeStart(method);
TR_IPBCDataStorageHeader *clientData = ipdata.empty() ? NULL : (TR_IPBCDataStorageHeader *) &ipdata[0];
Expand Down Expand Up @@ -237,10 +238,11 @@ JITServerIProfiler::profilingSample(TR_OpaqueMethodBlock *method, uint32_t byteC
//
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::IProfiler_profilingSample, method, byteCodeIndex, (uintptr_t)(_useCaching ? 0 : 1));
auto recv = stream->read<std::string, bool, bool>();
auto recv = stream->read<std::string, bool, bool, bool>();
const std::string ipdata = std::get<0>(recv);
bool wholeMethod = std::get<1>(recv); // indicates whether the client sent info for entire method
bool usePersistentCache = std::get<2>(recv); // indicates whether info can be saved in persistent memory, or only in heap memory
bool isCompiled = std::get<3>(recv);
_statsIProfilerInfoMsgToClient++;

bool doCache = _useCaching && wholeMethod;
Expand All @@ -254,10 +256,10 @@ JITServerIProfiler::profilingSample(TR_OpaqueMethodBlock *method, uint32_t byteC
{
// cache some empty data so that we don't ask again for this method
// this method contains empty data
if (usePersistentCache && !clientSessionData->cacheIProfilerInfo(method, byteCodeIndex, NULL))
_statsIProfilerInfoCachingFailures++;
if (usePersistentCache && !clientSessionData->cacheIProfilerInfo(method, byteCodeIndex, NULL, isCompiled))
_statsIProfilerInfoCachingFailures++;
else if (!usePersistentCache && !compInfoPT->cacheIProfilerInfo(method, byteCodeIndex, NULL))
_statsIProfilerInfoCachingFailures++;
_statsIProfilerInfoCachingFailures++;
}
return NULL;
}
Expand Down Expand Up @@ -300,7 +302,7 @@ JITServerIProfiler::profilingSample(TR_OpaqueMethodBlock *method, uint32_t byteC
bci += 2;
}
}
if (usePersistentCache && !clientSessionData->cacheIProfilerInfo(method, bci, entry))
if (usePersistentCache && !clientSessionData->cacheIProfilerInfo(method, bci, entry, isCompiled))
{
// If caching failed we must delete the entry allocated with persistent memory
_statsIProfilerInfoCachingFailures++;
Expand Down Expand Up @@ -496,14 +498,14 @@ JITServerIProfiler::setCallCount(TR_OpaqueMethodBlock *method, int32_t bcIndex,
return;

bool sendRemoteMessage = false;
bool createNewEntry = false;
bool methodInfoPresentInPersistent = false;
ClientSessionData *clientData = TR::compInfoPT->getClientData(); // Find clientSessionData
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) TR::compInfoPT;
if (_useCaching)
{
OMR::CriticalSection getRemoteROMClass(clientData->getROMMapMonitor());
auto & j9methodMap = clientData->getJ9MethodMap();
bool methodInfoPresentInPersistent = false;
bool methodInfoPresentInHeap = false;
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) TR::compInfoPT;
// Check persistent cache first, then per-compilation cache
TR_IPBytecodeHashTableEntry *entry = clientData->getCachedIProfilerInfo(method, bcIndex, &methodInfoPresentInPersistent);
if (!methodInfoPresentInPersistent)
Expand All @@ -529,24 +531,10 @@ JITServerIProfiler::setCallCount(TR_OpaqueMethodBlock *method, int32_t bcIndex,
// Nothing to do because the correct data is already in place
}
}
else
else // Info for this bcIndex is missing.
{
// Info for this bcIndex is missing.
// Create a new entry, add it to the cache and send a remote message as well
uintptr_t methodStart = TR::Compiler->mtd.bytecodeStart(method);
TR_AllocationKind allocKind = methodInfoPresentInPersistent ? persistentAlloc : heapAlloc;
TR_IPBCDataCallGraph *cgEntry = (TR_IPBCDataCallGraph*)comp->trMemory()->allocateMemory(sizeof(TR_IPBCDataCallGraph), allocKind, TR_Memory::IPBCDataCallGraph);
cgEntry = new (cgEntry) TR_IPBCDataCallGraph(methodStart + bcIndex);

CallSiteProfileInfo *csInfo = cgEntry->getCGData();
csInfo->_weight[0] = count;
// TODO: we should probably add some class as well
if (methodInfoPresentInPersistent)
clientData->cacheIProfilerInfo(method, bcIndex, cgEntry);
else
compInfoPT->cacheIProfilerInfo(method, bcIndex, cgEntry);

sendRemoteMessage = true;
createNewEntry = true;
}
}
else
Expand All @@ -563,7 +551,25 @@ JITServerIProfiler::setCallCount(TR_OpaqueMethodBlock *method, int32_t bcIndex,
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::IProfiler_setCallCount, method, bcIndex, count);
stream->read<JITServer::Void>();
auto recv = stream->read<bool>();
bool isCompiled = std::get<0>(recv);

if (createNewEntry)
{
// Create a new entry, add it to the cache and send a remote message as well
uintptr_t methodStart = TR::Compiler->mtd.bytecodeStart(method);
TR_AllocationKind allocKind = methodInfoPresentInPersistent ? persistentAlloc : heapAlloc;
TR_IPBCDataCallGraph *cgEntry = (TR_IPBCDataCallGraph*)comp->trMemory()->allocateMemory(sizeof(TR_IPBCDataCallGraph), allocKind, TR_Memory::IPBCDataCallGraph);
cgEntry = new (cgEntry) TR_IPBCDataCallGraph(methodStart + bcIndex);

CallSiteProfileInfo *csInfo = cgEntry->getCGData();
csInfo->_weight[0] = count;
// TODO: we should probably add some class as well
if (methodInfoPresentInPersistent)
clientData->cacheIProfilerInfo(method, bcIndex, cgEntry, isCompiled);
else
compInfoPT->cacheIProfilerInfo(method, bcIndex, cgEntry);
}
}
}

Expand Down Expand Up @@ -733,7 +739,7 @@ JITClientIProfiler::serializeIProfilerMethodEntries(uintptr_t *pcEntries, uint32
* @return Whether the operation was successful
*/
bool
JITClientIProfiler::serializeAndSendIProfileInfoForMethod(TR_OpaqueMethodBlock *method, TR::Compilation *comp, JITServer::ClientStream *client, bool usePersistentCache)
JITClientIProfiler::serializeAndSendIProfileInfoForMethod(TR_OpaqueMethodBlock *method, TR::Compilation *comp, JITServer::ClientStream *client, bool usePersistentCache, bool isCompiled)
{
TR::StackMemoryRegion stackMemoryRegion(*comp->trMemory());
uint32_t numEntries = 0;
Expand Down Expand Up @@ -762,11 +768,11 @@ JITClientIProfiler::serializeAndSendIProfileInfoForMethod(TR_OpaqueMethodBlock *
intptr_t writtenBytes = serializeIProfilerMethodEntries(pcEntries, numEntries, (uintptr_t)&buffer[0], methodStart);
TR_ASSERT(writtenBytes == bytesFootprint, "BST doesn't match expected footprint");
// send the information to the server
client->write(JITServer::MessageType::IProfiler_profilingSample, buffer, true, usePersistentCache);
client->write(JITServer::MessageType::IProfiler_profilingSample, buffer, true, usePersistentCache, isCompiled);
}
else if (!numEntries && !abort)// Empty IProfiler data for this method
{
client->write(JITServer::MessageType::IProfiler_profilingSample, std::string(), true, usePersistentCache);
client->write(JITServer::MessageType::IProfiler_profilingSample, std::string(), true, usePersistentCache, isCompiled);
}

// release any entry that has been locked by us
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/runtime/JITServerIProfiler.hpp
Expand Up @@ -142,7 +142,7 @@ class JITClientIProfiler : public TR_IProfiler
// Thus, any virtual function here must call the corresponding method in
// the base class. It may be better not to override any methods though

bool serializeAndSendIProfileInfoForMethod(TR_OpaqueMethodBlock*method, TR::Compilation *comp, JITServer::ClientStream *client, bool usePersistentCache);
bool serializeAndSendIProfileInfoForMethod(TR_OpaqueMethodBlock*method, TR::Compilation *comp, JITServer::ClientStream *client, bool usePersistentCache, bool isCompiled);
std::string serializeIProfilerMethodEntry(TR_OpaqueMethodBlock *omb);

private:
Expand Down

0 comments on commit 5c46748

Please sign in to comment.