Skip to content

Commit

Permalink
Enable inlining of abstract methods in AOT
Browse files Browse the repository at this point in the history
Signed-off-by: Irwin D'Souza <[email protected]>
  • Loading branch information
Irwin D'Souza committed Sep 18, 2018
1 parent 91469b4 commit 6084fd6
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 10 deletions.
5 changes: 4 additions & 1 deletion runtime/compiler/arm/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ uint8_t *J9::ARM::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
case TR_InlinedVirtualMethod:
case TR_InlinedInterfaceMethodWithNopGuard:
case TR_InlinedInterfaceMethod:
case TR_InlinedAbstractMethodWithNopGuard:
case TR_InlinedHCRMethod:
{
guard = (TR_VirtualGuard *) relocation->getTargetAddress2();
Expand Down Expand Up @@ -450,7 +451,8 @@ uint8_t *J9::ARM::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
cursor += SIZEPOINTER;

if (relocation->getTargetKind() == TR_InlinedInterfaceMethodWithNopGuard ||
relocation->getTargetKind() == TR_InlinedInterfaceMethod)
relocation->getTargetKind() == TR_InlinedInterfaceMethod ||
relocation->getTargetKind() == TR_InlinedAbstractMethodWithNopGuard)
{
TR_InlinedCallSite *inlinedCallSite = &comp->getInlinedCallSite(inlinedSiteIndex);
TR_AOTMethodInfo *aotMethodInfo = (TR_AOTMethodInfo *) inlinedCallSite->_methodInfo;
Expand Down Expand Up @@ -759,6 +761,7 @@ uint32_t J9::ARM::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_Nu
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61
24, // TR_InlinedAbstractMethodWithNopGuard = 62,
};


Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ J9::AheadOfTimeCompile::dumpRelocationData()
case TR_InlinedSpecialMethodWithNopGuard:
case TR_InlinedVirtualMethodWithNopGuard:
case TR_InlinedInterfaceMethodWithNopGuard:
case TR_InlinedAbstractMethodWithNopGuard:
case TR_InlinedHCRMethod:
cursor++; // unused field
if (is64BitTarget)
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,8 @@ void TR::CompilationInfo::stopCompilationThreads()
fprintf(stderr, "numVirtualMethodsValidationSucceeded: %d\n", aotStats->virtualMethods.numSucceededValidations);
fprintf(stderr, "numInterfaceMethodsValidationFailed: %d\n", aotStats->interfaceMethods.numFailedValidations);
fprintf(stderr, "numInterfaceMethodsValidationSucceeded: %d\n", aotStats->interfaceMethods.numSucceededValidations);
fprintf(stderr, "numAbstractMethodsValidationFailed: %d\n", aotStats->abstractMethod.numFailedValidations);
fprintf(stderr, "numAbstractMethodsValidationSucceeded: %d\n", aotStats->abstractMethod.numSucceededValidations);

