Skip to content

Commit

Permalink
Consolidate TR_ValidateMethodFromClassAndSig
Browse files Browse the repository at this point in the history
Remove the duplicated code that writes the
TR_ValidateMethodFromClassAndSig relocation header
information, and consolidate it in one canonical location.

Signed-off-by: Irwin D'Souza <dsouzai.gh@gmail.com>
  • Loading branch information
dsouzai committed Aug 25, 2020
1 parent 81ff084 commit b3e6b21
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 127 deletions.
24 changes: 0 additions & 24 deletions runtime/compiler/aarch64/codegen/J9AheadOfTimeCompile.cpp
Expand Up @@ -304,30 +304,6 @@ uint8_t *J9::ARM64::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
}
break;

case TR_ValidateMethodFromClassAndSig:
{
TR::MethodFromClassAndSigRecord *record = reinterpret_cast<TR::MethodFromClassAndSigRecord *>(relocation->getTargetAddress());

cursor -= sizeof(TR_RelocationRecordBinaryTemplate);

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

// Store rom method to get name of method
J9Method *methodToValidate = reinterpret_cast<J9Method *>(record->_method);
J9ROMMethod *romMethod = static_cast<TR_J9VM *>(fej9)->getROMMethodFromRAMMethod(methodToValidate);
uintptr_t romMethodOffsetInSharedCache = self()->offsetInSharedCacheFromROMMethod(sharedCache, romMethod);

binaryTemplate->_methodID = symValManager->getIDFromSymbol(static_cast<void *>(record->_method));
binaryTemplate->_definingClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->definingClass()));
binaryTemplate->_lookupClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->_lookupClass));
binaryTemplate->_beholderID = symValManager->getIDFromSymbol(static_cast<void *>(record->_beholder));
binaryTemplate->_romMethodOffsetInSCC = romMethodOffsetInSharedCache;

cursor += sizeof(TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate);
}
break;

case TR_ValidateMethodFromSingleImplementer:
{
TR::MethodFromSingleImplementer *record = reinterpret_cast<TR::MethodFromSingleImplementer *>(relocation->getTargetAddress());
Expand Down
58 changes: 36 additions & 22 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Expand Up @@ -867,6 +867,25 @@ J9::AheadOfTimeCompile::initializeCommonAOTRelocationHeader(TR::IteratedExternal
}
break;

case TR_ValidateMethodFromClassAndSig:
{
TR_RelocationRecordValidateMethodFromClassAndSig *mfcsRecord = reinterpret_cast<TR_RelocationRecordValidateMethodFromClassAndSig *>(reloRecord);

TR::MethodFromClassAndSigRecord *svmRecord = reinterpret_cast<TR::MethodFromClassAndSigRecord *>(relocation->getTargetAddress());

// Store rom method to get name of method
J9Method *methodToValidate = reinterpret_cast<J9Method *>(svmRecord->_method);
J9ROMMethod *romMethod = static_cast<TR_J9VM *>(fej9)->getROMMethodFromRAMMethod(methodToValidate);
uintptr_t romMethodOffsetInSharedCache = self()->offsetInSharedCacheFromROMMethod(sharedCache, romMethod);

mfcsRecord->setMethodID(reloTarget, symValManager->getIDFromSymbol(svmRecord->_method));
mfcsRecord->setDefiningClassID(reloTarget, symValManager->getIDFromSymbol(svmRecord->_definingClass));
mfcsRecord->setBeholderID(reloTarget, symValManager->getIDFromSymbol(svmRecord->_beholder));
mfcsRecord->setLookupClassID(reloTarget, symValManager->getIDFromSymbol(svmRecord->_lookupClass));
mfcsRecord->setRomMethodOffsetInSCC(reloTarget, romMethodOffsetInSharedCache);
}
break;

default:
return cursor;
}
Expand Down Expand Up @@ -1443,6 +1462,23 @@ J9::AheadOfTimeCompile::dumpRelocationHeaderData(uint8_t *cursor, bool isVerbose
}
break;

case TR_ValidateMethodFromClassAndSig:
{
TR_RelocationRecordValidateMethodFromClassAndSig *mfcsRecord = reinterpret_cast<TR_RelocationRecordValidateMethodFromClassAndSig *>(reloRecord);

self()->traceRelocationOffsets(cursor, offsetSize, endOfCurrentRecord, orderedPair);
if (isVerbose)
{
traceMsg(self()->comp(), "\n Validate Method From Class and Sig: methodID=%d, definingClassID=%d, lookupClassID=%d, beholderID=%d, romMethodOffsetInSCC=%p ",
(uint32_t)mfcsRecord->methodID(reloTarget),
(uint32_t)mfcsRecord->definingClassID(reloTarget),
(uint32_t)mfcsRecord->lookupClassID(reloTarget),
(uint32_t)mfcsRecord->beholderID(reloTarget),
(void *)mfcsRecord->romMethodOffsetInSCC(reloTarget));
}
}
break;

