Skip to content

Commit

Permalink
Add getJitMethodEntryAlignmentThreshold API
Browse files Browse the repository at this point in the history
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 to perform the boundary alignment as much code cache can be
wasted. This threshold can be used to avoid such situations.

Signed-off-by: Filip Jeremic <fjeremic@ca.ibm.com>
  • Loading branch information
fjeremic committed Sep 19, 2019
1 parent 3159106 commit f509723
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
24 changes: 18 additions & 6 deletions compiler/codegen/OMRCodeGenerator.cpp
Expand Up @@ -2160,17 +2160,23 @@ OMR::CodeGenerator::alignBinaryBufferCursor()
{
uintptr_t boundary = self()->getJitMethodEntryAlignmentBoundary();

/* Align cursor to boundary */
// Align cursor to boundary as long as it meets the threshold
if (boundary && (boundary & boundary - 1) == 0)
{
uintptr_t round = boundary - 1;
uintptr_t offset = self()->getPreJitMethodEntrySize();

_binaryBufferCursor += offset;
_binaryBufferCursor = (uint8_t *)(((uintptr_t)_binaryBufferCursor + round) & ~round);
_binaryBufferCursor -= offset;
self()->setJitMethodEntryPaddingSize(_binaryBufferCursor - _binaryBufferStart);
memset(_binaryBufferStart, 0, self()->getJitMethodEntryPaddingSize());
uint8_t* alignedBufferCursor = _binaryBufferCursor;
alignedBufferCursor += offset;
alignedBufferCursor = (uint8_t *)(((uintptr_t)alignedBufferCursor + round) & ~round);
alignedBufferCursor -= offset;

if (alignedBufferCursor - _binaryBufferCursor <= self()->getJitMethodEntryAlignmentThreshold())
{
_binaryBufferCursor = alignedBufferCursor;
self()->setJitMethodEntryPaddingSize(_binaryBufferCursor - _binaryBufferStart);
memset(_binaryBufferStart, 0, self()->getJitMethodEntryPaddingSize());
}
}

return _binaryBufferCursor;
Expand All @@ -2182,6 +2188,12 @@ OMR::CodeGenerator::getJitMethodEntryAlignmentBoundary()
return 1;
}

uint32_t
OMR::CodeGenerator::getJitMethodEntryAlignmentThreshold()
{
return self()->getJitMethodEntryAlignmentBoundary();
}

int32_t
OMR::CodeGenerator::setEstimatedLocationsForSnippetLabels(int32_t estimatedSnippetStart)
{
Expand Down
11 changes: 11 additions & 0 deletions compiler/codegen/OMRCodeGenerator.hpp
Expand Up @@ -766,6 +766,17 @@ 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
* to perform the boundary alignment as much code cache can be wasted. This threshold can be used to avoid such
* situations.
*
* \note
* This value must be less than or equal to the boundary returned via \see getJitMethodEntryAlignmentBoundary.
*/
uint32_t getJitMethodEntryAlignmentThreshold();

uint32_t getJitMethodEntryPaddingSize() {return _jitMethodEntryPaddingSize;}
uint32_t setJitMethodEntryPaddingSize(uint32_t s) {return (_jitMethodEntryPaddingSize = s);}
Expand Down
6 changes: 6 additions & 0 deletions compiler/z/codegen/OMRCodeGenerator.cpp
Expand Up @@ -4699,6 +4699,12 @@ OMR::Z::CodeGenerator::getJitMethodEntryAlignmentBoundary()
return 256;
}

uint32_t
OMR::Z::CodeGenerator::getJitMethodEntryAlignmentThreshold()
{
return 192;
}

/**
* This function sign extended the specified number of high order bits in the register.
*/
Expand Down
2 changes: 2 additions & 0 deletions compiler/z/codegen/OMRCodeGenerator.hpp
Expand Up @@ -783,6 +783,8 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator

uint32_t getJitMethodEntryAlignmentBoundary();

uint32_t getJitMethodEntryAlignmentThreshold();

// LL: move to .cpp
bool arithmeticNeedsLiteralFromPool(TR::Node *node);

Expand Down

0 comments on commit f509723

Please sign in to comment.