Skip to content

Commit 7bd2cd0

Browse files
author
Kim Barrett
committedApr 15, 2020
8242597: Remove GenericTaskQueue<>::push_slow
Remove push_slow and comment invariants. Reviewed-by: tschatzl, iwalulya
1 parent b0d709c commit 7bd2cd0

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed
 

‎src/hotspot/share/gc/shared/taskqueue.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ class TaskQueueSuper: public CHeapObj<F> {
206206
}
207207

208208
// Maximum number of elements allowed in the queue. This is two less
209-
// than the actual queue size, for somewhat complicated reasons.
209+
// than the actual queue size, so that a full queue can be distinguished
210+
// from underflow involving pop_local and concurrent pop_global operations
211+
// in GenericTaskQueue.
210212
uint max_elems() const { return N - 2; }
211213

212214
// Total size of queue.
@@ -267,8 +269,7 @@ class GenericTaskQueue: public TaskQueueSuper<N, F> {
267269
#endif
268270

269271
private:
270-
// Slow paths for push, pop_local. (pop_global has no fast path.)
271-
bool push_slow(E t, uint dirty_n_elems);
272+
// Slow path for pop_local, dealing with possible conflict with pop_global.
272273
bool pop_local_slow(uint localBot, Age oldAge);
273274

274275
public:

‎src/hotspot/share/gc/shared/taskqueue.inline.hpp

+13-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -57,31 +57,23 @@ inline GenericTaskQueue<E, F, N>::~GenericTaskQueue() {
5757
ArrayAllocator<E>::free(const_cast<E*>(_elems), N);
5858
}
5959

60-
template<class E, MEMFLAGS F, unsigned int N>
61-
bool GenericTaskQueue<E, F, N>::push_slow(E t, uint dirty_n_elems) {
62-
if (dirty_n_elems == N - 1) {
63-
// Actually means 0, so do the push.
64-
uint localBot = _bottom;
65-
// g++ complains if the volatile result of the assignment is
66-
// unused, so we cast the volatile away. We cannot cast directly
67-
// to void, because gcc treats that as not using the result of the
68-
// assignment. However, casting to E& means that we trigger an
69-
// unused-value warning. So, we cast the E& to void.
70-
(void)const_cast<E&>(_elems[localBot] = t);
71-
Atomic::release_store(&_bottom, increment_index(localBot));
72-
TASKQUEUE_STATS_ONLY(stats.record_push());
73-
return true;
74-
}
75-
return false;
76-
}
77-
7860
template<class E, MEMFLAGS F, unsigned int N> inline bool
7961
GenericTaskQueue<E, F, N>::push(E t) {
8062
uint localBot = _bottom;
8163
assert(localBot < N, "_bottom out of range.");
8264
idx_t top = _age.top();
8365
uint dirty_n_elems = dirty_size(localBot, top);
84-
assert(dirty_n_elems < N, "n_elems out of range.");
66+
// A dirty_size of N-1 cannot happen in push. Considering only push:
67+
// (1) dirty_n_elems is initially 0.
68+
// (2) push adds an element iff dirty_n_elems < max_elems(), which is N - 2.
69+
// (3) only push adding an element can increase dirty_n_elems.
70+
// => dirty_n_elems <= N - 2, by induction
71+
// => dirty_n_elems < N - 1, invariant
72+
//
73+
// A pop_global that is concurrent with push cannot produce a state where
74+
// dirty_size == N-1. pop_global only removes an element if dirty_elems > 0,
75+
// so can't underflow to -1 (== N-1) with push.
76+
assert(dirty_n_elems <= max_elems(), "n_elems out of range.");
8577
if (dirty_n_elems < max_elems()) {
8678
// g++ complains if the volatile result of the assignment is
8779
// unused, so we cast the volatile away. We cannot cast directly
@@ -92,9 +84,8 @@ GenericTaskQueue<E, F, N>::push(E t) {
9284
Atomic::release_store(&_bottom, increment_index(localBot));
9385
TASKQUEUE_STATS_ONLY(stats.record_push());
9486
return true;
95-
} else {
96-
return push_slow(t, dirty_n_elems);
9787
}
88+
return false; // Queue is full.
9889
}
9990

10091
template <class E, MEMFLAGS F, unsigned int N>

0 commit comments

Comments
 (0)
Please sign in to comment.