author | never |
Tue, 13 Oct 2009 16:29:31 -0700 | |
changeset 4014 | b59b8c387950 |
parent 3607 | fa62293fa65c |
child 4027 | 1c62fbaf6b68 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2105 | 2 |
* Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
class TaskQueueSuper: public CHeapObj { |
|
26 |
protected: |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
27 |
// Internal type for indexing the queue; also used for the tag. |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
28 |
typedef NOT_LP64(uint16_t) LP64_ONLY(uint32_t) idx_t; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
29 |
|
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
30 |
// The first free element after the last one pushed (mod N). |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
31 |
volatile uint _bottom; |
1 | 32 |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
33 |
enum { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
34 |
N = 1 << NOT_LP64(14) LP64_ONLY(17), // Queue size: 16K or 128K |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
35 |
MOD_N_MASK = N - 1 // To compute x mod N efficiently. |
1 | 36 |
}; |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
37 |
|
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
38 |
class Age { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
39 |
public: |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
40 |
Age(size_t data = 0) { _data = data; } |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
41 |
Age(const Age& age) { _data = age._data; } |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
42 |
Age(idx_t top, idx_t tag) { _fields._top = top; _fields._tag = tag; } |
1 | 43 |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
44 |
Age get() const volatile { return _data; } |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
45 |
void set(Age age) volatile { _data = age._data; } |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
46 |
|
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
47 |
idx_t top() const volatile { return _fields._top; } |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
48 |
idx_t tag() const volatile { return _fields._tag; } |
1 | 49 |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
50 |
// Increment top; if it wraps, increment tag also. |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
51 |
void increment() { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
52 |
_fields._top = increment_index(_fields._top); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
53 |
if (_fields._top == 0) ++_fields._tag; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
54 |
} |
1 | 55 |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
56 |
Age cmpxchg(const Age new_age, const Age old_age) volatile { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
57 |
return (size_t) Atomic::cmpxchg_ptr((intptr_t)new_age._data, |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
58 |
(volatile intptr_t *)&_data, |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
59 |
(intptr_t)old_age._data); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
60 |
} |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
61 |
|
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
62 |
bool operator ==(const Age& other) const { return _data == other._data; } |
1 | 63 |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
64 |
private: |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
65 |
struct fields { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
66 |
idx_t _top; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
67 |
idx_t _tag; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
68 |
}; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
69 |
union { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
70 |
size_t _data; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
71 |
fields _fields; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
72 |
}; |
1 | 73 |
}; |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
74 |
|
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
75 |
volatile Age _age; |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
76 |
|
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
77 |
// These both operate mod N. |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
78 |
static uint increment_index(uint ind) { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
79 |
return (ind + 1) & MOD_N_MASK; |
1 | 80 |
} |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
81 |
static uint decrement_index(uint ind) { |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
82 |
return (ind - 1) & MOD_N_MASK; |
1 | 83 |
} |
84 |
||
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
85 |
// Returns a number in the range [0..N). If the result is "N-1", it should be |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
86 |
// interpreted as 0. |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
87 |
uint dirty_size(uint bot, uint top) { |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
88 |
return (bot - top) & MOD_N_MASK; |
1 | 89 |
} |
90 |
||
91 |
// Returns the size corresponding to the given "bot" and "top". |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
92 |
uint size(uint bot, uint top) { |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
93 |
uint sz = dirty_size(bot, top); |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
94 |
// Has the queue "wrapped", so that bottom is less than top? There's a |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
95 |
// complicated special case here. A pair of threads could perform pop_local |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
96 |
// and pop_global operations concurrently, starting from a state in which |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
97 |
// _bottom == _top+1. The pop_local could succeed in decrementing _bottom, |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
98 |
// and the pop_global in incrementing _top (in which case the pop_global |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
99 |
// will be awarded the contested queue element.) The resulting state must |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
100 |
// be interpreted as an empty queue. (We only need to worry about one such |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
101 |
// event: only the queue owner performs pop_local's, and several concurrent |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
102 |
// threads attempting to perform the pop_global will all perform the same |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
103 |
// CAS, and only one can succeed.) Any stealing thread that reads after |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
104 |
// either the increment or decrement will see an empty queue, and will not |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
105 |
// join the competitors. The "sz == -1 || sz == N-1" state will not be |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
106 |
// modified by concurrent queues, so the owner thread can reset the state to |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
107 |
// _bottom == top so subsequent pushes will be performed normally. |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
108 |
return (sz == N - 1) ? 0 : sz; |
1 | 109 |
} |
110 |
||
111 |
public: |
|
112 |
TaskQueueSuper() : _bottom(0), _age() {} |
|
113 |
||
114 |
// Return "true" if the TaskQueue contains any tasks. |
|
115 |
bool peek(); |
|
116 |
||
117 |
// Return an estimate of the number of elements in the queue. |
|
118 |
// The "careful" version admits the possibility of pop_local/pop_global |
|
119 |
// races. |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
120 |
uint size() { |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
121 |
return size(_bottom, _age.top()); |
1 | 122 |
} |
123 |
||
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
124 |
uint dirty_size() { |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
125 |
return dirty_size(_bottom, _age.top()); |
1 | 126 |
} |
127 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
128 |
void set_empty() { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
129 |
_bottom = 0; |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
130 |
_age.set(0); |
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
131 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
132 |
|
1 | 133 |
// Maximum number of elements allowed in the queue. This is two less |
134 |
// than the actual queue size, for somewhat complicated reasons. |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
135 |
uint max_elems() { return N - 2; } |
1 | 136 |
}; |
137 |
||
138 |
template<class E> class GenericTaskQueue: public TaskQueueSuper { |
|
139 |
private: |
|
140 |
// Slow paths for push, pop_local. (pop_global has no fast path.) |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
141 |
bool push_slow(E t, uint dirty_n_elems); |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
142 |
bool pop_local_slow(uint localBot, Age oldAge); |
1 | 143 |
|
144 |
public: |
|
145 |
// Initializes the queue to empty. |
|
146 |
GenericTaskQueue(); |
|
147 |
||
148 |
void initialize(); |
|
149 |
||
150 |
// Push the task "t" on the queue. Returns "false" iff the queue is |
|
151 |
// full. |
|
152 |
inline bool push(E t); |
|
153 |
||
154 |
// If succeeds in claiming a task (from the 'local' end, that is, the |
|
155 |
// most recently pushed task), returns "true" and sets "t" to that task. |
|
156 |
// Otherwise, the queue is empty and returns false. |
|
157 |
inline bool pop_local(E& t); |
|
158 |
||
159 |
// If succeeds in claiming a task (from the 'global' end, that is, the |
|
160 |
// least recently pushed task), returns "true" and sets "t" to that task. |
|
161 |
// Otherwise, the queue is empty and returns false. |
|
162 |
bool pop_global(E& t); |
|
163 |
||
164 |
// Delete any resource associated with the queue. |
|
165 |
~GenericTaskQueue(); |
|
166 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
167 |
// apply the closure to all elements in the task queue |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
168 |
void oops_do(OopClosure* f); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
169 |
|
1 | 170 |
private: |
171 |
// Element array. |
|
172 |
volatile E* _elems; |
|
173 |
}; |
|
174 |
||
175 |
template<class E> |
|
176 |
GenericTaskQueue<E>::GenericTaskQueue():TaskQueueSuper() { |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
177 |
assert(sizeof(Age) == sizeof(size_t), "Depends on this."); |
1 | 178 |
} |
179 |
||
180 |
template<class E> |
|
181 |
void GenericTaskQueue<E>::initialize() { |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
182 |
_elems = NEW_C_HEAP_ARRAY(E, N); |
1 | 183 |
guarantee(_elems != NULL, "Allocation failed."); |
184 |
} |
|
185 |
||
186 |
template<class E> |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
187 |
void GenericTaskQueue<E>::oops_do(OopClosure* f) { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
188 |
// tty->print_cr("START OopTaskQueue::oops_do"); |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
189 |
uint iters = size(); |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
190 |
uint index = _bottom; |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
191 |
for (uint i = 0; i < iters; ++i) { |
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
192 |
index = decrement_index(index); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
193 |
// tty->print_cr(" doing entry %d," INTPTR_T " -> " INTPTR_T, |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
194 |
// index, &_elems[index], _elems[index]); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
195 |
E* t = (E*)&_elems[index]; // cast away volatility |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
196 |
oop* p = (oop*)t; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
197 |
assert((*t)->is_oop_or_null(), "Not an oop or null"); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
198 |
f->do_oop(p); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
199 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
200 |
// tty->print_cr("END OopTaskQueue::oops_do"); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
201 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
202 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
203 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
204 |
template<class E> |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
205 |
bool GenericTaskQueue<E>::push_slow(E t, uint dirty_n_elems) { |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
206 |
if (dirty_n_elems == N - 1) { |
1 | 207 |
// Actually means 0, so do the push. |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
208 |
uint localBot = _bottom; |
1 | 209 |
_elems[localBot] = t; |
210 |
_bottom = increment_index(localBot); |
|
211 |
return true; |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
212 |
} |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
213 |
return false; |
1 | 214 |
} |
215 |
||
216 |
template<class E> |
|
217 |
bool GenericTaskQueue<E>:: |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
218 |
pop_local_slow(uint localBot, Age oldAge) { |
1 | 219 |
// This queue was observed to contain exactly one element; either this |
220 |
// thread will claim it, or a competing "pop_global". In either case, |
|
221 |
// the queue will be logically empty afterwards. Create a new Age value |
|
222 |
// that represents the empty queue for the given value of "_bottom". (We |
|
223 |
// must also increment "tag" because of the case where "bottom == 1", |
|
224 |
// "top == 0". A pop_global could read the queue element in that case, |
|
225 |
// then have the owner thread do a pop followed by another push. Without |
|
226 |
// the incrementing of "tag", the pop_global's CAS could succeed, |
|
227 |
// allowing it to believe it has claimed the stale element.) |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
228 |
Age newAge((idx_t)localBot, oldAge.tag() + 1); |
1 | 229 |
// Perhaps a competing pop_global has already incremented "top", in which |
230 |
// case it wins the element. |
|
231 |
if (localBot == oldAge.top()) { |
|
232 |
// No competing pop_global has yet incremented "top"; we'll try to |
|
233 |
// install new_age, thus claiming the element. |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
234 |
Age tempAge = _age.cmpxchg(newAge, oldAge); |
1 | 235 |
if (tempAge == oldAge) { |
236 |
// We win. |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
237 |
assert(dirty_size(localBot, _age.top()) != N - 1, "sanity"); |
1 | 238 |
return true; |
239 |
} |
|
240 |
} |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
241 |
// We lose; a completing pop_global gets the element. But the queue is empty |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
242 |
// and top is greater than bottom. Fix this representation of the empty queue |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
243 |
// to become the canonical one. |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
244 |
_age.set(newAge); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
245 |
assert(dirty_size(localBot, _age.top()) != N - 1, "sanity"); |
1 | 246 |
return false; |
247 |
} |
|
248 |
||
249 |
template<class E> |
|
250 |
bool GenericTaskQueue<E>::pop_global(E& t) { |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
251 |
Age oldAge = _age.get(); |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
252 |
uint localBot = _bottom; |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
253 |
uint n_elems = size(localBot, oldAge.top()); |
1 | 254 |
if (n_elems == 0) { |
255 |
return false; |
|
256 |
} |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
257 |
|
1 | 258 |
t = _elems[oldAge.top()]; |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
259 |
Age newAge(oldAge); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
260 |
newAge.increment(); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
261 |
Age resAge = _age.cmpxchg(newAge, oldAge); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
262 |
|
1 | 263 |
// Note that using "_bottom" here might fail, since a pop_local might |
264 |
// have decremented it. |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
265 |
assert(dirty_size(localBot, newAge.top()) != N - 1, "sanity"); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
266 |
return resAge == oldAge; |
1 | 267 |
} |
268 |
||
269 |
template<class E> |
|
270 |
GenericTaskQueue<E>::~GenericTaskQueue() { |
|
271 |
FREE_C_HEAP_ARRAY(E, _elems); |
|
272 |
} |
|
273 |
||
274 |
// Inherits the typedef of "Task" from above. |
|
275 |
class TaskQueueSetSuper: public CHeapObj { |
|
276 |
protected: |
|
277 |
static int randomParkAndMiller(int* seed0); |
|
278 |
public: |
|
279 |
// Returns "true" if some TaskQueue in the set contains a task. |
|
280 |
virtual bool peek() = 0; |
|
281 |
}; |
|
282 |
||
283 |
template<class E> class GenericTaskQueueSet: public TaskQueueSetSuper { |
|
284 |
private: |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
285 |
uint _n; |
1 | 286 |
GenericTaskQueue<E>** _queues; |
287 |
||
288 |
public: |
|
289 |
GenericTaskQueueSet(int n) : _n(n) { |
|
290 |
typedef GenericTaskQueue<E>* GenericTaskQueuePtr; |
|
291 |
_queues = NEW_C_HEAP_ARRAY(GenericTaskQueuePtr, n); |
|
292 |
guarantee(_queues != NULL, "Allocation failure."); |
|
293 |
for (int i = 0; i < n; i++) { |
|
294 |
_queues[i] = NULL; |
|
295 |
} |
|
296 |
} |
|
297 |
||
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
298 |
bool steal_1_random(uint queue_num, int* seed, E& t); |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
299 |
bool steal_best_of_2(uint queue_num, int* seed, E& t); |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
300 |
bool steal_best_of_all(uint queue_num, int* seed, E& t); |
1 | 301 |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
302 |
void register_queue(uint i, GenericTaskQueue<E>* q); |
1 | 303 |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
304 |
GenericTaskQueue<E>* queue(uint n); |
1 | 305 |
|
306 |
// The thread with queue number "queue_num" (and whose random number seed |
|
307 |
// is at "seed") is trying to steal a task from some other queue. (It |
|
308 |
// may try several queues, according to some configuration parameter.) |
|
309 |
// If some steal succeeds, returns "true" and sets "t" the stolen task, |
|
310 |
// otherwise returns false. |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
311 |
bool steal(uint queue_num, int* seed, E& t); |
1 | 312 |
|
313 |
bool peek(); |
|
314 |
}; |
|
315 |
||
316 |
template<class E> |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
317 |
void GenericTaskQueueSet<E>::register_queue(uint i, GenericTaskQueue<E>* q) { |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
318 |
assert(i < _n, "index out of range."); |
1 | 319 |
_queues[i] = q; |
320 |
} |
|
321 |
||
322 |
template<class E> |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
323 |
GenericTaskQueue<E>* GenericTaskQueueSet<E>::queue(uint i) { |
1 | 324 |
return _queues[i]; |
325 |
} |
|
326 |
||
327 |
template<class E> |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
328 |
bool GenericTaskQueueSet<E>::steal(uint queue_num, int* seed, E& t) { |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
329 |
for (uint i = 0; i < 2 * _n; i++) |
1 | 330 |
if (steal_best_of_2(queue_num, seed, t)) |
331 |
return true; |
|
332 |
return false; |
|
333 |
} |
|
334 |
||
335 |
template<class E> |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
336 |
bool GenericTaskQueueSet<E>::steal_best_of_all(uint queue_num, int* seed, E& t) { |
1 | 337 |
if (_n > 2) { |
338 |
int best_k; |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
339 |
uint best_sz = 0; |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
340 |
for (uint k = 0; k < _n; k++) { |
1 | 341 |
if (k == queue_num) continue; |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
342 |
uint sz = _queues[k]->size(); |
1 | 343 |
if (sz > best_sz) { |
344 |
best_sz = sz; |
|
345 |
best_k = k; |
|
346 |
} |
|
347 |
} |
|
348 |
return best_sz > 0 && _queues[best_k]->pop_global(t); |
|
349 |
} else if (_n == 2) { |
|
350 |
// Just try the other one. |
|
351 |
int k = (queue_num + 1) % 2; |
|
352 |
return _queues[k]->pop_global(t); |
|
353 |
} else { |
|
354 |
assert(_n == 1, "can't be zero."); |
|
355 |
return false; |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
template<class E> |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
360 |
bool GenericTaskQueueSet<E>::steal_1_random(uint queue_num, int* seed, E& t) { |
1 | 361 |
if (_n > 2) { |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
362 |
uint k = queue_num; |
1 | 363 |
while (k == queue_num) k = randomParkAndMiller(seed) % _n; |
364 |
return _queues[2]->pop_global(t); |
|
365 |
} else if (_n == 2) { |
|
366 |
// Just try the other one. |
|
367 |
int k = (queue_num + 1) % 2; |
|
368 |
return _queues[k]->pop_global(t); |
|
369 |
} else { |
|
370 |
assert(_n == 1, "can't be zero."); |
|
371 |
return false; |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
template<class E> |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
376 |
bool GenericTaskQueueSet<E>::steal_best_of_2(uint queue_num, int* seed, E& t) { |
1 | 377 |
if (_n > 2) { |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
378 |
uint k1 = queue_num; |
1 | 379 |
while (k1 == queue_num) k1 = randomParkAndMiller(seed) % _n; |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
380 |
uint k2 = queue_num; |
1 | 381 |
while (k2 == queue_num || k2 == k1) k2 = randomParkAndMiller(seed) % _n; |
382 |
// Sample both and try the larger. |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
383 |
uint sz1 = _queues[k1]->size(); |
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
384 |
uint sz2 = _queues[k2]->size(); |
1 | 385 |
if (sz2 > sz1) return _queues[k2]->pop_global(t); |
386 |
else return _queues[k1]->pop_global(t); |
|
387 |
} else if (_n == 2) { |
|
388 |
// Just try the other one. |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
389 |
uint k = (queue_num + 1) % 2; |
1 | 390 |
return _queues[k]->pop_global(t); |
391 |
} else { |
|
392 |
assert(_n == 1, "can't be zero."); |
|
393 |
return false; |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
template<class E> |
|
398 |
bool GenericTaskQueueSet<E>::peek() { |
|
399 |
// Try all the queues. |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
400 |
for (uint j = 0; j < _n; j++) { |
1 | 401 |
if (_queues[j]->peek()) |
402 |
return true; |
|
403 |
} |
|
404 |
return false; |
|
405 |
} |
|
406 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
407 |
// When to terminate from the termination protocol. |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
408 |
class TerminatorTerminator: public CHeapObj { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
409 |
public: |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
410 |
virtual bool should_exit_termination() = 0; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
411 |
}; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
412 |
|
1 | 413 |
// A class to aid in the termination of a set of parallel tasks using |
414 |
// TaskQueueSet's for work stealing. |
|
415 |
||
2010
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
416 |
#undef TRACESPINNING |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
417 |
|
1 | 418 |
class ParallelTaskTerminator: public StackObj { |
419 |
private: |
|
420 |
int _n_threads; |
|
421 |
TaskQueueSetSuper* _queue_set; |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
422 |
int _offered_termination; |
1 | 423 |
|
2010
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
424 |
#ifdef TRACESPINNING |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
425 |
static uint _total_yields; |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
426 |
static uint _total_spins; |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
427 |
static uint _total_peeks; |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
428 |
#endif |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
429 |
|
1 | 430 |
bool peek_in_queue_set(); |
431 |
protected: |
|
432 |
virtual void yield(); |
|
433 |
void sleep(uint millis); |
|
434 |
||
435 |
public: |
|
436 |
||
437 |
// "n_threads" is the number of threads to be terminated. "queue_set" is a |
|
438 |
// queue sets of work queues of other threads. |
|
439 |
ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set); |
|
440 |
||
441 |
// The current thread has no work, and is ready to terminate if everyone |
|
442 |
// else is. If returns "true", all threads are terminated. If returns |
|
443 |
// "false", available work has been observed in one of the task queues, |
|
444 |
// so the global task is not complete. |
|
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
445 |
bool offer_termination() { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
446 |
return offer_termination(NULL); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
447 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
448 |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
449 |
// As above, but it also terminates if the should_exit_termination() |
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
450 |
// method of the terminator parameter returns true. If terminator is |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
451 |
// NULL, then it is ignored. |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
360
diff
changeset
|
452 |
bool offer_termination(TerminatorTerminator* terminator); |
1 | 453 |
|
454 |
// Reset the terminator, so that it may be reused again. |
|
455 |
// The caller is responsible for ensuring that this is done |
|
456 |
// in an MT-safe manner, once the previous round of use of |
|
457 |
// the terminator is finished. |
|
458 |
void reset_for_reuse(); |
|
459 |
||
2010
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
460 |
#ifdef TRACESPINNING |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
461 |
static uint total_yields() { return _total_yields; } |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
462 |
static uint total_spins() { return _total_spins; } |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
463 |
static uint total_peeks() { return _total_peeks; } |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
464 |
static void print_termination_counts(); |
c13462bbad17
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
2005
diff
changeset
|
465 |
#endif |
1 | 466 |
}; |
467 |
||
468 |
#define SIMPLE_STACK 0 |
|
469 |
||
470 |
template<class E> inline bool GenericTaskQueue<E>::push(E t) { |
|
471 |
#if SIMPLE_STACK |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
472 |
uint localBot = _bottom; |
1 | 473 |
if (_bottom < max_elems()) { |
474 |
_elems[localBot] = t; |
|
475 |
_bottom = localBot + 1; |
|
476 |
return true; |
|
477 |
} else { |
|
478 |
return false; |
|
479 |
} |
|
480 |
#else |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
481 |
uint localBot = _bottom; |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
482 |
assert((localBot >= 0) && (localBot < N), "_bottom out of range."); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
483 |
idx_t top = _age.top(); |
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
484 |
uint dirty_n_elems = dirty_size(localBot, top); |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
485 |
assert((dirty_n_elems >= 0) && (dirty_n_elems < N), "n_elems out of range."); |
1 | 486 |
if (dirty_n_elems < max_elems()) { |
487 |
_elems[localBot] = t; |
|
488 |
_bottom = increment_index(localBot); |
|
489 |
return true; |
|
490 |
} else { |
|
491 |
return push_slow(t, dirty_n_elems); |
|
492 |
} |
|
493 |
#endif |
|
494 |
} |
|
495 |
||
496 |
template<class E> inline bool GenericTaskQueue<E>::pop_local(E& t) { |
|
497 |
#if SIMPLE_STACK |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
498 |
uint localBot = _bottom; |
1 | 499 |
assert(localBot > 0, "precondition."); |
500 |
localBot--; |
|
501 |
t = _elems[localBot]; |
|
502 |
_bottom = localBot; |
|
503 |
return true; |
|
504 |
#else |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
505 |
uint localBot = _bottom; |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
506 |
// This value cannot be N-1. That can only occur as a result of |
1 | 507 |
// the assignment to bottom in this method. If it does, this method |
508 |
// resets the size( to 0 before the next call (which is sequential, |
|
509 |
// since this is pop_local.) |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
510 |
uint dirty_n_elems = dirty_size(localBot, _age.top()); |
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
511 |
assert(dirty_n_elems != N - 1, "Shouldn't be possible..."); |
1 | 512 |
if (dirty_n_elems == 0) return false; |
513 |
localBot = decrement_index(localBot); |
|
514 |
_bottom = localBot; |
|
515 |
// This is necessary to prevent any read below from being reordered |
|
516 |
// before the store just above. |
|
517 |
OrderAccess::fence(); |
|
518 |
t = _elems[localBot]; |
|
519 |
// This is a second read of "age"; the "size()" above is the first. |
|
520 |
// If there's still at least one element in the queue, based on the |
|
521 |
// "_bottom" and "age" we've read, then there can be no interference with |
|
522 |
// a "pop_global" operation, and we're done. |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
523 |
idx_t tp = _age.top(); // XXX |
1 | 524 |
if (size(localBot, tp) > 0) { |
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
525 |
assert(dirty_size(localBot, tp) != N - 1, "sanity"); |
1 | 526 |
return true; |
527 |
} else { |
|
528 |
// Otherwise, the queue contained exactly one element; we take the slow |
|
529 |
// path. |
|
3607
fa62293fa65c
6821693: 64-bit TaskQueue capacity still too small
jcoomes
parents:
3262
diff
changeset
|
530 |
return pop_local_slow(localBot, _age.get()); |
1 | 531 |
} |
532 |
#endif |
|
533 |
} |
|
534 |
||
535 |
typedef oop Task; |
|
536 |
typedef GenericTaskQueue<Task> OopTaskQueue; |
|
537 |
typedef GenericTaskQueueSet<Task> OopTaskQueueSet; |
|
538 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
539 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
540 |
#define COMPRESSED_OOP_MASK 1 |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
541 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
542 |
// This is a container class for either an oop* or a narrowOop*. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
543 |
// Both are pushed onto a task queue and the consumer will test is_narrow() |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
544 |
// to determine which should be processed. |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
545 |
class StarTask { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
546 |
void* _holder; // either union oop* or narrowOop* |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
547 |
public: |
3262
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
548 |
StarTask(narrowOop* p) { |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
549 |
assert(((uintptr_t)p & COMPRESSED_OOP_MASK) == 0, "Information loss!"); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
550 |
_holder = (void *)((uintptr_t)p | COMPRESSED_OOP_MASK); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
551 |
} |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
552 |
StarTask(oop* p) { |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
553 |
assert(((uintptr_t)p & COMPRESSED_OOP_MASK) == 0, "Information loss!"); |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
554 |
_holder = (void*)p; |
30d1c247fc25
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
2105
diff
changeset
|
555 |
} |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
556 |
StarTask() { _holder = NULL; } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
557 |
operator oop*() { return (oop*)_holder; } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
558 |
operator narrowOop*() { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
559 |
return (narrowOop*)((uintptr_t)_holder & ~COMPRESSED_OOP_MASK); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
560 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
561 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
562 |
// Operators to preserve const/volatile in assignments required by gcc |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
563 |
void operator=(const volatile StarTask& t) volatile { _holder = t._holder; } |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
564 |
|
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
565 |
bool is_narrow() const { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
566 |
return (((uintptr_t)_holder & COMPRESSED_OOP_MASK) != 0); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
567 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
568 |
}; |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
569 |
|
1 | 570 |
typedef GenericTaskQueue<StarTask> OopStarTaskQueue; |
571 |
typedef GenericTaskQueueSet<StarTask> OopStarTaskQueueSet; |
|
572 |
||
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
573 |
typedef size_t RegionTask; // index for region |
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
574 |
typedef GenericTaskQueue<RegionTask> RegionTaskQueue; |
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
575 |
typedef GenericTaskQueueSet<RegionTask> RegionTaskQueueSet; |
1 | 576 |
|
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
577 |
class RegionTaskQueueWithOverflow: public CHeapObj { |
1 | 578 |
protected: |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
579 |
RegionTaskQueue _region_queue; |
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
580 |
GrowableArray<RegionTask>* _overflow_stack; |
1 | 581 |
|
582 |
public: |
|
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
583 |
RegionTaskQueueWithOverflow() : _overflow_stack(NULL) {} |
1 | 584 |
// Initialize both stealable queue and overflow |
585 |
void initialize(); |
|
586 |
// Save first to stealable queue and then to overflow |
|
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
587 |
void save(RegionTask t); |
1 | 588 |
// Retrieve first from overflow and then from stealable queue |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
589 |
bool retrieve(RegionTask& region_index); |
1 | 590 |
// Retrieve from stealable queue |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
591 |
bool retrieve_from_stealable_queue(RegionTask& region_index); |
1 | 592 |
// Retrieve from overflow |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
593 |
bool retrieve_from_overflow(RegionTask& region_index); |
1 | 594 |
bool is_empty(); |
595 |
bool stealable_is_empty(); |
|
596 |
bool overflow_is_empty(); |
|
2005
42075507972b
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
1407
diff
changeset
|
597 |
uint stealable_size() { return _region_queue.size(); } |
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
598 |
RegionTaskQueue* task_queue() { return &_region_queue; } |
1 | 599 |
}; |
600 |
||
1407
9006b01ba3fd
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
1388
diff
changeset
|
601 |
#define USE_RegionTaskQueueWithOverflow |