< prev index next >

src/hotspot/share/services/threadService.cpp

Print this page
rev 57595 : v2.09a with 8235795, 8235931 and 8236035 extracted; rebased to jdk-14+28; merge with 8236035.patch.cr1; merge with 8235795.patch.cr1; merge with 8236035.patch.cr2; merge with 8235795.patch.cr2; merge with 8235795.patch.cr3.

@@ -206,19 +206,24 @@
 // FIXME: JVMTI should call this function
 Handle ThreadService::get_current_contended_monitor(JavaThread* thread) {
   assert(thread != NULL, "should be non-NULL");
   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
 
-  ObjectMonitor *wait_obj = thread->current_waiting_monitor();
+  // This function can be called on a target JavaThread that is not
+  // the caller and we are not at a safepoint. This ObjectMonitorHandle
+  // keeps the ObjectMonitor from being async deflated so the object
+  // reference we fetch remains non-NULL.
+  ObjectMonitorHandle omh;
+  ObjectMonitor *wait_obj = thread->current_waiting_monitor(&omh);
 
   oop obj = NULL;
   if (wait_obj != NULL) {
     // thread is doing an Object.wait() call
     obj = (oop) wait_obj->object();
     assert(obj != NULL, "Object.wait() should have an object");
   } else {
-    ObjectMonitor *enter_obj = thread->current_pending_monitor();
+    ObjectMonitor *enter_obj = thread->current_pending_monitor(&omh);
     if (enter_obj != NULL) {
       // thread is trying to enter() an ObjectMonitor.
       obj = (oop) enter_obj->object();
       assert(obj != NULL, "ObjectMonitor should have an associated object!");
     }

@@ -360,10 +365,13 @@
 DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(ThreadsList * t_list, bool concurrent_locks) {
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 
   // This code was modified from the original Threads::find_deadlocks code.
   int globalDfn = 0, thisDfn;
+  // This code is called at a safepoint so this ObjectMonitorHandle
+  // is not strictly necessary.
+  ObjectMonitorHandle omh;
   ObjectMonitor* waitingToLockMonitor = NULL;
   JvmtiRawMonitor* waitingToLockRawMonitor = NULL;
   oop waitingToLockBlocker = NULL;
   bool blocked_on_monitor = false;
   JavaThread *currentThread, *previousThread;

@@ -389,14 +397,19 @@
     previousThread = jt;
     currentThread = jt;
 
     cycle->reset();
 
+    if (waitingToLockMonitor != NULL) {
+      // Done with the current waitingToLockMonitor value so release
+      // the ObjectMonitorHandle manually before we use it again:
+      omh.unset_om_ptr();
+    }
     // When there is a deadlock, all the monitors involved in the dependency
     // cycle must be contended and heavyweight. So we only care about the
     // heavyweight monitor a thread is waiting to lock.
-    waitingToLockMonitor = jt->current_pending_monitor();
+    waitingToLockMonitor = jt->current_pending_monitor(&omh);
     // JVM TI raw monitors can also be involved in deadlocks, and we can be
     // waiting to lock both a raw monitor and ObjectMonitor at the same time.
     // It isn't clear how to make deadlock detection work correctly if that
     // happens.
     waitingToLockRawMonitor = jt->current_pending_raw_monitor();

@@ -483,11 +496,16 @@
         last = cycle;
         cycle = new DeadlockCycle();
         break;
       }
       previousThread = currentThread;
-      waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor();
+      if (waitingToLockMonitor != NULL) {
+        // Done with the current waitingToLockMonitor value so release
+        // the ObjectMonitorHandle manually before we use it again:
+        omh.unset_om_ptr();
+      }
+      waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor(&omh);
       if (concurrent_locks) {
         waitingToLockBlocker = currentThread->current_park_blocker();
       }
     }
 

@@ -965,17 +983,19 @@
   st->cr();
   st->print_cr("Found one Java-level deadlock:");
   st->print("=============================");
 
   JavaThread* currentThread;
-  ObjectMonitor* waitingToLockMonitor;
   JvmtiRawMonitor* waitingToLockRawMonitor;
   oop waitingToLockBlocker;
   int len = _threads->length();
   for (int i = 0; i < len; i++) {
     currentThread = _threads->at(i);
-    waitingToLockMonitor = currentThread->current_pending_monitor();
+    // This code is called at a safepoint so this ObjectMonitorHandle
+    // is not strictly necessary.
+    ObjectMonitorHandle omh;
+    ObjectMonitor* waitingToLockMonitor = currentThread->current_pending_monitor(&omh);
     waitingToLockRawMonitor = currentThread->current_pending_raw_monitor();
     waitingToLockBlocker = currentThread->current_park_blocker();
     st->cr();
     st->print_cr("\"%s\":", currentThread->get_thread_name());
     const char* owner_desc = ",\n  which is held by";
< prev index next >