author | coleenp |
Wed, 06 Jun 2018 10:45:40 -0400 | |
changeset 50429 | 83aec1d357d4 |
parent 47216 | 71c04702a3d5 |
child 51332 | c25572739e7c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/parallel/gcTaskManager.hpp" |
27 |
#include "gc/parallel/gcTaskThread.hpp" |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
28 |
#include "gc/shared/gcId.hpp" |
38216 | 29 |
#include "gc/shared/workerManager.hpp" |
35061 | 30 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
40096
diff
changeset
|
31 |
#include "logging/logStream.hpp" |
7397 | 32 |
#include "memory/allocation.hpp" |
33 |
#include "memory/allocation.inline.hpp" |
|
37224
fd3320bf6413
8153186: Convert TraceGCTaskThread to use unified logging
brutisso
parents:
35061
diff
changeset
|
34 |
#include "memory/resourceArea.hpp" |
7397 | 35 |
#include "runtime/mutex.hpp" |
36 |
#include "runtime/mutexLocker.hpp" |
|
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
47216
diff
changeset
|
37 |
#include "runtime/orderAccess.hpp" |
38216 | 38 |
#include "runtime/os.hpp" |
1 | 39 |
|
40 |
// |
|
41 |
// GCTask |
|
42 |
// |
|
43 |
||
44 |
const char* GCTask::Kind::to_string(kind value) { |
|
45 |
const char* result = "unknown GCTask kind"; |
|
46 |
switch (value) { |
|
47 |
default: |
|
48 |
result = "unknown GCTask kind"; |
|
49 |
break; |
|
50 |
case unknown_task: |
|
51 |
result = "unknown task"; |
|
52 |
break; |
|
53 |
case ordinary_task: |
|
54 |
result = "ordinary task"; |
|
55 |
break; |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
56 |
case wait_for_barrier_task: |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
57 |
result = "wait for barrier task"; |
1 | 58 |
break; |
59 |
case noop_task: |
|
60 |
result = "noop task"; |
|
61 |
break; |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
62 |
case idle_task: |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
63 |
result = "idle task"; |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
64 |
break; |
1 | 65 |
} |
66 |
return result; |
|
67 |
}; |
|
68 |
||
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
69 |
GCTask::GCTask() { |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
70 |
initialize(Kind::ordinary_task, GCId::current()); |
1 | 71 |
} |
72 |
||
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
73 |
GCTask::GCTask(Kind::kind kind) { |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
74 |
initialize(kind, GCId::current()); |
1 | 75 |
} |
76 |
||
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
77 |
GCTask::GCTask(Kind::kind kind, uint gc_id) { |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
78 |
initialize(kind, gc_id); |
1 | 79 |
} |
80 |
||
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
81 |
void GCTask::initialize(Kind::kind kind, uint gc_id) { |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
82 |
_kind = kind; |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
83 |
_affinity = GCTaskManager::sentinel_worker(); |
1 | 84 |
_older = NULL; |
85 |
_newer = NULL; |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
86 |
_gc_id = gc_id; |
1 | 87 |
} |
88 |
||
89 |
void GCTask::destruct() { |
|
90 |
assert(older() == NULL, "shouldn't have an older task"); |
|
91 |
assert(newer() == NULL, "shouldn't have a newer task"); |
|
92 |
// Nothing to do. |
|
93 |
} |
|
94 |
||
95 |
NOT_PRODUCT( |
|
96 |
void GCTask::print(const char* message) const { |
|
97 |
tty->print(INTPTR_FORMAT " <- " INTPTR_FORMAT "(%u) -> " INTPTR_FORMAT, |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
98 |
p2i(newer()), p2i(this), affinity(), p2i(older())); |
1 | 99 |
} |
100 |
) |
|
101 |
||
102 |
// |
|
103 |
// GCTaskQueue |
|
104 |
// |
|
105 |
||
106 |
GCTaskQueue* GCTaskQueue::create() { |
|
107 |
GCTaskQueue* result = new GCTaskQueue(false); |
|
108 |
if (TraceGCTaskQueue) { |
|
109 |
tty->print_cr("GCTaskQueue::create()" |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
110 |
" returns " INTPTR_FORMAT, p2i(result)); |
1 | 111 |
} |
112 |
return result; |
|
113 |
} |
|
114 |
||
115 |
GCTaskQueue* GCTaskQueue::create_on_c_heap() { |
|
13195 | 116 |
GCTaskQueue* result = new(ResourceObj::C_HEAP, mtGC) GCTaskQueue(true); |
1 | 117 |
if (TraceGCTaskQueue) { |
118 |
tty->print_cr("GCTaskQueue::create_on_c_heap()" |
|
119 |
" returns " INTPTR_FORMAT, |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
120 |
p2i(result)); |
1 | 121 |
} |
122 |
return result; |
|
123 |
} |
|
124 |
||
125 |
GCTaskQueue::GCTaskQueue(bool on_c_heap) : |
|
126 |
_is_c_heap_obj(on_c_heap) { |
|
127 |
initialize(); |
|
128 |
if (TraceGCTaskQueue) { |
|
129 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
130 |
" GCTaskQueue::GCTaskQueue() constructor", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
131 |
p2i(this)); |
1 | 132 |
} |
133 |
} |
|
134 |
||
135 |
void GCTaskQueue::destruct() { |
|
136 |
// Nothing to do. |
|
137 |
} |
|
138 |
||
139 |
void GCTaskQueue::destroy(GCTaskQueue* that) { |
|
140 |
if (TraceGCTaskQueue) { |
|
141 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
142 |
" GCTaskQueue::destroy()" |
|
143 |
" is_c_heap_obj: %s", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
144 |
p2i(that), |
1 | 145 |
that->is_c_heap_obj() ? "true" : "false"); |
146 |
} |
|
147 |
// That instance may have been allocated as a CHeapObj, |
|
148 |
// in which case we have to free it explicitly. |
|
149 |
if (that != NULL) { |
|
150 |
that->destruct(); |
|
151 |
assert(that->is_empty(), "should be empty"); |
|
152 |
if (that->is_c_heap_obj()) { |
|
153 |
FreeHeap(that); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
||
158 |
void GCTaskQueue::initialize() { |
|
159 |
set_insert_end(NULL); |
|
160 |
set_remove_end(NULL); |
|
161 |
set_length(0); |
|
162 |
} |
|
163 |
||
164 |
// Enqueue one task. |
|
165 |
void GCTaskQueue::enqueue(GCTask* task) { |
|
166 |
if (TraceGCTaskQueue) { |
|
167 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
168 |
" GCTaskQueue::enqueue(task: " |
|
169 |
INTPTR_FORMAT ")", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
170 |
p2i(this), p2i(task)); |
1 | 171 |
print("before:"); |
172 |
} |
|
173 |
assert(task != NULL, "shouldn't have null task"); |
|
174 |
assert(task->older() == NULL, "shouldn't be on queue"); |
|
175 |
assert(task->newer() == NULL, "shouldn't be on queue"); |
|
176 |
task->set_newer(NULL); |
|
177 |
task->set_older(insert_end()); |
|
178 |
if (is_empty()) { |
|
179 |
set_remove_end(task); |
|
180 |
} else { |
|
181 |
insert_end()->set_newer(task); |
|
182 |
} |
|
183 |
set_insert_end(task); |
|
184 |
increment_length(); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
185 |
verify_length(); |
1 | 186 |
if (TraceGCTaskQueue) { |
187 |
print("after:"); |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
// Enqueue a whole list of tasks. Empties the argument list. |
|
192 |
void GCTaskQueue::enqueue(GCTaskQueue* list) { |
|
193 |
if (TraceGCTaskQueue) { |
|
194 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
195 |
" GCTaskQueue::enqueue(list: " |
|
196 |
INTPTR_FORMAT ")", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
197 |
p2i(this), p2i(list)); |
1 | 198 |
print("before:"); |
199 |
list->print("list:"); |
|
200 |
} |
|
201 |
if (list->is_empty()) { |
|
22551 | 202 |
// Enqueueing the empty list: nothing to do. |
1 | 203 |
return; |
204 |
} |
|
205 |
uint list_length = list->length(); |
|
206 |
if (is_empty()) { |
|
22551 | 207 |
// Enqueueing to empty list: just acquire elements. |
1 | 208 |
set_insert_end(list->insert_end()); |
209 |
set_remove_end(list->remove_end()); |
|
210 |
set_length(list_length); |
|
211 |
} else { |
|
212 |
// Prepend argument list to our queue. |
|
213 |
list->remove_end()->set_older(insert_end()); |
|
214 |
insert_end()->set_newer(list->remove_end()); |
|
215 |
set_insert_end(list->insert_end()); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
216 |
set_length(length() + list_length); |
1 | 217 |
// empty the argument list. |
218 |
} |
|
219 |
list->initialize(); |
|
220 |
if (TraceGCTaskQueue) { |
|
221 |
print("after:"); |
|
222 |
list->print("list:"); |
|
223 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
224 |
verify_length(); |
1 | 225 |
} |
226 |
||
227 |
// Dequeue one task. |
|
228 |
GCTask* GCTaskQueue::dequeue() { |
|
229 |
if (TraceGCTaskQueue) { |
|
230 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
231 |
" GCTaskQueue::dequeue()", p2i(this)); |
1 | 232 |
print("before:"); |
233 |
} |
|
234 |
assert(!is_empty(), "shouldn't dequeue from empty list"); |
|
235 |
GCTask* result = remove(); |
|
236 |
assert(result != NULL, "shouldn't have NULL task"); |
|
237 |
if (TraceGCTaskQueue) { |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
238 |
tty->print_cr(" return: " INTPTR_FORMAT, p2i(result)); |
1 | 239 |
print("after:"); |
240 |
} |
|
241 |
return result; |
|
242 |
} |
|
243 |
||
244 |
// Dequeue one task, preferring one with affinity. |
|
245 |
GCTask* GCTaskQueue::dequeue(uint affinity) { |
|
246 |
if (TraceGCTaskQueue) { |
|
247 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
248 |
" GCTaskQueue::dequeue(%u)", p2i(this), affinity); |
1 | 249 |
print("before:"); |
250 |
} |
|
251 |
assert(!is_empty(), "shouldn't dequeue from empty list"); |
|
252 |
// Look down to the next barrier for a task with this affinity. |
|
253 |
GCTask* result = NULL; |
|
254 |
for (GCTask* element = remove_end(); |
|
255 |
element != NULL; |
|
256 |
element = element->newer()) { |
|
257 |
if (element->is_barrier_task()) { |
|
258 |
// Don't consider barrier tasks, nor past them. |
|
259 |
result = NULL; |
|
260 |
break; |
|
261 |
} |
|
262 |
if (element->affinity() == affinity) { |
|
263 |
result = remove(element); |
|
264 |
break; |
|
265 |
} |
|
266 |
} |
|
267 |
// If we didn't find anything with affinity, just take the next task. |
|
268 |
if (result == NULL) { |
|
269 |
result = remove(); |
|
270 |
} |
|
271 |
if (TraceGCTaskQueue) { |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
272 |
tty->print_cr(" return: " INTPTR_FORMAT, p2i(result)); |
1 | 273 |
print("after:"); |
274 |
} |
|
275 |
return result; |
|
276 |
} |
|
277 |
||
278 |
GCTask* GCTaskQueue::remove() { |
|
279 |
// Dequeue from remove end. |
|
280 |
GCTask* result = remove_end(); |
|
281 |
assert(result != NULL, "shouldn't have null task"); |
|
282 |
assert(result->older() == NULL, "not the remove_end"); |
|
283 |
set_remove_end(result->newer()); |
|
284 |
if (remove_end() == NULL) { |
|
285 |
assert(insert_end() == result, "not a singleton"); |
|
286 |
set_insert_end(NULL); |
|
287 |
} else { |
|
288 |
remove_end()->set_older(NULL); |
|
289 |
} |
|
290 |
result->set_newer(NULL); |
|
291 |
decrement_length(); |
|
292 |
assert(result->newer() == NULL, "shouldn't be on queue"); |
|
293 |
assert(result->older() == NULL, "shouldn't be on queue"); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
294 |
verify_length(); |
1 | 295 |
return result; |
296 |
} |
|
297 |
||
298 |
GCTask* GCTaskQueue::remove(GCTask* task) { |
|
299 |
// This is slightly more work, and has slightly fewer asserts |
|
300 |
// than removing from the remove end. |
|
301 |
assert(task != NULL, "shouldn't have null task"); |
|
302 |
GCTask* result = task; |
|
303 |
if (result->newer() != NULL) { |
|
304 |
result->newer()->set_older(result->older()); |
|
305 |
} else { |
|
306 |
assert(insert_end() == result, "not youngest"); |
|
307 |
set_insert_end(result->older()); |
|
308 |
} |
|
309 |
if (result->older() != NULL) { |
|
310 |
result->older()->set_newer(result->newer()); |
|
311 |
} else { |
|
312 |
assert(remove_end() == result, "not oldest"); |
|
313 |
set_remove_end(result->newer()); |
|
314 |
} |
|
315 |
result->set_newer(NULL); |
|
316 |
result->set_older(NULL); |
|
317 |
decrement_length(); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
318 |
verify_length(); |
1 | 319 |
return result; |
320 |
} |
|
321 |
||
322 |
NOT_PRODUCT( |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
323 |
// Count the elements in the queue and verify the length against |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
324 |
// that count. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
325 |
void GCTaskQueue::verify_length() const { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
326 |
uint count = 0; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
327 |
for (GCTask* element = insert_end(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
328 |
element != NULL; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
329 |
element = element->older()) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
330 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
331 |
count++; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
332 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
333 |
assert(count == length(), "Length does not match queue"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
334 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
335 |
|
1 | 336 |
void GCTaskQueue::print(const char* message) const { |
337 |
tty->print_cr("[" INTPTR_FORMAT "] GCTaskQueue:" |
|
338 |
" insert_end: " INTPTR_FORMAT |
|
339 |
" remove_end: " INTPTR_FORMAT |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
340 |
" length: %d" |
1 | 341 |
" %s", |
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
342 |
p2i(this), p2i(insert_end()), p2i(remove_end()), length(), message); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
343 |
uint count = 0; |
1 | 344 |
for (GCTask* element = insert_end(); |
345 |
element != NULL; |
|
346 |
element = element->older()) { |
|
347 |
element->print(" "); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
348 |
count++; |
1 | 349 |
tty->cr(); |
350 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
351 |
tty->print("Total tasks: %d", count); |
1 | 352 |
} |
353 |
) |
|
354 |
||
355 |
// |
|
356 |
// SynchronizedGCTaskQueue |
|
357 |
// |
|
358 |
||
359 |
SynchronizedGCTaskQueue::SynchronizedGCTaskQueue(GCTaskQueue* queue_arg, |
|
360 |
Monitor * lock_arg) : |
|
361 |
_unsynchronized_queue(queue_arg), |
|
362 |
_lock(lock_arg) { |
|
363 |
assert(unsynchronized_queue() != NULL, "null queue"); |
|
364 |
assert(lock() != NULL, "null lock"); |
|
365 |
} |
|
366 |
||
367 |
SynchronizedGCTaskQueue::~SynchronizedGCTaskQueue() { |
|
368 |
// Nothing to do. |
|
369 |
} |
|
370 |
||
371 |
// |
|
372 |
// GCTaskManager |
|
373 |
// |
|
374 |
GCTaskManager::GCTaskManager(uint workers) : |
|
375 |
_workers(workers), |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
376 |
_active_workers(0), |
38216 | 377 |
_idle_workers(0), |
378 |
_created_workers(0) { |
|
1 | 379 |
initialize(); |
380 |
} |
|
381 |
||
38216 | 382 |
GCTaskThread* GCTaskManager::install_worker(uint t) { |
383 |
GCTaskThread* new_worker = GCTaskThread::create(this, t, _processor_assignment[t]); |
|
384 |
set_thread(t, new_worker); |
|
385 |
return new_worker; |
|
386 |
} |
|
387 |
||
388 |
void GCTaskManager::add_workers(bool initializing) { |
|
389 |
os::ThreadType worker_type = os::pgc_thread; |
|
39704 | 390 |
uint previous_created_workers = _created_workers; |
391 |
||
38216 | 392 |
_created_workers = WorkerManager::add_workers(this, |
393 |
_active_workers, |
|
39704 | 394 |
_workers, |
38216 | 395 |
_created_workers, |
396 |
worker_type, |
|
397 |
initializing); |
|
398 |
_active_workers = MIN2(_created_workers, _active_workers); |
|
39704 | 399 |
|
400 |
WorkerManager::log_worker_creation(this, previous_created_workers, _active_workers, _created_workers, initializing); |
|
401 |
} |
|
402 |
||
403 |
const char* GCTaskManager::group_name() { |
|
404 |
return "ParGC Thread"; |
|
38216 | 405 |
} |
406 |
||
1 | 407 |
void GCTaskManager::initialize() { |
408 |
if (TraceGCTaskManager) { |
|
409 |
tty->print_cr("GCTaskManager::initialize: workers: %u", workers()); |
|
410 |
} |
|
411 |
assert(workers() != 0, "no workers"); |
|
412 |
_monitor = new Monitor(Mutex::barrier, // rank |
|
413 |
"GCTaskManager monitor", // name |
|
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
414 |
Mutex::_allow_vm_block_flag, // allow_vm_block |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
415 |
Monitor::_safepoint_check_never); |
1 | 416 |
// The queue for the GCTaskManager must be a CHeapObj. |
417 |
GCTaskQueue* unsynchronized_queue = GCTaskQueue::create_on_c_heap(); |
|
418 |
_queue = SynchronizedGCTaskQueue::create(unsynchronized_queue, lock()); |
|
419 |
_noop_task = NoopGCTask::create_on_c_heap(); |
|
13195 | 420 |
_resource_flag = NEW_C_HEAP_ARRAY(bool, workers(), mtGC); |
1 | 421 |
{ |
422 |
// Set up worker threads. |
|
423 |
// Distribute the workers among the available processors, |
|
424 |
// unless we were told not to, or if the os doesn't want to. |
|
38216 | 425 |
_processor_assignment = NEW_C_HEAP_ARRAY(uint, workers(), mtGC); |
1 | 426 |
if (!BindGCTaskThreadsToCPUs || |
38216 | 427 |
!os::distribute_processes(workers(), _processor_assignment)) { |
1 | 428 |
for (uint a = 0; a < workers(); a += 1) { |
38216 | 429 |
_processor_assignment[a] = sentinel_worker(); |
1 | 430 |
} |
431 |
} |
|
38216 | 432 |
|
13195 | 433 |
_thread = NEW_C_HEAP_ARRAY(GCTaskThread*, workers(), mtGC); |
38216 | 434 |
_active_workers = ParallelGCThreads; |
435 |
if (UseDynamicNumberOfGCThreads && !FLAG_IS_CMDLINE(ParallelGCThreads)) { |
|
436 |
_active_workers = 1U; |
|
1 | 437 |
} |
38216 | 438 |
|
37242 | 439 |
Log(gc, task, thread) log; |
37224
fd3320bf6413
8153186: Convert TraceGCTaskThread to use unified logging
brutisso
parents:
35061
diff
changeset
|
440 |
if (log.is_trace()) { |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
40096
diff
changeset
|
441 |
LogStream ls(log.trace()); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
40096
diff
changeset
|
442 |
ls.print("GCTaskManager::initialize: distribution:"); |
1 | 443 |
for (uint t = 0; t < workers(); t += 1) { |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
40096
diff
changeset
|
444 |
ls.print(" %u", _processor_assignment[t]); |
1 | 445 |
} |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
40096
diff
changeset
|
446 |
ls.cr(); |
1 | 447 |
} |
448 |
} |
|
449 |
reset_busy_workers(); |
|
450 |
set_unblocked(); |
|
451 |
for (uint w = 0; w < workers(); w += 1) { |
|
452 |
set_resource_flag(w, false); |
|
453 |
} |
|
454 |
reset_delivered_tasks(); |
|
455 |
reset_completed_tasks(); |
|
456 |
reset_barriers(); |
|
457 |
reset_emptied_queue(); |
|
38216 | 458 |
|
459 |
add_workers(true); |
|
1 | 460 |
} |
461 |
||
462 |
GCTaskManager::~GCTaskManager() { |
|
463 |
assert(busy_workers() == 0, "still have busy workers"); |
|
464 |
assert(queue()->is_empty(), "still have queued work"); |
|
465 |
NoopGCTask::destroy(_noop_task); |
|
466 |
_noop_task = NULL; |
|
467 |
if (_thread != NULL) { |
|
38216 | 468 |
for (uint i = 0; i < created_workers(); i += 1) { |
1 | 469 |
GCTaskThread::destroy(thread(i)); |
470 |
set_thread(i, NULL); |
|
471 |
} |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
472 |
FREE_C_HEAP_ARRAY(GCTaskThread*, _thread); |
1 | 473 |
_thread = NULL; |
474 |
} |
|
38216 | 475 |
if (_processor_assignment != NULL) { |
476 |
FREE_C_HEAP_ARRAY(uint, _processor_assignment); |
|
477 |
_processor_assignment = NULL; |
|
478 |
} |
|
1 | 479 |
if (_resource_flag != NULL) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
480 |
FREE_C_HEAP_ARRAY(bool, _resource_flag); |
1 | 481 |
_resource_flag = NULL; |
482 |
} |
|
483 |
if (queue() != NULL) { |
|
484 |
GCTaskQueue* unsynchronized_queue = queue()->unsynchronized_queue(); |
|
485 |
GCTaskQueue::destroy(unsynchronized_queue); |
|
486 |
SynchronizedGCTaskQueue::destroy(queue()); |
|
487 |
_queue = NULL; |
|
488 |
} |
|
489 |
if (monitor() != NULL) { |
|
490 |
delete monitor(); |
|
491 |
_monitor = NULL; |
|
492 |
} |
|
493 |
} |
|
494 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
495 |
void GCTaskManager::set_active_gang() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
496 |
_active_workers = |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
497 |
AdaptiveSizePolicy::calc_active_workers(workers(), |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
498 |
active_workers(), |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
499 |
Threads::number_of_non_daemon_threads()); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
500 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
501 |
assert(!all_workers_active() || active_workers() == ParallelGCThreads, |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31330
diff
changeset
|
502 |
"all_workers_active() is incorrect: " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31330
diff
changeset
|
503 |
"active %d ParallelGCThreads %u", active_workers(), |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31330
diff
changeset
|
504 |
ParallelGCThreads); |
38216 | 505 |
_active_workers = MIN2(_active_workers, _workers); |
506 |
// "add_workers" does not guarantee any additional workers |
|
507 |
add_workers(false); |
|
35061 | 508 |
log_trace(gc, task)("GCTaskManager::set_active_gang(): " |
509 |
"all_workers_active() %d workers %d " |
|
510 |
"active %d ParallelGCThreads %u", |
|
511 |
all_workers_active(), workers(), active_workers(), |
|
512 |
ParallelGCThreads); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
513 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
514 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
515 |
// Create IdleGCTasks for inactive workers. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
516 |
// Creates tasks in a ResourceArea and assumes |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
517 |
// an appropriate ResourceMark. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
518 |
void GCTaskManager::task_idle_workers() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
519 |
{ |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
520 |
int more_inactive_workers = 0; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
521 |
{ |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
522 |
// Stop any idle tasks from exiting their IdleGCTask's |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
523 |
// and get the count for additional IdleGCTask's under |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
524 |
// the GCTaskManager's monitor so that the "more_inactive_workers" |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
525 |
// count is correct. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
526 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
33125 | 527 |
_wait_helper.set_should_wait(true); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
528 |
// active_workers are a number being requested. idle_workers |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
529 |
// are the number currently idle. If all the workers are being |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
530 |
// requested to be active but some are already idle, reduce |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
531 |
// the number of active_workers to be consistent with the |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
532 |
// number of idle_workers. The idle_workers are stuck in |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
533 |
// idle tasks and will no longer be release (since a new GC |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
534 |
// is starting). Try later to release enough idle_workers |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
535 |
// to allow the desired number of active_workers. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
536 |
more_inactive_workers = |
38216 | 537 |
created_workers() - active_workers() - idle_workers(); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
538 |
if (more_inactive_workers < 0) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
539 |
int reduced_active_workers = active_workers() + more_inactive_workers; |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
540 |
update_active_workers(reduced_active_workers); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
541 |
more_inactive_workers = 0; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
542 |
} |
35061 | 543 |
log_trace(gc, task)("JT: %d workers %d active %d idle %d more %d", |
544 |
Threads::number_of_non_daemon_threads(), |
|
38216 | 545 |
created_workers(), |
35061 | 546 |
active_workers(), |
547 |
idle_workers(), |
|
548 |
more_inactive_workers); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
549 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
550 |
GCTaskQueue* q = GCTaskQueue::create(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
551 |
for(uint i = 0; i < (uint) more_inactive_workers; i++) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
552 |
q->enqueue(IdleGCTask::create_on_c_heap()); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
553 |
increment_idle_workers(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
554 |
} |
38216 | 555 |
assert(created_workers() == active_workers() + idle_workers(), |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
556 |
"total workers should equal active + inactive"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
557 |
add_list(q); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
558 |
// GCTaskQueue* q was created in a ResourceArea so a |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
559 |
// destroy() call is not needed. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
560 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
561 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
562 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
563 |
void GCTaskManager::release_idle_workers() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
564 |
{ |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
565 |
MutexLockerEx ml(monitor(), |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
566 |
Mutex::_no_safepoint_check_flag); |
33125 | 567 |
_wait_helper.set_should_wait(false); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
568 |
monitor()->notify_all(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
569 |
// Release monitor |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
570 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
571 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
572 |
|
1 | 573 |
void GCTaskManager::print_task_time_stamps() { |
35061 | 574 |
if (!log_is_enabled(Debug, gc, task, time)) { |
575 |
return; |
|
576 |
} |
|
38216 | 577 |
uint num_thr = created_workers(); |
578 |
for(uint i=0; i < num_thr; i++) { |
|
1 | 579 |
GCTaskThread* t = thread(i); |
580 |
t->print_task_time_stamps(); |
|
581 |
} |
|
582 |
} |
|
583 |
||
584 |
void GCTaskManager::print_threads_on(outputStream* st) { |
|
38216 | 585 |
uint num_thr = created_workers(); |
1 | 586 |
for (uint i = 0; i < num_thr; i++) { |
587 |
thread(i)->print_on(st); |
|
588 |
st->cr(); |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
void GCTaskManager::threads_do(ThreadClosure* tc) { |
|
593 |
assert(tc != NULL, "Null ThreadClosure"); |
|
38216 | 594 |
uint num_thr = created_workers(); |
1 | 595 |
for (uint i = 0; i < num_thr; i++) { |
596 |
tc->do_thread(thread(i)); |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
GCTaskThread* GCTaskManager::thread(uint which) { |
|
38216 | 601 |
assert(which < created_workers(), "index out of bounds"); |
1 | 602 |
assert(_thread[which] != NULL, "shouldn't have null thread"); |
603 |
return _thread[which]; |
|
604 |
} |
|
605 |
||
606 |
void GCTaskManager::set_thread(uint which, GCTaskThread* value) { |
|
38216 | 607 |
// "_created_workers" may not have been updated yet so use workers() |
1 | 608 |
assert(which < workers(), "index out of bounds"); |
609 |
assert(value != NULL, "shouldn't have null thread"); |
|
610 |
_thread[which] = value; |
|
611 |
} |
|
612 |
||
613 |
void GCTaskManager::add_task(GCTask* task) { |
|
614 |
assert(task != NULL, "shouldn't have null task"); |
|
615 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
|
616 |
if (TraceGCTaskManager) { |
|
617 |
tty->print_cr("GCTaskManager::add_task(" INTPTR_FORMAT " [%s])", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
618 |
p2i(task), GCTask::Kind::to_string(task->kind())); |
1 | 619 |
} |
620 |
queue()->enqueue(task); |
|
621 |
// Notify with the lock held to avoid missed notifies. |
|
622 |
if (TraceGCTaskManager) { |
|
623 |
tty->print_cr(" GCTaskManager::add_task (%s)->notify_all", |
|
624 |
monitor()->name()); |
|
625 |
} |
|
626 |
(void) monitor()->notify_all(); |
|
627 |
// Release monitor(). |
|
628 |
} |
|
629 |
||
630 |
void GCTaskManager::add_list(GCTaskQueue* list) { |
|
631 |
assert(list != NULL, "shouldn't have null task"); |
|
632 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
|
633 |
if (TraceGCTaskManager) { |
|
634 |
tty->print_cr("GCTaskManager::add_list(%u)", list->length()); |
|
635 |
} |
|
636 |
queue()->enqueue(list); |
|
637 |
// Notify with the lock held to avoid missed notifies. |
|
638 |
if (TraceGCTaskManager) { |
|
639 |
tty->print_cr(" GCTaskManager::add_list (%s)->notify_all", |
|
640 |
monitor()->name()); |
|
641 |
} |
|
642 |
(void) monitor()->notify_all(); |
|
643 |
// Release monitor(). |
|
644 |
} |
|
645 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
646 |
// GC workers wait in get_task() for new work to be added |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
647 |
// to the GCTaskManager's queue. When new work is added, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
648 |
// a notify is sent to the waiting GC workers which then |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
649 |
// compete to get tasks. If a GC worker wakes up and there |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
650 |
// is no work on the queue, it is given a noop_task to execute |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
651 |
// and then loops to find more work. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
652 |
|
1 | 653 |
GCTask* GCTaskManager::get_task(uint which) { |
654 |
GCTask* result = NULL; |
|
655 |
// Grab the queue lock. |
|
656 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
|
657 |
// Wait while the queue is block or |
|
658 |
// there is nothing to do, except maybe release resources. |
|
659 |
while (is_blocked() || |
|
660 |
(queue()->is_empty() && !should_release_resources(which))) { |
|
661 |
if (TraceGCTaskManager) { |
|
662 |
tty->print_cr("GCTaskManager::get_task(%u)" |
|
663 |
" blocked: %s" |
|
664 |
" empty: %s" |
|
665 |
" release: %s", |
|
666 |
which, |
|
667 |
is_blocked() ? "true" : "false", |
|
668 |
queue()->is_empty() ? "true" : "false", |
|
669 |
should_release_resources(which) ? "true" : "false"); |
|
670 |
tty->print_cr(" => (%s)->wait()", |
|
671 |
monitor()->name()); |
|
672 |
} |
|
673 |
monitor()->wait(Mutex::_no_safepoint_check_flag, 0); |
|
674 |
} |
|
675 |
// We've reacquired the queue lock here. |
|
676 |
// Figure out which condition caused us to exit the loop above. |
|
677 |
if (!queue()->is_empty()) { |
|
678 |
if (UseGCTaskAffinity) { |
|
679 |
result = queue()->dequeue(which); |
|
680 |
} else { |
|
681 |
result = queue()->dequeue(); |
|
682 |
} |
|
683 |
if (result->is_barrier_task()) { |
|
684 |
assert(which != sentinel_worker(), |
|
685 |
"blocker shouldn't be bogus"); |
|
686 |
set_blocking_worker(which); |
|
687 |
} |
|
688 |
} else { |
|
689 |
// The queue is empty, but we were woken up. |
|
690 |
// Just hand back a Noop task, |
|
691 |
// in case someone wanted us to release resources, or whatever. |
|
692 |
result = noop_task(); |
|
693 |
} |
|
694 |
assert(result != NULL, "shouldn't have null task"); |
|
695 |
if (TraceGCTaskManager) { |
|
696 |
tty->print_cr("GCTaskManager::get_task(%u) => " INTPTR_FORMAT " [%s]", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
697 |
which, p2i(result), GCTask::Kind::to_string(result->kind())); |
1 | 698 |
tty->print_cr(" %s", result->name()); |
699 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
700 |
if (!result->is_idle_task()) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
701 |
increment_busy_workers(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
702 |
increment_delivered_tasks(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
703 |
} |
1 | 704 |
return result; |
705 |
// Release monitor(). |
|
706 |
} |
|
707 |
||
708 |
void GCTaskManager::note_completion(uint which) { |
|
709 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
|
710 |
if (TraceGCTaskManager) { |
|
711 |
tty->print_cr("GCTaskManager::note_completion(%u)", which); |
|
712 |
} |
|
713 |
// If we are blocked, check if the completing thread is the blocker. |
|
714 |
if (blocking_worker() == which) { |
|
715 |
assert(blocking_worker() != sentinel_worker(), |
|
716 |
"blocker shouldn't be bogus"); |
|
717 |
increment_barriers(); |
|
718 |
set_unblocked(); |
|
719 |
} |
|
720 |
increment_completed_tasks(); |
|
721 |
uint active = decrement_busy_workers(); |
|
722 |
if ((active == 0) && (queue()->is_empty())) { |
|
723 |
increment_emptied_queue(); |
|
724 |
if (TraceGCTaskManager) { |
|
725 |
tty->print_cr(" GCTaskManager::note_completion(%u) done", which); |
|
726 |
} |
|
727 |
} |
|
728 |
if (TraceGCTaskManager) { |
|
729 |
tty->print_cr(" GCTaskManager::note_completion(%u) (%s)->notify_all", |
|
730 |
which, monitor()->name()); |
|
731 |
tty->print_cr(" " |
|
732 |
" blocked: %s" |
|
733 |
" empty: %s" |
|
734 |
" release: %s", |
|
735 |
is_blocked() ? "true" : "false", |
|
736 |
queue()->is_empty() ? "true" : "false", |
|
737 |
should_release_resources(which) ? "true" : "false"); |
|
738 |
tty->print_cr(" " |
|
739 |
" delivered: %u" |
|
740 |
" completed: %u" |
|
741 |
" barriers: %u" |
|
742 |
" emptied: %u", |
|
743 |
delivered_tasks(), |
|
744 |
completed_tasks(), |
|
745 |
barriers(), |
|
746 |
emptied_queue()); |
|
747 |
} |
|
748 |
// Tell everyone that a task has completed. |
|
749 |
(void) monitor()->notify_all(); |
|
750 |
// Release monitor(). |
|
751 |
} |
|
752 |
||
753 |
uint GCTaskManager::increment_busy_workers() { |
|
754 |
assert(queue()->own_lock(), "don't own the lock"); |
|
755 |
_busy_workers += 1; |
|
756 |
return _busy_workers; |
|
757 |
} |
|
758 |
||
759 |
uint GCTaskManager::decrement_busy_workers() { |
|
760 |
assert(queue()->own_lock(), "don't own the lock"); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
761 |
assert(_busy_workers > 0, "About to make a mistake"); |
1 | 762 |
_busy_workers -= 1; |
763 |
return _busy_workers; |
|
764 |
} |
|
765 |
||
766 |
void GCTaskManager::release_all_resources() { |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
767 |
// If you want this to be done atomically, do it in a WaitForBarrierGCTask. |
38216 | 768 |
for (uint i = 0; i < created_workers(); i += 1) { |
1 | 769 |
set_resource_flag(i, true); |
770 |
} |
|
771 |
} |
|
772 |
||
773 |
bool GCTaskManager::should_release_resources(uint which) { |
|
774 |
// This can be done without a lock because each thread reads one element. |
|
775 |
return resource_flag(which); |
|
776 |
} |
|
777 |
||
778 |
void GCTaskManager::note_release(uint which) { |
|
779 |
// This can be done without a lock because each thread writes one element. |
|
780 |
set_resource_flag(which, false); |
|
781 |
} |
|
782 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
783 |
// "list" contains tasks that are ready to execute. Those |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
784 |
// tasks are added to the GCTaskManager's queue of tasks and |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
785 |
// then the GC workers are notified that there is new work to |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
786 |
// do. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
787 |
// |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
788 |
// Typically different types of tasks can be added to the "list". |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
789 |
// For example in PSScavenge OldToYoungRootsTask, SerialOldToYoungRootsTask, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
790 |
// ScavengeRootsTask, and StealTask tasks are all added to the list |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
791 |
// and then the GC workers are notified of new work. The tasks are |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
792 |
// handed out in the order in which they are added to the list |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
793 |
// (although execution is not necessarily in that order). As long |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
794 |
// as any tasks are running the GCTaskManager will wait for execution |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
795 |
// to complete. GC workers that execute a stealing task remain in |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
796 |
// the stealing task until all stealing tasks have completed. The load |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
797 |
// balancing afforded by the stealing tasks work best if the stealing |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
798 |
// tasks are added last to the list. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
799 |
|
1 | 800 |
void GCTaskManager::execute_and_wait(GCTaskQueue* list) { |
801 |
WaitForBarrierGCTask* fin = WaitForBarrierGCTask::create(); |
|
802 |
list->enqueue(fin); |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
803 |
// The barrier task will be read by one of the GC |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
804 |
// workers once it is added to the list of tasks. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
805 |
// Be sure that is globally visible before the |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
806 |
// GC worker reads it (which is after the task is added |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
807 |
// to the list of tasks below). |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
808 |
OrderAccess::storestore(); |
1 | 809 |
add_list(list); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
810 |
fin->wait_for(true /* reset */); |
1 | 811 |
// We have to release the barrier tasks! |
812 |
WaitForBarrierGCTask::destroy(fin); |
|
813 |
} |
|
814 |
||
815 |
bool GCTaskManager::resource_flag(uint which) { |
|
816 |
assert(which < workers(), "index out of bounds"); |
|
817 |
return _resource_flag[which]; |
|
818 |
} |
|
819 |
||
820 |
void GCTaskManager::set_resource_flag(uint which, bool value) { |
|
821 |
assert(which < workers(), "index out of bounds"); |
|
822 |
_resource_flag[which] = value; |
|
823 |
} |
|
824 |
||
825 |
// |
|
826 |
// NoopGCTask |
|
827 |
// |
|
828 |
||
829 |
NoopGCTask* NoopGCTask::create_on_c_heap() { |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
830 |
NoopGCTask* result = new(ResourceObj::C_HEAP, mtGC) NoopGCTask(); |
1 | 831 |
return result; |
832 |
} |
|
833 |
||
834 |
void NoopGCTask::destroy(NoopGCTask* that) { |
|
835 |
if (that != NULL) { |
|
836 |
that->destruct(); |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
837 |
FreeHeap(that); |
1 | 838 |
} |
839 |
} |
|
840 |
||
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
841 |
// This task should never be performing GC work that require |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
842 |
// a valid GC id. |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
843 |
NoopGCTask::NoopGCTask() : GCTask(GCTask::Kind::noop_task, GCId::undefined()) { } |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
844 |
|
1 | 845 |
void NoopGCTask::destruct() { |
846 |
// This has to know it's superclass structure, just like the constructor. |
|
847 |
this->GCTask::destruct(); |
|
848 |
// Nothing else to do. |
|
849 |
} |
|
850 |
||
851 |
// |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
852 |
// IdleGCTask |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
853 |
// |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
854 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
855 |
IdleGCTask* IdleGCTask::create() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
856 |
IdleGCTask* result = new IdleGCTask(false); |
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
857 |
assert(UseDynamicNumberOfGCThreads, |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
858 |
"Should only be used with dynamic GC thread"); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
859 |
return result; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
860 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
861 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
862 |
IdleGCTask* IdleGCTask::create_on_c_heap() { |
13195 | 863 |
IdleGCTask* result = new(ResourceObj::C_HEAP, mtGC) IdleGCTask(true); |
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
864 |
assert(UseDynamicNumberOfGCThreads, |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
865 |
"Should only be used with dynamic GC thread"); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
866 |
return result; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
867 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
868 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
869 |
void IdleGCTask::do_it(GCTaskManager* manager, uint which) { |
33125 | 870 |
WaitHelper* wait_helper = manager->wait_helper(); |
35061 | 871 |
log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask:::do_it() should_wait: %s", |
33125 | 872 |
p2i(this), wait_helper->should_wait() ? "true" : "false"); |
35061 | 873 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
874 |
MutexLockerEx ml(manager->monitor(), Mutex::_no_safepoint_check_flag); |
35061 | 875 |
log_trace(gc, task)("--- idle %d", which); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
876 |
// Increment has to be done when the idle tasks are created. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
877 |
// manager->increment_idle_workers(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
878 |
manager->monitor()->notify_all(); |
33125 | 879 |
while (wait_helper->should_wait()) { |
35061 | 880 |
log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() [" INTPTR_FORMAT "] (%s)->wait()", |
881 |
p2i(this), p2i(manager->monitor()), manager->monitor()->name()); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
882 |
manager->monitor()->wait(Mutex::_no_safepoint_check_flag, 0); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
883 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
884 |
manager->decrement_idle_workers(); |
35061 | 885 |
|
886 |
log_trace(gc, task)("--- release %d", which); |
|
887 |
log_trace(gc, task)("[" INTPTR_FORMAT "] IdleGCTask::do_it() returns should_wait: %s", |
|
888 |
p2i(this), wait_helper->should_wait() ? "true" : "false"); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
889 |
// Release monitor(). |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
890 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
891 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
892 |
void IdleGCTask::destroy(IdleGCTask* that) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
893 |
if (that != NULL) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
894 |
that->destruct(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
895 |
if (that->is_c_heap_obj()) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
896 |
FreeHeap(that); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
897 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
898 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
899 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
900 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
901 |
void IdleGCTask::destruct() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
902 |
// This has to know it's superclass structure, just like the constructor. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
903 |
this->GCTask::destruct(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
904 |
// Nothing else to do. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
905 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
906 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
907 |
// |
1 | 908 |
// WaitForBarrierGCTask |
909 |
// |
|
910 |
WaitForBarrierGCTask* WaitForBarrierGCTask::create() { |
|
33125 | 911 |
WaitForBarrierGCTask* result = new WaitForBarrierGCTask(); |
1 | 912 |
return result; |
913 |
} |
|
914 |
||
33125 | 915 |
WaitForBarrierGCTask::WaitForBarrierGCTask() : GCTask(GCTask::Kind::wait_for_barrier_task) { } |
1 | 916 |
|
917 |
void WaitForBarrierGCTask::destroy(WaitForBarrierGCTask* that) { |
|
918 |
if (that != NULL) { |
|
919 |
if (TraceGCTaskManager) { |
|
33125 | 920 |
tty->print_cr("[" INTPTR_FORMAT "] WaitForBarrierGCTask::destroy()", p2i(that)); |
1 | 921 |
} |
922 |
that->destruct(); |
|
923 |
} |
|
924 |
} |
|
925 |
||
926 |
void WaitForBarrierGCTask::destruct() { |
|
927 |
if (TraceGCTaskManager) { |
|
33125 | 928 |
tty->print_cr("[" INTPTR_FORMAT "] WaitForBarrierGCTask::destruct()", p2i(this)); |
1 | 929 |
} |
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
930 |
this->GCTask::destruct(); |
1 | 931 |
// Clean up that should be in the destructor, |
932 |
// except that ResourceMarks don't call destructors. |
|
33125 | 933 |
_wait_helper.release_monitor(); |
1 | 934 |
} |
935 |
||
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
936 |
void WaitForBarrierGCTask::do_it_internal(GCTaskManager* manager, uint which) { |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
937 |
// Wait for this to be the only busy worker. |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
938 |
assert(manager->monitor()->owned_by_self(), "don't own the lock"); |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
939 |
assert(manager->is_blocked(), "manager isn't blocked"); |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
940 |
while (manager->busy_workers() > 1) { |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
941 |
if (TraceGCTaskManager) { |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
942 |
tty->print_cr("WaitForBarrierGCTask::do_it(%u) waiting on %u workers", |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
943 |
which, manager->busy_workers()); |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
944 |
} |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
945 |
manager->monitor()->wait(Mutex::_no_safepoint_check_flag, 0); |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
946 |
} |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
947 |
} |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
33105
diff
changeset
|
948 |
|
1 | 949 |
void WaitForBarrierGCTask::do_it(GCTaskManager* manager, uint which) { |
950 |
if (TraceGCTaskManager) { |
|
951 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
33125 | 952 |
" WaitForBarrierGCTask::do_it() waiting for idle", |
953 |
p2i(this)); |
|
1 | 954 |
} |
955 |
{ |
|
956 |
// First, wait for the barrier to arrive. |
|
957 |
MutexLockerEx ml(manager->lock(), Mutex::_no_safepoint_check_flag); |
|
958 |
do_it_internal(manager, which); |
|
959 |
// Release manager->lock(). |
|
960 |
} |
|
33125 | 961 |
// Then notify the waiter. |
962 |
_wait_helper.notify(); |
|
963 |
} |
|
964 |
||
965 |
WaitHelper::WaitHelper() : _should_wait(true), _monitor(MonitorSupply::reserve()) { |
|
966 |
if (TraceGCTaskManager) { |
|
967 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
968 |
" WaitHelper::WaitHelper()" |
|
969 |
" monitor: " INTPTR_FORMAT, |
|
970 |
p2i(this), p2i(monitor())); |
|
1 | 971 |
} |
972 |
} |
|
973 |
||
33125 | 974 |
void WaitHelper::release_monitor() { |
975 |
assert(_monitor != NULL, ""); |
|
976 |
MonitorSupply::release(_monitor); |
|
977 |
_monitor = NULL; |
|
978 |
} |
|
979 |
||
980 |
WaitHelper::~WaitHelper() { |
|
981 |
release_monitor(); |
|
982 |
} |
|
983 |
||
984 |
void WaitHelper::wait_for(bool reset) { |
|
1 | 985 |
if (TraceGCTaskManager) { |
986 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
987 |
" WaitForBarrierGCTask::wait_for()" |
|
988 |
" should_wait: %s", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
989 |
p2i(this), should_wait() ? "true" : "false"); |
1 | 990 |
} |
991 |
{ |
|
992 |
// Grab the lock and check again. |
|
993 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
|
994 |
while (should_wait()) { |
|
995 |
if (TraceGCTaskManager) { |
|
996 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
997 |
" WaitForBarrierGCTask::wait_for()" |
|
998 |
" [" INTPTR_FORMAT "] (%s)->wait()", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
999 |
p2i(this), p2i(monitor()), monitor()->name()); |
1 | 1000 |
} |
1001 |
monitor()->wait(Mutex::_no_safepoint_check_flag, 0); |
|
1002 |
} |
|
1003 |
// Reset the flag in case someone reuses this task. |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
1004 |
if (reset) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
1005 |
set_should_wait(true); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
1006 |
} |
1 | 1007 |
if (TraceGCTaskManager) { |
1008 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
1009 |
" WaitForBarrierGCTask::wait_for() returns" |
|
1010 |
" should_wait: %s", |
|
29798
451c73fdf690
8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
28163
diff
changeset
|
1011 |
p2i(this), should_wait() ? "true" : "false"); |
1 | 1012 |
} |
1013 |
// Release monitor(). |
|
1014 |
} |
|
1015 |
} |
|
1016 |
||
33125 | 1017 |
void WaitHelper::notify() { |
1018 |
MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); |
|
1019 |
set_should_wait(false); |
|
1020 |
// Waiter doesn't miss the notify in the wait_for method |
|
1021 |
// since it checks the flag after grabbing the monitor. |
|
1022 |
if (TraceGCTaskManager) { |
|
1023 |
tty->print_cr("[" INTPTR_FORMAT "]" |
|
1024 |
" WaitForBarrierGCTask::do_it()" |
|
1025 |
" [" INTPTR_FORMAT "] (%s)->notify_all()", |
|
1026 |
p2i(this), p2i(monitor()), monitor()->name()); |
|
1027 |
} |
|
1028 |
monitor()->notify_all(); |
|
1029 |
} |
|
1030 |
||
1 | 1031 |
Mutex* MonitorSupply::_lock = NULL; |
1032 |
GrowableArray<Monitor*>* MonitorSupply::_freelist = NULL; |
|
1033 |
||
1034 |
Monitor* MonitorSupply::reserve() { |
|
1035 |
Monitor* result = NULL; |
|
1036 |
// Lazy initialization: possible race. |
|
1037 |
if (lock() == NULL) { |
|
1038 |
_lock = new Mutex(Mutex::barrier, // rank |
|
1039 |
"MonitorSupply mutex", // name |
|
1040 |
Mutex::_allow_vm_block_flag); // allow_vm_block |
|
1041 |
} |
|
1042 |
{ |
|
1043 |
MutexLockerEx ml(lock()); |
|
1044 |
// Lazy initialization. |
|
1045 |
if (freelist() == NULL) { |
|
1046 |
_freelist = |
|
13195 | 1047 |
new(ResourceObj::C_HEAP, mtGC) GrowableArray<Monitor*>(ParallelGCThreads, |
1 | 1048 |
true); |
1049 |
} |
|
1050 |
if (! freelist()->is_empty()) { |
|
1051 |
result = freelist()->pop(); |
|
1052 |
} else { |
|
1053 |
result = new Monitor(Mutex::barrier, // rank |
|
1054 |
"MonitorSupply monitor", // name |
|
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
1055 |
Mutex::_allow_vm_block_flag, // allow_vm_block |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
1056 |
Monitor::_safepoint_check_never); |
1 | 1057 |
} |
1058 |
guarantee(result != NULL, "shouldn't return NULL"); |
|
1059 |
assert(!result->is_locked(), "shouldn't be locked"); |
|
1060 |
// release lock(). |
|
1061 |
} |
|
1062 |
return result; |
|
1063 |
} |
|
1064 |
||
1065 |
void MonitorSupply::release(Monitor* instance) { |
|
1066 |
assert(instance != NULL, "shouldn't release NULL"); |
|
1067 |
assert(!instance->is_locked(), "shouldn't be locked"); |
|
1068 |
{ |
|
1069 |
MutexLockerEx ml(lock()); |
|
1070 |
freelist()->push(instance); |
|
1071 |
// release lock(). |
|
1072 |
} |
|
1073 |
} |