Skip to content

Commit

Permalink
Add walkReferenceChain JITServer Support (eclipse-openj9#8293)
Browse files Browse the repository at this point in the history
Add walkReferenceChain JITServer Support
  • Loading branch information
mpirvu authored Jan 17, 2020
2 parents 9555017 + cd54e60 commit 3ab4200
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 104 deletions.
4 changes: 1 addition & 3 deletions runtime/compiler/control/CompilationRuntime.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1014,8 +1014,6 @@ class CompilationInfo
void markCHTableUpdateDone(uint8_t threadId) { _chTableUpdateFlags |= (1 << threadId); }
void resetCHTableUpdateDone(uint8_t threadId) { _chTableUpdateFlags &= ~(1 << threadId); }
uint8_t getCHTableUpdateDone() const { return _chTableUpdateFlags; }
uint32_t getLocalGCCounter() const { return _localGCCounter; }
void incrementLocalGCCounter() { _localGCCounter++; }

const PersistentVector<std::string> &getJITServerSslKeys() const { return _sslKeys; }
void addJITServerSslKey(const std::string &key) { _sslKeys.push_back(key); }
Expand Down
10 changes: 1 addition & 9 deletions runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1049,8 +1049,6 @@ TR::CompilationInfoPerThread::CompilationInfoPerThread(TR::CompilationInfo &comp
{
_classesThatShouldNotBeNewlyExtended = NULL;
}

_lastLocalGCCounter = 0;
#endif /* defined(JITSERVER_SUPPORT) */
}

Expand Down Expand Up @@ -12854,12 +12852,6 @@ TR::CompilationInfo::canRelocateMethod(TR::Compilation *comp)
}

#if defined(JITSERVER_SUPPORT)
void
TR::CompilationInfoPerThread::updateLastLocalGCCounter()
{
_lastLocalGCCounter = getCompilationInfo()->getLocalGCCounter();
}

// This method is executed by the JITServer to queue a placeholder for
// a compilation request received from the client. At the time the new
// entry is queued we do not know any details about the compilation request.
Expand Down
5 changes: 1 addition & 4 deletions runtime/compiler/control/CompilationThread.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -393,8 +393,6 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase
J9ROMClass *getAndCacheRemoteROMClass(J9Class *, TR_Memory *trMemory=NULL);
J9ROMClass *getRemoteROMClassIfCached(J9Class *);
PersistentUnorderedSet<TR_OpaqueClassBlock*> *getClassesThatShouldNotBeNewlyExtended() const { return _classesThatShouldNotBeNewlyExtended; }
uint32_t getLastLocalGCCounter() const { return _lastLocalGCCounter; }
void updateLastLocalGCCounter();
#endif /* defined(JITSERVER_SUPPORT) */

protected:
Expand All @@ -418,7 +416,6 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase
// The following hastable caches <classLoader,classname> --> <J9Class> mappings
// The cache only lives during a compilation due to class unloading concerns
PersistentUnorderedSet<TR_OpaqueClassBlock*> *_classesThatShouldNotBeNewlyExtended;
uint32_t _lastLocalGCCounter;
#endif /* defined(JITSERVER_SUPPORT) */

}; // CompilationInfoPerThread
Expand Down
5 changes: 0 additions & 5 deletions runtime/compiler/control/HookedByTheJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,11 +1563,6 @@ static void jitHookLocalGCEnd(J9HookInterface * * hookInterface, UDATA eventNum,

if (jitConfig->runtimeFlags & J9JIT_GC_NOTIFY)
printf("}");

#if defined(JITSERVER_SUPPORT)
TR::CompilationInfo *compInfo = TR::CompilationInfo::get(jitConfig);
compInfo->incrementLocalGCCounter();
#endif
}

static void initThreadAfterCreation(J9VMThread *vmThread)
Expand Down
151 changes: 94 additions & 57 deletions runtime/compiler/control/JITClientCompilationThread.cpp

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion runtime/compiler/control/JITServerHelpers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -27,6 +27,7 @@
#include "control/MethodToBeCompiled.hpp"
#include "infra/CriticalSection.hpp"


