diff src/share/vm/services/threadService.cpp @ 10985:ef748153ee8f

8016304: ThreadMXBean.getDeadlockedThreads reports bogus deadlocks on JDK 8 Reviewed-by: dcubed, mgronlun
author sla
date Mon, 17 Jun 2013 18:35:44 +0200
parents 5ee250974db9
children 0b9ea9a72436
line wrap: on
line diff
--- a/src/share/vm/services/threadService.cpp	Mon Jun 10 10:45:19 2013 -0400
+++ b/src/share/vm/services/threadService.cpp	Mon Jun 17 18:35:44 2013 +0200
@@ -327,27 +327,30 @@
     while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) {
       cycle->add_thread(currentThread);
       if (waitingToLockMonitor != NULL) {
-        currentThread = Threads::owning_thread_from_monitor_owner(
-                          (address)waitingToLockMonitor->owner(),
-                          false /* no locking needed */);
-        if (currentThread == NULL) {
-          // This function is called at a safepoint so the JavaThread
-          // that owns waitingToLockMonitor should be findable, but
-          // if it is not findable, then the previous currentThread is
-          // blocked permanently. We record this as a deadlock.
-          num_deadlocks++;
+        address currentOwner = (address)waitingToLockMonitor->owner();
+        if (currentOwner != NULL) {
+          currentThread = Threads::owning_thread_from_monitor_owner(
+                            currentOwner,
+                            false /* no locking needed */);
+          if (currentThread == NULL) {
+            // This function is called at a safepoint so the JavaThread
+            // that owns waitingToLockMonitor should be findable, but
+            // if it is not findable, then the previous currentThread is
+            // blocked permanently. We record this as a deadlock.
+            num_deadlocks++;
 
-          cycle->set_deadlock(true);
+            cycle->set_deadlock(true);
 
-          // add this cycle to the deadlocks list
-          if (deadlocks == NULL) {
-            deadlocks = cycle;
-          } else {
-            last->set_next(cycle);
+            // add this cycle to the deadlocks list
+            if (deadlocks == NULL) {
+              deadlocks = cycle;
+            } else {
+              last->set_next(cycle);
+            }
+            last = cycle;
+            cycle = new DeadlockCycle();
+            break;
           }
-          last = cycle;
-          cycle = new DeadlockCycle();
-          break;
         }
       } else {
         if (concurrent_locks) {