Skip to content

Commit

Permalink
Merge pull request #7039 from dsouzai/xtraceAOT
Browse files Browse the repository at this point in the history
Add relocation infrastructure to make enter/exit tracing consistent with default compilation
  • Loading branch information
jdmpapin authored Jul 26, 2023
2 parents 436bad3 + 50cffa9 commit 1dd4e59
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 18 deletions.
4 changes: 4 additions & 0 deletions compiler/aarch64/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ static void loadRelocatableConstant(TR::Node *node,
{
loadAddressConstant(cg, true, GCRnode, (intptr_t)ref, reg, NULL, TR_ClassAddress);
}
else if (symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress())
{
loadAddressConstant(cg, true, GCRnode, 1, reg, NULL, TR_MethodEnterExitHookAddress);
}
else
{
loadConstant64(cg, node, addr, reg);
Expand Down
10 changes: 10 additions & 0 deletions compiler/aarch64/codegen/OMRTreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5926,6 +5926,16 @@ addMetaDataForLoadAddressConstantFixed(TR::CodeGenerator *cg, TR::Node *node, TR
}
break;
}

case TR_MethodEnterExitHookAddress:
{
relo = new (cg->trHeapMemory()) TR::BeforeBinaryEncodingExternalRelocation(
firstInstruction,
(uint8_t *)node->getSymbolReference(),
NULL,
TR_MethodEnterExitHookAddress, cg);
break;
}
}

if (!relo)
Expand Down
4 changes: 4 additions & 0 deletions compiler/arm/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,10 @@ static void loadRelocatableConstant(TR::Node *node,
{
loadAddressConstant(cg, GCRnode, 1, reg, NULL, false, TR_DataAddress);
}
else if (symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress())
{
loadAddressConstant(cg, GCRnode, 1, reg, NULL, false, TR_MethodEnterExitHookAddress);
}
else
{
cg->addSnippet(mr->setUnresolvedSnippet(new (cg->trHeapMemory()) TR::UnresolvedDataSnippet(cg, node, ref, node->getOpCode().isStore(), false)));
Expand Down
14 changes: 14 additions & 0 deletions compiler/arm/codegen/OMRTreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,20 @@ TR::Instruction *loadAddressConstantFixed(TR::CodeGenerator *cg, TR::Node * node
node);
}
}
else if (typeAddress == TR_MethodEnterExitHookAddress)
{
if (doAOTRelocation)
{
cg->addExternalRelocation(new (cg->trHeapMemory()) TR::BeforeBinaryEncodingExternalRelocation(
cursor,
(uint8_t *)node->getSymbolReference(),
(uint8_t *)seqKind,
(TR_ExternalRelocationTargetKind)typeAddress, cg),
__FILE__,
__LINE__,
node);
}
}
else
{
if (doAOTRelocation)
Expand Down
9 changes: 5 additions & 4 deletions compiler/codegen/Relocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ uint8_t TR::ExternalOrderedPair32BitRelocation::collectModifier()

if (comp->target().cpu.isPower() &&
(kind == TR_ArrayCopyHelper || kind == TR_ArrayCopyToc || kind == TR_RamMethod || kind == TR_GlobalValue || kind == TR_BodyInfoAddressLoad || kind == TR_DataAddress
|| kind == TR_DebugCounter || kind == TR_BlockFrequency || kind == TR_RecompQueuedFlag || kind == TR_CatchBlockCounter))
|| kind == TR_DebugCounter || kind == TR_BlockFrequency || kind == TR_RecompQueuedFlag || kind == TR_CatchBlockCounter || kind == TR_MethodEnterExitHookAddress))
{
TR::Instruction *instr = (TR::Instruction *)getUpdateLocation();
TR::Instruction *instr2 = (TR::Instruction *)getLocation2();
Expand All @@ -322,9 +322,9 @@ uint8_t TR::ExternalOrderedPair32BitRelocation::collectModifier()
int32_t iLoc2 = static_cast<int32_t>(updateLocation2 - relocatableMethodCodeStart);

if ( (iLoc < MIN_SHORT_OFFSET || iLoc > MAX_SHORT_OFFSET ) || (iLoc2 < MIN_SHORT_OFFSET || iLoc2 > MAX_SHORT_OFFSET ) )
return RELOCATION_TYPE_WIDE_OFFSET | RELOCATION_TYPE_ORDERED_PAIR;
return RELOCATION_TYPE_WIDE_OFFSET | ITERATED_RELOCATION_TYPE_ORDERED_PAIR;

return RELOCATION_TYPE_ORDERED_PAIR;
return ITERATED_RELOCATION_TYPE_ORDERED_PAIR;
}


