changeset 6697:5da31e88dbf5

8047720: Xprof hangs on Solaris Summary: Update use of PeriodicTask_lock in WatcherThread::stop() to avoid safepoint deadlock. Reviewed-by: mgronlun, coleenp
author dcubed
date Fri, 27 Jun 2014 14:00:50 -0700
parents 88a7b3dd7d5d
children 56c8024da07e
files src/share/vm/runtime/thread.cpp
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/thread.cpp	Fri Jun 27 08:11:49 2014 -0700
+++ b/src/share/vm/runtime/thread.cpp	Fri Jun 27 14:00:50 2014 -0700
@@ -1358,14 +1358,24 @@
 }
 
 void WatcherThread::stop() {
-  {
-    MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
-    _should_terminate = true;
-    OrderAccess::fence();  // ensure WatcherThread sees update in main loop
-
+  // Get the PeriodicTask_lock if we can. If we cannot, then the
+  // WatcherThread is using it and we don't want to block on that lock
+  // here because that might cause a safepoint deadlock depending on
+  // what the current WatcherThread tasks are doing.
+  bool have_lock = PeriodicTask_lock->try_lock();
+
+  _should_terminate = true;
+  OrderAccess::fence();  // ensure WatcherThread sees update in main loop
+
+  if (have_lock) {
     WatcherThread* watcher = watcher_thread();
-    if (watcher != NULL)
+    if (watcher != NULL) {
+      // If we managed to get the lock, then we should unpark the
+      // WatcherThread so that it can see we want it to stop.
       watcher->unpark();
+    }
+
+    PeriodicTask_lock->unlock();
   }
 
   // it is ok to take late safepoints here, if needed