Skip to content

Commit 78e11b5

Browse files
author
duke
committedMay 7, 2024
Automatic merge of jdk:master into master
2 parents 1de100e + a2584a8 commit 78e11b5

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed
 

‎src/hotspot/share/oops/instanceKlass.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -1634,16 +1634,17 @@ void InstanceKlass::call_class_initializer(TRAPS) {
16341634

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

‎src/hotspot/share/runtime/mutexLocker.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ Mutex* tty_lock = nullptr;
100100
Mutex* RawMonitor_lock = nullptr;
101101
Mutex* PerfDataMemAlloc_lock = nullptr;
102102
Mutex* PerfDataManager_lock = nullptr;
103-
Mutex* OopMapCacheAlloc_lock = nullptr;
104103

105104
Mutex* FreeList_lock = nullptr;
106105
Mutex* OldSets_lock = nullptr;
@@ -349,7 +348,6 @@ void mutex_init() {
349348
MUTEX_DEFL(PSOldGenExpand_lock , PaddedMutex , Heap_lock, true);
350349
}
351350
#endif
352-
MUTEX_DEFL(OopMapCacheAlloc_lock , PaddedMutex , Threads_lock, true);
353351
MUTEX_DEFL(Module_lock , PaddedMutex , ClassLoaderDataGraph_lock);
354352
MUTEX_DEFL(SystemDictionary_lock , PaddedMonitor, Module_lock);
355353
MUTEX_DEFL(JNICritical_lock , PaddedMonitor, AdapterHandlerLibrary_lock); // used for JNI critical regions

‎src/hotspot/share/runtime/mutexLocker.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ extern Mutex* FullGCALot_lock; // a lock to make FullGCALot MT
9696
extern Mutex* RawMonitor_lock;
9797
extern Mutex* PerfDataMemAlloc_lock; // a lock on the allocator for PerfData memory for performance data
9898
extern Mutex* PerfDataManager_lock; // a long on access to PerfDataManager resources
99-
extern Mutex* OopMapCacheAlloc_lock; // protects allocation of oop_map caches
10099

101100
extern Mutex* FreeList_lock; // protects the free region list during safepoints
102101
extern Mutex* OldSets_lock; // protects the old region sets

0 commit comments

Comments
 (0)
Please sign in to comment.