uint32_t JITServerHelpers::serverMsgTypeCount[] = {};
uint64_t JITServerHelpers::_waitTimeMs = 1000;
bool JITServerHelpers::_serverAvailable = true;
Expand Down Expand Up @@ -549,3 +550,16 @@ JITServerHelpers::isAddressInROMClass(const void *address, const J9ROMClass *rom
{
return ((address >= romClass) && (address < (((uint8_t*) romClass) + romClass->romSize)));
}


uintptrj_t
JITServerHelpers::walkReferenceChainWithOffsets(TR_J9VM * fe, const std::vector<uintptrj_t>& listOfOffsets, uintptrj_t receiver)
{
uintptrj_t result = receiver;
for (size_t i = 0; i < listOfOffsets.size(); i++)
{
result = fe->getReferenceFieldAt(result, listOfOffsets[i]);
}
return result;
}

4 changes: 3 additions & 1 deletion runtime/compiler/control/JITServerHelpers.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -97,6 +97,8 @@ class JITServerHelpers

static bool isAddressInROMClass(const void *address, const J9ROMClass *romClass);

static uintptrj_t walkReferenceChainWithOffsets(TR_J9VM * fe, const std::vector<uintptrj_t>& listOfOffsets, uintptrj_t receiver);

private:
static void getROMClassData(const ClientSessionData::ClassInfo &classInfo, ClassInfoDataType dataType, void *data);
static TR::Monitor *getClientStreamMonitor()
Expand Down
118 changes: 100 additions & 18 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "env/JSR292Methods.h"
#include "control/MethodToBeCompiled.hpp"


#if defined(_MSC_VER)
#include <malloc.h>
#endif
Expand Down Expand Up @@ -7789,11 +7790,13 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)
#if defined(JITSERVER_SUPPORT)
if (comp()->isOutOfProcessCompilation())
{
std::vector<uintptrj_t> listOfOffsets;
if (!returnFromArchetype)
{
packReferenceChainOffsets(methodHandleExpression, listOfOffsets);
}
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_derefUintptrjPtr, thunkDetails->getHandleRef());
receiverHandle = std::get<0>(stream->read<uintptrj_t>());
methodHandle = returnFromArchetype ? receiverHandle : walkReferenceChain(methodHandleExpression, receiverHandle);
stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosInvokeExactAndFixup, methodHandle);
stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosInvokeExactAndFixup, thunkDetails->getHandleRef(), listOfOffsets);
auto recv = stream->read<std::string>();
std::string methodDescriptorString = std::get<0>(recv);
methodDescriptorLength = methodDescriptorString.length();
Expand Down Expand Up @@ -8627,6 +8630,24 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)

uintptrj_t methodHandle;
uintptrj_t argumentIndices;

#if defined(JITSERVER_SUPPORT)
if (comp()->isOutOfProcessCompilation())
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_invokeFilterArgumentsWithCombinerHandleArgumentIndices, thunkDetails->getHandleRef());

auto recv = stream->read<int32_t, std::vector<int32_t>>();
int32_t arrayLength = std::get<0>(recv);
std::vector<int32_t> argIndices = std::get<1>(recv);
// Push the indices in reverse order
for (int i = arrayLength - 1; i >= 0; i--) {
loadConstant(TR::iconst, argIndices[i]);
}
loadConstant(TR::iconst, arrayLength); // number of arguments
}
else
#endif /* defined(JITSERVER_SUPPORT) */
{
TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fej9);
methodHandle = *thunkDetails->getHandleRef();
Expand Down Expand Up @@ -8680,6 +8701,16 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)

uintptrj_t methodHandle;
int32_t filterPosition;

#if defined(JITSERVER_SUPPORT)
if (comp()->isOutOfProcessCompilation())
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_invokeFilterArgumentsWithCombinerHandleFilterPosition, thunkDetails->getHandleRef());
filterPosition = std::get<0>(stream->read<int32_t>());
}
else
#endif /* defined(JITSERVER_SUPPORT) */
{
TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fej9);
methodHandle = *thunkDetails->getHandleRef();
Expand Down Expand Up @@ -8785,6 +8816,17 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)
int32_t numArguments;
int32_t filterPos;

