Skip to content

Commit

Permalink
Track the total usage of the code cache
Browse files Browse the repository at this point in the history
To support `-XX:+PrintCodeCache`(eclipse-openj9/openj9#8184), the high water
mark of the code cache usage needs to be tracked.
The usage is tracked when increasing/decreasing the code cache repository
take place and also the reuse of the free blocks in the code cache.

Also added information on the config size, the total free size,
and the used size for each code cache in `printOccupancyStats()`
which is used by OpenJ9 to show the code cache usage
when `TR_PrintCompMem` is set.

Related to eclipse-openj9/openj9#8184

Signed-off-by: Annabelle Huo <Annabelle.Huo@ibm.com>
  • Loading branch information
a7ehuo committed Jan 22, 2020
1 parent 754ff1a commit 25211f2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
16 changes: 15 additions & 1 deletion compiler/runtime/OMRCodeCache.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1065,6 +1065,8 @@ OMR::CodeCache::addFreeBlock2WithCallSite(uint8_t *start,

self()->updateMaxSizeOfFreeBlocks(link, link->_size);

_manager->decreaseCurrTotalUsedInBytes(size);

if (config.verboseReclamation())
{
TR_VerboseLog::writeLineLocked(TR_Vlog_CODECACHE,"--ccr-- addFreeBlock2WithCallSite CC=%p start=%p end=%p mergedBlock=%p link=%p link->_size=%u, _sizeOfLargestFreeWarmBlock=%d _sizeOfLargestFreeColdBlock=%d warmCodeAlloc=%p coldBlockAlloc=%p",
Expand Down Expand Up @@ -1215,6 +1217,8 @@ OMR::CodeCache::findFreeBlock(size_t size, bool isCold, bool isMethodHeaderNeede
{
TR_VerboseLog::writeLineLocked(TR_Vlog_CODECACHE,"--ccr- findFreeBlock: CodeCache=%p size=%u isCold=%d bestFitLink=%p bestFitLink->size=%u leftBlock=%p", this, size, isCold, bestFitLink, bestFitLink->_size, leftBlock);
}

_manager->increaseCurrTotalUsedInBytes(bestFitLink->_size);
}
// Because we call this method only after we made sure a free block exists
// this function can never return NULL
Expand Down Expand Up @@ -1288,6 +1292,7 @@ OMR::CodeCache::printOccupancyStats()
fprintf(stderr, "Code Cache @%p flags=0x%x almostFull=%d\n", this, _flags, _almostFull);
fprintf(stderr, " cold-warm hole size = %8" OMR_PRIuSIZE " bytes\n", self()->getFreeContiguousSpace());
fprintf(stderr, " warmCodeAlloc=%p coldCodeAlloc=%p\n", (void*)_warmCodeAlloc, (void*)_coldCodeAlloc);
size_t totalRecliamed=0;
if (_freeBlockList)
{
fprintf(stderr, " sizeOfLargestFreeColdBlock = %8" OMR_PRIuSIZE " bytes\n", _sizeOfLargestFreeColdBlock);
Expand All @@ -1297,7 +1302,10 @@ OMR::CodeCache::printOccupancyStats()
{
CacheCriticalSection resolveAndCreateTrampoline(self());
for (CodeCacheFreeCacheBlock *currLink = _freeBlockList; currLink; currLink = currLink->_next)
{
fprintf(stderr, " %" OMR_PRIuSIZE, currLink->_size);
totalRecliamed += currLink->_size;
}
}
fprintf(stderr, "\n");
}
Expand All @@ -1309,6 +1317,12 @@ OMR::CodeCache::printOccupancyStats()
(int32_t)(_trampolineReservationMark - _trampolineBase),
(int32_t)(_tempTrampolineNext - _tempTrampolineBase));
}

size_t totalConfigSizeInBytes = config.codeCacheKB() * 1024;
size_t totalFreeSizeInBytes = self()->getFreeContiguousSpace() + totalRecliamed;
fprintf(stderr, " config size = %8" OMR_PRIuSIZE " bytes\n", totalConfigSizeInBytes);
fprintf(stderr, " total free size = %8" OMR_PRIuSIZE " bytes\n", totalFreeSizeInBytes);
fprintf(stderr, " total used size = %8" OMR_PRIuSIZE " bytes\n", totalConfigSizeInBytes - totalFreeSizeInBytes);
}


Expand Down
34 changes: 32 additions & 2 deletions compiler/runtime/OMRCodeCacheManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -56,7 +56,9 @@ TR::CodeCacheSymbolContainer * OMR::CodeCacheManager::_symbolContainer = NULL;
OMR::CodeCacheManager::CodeCacheManager(TR::RawAllocator rawAllocator) :
_rawAllocator(rawAllocator),
_initialized(false),
_codeCacheFull(false)
_codeCacheFull(false),
_currTotalUsedInBytes(0),
_maxUsedInBytes(0)
{
}

Expand All @@ -78,6 +80,10 @@ OMR::CodeCacheManager::RepositoryMonitorCriticalSection::RepositoryMonitorCritic
{
}

OMR::CodeCacheManager::UsageMonitorCriticalSection::UsageMonitorCriticalSection(TR::CodeCacheManager *mgr)
: CriticalSection(mgr->_usageMonitor)
{
}

TR::CodeCache *
OMR::CodeCacheManager::initialize(
Expand Down Expand Up @@ -141,6 +147,9 @@ OMR::CodeCacheManager::initialize(
if (_codeCacheList._mutex == NULL)
return NULL;

if (!(_usageMonitor = TR::Monitor::create("CodeCacheUsageMonitor")))
return NULL;

#if defined(TR_HOST_POWER)
#define REACHEABLE_RANGE_KB (32*1024)
#else
Expand Down Expand Up @@ -958,6 +967,23 @@ OMR::CodeCacheManager::chooseCacheStartAddress(size_t repositorySize)
}


void
OMR::CodeCacheManager::increaseCurrTotalUsedInBytes(size_t size)
{
UsageMonitorCriticalSection updateCodeCacheUsage(self());
_currTotalUsedInBytes += size;
_maxUsedInBytes = (_maxUsedInBytes < _currTotalUsedInBytes) ? _currTotalUsedInBytes : _maxUsedInBytes;
}


void
OMR::CodeCacheManager::decreaseCurrTotalUsedInBytes(size_t size)
{
UsageMonitorCriticalSection updateCodeCacheUsage(self());
_currTotalUsedInBytes = (size < _currTotalUsedInBytes) ? (_currTotalUsedInBytes - size) : 0;
}


void
OMR::CodeCacheManager::increaseFreeSpaceInCodeCacheRepository(size_t size)
{
Expand All @@ -969,6 +995,8 @@ OMR::CodeCacheManager::increaseFreeSpaceInCodeCacheRepository(size_t size)
// multiple compilation threads can adjust this value
if (self()->usingRepository())
{
self()->decreaseCurrTotalUsedInBytes(size);

RepositoryMonitorCriticalSection updateRepository(self());
_repositoryCodeCache->setColdCodeAlloc(_repositoryCodeCache->getColdCodeAlloc() + size);
}
Expand All @@ -986,6 +1014,8 @@ OMR::CodeCacheManager::decreaseFreeSpaceInCodeCacheRepository(size_t size)
// multiple compilation threads can adjust this value
if (self()->usingRepository())
{
self()->increaseCurrTotalUsedInBytes(size);

RepositoryMonitorCriticalSection updateRepository(self());
_repositoryCodeCache->setColdCodeAlloc(_repositoryCodeCache->getColdCodeAlloc() - size);
}
Expand Down
16 changes: 15 additions & 1 deletion compiler/runtime/OMRCodeCacheManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -128,6 +128,12 @@ class OMR_EXTENSIBLE CodeCacheManager
RepositoryMonitorCriticalSection(TR::CodeCacheManager *mgr);
};

class UsageMonitorCriticalSection : public CriticalSection
{
public:
UsageMonitorCriticalSection(TR::CodeCacheManager *mgr);
};

TR::CodeCacheConfig & codeCacheConfig() { return _config; }

/**
Expand Down Expand Up @@ -274,6 +280,11 @@ class OMR_EXTENSIBLE CodeCacheManager
*/
void freeCodeCacheSegment(TR::CodeCacheMemorySegment * memSegment) {}

void increaseCurrTotalUsedInBytes(size_t size);
void decreaseCurrTotalUsedInBytes(size_t size);
size_t getCurrTotalUsedInBytes() const { return _currTotalUsedInBytes; }
size_t getMaxUsedInBytes() const { return _maxUsedInBytes; }

protected:

TR::RawAllocator _rawAllocator;
Expand All @@ -291,6 +302,9 @@ class OMR_EXTENSIBLE CodeCacheManager
bool _lowCodeCacheSpaceThresholdReached; /*!< true if close to exhausting available code cache */
bool _codeCacheFull;

TR::Monitor *_usageMonitor;
size_t _currTotalUsedInBytes;
size_t _maxUsedInBytes;
#if (HOST_OS == OMR_LINUX)
public:
/**
Expand Down

0 comments on commit 25211f2

Please sign in to comment.