8331714: Make OopMapCache installation lock-free

Backport-of: a2584a8341
This commit is contained in:
Aleksey Shipilev
2024-05-29 11:44:12 +00:00
committed by Vitaly Provodin
parent 9b0d4afaa8
commit 62e180669d
3 changed files with 9 additions and 11 deletions

View File

@@ -1641,16 +1641,17 @@ void InstanceKlass::call_class_initializer(TRAPS) {
void InstanceKlass::mask_for(const methodHandle& method, int bci,
InterpreterOopMap* entry_for) {
// Lazily create the _oop_map_cache at first request
// Lock-free access requires load_acquire.
// Lazily create the _oop_map_cache at first request.
// Load_acquire is needed to safely get instance published with CAS by another thread.
OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
if (oop_map_cache == nullptr) {
MutexLocker x(OopMapCacheAlloc_lock);
// Check if _oop_map_cache was allocated while we were waiting for this lock
if ((oop_map_cache = _oop_map_cache) == nullptr) {
oop_map_cache = new OopMapCache();
// Ensure _oop_map_cache is stable, since it is examined without a lock
Atomic::release_store(&_oop_map_cache, oop_map_cache);
// Try to install new instance atomically.
oop_map_cache = new OopMapCache();
OopMapCache* other = Atomic::cmpxchg(&_oop_map_cache, (OopMapCache*)nullptr, oop_map_cache);
if (other != nullptr) {
// Someone else managed to install before us, ditch local copy and use the existing one.
delete oop_map_cache;
oop_map_cache = other;
}
}
// _oop_map_cache is constant after init; lookup below does its own locking.

View File

@@ -103,7 +103,6 @@ Mutex* tty_lock = nullptr;
Mutex* RawMonitor_lock = nullptr;
Mutex* PerfDataMemAlloc_lock = nullptr;
Mutex* PerfDataManager_lock = nullptr;
Mutex* OopMapCacheAlloc_lock = nullptr;
Mutex* FreeList_lock = nullptr;
Mutex* OldSets_lock = nullptr;
@@ -364,7 +363,6 @@ void mutex_init() {
MUTEX_DEFL(PSOldGenExpand_lock , PaddedMutex , Heap_lock, true);
}
#endif
MUTEX_DEFL(OopMapCacheAlloc_lock , PaddedMutex , Threads_lock, true);
MUTEX_DEFL(Module_lock , PaddedMutex , ClassLoaderDataGraph_lock);
MUTEX_DEFL(SystemDictionary_lock , PaddedMonitor, Module_lock);
MUTEX_DEFL(JNICritical_lock , PaddedMonitor, AdapterHandlerLibrary_lock); // used for JNI critical regions

View File

@@ -99,7 +99,6 @@ extern Mutex* FullGCALot_lock; // a lock to make FullGCALot MT
extern Mutex* RawMonitor_lock;
extern Mutex* PerfDataMemAlloc_lock; // a lock on the allocator for PerfData memory for performance data
extern Mutex* PerfDataManager_lock; // a long on access to PerfDataManager resources
extern Mutex* OopMapCacheAlloc_lock; // protects allocation of oop_map caches
extern Mutex* EnhancedRedefineClasses_lock; // locks classes from parallel enhanced redefinition