Skip to content

Commit

Permalink
Merge pull request #4781 from aviansie-ben/power-aot-new-relos
Browse files Browse the repository at this point in the history
Add Power-specific relocation types needed for SVM AOT
  • Loading branch information
Irwin D'Souza authored Feb 20, 2019
2 parents 4577abf + eb58c32 commit f4c2e8e
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 2 deletions.
25 changes: 25 additions & 0 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,25 @@ J9::AheadOfTimeCompile::dumpRelocationData()
}
}
break;

case TR_ResolvedTrampolines:
{
cursor++;
if (is64BitTarget)
cursor += 4; // padding
cursor -= sizeof(TR_RelocationRecordBinaryTemplate);
TR_RelocationRecordResolvedTrampolinesBinaryTemplate *binaryTemplate =
reinterpret_cast<TR_RelocationRecordResolvedTrampolinesBinaryTemplate *>(cursor);
if (isVerbose)
{
traceMsg(self()->comp(), "\n Resolved Trampoline: symbolID=%d ",
(uint32_t)binaryTemplate->_symbolID);
}
cursor += sizeof(TR_RelocationRecordResolvedTrampolinesBinaryTemplate);
self()->traceRelocationOffsets(cursor, offsetSize, endOfCurrentRecord, orderedPair);
}
break;

case TR_CheckMethodEnter:
case TR_CheckMethodExit:
cursor++; // unused field
Expand Down Expand Up @@ -1704,6 +1723,7 @@ J9::AheadOfTimeCompile::dumpRelocationData()


case TR_SymbolFromManager:
case TR_DiscontiguousSymbolFromManager:
{
cursor++;
if (is64BitTarget)
Expand All @@ -1715,6 +1735,11 @@ J9::AheadOfTimeCompile::dumpRelocationData()
{
traceMsg(self()->comp(), "\n Symbol From Manager: symbolID=%d symbolType=%d ",
(uint32_t)binaryTemplate->_symbolID, (uint32_t)binaryTemplate->_symbolType);

if (kind == TR_DiscontiguousSymbolFromManager)
{
traceMsg(self()->comp(), "isDiscontiguous ");
}
}
cursor += sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate);
self()->traceRelocationOffsets(cursor, offsetSize, endOfCurrentRecord, orderedPair);
Expand Down
48 changes: 48 additions & 0 deletions runtime/compiler/p/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,23 @@ uint8_t *J9::Power::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
}
break;

case TR_ResolvedTrampolines:
{
uint8_t *symbol = relocation->getTargetAddress();
uint16_t symbolID = comp->getSymbolValidationManager()->getIDFromSymbol(static_cast<void *>(symbol));
TR_ASSERT_FATAL(symbolID, "symbolID should exist!\n");

cursor -= sizeof(TR_RelocationRecordBinaryTemplate);

TR_RelocationRecordResolvedTrampolinesBinaryTemplate *binaryTemplate =
reinterpret_cast<TR_RelocationRecordResolvedTrampolinesBinaryTemplate *>(cursor);

binaryTemplate->_symbolID = symbolID;

cursor += sizeof(TR_RelocationRecordResolvedTrampolinesBinaryTemplate);
}
break;

case TR_J2IVirtualThunkPointer:
{
auto info = (TR_RelocationRecordInformation*)relocation->getTargetAddress();
Expand Down Expand Up @@ -1304,6 +1321,31 @@ uint8_t *J9::Power::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
}
break;

case TR_DiscontiguousSymbolFromManager:
{
TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();

uint8_t *symbol = (uint8_t *)recordInfo->data1;
uint16_t symbolID = comp->getSymbolValidationManager()->getIDFromSymbol(static_cast<void *>(symbol));

uint16_t symbolType = (uint16_t)recordInfo->data2;

uint8_t flags = (uint8_t) recordInfo->data3;
TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");

cursor -= sizeof(TR_RelocationRecordBinaryTemplate);

TR_RelocationRecordSymbolFromManagerBinaryTemplate *binaryTemplate =
reinterpret_cast<TR_RelocationRecordSymbolFromManagerBinaryTemplate *>(cursor);

binaryTemplate->_flags |= (flags & RELOCATION_RELOC_FLAGS_MASK);
binaryTemplate->_symbolID = symbolID;
binaryTemplate->_symbolType = symbolType;

cursor += sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate);
}
break;

