From b3eb10f29428ae7e91cbfba4100199c10084ef69 Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Mon, 13 Jan 2020 17:14:09 -0500 Subject: [PATCH 01/10] Add walkReferenceChain JITServer Support The purpose of this change is to avoid using object addresses on JITServer. Using object addresses on JITServer creates problems when GC changes the object addresses. Instead, JITServer must use some kind of handle (a GlobalReference or some other GC root) to hold the object so that JITServer always has the valid object addresses. walkReferenceChain is special in that it needs half of its information from the JITServer(TR::Node) and half of its information from JITClient(object address). During the walk, we need vmaccess so that GC doesn't move the object of interest. We can only have vmaccess on JITClient, which means we need to do walkReferenceChain on JITClient. This change makes JITServer to generate the offsets information JITClient needed for the walk and passes to JITClient in the form of a vector. Issue: #8109 Signed-off-by: Harry Yu --- .../control/JITClientCompilationThread.cpp | 14 ++--- runtime/compiler/control/JITServerHelpers.cpp | 16 +++++- runtime/compiler/control/JITServerHelpers.hpp | 4 +- runtime/compiler/env/j9method.cpp | 53 +++++++++++++++++-- .../compiler/ilgen/J9ByteCodeIlGenerator.hpp | 6 ++- 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index 11a1bb0f2a4..61ebc4173c3 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -2072,17 +2072,11 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeILGenMacrosInvokeExactAndFixup: { - auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeILGenMacrosInvokeExactAndFixup(fe); - - if (compInfoPT->getLastLocalGCCounter() != compInfoPT->getCompilationInfo()->getLocalGCCounter()) - { - // GC happened, fail compilation - auto comp = compInfoPT->getCompilation(); - comp->failCompilation("Compilation interrupted due to GC"); - } - - uintptrj_t methodHandle = std::get<0>(recv); + auto recv = client->getRecvData >(); + uintptrj_t receiverHandle = *std::get<0>(recv); + std::vector listOfOffsets = std::get<1>(recv); + uintptrj_t methodHandle = listOfOffsets.size() == 0 ? receiverHandle : JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); uintptrj_t methodDescriptorRef = fe->getReferenceField(fe->getReferenceField( methodHandle, "type", "Ljava/lang/invoke/MethodType;"), diff --git a/runtime/compiler/control/JITServerHelpers.cpp b/runtime/compiler/control/JITServerHelpers.cpp index 20345b2e885..8612a8b6aca 100644 --- a/runtime/compiler/control/JITServerHelpers.cpp +++ b/runtime/compiler/control/JITServerHelpers.cpp @@ -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 @@ -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; @@ -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, std::vector& 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; + } + diff --git a/runtime/compiler/control/JITServerHelpers.hpp b/runtime/compiler/control/JITServerHelpers.hpp index 3d518cbbe32..b6cb7591abc 100644 --- a/runtime/compiler/control/JITServerHelpers.hpp +++ b/runtime/compiler/control/JITServerHelpers.hpp @@ -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 @@ -97,6 +97,8 @@ class JITServerHelpers static bool isAddressInROMClass(const void *address, const J9ROMClass *romClass); + static uintptrj_t walkReferenceChainWithOffsets(TR_J9VM * fe, std::vector& listOfOffsets, uintptrj_t receiver); + private: static void getROMClassData(const ClientSessionData::ClassInfo &classInfo, ClassInfoDataType dataType, void *data); static TR::Monitor *getClientStreamMonitor() diff --git a/runtime/compiler/env/j9method.cpp b/runtime/compiler/env/j9method.cpp index 16c0212643e..77f2a3721f1 100644 --- a/runtime/compiler/env/j9method.cpp +++ b/runtime/compiler/env/j9method.cpp @@ -65,6 +65,7 @@ #include "env/JSR292Methods.h" #include "control/MethodToBeCompiled.hpp" + #if defined(_MSC_VER) #include #endif @@ -7789,11 +7790,13 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef) #if defined(JITSERVER_SUPPORT) if (comp()->isOutOfProcessCompilation()) { + std::vector 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()); - 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 methodDescriptorString = std::get<0>(recv); methodDescriptorLength = methodDescriptorString.length(); @@ -9200,3 +9203,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& 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("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(); // blah + packReferenceChainOffsets(node->getFirstChild(), listOfOffsets); + listOfOffsets.push_back(fieldOffset); + } + else + { + TR_ASSERT(0, "Unexpected opcode in walkReferenceChain: %s", node->getOpCode().getName()); + comp()->failCompilation("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 diff --git a/runtime/compiler/ilgen/J9ByteCodeIlGenerator.hpp b/runtime/compiler/ilgen/J9ByteCodeIlGenerator.hpp index 59394baa892..6a62d303187 100644 --- a/runtime/compiler/ilgen/J9ByteCodeIlGenerator.hpp +++ b/runtime/compiler/ilgen/J9ByteCodeIlGenerator.hpp @@ -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 @@ -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& listOfOffsets); +#endif + bool hasFPU(); // data From 1988428a74712cb18e3502185d0aafcac5537a5a Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 11:31:20 -0500 Subject: [PATCH 02/10] Read globalreference after acquire vmaccess After JITClient receives the globalreference from JITServer, we need to obtain vmaccess before we dereference it. Signed-off-by: Harry Yu --- .../control/JITClientCompilationThread.cpp | 53 ++++++++++--------- runtime/compiler/env/j9method.cpp | 8 ++- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index 61ebc4173c3..dd9f009ab52 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -2065,6 +2065,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_derefUintptrjPtr: { + // should not be used anymore TR::VMAccessCriticalSection deref(fe); compInfoPT->updateLastLocalGCCounter(); client->write(response, *std::get<0>(client->getRecvData())); @@ -2072,8 +2073,8 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeILGenMacrosInvokeExactAndFixup: { - TR::VMAccessCriticalSection invokeILGenMacrosInvokeExactAndFixup(fe); auto recv = client->getRecvData >(); + TR::VMAccessCriticalSection invokeILGenMacrosInvokeExactAndFixup(fe); uintptrj_t receiverHandle = *std::get<0>(recv); std::vector listOfOffsets = std::get<1>(recv); uintptrj_t methodHandle = listOfOffsets.size() == 0 ? receiverHandle : JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); @@ -2090,9 +2091,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes case MessageType::runFEMacro_invokeCollectHandleNumArgsToCollect: { auto recv = client->getRecvData(); + TR::VMAccessCriticalSection invokeCollectHandleNumArgsToCollect(fe); uintptrj_t methodHandle = *std::get<0>(recv); bool getPos = std::get<1>(recv); - TR::VMAccessCriticalSection invokeCollectHandleNumArgsToCollect(fe); int32_t collectArraySize = fe->getInt32Field(methodHandle, "collectArraySize"); uintptrj_t arguments = fe->getReferenceField( fe->getReferenceField(methodHandle, "type", "Ljava/lang/invoke/MethodType;"), @@ -2135,9 +2136,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes case MessageType::runFEMacro_targetTypeL: { auto recv = client->getRecvData(); - int32_t argIndex = std::get<1>(recv); TR::VMAccessCriticalSection targetTypeL(fe); uintptrj_t methodHandle = *std::get<0>(recv); + int32_t argIndex = std::get<1>(recv); uintptrj_t targetArguments = fe->getReferenceField(fe->getReferenceField(fe->getReferenceField( methodHandle, "next", "Ljava/lang/invoke/MethodHandle;"), @@ -2186,8 +2187,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeSpreadHandleArrayArg: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeSpreadHandleArrayArg(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t arrayClass = fe->getReferenceField(methodHandle, "arrayClass", "Ljava/lang/Class;"); J9ArrayClass *arrayJ9Class = (J9ArrayClass*)(intptrj_t)fe->getInt64Field(arrayClass, "vmRef" /* should use fej9->getOffsetOfClassFromJavaLangClassField() */); @@ -2207,10 +2209,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes case MessageType::runFEMacro_invokeSpreadHandle: { auto recv = client->getRecvData(); + TR::VMAccessCriticalSection invokeSpreadHandle(fe); uintptrj_t methodHandle = *std::get<0>(recv); bool getSpreadPosition = std::get<1>(recv); - - TR::VMAccessCriticalSection invokeSpreadHandle(fe); uintptrj_t arguments = fe->getReferenceField(fe->methodHandle_type(methodHandle), "arguments", "[Ljava/lang/Class;"); int32_t numArguments = (int32_t)fe->getArrayLengthInElements(arguments); uintptrj_t next = fe->getReferenceField(methodHandle, "next", "Ljava/lang/invoke/MethodHandle;"); @@ -2225,8 +2226,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeInsertHandle: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeInsertHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); int32_t insertionIndex = fe->getInt32Field(methodHandle, "insertionIndex"); uintptrj_t arguments = fe->getReferenceField(fe->getReferenceField(methodHandle, "type", "Ljava/lang/invoke/MethodType;"), "arguments", "[Ljava/lang/Class;"); @@ -2238,8 +2240,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeFoldHandle: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeFoldHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t argIndices = fe->getReferenceField(methodHandle, "argumentIndices", "[I"); int32_t arrayLength = (int32_t)fe->getArrayLengthInElements(argIndices); int32_t foldPosition = fe->getInt32Field(methodHandle, "foldPosition"); @@ -2264,16 +2267,18 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeFoldHandle2: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeFoldHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); int32_t foldPosition = fe->getInt32Field(methodHandle, "foldPosition"); client->write(response, foldPosition); } break; case MessageType::runFEMacro_invokeFinallyHandle: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeFinallyHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t finallyTarget = fe->getReferenceField(methodHandle, "finallyTarget", "Ljava/lang/invoke/MethodHandle;"); uintptrj_t finallyType = fe->getReferenceField(finallyTarget, "type", "Ljava/lang/invoke/MethodType;"); uintptrj_t arguments = fe->getReferenceField(finallyType, "arguments", "[Ljava/lang/Class;"); @@ -2288,9 +2293,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeFilterArgumentsHandle: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeFilterArgumentsHandle(fe); - + uintptrj_t methodHandle = *std::get<0>(recv); int32_t startPos = (int32_t)fe->getInt32Field(methodHandle, "startPos"); uintptrj_t filters = fe->getReferenceField(methodHandle, "filters", "[Ljava/lang/invoke/MethodHandle;"); @@ -2315,8 +2320,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeFilterArgumentsHandle2: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeFilderArgumentsHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t arguments = fe->getReferenceField(fe->methodHandle_type(methodHandle), "arguments", "[Ljava/lang/Class;"); int32_t numArguments = (int32_t)fe->getArrayLengthInElements(arguments); int32_t startPos = (int32_t)fe->getInt32Field(methodHandle, "startPos"); @@ -2327,8 +2333,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeCatchHandle: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeCatchHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t catchTarget = fe->getReferenceField(methodHandle, "catchTarget", "Ljava/lang/invoke/MethodHandle;"); uintptrj_t catchArguments = fe->getReferenceField(fe->getReferenceField( catchTarget, @@ -2340,8 +2347,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeArgumentMoverHandlePermuteArgs: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokeArgumentMoverHandlePermuteArgs(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t methodDescriptorRef = fe->getReferenceField(fe->getReferenceField(fe->getReferenceField( methodHandle, "next", "Ljava/lang/invoke/MethodHandle;"), @@ -2355,8 +2363,9 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokePermuteHandlePermuteArgs: { - uintptrj_t methodHandle = *std::get<0>(client->getRecvData()); + auto recv = client->getRecvData(); TR::VMAccessCriticalSection invokePermuteHandlePermuteArgs(fe); + uintptrj_t methodHandle = *std::get<0>(recv); uintptrj_t permuteArray = fe->getReferenceField(methodHandle, "permute", "[I"); int32_t permuteLength = fe->getArrayLengthInElements(permuteArray); std::vector argIndices(permuteLength); @@ -2369,15 +2378,11 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::runFEMacro_invokeILGenMacros: { - if (compInfoPT->getLastLocalGCCounter() != compInfoPT->getCompilationInfo()->getLocalGCCounter()) - { - // GC happened, fail compilation - auto comp = compInfoPT->getCompilation(); - comp->failCompilation("Compilation interrupted due to GC"); - } - - uintptrj_t methodHandle = std::get<0>(client->getRecvData()); + auto recv = client->getRecvData >(); TR::VMAccessCriticalSection invokeILGenMacros(fe); + uintptrj_t receiverHandle = *std::get<0>(recv); + std::vector listOfOffsets = std::get<1>(recv); + uintptrj_t methodHandle = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); uintptrj_t arguments = fe->getReferenceField(fe->getReferenceField( methodHandle, "type", "Ljava/lang/invoke/MethodType;"), diff --git a/runtime/compiler/env/j9method.cpp b/runtime/compiler/env/j9method.cpp index 77f2a3721f1..f56aea0481c 100644 --- a/runtime/compiler/env/j9method.cpp +++ b/runtime/compiler/env/j9method.cpp @@ -9053,11 +9053,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 methodHandle = walkReferenceChain(pop(), receiverHandle); - - stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacros, methodHandle); + std::vector listOfOffsets; + packReferenceChainOffsets(pop(), listOfOffsets); + stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacros, thunkDetails->getHandleRef(), listOfOffsets); parameterCount = std::get<0>(stream->read()); } else From d4756331210ee9f4a807ee9323ab4b31847ac564 Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 11:56:30 -0500 Subject: [PATCH 03/10] Update all JITServer walkReferenceChain There are 4 instances where JITServer incorrectly uses the walkReferenceChain routine. Update them to the new implementation. Signed-off-by: Harry Yu --- .../control/JITClientCompilationThread.cpp | 28 +++++++++++++++++-- runtime/compiler/env/j9method.cpp | 18 ++++++------ runtime/compiler/net/protos/compile.proto | 6 ++-- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index dd9f009ab52..b0842017c2f 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -2376,10 +2376,10 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes client->write(response, permuteLength, argIndices); } break; - case MessageType::runFEMacro_invokeILGenMacros: + case MessageType::runFEMacro_invokeILGenMacrosParameterCount: { auto recv = client->getRecvData >(); - TR::VMAccessCriticalSection invokeILGenMacros(fe); + TR::VMAccessCriticalSection invokeILGenMacrosParameterCount(fe); uintptrj_t receiverHandle = *std::get<0>(recv); std::vector listOfOffsets = std::get<1>(recv); uintptrj_t methodHandle = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); @@ -2391,7 +2391,29 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes client->write(response, parameterCount); } break; - + case MessageType::runFEMacro_invokeILGenMacrosArrayLength: + { + auto recv = client->getRecvData >(); + TR::VMAccessCriticalSection invokeILGenMacrosArrayLength(fe); + uintptrj_t receiverHandle = *std::get<0>(recv); + std::vector listOfOffsets = std::get<1>(recv); + uintptrj_t array = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); + int32_t arrayLength = (int32_t)fej9->getArrayLengthInElements(array); + client->write(response, arrayLength); + } + break; + case MessageType::runFEMacro_invokeILGenMacrosGetField: + { + auto recv = client->getRecvData >(); + TR::VMAccessCriticalSection invokeILGenMacrosGetField(fe); + uintptrj_t receiverHandle = *std::get<0>(recv); + uintptrj_t fieldOffset = std::get<1>(recv); + std::vector listOfOffsets = std::get<2>(recv); + uintptrj_t baseObject = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); + int32_t result = fej9->getInt32FieldAt(baseObject, fieldOffset);; + client->write(response, result); + } + break; case MessageType::CHTable_getAllClassInfo: { client->getRecvData(); diff --git a/runtime/compiler/env/j9method.cpp b/runtime/compiler/env/j9method.cpp index f56aea0481c..87e3c2d61c0 100644 --- a/runtime/compiler/env/j9method.cpp +++ b/runtime/compiler/env/j9method.cpp @@ -9055,7 +9055,7 @@ TR_J9ByteCodeIlGenerator::runFEMacro(TR::SymbolReference *symRef) auto stream = TR::CompilationInfo::getStream(); std::vector listOfOffsets; packReferenceChainOffsets(pop(), listOfOffsets); - stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacros, thunkDetails->getHandleRef(), listOfOffsets); + stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosParameterCount, thunkDetails->getHandleRef(), listOfOffsets); parameterCount = std::get<0>(stream->read()); } else @@ -9086,10 +9086,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 array = walkReferenceChain(pop(), receiverHandle); - arrayLength = (int32_t)fej9->getArrayLengthInElements(array); + std::vector listOfOffsets; + packReferenceChainOffsets(pop(), listOfOffsets); + stream->write(JITServer::MessageType::runFEMacro_invokeILGenMacrosArrayLength, thunkDetails->getHandleRef(), listOfOffsets); + arrayLength = std::get<0>(stream->read()); } else #endif /* defined(JITSERVER_SUPPORT) */ @@ -9123,11 +9123,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 baseObject = walkReferenceChain(baseObjectNode, receiverHandle); + std::vector 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()); } else #endif /* defined(JITSERVER_SUPPORT) */ diff --git a/runtime/compiler/net/protos/compile.proto b/runtime/compiler/net/protos/compile.proto index f0e8dcc2638..544a0fcf0e0 100644 --- a/runtime/compiler/net/protos/compile.proto +++ b/runtime/compiler/net/protos/compile.proto @@ -281,8 +281,10 @@ 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_derefUintptrjPtr = 720; // for JITServerPersistentCHTable CHTable_getAllClassInfo = 800; From 42f4a748a46397408589bc97b375c2ca7f0203e3 Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 12:03:51 -0500 Subject: [PATCH 04/10] Remove JITServer runFEMacro_derefUintptrjPtr API This messageType has been eliminated by the JITServer walkReferenceChain routine. Signed-off-by: Harry Yu --- .../compiler/control/JITClientCompilationThread.cpp | 12 ++---------- runtime/compiler/net/protos/compile.proto | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index b0842017c2f..4dfb3c5c729 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -2063,14 +2063,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes client->write(response, ptr); } break; - case MessageType::runFEMacro_derefUintptrjPtr: - { - // should not be used anymore - TR::VMAccessCriticalSection deref(fe); - compInfoPT->updateLastLocalGCCounter(); - client->write(response, *std::get<0>(client->getRecvData())); - } - break; case MessageType::runFEMacro_invokeILGenMacrosInvokeExactAndFixup: { auto recv = client->getRecvData >(); @@ -2398,7 +2390,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes uintptrj_t receiverHandle = *std::get<0>(recv); std::vector listOfOffsets = std::get<1>(recv); uintptrj_t array = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); - int32_t arrayLength = (int32_t)fej9->getArrayLengthInElements(array); + int32_t arrayLength = (int32_t)fe->getArrayLengthInElements(array); client->write(response, arrayLength); } break; @@ -2410,7 +2402,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes uintptrj_t fieldOffset = std::get<1>(recv); std::vector listOfOffsets = std::get<2>(recv); uintptrj_t baseObject = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); - int32_t result = fej9->getInt32FieldAt(baseObject, fieldOffset);; + int32_t result = fe->getInt32FieldAt(baseObject, fieldOffset); client->write(response, result); } break; diff --git a/runtime/compiler/net/protos/compile.proto b/runtime/compiler/net/protos/compile.proto index 544a0fcf0e0..c91eaba777e 100644 --- a/runtime/compiler/net/protos/compile.proto +++ b/runtime/compiler/net/protos/compile.proto @@ -284,7 +284,6 @@ enum MessageType runFEMacro_invokeILGenMacrosParameterCount = 717; runFEMacro_invokeILGenMacrosArrayLength = 718; runFEMacro_invokeILGenMacrosGetField = 719; - runFEMacro_derefUintptrjPtr = 720; // for JITServerPersistentCHTable CHTable_getAllClassInfo = 800; From 43692796317cded59420aec08263ded1034f8eaa Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 13:57:49 -0500 Subject: [PATCH 05/10] Remove the JITServer LocalGCCounter hack Now that walkReferenceChain is handled properly on JITServer and JITClient, the LocalGCCOunter hack, which does not cover all cases and not an efficient workaround, should be removed. Signed-off-by: Harry Yu --- runtime/compiler/control/CompilationRuntime.hpp | 2 -- runtime/compiler/control/CompilationThread.cpp | 8 -------- runtime/compiler/control/CompilationThread.hpp | 3 --- runtime/compiler/control/HookedByTheJit.cpp | 5 ----- .../control/JITClientCompilationThread.cpp | 14 -------------- 5 files changed, 32 deletions(-) diff --git a/runtime/compiler/control/CompilationRuntime.hpp b/runtime/compiler/control/CompilationRuntime.hpp index 44386e9d452..d774d5ab545 100644 --- a/runtime/compiler/control/CompilationRuntime.hpp +++ b/runtime/compiler/control/CompilationRuntime.hpp @@ -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 &getJITServerSslKeys() const { return _sslKeys; } void addJITServerSslKey(const std::string &key) { _sslKeys.push_back(key); } diff --git a/runtime/compiler/control/CompilationThread.cpp b/runtime/compiler/control/CompilationThread.cpp index 54efc7deee9..d0989d1582c 100644 --- a/runtime/compiler/control/CompilationThread.cpp +++ b/runtime/compiler/control/CompilationThread.cpp @@ -1049,8 +1049,6 @@ TR::CompilationInfoPerThread::CompilationInfoPerThread(TR::CompilationInfo &comp { _classesThatShouldNotBeNewlyExtended = NULL; } - - _lastLocalGCCounter = 0; #endif /* defined(JITSERVER_SUPPORT) */ } @@ -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. diff --git a/runtime/compiler/control/CompilationThread.hpp b/runtime/compiler/control/CompilationThread.hpp index 6d86a26f743..8cdaa3cf30e 100644 --- a/runtime/compiler/control/CompilationThread.hpp +++ b/runtime/compiler/control/CompilationThread.hpp @@ -393,8 +393,6 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase J9ROMClass *getAndCacheRemoteROMClass(J9Class *, TR_Memory *trMemory=NULL); J9ROMClass *getRemoteROMClassIfCached(J9Class *); PersistentUnorderedSet *getClassesThatShouldNotBeNewlyExtended() const { return _classesThatShouldNotBeNewlyExtended; } - uint32_t getLastLocalGCCounter() const { return _lastLocalGCCounter; } - void updateLastLocalGCCounter(); #endif /* defined(JITSERVER_SUPPORT) */ protected: @@ -418,7 +416,6 @@ class CompilationInfoPerThread : public TR::CompilationInfoPerThreadBase // The following hastable caches --> mappings // The cache only lives during a compilation due to class unloading concerns PersistentUnorderedSet *_classesThatShouldNotBeNewlyExtended; - uint32_t _lastLocalGCCounter; #endif /* defined(JITSERVER_SUPPORT) */ }; // CompilationInfoPerThread diff --git a/runtime/compiler/control/HookedByTheJit.cpp b/runtime/compiler/control/HookedByTheJit.cpp index fef9a49009f..2244749af99 100644 --- a/runtime/compiler/control/HookedByTheJit.cpp +++ b/runtime/compiler/control/HookedByTheJit.cpp @@ -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) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index 4dfb3c5c729..853a348bc3b 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -656,13 +656,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::VM_getInt32FieldAt: { - if (compInfoPT->getLastLocalGCCounter() != compInfoPT->getCompilationInfo()->getLocalGCCounter()) - { - // GC happened, fail compilation - auto comp = compInfoPT->getCompilation(); - comp->failCompilation("Compilation interrupted due to GC"); - } - auto recv = client->getRecvData(); uintptrj_t objectPointer = std::get<0>(recv); uintptrj_t fieldOffset = std::get<1>(recv); @@ -699,13 +692,6 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes break; case MessageType::VM_getArrayLengthInElements: { - if (compInfoPT->getLastLocalGCCounter() != compInfoPT->getCompilationInfo()->getLocalGCCounter()) - { - // GC happened, fail compilation - auto comp = compInfoPT->getCompilation(); - comp->failCompilation("Compilation interrupted due to GC"); - } - uintptrj_t objectPointer = std::get<0>(client->getRecvData()); client->write(response, fe->getArrayLengthInElements(objectPointer)); } From 4c6ddf7d6153bced67e980a82a42c575c695082c Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 14:03:10 -0500 Subject: [PATCH 06/10] Fix copyright issues Signed-off-by: Harry Yu --- runtime/compiler/control/CompilationRuntime.hpp | 2 +- runtime/compiler/control/CompilationThread.cpp | 2 +- runtime/compiler/control/CompilationThread.hpp | 2 +- runtime/compiler/net/protos/compile.proto | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/compiler/control/CompilationRuntime.hpp b/runtime/compiler/control/CompilationRuntime.hpp index d774d5ab545..67ebb84abae 100644 --- a/runtime/compiler/control/CompilationRuntime.hpp +++ b/runtime/compiler/control/CompilationRuntime.hpp @@ -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 diff --git a/runtime/compiler/control/CompilationThread.cpp b/runtime/compiler/control/CompilationThread.cpp index d0989d1582c..ba0ac26ea8f 100644 --- a/runtime/compiler/control/CompilationThread.cpp +++ b/runtime/compiler/control/CompilationThread.cpp @@ -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 diff --git a/runtime/compiler/control/CompilationThread.hpp b/runtime/compiler/control/CompilationThread.hpp index 8cdaa3cf30e..abeb5dc62f1 100644 --- a/runtime/compiler/control/CompilationThread.hpp +++ b/runtime/compiler/control/CompilationThread.hpp @@ -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 diff --git a/runtime/compiler/net/protos/compile.proto b/runtime/compiler/net/protos/compile.proto index c91eaba777e..92bd3919a98 100644 --- a/runtime/compiler/net/protos/compile.proto +++ b/runtime/compiler/net/protos/compile.proto @@ -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 From 73d4106211bcd3f38c97678e8c59e21f3fdc13c9 Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 14:19:25 -0500 Subject: [PATCH 07/10] Incrementing version number Signed-off-by: Harry Yu --- runtime/compiler/net/CommunicationStream.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/compiler/net/CommunicationStream.hpp b/runtime/compiler/net/CommunicationStream.hpp index 22c0b34dbf0..7c87651315f 100644 --- a/runtime/compiler/net/CommunicationStream.hpp +++ b/runtime/compiler/net/CommunicationStream.hpp @@ -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 @@ -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; }; From 2bac4a756d16934bb44f0bb64d46953d98daeeca Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Tue, 14 Jan 2020 15:40:40 -0500 Subject: [PATCH 08/10] Add runFEMacro JITServer Support This change handles the following 3 methods for JITServer: 1. java_lang_invoke_FilterArgumentsWithCombinerHandle_numSuffixArgs 2. java_lang_invoke_FilterArgumentsWithCombinerHandle_filterPosition 3. java_lang_invoke_FilterArgumentsWithCombinerHandle_argumentIndices Signed-off-by: Harry Yu --- .../control/JITClientCompilationThread.cpp | 35 +++++++++++++++++ runtime/compiler/env/j9method.cpp | 39 +++++++++++++++++++ runtime/compiler/net/protos/compile.proto | 3 ++ 3 files changed, 77 insertions(+) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index 853a348bc3b..a8e5bcc8b95 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -2252,6 +2252,30 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes client->write(response, foldPosition); } break; + case MessageType::runFEMacro_invokeFilterArgumentsWithCombinerHandleArgumentIndices: + { + auto recv = client->getRecvData(); + TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); + uintptrj_t argumentIndices = fe->getReferenceField(methodHandle, "argumentIndices", "[I"); + int32_t arrayLength = fe->getArrayLengthInElements(argumentIndices); + std::vector argIndices(arrayLength); + for (int i = arrayLength - 1; i >= 0; i--) + { + argIndices[i] = fe->getInt32Element(argumentIndices, i); + } + client->write(response, arrayLength, argIndices); + } + break; + case MessageType::runFEMacro_invokeFilterArgumentsWithCombinerHandleFilterPosition: + { + auto recv = client->getRecvData(); + TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); + int32_t filterPosition = fe->getInt32Field(methodHandle, "filterPosition"); + client->write(response, filterPosition); + } + break; case MessageType::runFEMacro_invokeFinallyHandle: { auto recv = client->getRecvData(); @@ -2269,6 +2293,17 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes client->write(response, numArgsPassToFinallyTarget, std::string(methodDescriptor, methodDescriptorLength)); } break; + case MessageType::runFEMacro_invokeFilterArgumentsWithCombinerHandleNumSuffixArgs: + { + auto recv = client->getRecvData(); + TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fe); + uintptrj_t methodHandle = *std::get<0>(recv); + uintptrj_t arguments = fe->getReferenceField(fe->methodHandle_type(methodHandle), "arguments", "[Ljava/lang/Class;"); + int32_t numArguments = (int32_t)fe->getArrayLengthInElements(arguments); + int32_t filterPos = (int32_t)fe->getInt32Field(methodHandle, "filterPosition"); + client->write(response, numArguments, filterPos); + } + break; case MessageType::runFEMacro_invokeFilterArgumentsHandle: { auto recv = client->getRecvData(); diff --git a/runtime/compiler/env/j9method.cpp b/runtime/compiler/env/j9method.cpp index 87e3c2d61c0..b0b20cdd03b 100644 --- a/runtime/compiler/env/j9method.cpp +++ b/runtime/compiler/env/j9method.cpp @@ -8630,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 arrayLength = std::get<0>(recv); + std::vector 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(); @@ -8683,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()); + } + else +#endif /* defined(JITSERVER_SUPPORT) */ { TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fej9); methodHandle = *thunkDetails->getHandleRef(); @@ -8788,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(); + numArguments = std::get<0>(recv); + filterPos = std::get<1>(recv); + } + else +#endif /* defined(JITSERVER_SUPPORT) */ { TR::VMAccessCriticalSection invokeFilterArgumentsWithCombinerHandle(fej9); methodHandle = *thunkDetails->getHandleRef(); diff --git a/runtime/compiler/net/protos/compile.proto b/runtime/compiler/net/protos/compile.proto index 92bd3919a98..d8b276ce802 100644 --- a/runtime/compiler/net/protos/compile.proto +++ b/runtime/compiler/net/protos/compile.proto @@ -284,6 +284,9 @@ enum MessageType runFEMacro_invokeILGenMacrosParameterCount = 717; runFEMacro_invokeILGenMacrosArrayLength = 718; runFEMacro_invokeILGenMacrosGetField = 719; + runFEMacro_invokeFilterArgumentsWithCombinerHandleNumSuffixArgs = 720; + runFEMacro_invokeFilterArgumentsWithCombinerHandleFilterPosition = 721; + runFEMacro_invokeFilterArgumentsWithCombinerHandleArgumentIndices = 722; // for JITServerPersistentCHTable CHTable_getAllClassInfo = 800; From c963b8c885395d8f89b693416870dcc548523a1f Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Thu, 16 Jan 2020 11:31:11 -0500 Subject: [PATCH 09/10] Make listOfOffsets const vector reference Signed-off-by: Harry Yu --- runtime/compiler/control/JITClientCompilationThread.cpp | 8 ++++---- runtime/compiler/control/JITServerHelpers.cpp | 2 +- runtime/compiler/control/JITServerHelpers.hpp | 2 +- runtime/compiler/env/j9method.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index a8e5bcc8b95..1ad31809092 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -2054,7 +2054,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes auto recv = client->getRecvData >(); TR::VMAccessCriticalSection invokeILGenMacrosInvokeExactAndFixup(fe); uintptrj_t receiverHandle = *std::get<0>(recv); - std::vector listOfOffsets = std::get<1>(recv); + const std::vector& listOfOffsets = std::get<1>(recv); uintptrj_t methodHandle = listOfOffsets.size() == 0 ? receiverHandle : JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); uintptrj_t methodDescriptorRef = fe->getReferenceField(fe->getReferenceField( methodHandle, @@ -2394,7 +2394,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes auto recv = client->getRecvData >(); TR::VMAccessCriticalSection invokeILGenMacrosParameterCount(fe); uintptrj_t receiverHandle = *std::get<0>(recv); - std::vector listOfOffsets = std::get<1>(recv); + const std::vector& listOfOffsets = std::get<1>(recv); uintptrj_t methodHandle = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); uintptrj_t arguments = fe->getReferenceField(fe->getReferenceField( methodHandle, @@ -2409,7 +2409,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes auto recv = client->getRecvData >(); TR::VMAccessCriticalSection invokeILGenMacrosArrayLength(fe); uintptrj_t receiverHandle = *std::get<0>(recv); - std::vector listOfOffsets = std::get<1>(recv); + const std::vector& listOfOffsets = std::get<1>(recv); uintptrj_t array = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); int32_t arrayLength = (int32_t)fe->getArrayLengthInElements(array); client->write(response, arrayLength); @@ -2421,7 +2421,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes TR::VMAccessCriticalSection invokeILGenMacrosGetField(fe); uintptrj_t receiverHandle = *std::get<0>(recv); uintptrj_t fieldOffset = std::get<1>(recv); - std::vector listOfOffsets = std::get<2>(recv); + const std::vector& listOfOffsets = std::get<2>(recv); uintptrj_t baseObject = JITServerHelpers::walkReferenceChainWithOffsets(fe, listOfOffsets, receiverHandle); int32_t result = fe->getInt32FieldAt(baseObject, fieldOffset); client->write(response, result); diff --git a/runtime/compiler/control/JITServerHelpers.cpp b/runtime/compiler/control/JITServerHelpers.cpp index 8612a8b6aca..15aadbb7889 100644 --- a/runtime/compiler/control/JITServerHelpers.cpp +++ b/runtime/compiler/control/JITServerHelpers.cpp @@ -553,7 +553,7 @@ JITServerHelpers::isAddressInROMClass(const void *address, const J9ROMClass *rom uintptrj_t -JITServerHelpers::walkReferenceChainWithOffsets(TR_J9VM * fe, std::vector& listOfOffsets, uintptrj_t receiver) +JITServerHelpers::walkReferenceChainWithOffsets(TR_J9VM * fe, const std::vector& listOfOffsets, uintptrj_t receiver) { uintptrj_t result = receiver; for (size_t i = 0; i < listOfOffsets.size(); i++) diff --git a/runtime/compiler/control/JITServerHelpers.hpp b/runtime/compiler/control/JITServerHelpers.hpp index b6cb7591abc..3cacfbc67a1 100644 --- a/runtime/compiler/control/JITServerHelpers.hpp +++ b/runtime/compiler/control/JITServerHelpers.hpp @@ -97,7 +97,7 @@ class JITServerHelpers static bool isAddressInROMClass(const void *address, const J9ROMClass *romClass); - static uintptrj_t walkReferenceChainWithOffsets(TR_J9VM * fe, std::vector& listOfOffsets, uintptrj_t receiver); + static uintptrj_t walkReferenceChainWithOffsets(TR_J9VM * fe, const std::vector& listOfOffsets, uintptrj_t receiver); private: static void getROMClassData(const ClientSessionData::ClassInfo &classInfo, ClassInfoDataType dataType, void *data); diff --git a/runtime/compiler/env/j9method.cpp b/runtime/compiler/env/j9method.cpp index b0b20cdd03b..d47f5a63c60 100644 --- a/runtime/compiler/env/j9method.cpp +++ b/runtime/compiler/env/j9method.cpp @@ -9220,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 @@ -9262,7 +9262,7 @@ TR_J9ByteCodeIlGenerator::packReferenceChainOffsets(TR::Node *node, std::vector< } 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(); packReferenceChainOffsets(node->getFirstChild(), listOfOffsets); listOfOffsets.push_back(fieldOffset); } From cd54e6009d7fc5f59cbf541022d8be29d090e0a6 Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Thu, 16 Jan 2020 14:05:08 -0500 Subject: [PATCH 10/10] Acquire VMAccess for various JITClient APIs Signed-off-by: Harry Yu --- runtime/compiler/control/JITClientCompilationThread.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/compiler/control/JITClientCompilationThread.cpp b/runtime/compiler/control/JITClientCompilationThread.cpp index 1ad31809092..a53c6514e04 100644 --- a/runtime/compiler/control/JITClientCompilationThread.cpp +++ b/runtime/compiler/control/JITClientCompilationThread.cpp @@ -659,6 +659,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes auto recv = client->getRecvData(); uintptrj_t objectPointer = std::get<0>(recv); uintptrj_t fieldOffset = std::get<1>(recv); + TR::VMAccessCriticalSection getInt32FieldAt(fe); client->write(response, fe->getInt32FieldAt(objectPointer, fieldOffset)); } break; @@ -667,6 +668,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes auto recv = client->getRecvData(); uintptrj_t objectPointer = std::get<0>(recv); uintptrj_t fieldOffset = std::get<1>(recv); + TR::VMAccessCriticalSection getInt64FieldAt(fe); client->write(response, fe->getInt64FieldAt(objectPointer, fieldOffset)); } break; @@ -693,6 +695,7 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes case MessageType::VM_getArrayLengthInElements: { uintptrj_t objectPointer = std::get<0>(client->getRecvData()); + TR::VMAccessCriticalSection getArrayLengthInElements(fe); client->write(response, fe->getArrayLengthInElements(objectPointer)); } break;