8210889: Some service thread cleanups can be starved
authorkbarrett
Wed, 19 Sep 2018 20:07:02 -0400
changeset 51813 cfa50d6a6fba
parent 51812 30e6079a9a12
child 51814 43668e3cae4d
8210889: Some service thread cleanups can be starved Summary: Do all available work on each iteration. Reviewed-by: pliden, tschatzl, coleenp
src/hotspot/share/runtime/serviceThread.cpp
--- a/src/hotspot/share/runtime/serviceThread.cpp	Wed Sep 19 16:07:03 2018 -0700
+++ b/src/hotspot/share/runtime/serviceThread.cpp	Wed Sep 19 20:07:02 2018 -0400
@@ -86,7 +86,6 @@
     bool has_jvmti_events = false;
     bool has_gc_notification_event = false;
     bool has_dcmd_notification_event = false;
-    bool acs_notify = false;
     bool stringtable_work = false;
     bool symboltable_work = false;
     bool resolved_method_table_work = false;
@@ -104,16 +103,20 @@
       ThreadBlockInVM tbivm(jt);
 
       MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
-      while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
-             !(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
-              !(has_gc_notification_event = GCNotifier::has_event()) &&
-              !(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) &&
-              !(stringtable_work = StringTable::has_work()) &&
-              !(symboltable_work = SymbolTable::has_work()) &&
-              !(resolved_method_table_work = ResolvedMethodTable::has_work()) &&
-              !(protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work())) {
-        // wait until one of the sensors has pending requests, or there is a
-        // pending JVMTI event or JMX GC notification to post
+      // Process all available work on each (outer) iteration, rather than
+      // only the first recognized bit of work, to avoid frequently true early
+      // tests from potentially starving later work.  Hence the use of
+      // arithmetic-or to combine results; we don't want short-circuiting.
+      while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
+              (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
+              (has_gc_notification_event = GCNotifier::has_event()) |
+              (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
+              (stringtable_work = StringTable::has_work()) |
+              (symboltable_work = SymbolTable::has_work()) |
+              (resolved_method_table_work = ResolvedMethodTable::has_work()) |
+              (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()))
+             == 0) {
+        // Wait until notified that there is some work to do.
         Service_lock->wait(Mutex::_no_safepoint_check_flag);
       }