fprintf(stderr, "-------------------------\n");
fprintf(stderr, "numProfiledClassGuardsValidationFailed: %d\n", aotStats->profiledClassGuards.numFailedValidations);
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/env/PersistentCHTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ TR_PersistentCHTable::findSingleAbstractImplementer(
{
if (comp->getOption(TR_DisableCHOpts))
return 0;
TR_PersistentClassInfo * classInfo = findClassInfoAfterLocking(thisClass, comp);
TR_PersistentClassInfo * classInfo = findClassInfoAfterLocking(thisClass, comp, true);
if (!classInfo) return 0;

if (TR::Compiler->cls.isInterfaceClass(comp, thisClass))
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/optimizer/J9Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ bool TR_J9VirtualCallSite::findCallSiteForAbstractClass(TR_InlinerBase* inliner)
TR_PersistentCHTable *chTable = comp()->getPersistentInfo()->getPersistentCHTable();
TR_ResolvedMethod *implementer;

if (!comp()->compileRelocatableCode() && TR::Compiler->cls.isAbstractClass(comp(), _receiverClass) &&!comp()->getOption(TR_DisableAbstractInlining) &&
(implementer = chTable->findSingleAbstractImplementer(_receiverClass, _vftSlot, _callerResolvedMethod, comp())))
if (TR::Compiler->cls.isAbstractClass(comp(), _receiverClass) &&!comp()->getOption(TR_DisableAbstractInlining) &&
(implementer = chTable->findSingleAbstractImplementer(_receiverClass, _vftSlot, _callerResolvedMethod, comp())))
{
heuristicTrace(inliner->tracer(),"Found a single Abstract Implementer %p, signature = %s",implementer,inliner->tracer()->traceSignature(implementer));
TR_VirtualGuardSelection *guard = new (comp()->trHeapMemory()) TR_VirtualGuardSelection(TR_AbstractGuard, TR_MethodTest);
Expand Down
6 changes: 5 additions & 1 deletion runtime/compiler/p/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ uint8_t *J9::Power::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
case TR_InlinedVirtualMethod:
case TR_InlinedInterfaceMethodWithNopGuard:
case TR_InlinedInterfaceMethod:
case TR_InlinedAbstractMethodWithNopGuard:
case TR_InlinedHCRMethod:
{
guard = (TR_VirtualGuard *) relocation->getTargetAddress2();
Expand Down Expand Up @@ -587,7 +588,8 @@ uint8_t *J9::Power::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
cursor += SIZEPOINTER;

if (relocation->getTargetKind() == TR_InlinedInterfaceMethodWithNopGuard ||
relocation->getTargetKind() == TR_InlinedInterfaceMethod)
relocation->getTargetKind() == TR_InlinedInterfaceMethod ||
relocation->getTargetKind() == TR_InlinedAbstractMethodWithNopGuard)
{
TR_InlinedCallSite *inlinedCallSite = &comp->getInlinedCallSite(inlinedSiteIndex);
TR_AOTMethodInfo *aotMethodInfo = (TR_AOTMethodInfo *) inlinedCallSite->_methodInfo;
Expand Down Expand Up @@ -907,6 +909,7 @@ uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_
56, // TR_DebugCounter = 59
8, // TR_ClassUnloadAssumption = 60
32, // TR_J2IVirtualThunkPointer = 61
48, // TR_InlinedAbstractMethodWithNopGuard = 62,
};
#else
uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumExternalRelocationKinds] =
Expand Down Expand Up @@ -973,6 +976,7 @@ uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61
24, // TR_InlinedAbstractMethodWithNopGuard = 62,
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/p/codegen/PPCPrivateLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ void TR::PPCPrivateLinkage::buildVirtualDispatch(TR::Node
TR_OpaqueClassBlock *thisClass = refinedThisClass ? refinedThisClass : resolvedMethod->containingClass();

TR_PersistentCHTable *chTable = comp()->getPersistentInfo()->getPersistentCHTable();
if (thisClass && TR::Compiler->cls.isAbstractClass(comp(), thisClass))
if (thisClass && TR::Compiler->cls.isAbstractClass(comp(), thisClass) && !comp()->compileRelocatableCode())
{
TR_ResolvedMethod *calleeMethod = chTable->findSingleAbstractImplementer(thisClass, methodSymRef->getOffset(), methodSymRef->getOwningMethod(comp()), comp());
if (calleeMethod &&
Expand Down
93 changes: 93 additions & 0 deletions runtime/compiler/runtime/RelocationRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,61 @@ TR_RelocationRecordConstantPoolWithIndex::getInterfaceMethodFromCP(TR_Relocation
return calleeMethod;
}

TR_OpaqueMethodBlock *
TR_RelocationRecordConstantPoolWithIndex::getAbstractMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpIndex, TR_OpaqueMethodBlock *callerMethod)
{
TR_RelocationRuntimeLogger *reloLogger = reloRuntime->reloLogger();
TR_RelocationRecordInlinedMethodPrivateData *reloPrivateData = &(privateData()->inlinedMethod);

J9JavaVM *javaVM = reloRuntime->javaVM();
TR_J9VMBase *fe = reloRuntime->fej9();
TR_Memory *trMemory = reloRuntime->trMemory();

J9ConstantPool *cp = (J9ConstantPool *) void_cp;
J9ROMMethodRef *romMethodRef = (J9ROMMethodRef *)&cp->romConstantPool[cpIndex];

TR_OpaqueMethodBlock *calleeMethod = NULL;
TR_OpaqueClassBlock *abstractClass = NULL;
UDATA vTableOffset = (UDATA)-1;
int32_t vftSlot = -1;

{
TR::VMAccessCriticalSection getAbstractlMethodFromCP(reloRuntime->fej9());
abstractClass = (TR_OpaqueClassBlock *) javaVM->internalVMFunctions->resolveClassRef(reloRuntime->currentThread(),
cp,
romMethodRef->classRefCPIndex,
J9_RESOLVE_FLAG_AOT_LOAD_TIME);

J9Method *method;
vTableOffset = javaVM->internalVMFunctions->resolveVirtualMethodRefInto(reloRuntime->currentThread(),
cp,
cpIndex,
J9_RESOLVE_FLAG_AOT_LOAD_TIME,
&method,
NULL);
}

if (abstractClass)
{
vftSlot = (int32_t)(-(vTableOffset - J9JIT_INTERP_VTABLE_OFFSET));
TR_PersistentCHTable * chTable = reloRuntime->getPersistentInfo()->getPersistentCHTable();
TR_ResolvedMethod *callerResolvedMethod = fe->createResolvedMethod(trMemory, callerMethod, NULL);

TR_ResolvedMethod *calleeResolvedMethod = chTable->findSingleAbstractImplementer(abstractClass, vftSlot, callerResolvedMethod, reloRuntime->comp());

if (calleeResolvedMethod)
{
if (!calleeResolvedMethod->virtualMethodIsOverridden())
calleeMethod = calleeResolvedMethod->getPersistentIdentifier();
else
RELO_LOG(reloLogger, 6, "\tgetMethodFromCP: callee method overridden\n");
}
}

reloPrivateData->_receiverClass = abstractClass;
return calleeMethod;
}

// TR_HelperAddress
char *
TR_RelocationRecordHelperAddress::name()
Expand Down Expand Up @@ -2524,6 +2579,44 @@ TR_RelocationRecordInlinedInterfaceMethod::getMethodFromCP(TR_RelocationRuntime
return getInterfaceMethodFromCP(reloRuntime, void_cp, cpIndex, callerMethod);
}

// TR_InlinedAbstractMethodWithNopGuard
char *
TR_RelocationRecordInlinedAbstractMethodWithNopGuard::name()
{
return "TR_InlinedAbstractMethodWithNopGuard";
}

TR_OpaqueMethodBlock *
TR_RelocationRecordInlinedAbstractMethodWithNopGuard::getMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpIndex, TR_OpaqueMethodBlock *callerMethod)
{
return getAbstractMethodFromCP(reloRuntime, void_cp, cpIndex, callerMethod);
}

void
TR_RelocationRecordInlinedAbstractMethodWithNopGuard::createAssumptions(TR_RelocationRuntime *reloRuntime, uint8_t *reloLocation)
{
TR_RelocationRecordInlinedMethodPrivateData *reloPrivateData = &(privateData()->inlinedMethod);
TR_PersistentCHTable *table = reloRuntime->getPersistentInfo()->getPersistentCHTable();
List<TR_VirtualGuardSite> sites(reloRuntime->comp()->trMemory());
TR_VirtualGuardSite site;
site.setLocation(reloLocation);
site.setDestination(reloPrivateData->_destination);
sites.add(&site);
TR_ClassQueries::addAnAssumptionForEachSubClass(table, table->findClassInfo(reloPrivateData->_receiverClass), sites, reloRuntime->comp());
}

void
TR_RelocationRecordInlinedAbstractMethodWithNopGuard::updateFailedStats(TR_AOTStats *aotStats)
{
aotStats->abstractMethods.numFailedValidations++;
}

void
TR_RelocationRecordInlinedAbstractMethodWithNopGuard::updateSucceededStats(TR_AOTStats *aotStats)
{
aotStats->abstractMethods.numSucceededValidations++;
}

// TR_ProfiledInlinedMethod
char *
TR_RelocationRecordProfiledInlinedMethod::name()
Expand Down
14 changes: 14 additions & 0 deletions runtime/compiler/runtime/RelocationRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class TR_RelocationRecordConstantPoolWithIndex : public TR_RelocationRecordConst
TR_OpaqueMethodBlock *getStaticMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpIndex);
TR_OpaqueMethodBlock *getSpecialMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpIndex);
TR_OpaqueMethodBlock *getInterfaceMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpIndex, TR_OpaqueMethodBlock *callerMethod);
TR_OpaqueMethodBlock *getAbstractMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpIndex, TR_OpaqueMethodBlock *callerMethod);

