hotspot/src/share/vm/runtime/vmThread.cpp
changeset 46496 76ed99d51a67
parent 40667 f9cf2db7f59f
child 46589 f1c04490ded1
--- a/hotspot/src/share/vm/runtime/vmThread.cpp	Thu May 25 09:38:33 2017 +0200
+++ b/hotspot/src/share/vm/runtime/vmThread.cpp	Thu May 25 09:43:43 2017 +0200
@@ -204,6 +204,7 @@
 VM_Operation*     VMThread::_cur_vm_operation   = NULL;
 VMOperationQueue* VMThread::_vm_queue           = NULL;
 PerfCounter*      VMThread::_perf_accumulated_vm_operation_time = NULL;
+const char*       VMThread::_no_op_reason       = NULL;
 
 
 void VMThread::create() {
@@ -273,6 +274,7 @@
   }
 
   // 4526887 let VM thread exit at Safepoint
+  _no_op_reason = "Halt";
   SafepointSynchronize::begin();
 
   if (VerifyBeforeExit) {
@@ -380,6 +382,25 @@
   }
 }
 
+bool VMThread::no_op_safepoint_needed(bool check_time) {
+  if (SafepointALot) {
+    _no_op_reason = "SafepointALot";
+    return true;
+  }
+  if (!SafepointSynchronize::is_cleanup_needed()) {
+    return false;
+  }
+  if (check_time) {
+    long interval = SafepointSynchronize::last_non_safepoint_interval();
+    bool max_time_exceeded = GuaranteedSafepointInterval != 0 &&
+                             (interval > GuaranteedSafepointInterval);
+    if (!max_time_exceeded) {
+      return false;
+    }
+  }
+  _no_op_reason = "Cleanup";
+  return true;
+}
 
 void VMThread::loop() {
   assert(_cur_vm_operation == NULL, "no current one should be executing");
@@ -418,8 +439,7 @@
           exit(-1);
         }
 
-        if (timedout && (SafepointALot ||
-                         SafepointSynchronize::is_cleanup_needed())) {
+        if (timedout && VMThread::no_op_safepoint_needed(false)) {
           MutexUnlockerEx mul(VMOperationQueue_lock,
                               Mutex::_no_safepoint_check_flag);
           // Force a safepoint since we have not had one for at least
@@ -542,14 +562,10 @@
     //
     // We want to make sure that we get to a safepoint regularly.
     //
-    if (SafepointALot || SafepointSynchronize::is_cleanup_needed()) {
-      long interval          = SafepointSynchronize::last_non_safepoint_interval();
-      bool max_time_exceeded = GuaranteedSafepointInterval != 0 && (interval > GuaranteedSafepointInterval);
-      if (SafepointALot || max_time_exceeded) {
-        HandleMark hm(VMThread::vm_thread());
-        SafepointSynchronize::begin();
-        SafepointSynchronize::end();
-      }
+    if (VMThread::no_op_safepoint_needed(true)) {
+      HandleMark hm(VMThread::vm_thread());
+      SafepointSynchronize::begin();
+      SafepointSynchronize::end();
     }
   }
 }