JDK-8265921 : Mutex name may point to garbage after JDK-8264146
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 17
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2021-04-25
  • Updated: 2021-04-26
  • Resolved: 2021-04-26
Related Reports
Duplicate :  
Relates :  
Description
While playing Kim's latest string deduplication code to enable string deduplication during root scan, I got following assertion:

#  assert(false) failed: Attempting to acquire lock ^H<98>��l<8d>^?/9 out of order with lock stack_watermark_lock/2 -- possible deadlock

The first lock name should be one of OopStorage's _allocation_mutex, but it showed as garbage above.

It turns out that _allocation_mutex name is generated dynamically.

e.g. 
_allocation_mutex(make_oopstorage_mutex(name, "alloc", Mutex::oopstorage)),

and 

static Mutex* make_oopstorage_mutex(const char* storage_name,
                                    const char* kind,
                                    int rank) {
  char name[256];
  os::snprintf(name, sizeof(name), "%s %s lock", storage_name, kind);
  return new PaddedMutex(rank, name, true, Mutex::_safepoint_check_never);
}

Comments
Used following code, I found quite a few stack allocated mutex name that passed to Mutex constructor. diff --git a/src/hotspot/share/runtime/mutex.cpp b/src/hotspot/share/runtime/mutex.cpp index bf3b7839157..3830e963fc0 100644 --- a/src/hotspot/share/runtime/mutex.cpp +++ b/src/hotspot/share/runtime/mutex.cpp @@ -280,6 +280,11 @@ Mutex::Mutex(int Rank, const char * name, bool allow_vm_block, assert(_rank > special || _safepoint_check_required == _safepoint_check_never, "Special locks or below should never safepoint"); + + char limit; + if (Thread::current_or_null() != nullptr && Thread::current()->is_in_stack_range_excl((address)name, (address)&limit)) { + printf("Mutex name: %s looks like stack allocated\n", name); + } #endif } Mutex name: ObjectSynchronizer Weak alloc lock looks like stack allocated Mutex name: ObjectSynchronizer Weak active lock looks like stack allocated Mutex name: ThreadService OopStorage alloc lock looks like stack allocated Mutex name: ThreadService OopStorage active lock looks like stack allocated Mutex name: JVMTI OopStorage alloc lock looks like stack allocated Mutex name: JVMTI OopStorage active lock looks like stack allocated Mutex name: JVMTI Tag Weak OopStorage alloc lock looks like stack allocated Mutex name: JVMTI Tag Weak OopStorage active lock looks like stack allocated Mutex name: StringTable Weak alloc lock looks like stack allocated Mutex name: StringTable Weak active lock looks like stack allocated Mutex name: ResolvedMethodTable Weak alloc lock looks like stack allocated Mutex name: ResolvedMethodTable Weak active lock looks like stack allocated Mutex name: JNI Global alloc lock looks like stack allocated Mutex name: JNI Global active lock looks like stack allocated Mutex name: JNI Weak alloc lock looks like stack allocated Mutex name: JNI Weak active lock looks like stack allocated Mutex name: Weak JFR Old Object Samples alloc lock looks like stack allocated Mutex name: Weak JFR Old Object Samples active lock looks like stack allocated Mutex name: ObjectSynchronizer Weak alloc lock looks like stack allocated Mutex name: ObjectSynchronizer Weak active lock looks like stack allocated Mutex name: ThreadService OopStorage alloc lock looks like stack allocated Mutex name: ThreadService OopStorage active lock looks like stack allocated Mutex name: JVMTI OopStorage alloc lock looks like stack allocated Mutex name: JVMTI OopStorage active lock looks like stack allocated Mutex name: JVMTI Tag Weak OopStorage alloc lock looks like stack allocated Mutex name: JVMTI Tag Weak OopStorage active lock looks like stack allocated Mutex name: HeapRegionRemSet lock #0 looks like stack allocated Mutex name: HeapRegionRemSet lock #1 looks like stack allocated Mutex name: HeapRegionRemSet lock #2 looks like stack allocated Mutex name: HeapRegionRemSet lock #3 looks like stack allocated Mutex name: HeapRegionRemSet lock #4 looks like stack allocated Mutex name: HeapRegionRemSet lock #5 looks like stack allocated Mutex name: HeapRegionRemSet lock #6 looks like stack allocated Mutex name: HeapRegionRemSet lock #7 looks like stack allocated Mutex name: HeapRegionRemSet lock #8 looks like stack allocated Mutex name: HeapRegionRemSet lock #9 looks like stack allocated Mutex name: HeapRegionRemSet lock #10 looks like stack allocated Mutex name: HeapRegionRemSet lock #11 looks like stack allocated Mutex name: HeapRegionRemSet lock #12 looks like stack allocated Mutex name: HeapRegionRemSet lock #13 looks like stack allocated Mutex name: HeapRegionRemSet lock #14 looks like stack allocated Mutex name: HeapRegionRemSet lock #15 looks like stack allocated Mutex name: HeapRegionRemSet lock #16 looks like stack allocated Mutex name: HeapRegionRemSet lock #17 looks like stack allocated Mutex name: HeapRegionRemSet lock #18 looks like stack allocated Mutex name: HeapRegionRemSet lock #19 looks like stack allocated Mutex name: HeapRegionRemSet lock #20 looks like stack allocated Mutex name: HeapRegionRemSet lock #21 looks like stack allocated Mutex name: HeapRegionRemSet lock #22 looks like stack allocated Mutex name: HeapRegionRemSet lock #23 looks like stack allocated Mutex name: HeapRegionRemSet lock #24 looks like stack allocated Mutex name: HeapRegionRemSet lock #25 looks like stack allocated Mutex name: HeapRegionRemSet lock #26 looks like stack allocated Mutex name: HeapRegionRemSet lock #27 looks like stack allocated Mutex name: HeapRegionRemSet lock #28 looks like stack allocated Mutex name: HeapRegionRemSet lock #29 looks like stack allocated Mutex name: HeapRegionRemSet lock #30 looks like stack allocated Mutex name: HeapRegionRemSet lock #31 looks like stack allocated Mutex name: HeapRegionRemSet lock #32 looks like stack allocated Mutex name: HeapRegionRemSet lock #33 looks like stack allocated Mutex name: HeapRegionRemSet lock #34 looks like stack allocated Mutex name: HeapRegionRemSet lock #35 looks like stack allocated Mutex name: HeapRegionRemSet lock #36 looks like stack allocated Mutex name: HeapRegionRemSet lock #37 looks like stack allocated Mutex name: HeapRegionRemSet lock #38 looks like stack allocated Mutex name: HeapRegionRemSet lock #39 looks like stack allocated Mutex name: HeapRegionRemSet lock #40 looks like stack allocated Mutex name: HeapRegionRemSet lock #41 looks like stack allocated Mutex name: HeapRegionRemSet lock #42 looks like stack allocated Mutex name: HeapRegionRemSet lock #43 looks like stack allocated Mutex name: HeapRegionRemSet lock #44 looks like stack allocated Mutex name: HeapRegionRemSet lock #45 looks like stack allocated Mutex name: HeapRegionRemSet lock #46 looks like stack allocated Mutex name: HeapRegionRemSet lock #47 looks like stack allocated Mutex name: HeapRegionRemSet lock #48 looks like stack allocated Mutex name: HeapRegionRemSet lock #49 looks like stack allocated Mutex name: HeapRegionRemSet lock #50 looks like stack allocated Mutex name: HeapRegionRemSet lock #51 looks like stack allocated Mutex name: HeapRegionRemSet lock #52 looks like stack allocated Mutex name: HeapRegionRemSet lock #53 looks like stack allocated
25-04-2021