virtual int32_t bytesInHeaderAndPayload();
};
Expand Down Expand Up @@ -814,6 +815,19 @@ class TR_RelocationRecordInlinedInterfaceMethod: public TR_RelocationRecordInlin
virtual TR_OpaqueMethodBlock *getMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpindex, TR_OpaqueMethodBlock *callerMethod);
};

class TR_RelocationRecordInlinedAbstractMethodWithNopGuard : public TR_RelocationRecordNopGuard
{
public:
TR_RelocationRecordInlinedAbstractMethodWithNopGuard() {}
TR_RelocationRecordInlinedAbstractMethodWithNopGuard(TR_RelocationRuntime *reloRuntime, TR_RelocationRecordBinaryTemplate *record) : TR_RelocationRecordNopGuard(reloRuntime, record) {}
virtual char *name();
private:
virtual TR_OpaqueMethodBlock *getMethodFromCP(TR_RelocationRuntime *reloRuntime, void *void_cp, int32_t cpindex, TR_OpaqueMethodBlock *callerMethod);
virtual void updateFailedStats(TR_AOTStats *aotStats);
virtual void updateSucceededStats(TR_AOTStats *aotStats);
virtual void createAssumptions(TR_RelocationRuntime *reloRuntime, uint8_t *reloLocation);
};

