changeset 59173:871e0be28aed

8243325: Cleanup TaskQueueSuper<>::peek Summary: Replaced uses of peek with new assert_empty. Reviewed-by: tschatzl, sjohanss
author kbarrett
date Wed, 06 May 2020 00:23:51 -0400
parents b51f26a6647a
children f5373fc53bed
files src/hotspot/share/gc/shared/taskTerminator.cpp src/hotspot/share/gc/shared/taskTerminator.hpp src/hotspot/share/gc/shared/taskqueue.hpp
diffstat 3 files changed, 27 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shared/taskTerminator.cpp	Wed May 06 13:41:11 2020 +0800
+++ b/src/hotspot/share/gc/shared/taskTerminator.cpp	Wed May 06 00:23:51 2020 -0400
@@ -39,8 +39,10 @@
 }
 
 TaskTerminator::~TaskTerminator() {
-  assert(_offered_termination == 0 || !peek_in_queue_set(), "Precondition");
-  assert(_offered_termination == 0 || _offered_termination == _n_threads, "Terminated or aborted" );
+  if (_offered_termination != 0) {
+    assert(_offered_termination == _n_threads, "Must be terminated or aborted");
+    assert_queue_set_empty();
+  }
 
   assert(_spin_master == NULL, "Should have been reset");
   assert(_blocker != NULL, "Can not be NULL");
@@ -48,8 +50,8 @@
 }
 
 #ifdef ASSERT
-bool TaskTerminator::peek_in_queue_set() {
-  return _queue_set->peek();
+void TaskTerminator::assert_queue_set_empty() const {
+  _queue_set->assert_empty();
 }
 #endif
 
@@ -87,7 +89,7 @@
   // Single worker, done
   if (_n_threads == 1) {
     _offered_termination = 1;
-    assert(!peek_in_queue_set(), "Precondition");
+    assert_queue_set_empty();
     return true;
   }
 
@@ -97,7 +99,7 @@
   if (_offered_termination == _n_threads) {
     _blocker->notify_all();
     _blocker->unlock();
-    assert(!peek_in_queue_set(), "Precondition");
+    assert_queue_set_empty();
     return true;
   }
 
@@ -110,7 +112,7 @@
 
       if (do_spin_master_work(terminator)) {
         assert(_offered_termination == _n_threads, "termination condition");
-        assert(!peek_in_queue_set(), "Precondition");
+        assert_queue_set_empty();
         return true;
       } else {
         _blocker->lock_without_safepoint_check();
@@ -118,7 +120,7 @@
         // before returning from do_spin_master_work() and acquiring lock above.
         if (_offered_termination == _n_threads) {
           _blocker->unlock();
-          assert(!peek_in_queue_set(), "Precondition");
+          assert_queue_set_empty();
           return true;
         }
       }
@@ -127,7 +129,7 @@
 
       if (_offered_termination == _n_threads) {
         _blocker->unlock();
-        assert(!peek_in_queue_set(), "Precondition");
+        assert_queue_set_empty();
         return true;
       }
     }
--- a/src/hotspot/share/gc/shared/taskTerminator.hpp	Wed May 06 13:41:11 2020 +0800
+++ b/src/hotspot/share/gc/shared/taskTerminator.hpp	Wed May 06 00:23:51 2020 -0400
@@ -57,9 +57,8 @@
   volatile uint _offered_termination;
   DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile uint));
 
-#ifdef ASSERT
-  bool peek_in_queue_set();
-#endif
+  void assert_queue_set_empty() const NOT_DEBUG_RETURN;
+
   void yield();
 
   Monitor*    _blocker;
--- a/src/hotspot/share/gc/shared/taskqueue.hpp	Wed May 06 13:41:11 2020 +0800
+++ b/src/hotspot/share/gc/shared/taskqueue.hpp	Wed May 06 00:23:51 2020 -0400
@@ -240,10 +240,10 @@
 public:
   TaskQueueSuper() : _bottom(0), _age() {}
 
-  // Return true if the TaskQueue contains any tasks.
+  // Assert the queue is empty.
   // Unreliable if there are concurrent pushes or pops.
-  bool peek() const {
-    return bottom_relaxed() != age_top_relaxed();
+  void assert_empty() const {
+    assert(bottom_relaxed() == age_top_relaxed(), "not empty");
   }
 
   bool is_empty() const {
@@ -439,8 +439,10 @@
 
 class TaskQueueSetSuper {
 public:
-  // Returns "true" if some TaskQueue in the set contains a task.
-  virtual bool peek() = 0;
+  // Assert all queues in the set are empty.
+  NOT_DEBUG(void assert_empty() const {})
+  DEBUG_ONLY(virtual void assert_empty() const = 0;)
+
   // Tasks in queue
   virtual uint tasks() const = 0;
 };
@@ -471,8 +473,9 @@
   // Returns if stealing succeeds, and sets "t" to the stolen task.
   bool steal(uint queue_num, E& t);
 
-  bool peek();
-  uint tasks() const;
+  DEBUG_ONLY(virtual void assert_empty() const;)
+
+  virtual uint tasks() const;
 
   uint size() const { return _n; }
 };
@@ -488,15 +491,14 @@
   return _queues[i];
 }
 
+#ifdef ASSERT
 template<class T, MEMFLAGS F>
-bool GenericTaskQueueSet<T, F>::peek() {
-  // Try all the queues.
+void GenericTaskQueueSet<T, F>::assert_empty() const {
   for (uint j = 0; j < _n; j++) {
-    if (_queues[j]->peek())
-      return true;
+    _queues[j]->assert_empty();
   }
-  return false;
 }
+#endif // ASSERT
 
 template<class T, MEMFLAGS F>
 uint GenericTaskQueueSet<T, F>::tasks() const {