Expand All @@ -337,7 +337,7 @@ void TR::ExternalOrderedPair32BitRelocation::apply(TR::CodeGenerator *cg)
TR_ExternalRelocationTargetKind kind = getRelocationRecord()->getTargetKind();
if (comp->target().cpu.isPower() &&
(kind == TR_ArrayCopyHelper || kind == TR_ArrayCopyToc || kind == TR_RamMethodSequence || kind == TR_GlobalValue || kind == TR_BodyInfoAddressLoad || kind == TR_DataAddress
|| kind == TR_DebugCounter || kind == TR_BlockFrequency || kind == TR_RecompQueuedFlag || kind == TR_CatchBlockCounter))
|| kind == TR_DebugCounter || kind == TR_BlockFrequency || kind == TR_RecompQueuedFlag || kind == TR_CatchBlockCounter || kind == TR_MethodEnterExitHookAddress))
{
TR::Instruction *instr = (TR::Instruction *)getUpdateLocation();
TR::Instruction *instr2 = (TR::Instruction *)getLocation2();
Expand Down Expand Up @@ -469,6 +469,7 @@ const char *TR::ExternalRelocation::_externalRelocationTargetKindNames[TR_NumExt
"TR_ValidateIsClassVisible (112)",
"TR_CatchBlockCounter (113)",
"TR_StartPC (114)",
"TR_MethodEnterExitHookAddress (115)",
};

uintptr_t TR::ExternalRelocation::_globalValueList[TR_NumGlobalValueItems] =
Expand Down
4 changes: 2 additions & 2 deletions compiler/codegen/Relocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ class IteratedExternalRelocation : public TR_Link<TR::IteratedExternalRelocation
{return _recordModifier.testAny(RELOCATION_TYPE_WIDE_OFFSET);}
void setNeedsWideOffsets() {_recordModifier.set(RELOCATION_TYPE_WIDE_OFFSET);}

bool isOrderedPair() {return _recordModifier.testAny(RELOCATION_TYPE_ORDERED_PAIR);}
void setOrderedPair() {_recordModifier.set(RELOCATION_TYPE_ORDERED_PAIR);}
bool isOrderedPair() {return _recordModifier.testAny(ITERATED_RELOCATION_TYPE_ORDERED_PAIR);}
void setOrderedPair() {_recordModifier.set(ITERATED_RELOCATION_TYPE_ORDERED_PAIR);}

uint8_t getModifierValue() {return _recordModifier.getValue();}
void setModifierValue(uint8_t v) {_recordModifier.setValue(0x00, v);}
Expand Down
8 changes: 8 additions & 0 deletions compiler/il/OMRSymbol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ class OMR_EXTENSIBLE Symbol
void setIsCatchBlockCounter() { _flags2.set(CatchBlockCounter); }
bool isCatchBlockCounter() { return _flags2.testAny(CatchBlockCounter); }

void setIsEnterEventHookAddress() { _flags2.set(EnterEventHookAddress); }
bool isEnterEventHookAddress() { return _flags2.testAny(EnterEventHookAddress); }

void setIsExitEventHookAddress() { _flags2.set(ExitEventHookAddress); }
bool isExitEventHookAddress() { return _flags2.testAny(ExitEventHookAddress); }

inline bool isNamed();

// flag methods specific to Autos
Expand Down Expand Up @@ -600,6 +606,8 @@ class OMR_EXTENSIBLE Symbol
*/
StaticDefaultValueInstance = 0x00020000,
CatchBlockCounter = 0x00040000,
EnterEventHookAddress = 0x00080000,
ExitEventHookAddress = 0x00100000,
};

protected:
Expand Down
18 changes: 18 additions & 0 deletions compiler/p/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,16 @@ OMR::Power::CodeGenerator::addMetaDataForLoadAddressConstantFixed(
value = (uintptr_t)node->getSymbolReference();
break;
}