class TR_RelocationRecordProfiledInlinedMethod : public TR_RelocationRecordInlinedMethod
{
public:
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/runtime/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ typedef struct TR_AOTStats
TR_AOTInliningStats specialMethods;
TR_AOTInliningStats virtualMethods;
TR_AOTInliningStats interfaceMethods;
TR_AOTInliningStats abstractMethods;

TR_AOTInliningStats profiledInlinedMethods;
TR_AOTInliningStats profiledClassGuards;
Expand Down
6 changes: 5 additions & 1 deletion runtime/compiler/x/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ uint8_t *J9::X86::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
case TR_InlinedVirtualMethod:
case TR_InlinedInterfaceMethodWithNopGuard:
case TR_InlinedInterfaceMethod:
case TR_InlinedAbstractMethodWithNopGuard:
case TR_InlinedHCRMethod:
{
guard = (TR_VirtualGuard *)relocation->getTargetAddress2();
Expand Down Expand Up @@ -242,7 +243,8 @@ uint8_t *J9::X86::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
cursor += SIZEPOINTER;

if (relocation->getTargetKind() == TR_InlinedInterfaceMethodWithNopGuard ||
relocation->getTargetKind() == TR_InlinedInterfaceMethod)
relocation->getTargetKind() == TR_InlinedInterfaceMethod ||
relocation->getTargetKind() == TR_InlinedAbstractMethodWithNopGuard)
{
TR_InlinedCallSite *inlinedCallSite = &comp->getInlinedCallSite(inlinedSiteIndex);
TR_AOTMethodInfo *aotMethodInfo = (TR_AOTMethodInfo *)inlinedCallSite->_methodInfo;
Expand Down Expand Up @@ -704,6 +706,7 @@ uint32_t J9::X86::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_Nu
56, // TR_DebugCounter = 59
8, // TR_ClassUnloadAssumption = 60
32, // TR_J2IVirtualThunkPointer = 61,
48, // TR_InlinedAbstractMethodWithNopGuard = 62,
#else

12, // TR_ConstantPool = 0
Expand Down Expand Up @@ -768,6 +771,7 @@ uint32_t J9::X86::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_Nu
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61,
24, // TR_InlinedAbstractMethodWithNopGuard = 62,
#endif
};

2 changes: 1 addition & 1 deletion runtime/compiler/x/codegen/X86PrivateLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ void TR::X86CallSite::setupVirtualGuardInfo()

TR::SymbolReference *methodSymRef = getSymbolReference();
TR_PersistentCHTable * chTable = comp()->getPersistentInfo()->getPersistentCHTable();
if (thisClass && TR::Compiler->cls.isAbstractClass(comp(), thisClass))
if (thisClass && TR::Compiler->cls.isAbstractClass(comp(), thisClass) && !comp()->compileRelocatableCode())
{
TR_ResolvedMethod * method = chTable->findSingleAbstractImplementer(thisClass, methodSymRef->getOffset(), methodSymRef->getOwningMethod(comp()), comp());
if (method &&
Expand Down
6 changes: 5 additions & 1 deletion runtime/compiler/z/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ uint8_t *J9::Z::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::IteratedEx
case TR_InlinedVirtualMethod:
case TR_InlinedInterfaceMethodWithNopGuard:
case TR_InlinedInterfaceMethod:
case TR_InlinedAbstractMethodWithNopGuard:
case TR_InlinedHCRMethod:
{
guard = (TR_VirtualGuard *)relocation->getTargetAddress2();
Expand Down Expand Up @@ -510,7 +511,8 @@ uint8_t *J9::Z::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::IteratedEx
cursor += SIZEPOINTER;

if (relocation->getTargetKind() == TR_InlinedInterfaceMethodWithNopGuard ||
relocation->getTargetKind() == TR_InlinedInterfaceMethod)
relocation->getTargetKind() == TR_InlinedInterfaceMethod ||
relocation->getTargetKind() == TR_InlinedAbstractMethodWithNopGuard)
{
TR_InlinedCallSite *inlinedCallSite = &self()->comp()->getInlinedCallSite(inlinedSiteIndex);
TR_AOTMethodInfo *aotMethodInfo = (TR_AOTMethodInfo *)inlinedCallSite->_methodInfo;
Expand Down Expand Up @@ -1025,6 +1027,7 @@ uint32_t J9::Z::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumE
56, // TR_DebugCounter = 59
8, // TR_ClassUnloadAssumption = 60
32, // TR_J2IVirtualThunkPointer = 61
48, // TR_InlinedAbstractMethodWithNopGuard = 62,
};

#else
Expand Down Expand Up @@ -1093,6 +1096,7 @@ uint32_t J9::Z::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumE
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61
24, // TR_InlinedAbstractMethodWithNopGuard = 62,
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/z/codegen/J9S390PrivateLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ TR::S390PrivateLinkage::buildVirtualDispatch(TR::Node * callNode, TR::RegisterDe
}

TR_PersistentCHTable * chTable = comp()->getPersistentInfo()->getPersistentCHTable();
if (thisClass && TR::Compiler->cls.isAbstractClass(comp(), thisClass))
if (thisClass && TR::Compiler->cls.isAbstractClass(comp(), thisClass) && !comp()->compileRelocatableCode())
{
TR_ResolvedMethod * method = chTable->findSingleAbstractImplementer(thisClass, methodSymRef->getOffset(),
methodSymRef->getOwningMethod(comp()), comp());
Expand Down

0 comments on commit 6084fd6

Please sign in to comment.