From f5097237fe7a3f214c944ba550dcd0ba05538455 Mon Sep 17 00:00:00 2001 From: Filip Jeremic Date: Fri, 13 Sep 2019 14:09:18 -0400 Subject: [PATCH] Add getJitMethodEntryAlignmentThreshold API 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 --- compiler/codegen/OMRCodeGenerator.cpp | 24 ++++++++++++++++++------ compiler/codegen/OMRCodeGenerator.hpp | 11 +++++++++++ compiler/z/codegen/OMRCodeGenerator.cpp | 6 ++++++ compiler/z/codegen/OMRCodeGenerator.hpp | 2 ++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/compiler/codegen/OMRCodeGenerator.cpp b/compiler/codegen/OMRCodeGenerator.cpp index 892be16aea9..09a64f61199 100644 --- a/compiler/codegen/OMRCodeGenerator.cpp +++ b/compiler/codegen/OMRCodeGenerator.cpp @@ -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; @@ -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) { diff --git a/compiler/codegen/OMRCodeGenerator.hpp b/compiler/codegen/OMRCodeGenerator.hpp index e10dbb84de9..410fd440f79 100644 --- a/compiler/codegen/OMRCodeGenerator.hpp +++ b/compiler/codegen/OMRCodeGenerator.hpp @@ -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 y & (x - 1) == 0. */ 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);} diff --git a/compiler/z/codegen/OMRCodeGenerator.cpp b/compiler/z/codegen/OMRCodeGenerator.cpp index 29bd8ccd790..beeef6d3752 100644 --- a/compiler/z/codegen/OMRCodeGenerator.cpp +++ b/compiler/z/codegen/OMRCodeGenerator.cpp @@ -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. */ diff --git a/compiler/z/codegen/OMRCodeGenerator.hpp b/compiler/z/codegen/OMRCodeGenerator.hpp index 592fd34b7af..69bdc44f341 100644 --- a/compiler/z/codegen/OMRCodeGenerator.hpp +++ b/compiler/z/codegen/OMRCodeGenerator.hpp @@ -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);