Skip to content

Commit

Permalink
Merge pull request #4576 from 0xdaryl/rereserve
Browse files Browse the repository at this point in the history
Share implementation to re-reserve trampolines on code cache switch
  • Loading branch information
fjeremic authored Nov 21, 2019
2 parents 1e4b624 + 4b5d965 commit 629ebe5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 53 deletions.
17 changes: 1 addition & 16 deletions compiler/arm/codegen/ARMBinaryEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,7 @@ uint8_t *TR::ARMImmSymInstruction::generateBinaryEncoding()

if (cg()->hasCodeCacheSwitched())
{
TR::SymbolReference *calleeSymRef = NULL;

if (label == NULL)
calleeSymRef = getSymbolReference();
else if (getNode() != NULL)
calleeSymRef = getNode()->getSymbolReference();

if (calleeSymRef != NULL)
{
if (calleeSymRef->getReferenceNumber()>=TR_ARMnumRuntimeHelpers)
cg()->fe()->reserveTrampolineIfNecessary(comp, calleeSymRef, true);
}
else
{
TR_ASSERT(0, "Missing possible re-reservation for trampolines.\n");
}
cg()->redoTrampolineReservationIfNecessary(this, getSymbolReference());
}

TR::ResolvedMethodSymbol *sym = getSymbolReference()->getSymbol()->getResolvedMethodSymbol();
Expand Down
29 changes: 29 additions & 0 deletions compiler/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3251,3 +3251,32 @@ OMR::CodeGenerator::switchCodeCacheTo(TR::CodeCache *newCodeCache)
}

}


void
OMR::CodeGenerator::redoTrampolineReservationIfNecessary(TR::Instruction *callInstr, TR::SymbolReference *instructionSymRef)
{
TR_ASSERT_FATAL(instructionSymRef, "Expecting instruction to have a SymbolReference");

/**
* Determine the callee symbol reference based on the target of the call instruction
*/
TR::LabelSymbol *labelSymbol = instructionSymRef->getSymbol()->getLabelSymbol();
TR::SymbolReference *calleeSymRef = NULL;

if (labelSymbol == NULL)
{
calleeSymRef = instructionSymRef;
}
else if (callInstr->getNode() != NULL)
{
calleeSymRef = callInstr->getNode()->getSymbolReference();
}

TR_ASSERT_FATAL(calleeSymRef != NULL, "Missing possible re-reservation for trampolines");

if (calleeSymRef->getReferenceNumber() >= TR_numRuntimeHelpers)
{
self()->fe()->reserveTrampolineIfNecessary(self()->comp(), calleeSymRef, true);
}
}
27 changes: 22 additions & 5 deletions compiler/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class OMR_EXTENSIBLE CodeGenerator

uint32_t getPreJitMethodEntrySize() {return _preJitMethodEntrySize;}
uint32_t setPreJitMethodEntrySize(uint32_t s) {return (_preJitMethodEntrySize = s);}

/** \brief
* Determines whether the code generator supports or allows JIT-to-JIT method entry point alignment.
*/
Expand All @@ -772,7 +772,7 @@ class OMR_EXTENSIBLE CodeGenerator
* specified to be \c x and the JIT-to-JIT method entry point to be \c y then <c>y & (x - 1) == 0</c>.
*/
uint32_t getJitMethodEntryAlignmentBoundary();

/** \brief
* Determines the byte threshold at which the JIT-to-JIT method entry point boundary alignment will not be
* performed. If the JIT-to-JIT method entry point is already close to the boundary then it may not make sense
Expand Down Expand Up @@ -1073,7 +1073,7 @@ class OMR_EXTENSIBLE CodeGenerator

TR::list<TR::Register*> *getSpilledRegisterList() {return _spilledRegisterList;}
TR::list<TR::Register*> *setSpilledRegisterList(TR::list<TR::Register*> *r) {return _spilledRegisterList = r;}

TR_BackingStore *allocateSpill(bool containsCollectedReference, int32_t *offset, bool reuse=true);
TR_BackingStore *allocateSpill(int32_t size, bool containsCollectedReference, int32_t *offset, bool reuse=true);
TR_BackingStore *allocateInternalPointerSpill(TR::AutomaticSymbol *pinningArrayPointer);
Expand Down Expand Up @@ -1402,7 +1402,24 @@ class OMR_EXTENSIBLE CodeGenerator
return true;
}

// --------------------------------------------------------------------------
/**
* @brief
* Redo the trampoline reservation for a call target, if a trampoline might be
* required for the target. This is typically required if a new code cache is
* allocated between the instruction selection and binary encoding phases.
*
* @details
* Note that the instructionSymRef cannot simply be read from the provided instruction
* because this function is shared across multiple architectures with incompatible
* instruction hierarchies.
*
* @param[in] callInstr : the call instruction to which this trampoline applies
* @param[in] instructionSymRef : the TR::SymbolReference present on the instruction
*
*/
void redoTrampolineReservationIfNecessary(TR::Instruction *callInstr, TR::SymbolReference *instructionSymRef);

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

bool constantAddressesCanChangeSize(TR::Node *node);
bool profiledPointersRequireRelocation();
Expand Down Expand Up @@ -1892,7 +1909,7 @@ class OMR_EXTENSIBLE CodeGenerator
TR::list<TR::Register*> *_spilledRegisterList;
TR::list<OMR::RegisterUsage*> *_referencedRegistersList;
int32_t _currentPathDepth;



TR_Array<void *> _monitorMapping;
Expand Down
18 changes: 1 addition & 17 deletions compiler/x/codegen/X86BinaryEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,23 +1220,7 @@ uint8_t* TR::X86ImmSymInstruction::generateOperand(uint8_t* cursor)

if (TR::Compiler->target.is64Bit() && cg()->hasCodeCacheSwitched() && getOpCodeValue() == CALLImm4)
{
TR::SymbolReference *calleeSymRef = NULL;
TR::LabelSymbol *labelSym = sym->getLabelSymbol();

if (labelSym==NULL)
calleeSymRef = getSymbolReference();
else if (getNode() != NULL)
calleeSymRef = getNode()->getSymbolReference();

if (calleeSymRef != NULL)
{
if (calleeSymRef->getReferenceNumber()>=TR_AMD64numRuntimeHelpers)
cg()->fe()->reserveTrampolineIfNecessary(comp, calleeSymRef, true);
}
else
{
TR_ASSERT(0, "Missing possible re-reservation for trampolines.\n");
}
cg()->redoTrampolineReservationIfNecessary(this, getSymbolReference());
}

intptrj_t currentInstructionAddress = (intptrj_t)(cursor-1);
Expand Down
16 changes: 1 addition & 15 deletions compiler/z/codegen/S390Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2392,21 +2392,7 @@ TR::S390RILInstruction::generateBinaryEncoding()
{
if (cg()->hasCodeCacheSwitched())
{
TR::SymbolReference *calleeSymRef = NULL;

calleeSymRef = getSymbolReference();

if (calleeSymRef != NULL)
{
if (calleeSymRef->getReferenceNumber()>=TR_S390numRuntimeHelpers)
cg()->fe()->reserveTrampolineIfNecessary(comp, calleeSymRef, true);
}
else
{
#ifdef DEBUG
printf("Missing possible re-reservation for trampolines.\n");
#endif
}
cg()->redoTrampolineReservationIfNecessary(this, getSymbolReference());
}
}
#endif
Expand Down

0 comments on commit 629ebe5

Please sign in to comment.