changeset 66:e2e304d54b02

Bug 3225: JVM may hang when deadlock detector and safepoint are conflicted Reviewed-by: ykubota https://github.com/HeapStats/heapstats/pull/48
author Yasumasa Suenaga <yasuenag@gmail.com>
date Wed, 09 Nov 2016 21:21:42 +0900
parents 39e61d11adcd
children 144f6b0a2dc1
files agent/ChangeLog agent/src/deadlockFinder.cpp
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/agent/ChangeLog	Thu Apr 28 12:41:12 2016 +0900
+++ b/agent/ChangeLog	Wed Nov 09 21:21:42 2016 +0900
@@ -1,3 +1,7 @@
+2016-11-09 Yasumasa Suenaga  <yasuenag@gmail.com>
+
+	* Bug 3225: JVM may hang when deadlock detector and safepoint are conflicted
+
 2016-04-28 KUBOTA Yuji  <kubota.yuji@lab.ntt.co.jp>
 
 	* Bump to 1.0.5
--- a/agent/src/deadlockFinder.cpp	Thu Apr 28 12:41:12 2016 +0900
+++ b/agent/src/deadlockFinder.cpp	Wed Nov 09 21:21:42 2016 +0900
@@ -373,6 +373,17 @@
     }
 
     if (*status == THREAD_IN_VM) {
+      /*
+       * Reset "_thread_state".
+       *
+       * CAUTION!!
+       *   According to the comment of Monitor::lock_without_safepoint_check() in
+       *   hotspot/src/share/vm/runtime/mutex.cpp:
+       *     If this is called with thread state set to be in VM, the safepoint
+       *     synchronization code will deadlock!
+       */
+      *status = original_status;
+
       bool needLock = !monitor_owned_by_self(thread_lock);
       
       /*
@@ -388,8 +399,6 @@
         }
       }
       
-      /* Reset "_thread_state". */
-      *status = original_status;
       /* Reset "_safepoint_state". */
       threadSafepointStateDestroy(thisThreadPtr);
       threadSafepointStateCreate(thisThreadPtr);