default:
return cursor;
}
Expand Down Expand Up @@ -1946,28 +1982,6 @@ J9::AheadOfTimeCompile::dumpRelocationData()
}
break;

case TR_ValidateMethodFromClassAndSig:
{
cursor++;
if (is64BitTarget)
cursor += 4; // padding
cursor -= sizeof(TR_RelocationRecordBinaryTemplate);
TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *binaryTemplate =
reinterpret_cast<TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *>(cursor);
if (isVerbose)
{
traceMsg(self()->comp(), "\n Validate Method From Class and Sig: methodID=%d, definingClassID=%d, lookupClassID=%d, beholderID=%d, romMethodOffsetInSCC=%p ",
(uint32_t)binaryTemplate->_methodID,
(uint32_t)binaryTemplate->_definingClassID,
(uint32_t)binaryTemplate->_lookupClassID,
(uint32_t)binaryTemplate->_beholderID,
binaryTemplate->_romMethodOffsetInSCC);
}
cursor += sizeof(TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate);
self()->traceRelocationOffsets(cursor, offsetSize, endOfCurrentRecord, orderedPair);
}
break;

case TR_ValidateStackWalkerMaySkipFramesRecord:
{
cursor++;
Expand Down
24 changes: 0 additions & 24 deletions runtime/compiler/p/codegen/J9AheadOfTimeCompile.cpp
Expand Up @@ -475,30 +475,6 @@ uint8_t *J9::Power::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
}
break;

case TR_ValidateMethodFromClassAndSig:
{
TR::MethodFromClassAndSigRecord *record = reinterpret_cast<TR::MethodFromClassAndSigRecord *>(relocation->getTargetAddress());

cursor -= sizeof(TR_RelocationRecordBinaryTemplate);

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

// Store rom method to get name of method
J9Method *methodToValidate = reinterpret_cast<J9Method *>(record->_method);
J9ROMMethod *romMethod = static_cast<TR_J9VM *>(fej9)->getROMMethodFromRAMMethod(methodToValidate);
uintptr_t romMethodOffsetInSharedCache = self()->offsetInSharedCacheFromROMMethod(sharedCache, romMethod);

binaryTemplate->_methodID = symValManager->getIDFromSymbol(static_cast<void *>(record->_method));
binaryTemplate->_definingClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->definingClass()));
binaryTemplate->_lookupClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->_lookupClass));
binaryTemplate->_beholderID = symValManager->getIDFromSymbol(static_cast<void *>(record->_beholder));
binaryTemplate->_romMethodOffsetInSCC = romMethodOffsetInSharedCache;

cursor += sizeof(TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate);
}
break;

case TR_ValidateMethodFromSingleImplementer:
{
TR::MethodFromSingleImplementer *record = reinterpret_cast<TR::MethodFromSingleImplementer *>(relocation->getTargetAddress());
Expand Down
93 changes: 78 additions & 15 deletions runtime/compiler/runtime/RelocationRecord.cpp
Expand Up @@ -4286,30 +4286,93 @@ TR_RelocationRecordValidateImproperInterfaceMethodFromCP::applyRelocation(TR_Rel
int32_t
TR_RelocationRecordValidateMethodFromClassAndSig::applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
uint16_t methodID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_methodID);
uint16_t definingClassID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_definingClassID);
uint16_t lookupClassID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_lookupClassID);
uint16_t beholderID = reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_beholderID);
uint16_t methodID = this->methodID(reloTarget);
uint16_t definingClassID = this->definingClassID(reloTarget);
uint16_t lookupClassID = this->lookupClassID(reloTarget);
uint16_t beholderID = this->beholderID(reloTarget);