#if defined(JITSERVER_SUPPORT)
if (comp()->isOutOfProcessCompilation())
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_invokeFilterArgumentsWithCombinerHandleNumSuffixArgs, thunkDetails->getHandleRef());
auto recv = stream->read<int32_t, int32_t>();
numArguments = std::get<0>(recv);
filterPos = std::get<1>(recv);
}
else
#endif /* defined(JITSERVER_SUPPORT) */
{
TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fej9);
methodHandle = *thunkDetails->getHandleRef();
Expand Down Expand Up @@ -9050,11 +9092,9 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)
if (comp()->isOutOfProcessCompilation())
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_derefUintptrjPtr, thunkDetails->getHandleRef());
uintptrj_t receiverHandle = std::get<0>(stream->read<uintptrj_t>());
uintptrj_t methodHandle = walkReferenceChain(pop(), receiverHandle);

stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacros, methodHandle);
std::vector<uintptrj_t> listOfOffsets;
packReferenceChainOffsets(pop(), listOfOffsets);
stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosParameterCount, thunkDetails->getHandleRef(), listOfOffsets);
parameterCount = std::get<0>(stream->read<int32_t>());
}
else
Expand Down Expand Up @@ -9085,10 +9125,10 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)
if (comp()->isOutOfProcessCompilation())
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_derefUintptrjPtr, thunkDetails->getHandleRef());
uintptrj_t receiverHandle = std::get<0>(stream->read<uintptrj_t>());
uintptrj_t array = walkReferenceChain(pop(), receiverHandle);
arrayLength = (int32_t)fej9->getArrayLengthInElements(array);
std::vector<uintptrj_t> listOfOffsets;
packReferenceChainOffsets(pop(), listOfOffsets);
stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosArrayLength, thunkDetails->getHandleRef(), listOfOffsets);
arrayLength = std::get<0>(stream->read<int32_t>());
}
else
#endif /* defined(JITSERVER_SUPPORT) */
Expand Down Expand Up @@ -9122,11 +9162,11 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef)
if (comp()->isOutOfProcessCompilation())
{
auto stream = TR::CompilationInfo::getStream();
stream->write(JITServer::MessageType::runFEMacro_derefUintptrjPtr, thunkDetails->getHandleRef());
uintptrj_t receiverHandle = std::get<0>(stream->read<uintptrj_t>());
uintptrj_t baseObject = walkReferenceChain(baseObjectNode, receiverHandle);
std::vector<uintptrj_t> listOfOffsets;
packReferenceChainOffsets(baseObjectNode, listOfOffsets);
TR_ASSERT(fieldSym->getDataType() == TR::Int32, "ILGenMacros.getField expecting int field; found load of %s", comp()->getDebug()->getName(symRef));
result = fej9->getInt32FieldAt(baseObject, fieldOffset); // TODO: Handle types other than int32
stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosGetField, thunkDetails->getHandleRef(), fieldOffset, listOfOffsets);
result = std::get<0>(stream->read<int32_t>());
}
else
#endif /* defined(JITSERVER_SUPPORT) */
Expand Down Expand Up @@ -9180,7 +9220,7 @@ TR_J9ByteCodeIlGenerator::walkReferenceChain(TR::Node *node, uintptrj_t receiver
}
TR::Symbol *sym = symRef->getSymbol();
TR_ASSERT(sym->isShadow() && symRef->getCPIndex() > 0, "walkReferenceChain expecting field load; found load of %s", comp()->getDebug()->getName(symRef));
uintptrj_t fieldOffset = symRef->getOffset() - TR::Compiler->om.objectHeaderSizeInBytes(); // blah
uintptrj_t fieldOffset = symRef->getOffset() - TR::Compiler->om.objectHeaderSizeInBytes();
result = fej9->getReferenceFieldAt(walkReferenceChain(node->getFirstChild(), receiver), fieldOffset);
}
else
Expand All @@ -9200,3 +9240,45 @@ TR_J9ByteCodeIlGenerator::walkReferenceChain(TR::Node *node, uintptrj_t receiver

return result;
}


