diff --git a/gc/stats/AllocationStats.cpp b/gc/stats/AllocationStats.cpp index cf6d46f5868..2bf49b19cec 100644 --- a/gc/stats/AllocationStats.cpp +++ b/gc/stats/AllocationStats.cpp @@ -26,6 +26,10 @@ void MM_AllocationStats::clear() { + /* calculate cumulative stats before any clear */ + _allocationBytesCumulative += bytesAllocated(); + + #if defined(OMR_GC_THREAD_LOCAL_HEAP) _tlhRefreshCountFresh = 0; _tlhRefreshCountReused = 0; diff --git a/gc/stats/AllocationStats.hpp b/gc/stats/AllocationStats.hpp index f5554b4d64d..2132c39484c 100644 --- a/gc/stats/AllocationStats.hpp +++ b/gc/stats/AllocationStats.hpp @@ -49,6 +49,7 @@ class MM_AllocationStats : public MM_Base uintptr_t _allocationCount; uintptr_t _allocationBytes; + uintptr_t _allocationBytesCumulative; /**< cumulative allocation up to last clear, excluding since last clear */ uintptr_t _ownableSynchronizerObjectCount; /**< Number of Ownable Synchronizer Object allocations */ uintptr_t _continuationObjectCount; /**< Number of Continuation Object allocations */ uintptr_t _discardedBytes; @@ -86,6 +87,18 @@ class MM_AllocationStats : public MM_Base return totalBytesAllocated; } + bool bytesAllocatedCumulative(uintptr_t *cumulativeValue) { + if (NULL != cumulativeValue) { + /* sum the values up to last clear and since last clear */ + *cumulativeValue = _allocationBytesCumulative + bytesAllocated(); + + /* return false if overflowing */ + return (_allocationBytesCumulative <= *cumulativeValue); + } + + return false; + } + MM_AllocationStats() : #if defined(OMR_GC_THREAD_LOCAL_HEAP) _tlhRefreshCountFresh(0),