Navigation Menu

Skip to content

Commit

Permalink
8243325: Cleanup TaskQueueSuper<>::peek
Browse files Browse the repository at this point in the history
Replaced uses of peek with new assert_empty.

Reviewed-by: tschatzl, sjohanss
  • Loading branch information
Kim Barrett committed May 6, 2020
1 parent 611fda6 commit 5b06609
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
20 changes: 11 additions & 9 deletions src/hotspot/share/gc/shared/taskTerminator.cpp
Expand Up @@ -39,17 +39,19 @@ 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");
delete _blocker;
}

#ifdef ASSERT
bool TaskTerminator::peek_in_queue_set() {
return _queue_set->peek();
void TaskTerminator::assert_queue_set_empty() const {
_queue_set->assert_empty();
}
#endif

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -110,15 +112,15 @@ 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();
// There is possibility that termination is reached between dropping the lock
// 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;
}
}
Expand All @@ -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;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/gc/shared/taskTerminator.hpp
Expand Up @@ -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;
Expand Down
26 changes: 14 additions & 12 deletions src/hotspot/share/gc/shared/taskqueue.hpp
Expand Up @@ -240,10 +240,10 @@ class TaskQueueSuper: public CHeapObj<F> {
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 {
Expand Down Expand Up @@ -439,8 +439,10 @@ class OverflowTaskQueue: public GenericTaskQueue<E, F, N>

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;
};
Expand Down Expand Up @@ -471,8 +473,9 @@ class GenericTaskQueueSet: public TaskQueueSetSuperImpl<F> {
// 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; }
};
Expand All @@ -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 {
Expand Down

0 comments on commit 5b06609

Please sign in to comment.