8243325: Cleanup TaskQueueSuper<>::peek

Replaced uses of peek with new assert_empty.

Reviewed-by: tschatzl, sjohanss
This commit is contained in:
Kim Barrett 2020-05-06 00:23:51 -04:00
parent 611fda672f
commit 5b066096a4
3 changed files with 27 additions and 24 deletions

View File

@ -39,8 +39,10 @@ TaskTerminator::TaskTerminator(uint n_threads, TaskQueueSetSuper* queue_set) :
}
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 @@ TaskTerminator::~TaskTerminator() {
}
#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 @@ bool TaskTerminator::offer_termination(TerminatorTerminator* terminator) {
// 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 @@ bool TaskTerminator::offer_termination(TerminatorTerminator* terminator) {
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 @@ bool TaskTerminator::offer_termination(TerminatorTerminator* terminator) {
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 @@ bool TaskTerminator::offer_termination(TerminatorTerminator* terminator) {
// 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 @@ bool TaskTerminator::offer_termination(TerminatorTerminator* terminator) {
if (_offered_termination == _n_threads) {
_blocker->unlock();
assert(!peek_in_queue_set(), "Precondition");
assert_queue_set_empty();
return true;
}
}

View File

@ -57,9 +57,8 @@ class TaskTerminator : public CHeapObj<mtGC> {
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;

View File

@ -240,10 +240,10 @@ private:
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 @@ private:
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 @@ public:
// 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 @@ GenericTaskQueueSet<T, F>::queue(uint i) {
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 {