#if defined(JITSERVER_SUPPORT)
void
TR_J9ByteCodeIlGenerator::packReferenceChainOffsets(TR::Node *node, std::vector<uintptrj_t>& listOfOffsets)
{
if (node->getOpCode().isLoadDirect() && node->getType() == TR::Address)
{
TR_ASSERT(node->getSymbolReference()->getCPIndex() == 0, "walkReferenceChain expecting aload of 'this'; found aload of %s", comp()->getDebug()->getName(node->getSymbolReference()));
return;
}
else if (node->getOpCode().isLoadIndirect() && node->getType() == TR::Address)
{
TR::SymbolReference *symRef = node->getSymbolReference();
if (symRef->isUnresolved())
{
if (comp()->getOption(TR_TraceILGen))
traceMsg(comp(), " walkReferenceChain hit unresolved symref %s; aborting\n", symRef->getName(comp()->getDebug()));
comp()->failCompilation<TR::ILGenFailure>("Symbol reference is unresolved");
}
TR::Symbol *sym = symRef->getSymbol();
TR_ASSERT(sym->isShadow() && symRef->getCPIndex() > 0, "walkReferenceChain expecting field load; found load of %s", comp()->getDebug()->getName(symRef));
uintptrj_t fieldOffset = symRef->getOffset() - TR::Compiler->om.objectHeaderSizeInBytes();
packReferenceChainOffsets(node->getFirstChild(), listOfOffsets);
listOfOffsets.push_back(fieldOffset);
}
else
{
TR_ASSERT(0, "Unexpected opcode in walkReferenceChain: %s", node->getOpCode().getName());
comp()->failCompilation<TR::ILGenFailure>("Unexpected opcode in walkReferenceChain");
}

if (comp()->getOption(TR_TraceILGen))
{
TR_ASSERT(node->getOpCode().hasSymbolReference(), "Can't get here without a symref");
traceMsg(comp(), " walkReferenceChain(%s) // %s\n",
comp()->getDebug()->getName(node),
comp()->getDebug()->getName(node->getSymbolReference()));
}
return;
}
#endif
6 changes: 5 additions & 1 deletion runtime/compiler/ilgen/J9ByteCodeIlGenerator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -342,6 +342,10 @@ class TR_J9ByteCodeIlGenerator : public TR_IlGenerator, public TR_J9ByteCodeIter
bool replaceStatic(TR::Node* node, char* dstClassName, char* staticName, char* type);

uintptrj_t walkReferenceChain(TR::Node *node, uintptrj_t receiver);
#if defined(JITSERVER_SUPPORT)
void packReferenceChainOffsets(TR::Node *node, std::vector<uintptrj_t>& listOfOffsets);
#endif

bool hasFPU();

// data
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/net/CommunicationStream.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 IBM Corp. and others
* Copyright (c) 2018, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -158,7 +158,7 @@ class CommunicationStream
ZeroCopyOutputStream *_outputStream;

static const uint8_t MAJOR_NUMBER = 0;
static const uint16_t MINOR_NUMBER = 1;
static const uint16_t MINOR_NUMBER = 2;
static const uint8_t PATCH_NUMBER = 0;
static uint32_t CONFIGURATION_FLAGS;
};
Expand Down
10 changes: 7 additions & 3 deletions runtime/compiler/net/protos/compile.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 IBM Corp. and others
* Copyright (c) 2018, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -281,8 +281,12 @@ enum MessageType
runFEMacro_invokeFilterArgumentsHandle = 714;
runFEMacro_invokeFilterArgumentsHandle2 = 715;
runFEMacro_invokeCatchHandle = 716;
runFEMacro_invokeILGenMacros = 717;
runFEMacro_derefUintptrjPtr = 718;
runFEMacro_invokeILGenMacrosParameterCount = 717;
runFEMacro_invokeILGenMacrosArrayLength = 718;
runFEMacro_invokeILGenMacrosGetField = 719;
runFEMacro_invokeFilterArgumentsWithCombinerHandleNumSuffixArgs = 720;
runFEMacro_invokeFilterArgumentsWithCombinerHandleFilterPosition = 721;
runFEMacro_invokeFilterArgumentsWithCombinerHandleArgumentIndices = 722;

// for JITServerPersistentCHTable
CHTable_getAllClassInfo = 800;
Expand Down

0 comments on commit 3ab4200

Please sign in to comment.