diff --git a/compiler/runtime/OMRCodeCache.cpp b/compiler/runtime/OMRCodeCache.cpp index 3efda37f737..a4c5afb87e2 100644 --- a/compiler/runtime/OMRCodeCache.cpp +++ b/compiler/runtime/OMRCodeCache.cpp @@ -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 @@ -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", @@ -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 @@ -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); @@ -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"); } @@ -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); } diff --git a/compiler/runtime/OMRCodeCacheManager.cpp b/compiler/runtime/OMRCodeCacheManager.cpp index d4a16f33da1..3607a476718 100644 --- a/compiler/runtime/OMRCodeCacheManager.cpp +++ b/compiler/runtime/OMRCodeCacheManager.cpp @@ -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 @@ -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) { } @@ -78,6 +80,10 @@ OMR::CodeCacheManager::RepositoryMonitorCriticalSection::RepositoryMonitorCritic { } +OMR::CodeCacheManager::UsageMonitorCriticalSection::UsageMonitorCriticalSection(TR::CodeCacheManager *mgr) + : CriticalSection(mgr->_usageMonitor) + { + } TR::CodeCache * OMR::CodeCacheManager::initialize( @@ -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 @@ -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) { @@ -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); } @@ -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); } diff --git a/compiler/runtime/OMRCodeCacheManager.hpp b/compiler/runtime/OMRCodeCacheManager.hpp index 535fa1b077a..d4abc30dc73 100644 --- a/compiler/runtime/OMRCodeCacheManager.hpp +++ b/compiler/runtime/OMRCodeCacheManager.hpp @@ -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 @@ -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; } /** @@ -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; @@ -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: /**