From 3473148d401fe3fd5b95457b0bde9a5002247525 Mon Sep 17 00:00:00 2001 From: Dmitri Pivkine Date: Mon, 19 Sep 2022 16:26:40 -0400 Subject: [PATCH] Fix discrepancy in definition of functions in GC Extensions There is number of functions in GC Extensions Base defined under OMR_GC_MODRON_SCAVENGER flag. However there are many places these functions are called unconditionally without checking of this flag. This flag is on always in our compilation environment and code compiles. If it is disabled code won't compile. The solution is make these functions be defined always and wrap Scavenger related content inside. Signed-off-by: Dmitri Pivkine --- example/glue/ObjectModelDelegate.hpp | 26 +++---- gc/base/GCExtensionsBase.hpp | 75 +++++++++++++++++-- gc/base/standard/ConcurrentCardTable.cpp | 2 +- gc/base/standard/ConcurrentGC.cpp | 14 +--- gc/base/standard/ConcurrentOverflow.cpp | 8 +- .../standard/ConfigurationGenerational.cpp | 7 +- gc/base/standard/HeapWalker.cpp | 4 +- gc/base/standard/ParallelGlobalGC.cpp | 2 +- gc/base/standard/Scavenger.hpp | 6 +- gc/structs/SublistFragment.cpp | 6 +- 10 files changed, 102 insertions(+), 48 deletions(-) diff --git a/example/glue/ObjectModelDelegate.hpp b/example/glue/ObjectModelDelegate.hpp index 34422ef2b62..60662870067 100644 --- a/example/glue/ObjectModelDelegate.hpp +++ b/example/glue/ObjectModelDelegate.hpp @@ -208,6 +208,19 @@ class GC_ObjectModelDelegate { return U_8_MAX; } + + /** + * Returns the field offset of the third hottest field of the object referred to by the forwarded header. + * Valid if scavenger dynamicBreadthFirstScanOrdering is enabled + * + * @param forwardedHeader pointer to the MM_ForwardedHeader instance encapsulating the object + * @return the offset of the third hottest field of the given object referred to by the forwarded header, return U_8_MAX if the hot field does not exist + */ + MMINLINE uint8_t + getHotFieldOffset3(MM_ForwardedHeader *forwardedHeader) + { + return U_8_MAX; + } #endif /* defined(OMR_GC_MODRON_SCAVENGER) || defined(OMR_GC_VLHGC) */ /** @@ -229,19 +242,6 @@ class GC_ObjectModelDelegate return false; } - /** - * Returns the field offset of the third hottest field of the object referred to by the forwarded header. - * Valid if scavenger dynamicBreadthFirstScanOrdering is enabled - * - * @param forwardedHeader pointer to the MM_ForwardedHeader instance encapsulating the object - * @return the offset of the third hottest field of the given object referred to by the forwarded header, return U_8_MAX if the hot field does not exist - */ - MMINLINE uint8_t - getHotFieldOffset3(MM_ForwardedHeader *forwardedHeader) - { - return U_8_MAX; - } - /** * Get the instance size (total) of a forwarded object from the forwarding pointer. The size must * include the header and any expansion bytes to be allocated if the object will grow when moved. diff --git a/gc/base/GCExtensionsBase.hpp b/gc/base/GCExtensionsBase.hpp index b729d785361..338abb6b301 100644 --- a/gc/base/GCExtensionsBase.hpp +++ b/gc/base/GCExtensionsBase.hpp @@ -1105,31 +1105,94 @@ class MM_GCExtensionsBase : public MM_BaseVirtual { MMINLINE MM_Heap* getHeap() { return heap; } -#if defined(OMR_GC_MODRON_SCAVENGER) MMINLINE void setGuaranteedNurseryRange(void* start, void* end) { +#if defined(OMR_GC_MODRON_SCAVENGER) _guaranteedNurseryStart = start; _guaranteedNurseryEnd = end; +#endif /* OMR_GC_MODRON_SCAVENGER */ } MMINLINE void getGuaranteedNurseryRange(void** start, void** end) { +#if defined(OMR_GC_MODRON_SCAVENGER) *start = _guaranteedNurseryStart; *end = _guaranteedNurseryEnd; +#else /* OMR_GC_MODRON_SCAVENGER */ + *start = NULL; + *end = NULL; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE bool isRememberedSetInOverflowState() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + return _isRememberedSetInOverflow; +#else /* OMR_GC_MODRON_SCAVENGER */ + return false; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE void setRememberedSetOverflowState() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + _isRememberedSetInOverflow = true; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE void clearRememberedSetOverflowState() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + _isRememberedSetInOverflow = false; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE bool isScavengerRememberedSetInOverflowState() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + return _isRememberedSetInOverflow; +#else /* OMR_GC_MODRON_SCAVENGER */ + return false; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE void setScavengerRememberedSetOverflowState() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + _isRememberedSetInOverflow = true; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE void clearScavengerRememberedSetOverflowState() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + _isRememberedSetInOverflow = false; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } + + MMINLINE bool isScavengerBackOutFlagRaised() + { +#if defined(OMR_GC_MODRON_SCAVENGER) + return backOutFlagCleared < _backOutState; +#else /* OMR_GC_MODRON_SCAVENGER */ + return false; +#endif /* OMR_GC_MODRON_SCAVENGER */ } - MMINLINE bool isRememberedSetInOverflowState() { return _isRememberedSetInOverflow; } - MMINLINE void setRememberedSetOverflowState() { _isRememberedSetInOverflow = true; } - MMINLINE void clearRememberedSetOverflowState() { _isRememberedSetInOverflow = false; } + MMINLINE void setConcurrentGlobalGCInProgress(bool inProgress) + { +#if defined(OMR_GC_MODRON_SCAVENGER) + _concurrentGlobalGCInProgress = inProgress; +#endif /* OMR_GC_MODRON_SCAVENGER */ + } +#if defined(OMR_GC_MODRON_SCAVENGER) MMINLINE void setScavengerBackOutState(BackOutState backOutState) { _backOutState = backOutState; } MMINLINE BackOutState getScavengerBackOutState() { return _backOutState; } - MMINLINE bool isScavengerBackOutFlagRaised() { return backOutFlagCleared < _backOutState; } MMINLINE bool shouldScavengeNotifyGlobalGCOfOldToOldReference() { return _concurrentGlobalGCInProgress; } - MMINLINE void setConcurrentGlobalGCInProgress(bool inProgress) { _concurrentGlobalGCInProgress = inProgress; } /** * Determine whether Adaptive Threading is enabled. AdaptiveGCThreading flag diff --git a/gc/base/standard/ConcurrentCardTable.cpp b/gc/base/standard/ConcurrentCardTable.cpp index 434b3f5120a..081caadf3a9 100644 --- a/gc/base/standard/ConcurrentCardTable.cpp +++ b/gc/base/standard/ConcurrentCardTable.cpp @@ -998,7 +998,7 @@ MM_ConcurrentCardTable::cleanSingleCard(MM_EnvironmentBase *env, Card *card, uin * mean we re-trace objects not in the RS but RS overflow is assumed to be * an exceptional circumstance. */ - if (rememberedObjectsFound && (env->getExtensions()->isRememberedSetInOverflowState())) { + if (rememberedObjectsFound && (env->getExtensions()->isScavengerRememberedSetInOverflowState())) { *card = (Card)CARD_DIRTY; } diff --git a/gc/base/standard/ConcurrentGC.cpp b/gc/base/standard/ConcurrentGC.cpp index e7fcc48a358..40f321a1217 100644 --- a/gc/base/standard/ConcurrentGC.cpp +++ b/gc/base/standard/ConcurrentGC.cpp @@ -1676,9 +1676,7 @@ MM_ConcurrentGC::timeToKickoffConcurrent(MM_EnvironmentBase *env, MM_AllocateDes if (LANGUAGE_DEFINED_REASON != _stats.getKickoffReason()) { _languageKickoffReason = NO_LANGUAGE_KICKOFF_REASON; } -#if defined(OMR_GC_MODRON_SCAVENGER) _extensions->setConcurrentGlobalGCInProgress(true); -#endif reportConcurrentKickoff(env); } return true; @@ -1923,8 +1921,6 @@ MM_ConcurrentGC::clearWorkStackOverflow() void MM_ConcurrentGC::internalPreCollect(MM_EnvironmentBase *env, MM_MemorySubSpace *subSpace, MM_AllocateDescription *allocDescription, uint32_t gcCode) { - OMRPORT_ACCESS_FROM_ENVIRONMENT(env); - Trc_MM_ConcurrentGC_internalPreCollect_Entry(env->getLanguageVMThread(), subSpace); /* Thread roots must have been flushed by this point */ @@ -1997,8 +1993,8 @@ MM_ConcurrentGC::internalPreCollect(MM_EnvironmentBase *env, MM_MemorySubSpace * MM_ParallelGlobalGC::internalPreCollect(env, subSpace, allocDescription, gcCode); } else #endif /* OMR_GC_IDLE_HEAP_MANAGER */ - if (_extensions->isRememberedSetInOverflowState() || ((CONCURRENT_OFF < executionModeAtGC) && (CONCURRENT_TRACE_ONLY > executionModeAtGC))) { - CollectionAbortReason reason = (_extensions->isRememberedSetInOverflowState() ? ABORT_COLLECTION_REMEMBERSET_OVERFLOW : ABORT_COLLECTION_INSUFFICENT_PROGRESS); + if (_extensions->isScavengerRememberedSetInOverflowState() || ((CONCURRENT_OFF < executionModeAtGC) && (CONCURRENT_TRACE_ONLY > executionModeAtGC))) { + CollectionAbortReason reason = (_extensions->isScavengerRememberedSetInOverflowState() ? ABORT_COLLECTION_REMEMBERSET_OVERFLOW : ABORT_COLLECTION_INSUFFICENT_PROGRESS); abortCollection(env, reason); /* concurrent cycle was aborted so we need to kick off a new cycle and set up the cycle state */ MM_ParallelGlobalGC::internalPreCollect(env, subSpace, allocDescription, gcCode); @@ -2011,9 +2007,7 @@ MM_ConcurrentGC::internalPreCollect(MM_EnvironmentBase *env, MM_MemorySubSpace * /* Switch the executionMode to OFF to complete the STW collection */ _stats.switchExecutionMode(executionModeAtGC, CONCURRENT_OFF); -#if defined(OMR_GC_MODRON_SCAVENGER) _extensions->setConcurrentGlobalGCInProgress(false); -#endif /* Mark map is usable. We got far enough into the concurrent to be * sure we at least initialized the mark map so no need to do so again. @@ -2024,6 +2018,7 @@ MM_ConcurrentGC::internalPreCollect(MM_EnvironmentBase *env, MM_MemorySubSpace * #if defined(OMR_GC_MODRON_SCAVENGER) if (_extensions->scavengerEnabled) { + OMRPORT_ACCESS_FROM_ENVIRONMENT(env); reportConcurrentRememberedSetScanStart(env); uint64_t startTime = omrtime_hires_clock(); @@ -2186,9 +2181,8 @@ MM_ConcurrentGC::abortCollection(MM_EnvironmentBase *env, CollectionAbortReason switchConHelperRequest(CONCURRENT_HELPER_MARK, CONCURRENT_HELPER_WAIT); _stats.switchExecutionMode(_stats.getExecutionMode(), CONCURRENT_OFF); -#if defined(OMR_GC_MODRON_SCAVENGER) + _extensions->setConcurrentGlobalGCInProgress(false); -#endif /* make sure to reset the init ranges before the next kickOff */ resetInitRangesForConcurrentKO(); diff --git a/gc/base/standard/ConcurrentOverflow.cpp b/gc/base/standard/ConcurrentOverflow.cpp index 9c6df04900e..2b2f7ac7c0d 100644 --- a/gc/base/standard/ConcurrentOverflow.cpp +++ b/gc/base/standard/ConcurrentOverflow.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2020 IBM Corp. and others + * Copyright (c) 1991, 2022 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -70,12 +70,14 @@ MM_ConcurrentOverflow::initialize(MM_EnvironmentBase *env) { bool result = MM_WorkPacketOverflow::initialize(env); +#if defined(OMR_GC_MODRON_SCAVENGER) if (result) { /* Initialize monitor for safe initial Cards cleaning in Work Packets Overflow handler */ if(omrthread_monitor_init_with_name(&_cardsClearingMonitor, 0, "MM_ConcurrentOverflow::cardsClearingMonitor")) { result = false; } } +#endif /* OMR_GC_MODRON_SCAVENGER */ return result; } @@ -86,10 +88,12 @@ MM_ConcurrentOverflow::initialize(MM_EnvironmentBase *env) void MM_ConcurrentOverflow::tearDown(MM_EnvironmentBase *env) { - if(NULL != _cardsClearingMonitor) { +#if defined(OMR_GC_MODRON_SCAVENGER) + if (NULL != _cardsClearingMonitor) { omrthread_monitor_destroy(_cardsClearingMonitor); _cardsClearingMonitor = NULL; } +#endif /* OMR_GC_MODRON_SCAVENGER */ MM_WorkPacketOverflow::tearDown(env); } diff --git a/gc/base/standard/ConfigurationGenerational.cpp b/gc/base/standard/ConfigurationGenerational.cpp index 4bf85f121e6..a560383b381 100644 --- a/gc/base/standard/ConfigurationGenerational.cpp +++ b/gc/base/standard/ConfigurationGenerational.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2018 IBM Corp. and others + * Copyright (c) 1991, 2022 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -217,7 +217,6 @@ MM_ConfigurationGenerational::createHeapWithManager(MM_EnvironmentBase *env, UDA MM_GCExtensionsBase *extensions = env->getExtensions(); MM_Heap *heap = NULL; -#if defined(OMR_GC_MODRON_SCAVENGER) /* gencon supports split heaps so check that flag here when deciding what kind of MM_Heap to create */ if (extensions->enableSplitHeap) { UDATA lowSize = extensions->oldSpaceSize; @@ -228,9 +227,7 @@ MM_ConfigurationGenerational::createHeapWithManager(MM_EnvironmentBase *env, UDA * set and "inverted" flag in the extensions and check that in the PSA attach code when determining attachment policy. * May allow more versatile use cases of the split heaps, though. */ - } else -#endif /* OMR_GC_MODRON_SCAVENGER */ - { + } else { heap = MM_ConfigurationStandard::createHeapWithManager(env, heapBytesRequested, regionManager); } return heap; diff --git a/gc/base/standard/HeapWalker.cpp b/gc/base/standard/HeapWalker.cpp index c6e82e1ec75..cf68b155873 100644 --- a/gc/base/standard/HeapWalker.cpp +++ b/gc/base/standard/HeapWalker.cpp @@ -182,14 +182,12 @@ MM_HeapWalker::allObjectSlotsDo(MM_EnvironmentBase *env, MM_HeapWalkerSlotFunc f SlotObjectDoUserData slotObjectDoUserData = { function, userData, walkFlags, this }; uintptr_t modifiedWalkFlags = walkFlags; -#if defined(OMR_GC_MODRON_SCAVENGER) /* If J9_MU_WALK_NEW_AND_REMEMBERED_ONLY is specified, and rsOverflow has * occurred, any object in old space might be remembered, so we must walk them all */ - if (env->getExtensions()->isRememberedSetInOverflowState()) { + if (env->getExtensions()->isScavengerRememberedSetInOverflowState()) { modifiedWalkFlags &= ~J9_MU_WALK_NEW_AND_REMEMBERED_ONLY; } -#endif /* OMR_GC_MODRON_SCAVENGER */ allObjectsDo(env, heapWalkerObjectSlotsDo, (void *)&slotObjectDoUserData, modifiedWalkFlags, parallel, prepareHeapForWalk); diff --git a/gc/base/standard/ParallelGlobalGC.cpp b/gc/base/standard/ParallelGlobalGC.cpp index 12554e43da3..35028cb5b32 100644 --- a/gc/base/standard/ParallelGlobalGC.cpp +++ b/gc/base/standard/ParallelGlobalGC.cpp @@ -192,7 +192,7 @@ hookGlobalGcSweepEndRsoSafetyFixHeap(J9HookInterface** hook, uintptr_t eventNum, MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(event->currentThread); MM_GCExtensionsBase *extensions = env->getExtensions(); - extensions->scavengerRsoScanUnsafe = !extensions->isRememberedSetInOverflowState(); + extensions->scavengerRsoScanUnsafe = !extensions->isScavengerRememberedSetInOverflowState(); if (!extensions->scavengerRsoScanUnsafe) { MM_ParallelGlobalGC *pggc = (MM_ParallelGlobalGC *)userData; pggc->fixHeapForWalk(env, MEMORY_TYPE_OLD_RAM, FIXUP_DEBUG_TOOLING, fixObject); diff --git a/gc/base/standard/Scavenger.hpp b/gc/base/standard/Scavenger.hpp index b851c4c0cd6..f882c7f0ea3 100644 --- a/gc/base/standard/Scavenger.hpp +++ b/gc/base/standard/Scavenger.hpp @@ -535,9 +535,9 @@ class MM_Scavenger : public MM_Collector void clearRememberedSetLists(MM_EnvironmentStandard *env); - MMINLINE bool isRememberedSetInOverflowState() { return _extensions->isRememberedSetInOverflowState(); } - MMINLINE void setRememberedSetOverflowState() { _extensions->setRememberedSetOverflowState(); } - MMINLINE void clearRememberedSetOverflowState() { _extensions->clearRememberedSetOverflowState(); } + MMINLINE bool isRememberedSetInOverflowState() { return _extensions->isScavengerRememberedSetInOverflowState(); } + MMINLINE void setRememberedSetOverflowState() { _extensions->setScavengerRememberedSetOverflowState(); } + MMINLINE void clearRememberedSetOverflowState() { _extensions->clearScavengerRememberedSetOverflowState(); } /* Auto-remember stack objects so JIT can omit generational barriers */ void rescanThreadSlots(MM_EnvironmentStandard *env); diff --git a/gc/structs/SublistFragment.cpp b/gc/structs/SublistFragment.cpp index 76945743853..2b62cbc99d8 100644 --- a/gc/structs/SublistFragment.cpp +++ b/gc/structs/SublistFragment.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2016 IBM Corp. and others + * Copyright (c) 1991, 2022 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -53,9 +53,7 @@ allocateMemoryForSublistFragment(void *vmThreadRawPtr, J9VMGC_SublistFragment *f if (result) { return 0; } else { -#if defined(OMR_GC_MODRON_SCAVENGER) - env->getExtensions()->setRememberedSetOverflowState(); -#endif /* OMR_GC_MODRON_SCAVENGER */ + env->getExtensions()->setScavengerRememberedSetOverflowState(); return 1; } }