case TR_ValidateClass:
case TR_ValidateInstanceField:
{
Expand Down Expand Up @@ -1518,6 +1560,9 @@ uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_
sizeof(TR_RelocationRecordValidateMethodFromSingleAbstractImplBinaryTemplate),//TR_ValidateMethodFromSingleAbstractImplementer= 96,
sizeof(TR_RelocationRecordValidateImproperInterfaceMethodFromCPBinaryTemplate),//TR_ValidateImproperInterfaceMethodFromCP= 97,
sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate), // TR_SymbolFromManager = 98,
0, // TR_MethodCallAddress = 99,
sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate), // TR_DiscontiguousSymbolFromManager = 100,
sizeof(TR_RelocationRecordResolvedTrampolinesBinaryTemplate), // TR_ResolvedTrampolines = 101,
};
#else
uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumExternalRelocationKinds] =
Expand Down Expand Up @@ -1621,6 +1666,9 @@ uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_
sizeof(TR_RelocationRecordValidateMethodFromSingleAbstractImplBinaryTemplate),//TR_ValidateMethodFromSingleAbstractImplementer= 96,
sizeof(TR_RelocationRecordValidateImproperInterfaceMethodFromCPBinaryTemplate),//TR_ValidateImproperInterfaceMethodFromCP= 97,
sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate), // TR_SymbolFromManager = 98,
0, // TR_MethodCallAddress = 99,
sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate), // TR_DiscontiguousSymbolFromManager = 100,
sizeof(TR_RelocationRecordResolvedTrampolinesBinaryTemplate), // TR_ResolvedTrampolines = 101,
};

#endif
Expand Down
65 changes: 63 additions & 2 deletions runtime/compiler/runtime/RelocationRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ TR_RelocationRecord::create(TR_RelocationRecord *storage, TR_RelocationRuntime *
case TR_MethodCallAddress:
reloRecord = new (storage) TR_RelocationRecordMethodCallAddress(reloRuntime, record);
break;
case TR_DiscontiguousSymbolFromManager:
reloRecord = new (storage) TR_RelocationRecordDiscontiguousSymbolFromManager(reloRuntime, record);
break;
case TR_ResolvedTrampolines:
reloRecord = new (storage) TR_RelocationRecordResolvedTrampolines(reloRuntime, record);
break;
default:
// TODO: error condition
printf("Unexpected relo record: %d\n", reloType);fflush(stdout);
Expand Down Expand Up @@ -3911,12 +3917,12 @@ TR_RelocationRecordSymbolFromManager::applyRelocation(TR_RelocationRuntime *relo
if (reloRuntime->reloLogger()->logEnabled())
{
reloRuntime->reloLogger()->printf("%s\n", name());
reloRuntime->reloLogger()->printf("\tpreparePrivateData: symbol %p\n", symbol);
reloRuntime->reloLogger()->printf("\tapplyRelocation: symbol %p\n", symbol);
}

if (symbol)
{
reloTarget->storeAddressSequence((uint8_t *)symbol, reloLocation, reloFlags(reloTarget));
storePointer(reloRuntime, reloTarget, reloLocation);
activatePointer(reloRuntime, reloTarget, reloLocation);
}
else
Expand Down Expand Up @@ -3961,6 +3967,22 @@ TR_RelocationRecordSymbolFromManager::needsRedefinitionAssumption(TR_RelocationR
return needsAssumptions;
}

void
TR_RelocationRecordSymbolFromManager::storePointer(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
TR_RelocationSymbolFromManagerPrivateData *reloPrivateData = &(privateData()->symbolFromManager);

reloTarget->storePointer((uint8_t *)reloPrivateData->_symbol, reloLocation);
}

void
TR_RelocationRecordDiscontiguousSymbolFromManager::storePointer(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
TR_RelocationSymbolFromManagerPrivateData *reloPrivateData = &(privateData()->symbolFromManager);

reloTarget->storeAddressSequence((uint8_t *)reloPrivateData->_symbol, reloLocation, reloFlags(reloTarget));
}

void
TR_RelocationRecordSymbolFromManager::activatePointer(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
Expand Down Expand Up @@ -3990,6 +4012,43 @@ TR_RelocationRecordSymbolFromManager::activatePointer(TR_RelocationRuntime *relo
}
}

void
TR_RelocationRecordResolvedTrampolines::preparePrivateData(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget)
{
TR_RelocationRecordResolvedTrampolinesPrivateData *reloPrivateData = &(privateData()->resolvedTrampolines);

uint16_t symbolID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordResolvedTrampolinesBinaryTemplate *)_record)->_symbolID);

if (reloRuntime->reloLogger()->logEnabled())
{
reloRuntime->reloLogger()->printf("%s\n", name());
reloRuntime->reloLogger()->printf("\tpreparePrivateData: symbolID %d\n", symbolID);
}

reloPrivateData->_method = reloRuntime->comp()->getSymbolValidationManager()->getMethodFromID(symbolID);
}

int32_t
TR_RelocationRecordResolvedTrampolines::applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
TR_RelocationRecordResolvedTrampolinesPrivateData *reloPrivateData = &(privateData()->resolvedTrampolines);
TR_OpaqueMethodBlock *method = reloPrivateData->_method;