uintptr_t romMethodOffset = reloTarget->loadRelocationRecordValue((uintptr_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_romMethodOffsetInSCC);
uintptr_t romMethodOffset = this->romMethodOffsetInSCC(reloTarget);
J9ROMMethod *romMethod = reloRuntime->fej9()->sharedCache()->romMethodFromOffsetInSharedCache(romMethodOffset);

if (reloRuntime->reloLogger()->logEnabled())
{
reloRuntime->reloLogger()->printf("%s\n", name());
reloRuntime->reloLogger()->printf("\tapplyRelocation: methodID %d\n", methodID);
reloRuntime->reloLogger()->printf("\tapplyRelocation: definingClassID %d\n", definingClassID);
reloRuntime->reloLogger()->printf("\tapplyRelocation: lookupClassID %d\n", lookupClassID);
reloRuntime->reloLogger()->printf("\tapplyRelocation: beholderID %d\n", beholderID);
reloRuntime->reloLogger()->printf("\tapplyRelocation: romMethod %p\n", romMethod);
}

if (reloRuntime->comp()->getSymbolValidationManager()->validateMethodFromClassAndSignatureRecord(methodID, definingClassID, lookupClassID, beholderID, romMethod))
return 0;
else
return compilationAotClassReloFailure;
}

void
TR_RelocationRecordValidateMethodFromClassAndSig::print(TR_RelocationRuntime *reloRuntime)
{
TR_RelocationTarget *reloTarget = reloRuntime->reloTarget();
TR_RelocationRuntimeLogger *reloLogger = reloRuntime->reloLogger();
TR_RelocationRecord::print(reloRuntime);
reloLogger->printf("\tmethodID %d\n", methodID(reloTarget));
reloLogger->printf("\tdefiningClassID %d\n", definingClassID(reloTarget));
reloLogger->printf("\tbeholderID %d\n", beholderID(reloTarget));
reloLogger->printf("\tlookupClassID %d\n", lookupClassID(reloTarget));
reloLogger->printf("\tromMethodOffsetInSCC %p\n", (void *)romMethodOffsetInSCC(reloTarget));
}

void
TR_RelocationRecordValidateMethodFromClassAndSig::setMethodID(TR_RelocationTarget *reloTarget, uint16_t methodID)
{
reloTarget->storeUnsigned16b(methodID, (uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_methodID);
}

uint16_t
TR_RelocationRecordValidateMethodFromClassAndSig::methodID(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_methodID);
}

void
TR_RelocationRecordValidateMethodFromClassAndSig::setDefiningClassID(TR_RelocationTarget *reloTarget, uint16_t definingClassID)
{
reloTarget->storeUnsigned16b(definingClassID, (uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_definingClassID);
}

uint16_t
TR_RelocationRecordValidateMethodFromClassAndSig::definingClassID(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_definingClassID);
}

void
TR_RelocationRecordValidateMethodFromClassAndSig::setLookupClassID(TR_RelocationTarget *reloTarget, uint16_t lookupClassID)
{
reloTarget->storeUnsigned16b(lookupClassID, (uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_lookupClassID);
}

uint16_t
TR_RelocationRecordValidateMethodFromClassAndSig::lookupClassID(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_lookupClassID);
}

void
TR_RelocationRecordValidateMethodFromClassAndSig::setBeholderID(TR_RelocationTarget *reloTarget, uint16_t beholderID)
{
reloTarget->storeUnsigned16b(beholderID, (uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_beholderID);
}

uint16_t
TR_RelocationRecordValidateMethodFromClassAndSig::beholderID(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadUnsigned16b((uint8_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_beholderID);
}

void
TR_RelocationRecordValidateMethodFromClassAndSig::setRomMethodOffsetInSCC(TR_RelocationTarget *reloTarget, uintptr_t romMethodOffsetInSCC)
{
reloTarget->storeRelocationRecordValue(romMethodOffsetInSCC, (uintptr_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_romMethodOffsetInSCC);
}

uintptr_t
TR_RelocationRecordValidateMethodFromClassAndSig::romMethodOffsetInSCC(TR_RelocationTarget *reloTarget)
{
return reloTarget->loadRelocationRecordValue((uintptr_t *) &((TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *)_record)->_romMethodOffsetInSCC);
}

int32_t
TR_RelocationRecordValidateStackWalkerMaySkipFrames::applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation)
{
Expand Down
17 changes: 17 additions & 0 deletions runtime/compiler/runtime/RelocationRecord.hpp
Expand Up @@ -1788,6 +1788,23 @@ class TR_RelocationRecordValidateMethodFromClassAndSig : public TR_RelocationRec
virtual int32_t bytesInHeaderAndPayload() { return sizeof(TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate); }
virtual void preparePrivateData(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget) {}
virtual int32_t applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);

virtual void print(TR_RelocationRuntime *reloRuntime);

void setMethodID(TR_RelocationTarget *reloTarget, uint16_t methodID);
uint16_t methodID(TR_RelocationTarget *reloTarget);

void setDefiningClassID(TR_RelocationTarget *reloTarget, uint16_t definingClassID);
uint16_t definingClassID(TR_RelocationTarget *reloTarget);

void setBeholderID(TR_RelocationTarget *reloTarget, uint16_t beholderID);
uint16_t beholderID(TR_RelocationTarget *reloTarget);

void setLookupClassID(TR_RelocationTarget *reloTarget, uint16_t lookupClassID);
uint16_t lookupClassID(TR_RelocationTarget *reloTarget);

void setRomMethodOffsetInSCC(TR_RelocationTarget *reloTarget, uintptr_t romMethodOffsetInSCC);
uintptr_t romMethodOffsetInSCC(TR_RelocationTarget *reloTarget);
};

class TR_RelocationRecordValidateStackWalkerMaySkipFrames : public TR_RelocationRecord
Expand Down
24 changes: 0 additions & 24 deletions runtime/compiler/x/codegen/J9AheadOfTimeCompile.cpp
Expand Up @@ -302,30 +302,6 @@ uint8_t *J9::X86::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
}
break;

