author | stefank |
Thu, 22 Feb 2018 18:36:07 +0100 | |
changeset 49047 | 8f004146e407 |
parent 48955 | e22914003cf0 |
child 51332 | c25572739e7c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48123
diff
changeset
|
2 |
* Copyright (c) 2001, 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:
1374
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1374
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:
1374
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
26 |
#include "gc/shared/gcId.hpp" |
30764 | 27 |
#include "gc/shared/workgroup.hpp" |
38216 | 28 |
#include "gc/shared/workerManager.hpp" |
7397 | 29 |
#include "memory/allocation.hpp" |
30 |
#include "memory/allocation.inline.hpp" |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
40096
diff
changeset
|
31 |
#include "runtime/atomic.hpp" |
7397 | 32 |
#include "runtime/os.hpp" |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
33 |
#include "runtime/semaphore.hpp" |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
34 |
#include "runtime/thread.inline.hpp" |
1 | 35 |
|
36 |
// Definitions of WorkGang methods. |
|
37 |
||
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
38 |
// The current implementation will exit if the allocation |
38216 | 39 |
// of any worker fails. |
40 |
void AbstractWorkGang::initialize_workers() { |
|
37225
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
41 |
log_develop_trace(gc, workgang)("Constructing work gang %s with %u threads", name(), total_workers()); |
32360 | 42 |
_workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal); |
43 |
if (_workers == NULL) { |
|
17087
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
44 |
vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array."); |
38216 | 45 |
} |
46 |
||
47 |
add_workers(true); |
|
48 |
} |
|
49 |
||
50 |
||
51 |
AbstractGangWorker* AbstractWorkGang::install_worker(uint worker_id) { |
|
52 |
AbstractGangWorker* new_worker = allocate_worker(worker_id); |
|
53 |
set_thread(worker_id, new_worker); |
|
54 |
return new_worker; |
|
55 |
} |
|
56 |
||
57 |
void AbstractWorkGang::add_workers(bool initializing) { |
|
39231
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
58 |
add_workers(_active_workers, initializing); |
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
59 |
} |
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
60 |
|
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
61 |
void AbstractWorkGang::add_workers(uint active_workers, bool initializing) { |
38216 | 62 |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
63 |
os::ThreadType worker_type; |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
64 |
if (are_ConcurrentGC_threads()) { |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
65 |
worker_type = os::cgc_thread; |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
66 |
} else { |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
67 |
worker_type = os::pgc_thread; |
1374 | 68 |
} |
39704 | 69 |
uint previous_created_workers = _created_workers; |
38216 | 70 |
|
71 |
_created_workers = WorkerManager::add_workers(this, |
|
39231
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
72 |
active_workers, |
38216 | 73 |
_total_workers, |
74 |
_created_workers, |
|
75 |
worker_type, |
|
76 |
initializing); |
|
77 |
_active_workers = MIN2(_created_workers, _active_workers); |
|
39704 | 78 |
|
79 |
WorkerManager::log_worker_creation(this, previous_created_workers, _active_workers, _created_workers, initializing); |
|
1 | 80 |
} |
81 |
||
32360 | 82 |
AbstractGangWorker* AbstractWorkGang::worker(uint i) const { |
1 | 83 |
// Array index bounds checking. |
32360 | 84 |
AbstractGangWorker* result = NULL; |
85 |
assert(_workers != NULL, "No workers for indexing"); |
|
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
29464
diff
changeset
|
86 |
assert(i < total_workers(), "Worker index out of bounds"); |
32360 | 87 |
result = _workers[i]; |
1 | 88 |
assert(result != NULL, "Indexing to null worker"); |
89 |
return result; |
|
90 |
} |
|
91 |
||
32360 | 92 |
void AbstractWorkGang::print_worker_threads_on(outputStream* st) const { |
38216 | 93 |
uint workers = created_workers(); |
32360 | 94 |
for (uint i = 0; i < workers; i++) { |
95 |
worker(i)->print_on(st); |
|
96 |
st->cr(); |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
void AbstractWorkGang::threads_do(ThreadClosure* tc) const { |
|
101 |
assert(tc != NULL, "Null ThreadClosure"); |
|
38216 | 102 |
uint workers = created_workers(); |
32360 | 103 |
for (uint i = 0; i < workers; i++) { |
104 |
tc->do_thread(worker(i)); |
|
105 |
} |
|
106 |
} |
|
107 |
||
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
108 |
// WorkGang dispatcher implemented with semaphores. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
109 |
// |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
110 |
// Semaphores don't require the worker threads to re-claim the lock when they wake up. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
111 |
// This helps lowering the latency when starting and stopping the worker threads. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
112 |
class SemaphoreGangTaskDispatcher : public GangTaskDispatcher { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
113 |
// The task currently being dispatched to the GangWorkers. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
114 |
AbstractGangTask* _task; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
115 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
116 |
volatile uint _started; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
117 |
volatile uint _not_finished; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
118 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
119 |
// Semaphore used to start the GangWorkers. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
120 |
Semaphore* _start_semaphore; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
121 |
// Semaphore used to notify the coordinator that all workers are done. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
122 |
Semaphore* _end_semaphore; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
123 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
124 |
public: |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
125 |
SemaphoreGangTaskDispatcher() : |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
126 |
_task(NULL), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
127 |
_started(0), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
128 |
_not_finished(0), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
129 |
_start_semaphore(new Semaphore()), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
130 |
_end_semaphore(new Semaphore()) |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
131 |
{ } |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
132 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
133 |
~SemaphoreGangTaskDispatcher() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
134 |
delete _start_semaphore; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
135 |
delete _end_semaphore; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
136 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
137 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
138 |
void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
139 |
// No workers are allowed to read the state variables until they have been signaled. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
140 |
_task = task; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
141 |
_not_finished = num_workers; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
142 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
143 |
// Dispatch 'num_workers' number of tasks. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
144 |
_start_semaphore->signal(num_workers); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
145 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
146 |
// Wait for the last worker to signal the coordinator. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
147 |
_end_semaphore->wait(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
148 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
149 |
// No workers are allowed to read the state variables after the coordinator has been signaled. |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32361
diff
changeset
|
150 |
assert(_not_finished == 0, "%d not finished workers?", _not_finished); |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
151 |
_task = NULL; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
152 |
_started = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
153 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
154 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
155 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
156 |
WorkData worker_wait_for_task() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
157 |
// Wait for the coordinator to dispatch a task. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
158 |
_start_semaphore->wait(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
159 |
|
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48123
diff
changeset
|
160 |
uint num_started = Atomic::add(1u, &_started); |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
161 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
162 |
// Subtract one to get a zero-indexed worker id. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
163 |
uint worker_id = num_started - 1; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
164 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
165 |
return WorkData(_task, worker_id); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
166 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
167 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
168 |
void worker_done_with_task() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
169 |
// Mark that the worker is done with the task. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
170 |
// The worker is not allowed to read the state variables after this line. |
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48123
diff
changeset
|
171 |
uint not_finished = Atomic::sub(1u, &_not_finished); |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
172 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
173 |
// The last worker signals to the coordinator that all work is completed. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
174 |
if (not_finished == 0) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
175 |
_end_semaphore->signal(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
176 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
177 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
178 |
}; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
179 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
180 |
class MutexGangTaskDispatcher : public GangTaskDispatcher { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
181 |
AbstractGangTask* _task; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
182 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
183 |
volatile uint _started; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
184 |
volatile uint _finished; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
185 |
volatile uint _num_workers; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
186 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
187 |
Monitor* _monitor; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
188 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
189 |
public: |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
190 |
MutexGangTaskDispatcher() |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
191 |
: _task(NULL), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
192 |
_monitor(new Monitor(Monitor::leaf, "WorkGang dispatcher lock", false, Monitor::_safepoint_check_never)), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
193 |
_started(0), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
194 |
_finished(0), |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
195 |
_num_workers(0) {} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
196 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
197 |
~MutexGangTaskDispatcher() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
198 |
delete _monitor; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
199 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
200 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
201 |
void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
202 |
MutexLockerEx ml(_monitor, Mutex::_no_safepoint_check_flag); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
203 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
204 |
_task = task; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
205 |
_num_workers = num_workers; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
206 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
207 |
// Tell the workers to get to work. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
208 |
_monitor->notify_all(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
209 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
210 |
// Wait for them to finish. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
211 |
while (_finished < _num_workers) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
212 |
_monitor->wait(/* no_safepoint_check */ true); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
213 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
214 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
215 |
_task = NULL; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
216 |
_num_workers = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
217 |
_started = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
218 |
_finished = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
219 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
220 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
221 |
WorkData worker_wait_for_task() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
222 |
MonitorLockerEx ml(_monitor, Mutex::_no_safepoint_check_flag); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
223 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
224 |
while (_num_workers == 0 || _started == _num_workers) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
225 |
_monitor->wait(/* no_safepoint_check */ true); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
226 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
227 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
228 |
_started++; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
229 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
230 |
// Subtract one to get a zero-indexed worker id. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
231 |
uint worker_id = _started - 1; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
232 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
233 |
return WorkData(_task, worker_id); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
234 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
235 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
236 |
void worker_done_with_task() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
237 |
MonitorLockerEx ml(_monitor, Mutex::_no_safepoint_check_flag); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
238 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
239 |
_finished++; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
240 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
241 |
if (_finished == _num_workers) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
242 |
// This will wake up all workers and not only the coordinator. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
243 |
_monitor->notify_all(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
244 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
245 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
246 |
}; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
247 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
248 |
static GangTaskDispatcher* create_dispatcher() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
249 |
if (UseSemaphoreGCThreadsSynchronization) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
250 |
return new SemaphoreGangTaskDispatcher(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
251 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
252 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
253 |
return new MutexGangTaskDispatcher(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
254 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
255 |
|
32360 | 256 |
WorkGang::WorkGang(const char* name, |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
257 |
uint workers, |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
258 |
bool are_GC_task_threads, |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
259 |
bool are_ConcurrentGC_threads) : |
32360 | 260 |
AbstractWorkGang(name, workers, are_GC_task_threads, are_ConcurrentGC_threads), |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
261 |
_dispatcher(create_dispatcher()) |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
262 |
{ } |
32360 | 263 |
|
48123 | 264 |
WorkGang::~WorkGang() { |
265 |
delete _dispatcher; |
|
266 |
} |
|
267 |
||
32360 | 268 |
AbstractGangWorker* WorkGang::allocate_worker(uint worker_id) { |
269 |
return new GangWorker(this, worker_id); |
|
270 |
} |
|
271 |
||
1 | 272 |
void WorkGang::run_task(AbstractGangTask* task) { |
38153
4f13f0b690c3
8155232: Augment Workgang to run task with a given number of threads
tschatzl
parents:
37225
diff
changeset
|
273 |
run_task(task, active_workers()); |
4f13f0b690c3
8155232: Augment Workgang to run task with a given number of threads
tschatzl
parents:
37225
diff
changeset
|
274 |
} |
4f13f0b690c3
8155232: Augment Workgang to run task with a given number of threads
tschatzl
parents:
37225
diff
changeset
|
275 |
|
4f13f0b690c3
8155232: Augment Workgang to run task with a given number of threads
tschatzl
parents:
37225
diff
changeset
|
276 |
void WorkGang::run_task(AbstractGangTask* task, uint num_workers) { |
39231
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
277 |
guarantee(num_workers <= total_workers(), |
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
278 |
"Trying to execute task %s with %u workers which is more than the amount of total workers %u.", |
e6aa09b4f1b9
8157620: Guarantee in run_task(task, num_workers) fails
jmasa
parents:
38216
diff
changeset
|
279 |
task->name(), num_workers, total_workers()); |
38153
4f13f0b690c3
8155232: Augment Workgang to run task with a given number of threads
tschatzl
parents:
37225
diff
changeset
|
280 |
guarantee(num_workers > 0, "Trying to execute task %s with zero workers", task->name()); |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
281 |
uint old_num_workers = _active_workers; |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
282 |
update_active_workers(num_workers); |
38153
4f13f0b690c3
8155232: Augment Workgang to run task with a given number of threads
tschatzl
parents:
37225
diff
changeset
|
283 |
_dispatcher->coordinator_execute_on_workers(task, num_workers); |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
284 |
update_active_workers(old_num_workers); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
8688
diff
changeset
|
285 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
8688
diff
changeset
|
286 |
|
32360 | 287 |
AbstractGangWorker::AbstractGangWorker(AbstractWorkGang* gang, uint id) { |
1 | 288 |
_gang = gang; |
289 |
set_id(id); |
|
29464
02c245ad3ec9
8073545: Use shorter and more descriptive names for GC worker threads
david
parents:
29326
diff
changeset
|
290 |
set_name("%s#%d", gang->name(), id); |
1 | 291 |
} |
292 |
||
32360 | 293 |
void AbstractGangWorker::run() { |
1 | 294 |
initialize(); |
295 |
loop(); |
|
296 |
} |
|
297 |
||
32360 | 298 |
void AbstractGangWorker::initialize() { |
13195 | 299 |
this->record_stack_base_and_size(); |
29326 | 300 |
this->initialize_named_thread(); |
1 | 301 |
assert(_gang != NULL, "No gang to run in"); |
302 |
os::set_priority(this, NearMaxPriority); |
|
37225
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
303 |
log_develop_trace(gc, workgang)("Running gang worker for gang %s id %u", gang()->name(), id()); |
1 | 304 |
// The VM thread should not execute here because MutexLocker's are used |
305 |
// as (opposed to MutexLockerEx's). |
|
306 |
assert(!Thread::current()->is_VM_thread(), "VM thread should not be part" |
|
307 |
" of a work gang"); |
|
308 |
} |
|
309 |
||
32360 | 310 |
bool AbstractGangWorker::is_GC_task_thread() const { |
311 |
return gang()->are_GC_task_threads(); |
|
312 |
} |
|
313 |
||
314 |
bool AbstractGangWorker::is_ConcurrentGC_thread() const { |
|
315 |
return gang()->are_ConcurrentGC_threads(); |
|
316 |
} |
|
317 |
||
318 |
void AbstractGangWorker::print_on(outputStream* st) const { |
|
319 |
st->print("\"%s\" ", name()); |
|
320 |
Thread::print_on(st); |
|
321 |
st->cr(); |
|
322 |
} |
|
323 |
||
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
324 |
WorkData GangWorker::wait_for_task() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
325 |
return gang()->dispatcher()->worker_wait_for_task(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
326 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
327 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
328 |
void GangWorker::signal_task_done() { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
329 |
gang()->dispatcher()->worker_done_with_task(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
330 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
331 |
|
37225
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
332 |
void GangWorker::run_task(WorkData data) { |
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
333 |
GCIdMark gc_id_mark(data._task->gc_id()); |
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
334 |
log_develop_trace(gc, workgang)("Running work gang: %s task: %s worker: %u", name(), data._task->name(), data._worker_id); |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
335 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
336 |
data._task->work(data._worker_id); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
337 |
|
37225
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
338 |
log_develop_trace(gc, workgang)("Finished work gang: %s task: %s worker: %u thread: " PTR_FORMAT, |
ac6c704f9a8c
8153187: Convert TraceWorkGang to use unified logging
brutisso
parents:
35465
diff
changeset
|
339 |
name(), data._task->name(), data._worker_id, p2i(Thread::current())); |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
340 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
341 |
|
1 | 342 |
void GangWorker::loop() { |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
343 |
while (true) { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
344 |
WorkData data = wait_for_task(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
345 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
346 |
run_task(data); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
347 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
348 |
signal_task_done(); |
1 | 349 |
} |
350 |
} |
|
351 |
||
352 |
// *** WorkGangBarrierSync |
|
353 |
||
354 |
WorkGangBarrierSync::WorkGangBarrierSync() |
|
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
355 |
: _monitor(Mutex::safepoint, "work gang barrier sync", true, |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
356 |
Monitor::_safepoint_check_never), |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
357 |
_n_workers(0), _n_completed(0), _should_reset(false), _aborted(false) { |
1 | 358 |
} |
359 |
||
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
360 |
WorkGangBarrierSync::WorkGangBarrierSync(uint n_workers, const char* name) |
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
27880
diff
changeset
|
361 |
: _monitor(Mutex::safepoint, name, true, Monitor::_safepoint_check_never), |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
362 |
_n_workers(n_workers), _n_completed(0), _should_reset(false), _aborted(false) { |
1 | 363 |
} |
364 |
||
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
365 |
void WorkGangBarrierSync::set_n_workers(uint n_workers) { |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
366 |
_n_workers = n_workers; |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
367 |
_n_completed = 0; |
1374 | 368 |
_should_reset = false; |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
369 |
_aborted = false; |
1 | 370 |
} |
371 |
||
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
372 |
bool WorkGangBarrierSync::enter() { |
1 | 373 |
MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag); |
1374 | 374 |
if (should_reset()) { |
375 |
// The should_reset() was set and we are the first worker to enter |
|
376 |
// the sync barrier. We will zero the n_completed() count which |
|
377 |
// effectively resets the barrier. |
|
378 |
zero_completed(); |
|
379 |
set_should_reset(false); |
|
380 |
} |
|
1 | 381 |
inc_completed(); |
382 |
if (n_completed() == n_workers()) { |
|
1374 | 383 |
// At this point we would like to reset the barrier to be ready in |
384 |
// case it is used again. However, we cannot set n_completed() to |
|
385 |
// 0, even after the notify_all(), given that some other workers |
|
386 |
// might still be waiting for n_completed() to become == |
|
387 |
// n_workers(). So, if we set n_completed() to 0, those workers |
|
388 |
// will get stuck (as they will wake up, see that n_completed() != |
|
389 |
// n_workers() and go back to sleep). Instead, we raise the |
|
390 |
// should_reset() flag and the barrier will be reset the first |
|
391 |
// time a worker enters it again. |
|
392 |
set_should_reset(true); |
|
1 | 393 |
monitor()->notify_all(); |
1374 | 394 |
} else { |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
395 |
while (n_completed() != n_workers() && !aborted()) { |
1 | 396 |
monitor()->wait(/* no_safepoint_check */ true); |
397 |
} |
|
398 |
} |
|
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
399 |
return !aborted(); |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
400 |
} |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
401 |
|
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
402 |
void WorkGangBarrierSync::abort() { |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
403 |
MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag); |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
404 |
set_aborted(); |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
405 |
monitor()->notify_all(); |
1 | 406 |
} |
407 |
||
408 |
// SubTasksDone functions. |
|
409 |
||
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
410 |
SubTasksDone::SubTasksDone(uint n) : |
30869 | 411 |
_n_tasks(n), _tasks(NULL) { |
13195 | 412 |
_tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal); |
1 | 413 |
guarantee(_tasks != NULL, "alloc failure"); |
414 |
clear(); |
|
415 |
} |
|
416 |
||
417 |
bool SubTasksDone::valid() { |
|
418 |
return _tasks != NULL; |
|
419 |
} |
|
420 |
||
421 |
void SubTasksDone::clear() { |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
422 |
for (uint i = 0; i < _n_tasks; i++) { |
1 | 423 |
_tasks[i] = 0; |
424 |
} |
|
425 |
_threads_completed = 0; |
|
426 |
#ifdef ASSERT |
|
427 |
_claimed = 0; |
|
428 |
#endif |
|
429 |
} |
|
430 |
||
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
431 |
bool SubTasksDone::is_task_claimed(uint t) { |
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
29464
diff
changeset
|
432 |
assert(t < _n_tasks, "bad task id."); |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
433 |
uint old = _tasks[t]; |
1 | 434 |
if (old == 0) { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
41279
diff
changeset
|
435 |
old = Atomic::cmpxchg(1u, &_tasks[t], 0u); |
1 | 436 |
} |
437 |
assert(_tasks[t] == 1, "What else?"); |
|
438 |
bool res = old != 0; |
|
439 |
#ifdef ASSERT |
|
440 |
if (!res) { |
|
441 |
assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); |
|
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48123
diff
changeset
|
442 |
Atomic::inc(&_claimed); |
1 | 443 |
} |
444 |
#endif |
|
445 |
return res; |
|
446 |
} |
|
447 |
||
30869 | 448 |
void SubTasksDone::all_tasks_completed(uint n_threads) { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
41279
diff
changeset
|
449 |
uint observed = _threads_completed; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
41279
diff
changeset
|
450 |
uint old; |
1 | 451 |
do { |
452 |
old = observed; |
|
453 |
observed = Atomic::cmpxchg(old+1, &_threads_completed, old); |
|
454 |
} while (observed != old); |
|
455 |
// If this was the last thread checking in, clear the tasks. |
|
30869 | 456 |
uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads); |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
41279
diff
changeset
|
457 |
if (observed + 1 == adjusted_thread_count) { |
30869 | 458 |
clear(); |
459 |
} |
|
1 | 460 |
} |
461 |
||
462 |
||
463 |
SubTasksDone::~SubTasksDone() { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25351
diff
changeset
|
464 |
if (_tasks != NULL) FREE_C_HEAP_ARRAY(jint, _tasks); |
1 | 465 |
} |
466 |
||
467 |
// *** SequentialSubTasksDone |
|
468 |
||
469 |
void SequentialSubTasksDone::clear() { |
|
470 |
_n_tasks = _n_claimed = 0; |
|
471 |
_n_threads = _n_completed = 0; |
|
472 |
} |
|
473 |
||
474 |
bool SequentialSubTasksDone::valid() { |
|
475 |
return _n_threads > 0; |
|
476 |
} |
|
477 |
||
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
478 |
bool SequentialSubTasksDone::is_task_claimed(uint& t) { |
41279
5a7c83da4a2d
8165860: WorkGroup classes are missing volatile specifiers for lock-free code
eosterlund
parents:
40655
diff
changeset
|
479 |
t = _n_claimed; |
1 | 480 |
while (t < _n_tasks) { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
41279
diff
changeset
|
481 |
uint res = Atomic::cmpxchg(t+1, &_n_claimed, t); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
41279
diff
changeset
|
482 |
if (res == t) { |
1 | 483 |
return false; |
484 |
} |
|
41279
5a7c83da4a2d
8165860: WorkGroup classes are missing volatile specifiers for lock-free code
eosterlund
parents:
40655
diff
changeset
|
485 |
t = res; |
1 | 486 |
} |
487 |
return true; |
|
488 |
} |
|
489 |
||
490 |
bool SequentialSubTasksDone::all_tasks_completed() { |
|
41279
5a7c83da4a2d
8165860: WorkGroup classes are missing volatile specifiers for lock-free code
eosterlund
parents:
40655
diff
changeset
|
491 |
uint complete = _n_completed; |
1 | 492 |
while (true) { |
41279
5a7c83da4a2d
8165860: WorkGroup classes are missing volatile specifiers for lock-free code
eosterlund
parents:
40655
diff
changeset
|
493 |
uint res = Atomic::cmpxchg(complete+1, &_n_completed, complete); |
1 | 494 |
if (res == complete) { |
495 |
break; |
|
496 |
} |
|
497 |
complete = res; |
|
498 |
} |
|
499 |
if (complete+1 == _n_threads) { |
|
500 |
clear(); |
|
501 |
return true; |
|
502 |
} |
|
503 |
return false; |
|
504 |
} |