Skip to content

Commit

Permalink
Port j9methodServer from jitaas to master (#7151)
Browse files Browse the repository at this point in the history
Port j9methodServer from jitaas to master
  • Loading branch information
mpirvu committed Sep 20, 2019
2 parents ad592a0 + 6cbd24a commit 18580e3
Show file tree
Hide file tree
Showing 15 changed files with 3,248 additions and 93 deletions.
1 change: 1 addition & 0 deletions runtime/compiler/build/files/common.mk
Expand Up @@ -385,6 +385,7 @@ ifneq ($(JITSERVER_SUPPORT),)
JIT_PRODUCT_SOURCE_FILES+=\
compiler/control/JITServerCompilationThread.cpp \
compiler/control/JITServerHelpers.cpp \
compiler/env/j9methodServer.cpp \
compiler/net/ClientStream.cpp \
compiler/net/CommunicationStream.cpp \
compiler/net/ProtobufTypeConvert.cpp \
Expand Down
23 changes: 23 additions & 0 deletions runtime/compiler/control/J9Recompilation.cpp
Expand Up @@ -31,6 +31,9 @@
#include "env/VMJ9.h"
#include "runtime/J9Profiler.hpp"
#include "exceptions/RuntimeFailure.hpp"
#if defined(JITSERVER_SUPPORT)
#include "control/JITServerCompilationThread.hpp"
#endif

bool J9::Recompilation::_countingSupported = false;

Expand Down Expand Up @@ -717,3 +720,23 @@ TR_PersistentMethodInfo::setForSharedInfo(TR_PersistentProfileInfo** ptr, TR_Per
if (oldPtr)
TR_PersistentProfileInfo::decRefCount((TR_PersistentProfileInfo*)oldPtr);
}

#if defined(JITSERVER_SUPPORT)
TR_PersistentJittedBodyInfo *
J9::Recompilation::persistentJittedBodyInfoFromString(const std::string &bodyInfoStr, const std::string &methodInfoStr, TR_Memory *trMemory)
{
auto bodyInfo = (TR_PersistentJittedBodyInfo*) trMemory->allocateHeapMemory(sizeof(TR_PersistentJittedBodyInfo), TR_MemoryBase::Recompilation);
auto methodInfo = (TR_PersistentMethodInfo*) trMemory->allocateHeapMemory(sizeof(TR_PersistentMethodInfo), TR_MemoryBase::Recompilation);
memcpy(bodyInfo, &bodyInfoStr[0], sizeof(TR_PersistentJittedBodyInfo));
memcpy(methodInfo, &methodInfoStr[0], sizeof(TR_PersistentMethodInfo));
bodyInfo->setMethodInfo(methodInfo);
bodyInfo->setProfileInfo(NULL);
bodyInfo->setMapTable(NULL);
methodInfo->setOptimizationPlan(NULL);
// cannot use setter because it calls the destructor on the old profile data,
// which is a client pointer
methodInfo->_recentProfileInfo = NULL;
methodInfo->_bestProfileInfo = NULL;
return bodyInfo;
}
#endif
6 changes: 5 additions & 1 deletion runtime/compiler/control/J9Recompilation.hpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 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 @@ -130,6 +130,10 @@ class Recompilation : public OMR::RecompilationConnector
static int32_t jitGlobalSampleCount;
static int32_t jitRecompilationsInduced;

#if defined(JITSERVER_SUPPORT)
static TR_PersistentJittedBodyInfo * persistentJittedBodyInfoFromString(const std::string &bodyInfoStr, const std::string &methodInfoStr, TR_Memory * trMemory);
#endif

protected:

virtual TR_PersistentMethodInfo *getExistingMethodInfo(TR_ResolvedMethod *method);
Expand Down
209 changes: 207 additions & 2 deletions runtime/compiler/control/JITServerCompilationThread.cpp
Expand Up @@ -49,7 +49,7 @@ TR::CompilationInfoPerThreadRemote::CompilationInfoPerThreadRemote(TR::Compilati
{}

/**
* Code to be executed on the JITServer to store bytecode iprofiler info to heap memory (instead of to persistent memory)
* @brief Method executed by JITServer to store bytecode iprofiler info to heap memory (instead of to persistent memory)
*
* @param method J9Method in question
* @param byteCodeIndex bytecode in question
Expand Down Expand Up @@ -84,7 +84,7 @@ TR::CompilationInfoPerThreadRemote::cacheIProfilerInfo(TR_OpaqueMethodBlock *met
}

/**
* Code to be executed on the JITServer to retrieve bytecode iprofiler info from the heap memory
* @brief Method executed by JITServer to retrieve bytecode iprofiler info from the heap memory
*
* @param method J9Method in question
* @param byteCodeIndex bytecode in question
Expand All @@ -110,6 +110,119 @@ TR::CompilationInfoPerThreadRemote::getCachedIProfilerInfo(TR_OpaqueMethodBlock
return ipEntry;
}

/**
* @brief Method executed by JITServer to cache a resolved method to the resolved method cache
*
* @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 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, TR_ResolvedJ9JITServerMethodInfo &methodInfo)
{
static bool useCaching = !feGetEnv("TR_DisableResolvedMethodsCaching");
if (!useCaching)
return;

cacheToPerCompilationMap(_resolvedMethodInfoMap, key, {method, vTableSlot, methodInfo});
}

/**
* @brief Method executed by JITServer to retrieve a resolved method from the resolved method cache
*
* @param key Identifier used to identify a resolved method in resolved methods cache
* @param owningMethod Owning method of the resolved method of interest
* @param resolvedMethod The resolved method of interest, set by this API
* @param unresolvedInCP The unresolvedInCP boolean value of interest, set by this API
* @return returns true if method is cached, sets resolvedMethod and unresolvedInCP to cached values, false otherwise.
*/
bool
TR::CompilationInfoPerThreadRemote::getCachedResolvedMethod(TR_ResolvedMethodKey key, TR_ResolvedJ9JITServerMethod *owningMethod, TR_ResolvedMethod **resolvedMethod, bool *unresolvedInCP)
{
TR_ResolvedMethodCacheEntry methodCacheEntry;
if (getCachedValueFromPerCompilationMap(_resolvedMethodInfoMap, key, methodCacheEntry))
{
auto comp = getCompilation();
TR_OpaqueMethodBlock *method = methodCacheEntry.method;
if (!method)
{
*resolvedMethod = NULL;
return true;
}
auto methodInfo = methodCacheEntry.methodInfo;
uint32_t vTableSlot = methodCacheEntry.vTableSlot;


// Re-add validation record
if (comp->compileRelocatableCode() && comp->getOption(TR_UseSymbolValidationManager) && !comp->getSymbolValidationManager()->inHeuristicRegion())
{
if(!owningMethod->addValidationRecordForCachedResolvedMethod(key, method))
{
// Could not add a validation record
*resolvedMethod = NULL;
if (unresolvedInCP)
*unresolvedInCP = true;
return true;
}
}
// Create resolved method from cached method info
if (key.type != TR_ResolvedMethodType::VirtualFromOffset)
{
*resolvedMethod = owningMethod->createResolvedMethodFromJ9Method(
comp,
key.cpIndex,
vTableSlot,
(J9Method *) method,
unresolvedInCP,
NULL,
methodInfo);
}
else
{
if (_vm->isAOT_DEPRECATED_DO_NOT_USE())
*resolvedMethod = method ? new (comp->trHeapMemory()) TR_ResolvedRelocatableJ9JITServerMethod(method, _vm, comp->trMemory(), methodInfo, owningMethod) : 0;
else
*resolvedMethod = method ? new (comp->trHeapMemory()) TR_ResolvedJ9JITServerMethod(method, _vm, comp->trMemory(), methodInfo, owningMethod) : 0;
}

if (*resolvedMethod)
{
if (unresolvedInCP)
*unresolvedInCP = false;
return true;
}
else
{
TR_ASSERT(false, "Should not have cached unresolved method globally");
}
}
return false;
}

/**
* @brief Method executed by JITServer to compose a TR_ResolvedMethodKey used for the resolved method cache
*
* @param type Resolved method type: VirtualFromCP, VirtualFromOffset, Interface, Static, Special, ImproperInterface, NoType
* @param ramClass ramClass of resolved method of interest
* @param cpIndex constant pool index
* @param classObject default to NULL, only set for resolved interface method
* @return key used to identify a resolved method in the resolved method cache
*/
TR_ResolvedMethodKey
TR::CompilationInfoPerThreadRemote::getResolvedMethodKey(TR_ResolvedMethodType type, TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_OpaqueClassBlock *classObject)
{
TR_ResolvedMethodKey key = {type, ramClass, cpIndex, classObject};
return key;
}

/**
* @brief Method executed by JITServer to save the mirrors of resolved method of interest to a list
*
* @param resolvedMethod The mirror of the resolved method of interest (existing at JITClient)
* @return void
*/
void
TR::CompilationInfoPerThreadRemote::cacheResolvedMirrorMethodsPersistIPInfo(TR_ResolvedJ9Method *resolvedMethod)
{
Expand All @@ -122,3 +235,95 @@ TR::CompilationInfoPerThreadRemote::cacheResolvedMirrorMethodsPersistIPInfo(TR_R

_resolvedMirrorMethodsPersistIPInfo->push_back(resolvedMethod);
}

/**
* @brief Method executed by JITServer to remember NULL answers for classOfStatic() queries
*
* @param ramClass The static class of interest as part of the key
* @param cpIndex The constant pool index of interest as part of the key
* @return void
*/
void
TR::CompilationInfoPerThreadRemote::cacheNullClassOfStatic(TR_OpaqueClassBlock *ramClass, int32_t cpIndex)
{
TR_OpaqueClassBlock *nullClazz = NULL;
cacheToPerCompilationMap(_classOfStaticMap, std::make_pair(ramClass, cpIndex), nullClazz);
}

/**
* @brief Method executed by JITServer to determine if a previous classOfStatic() query returned NULL
*
* @param ramClass The static class of interest
* @param cpIndex The constant pool index of interest
* @return returns true if the previous classOfStatic() query returned NULL and false otherwise
*/
bool
TR::CompilationInfoPerThreadRemote::getCachedNullClassOfStatic(TR_OpaqueClassBlock *ramClass, int32_t cpIndex)
{
TR_OpaqueClassBlock *nullClazz;
return getCachedValueFromPerCompilationMap(_classOfStaticMap, std::make_pair(ramClass, cpIndex), nullClazz);
}

/**
* @brief Method executed by JITServer to cache field or static attributes
*
* @param ramClass The ramClass of interest as part of the key
* @param cpIndex The cpIndex of interest as part of the key
* @param attrs The value we are going to cache
* @param isStatic Whether the field is static
* @return void
*/
void
TR::CompilationInfoPerThreadRemote::cacheFieldOrStaticAttributes(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, const TR_J9MethodFieldAttributes &attrs, bool isStatic)
{
if (isStatic)
cacheToPerCompilationMap(_staticAttributesCache, std::make_pair(ramClass, cpIndex), attrs);
else
cacheToPerCompilationMap(_fieldAttributesCache, std::make_pair(ramClass, cpIndex), attrs);
}

/**
* @brief Method executed by JITServer to retrieve field or static attributes from the cache
*
* @param ramClass The ramClass of interest as part of the key
* @param cpIndex The cpIndex of interest as part of the value
* @param attrs The value to be set by the API
* @param isStatic Whether the field is static
* @return returns true if found in cache else false
*/
bool
TR::CompilationInfoPerThreadRemote::getCachedFieldOrStaticAttributes(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_J9MethodFieldAttributes &attrs, bool isStatic)
{
if (isStatic)
return getCachedValueFromPerCompilationMap(_staticAttributesCache, std::make_pair(ramClass, cpIndex), attrs);
else
return getCachedValueFromPerCompilationMap(_fieldAttributesCache, std::make_pair(ramClass, cpIndex), attrs);
}

/**
* @brief Method executed by JITServer to cache unresolved string
*
* @param ramClass The ramClass of interest as part of the key
* @param cpIndex The cpIndex of interest as part of the key
* @param stringAttrs The value we are going to cache
* @return void
*/
void
TR::CompilationInfoPerThreadRemote::cacheIsUnresolvedStr(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, const TR_IsUnresolvedString &stringAttrs)
{
cacheToPerCompilationMap(_isUnresolvedStrCache, std::make_pair(ramClass, cpIndex), stringAttrs);
}

/**
* @brief Method executed by JITServer to retrieve unresolved string
*
* @param ramClass The ramClass of interest as part of the key
* @param cpIndex The cpIndex of interest as part of the key
* @param attrs The value to be set by the API
* @return returns true if found in cache else false
*/
bool
TR::CompilationInfoPerThreadRemote::getCachedIsUnresolvedStr(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_IsUnresolvedString &stringAttrs)
{
return getCachedValueFromPerCompilationMap(_isUnresolvedStrCache, std::make_pair(ramClass, cpIndex), stringAttrs);
}
16 changes: 14 additions & 2 deletions runtime/compiler/control/JITServerCompilationThread.hpp
Expand Up @@ -24,11 +24,10 @@
#define JITSERVER_COMPILATION_THREAD_H

#include "control/CompilationThread.hpp"
#include "env/j9methodServer.hpp"
#include "runtime/JITClientSession.hpp"

class TR_IPBytecodeHashTableEntry;
class TR_ResolvedMethodInfoCache;
class TR_IsUnresolvedString;

using IPTableHeapEntry = UnorderedMap<uint32_t, TR_IPBytecodeHashTableEntry*>;
using IPTableHeap_t = UnorderedMap<J9Method *, IPTableHeapEntry *>;
Expand All @@ -50,9 +49,22 @@ 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, TR_ResolvedJ9JITServerMethodInfo &methodInfo);
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);

void cacheResolvedMirrorMethodsPersistIPInfo(TR_ResolvedJ9Method *resolvedMethod);
ResolvedMirrorMethodsPersistIP_t *getCachedResolvedMirrorMethodsPersistIPInfo() const { return _resolvedMirrorMethodsPersistIPInfo; }

void cacheNullClassOfStatic(TR_OpaqueClassBlock *ramClass, int32_t cpIndex);
bool getCachedNullClassOfStatic(TR_OpaqueClassBlock *ramClass, int32_t cpIndex);

void cacheFieldOrStaticAttributes(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, const TR_J9MethodFieldAttributes &attrs, bool isStatic);
bool getCachedFieldOrStaticAttributes(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_J9MethodFieldAttributes &attrs, bool isStatic);

void cacheIsUnresolvedStr(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, const TR_IsUnresolvedString &stringAttrs);
bool getCachedIsUnresolvedStr(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_IsUnresolvedString &stringAttrs);

private:
/* Template method for allocating a cache of type T on the heap.
* Cache pointer must be NULL.
Expand Down
11 changes: 0 additions & 11 deletions runtime/compiler/control/JITServerHelpers.cpp
Expand Up @@ -196,8 +196,6 @@ JITServerHelpers::cacheRemoteROMClass(ClientSessionData *clientSessionData, J9Cl
J9Method *methods = classInfoStruct._methodsOfClass;
classInfoStruct._baseComponentClass = std::get<2>(classInfo);
classInfoStruct._numDimensions = std::get<3>(classInfo);
classInfoStruct._remoteROMStringsCache = NULL;
classInfoStruct._fieldOrStaticNameCache = NULL;
classInfoStruct._parentClass = std::get<4>(classInfo);
auto &tmpInterfaces = std::get<5>(classInfo);
classInfoStruct._interfaces = new (PERSISTENT_NEW) PersistentVector<TR_OpaqueClassBlock *>
Expand All @@ -214,18 +212,9 @@ JITServerHelpers::cacheRemoteROMClass(ClientSessionData *clientSessionData, J9Cl
classInfoStruct._componentClass = std::get<14>(classInfo);
classInfoStruct._arrayClass = std::get<15>(classInfo);
classInfoStruct._totalInstanceSize = std::get<16>(classInfo);
classInfoStruct._classOfStaticCache = NULL;
classInfoStruct._constantClassPoolCache = NULL;
classInfoStruct._remoteRomClass = std::get<17>(classInfo);
classInfoStruct._fieldAttributesCache = NULL;
classInfoStruct._staticAttributesCache = NULL;
classInfoStruct._fieldAttributesCacheAOT = NULL;
classInfoStruct._staticAttributesCacheAOT = NULL;
classInfoStruct._constantPool = (J9ConstantPool *)std::get<18>(classInfo);
classInfoStruct._jitFieldsCache = NULL;
classInfoStruct._classFlags = std::get<19>(classInfo);
classInfoStruct._fieldOrStaticDeclaringClassCache = NULL;
classInfoStruct._J9MethodNameCache = NULL;
clientSessionData->getROMClassMap().insert({ clazz, classInfoStruct});

uint32_t numMethods = romClass->romMethodCount;
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/control/RecompilationInfo.hpp
Expand Up @@ -171,6 +171,7 @@ class TR_PersistentMethodInfo
uint16_t getTimeStamp() { return _timeStamp; }

TR_OptimizationPlan * getOptimizationPlan() {return _optimizationPlan;}
void setOptimizationPlan(TR_OptimizationPlan *optPlan) { _optimizationPlan = optPlan; }
uint8_t getNumberOfInvalidations() {return _numberOfInvalidations;}
void incrementNumberOfInvalidations() {_numberOfInvalidations++;}
uint8_t getNumberOfInlinedMethodRedefinition() {return _numberOfInlinedMethodRedefinition;}
Expand Down
8 changes: 7 additions & 1 deletion runtime/compiler/env/CMakeLists.txt
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2019 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 @@ -58,3 +58,9 @@ j9jit_files(
env/SystemSegmentProvider.cpp
env/VMJ9.cpp
)

if(JITSERVER_SUPPORT)
j9jit_files(
env/j9methodServer.cpp
)
endif()

0 comments on commit 18580e3

Please sign in to comment.