changeset 172:5dbec349fffe

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:18:46 +0900
parents 00afdf817f77
children 59fbf49bb98d
files ChangeLog agent/src/heapstats-engines/deadlockFinder.cpp
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Nov 08 22:34:43 2016 +0900
+++ b/ChangeLog	Wed Nov 09 21:18:46 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-11-08  Yasumasa Suenaga <yasuenag@gmail.com>
 
 	* Bug 3223: Cannot set empty value to signal setting
--- a/agent/src/heapstats-engines/deadlockFinder.cpp	Tue Nov 08 22:34:43 2016 +0900
+++ b/agent/src/heapstats-engines/deadlockFinder.cpp	Wed Nov 09 21:18:46 2016 +0900
@@ -545,6 +545,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);
 
       /*
@@ -560,8 +571,6 @@
         }
       }
 
-      /* Reset "_thread_state". */
-      *status = original_status;
       /* Reset "_safepoint_state". */
       threadSafepointStateDestroy(thisThreadPtr);
       threadSafepointStateCreate(thisThreadPtr);