case TR_MethodEnterExitHookAddress:
{
relo = new (self()->trHeapMemory()) TR::BeforeBinaryEncodingExternalRelocation(
firstInstruction,
(uint8_t *)node->getSymbolReference(),
(uint8_t *)seqKind,
TR_MethodEnterExitHookAddress, self());
break;
}
}

if (comp->getOption(TR_UseSymbolValidationManager) && !relo)
Expand Down Expand Up @@ -2153,6 +2163,14 @@ OMR::Power::CodeGenerator::addMetaDataForLoadIntConstantFixed(
(TR_ExternalRelocationTargetKind)typeAddress, self()),
__FILE__, __LINE__, node);
}
else if (typeAddress == TR_MethodEnterExitHookAddress)
{
self()->addExternalRelocation(new (self()->trHeapMemory()) TR::ExternalOrderedPair32BitRelocation((uint8_t *)firstInstruction,
(uint8_t *)node->getSymbolReference(),
(uint8_t *)orderedPairSequence2,
(TR_ExternalRelocationTargetKind)TR_MethodEnterExitHookAddress, self()),
__FILE__, __LINE__, node);
}
else if (typeAddress != -1)
{
TR_RelocationRecordInformation *recordInfo = ( TR_RelocationRecordInformation *)comp->trMemory()->allocateMemory(sizeof( TR_RelocationRecordInformation), heapAlloc);
Expand Down
17 changes: 14 additions & 3 deletions compiler/p/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ TR::Instruction *OMR::Power::MemoryReference::expandInstruction(TR::Instruction
cg,
TR::InstOpCode::Op_st,
node,
TR::MemoryReference::createWithDisplacement(cg, stackPtr, -saveLen, saveLen),
TR::MemoryReference::createWithDisplacement(cg, stackPtr, -saveLen, saveLen),
rX,
prevInstruction
);
Expand All @@ -1504,7 +1504,7 @@ TR::Instruction *OMR::Power::MemoryReference::expandInstruction(TR::Instruction
TR::InstOpCode::Op_load,
node,
rX,
TR::MemoryReference::createWithDisplacement(cg, stackPtr, -saveLen, saveLen),
TR::MemoryReference::createWithDisplacement(cg, stackPtr, -saveLen, saveLen),
currentInstruction
);
}
Expand Down Expand Up @@ -1632,6 +1632,12 @@ void OMR::Power::MemoryReference::accessStaticItem(TR::Node *node, TR::SymbolRef
loadAddressConstant(cg, true, nodeForSymbol, 1, reg, NULL, false, TR_RecompQueuedFlag);
return;
}
else if ((symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress()) && cg->comp()->compileRelocatableCode())
{
TR::Register *reg = _baseRegister = cg->allocateRegister();
loadAddressConstant(cg, true, nodeForSymbol, 1, reg, NULL, false, TR_MethodEnterExitHookAddress);
return;
}
else
{
TR_ASSERT_FATAL(!comp->getOption(TR_UseSymbolValidationManager) || ref->isUnresolved(), "SVM relocation unhandled");
Expand Down Expand Up @@ -1782,7 +1788,12 @@ void OMR::Power::MemoryReference::accessStaticItem(TR::Node *node, TR::SymbolRef
loadAddressConstant(cg, true, nodeForSymbol, 1, reg, NULL, false, TR_RecompQueuedFlag);
return;
}

else if ((symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress()) && cg->comp()->compileRelocatableCode())
{
TR::Register *reg = _baseRegister = cg->allocateRegister();
loadAddressConstant(cg, true, nodeForSymbol, 1, reg, NULL, false, TR_MethodEnterExitHookAddress);
return;
}
else if (refIsUnresolved || useUnresSnippetToAvoidRelo)
{
self()->setUnresolvedSnippet(new (cg->trHeapMemory()) TR::UnresolvedDataSnippet(cg, node, ref, isStore, false));
Expand Down
28 changes: 19 additions & 9 deletions compiler/runtime/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,24 @@ inline TR_LinkageConventions runtimeHelperLinkage(TR_RuntimeHelper h) { return r

// -----------------------------------------------------------------------------

// Relocation flags and masks
typedef enum
{
RELOCATION_TYPE_EIP_OFFSET = 0x1,
RELOCATION_TYPE_WIDE_OFFSET = 0x2,

ITERATED_RELOCATION_TYPE_ORDERED_PAIR = 0x4,

#define RELOCATION_TYPE_DESCRIPTION_MASK 15
#define RELOCATION_TYPE_ORDERED_PAIR 32
#define RELOCATION_TYPE_EIP_OFFSET 0x40
#define RELOCATION_TYPE_WIDE_OFFSET 0x80
#define RELOCATION_CROSS_PLATFORM_FLAGS_MASK (RELOCATION_TYPE_EIP_OFFSET | RELOCATION_TYPE_WIDE_OFFSET)
#define RELOCATION_RELOC_FLAGS_MASK (~RELOCATION_CROSS_PLATFORM_FLAGS_MASK)
// ITERATED_RELOCATION_TYPE_ORDERED_PAIR is not stored in the binary template
// as the isOrderedPairRelocation API is used to determine whether a given
// relocation is an Orderd Pair Relocation or not.
RELOCATION_CROSS_PLATFORM_FLAGS_MASK = (RELOCATION_TYPE_EIP_OFFSET | RELOCATION_TYPE_WIDE_OFFSET),

RELOCATION_RELOC_FLAGS_MASK = (~RELOCATION_CROSS_PLATFORM_FLAGS_MASK),
RELOCATION_RELOC_FLAGS_SHIFT = 4,

} TR_RelocationFlagUtilities;

#define RELOCATION_TYPE_ARRAY_COPY_SUBTYPE 32
#define RELOCATION_TYPE_ARRAY_COPY_TOC 64
// These macros are intended for use when HI_VALUE and LO_VALUE will be recombined after LO_VALUE is sign-extended
// (e.g. when LO_VALUE is used with an instruction that takes a signed 16-bit operand).
// In this case we have to adjust HI_VALUE now so that the original value will be obtained once the two are recombined.
Expand Down Expand Up @@ -340,10 +348,12 @@ typedef enum
TR_ValidateIsClassVisible = 112,
TR_CatchBlockCounter = 113,
TR_StartPC = 114,
TR_NumExternalRelocationKinds = 115,
TR_MethodEnterExitHookAddress = 115,
TR_NumExternalRelocationKinds = 116,
TR_ExternalRelocationTargetKindMask = 0xff,
} TR_ExternalRelocationTargetKind;


namespace TR {

enum SymbolType
Expand Down
16 changes: 16 additions & 0 deletions compiler/x/amd64/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,22 @@ OMR::X86::AMD64::MemoryReference::addMetaDataForCodeAddressWithLoad(
counter);
}
}
else if (sr.getSymbol()->isEnterEventHookAddress() || sr.getSymbol()->isExitEventHookAddress())
{
if (cg->needRelocationsForStatics())
{
cg->addExternalRelocation(
TR::ExternalRelocation::create(
displacementLocation,
(uint8_t *)srCopy,
NULL,
TR_MethodEnterExitHookAddress,
cg),
__FILE__,
__LINE__,
containingInstruction->getNode());
}
}
}
else
{
Expand Down
13 changes: 13 additions & 0 deletions compiler/x/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,19 @@ OMR::X86::MemoryReference::addMetaDataForCodeAddress(
node,
counter);
}
else if (symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress())
{
cg->addExternalRelocation(
TR::ExternalRelocation::create(
cursor,
(uint8_t *)&self()->getSymbolReference(),
NULL,
TR_MethodEnterExitHookAddress,
cg),
__FILE__,
__LINE__,
node);
}
else
{
cg->addExternalRelocation(
Expand Down
6 changes: 6 additions & 0 deletions compiler/x/codegen/OMRX86Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,10 @@ TR::X86RegImmSymInstruction::autoSetReloKind()
{
setReloKind(TR_RecompQueuedFlag);
}
else if (symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress())
{
setReloKind(TR_MethodEnterExitHookAddress);
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -4460,6 +4464,8 @@ TR::AMD64RegImm64SymInstruction::autoSetReloKind()
setReloKind(TR_BlockFrequency);
else if (symbol->isRecompQueuedFlag())
setReloKind(TR_RecompQueuedFlag);
else if (symbol->isEnterEventHookAddress() || symbol->isExitEventHookAddress())
setReloKind(TR_MethodEnterExitHookAddress);
else
setReloKind(-1);
}
Expand Down
Loading

0 comments on commit 1dd4e59

Please sign in to comment.