Skip to content

Commit

Permalink
Merge pull request eclipse-omr#3911 from cedrichansen/master
Browse files Browse the repository at this point in the history
Total regions count for metronome regions lists
  • Loading branch information
charliegracie authored May 28, 2019
2 parents 6235bd8 + 5c317b7 commit 092e054
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
2 changes: 0 additions & 2 deletions gc/base/segregated/FreeHeapRegionList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class MM_FreeHeapRegionList : public MM_HeapRegionList
}
return region;
}

virtual uintptr_t getMaxRegions() = 0;

/* Methods inherited from HeapRegionList */
virtual bool isEmpty() { return 0 == _length; }
Expand Down
19 changes: 1 addition & 18 deletions gc/base/segregated/LockingFreeHeapRegionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,9 @@ MM_LockingFreeHeapRegionList::tearDown(MM_EnvironmentBase *env)
uintptr_t
MM_LockingFreeHeapRegionList::getTotalRegions()
{
uintptr_t count = 0;
lock();
for (MM_HeapRegionDescriptorSegregated *cur = _head; cur != NULL; cur = cur->getNext()) {
count += cur->getRange();
}
unlock();
return count;
return _totalRegionsCount;
}

uintptr_t
MM_LockingFreeHeapRegionList::getMaxRegions()
{
uintptr_t max = 0;
lock();
for (MM_HeapRegionDescriptorSegregated *cur = _head; cur != NULL; cur = cur->getNext()) {
max = (max > cur->getRange()) ? max : cur->getRange();
}
unlock();
return max;
}

void
MM_LockingFreeHeapRegionList::showList(MM_EnvironmentBase *env)
Expand Down
19 changes: 15 additions & 4 deletions gc/base/segregated/LockingFreeHeapRegionList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
MM_HeapRegionDescriptorSegregated *_head;
MM_HeapRegionDescriptorSegregated *_tail;
omrthread_monitor_t _lockMonitor;
uintptr_t _totalRegionsCount;

/* Methods */
public:
Expand All @@ -57,7 +58,8 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
MM_FreeHeapRegionList(regionListKind, singleRegionsOnly),
_head(NULL),
_tail(NULL),
_lockMonitor(NULL)
_lockMonitor(NULL),
_totalRegionsCount(0)
{
_typeId = __FUNCTION__;
}
Expand All @@ -84,9 +86,11 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
MM_HeapRegionDescriptorSegregated *front = src->_head;
MM_HeapRegionDescriptorSegregated *back = src->_tail;
uintptr_t srcLength = src->_length;
uintptr_t srcRegionsCount = src->_totalRegionsCount;
src->_head = NULL;
src->_tail = NULL;
src->_length = 0;
src->_totalRegionsCount = 0;

/* Add to front of self */
back->setNext(_head); /* OK even if _head is NULL */
Expand All @@ -97,7 +101,8 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
}
_head = front;
_length += srcLength;

_totalRegionsCount += srcRegionsCount;

src->unlock();
unlock();
}
Expand All @@ -116,9 +121,11 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
MM_HeapRegionDescriptorSegregated *front = src->_head;
MM_HeapRegionDescriptorSegregated *back = src->_tail;
uintptr_t srcLength = src->_length;
uintptr_t srcRegionsCount = src->_totalRegionsCount;
src->_head = NULL;
src->_tail = NULL;
src->_length = 0;
src->_totalRegionsCount = 0;

/* Add to front of self */
back->setNext(_head); /* OK even if _head is NULL */
Expand All @@ -129,7 +136,8 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
}
_head = front;
_length += srcLength;

_totalRegionsCount += srcRegionsCount;

src->unlock();
unlock();
}
Expand All @@ -154,7 +162,6 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
virtual MM_HeapRegionDescriptorSegregated* allocate(MM_EnvironmentBase *env, uintptr_t szClass, uintptr_t numRegions, uintptr_t maxExcess);

virtual uintptr_t getTotalRegions();
virtual uintptr_t getMaxRegions();

virtual void showList(MM_EnvironmentBase *env);

Expand All @@ -167,6 +174,7 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
return (MM_LockingFreeHeapRegionList *)pl;
}


