From c0b53875b978b8e2ebe4cd7ed37157dddb198796 Mon Sep 17 00:00:00 2001 From: Hang Shao Date: Fri, 1 Dec 2023 14:36:46 -0500 Subject: [PATCH] Add an additional param to SH_CompositeCacheImpl::reset() Add an parameter to SH_CompositeCacheImpl::reset() to indicate whether the SCC can be unlocked by it or not. When updating romClass resources or doing stale marking, the SCC should always be locked. Do not unlock the SCC in these 2 cases. Fixes #18526 Signed-off-by: Hang Shao --- runtime/shared_common/CacheMap.cpp | 12 ++++++------ runtime/shared_common/CacheMap.hpp | 4 ++-- runtime/shared_common/CompositeCache.cpp | 8 +++++--- runtime/shared_common/CompositeCacheImpl.hpp | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/runtime/shared_common/CacheMap.cpp b/runtime/shared_common/CacheMap.cpp index a83bfdab557..8b4166de558 100644 --- a/runtime/shared_common/CacheMap.cpp +++ b/runtime/shared_common/CacheMap.cpp @@ -1221,7 +1221,7 @@ SH_CacheMap::readCache(J9VMThread* currentThread, SH_CompositeCacheImpl* cache, /* THREADING: MUST be protected by cache write mutex - therefore single-threaded within this JVM */ IDATA -SH_CacheMap::checkForCrash(J9VMThread* currentThread, bool hasClassSegmentMutex) +SH_CacheMap::checkForCrash(J9VMThread* currentThread, bool hasClassSegmentMutex, bool canUnlockCache) { IDATA rc = 0; PORT_ACCESS_FROM_PORT(_portlib); @@ -1235,7 +1235,7 @@ SH_CacheMap::checkForCrash(J9VMThread* currentThread, bool hasClassSegmentMutex) if (resetAllManagers(currentThread) != 0) { return -1; } - _cc->reset(currentThread); + _cc->reset(currentThread, canUnlockCache); rc = refreshHashtables(currentThread, hasClassSegmentMutex); } return rc; @@ -1567,7 +1567,7 @@ SH_CacheMap::addClasspathToCache(J9VMThread* currentThread, ClasspathItem* obj) * @return the number of items read, or -1 on error */ IDATA -SH_CacheMap::runEntryPointChecks(J9VMThread* currentThread, void* address, const char** p_subcstr) +SH_CacheMap::runEntryPointChecks(J9VMThread* currentThread, void* address, const char** p_subcstr, bool canUnlockCache) { bool hasClassSegmentMutex = false; IDATA itemsAdded; @@ -1600,7 +1600,7 @@ SH_CacheMap::runEntryPointChecks(J9VMThread* currentThread, void* address, const if (!_ccHead->isRunningReadOnly()) { if (_ccHead->hasWriteMutex(currentThread)) { /* Can only call this function if we have the write mutex */ - rc = checkForCrash(currentThread, hasClassSegmentMutex); + rc = checkForCrash(currentThread, hasClassSegmentMutex, canUnlockCache); if(rc < 0) { Trc_SHR_CM_runEntryPointChecks_Exit_Failed4(currentThread); return rc; @@ -2975,7 +2975,7 @@ SH_CacheMap::updateROMClassResource(J9VMThread* currentThread, const void* addre } hasWriteMutex = true; - if (runEntryPointChecks(currentThread, (void*)addressInCache, p_subcstr) == -1) { + if (runEntryPointChecks(currentThread, (void*)addressInCache, p_subcstr, false) == -1) { Trc_SHR_CM_updateROMClassResource_Exit3(currentThread); result = J9SHR_RESOURCE_STORE_ERROR; break; @@ -4410,7 +4410,7 @@ SH_CacheMap::markStale(J9VMThread* currentThread, ClasspathEntryItem* cpei, bool currentThread->omrVMThread->vmState = J9VMSTATE_SHAREDCLASS_MARKSTALE; while (retryCount < MARK_STALE_RETRY_TIMES) { if (hasWriteMutex || (_ccHead->enterWriteMutex(currentThread, true,fnName)==0)) { /* true = lockCache */ - if (runEntryPointChecks(currentThread, NULL, NULL) == -1) { + if (runEntryPointChecks(currentThread, NULL, NULL, false) == -1) { if (!hasWriteMutex) { _ccHead->exitWriteMutex(currentThread, fnName); /* Will unlock cache */ } diff --git a/runtime/shared_common/CacheMap.hpp b/runtime/shared_common/CacheMap.hpp index 10e5218e1f7..7ffb3d52e9c 100644 --- a/runtime/shared_common/CacheMap.hpp +++ b/runtime/shared_common/CacheMap.hpp @@ -265,7 +265,7 @@ class SH_CacheMap : public SH_SharedCache, public SH_CacheMapStats bool isCacheCorruptReported(void); - IDATA runEntryPointChecks(J9VMThread* currentThread, void* isAddressInCache, const char** subcstr); + IDATA runEntryPointChecks(J9VMThread* currentThread, void* isAddressInCache, const char** subcstr, bool canUnlockCache = true); void protectPartiallyFilledPages(J9VMThread *currentThread); @@ -364,7 +364,7 @@ class SH_CacheMap : public SH_SharedCache, public SH_CacheMapStats UDATA initializeROMSegmentList(J9VMThread* currentThread); - IDATA checkForCrash(J9VMThread* currentThread, bool hasClassSegmentMutex); + IDATA checkForCrash(J9VMThread* currentThread, bool hasClassSegmentMutex, bool canUnlockCache = true); void reportCorruptCache(J9VMThread* currentThread, SH_CompositeCacheImpl* _ccToUse); diff --git a/runtime/shared_common/CompositeCache.cpp b/runtime/shared_common/CompositeCache.cpp index 7fe26a61a3d..deedc072225 100644 --- a/runtime/shared_common/CompositeCache.cpp +++ b/runtime/shared_common/CompositeCache.cpp @@ -456,7 +456,7 @@ SH_CompositeCacheImpl::crashDetected(UDATA* localCrashCntr) * @param [in] currentThread Pointer to J9VMThread structure for the current thread */ void -SH_CompositeCacheImpl::reset(J9VMThread* currentThread) +SH_CompositeCacheImpl::reset(J9VMThread* currentThread, bool canUnlockCache) { if (!_started) { Trc_SHR_Assert_ShouldNeverHappen(); @@ -475,8 +475,10 @@ SH_CompositeCacheImpl::reset(J9VMThread* currentThread) _maxAOTUnstoredBytes = 0; _maxJITUnstoredBytes = 0; - /* If cache is locked, unlock it */ - doUnlockCache(currentThread); + if (canUnlockCache) { + /* If cache is locked, unlock it */ + doUnlockCache(currentThread); + } Trc_SHR_CC_reset_Exit(currentThread); } diff --git a/runtime/shared_common/CompositeCacheImpl.hpp b/runtime/shared_common/CompositeCacheImpl.hpp index 99649adb782..400eb27de11 100644 --- a/runtime/shared_common/CompositeCacheImpl.hpp +++ b/runtime/shared_common/CompositeCacheImpl.hpp @@ -140,7 +140,7 @@ class SH_CompositeCacheImpl : public SH_CompositeCache, public AbstractMemoryPer bool crashDetected(UDATA* localCrashCntr); - void reset(J9VMThread* currentThread); + void reset(J9VMThread* currentThread, bool canUnlockCache = true); BlockPtr nextEntry(J9VMThread* currentThread, UDATA* staleItems);