Skip to content

Commit

Permalink
Implement RSSReport class
Browse files Browse the repository at this point in the history
- Implement a class that can monitor RSS status of any number
  of arbitry memory regions
- In addition to start address and size, region can have name,
  as well as a list of items describing its content
  • Loading branch information
gita-omr committed Jul 10, 2024
1 parent d58019e commit 156d9f2
Show file tree
Hide file tree
Showing 12 changed files with 901 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4983,7 +4983,9 @@ const char *OMR::Options::_verboseOptionNames[TR_NumVerboseOptions] =
"vectorAPI",
"iprofilerPersistence",
"CheckpointRestore",
"CheckpointRestoreDetails"
"CheckpointRestoreDetails",
"RSSReport",
"RSSReportDetailed"
};


Expand Down
2 changes: 2 additions & 0 deletions compiler/control/OMROptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,8 @@ enum TR_VerboseFlags
TR_VerboseIProfilerPersistence,
TR_VerboseCheckpointRestore,
TR_VerboseCheckpointRestoreDetails,
TR_VerboseRSSReport,
TR_VerboseRSSReportDetailed,
//If adding new options add an entry to _verboseOptionNames as well
TR_NumVerboseOptions // Must be the last one;
};
Expand Down
31 changes: 31 additions & 0 deletions compiler/ras/DebugCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "env/PersistentInfo.hpp"
#include "env/jittypes.h"
#include "env/StackMemoryRegion.hpp"
#include "env/VerboseLog.hpp"
#include "il/DataTypes.hpp"
#include "il/ILOpCodes.hpp"
#include "il/Node.hpp"
Expand Down Expand Up @@ -462,6 +463,36 @@ void TR::DebugCounterAggregation::accumulate()
}
}


int64_t TR::DebugCounterAggregation::getCount()
{
int64_t count = 0;
ListIterator<CounterDelta> it(_counterDeltas);

for (CounterDelta *counterDelta = it.getFirst(); counterDelta; counterDelta = it.getNext())
{
count += counterDelta->counter->getCount();
}

return count;
}

void TR::DebugCounterAggregation::printCounters(bool printZeroCounters)
{
ListIterator<CounterDelta> it(_counterDeltas);

for (CounterDelta *counterDelta = it.getFirst(); counterDelta; counterDelta = it.getNext())
{
TR::DebugCounter *counter = counterDelta->counter;
int64_t count = counter->getCount();

if (count || printZeroCounters)
{
TR_VerboseLog::writeLineLocked(TR_Vlog_PERF, "Counter count=%d %s", count, counter->getName());
}
}
}

TR::DebugCounter *TR::DebugCounterGroup::findCounter(const char *nameChars, int32_t nameLength)
{
if (nameChars == NULL)
Expand Down
2 changes: 2 additions & 0 deletions compiler/ras/DebugCounter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ class DebugCounterAggregation : public DebugCounterBase
TR::SymbolReference *getBumpCountSymRef(TR::Compilation *comp);

void accumulate();
int64_t getCount();
void printCounters(bool printZeroCounters = true);
};

class DebugCounterGroup
Expand Down
1 change: 1 addition & 0 deletions compiler/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ compiler_library(runtime
${CMAKE_CURRENT_LIST_DIR}/OMRCodeCacheManager.cpp
${CMAKE_CURRENT_LIST_DIR}/OMRCodeCacheMemorySegment.cpp
${CMAKE_CURRENT_LIST_DIR}/OMRCodeCacheConfig.cpp
${CMAKE_CURRENT_LIST_DIR}/OMRRSSReport.cpp
)
32 changes: 32 additions & 0 deletions compiler/runtime/OMRCodeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ OMR::CodeCache::allocateCodeMemory(size_t warmCodeSize,
uint8_t * cacheHeapAlloc;
bool warmIsFreeBlock = false;
bool coldIsFreeBlock = false;
uint8_t *oldColdAlloc = _coldCodeAlloc;

size_t warmSize = warmCodeSize;
size_t coldSize = coldCodeSize;
Expand Down Expand Up @@ -1678,6 +1679,37 @@ OMR::CodeCache::allocateCodeMemory(size_t warmCodeSize,
*coldCode = coldCodeAddress;
else
*coldCode = warmCodeAddress;

if (OMR::RSSReport::instance() &&
!coldIsFreeBlock &&
!needsToBeContiguous &&
_coldCodeRSSRegion)
{
_coldCodeRSSRegion->_size = _coldCodeRSSRegion->_start - _coldCodeAlloc;

int32_t padding = static_cast<int32_t>(oldColdAlloc - coldCodeAddress - coldCodeSize);
TR_ASSERT_FATAL(padding >= 0, "Cold code padding should be >= 0");

if (padding > 0)
{
OMR::RSSItem *rssItem = new (TR::Compiler->persistentMemory()) OMR::RSSItem(OMR::RSSItem::alignment,
oldColdAlloc - padding, padding,
NULL /* counters */);
_coldCodeRSSRegion->addRSSItem(rssItem, self()->getReservingCompThreadID());
}

int32_t header = static_cast<uint32_t>(coldCodeAddress - _coldCodeAlloc);
TR_ASSERT_FATAL(header >= 0, "Cold code header should be >= 0");

if (header > 0)
{
OMR::RSSItem *rssItem = new (TR::Compiler->persistentMemory()) OMR::RSSItem(OMR::RSSItem::header,
coldCodeAddress - header, header,
NULL /* counters */);
_coldCodeRSSRegion->addRSSItem(rssItem, self()->getReservingCompThreadID());
}
}

return warmCodeAddress;
}

Expand Down
10 changes: 9 additions & 1 deletion compiler/runtime/OMRCodeCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace OMR { typedef CodeCache CodeCacheConnector; }
#include "runtime/CodeCacheConfig.hpp"
#include "runtime/Runtime.hpp"
#include "runtime/CodeCacheTypes.hpp"
#include "runtime/OMRRSSReport.hpp"
#include "OMR/Bytes.hpp"

class TR_OpaqueMethodBlock;
Expand All @@ -57,7 +58,7 @@ class OMR_EXTENSIBLE CodeCache
TR::CodeCache *self();

public:
CodeCache() { }
CodeCache() : _coldCodeRSSRegion(NULL) { }

void *operator new(size_t s, TR::CodeCache *cache) { return cache; }
void operator delete(void *p, TR::CodeCache *cache) { /* do nothing */ }
Expand Down Expand Up @@ -416,6 +417,11 @@ class OMR_EXTENSIBLE CodeCache

CodeCacheFreeCacheBlock *_freeBlockList;

/**
* @brief Returns pointer to the cold code RSS Region
*/
OMR::RSSRegion *getColdCodeRSSRegion() { return _coldCodeRSSRegion; }

// This is used in an attempt to enforce mutually exclusive ownership.
// flag accessed under mutex <== This is deceiving! There are two different monitors we may hold (not at the same time!) when we write to this.
// We can either be holding the code cache monitor *OR* the manager's code cache list monitor.
Expand Down Expand Up @@ -450,6 +456,8 @@ class OMR_EXTENSIBLE CodeCache

TR_YesNoMaybe _almostFull;
CodeCacheMethodHeader *_lastAllocatedBlock; // used for error detection (RAS)

OMR::RSSRegion *_coldCodeRSSRegion;
};

} // namespace OMR
Expand Down
Loading

0 comments on commit 156d9f2

Please sign in to comment.