protected:
private:
MMINLINE void lock() { omrthread_monitor_enter(_lockMonitor); }
Expand All @@ -178,6 +186,7 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
{
Assert_MM_true(NULL == region->getNext() && NULL == region->getPrev());
_length++;
_totalRegionsCount += region->getRange();
if (NULL == _head) {
_head = region;
_tail = region;
Expand All @@ -194,6 +203,7 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
MM_HeapRegionDescriptorSegregated *result = _head;
if (_head != NULL) {
_length--;
_totalRegionsCount -= result->getRange();
_head = result->getNext();
result->setNext(NULL);
if (NULL == _head) {
Expand All @@ -213,6 +223,7 @@ class MM_LockingFreeHeapRegionList : public MM_FreeHeapRegionList
detachInternal(MM_HeapRegionDescriptorSegregated *cur)
{
_length--;
_totalRegionsCount -= cur->getRange();
MM_HeapRegionDescriptorSegregated *prev = cur->getPrev();
MM_HeapRegionDescriptorSegregated *next = cur->getNext();
if (prev != NULL) {
Expand Down
9 changes: 8 additions & 1 deletion gc/base/segregated/LockingHeapRegionQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ friend class MM_LockingFreeHeapRegionList;
MM_HeapRegionDescriptorSegregated *_tail;
bool _needLock;
omrthread_monitor_t _lockMonitor;
uintptr_t _totalRegionsCount;

public:
static MM_LockingHeapRegionQueue *newInstance(MM_EnvironmentBase *env, RegionListKind regionListKind, bool singleRegionOnly, bool concurrentAccess, bool trackFreeBytes = false);
Expand All @@ -70,7 +71,8 @@ friend class MM_LockingFreeHeapRegionList;
_head(NULL),
_tail(NULL),
_needLock(concurrentAccess),
_lockMonitor(NULL)
_lockMonitor(NULL),
_totalRegionsCount(0)
{
_typeId = __FUNCTION__;
}
Expand Down Expand Up @@ -99,9 +101,11 @@ friend class MM_LockingFreeHeapRegionList;
MM_HeapRegionDescriptorSegregated *front = src->_head;
MM_HeapRegionDescriptorSegregated *back = src->_tail;
uintptr_t srcLength = src->_length;
uintptr_t srcRegionsCount = src->_totalRegionsCount;
src->_head = NULL;
src->_tail = NULL;
src->_length = 0;
src->_totalRegionsCount = 0;

/* Add to back of self */
front->setPrev(_tail); /* OK even if _tail is NULL */
Expand All @@ -112,6 +116,7 @@ friend class MM_LockingFreeHeapRegionList;
}
_tail = back;
_length += srcLength;
_totalRegionsCount += srcRegionsCount;

src->unlock();
unlock();
Expand Down Expand Up @@ -180,6 +185,7 @@ friend class MM_LockingFreeHeapRegionList;
_tail = region;
}
_length++;
_totalRegionsCount += region->getRange();
}

uintptr_t dequeueInternal(MM_LockingHeapRegionQueue *target, uintptr_t count)
Expand All @@ -201,6 +207,7 @@ friend class MM_LockingFreeHeapRegionList;
MM_HeapRegionDescriptorSegregated *result = _head;
if (_head != NULL) {
_length--;
_totalRegionsCount -= result->getRange();
_head = result->getNext();
result->setNext(NULL);
if (NULL == _head) {
Expand Down
3 changes: 1 addition & 2 deletions gc/base/segregated/MemoryPoolSegregated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,9 @@ MM_MemoryPoolSegregated::getActualFreeMemorySize()
{
uintptr_t single = 0;
uintptr_t multi = 0;
uintptr_t maxMulti = 0;
uintptr_t coalesce = 0;

_regionPool->countFreeRegions(&single, &multi, &maxMulti, &coalesce);
_regionPool->countFreeRegions(&single, &multi, &coalesce);

return (single + multi + coalesce) * _extensions->getHeap()->getHeapRegionManager()->getRegionSize();
}
Expand Down
3 changes: 1 addition & 2 deletions gc/base/segregated/RegionPoolSegregated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ MM_RegionPoolSegregated::moveInUseToSweep(MM_EnvironmentBase *env)
}

void
MM_RegionPoolSegregated::countFreeRegions(uintptr_t *singleFree, uintptr_t *multiFree, uintptr_t *maxMultiFree, uintptr_t *coalesceFree)
MM_RegionPoolSegregated::countFreeRegions(uintptr_t *singleFree, uintptr_t *multiFree, uintptr_t *coalesceFree)
{
*singleFree = _singleFreeList->getTotalRegions();
*multiFree = _multiFreeList->getTotalRegions();
*maxMultiFree = _multiFreeList->getMaxRegions();
*coalesceFree = _coalesceFreeList->getTotalRegions();
}

Expand Down
2 changes: 1 addition & 1 deletion gc/base/segregated/RegionPoolSegregated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class MM_RegionPoolSegregated : public MM_RegionPool
* region lists to "sweep" region lists.
*/
void moveInUseToSweep(MM_EnvironmentBase *env);
void countFreeRegions(uintptr_t *singleFree, uintptr_t *multiFree, uintptr_t *maxMultiFree, uintptr_t *coalesceFree);
void countFreeRegions(uintptr_t *singleFree, uintptr_t *multiFree, uintptr_t *coalesceFree);
void addFreeRange(void *lowAddress, void *highAddress);
void addFreeRegion(MM_EnvironmentBase *env, MM_HeapRegionDescriptorSegregated *region, bool alreadyFree = false);
void addSingleFree(MM_EnvironmentBase *env, MM_HeapRegionQueue *regionQueue);
Expand Down

0 comments on commit 092e054

Please sign in to comment.