Skip to content

Commit d151050

Browse files
committed
8334594: Generational ZGC: Deadlock after OopMap rewrites in 8331572
Reviewed-by: stefank Backport-of: 05ff318
1 parent ae49182 commit d151050

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

src/hotspot/share/gc/shared/gcVMOperations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ bool VM_GC_Operation::doit_prologue() {
132132
void VM_GC_Operation::doit_epilogue() {
133133
// GC thread root traversal likely used OopMapCache a lot, which
134134
// might have created lots of old entries. Trigger the cleanup now.
135-
OopMapCache::trigger_cleanup();
135+
OopMapCache::try_trigger_cleanup();
136136
if (Universe::has_reference_pending_list()) {
137137
Heap_lock->notify_all();
138138
}

src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void VM_ShenandoahOperation::doit_epilogue() {
4444
assert(!ShenandoahHeap::heap()->has_gc_state_changed(), "GC State was not synchronized to java threads.");
4545
// GC thread root traversal likely used OopMapCache a lot, which
4646
// might have created lots of old entries. Trigger the cleanup now.
47-
OopMapCache::trigger_cleanup();
47+
OopMapCache::try_trigger_cleanup();
4848
}
4949

5050
bool VM_ShenandoahReferenceOperation::doit_prologue() {

src/hotspot/share/gc/x/xDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class VM_XOperation : public VM_Operation {
134134

135135
// GC thread root traversal likely used OopMapCache a lot, which
136136
// might have created lots of old entries. Trigger the cleanup now.
137-
OopMapCache::trigger_cleanup();
137+
OopMapCache::try_trigger_cleanup();
138138
}
139139

140140
bool gc_locked() const {

src/hotspot/share/gc/z/zGeneration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ class VM_ZOperation : public VM_Operation {
456456

457457
// GC thread root traversal likely used OopMapCache a lot, which
458458
// might have created lots of old entries. Trigger the cleanup now.
459-
OopMapCache::trigger_cleanup();
459+
OopMapCache::try_trigger_cleanup();
460460
}
461461

462462
bool success() const {

src/hotspot/share/interpreter/oopMapCache.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,13 @@ bool OopMapCache::has_cleanup_work() {
592592
return Atomic::load(&_old_entries) != nullptr;
593593
}
594594

595-
void OopMapCache::trigger_cleanup() {
596-
if (has_cleanup_work()) {
597-
MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
595+
void OopMapCache::try_trigger_cleanup() {
596+
// See we can take the lock for the notification without blocking.
597+
// This allows triggering the cleanup from GC paths, that can hold
598+
// the service lock for e.g. oop iteration in service thread.
599+
if (has_cleanup_work() && Service_lock->try_lock_without_rank_check()) {
598600
Service_lock->notify_all();
601+
Service_lock->unlock();
599602
}
600603
}
601604

src/hotspot/share/interpreter/oopMapCache.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ class OopMapCache : public CHeapObj<mtClass> {
183183
// Check if we need to clean up old entries
184184
static bool has_cleanup_work();
185185

186-
// Request cleanup if work is needed
187-
static void trigger_cleanup();
186+
// Request cleanup if work is needed and notification is currently possible
187+
static void try_trigger_cleanup();
188188

189189
// Clean up the old entries
190190
static void cleanup();

0 commit comments

Comments
 (0)