Skip to content

Commit

Permalink
Deprecate FrontEnd allocateCodeMemory
Browse files Browse the repository at this point in the history
* introduce a CodeGenerator `allocateCodeMemoryInner` function that takes
  the place of the FrontEnd function and that downstream projects can
  override.
* improve documentation for existing CodeGenerator `allocateCodeMemory`
  functions
* remove FrontEnd API

Signed-off-by: Daryl Maier <maier@ca.ibm.com>
  • Loading branch information
0xdaryl committed Jan 30, 2019
1 parent 6d994e9 commit 330f258
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 56 deletions.
7 changes: 0 additions & 7 deletions compiler/codegen/FrontEnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ TR_FrontEnd::classHasBeenReplaced(TR_OpaqueClassBlock *)
return false;
}

uint8_t *
TR_FrontEnd::allocateCodeMemory(TR::Compilation *, uint32_t warmCodeSize, uint32_t coldCodeSize, uint8_t ** coldCode, bool isMethodHeaderNeeded)
{
notImplemented("allocateCodeMemory");
return 0;
}

uint8_t *
TR_FrontEnd::allocateRelocationData(TR::Compilation * comp, uint32_t numBytes)
{
Expand Down
1 change: 0 additions & 1 deletion compiler/codegen/FrontEnd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class TR_FrontEnd : public TR_Uncopyable
// Code cache
// --------------------------------------------------------------------------

virtual uint8_t * allocateCodeMemory(TR::Compilation *, uint32_t warmCodeSize, uint32_t coldCodeSize, uint8_t ** coldCode, bool isMethodHeaderNeeded=true);
virtual void reserveTrampolineIfNecessary(TR::Compilation *, TR::SymbolReference *symRef, bool inBinaryEncoding);
virtual intptrj_t methodTrampolineLookup(TR::Compilation *, TR::SymbolReference *symRef, void * callSite);
virtual intptrj_t indexedTrampolineLookup(int32_t helperIndex, void * callSite); // No TR::Compilation parameter so this can be called from runtime code
Expand Down
60 changes: 54 additions & 6 deletions compiler/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,28 +1719,76 @@ OMR::CodeGenerator::reserveCodeCache()
}

uint8_t *
OMR::CodeGenerator::allocateCodeMemory(uint32_t warmSize, uint32_t coldSize, uint8_t **coldCode, bool isMethodHeaderNeeded)
OMR::CodeGenerator::allocateCodeMemoryInner(
uint32_t warmCodeSizeInBytes,
uint32_t coldCodeSizeInBytes,
uint8_t **coldCode,
bool isMethodHeaderNeeded)
{
TR::CodeCache *codeCache = self()->getCodeCache();

TR_ASSERT(codeCache->isReserved(), "Code cache should have been reserved.");

uint8_t *warmCode = TR::CodeCacheManager::instance()->allocateCodeMemory(
warmCodeSizeInBytes,
coldCodeSizeInBytes,
&codeCache,
coldCode,
false,
isMethodHeaderNeeded);

if (codeCache != self()->getCodeCache())
{
// Either we didn't get a code cache, or the one we got should be reserved
TR_ASSERT(!codeCache || codeCache->isReserved(), "Substitute code cache isn't marked as reserved");
self()->comp()->setRelocatableMethodCodeStart(warmCode);
self()->switchCodeCacheTo(codeCache);
}

if (warmCode == NULL)
{
TR::Compilation *comp = self()->comp();

if (TR::CodeCacheManager::instance()->codeCacheIsFull())
{
comp->failCompilation<TR::CodeCacheError>("Code Cache Full");
}
else
{
comp->failCompilation<TR::RecoverableCodeCacheError>("Failed to allocate code memory");
}
}

TR_ASSERT( !((warmCodeSizeInBytes && !warmCode) || (coldCodeSizeInBytes && !coldCode)), "Allocation failed but didn't throw an exception");

return warmCode;
}

uint8_t *
OMR::CodeGenerator::allocateCodeMemory(uint32_t warmCodeSizeInBytes, uint32_t coldCodeSizeInBytes, uint8_t **coldCode, bool isMethodHeaderNeeded)
{
uint8_t *warmCode;
warmCode = self()->fe()->allocateCodeMemory(self()->comp(), warmSize, coldSize, coldCode, isMethodHeaderNeeded);
warmCode = self()->allocateCodeMemoryInner(warmCodeSizeInBytes, coldCodeSizeInBytes, coldCode, isMethodHeaderNeeded);

if (self()->getCodeGeneratorPhase() == TR::CodeGenPhase::BinaryEncodingPhase)
{
self()->commitToCodeCache();
}
TR_ASSERT( !((warmSize && !warmCode) || (coldSize && !coldCode)), "Allocation failed but didn't throw an exception");

TR_ASSERT( !((warmCodeSizeInBytes && !warmCode) || (coldCodeSizeInBytes && !coldCode)), "Allocation failed but didn't throw an exception");
return warmCode;
}

uint8_t *
OMR::CodeGenerator::allocateCodeMemory(uint32_t size, bool isCold, bool isMethodHeaderNeeded)
OMR::CodeGenerator::allocateCodeMemory(uint32_t codeSizeInBytes, bool isCold, bool isMethodHeaderNeeded)
{
uint8_t *coldCode;
if (isCold)
{
self()->allocateCodeMemory(0, size, &coldCode, isMethodHeaderNeeded);
self()->allocateCodeMemory(0, codeSizeInBytes, &coldCode, isMethodHeaderNeeded);
return coldCode;
}
return self()->allocateCodeMemory(size, 0, &coldCode, isMethodHeaderNeeded);
return self()->allocateCodeMemory(codeSizeInBytes, 0, &coldCode, isMethodHeaderNeeded);
}

