From 82c15c9de6c5d5a5f49052efec7bdaf8d6c78ffe Mon Sep 17 00:00:00 2001 From: Cedric Hansen Date: Thu, 9 Sep 2021 10:39:40 -0700 Subject: [PATCH] Clean up `MemorySubSpaceTarok` softmx heap resizing Please see related PR link for motivations behind this change. Changes include: - remove `MemorySubSpaceTarok::adjustExpansionWithinSoftMx()` in favour of `adjustExpansionWithinSoftMax()`. The latter of the two, is inherited from `MemorySubSpace` and has no functional differences. This allows better code sharing/consistency - Use `SOFT_MX_CONTRACT` contraction flag in `MemorySubSpaceTarok`. This better reflects the reason for contraction due to softmx. This depends on the linked OMR PR. - Use `MEMORY_SUBSPACE_NAME_TAROK` and `MEMORY_SUBSPACE_DESCRIPTION_TAROK` flags instead of hard coded value for `getName()` and `getDescription()` in `MemorySubSpaceTarok` This PR is related to, and is a follow up on: https://github.com/eclipse-openj9/openj9/pull/13308 This PR depends on: https://github.com/eclipse/omr/pull/6141 Signed-off-by: Cedric Hansen cedric.hansen@ibm.com --- runtime/gc_vlhgc/MemorySubSpaceTarok.cpp | 39 +++--------------------- runtime/gc_vlhgc/MemorySubSpaceTarok.hpp | 5 ++- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/runtime/gc_vlhgc/MemorySubSpaceTarok.cpp b/runtime/gc_vlhgc/MemorySubSpaceTarok.cpp index d7277bfd77b..15ccf2f6622 100644 --- a/runtime/gc_vlhgc/MemorySubSpaceTarok.cpp +++ b/runtime/gc_vlhgc/MemorySubSpaceTarok.cpp @@ -1128,7 +1128,7 @@ MM_MemorySubSpaceTarok::timeForHeapContract(MM_EnvironmentBase *env, MM_Allocate if(actualSoftMx < getActiveMemorySize()) { /* the softmx is less than the currentsize so we're going to attempt an aggressive contract */ _contractionSize = getActiveMemorySize() - actualSoftMx; - _extensions->heap->getResizeStats()->setLastContractReason(HEAP_RESIZE); + _extensions->heap->getResizeStats()->setLastContractReason(SOFT_MX_CONTRACT); return true; } } @@ -1347,12 +1347,12 @@ MM_MemorySubSpaceTarok::calculateExpandSize(MM_EnvironmentBase *env, UDATA bytes /* Adjust within -XsoftMx limit */ if (expandToSatisfy){ /* we need at least bytesRequired or we will get an OOM */ - expandSize = adjustExpansionWithinSoftMx(env, expandSize, bytesRequired); + expandSize = adjustExpansionWithinSoftMax(env, expandSize, bytesRequired); } else { /* we are adjusting based on other command line options, so fully respect softmx, * the minimum expand it can allow in this case is 0 */ - expandSize = adjustExpansionWithinSoftMx(env, expandSize, 0); + expandSize = adjustExpansionWithinSoftMax(env, expandSize, 0); } Trc_MM_MemorySubSpaceTarok_calculateExpandSize_Exit1(env->getLanguageVMThread(), desiredFree, currentFree, expandSize); @@ -1369,7 +1369,7 @@ MM_MemorySubSpaceTarok::calculateCollectorExpandSize(MM_EnvironmentBase *env) UDATA expandSize = _heapRegionManager->getRegionSize(); /* Adjust within -XsoftMx limit */ - expandSize = adjustExpansionWithinSoftMx(env, expandSize,0); + expandSize = adjustExpansionWithinSoftMax(env, expandSize,0); Trc_MM_MemorySubSpaceTarok_calculateCollectorExpandSize_Exit1(env->getLanguageVMThread(), expandSize); @@ -1505,34 +1505,3 @@ MM_MemorySubSpaceTarok::adjustExpansionWithinFreeLimits(MM_EnvironmentBase *env, } return result; } - -/** - * Compare the specified expand amount with -XsoftMX value - * @return Updated expand size - */ -MMINLINE UDATA -MM_MemorySubSpaceTarok::adjustExpansionWithinSoftMx(MM_EnvironmentBase *env, UDATA expandSize, UDATA minimumBytesRequired) -{ - MM_Heap * heap = env->getExtensions()->getHeap(); - UDATA actualSoftMx = heap->getActualSoftMxSize(env); - UDATA activeMemorySize = getActiveMemorySize(); - PORT_ACCESS_FROM_ENVIRONMENT(env); - - if (0 != actualSoftMx) { - if ((minimumBytesRequired != 0) && ((activeMemorySize + minimumBytesRequired) > actualSoftMx)) { - if (J9_EVENT_IS_HOOKED(MM_GCExtensions::getExtensions(env)->omrHookInterface, J9HOOK_MM_OMR_OOM_DUE_TO_SOFTMX)){ - ALWAYS_TRIGGER_J9HOOK_MM_OMR_OOM_DUE_TO_SOFTMX(MM_GCExtensions::getExtensions(env)->omrHookInterface, env->getOmrVMThread(), - j9time_hires_clock(), heap->getMaximumMemorySize(), heap->getActiveMemorySize(), MM_GCExtensions::getExtensions(env)->softMx, minimumBytesRequired); - actualSoftMx = heap->getActualSoftMxSize(env); - } - } - if (actualSoftMx < activeMemorySize) { - /* if our softmx is smaller than our currentsize, we should be contracting not expanding */ - expandSize = 0; - } else if((activeMemorySize + expandSize) > actualSoftMx) { - /* we would go past our -XsoftMx so just expand up to it instead */ - expandSize = actualSoftMx - activeMemorySize; - } - } - return expandSize; -} diff --git a/runtime/gc_vlhgc/MemorySubSpaceTarok.hpp b/runtime/gc_vlhgc/MemorySubSpaceTarok.hpp index 03853292331..f1d2a8d0643 100644 --- a/runtime/gc_vlhgc/MemorySubSpaceTarok.hpp +++ b/runtime/gc_vlhgc/MemorySubSpaceTarok.hpp @@ -68,7 +68,6 @@ class MM_MemorySubSpaceTarok : public MM_MemorySubSpace private: bool initialize(MM_EnvironmentBase *env); UDATA adjustExpansionWithinFreeLimits(MM_EnvironmentBase *env, UDATA expandSize); - UDATA adjustExpansionWithinSoftMx(MM_EnvironmentBase *env, UDATA expandSize, UDATA minimumBytesRequired); UDATA checkForRatioExpand(MM_EnvironmentBase *env, UDATA bytesRequired); bool checkForRatioContract(MM_EnvironmentBase *env); UDATA calculateExpandSize(MM_EnvironmentBase *env, UDATA bytesRequired, bool expandToSatisfy); @@ -110,8 +109,8 @@ class MM_MemorySubSpaceTarok : public MM_MemorySubSpace public: static MM_MemorySubSpaceTarok *newInstance(MM_EnvironmentBase *env, MM_PhysicalSubArena *physicalSubArena, MM_GlobalAllocationManagerTarok *gamt, bool usesGlobalCollector, UDATA minimumSize, UDATA initialSize, UDATA maximumSize, UDATA memoryType, U_32 objectFlags); - virtual const char *getName() { return "Tarok"; } - virtual const char *getDescription() { return "Tarok MemorySubSpace Description"; } + virtual const char *getName() { return MEMORY_SUBSPACE_NAME_TAROK; } + virtual const char *getDescription() { return MEMORY_SUBSPACE_DESCRIPTION_TAROK; } virtual MM_MemoryPool *getMemoryPool(); virtual MM_MemoryPool *getMemoryPool(void *addr);