Skip to content

Commit

Permalink
Merge pull request #6326 from dsouzai/jniRelo
Browse files Browse the repository at this point in the history
Update JNI Target relocation record to have offset to the reloLocation.
  • Loading branch information
mstoodle authored Feb 3, 2022
2 parents 96a484d + 0d1928b commit 9484ecf
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
66 changes: 58 additions & 8 deletions compiler/x/codegen/X86BinaryEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,27 @@ TR::X86ImmSymInstruction::addMetaDataForCodeAddress(uint8_t *cursor)
int rType = methodSym->getMethodKind()-1; //method kinds are 1-based
TR_ASSERT(reloTypes[rType], "There shouldn't be direct JNI interface calls!");

cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *)getNode()->getSymbolReference(),
getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1,
(TR_ExternalRelocationTargetKind) reloTypes [rType], cg()),
__FILE__, __LINE__, getNode());
uint8_t *startOfInstruction = self()->getBinaryEncoding();
uint8_t *startOfImmediate = cursor;
intptr_t diff = reinterpret_cast<intptr_t>(startOfImmediate) - reinterpret_cast<intptr_t>(startOfInstruction);
TR_ASSERT_FATAL(diff > 0, "Address of immediate %p less than address of instruction %p\n",
startOfImmediate, startOfInstruction);

TR_RelocationRecordInformation *info =
reinterpret_cast<TR_RelocationRecordInformation *>(
comp->trMemory()->allocateHeapMemory(sizeof(TR_RelocationRecordInformation)));
info->data1 = static_cast<uintptr_t>(diff);
info->data2 = reinterpret_cast<uintptr_t>(getNode()->getSymbolReference());
int16_t inlinedSiteIndex = getNode() ? getNode()->getInlinedSiteIndex() : -1;
info->data3 = static_cast<uintptr_t>(inlinedSiteIndex);

cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
startOfInstruction,
reinterpret_cast<uint8_t *>(info),
static_cast<TR_ExternalRelocationTargetKind>(reloTypes[rType]),
cg()),
__FILE__, __LINE__, getNode());
}
else if (resolvedMethod)
{
Expand Down Expand Up @@ -2767,13 +2784,46 @@ TR::AMD64RegImm64Instruction::addMetaDataForCodeAddress(uint8_t *cursor)
__FILE__, __LINE__, getNode());
}
break;
case TR_JNIStaticTargetAddress:
case TR_JNISpecialTargetAddress:
case TR_JNIVirtualTargetAddress:
case TR_StaticRamMethodConst:
case TR_VirtualRamMethodConst:
case TR_SpecialRamMethodConst:
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) getNode()->getSymbolReference(), getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1, (TR_ExternalRelocationTargetKind) _reloKind, cg()), __FILE__,__LINE__, getNode());
cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
cursor,
(uint8_t *) getNode()->getSymbolReference(),
getNode()
? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex()
: (uint8_t *)-1,
(TR_ExternalRelocationTargetKind) _reloKind,
cg()),
__FILE__,__LINE__, getNode());
break;
case TR_JNIStaticTargetAddress:
case TR_JNISpecialTargetAddress:
case TR_JNIVirtualTargetAddress:
{
uint8_t *startOfInstruction = self()->getBinaryEncoding();
uint8_t *startOfImmediate = cursor;
intptr_t diff = reinterpret_cast<intptr_t>(startOfImmediate) - reinterpret_cast<intptr_t>(startOfInstruction);
TR_ASSERT_FATAL(diff > 0, "Address of immediate %p less than address of instruction %p\n",
startOfImmediate, startOfInstruction);

TR_RelocationRecordInformation *info =
reinterpret_cast<TR_RelocationRecordInformation *>(
comp->trMemory()->allocateHeapMemory(sizeof(TR_RelocationRecordInformation)));
info->data1 = static_cast<uintptr_t>(diff);
info->data2 = reinterpret_cast<uintptr_t>(getNode()->getSymbolReference());
int16_t inlinedSiteIndex = getNode() ? getNode()->getInlinedSiteIndex() : -1;
info->data3 = static_cast<uintptr_t>(inlinedSiteIndex);

cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
startOfInstruction,
reinterpret_cast<uint8_t *>(info),
static_cast<TR_ExternalRelocationTargetKind>(_reloKind),
cg()),
__FILE__,__LINE__, getNode());
}
break;
}
}
Expand Down
18 changes: 14 additions & 4 deletions compiler/z/codegen/ConstantDataSnippet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,20 @@ TR::S390ConstantDataSnippet::addMetaDataForCodeAddress(uint8_t *cursor)
case TR_JNIVirtualTargetAddress:
{
AOTcgDiag3(comp, "add relocation (%d) cursor=%x symbolReference=%x\n", reloType, cursor, getSymbolReference());
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *)getNode()->getSymbolReference(),
getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1,
(TR_ExternalRelocationTargetKind) reloType, cg()),
__FILE__, __LINE__, getNode());

TR_RelocationRecordInformation *info = new (comp->trHeapMemory()) TR_RelocationRecordInformation();
info->data1 = 0;
info->data2 = reinterpret_cast<uintptr_t>(getNode()->getSymbolReference());
int16_t inlinedSiteIndex = getNode() ? getNode()->getInlinedSiteIndex() : -1;
info->data3 = static_cast<uintptr_t>(inlinedSiteIndex);

cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
cursor,
reinterpret_cast<uint8_t *>(info),
static_cast<TR_ExternalRelocationTargetKind>(reloType),
cg()),
__FILE__, __LINE__, getNode());
}
break;

Expand Down

0 comments on commit 9484ecf

Please sign in to comment.