case TR_ValidateMethodFromClassAndSig:
{
TR::MethodFromClassAndSigRecord *record = reinterpret_cast<TR::MethodFromClassAndSigRecord *>(relocation->getTargetAddress());

cursor -= sizeof(TR_RelocationRecordBinaryTemplate);

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

// Store rom method to get name of method
J9Method *methodToValidate = reinterpret_cast<J9Method *>(record->_method);
J9ROMMethod *romMethod = static_cast<TR_J9VM *>(fej9)->getROMMethodFromRAMMethod(methodToValidate);
uintptr_t romMethodOffsetInSharedCache = self()->offsetInSharedCacheFromROMMethod(sharedCache, romMethod);

binaryTemplate->_methodID = symValManager->getIDFromSymbol(static_cast<void *>(record->_method));
binaryTemplate->_definingClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->definingClass()));
binaryTemplate->_lookupClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->_lookupClass));
binaryTemplate->_beholderID = symValManager->getIDFromSymbol(static_cast<void *>(record->_beholder));
binaryTemplate->_romMethodOffsetInSCC = romMethodOffsetInSharedCache;

cursor += sizeof(TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate);
}
break;

case TR_ValidateMethodFromSingleImplementer:
{
TR::MethodFromSingleImplementer *record = reinterpret_cast<TR::MethodFromSingleImplementer *>(relocation->getTargetAddress());
Expand Down
18 changes: 0 additions & 18 deletions runtime/compiler/z/codegen/J9AheadOfTimeCompile.cpp
Expand Up @@ -285,24 +285,6 @@ uint8_t *J9::Z::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::IteratedEx
cursor += sizeof(TR_RelocationRecordValidateImproperInterfaceMethodFromCPBinaryTemplate);
}
break;
case TR_ValidateMethodFromClassAndSig:
{
TR::MethodFromClassAndSigRecord *record = reinterpret_cast<TR::MethodFromClassAndSigRecord *>(relocation->getTargetAddress());
cursor -= sizeof(TR_RelocationRecordBinaryTemplate);
TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *binaryTemplate =
reinterpret_cast<TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate *>(cursor);
// Store rom method to get name of method
J9Method *methodToValidate = reinterpret_cast<J9Method *>(record->_method);
J9ROMMethod *romMethod = static_cast<TR_J9VM *>(fej9)->getROMMethodFromRAMMethod(methodToValidate);
uintptr_t romMethodOffsetInSharedCache = self()->offsetInSharedCacheFromROMMethod(sharedCache, romMethod);
binaryTemplate->_methodID = symValManager->getIDFromSymbol(static_cast<void *>(record->_method));
binaryTemplate->_definingClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->definingClass()));
binaryTemplate->_lookupClassID = symValManager->getIDFromSymbol(static_cast<void *>(record->_lookupClass));
binaryTemplate->_beholderID = symValManager->getIDFromSymbol(static_cast<void *>(record->_beholder));
binaryTemplate->_romMethodOffsetInSCC = romMethodOffsetInSharedCache;
cursor += sizeof(TR_RelocationRecordValidateMethodFromClassAndSigBinaryTemplate);
}
break;
case TR_ValidateMethodFromSingleImplementer:
{
TR::MethodFromSingleImplementer *record = reinterpret_cast<TR::MethodFromSingleImplementer *>(relocation->getTargetAddress());
Expand Down

0 comments on commit b3e6b21

Please sign in to comment.