changeset 55:cde91311e623

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:20:26 +0900
parents 45b3506c6bd0
children 276d14d7b511
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:47:31 2016 +0900
+++ b/agent/ChangeLog	Wed Nov 09 21:20:26 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.1.4
--- a/agent/src/deadlockFinder.cpp	Thu Apr 28 12:47:31 2016 +0900
+++ b/agent/src/deadlockFinder.cpp	Wed Nov 09 21:20:26 2016 +0900
@@ -376,6 +376,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);
             
             /*
@@ -391,8 +402,6 @@
                 }
             }
             
-            /* Reset "_thread_state". */
-            *status = original_status;
             /* Reset "_safepoint_state". */
             threadSafepointStateDestroy(thisThreadPtr);
             threadSafepointStateCreate(thisThreadPtr);