Skip to content

Commit

Permalink
Update LOAresize to avoid potential issue
Browse files Browse the repository at this point in the history
   -add the protection to prevent the potential issue, 
   which expected contract LOA size could be bigger than 
   current LOA size.(resizeLOA() pass "new loa size" as unsigned int
   parameter to method isSizeEnoughForLOA() for checking if the size
   is big enough for LOA, in case calculated new size is smaller than
   0, it could cause isSizeEnoughForLOA() return wrong decision).
   -change Xgc:debugLOAResive option to standard trace point 
   for better debugging option

Signed-off-by: Lin Hu <linhu@ca.ibm.com>
  • Loading branch information
LinHu2016 committed Dec 6, 2018
1 parent 8a9f1fc commit 47233e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 64 deletions.
2 changes: 0 additions & 2 deletions gc/base/GCExtensionsBase.hpp
Expand Up @@ -320,7 +320,6 @@ class MM_GCExtensionsBase : public MM_BaseVirtual {
double largeObjectAreaInitialRatio;
double largeObjectAreaMinimumRatio;
double largeObjectAreaMaximumRatio;
bool debugLOAResize;
bool debugLOAFreelist;
bool debugLOAAllocate;
int loaFreeHistorySize; /**< max size of _loaFreeRatioHistory array */
Expand Down Expand Up @@ -1306,7 +1305,6 @@ class MM_GCExtensionsBase : public MM_BaseVirtual {
, largeObjectAreaInitialRatio(0.050) /* initial LOA 5% */
, largeObjectAreaMinimumRatio(0.01) /* initial LOA 1% */
, largeObjectAreaMaximumRatio(0.500) /* maximum LOA 50% */
, debugLOAResize(false)
, debugLOAFreelist(false)
, debugLOAAllocate(false)
, loaFreeHistorySize(15)
Expand Down
76 changes: 14 additions & 62 deletions gc/base/MemoryPoolLargeObjects.cpp
Expand Up @@ -82,9 +82,6 @@ MM_MemoryPoolLargeObjects::newInstance(MM_EnvironmentBase* env, MM_MemoryPoolAdd
bool
MM_MemoryPoolLargeObjects::initialize(MM_EnvironmentBase* env)
{
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
bool debug = _extensions->debugLOAResize;

if (!MM_MemoryPool::initialize(env)) {
return false;
}
Expand Down Expand Up @@ -119,9 +116,7 @@ MM_MemoryPoolLargeObjects::initialize(MM_EnvironmentBase* env)
return false;
}

if (debug) {
omrtty_printf("LOA Initialize: SOA subpool %p LOA subpool %p\n ", _memoryPoolSmallObjects, _memoryPoolLargeObjects);
}
Trc_MM_LOAResize_initialize(env->getLanguageVMThread(), _memoryPoolSmallObjects, _memoryPoolLargeObjects);

_loaFreeRatioHistory = (double*)env->getForge()->allocate(_extensions->loaFreeHistorySize * sizeof(double), OMR::GC::AllocationCategory::FIXED, OMR_GET_CALLSITE());

Expand Down Expand Up @@ -223,8 +218,6 @@ MM_MemoryPoolLargeObjects::preCollect(MM_EnvironmentBase* env, bool systemGC, bo
void
MM_MemoryPoolLargeObjects::resizeLOA(MM_EnvironmentBase* env)
{
bool debug = _extensions->debugLOAResize;

_soaFreeBytesAfterLastGC = _memoryPoolSmallObjects->getApproximateFreeMemorySize();

float minimumFreeRatio = ((float)_extensions->heapFreeMinimumRatioMultiplier) / ((float)_extensions->heapFreeMinimumRatioDivisor);
Expand All @@ -240,7 +233,6 @@ MM_MemoryPoolLargeObjects::resizeLOA(MM_EnvironmentBase* env)
void* newLOABase;
double oldLOARatio;
uintptr_t contractRequired;
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);

/* Calculate LOA size based on new loa ratio */
uintptr_t loaMinimumSize = MM_Math::roundToFloor(_extensions->heapAlignment,
Expand All @@ -256,9 +248,7 @@ MM_MemoryPoolLargeObjects::resizeLOA(MM_EnvironmentBase* env)

uintptr_t newLOAsize = _soaFreeBytesAfterLastGC * (uintptr_t)( _extensions->largeObjectAreaInitialRatio / minimumFreeRatio);

if (debug) {
omrtty_printf("post GC resize LOA: newLOAsize %zu\n", newLOAsize);
}
Trc_MM_LOAResize_resizeLOA1(env->getLanguageVMThread(), newLOAsize);

if (newLOAsize < _loaSize){

Expand All @@ -276,17 +266,14 @@ MM_MemoryPoolLargeObjects::resizeLOA(MM_EnvironmentBase* env)

newLOAsize = _loaSize - contractRequired;

if (debug) {
omrtty_printf("newLOAsize adjusted by LOA occupnacy %zu\n", newLOAsize);
}
Trc_MM_LOAResize_resizeLOA2(env->getLanguageVMThread(), newLOAsize);

if ((double)newLOAsize/(double)_memorySubSpace->getActiveMemorySize() < _extensions->largeObjectAreaMinimumRatio){

contractRequired = (uintptr_t)((double)_loaSize - ((double)(_memorySubSpace->getActiveMemorySize() * _extensions->largeObjectAreaMinimumRatio)));
newLOAsize = _loaSize - contractRequired;
if (debug) {
omrtty_printf("newLOAsize adjusted min LOA ratio %zu\n", newLOAsize);
}

Trc_MM_LOAResize_resizeLOA3(env->getLanguageVMThread(), newLOAsize);
}

/* If minimum required now zero then there is no storage available for transfer */
Expand All @@ -310,7 +297,7 @@ MM_MemoryPoolLargeObjects::resizeLOA(MM_EnvironmentBase* env)
oldLOARatio = _currentLOARatio;

/* Does this leave a reasonable sized LOA ? */
if (!isSizeEnoughForLOA(env, _loaSize - spaceDelta)) {
if (!isSizeEnoughForLOA(env, (_loaSize > spaceDelta) ? (_loaSize - spaceDelta) : 0)) {
/* No.. make LOA empty as not even big enough for one free chunk of LOA */
spaceDelta = _loaSize;
_soaSize += spaceDelta;
Expand All @@ -332,11 +319,7 @@ MM_MemoryPoolLargeObjects::resizeLOA(MM_EnvironmentBase* env)
assume0(0 != _currentLOARatio);
}

if (debug) {
omrtty_printf("LOA Rebalanced to meet minimum SOA requirements: LOA ratio has decreased from %.3f --> %.3f\n",
oldLOARatio,
_currentLOARatio);
}
Trc_MM_LOAResize_resizeLOA4(env->getLanguageVMThread(), oldLOARatio, _currentLOARatio);

_extensions->heap->getResizeStats()->setLastLoaResizeReason(LOA_CONTRACT_MIN_SOA);
_memorySubSpace->reportHeapResizeAttempt(env, spaceDelta , HEAP_LOA_CONTRACT);
Expand Down Expand Up @@ -371,8 +354,6 @@ MM_MemoryPoolLargeObjects::completeFreelistRebuildRequired(MM_EnvironmentBase* e
double
MM_MemoryPoolLargeObjects::calculateTargetLOARatio(MM_EnvironmentBase* env, uintptr_t allocSize)
{
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
bool debug = _extensions->debugLOAResize;
double newLOARatio = _currentLOARatio;
float maxLOAFreeRatio = ((float)_extensions->heapFreeMaximumRatioMultiplier) / ((float)_extensions->heapFreeMinimumRatioDivisor);
uintptr_t loaFreeBytes = _memoryPoolLargeObjects->getActualFreeMemorySize();
Expand Down Expand Up @@ -438,11 +419,8 @@ MM_MemoryPoolLargeObjects::calculateTargetLOARatio(MM_EnvironmentBase* env, uint
_extensions->heap->getResizeStats()->setLastLoaResizeReason(LOA_EXPAND_HEAP_ALIGNMENT);
}

if (debug && newLOARatio != _currentLOARatio) {
omrtty_printf("LOA Calculate target ratio: ratio has %s from %.3f --> %.3f\n",
newLOARatio < _currentLOARatio ? "decreased" : "increased",
_currentLOARatio,
newLOARatio);
if (newLOARatio != _currentLOARatio) {
Trc_MM_LOAResize_calculateTargetLOARatio(env->getLanguageVMThread(), newLOARatio < _currentLOARatio ? "decreased" : "increased", _currentLOARatio, newLOARatio);
}

return newLOARatio;
Expand All @@ -455,18 +433,12 @@ MM_MemoryPoolLargeObjects::calculateTargetLOARatio(MM_EnvironmentBase* env, uint
double
MM_MemoryPoolLargeObjects::resetTargetLOARatio(MM_EnvironmentBase* env)
{
bool debug = _extensions->debugLOAResize;

/* Nothing needs to be done if the LOA size is already at minimum size */
if (_currentLOARatio == _extensions->largeObjectAreaMinimumRatio) {
return _currentLOARatio;
}

if (debug) {
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
omrtty_printf("LOA Reset target ratio: ratio reset from %.3f to minimum size of %.3f\n",
_currentLOARatio, _extensions->largeObjectAreaMinimumRatio);
}
Trc_MM_LOAResize_resetTargetLOARatio(env->getLanguageVMThread(), _currentLOARatio, _extensions->largeObjectAreaMinimumRatio);

_extensions->heap->getResizeStats()->setLastLoaResizeReason(LOA_CONTRACT_AGGRESSIVE);

Expand All @@ -478,7 +450,6 @@ MM_MemoryPoolLargeObjects::resetLOASize(MM_EnvironmentBase* env, double newLOARa
{
uintptr_t oldLOASize = _loaSize;
uintptr_t newLOASize, oldAreaSize;
bool debug = _extensions->debugLOAResize;
HeapResizeType resizeType = HEAP_NO_RESIZE;

/* Has LOA changed in size ? */
Expand Down Expand Up @@ -517,10 +488,7 @@ MM_MemoryPoolLargeObjects::resetLOASize(MM_EnvironmentBase* env, double newLOARa
/* and new LOA base if LOA ratio > 0 */
_currentLOABase = _currentLOARatio > 0 ? determineLOABase(env, _soaSize) : LOA_EMPTY;

if (debug) {
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
omrtty_printf("Reset LOA Size: LOA Base is now %p\n", _currentLOABase);
}
Trc_MM_LOAResize_resetLOASize(env->getLanguageVMThread(), _currentLOABase);

_memorySubSpace->reportHeapResizeAttempt(env, resizeSize , resizeType);
}
Expand Down Expand Up @@ -924,9 +892,6 @@ MM_MemoryPoolLargeObjects::collectorAllocateTLH(MM_EnvironmentBase* env, MM_Allo
void
MM_MemoryPoolLargeObjects::expandWithRange(MM_EnvironmentBase* env, uintptr_t expandSize, void* lowAddress, void* highAddress, bool canCoalesce)
{
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
bool debug = _extensions->debugLOAResize;

uintptr_t oldAreaSize, newLOASize;

assume0(MM_Math::roundToCeiling(_extensions->heapAlignment, expandSize) == expandSize);
Expand All @@ -952,11 +917,7 @@ MM_MemoryPoolLargeObjects::expandWithRange(MM_EnvironmentBase* env, uintptr_t ex
_memoryPoolLargeObjects->expandWithRange(env, _loaSize, _currentLOABase, highAddress, canCoalesce);
}

if (debug) {
omrtty_printf("LOA Initial Allocation: heapSize %zu, Initial LOA ratio is %.3f --> LOA base is %p initial LOA size %zu\n",
oldAreaSize, _currentLOARatio, _currentLOABase, _loaSize);
}

Trc_MM_LOAResize_expandWithRange1(env->getLanguageVMThread(), oldAreaSize, _currentLOARatio, _currentLOABase, _loaSize);
} else {

/* If LOA ratio has reduced to zero then we have an empty
Expand All @@ -976,10 +937,7 @@ MM_MemoryPoolLargeObjects::expandWithRange(MM_EnvironmentBase* env, uintptr_t ex
/* ..and then redistribute free memory between SOA and LOA */
redistributeFreeMemory(env, oldAreaSize);

if (debug) {
omrtty_printf("LOA resized on heap expansion: heapSize %zu, LOA ratio is %.3f --> LOA base is now %p LOA size %zu\n",
oldAreaSize, _currentLOARatio, _currentLOABase, _loaSize);
}
Trc_MM_LOAResize_expandWithRange2(env->getLanguageVMThread(), oldAreaSize, _currentLOARatio, _currentLOABase, _loaSize);
}

/* Reset SOA LWM.
Expand Down Expand Up @@ -1009,9 +967,6 @@ MM_MemoryPoolLargeObjects::expandWithRange(MM_EnvironmentBase* env, uintptr_t ex
void*
MM_MemoryPoolLargeObjects::contractWithRange(MM_EnvironmentBase* env, uintptr_t contractSize, void* lowAddress, void* highAddress)
{
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
bool debug = _extensions->debugLOAResize;

/* Get current size of old area */
uintptr_t oldAreaSize = _memorySubSpace->getActiveMemorySize();

Expand All @@ -1034,10 +989,7 @@ MM_MemoryPoolLargeObjects::contractWithRange(MM_EnvironmentBase* env, uintptr_t

redistributeFreeMemory(env, oldAreaSize);

if (debug) {
omrtty_printf("LOA resized on heap contraction: heapSize %zu, LOA ratio is %.3f --> LOA base is now %p LOA size %zu\n",
oldAreaSize, _currentLOARatio, _currentLOABase, _loaSize);
}
Trc_MM_LOAResize_contractWithRange(env->getLanguageVMThread(), oldAreaSize, _currentLOARatio, _currentLOABase, _loaSize);
}

/* ..and remmeber new old area size for next time */
Expand Down
12 changes: 12 additions & 0 deletions gc/base/j9mm.tdf
Expand Up @@ -898,3 +898,15 @@ TraceEntry=Trc_MM_MSSGenerational_allocationRequestFailed_entry Overhead=1 Level
TraceEvent=Trc_MM_MSSGenerational_allocationRequestFailed1 Overhead=1 Level=1 Group=allocate Template="MSSGenerational::allocationRequestFailed size %zu prev != new %llx, allocate from old %llx"
TraceEvent=Trc_MM_MSSGenerational_allocationRequestFailed Overhead=1 Level=1 Group=allocate Template="MSSGenerational::allocationRequestFailed size %zu event %u"
TraceExit=Trc_MM_MSSGenerational_allocationRequestFailed_exit Overhead=1 Level=1 Group=allocate Template="MSSGenerational::allocationRequestFailed size %zu exit %zu result %llx"

TraceEvent=Trc_MM_LOAResize_initialize Overhead=1 Level=1 Group=loaresize Template="LOA Initialize: SOA subpool %p LOA subpool %p"
TraceEvent=Trc_MM_LOAResize_resizeLOA1 Overhead=1 Level=1 Group=loaresize Template="post GC resize LOA: newLOAsize %zu"
TraceEvent=Trc_MM_LOAResize_resizeLOA2 Overhead=1 Level=1 Group=loaresize Template="newLOAsize adjusted by LOA occupnacy %zu"
TraceEvent=Trc_MM_LOAResize_resizeLOA3 Overhead=1 Level=1 Group=loaresize Template="newLOAsize adjusted min LOA ratio %zu"
TraceEvent=Trc_MM_LOAResize_resizeLOA4 Overhead=1 Level=1 Group=loaresize Template="LOA Rebalanced to meet minimum SOA requirements: LOA ratio has decreased from %.3f --> %.3f"
TraceEvent=Trc_MM_LOAResize_calculateTargetLOARatio Overhead=1 Level=1 Group=loaresize Template="LOA Calculate target ratio: ratio has %s from %.3f --> %.3f"
TraceEvent=Trc_MM_LOAResize_resetTargetLOARatio Overhead=1 Level=1 Group=loaresize Template="LOA Reset target ratio: ratio reset from %.3f to minimum size of %.3f"
TraceEvent=Trc_MM_LOAResize_resetLOASize Overhead=1 Level=1 Group=loaresize Template="Reset LOA Size: LOA Base is now %p"
TraceEvent=Trc_MM_LOAResize_expandWithRange1 Overhead=1 Level=1 Group=loaresize Template="LOA Initial Allocation: heapSize %zu, Initial LOA ratio is %.3f --> LOA base is %p initial LOA size %zu"
TraceEvent=Trc_MM_LOAResize_expandWithRange2 Overhead=1 Level=1 Group=loaresize Template="LOA resized on heap expansion: heapSize %zu, LOA ratio is %.3f --> LOA base is now %p LOA size %zu"
TraceEvent=Trc_MM_LOAResize_contractWithRange Overhead=1 Level=1 Group=loaresize Template="LOA resized on heap contraction: heapSize %zu, LOA ratio is %.3f --> LOA base is now %p LOA size %zu"

0 comments on commit 47233e0

Please sign in to comment.