void
Expand Down
53 changes: 51 additions & 2 deletions compiler/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,57 @@ class OMR_EXTENSIBLE CodeGenerator
TR::CodeCache * getCodeCache() { return _codeCache; }
void setCodeCache(TR::CodeCache * codeCache) { _codeCache = codeCache; }
void reserveCodeCache();
uint8_t * allocateCodeMemory(uint32_t size, bool isCold, bool isMethodHeaderNeeded=true);
uint8_t * allocateCodeMemory(uint32_t warmSize, uint32_t coldSize, uint8_t **coldCode, bool isMethodHeaderNeeded=true);

/**
* \brief Allocates code memory of the specified size in the specified area of
* the code cache. The compilation will fail if unsuccessful.
*
* \param[in] codeSizeInBytes : the number of bytes to allocate
* \param[in] isCold : whether the allocation should be done in the cold area or not
* \param[in] isMethodHeaderNeeded : boolean indicating whether space for a
* method header must be allocated
*
* \return address of the allocated code (if allocated)
*/
uint8_t *allocateCodeMemory(uint32_t codeSizeInBytes, bool isCold, bool isMethodHeaderNeeded=true);

/**
* \brief Allocates code memory of the specified size in the specified area of
* the code cache. The compilation will fail if unsuccessful.
*
* \param[in] warmCodeSizeInBytes : the number of bytes to allocate in the warm area
* \param[in] coldCodeSizeInBytes : the number of bytes to allocate in the cold area
* \param[out] coldCode : address of the cold code (if allocated)
* \param[in] isMethodHeaderNeeded : boolean indicating whether space for a
* method header must be allocated
*
* \return address of the allocated warm code (if allocated)
*/
uint8_t *allocateCodeMemory(
uint32_t warmCodeSizeInBytes,
uint32_t coldCodeSizeInBytes,
uint8_t **coldCode,
bool isMethodHeaderNeeded=true);

/**
* \brief Allocates code memory of the specified size in the specified area of
* the code cache. The compilation will fail if unsuccessful. This function
* provides a means of specialization in the allocation process for downstream
* consumers of this API.
*
* \param[in] warmCodeSizeInBytes : the number of bytes to allocate in the warm area
* \param[in] coldCodeSizeInBytes : the number of bytes to allocate in the cold area
* \param[out] coldCode : address of the cold code (if allocated)
* \param[in] isMethodHeaderNeeded : boolean indicating whether space for a
* method header must be allocated
*
* \return address of the allocated warm code (if allocated)
*/
uint8_t *allocateCodeMemoryInner(
uint32_t warmCodeSizeInBytes,
uint32_t coldCodeSizeInBytes,
uint8_t **coldCode,
bool isMethodHeaderNeeded);

/**
* \brief Trim the size of code memory required by this method to match the
Expand Down
2 changes: 0 additions & 2 deletions compiler/env/FEBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class FEBase : public FECommon
JitConfig *jitConfig() { return &_config; }
TR::CodeCacheManager &codeCacheManager() { return _codeCacheManager; }

virtual uint8_t *allocateCodeMemory(TR::Compilation *comp, uint32_t warmCodeSize, uint32_t coldCodeSize,
uint8_t **coldCode, bool isMethodHeaderNeeded);
virtual uint8_t * allocateRelocationData(TR::Compilation* comp, uint32_t size);

virtual intptrj_t indexedTrampolineLookup(int32_t helperIndex, void * callSite);
Expand Down
38 changes: 0 additions & 38 deletions compiler/env/FEBase_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,6 @@
namespace TR
{

template <class Derived>
uint8_t *
FEBase<Derived>::allocateCodeMemory(TR::Compilation *comp, uint32_t warmCodeSize, uint32_t coldCodeSize,
uint8_t **coldCode, bool isMethodHeaderNeeded)
{
TR::CodeGenerator *cg = comp->cg();
TR::CodeCache *codeCache = cg->getCodeCache();

TR_ASSERT(codeCache->isReserved(), "Code cache should have been reserved.");

uint8_t *warmCode = codeCacheManager().allocateCodeMemory(warmCodeSize, coldCodeSize, &codeCache,
coldCode, false, isMethodHeaderNeeded);

if (codeCache != cg->getCodeCache())
{
// Either we didn't get a code cache, or the one we get should be reserved
TR_ASSERT(!codeCache || codeCache->isReserved(), "Substitute code cache isn't marked as reserved");
comp->setRelocatableMethodCodeStart(warmCode);
cg->switchCodeCacheTo(codeCache);
}

if (warmCode == NULL)
{
if (codeCacheManager().codeCacheIsFull())
{
comp->failCompilation<TR::CodeCacheError>("Code Cache Full");
}
else
{
comp->failCompilation<TR::RecoverableCodeCacheError>("Failed to allocate code memory");
}
}

TR_ASSERT( !((warmCodeSize && !warmCode) || (coldCodeSize && !coldCode)), "Allocation failed but didn't throw an exception");

return warmCode;
}

// This code does not really belong here (along with allocateRelocationData, really)
// We should be relying on the port library to allocate memory, but this connection
// has not yet been made, so as a quick workaround for platforms like OS X <= 10.9,
Expand Down

0 comments on commit 330f258

Please sign in to comment.