author | brutisso |
Wed, 30 Sep 2015 09:07:21 +0200 | |
changeset 33107 | 77bf0d2069a3 |
parent 33105 | 294e48b4f704 |
child 35040 | d00805788fdd |
permissions | -rw-r--r-- |
1 | 1 |
/* |
30585 | 2 |
* Copyright (c) 2002, 2015, 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:
2105
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
2105
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:
2105
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
30764 | 25 |
#ifndef SHARE_VM_GC_SHARED_WORKGROUP_HPP |
26 |
#define SHARE_VM_GC_SHARED_WORKGROUP_HPP |
|
7397 | 27 |
|
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
29 |
#include "runtime/globals.hpp" |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
30 |
#include "runtime/thread.hpp" |
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
31 |
#include "gc/shared/gcId.hpp" |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
32 |
#include "utilities/debug.hpp" |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
33 |
#include "utilities/globalDefinitions.hpp" |
7397 | 34 |
|
8688
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
35 |
// Task class hierarchy: |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
36 |
// AbstractGangTask |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
37 |
// |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
38 |
// Gang/Group class hierarchy: |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
39 |
// AbstractWorkGang |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
40 |
// WorkGang |
32360 | 41 |
// YieldingFlexibleWorkGang (defined in another file) |
8688
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
42 |
// |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
43 |
// Worker class hierarchy: |
32360 | 44 |
// AbstractGangWorker (subclass of WorkerThread) |
45 |
// GangWorker |
|
8688
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
46 |
// YieldingFlexibleGangWorker (defined in another file) |
493d12ccc6db
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
7397
diff
changeset
|
47 |
|
1 | 48 |
// Forward declarations of classes defined here |
49 |
||
32360 | 50 |
class AbstractGangWorker; |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
51 |
class Semaphore; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
52 |
class WorkGang; |
1 | 53 |
|
54 |
// An abstract task to be worked on by a gang. |
|
55 |
// You subclass this to supply your own work() method |
|
2013
49e915da0905
6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents:
1374
diff
changeset
|
56 |
class AbstractGangTask VALUE_OBJ_CLASS_SPEC { |
32360 | 57 |
const char* _name; |
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
58 |
const uint _gc_id; |
32360 | 59 |
|
60 |
public: |
|
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
61 |
AbstractGangTask(const char* name) : |
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
62 |
_name(name), |
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
63 |
_gc_id(GCId::current_raw()) |
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
64 |
{} |
32360 | 65 |
|
1 | 66 |
// The abstract work method. |
67 |
// The argument tells you which member of the gang you are. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
68 |
virtual void work(uint worker_id) = 0; |
1 | 69 |
|
70 |
// Debugging accessor for the name. |
|
32360 | 71 |
const char* name() const { return _name; } |
33107
77bf0d2069a3
8134953: Make the GC ID available in a central place
brutisso
parents:
33105
diff
changeset
|
72 |
const uint gc_id() const { return _gc_id; } |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
73 |
}; |
1 | 74 |
|
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
75 |
struct WorkData { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
76 |
AbstractGangTask* _task; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
77 |
uint _worker_id; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
78 |
WorkData(AbstractGangTask* task, uint worker_id) : _task(task), _worker_id(worker_id) {} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
79 |
}; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
80 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
81 |
// Interface to handle the synchronization between the coordinator thread and the worker threads, |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
82 |
// when a task is dispatched out to the worker threads. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
83 |
class GangTaskDispatcher : public CHeapObj<mtGC> { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
84 |
public: |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
85 |
virtual ~GangTaskDispatcher() {} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
86 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
87 |
// Coordinator API. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
88 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
89 |
// Distributes the task out to num_workers workers. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
90 |
// Returns when the task has been completed by all workers. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
91 |
virtual void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
92 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
93 |
// Worker API. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
94 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
95 |
// Waits for a task to become available to the worker. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
96 |
// Returns when the worker has been assigned a task. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
97 |
virtual WorkData worker_wait_for_task() = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
98 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
99 |
// Signal to the coordinator that the worker is done with the assigned task. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
100 |
virtual void worker_done_with_task() = 0; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
101 |
}; |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
10565
diff
changeset
|
102 |
|
32360 | 103 |
// The work gang is the collection of workers to execute tasks. |
104 |
// The number of workers run for a task is "_active_workers" |
|
105 |
// while "_total_workers" is the number of available of workers. |
|
106 |
class AbstractWorkGang : public CHeapObj<mtInternal> { |
|
107 |
protected: |
|
108 |
// The array of worker threads for this gang. |
|
109 |
AbstractGangWorker** _workers; |
|
110 |
// The count of the number of workers in the gang. |
|
111 |
uint _total_workers; |
|
112 |
// The currently active workers in this gang. |
|
113 |
uint _active_workers; |
|
114 |
// Printing support. |
|
115 |
const char* _name; |
|
116 |
||
117 |
private: |
|
1 | 118 |
// Initialize only instance data. |
1374 | 119 |
const bool _are_GC_task_threads; |
120 |
const bool _are_ConcurrentGC_threads; |
|
32360 | 121 |
|
122 |
public: |
|
123 |
AbstractWorkGang(const char* name, uint workers, bool are_GC_task_threads, bool are_ConcurrentGC_threads) : |
|
124 |
_name(name), |
|
125 |
_total_workers(workers), |
|
126 |
_active_workers(UseDynamicNumberOfGCThreads ? 1U : workers), |
|
127 |
_are_GC_task_threads(are_GC_task_threads), |
|
128 |
_are_ConcurrentGC_threads(are_ConcurrentGC_threads) |
|
129 |
{ } |
|
130 |
||
131 |
// Initialize workers in the gang. Return true if initialization succeeded. |
|
132 |
bool initialize_workers(); |
|
133 |
||
134 |
bool are_GC_task_threads() const { return _are_GC_task_threads; } |
|
135 |
bool are_ConcurrentGC_threads() const { return _are_ConcurrentGC_threads; } |
|
136 |
||
137 |
uint total_workers() const { return _total_workers; } |
|
138 |
||
139 |
virtual uint active_workers() const { |
|
140 |
assert(_active_workers <= _total_workers, |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32361
diff
changeset
|
141 |
"_active_workers: %u > _total_workers: %u", _active_workers, _total_workers); |
32360 | 142 |
assert(UseDynamicNumberOfGCThreads || _active_workers == _total_workers, |
143 |
"Unless dynamic should use total workers"); |
|
144 |
return _active_workers; |
|
145 |
} |
|
146 |
void set_active_workers(uint v) { |
|
147 |
assert(v <= _total_workers, |
|
148 |
"Trying to set more workers active than there are"); |
|
149 |
_active_workers = MIN2(v, _total_workers); |
|
150 |
assert(v != 0, "Trying to set active workers to 0"); |
|
151 |
_active_workers = MAX2(1U, _active_workers); |
|
152 |
assert(UseDynamicNumberOfGCThreads || _active_workers == _total_workers, |
|
153 |
"Unless dynamic should use total workers"); |
|
154 |
} |
|
155 |
||
156 |
// Return the Ith worker. |
|
157 |
AbstractGangWorker* worker(uint i) const; |
|
158 |
||
159 |
void threads_do(ThreadClosure* tc) const; |
|
160 |
||
161 |
// Debugging. |
|
162 |
const char* name() const { return _name; } |
|
163 |
||
164 |
// Printing |
|
165 |
void print_worker_threads_on(outputStream *st) const; |
|
166 |
void print_worker_threads() const { |
|
167 |
print_worker_threads_on(tty); |
|
168 |
} |
|
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
169 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
170 |
protected: |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
171 |
virtual AbstractGangWorker* allocate_worker(uint which) = 0; |
32360 | 172 |
}; |
173 |
||
174 |
// An class representing a gang of workers. |
|
175 |
class WorkGang: public AbstractWorkGang { |
|
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
176 |
// To get access to the GangTaskDispatcher instance. |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
177 |
friend class GangWorker; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
178 |
|
32360 | 179 |
// Never deleted. |
180 |
~WorkGang(); |
|
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
181 |
|
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
182 |
GangTaskDispatcher* const _dispatcher; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
183 |
GangTaskDispatcher* dispatcher() const { |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
184 |
return _dispatcher; |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
185 |
} |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
186 |
|
32360 | 187 |
public: |
188 |
WorkGang(const char* name, |
|
189 |
uint workers, |
|
190 |
bool are_GC_task_threads, |
|
191 |
bool are_ConcurrentGC_threads); |
|
192 |
||
193 |
// Run a task, returns when the task is done. |
|
194 |
virtual void run_task(AbstractGangTask* task); |
|
195 |
||
196 |
protected: |
|
197 |
virtual AbstractGangWorker* allocate_worker(uint which); |
|
1 | 198 |
}; |
199 |
||
32360 | 200 |
// Several instances of this class run in parallel as workers for a gang. |
201 |
class AbstractGangWorker: public WorkerThread { |
|
1 | 202 |
public: |
32360 | 203 |
AbstractGangWorker(AbstractWorkGang* gang, uint id); |
1 | 204 |
|
205 |
// The only real method: run a task for the gang. |
|
206 |
virtual void run(); |
|
207 |
// Predicate for Thread |
|
208 |
virtual bool is_GC_task_thread() const; |
|
1374 | 209 |
virtual bool is_ConcurrentGC_thread() const; |
1 | 210 |
// Printing |
211 |
void print_on(outputStream* st) const; |
|
212 |
virtual void print() const { print_on(tty); } |
|
32360 | 213 |
|
1 | 214 |
protected: |
215 |
AbstractWorkGang* _gang; |
|
216 |
||
217 |
virtual void initialize(); |
|
32360 | 218 |
virtual void loop() = 0; |
219 |
||
220 |
AbstractWorkGang* gang() const { return _gang; } |
|
221 |
}; |
|
222 |
||
223 |
class GangWorker: public AbstractGangWorker { |
|
224 |
public: |
|
225 |
GangWorker(WorkGang* gang, uint id) : AbstractGangWorker(gang, id) {} |
|
226 |
||
227 |
protected: |
|
1 | 228 |
virtual void loop(); |
229 |
||
32360 | 230 |
private: |
32361
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
231 |
WorkData wait_for_task(); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
232 |
void run_task(WorkData work); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
233 |
void signal_task_done(); |
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 |
void print_task_started(WorkData data); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
236 |
void print_task_done(WorkData data); |
3de9a2e1e2d0
8087324: Use semaphores when starting and stopping GC task threads
stefank
parents:
32360
diff
changeset
|
237 |
|
32360 | 238 |
WorkGang* gang() const { return (WorkGang*)_gang; } |
1 | 239 |
}; |
240 |
||
241 |
// A class that acts as a synchronisation barrier. Workers enter |
|
242 |
// the barrier and must wait until all other workers have entered |
|
243 |
// before any of them may leave. |
|
244 |
||
245 |
class WorkGangBarrierSync : public StackObj { |
|
246 |
protected: |
|
247 |
Monitor _monitor; |
|
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
248 |
uint _n_workers; |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
249 |
uint _n_completed; |
1374 | 250 |
bool _should_reset; |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
251 |
bool _aborted; |
1 | 252 |
|
1374 | 253 |
Monitor* monitor() { return &_monitor; } |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
254 |
uint n_workers() { return _n_workers; } |
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
255 |
uint n_completed() { return _n_completed; } |
1374 | 256 |
bool should_reset() { return _should_reset; } |
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
257 |
bool aborted() { return _aborted; } |
1 | 258 |
|
1374 | 259 |
void zero_completed() { _n_completed = 0; } |
260 |
void inc_completed() { _n_completed++; } |
|
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
261 |
void set_aborted() { _aborted = true; } |
1374 | 262 |
void set_should_reset(bool v) { _should_reset = v; } |
1 | 263 |
|
264 |
public: |
|
265 |
WorkGangBarrierSync(); |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
266 |
WorkGangBarrierSync(uint n_workers, const char* name); |
1 | 267 |
|
268 |
// Set the number of workers that will use the barrier. |
|
269 |
// Must be called before any of the workers start running. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
270 |
void set_n_workers(uint n_workers); |
1 | 271 |
|
272 |
// Enter the barrier. A worker that enters the barrier will |
|
273 |
// not be allowed to leave until all other threads have |
|
24468
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
274 |
// also entered the barrier or the barrier is aborted. |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
275 |
// Returns false if the barrier was aborted. |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
276 |
bool enter(); |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
277 |
|
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
278 |
// Aborts the barrier and wakes up any threads waiting for |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
279 |
// the barrier to complete. The barrier will remain in the |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
280 |
// aborted state until the next call to set_n_workers(). |
cb71997b6484
8040803: G1: Concurrent mark hangs when mark stack overflows
pliden
parents:
17376
diff
changeset
|
281 |
void abort(); |
1 | 282 |
}; |
283 |
||
284 |
// A class to manage claiming of subtasks within a group of tasks. The |
|
285 |
// subtasks will be identified by integer indices, usually elements of an |
|
286 |
// enumeration type. |
|
287 |
||
13195 | 288 |
class SubTasksDone: public CHeapObj<mtInternal> { |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
289 |
uint* _tasks; |
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
290 |
uint _n_tasks; |
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
291 |
uint _threads_completed; |
1 | 292 |
#ifdef ASSERT |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
293 |
volatile uint _claimed; |
1 | 294 |
#endif |
295 |
||
296 |
// Set all tasks to unclaimed. |
|
297 |
void clear(); |
|
298 |
||
299 |
public: |
|
300 |
// Initializes "this" to a state in which there are "n" tasks to be |
|
301 |
// processed, none of the which are originally claimed. The number of |
|
302 |
// threads doing the tasks is initialized 1. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
303 |
SubTasksDone(uint n); |
1 | 304 |
|
305 |
// True iff the object is in a valid state. |
|
306 |
bool valid(); |
|
307 |
||
308 |
// Returns "false" if the task "t" is unclaimed, and ensures that task is |
|
309 |
// claimed. The task "t" is required to be within the range of "this". |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
310 |
bool is_task_claimed(uint t); |
1 | 311 |
|
312 |
// The calling thread asserts that it has attempted to claim all the |
|
313 |
// tasks that it will try to claim. Every thread in the parallel task |
|
314 |
// must execute this. (When the last thread does so, the task array is |
|
315 |
// cleared.) |
|
30869 | 316 |
// |
317 |
// n_threads - Number of threads executing the sub-tasks. |
|
318 |
void all_tasks_completed(uint n_threads); |
|
1 | 319 |
|
320 |
// Destructor. |
|
321 |
~SubTasksDone(); |
|
322 |
}; |
|
323 |
||
324 |
// As above, but for sequential tasks, i.e. instead of claiming |
|
325 |
// sub-tasks from a set (possibly an enumeration), claim sub-tasks |
|
326 |
// in sequential order. This is ideal for claiming dynamically |
|
327 |
// partitioned tasks (like striding in the parallel remembered |
|
328 |
// set scanning). Note that unlike the above class this is |
|
329 |
// a stack object - is there any reason for it not to be? |
|
330 |
||
331 |
class SequentialSubTasksDone : public StackObj { |
|
332 |
protected: |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
333 |
uint _n_tasks; // Total number of tasks available. |
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
334 |
uint _n_claimed; // Number of tasks claimed. |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
335 |
// _n_threads is used to determine when a sub task is done. |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
336 |
// See comments on SubTasksDone::_n_threads |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
337 |
uint _n_threads; // Total number of parallel threads. |
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
338 |
uint _n_completed; // Number of completed threads. |
1 | 339 |
|
340 |
void clear(); |
|
341 |
||
342 |
public: |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
343 |
SequentialSubTasksDone() { |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
344 |
clear(); |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
345 |
} |
1 | 346 |
~SequentialSubTasksDone() {} |
347 |
||
348 |
// True iff the object is in a valid state. |
|
349 |
bool valid(); |
|
350 |
||
351 |
// number of tasks |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
352 |
uint n_tasks() const { return _n_tasks; } |
1 | 353 |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
354 |
// Get/set the number of parallel threads doing the tasks to t. |
1 | 355 |
// Should be called before the task starts but it is safe |
356 |
// to call this once a task is running provided that all |
|
357 |
// threads agree on the number of threads. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
358 |
uint n_threads() { return _n_threads; } |
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
359 |
void set_n_threads(uint t) { _n_threads = t; } |
1 | 360 |
|
361 |
// Set the number of tasks to be claimed to t. As above, |
|
362 |
// should be called before the tasks start but it is safe |
|
363 |
// to call this once a task is running provided all threads |
|
364 |
// agree on the number of tasks. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
365 |
void set_n_tasks(uint t) { _n_tasks = t; } |
1 | 366 |
|
367 |
// Returns false if the next task in the sequence is unclaimed, |
|
368 |
// and ensures that it is claimed. Will set t to be the index |
|
369 |
// of the claimed task in the sequence. Will return true if |
|
370 |
// the task cannot be claimed and there are none left to claim. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
371 |
bool is_task_claimed(uint& t); |
1 | 372 |
|
373 |
// The calling thread asserts that it has attempted to claim |
|
374 |
// all the tasks it possibly can in the sequence. Every thread |
|
375 |
// claiming tasks must promise call this. Returns true if this |
|
376 |
// is the last thread to complete so that the thread can perform |
|
377 |
// cleanup if necessary. |
|
378 |
bool all_tasks_completed(); |
|
379 |
}; |
|
1374 | 380 |
|
381 |
// Represents a set of free small integer ids. |
|
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17031
diff
changeset
|
382 |
class FreeIdSet : public CHeapObj<mtInternal> { |
1374 | 383 |
enum { |
384 |
end_of_list = -1, |
|
385 |
claimed = -2 |
|
386 |
}; |
|
387 |
||
388 |
int _sz; |
|
389 |
Monitor* _mon; |
|
390 |
||
391 |
int* _ids; |
|
392 |
int _hd; |
|
393 |
int _waiters; |
|
394 |
int _claimed; |
|
395 |
||
396 |
static bool _safepoint; |
|
397 |
typedef FreeIdSet* FreeIdSetPtr; |
|
398 |
static const int NSets = 10; |
|
399 |
static FreeIdSetPtr _sets[NSets]; |
|
400 |
static bool _stat_init; |
|
401 |
int _index; |
|
402 |
||
403 |
public: |
|
404 |
FreeIdSet(int sz, Monitor* mon); |
|
405 |
~FreeIdSet(); |
|
406 |
||
407 |
static void set_safepoint(bool b); |
|
408 |
||
409 |
// Attempt to claim the given id permanently. Returns "true" iff |
|
410 |
// successful. |
|
411 |
bool claim_perm_id(int i); |
|
412 |
||
413 |
// Returns an unclaimed parallel id (waiting for one to be released if |
|
414 |
// necessary). Returns "-1" if a GC wakes up a wait for an id. |
|
415 |
int claim_par_id(); |
|
416 |
||
417 |
void release_par_id(int id); |
|
418 |
}; |
|
7397 | 419 |
|
30764 | 420 |
#endif // SHARE_VM_GC_SHARED_WORKGROUP_HPP |