if (reloRuntime->reloLogger()->logEnabled())
{
reloRuntime->reloLogger()->printf("%s\n", name());
reloRuntime->reloLogger()->printf("\tapplyRelocation: method %p\n", method);
}

if (reloRuntime->codeCache()->reserveResolvedTrampoline(method, true) != OMR::CodeCacheErrorCode::ERRORCODE_SUCCESS)
{
RELO_LOG(reloRuntime->reloLogger(), 6, "\t\tapplyRelocation: aborting AOT relocation because trampoline was not reserved. Will be retried.\n");
return compilationAotTrampolineReloFailure;
}

return 0;
}


// TR_HCR
char *
Expand Down Expand Up @@ -4619,5 +4678,7 @@ uint32_t TR_RelocationRecord::_relocationRecordHeaderSizeTable[TR_NumExternalRel
sizeof(TR_RelocationRecordValidateImproperInterfaceMethodFromCPBinaryTemplate), // TR_ValidateImproperInterfaceMethodFromCP = 97
sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate), // TR_SymbolFromManager = 98
sizeof(TR_RelocationRecordMethodCallAddressBinaryTemplate), // TR_MethodCallAddress = 99
sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate), // TR_DiscontiguousSymbolFromManager = 100
sizeof(TR_RelocationRecordResolvedTrampolinesBinaryTemplate), // TR_ResolvedTrampolines = 101
};

32 changes: 32 additions & 0 deletions runtime/compiler/runtime/RelocationRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ struct TR_RelocationRecordMethodCallAddressBinaryTemplate : public TR_Relocation
UDATA _methodAddress;
};

struct TR_RelocationRecordResolvedTrampolinesBinaryTemplate : public TR_RelocationRecordBinaryTemplate
{
uint16_t _symbolID;
};

extern char* AOTcgDiagOn;

class TR_RelocationRecordGroup
Expand Down Expand Up @@ -489,6 +494,11 @@ struct TR_RelocationSymbolFromManagerPrivateData
void *_symbol;
};

struct TR_RelocationRecordResolvedTrampolinesPrivateData
{
TR_OpaqueMethodBlock *_method;
};

union TR_RelocationRecordPrivateData
{
TR_RelocationRecordHelperAddressPrivateData helperAddress;
Expand All @@ -503,6 +513,7 @@ union TR_RelocationRecordPrivateData
TR_RelocationRecordEmitClassPrivateData emitClass;
TR_RelocationRecordDebugCounterPrivateData debugCounter;
TR_RelocationSymbolFromManagerPrivateData symbolFromManager;
TR_RelocationRecordResolvedTrampolinesPrivateData resolvedTrampolines;
};

// TR_RelocationRecord is the base class for all relocation records. It is used for all queries on relocation
Expand Down Expand Up @@ -1705,10 +1716,31 @@ class TR_RelocationRecordSymbolFromManager : public TR_RelocationRecord
virtual int32_t bytesInHeaderAndPayload() { return sizeof(TR_RelocationRecordSymbolFromManagerBinaryTemplate); }
virtual void preparePrivateData(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget);
virtual int32_t applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);
virtual void storePointer(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);
virtual void activatePointer(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);
bool needsUnloadAssumptions(TR::SymbolType symbolType);
bool needsRedefinitionAssumption(TR_RelocationRuntime *reloRuntime, uint8_t *reloLocation, TR_OpaqueClassBlock *clazz, TR::SymbolType symbolType);
};

class TR_RelocationRecordDiscontiguousSymbolFromManager : public TR_RelocationRecordSymbolFromManager
{
public:
TR_RelocationRecordDiscontiguousSymbolFromManager() {}
TR_RelocationRecordDiscontiguousSymbolFromManager(TR_RelocationRuntime *reloRuntime, TR_RelocationRecordBinaryTemplate *record) : TR_RelocationRecordSymbolFromManager(reloRuntime, record) {}
virtual char *name() { return "TR_RelocationRecordDiscontiguousSymbolFromManager"; }
virtual void storePointer(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);
};

class TR_RelocationRecordResolvedTrampolines : public TR_RelocationRecord
{
public:
TR_RelocationRecordResolvedTrampolines() {}
TR_RelocationRecordResolvedTrampolines(TR_RelocationRuntime *reloRuntime, TR_RelocationRecordBinaryTemplate *record) : TR_RelocationRecord(reloRuntime, record) {}
virtual char *name() { return "TR_RelocationRecordResolvedTrampolines"; }
virtual int32_t bytesInHeaderAndPayload() { return sizeof(TR_RelocationRecordResolvedTrampolinesBinaryTemplate); }
virtual void preparePrivateData(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget);
virtual int32_t applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);
};
/* SYMBOL VALIDATION MANAGER */

class TR_RelocationRecordHCR : public TR_RelocationRecordWithOffset
Expand Down

0 comments on commit f4c2e8e

Please sign in to comment.