Mercurial > hg > graal-jvmci-8
annotate src/share/vm/utilities/workgroup.hpp @ 3939:f6f3bb0ee072
7088955: add C2 IR support to the SA
Reviewed-by: kvn
author | never |
---|---|
date | Sun, 11 Sep 2011 14:48:24 -0700 |
parents | 92da084fefc9 |
children | f08d439fab8c |
rev | line source |
---|---|
0 | 1 /* |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_UTILITIES_WORKGROUP_HPP |
26 #define SHARE_VM_UTILITIES_WORKGROUP_HPP | |
27 | |
28 #include "utilities/taskqueue.hpp" | |
29 #ifdef TARGET_OS_FAMILY_linux | |
30 # include "thread_linux.inline.hpp" | |
31 #endif | |
32 #ifdef TARGET_OS_FAMILY_solaris | |
33 # include "thread_solaris.inline.hpp" | |
34 #endif | |
35 #ifdef TARGET_OS_FAMILY_windows | |
36 # include "thread_windows.inline.hpp" | |
37 #endif | |
38 | |
2369
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
39 // Task class hierarchy: |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
40 // AbstractGangTask |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
41 // AbstractGangTaskWOopQueues |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
42 // |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
43 // Gang/Group class hierarchy: |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
44 // AbstractWorkGang |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
45 // WorkGang |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
46 // FlexibleWorkGang |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
47 // YieldingFlexibleWorkGang (defined in another file) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
48 // |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
49 // Worker class hierarchy: |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
50 // GangWorker (subclass of WorkerThread) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
51 // YieldingFlexibleGangWorker (defined in another file) |
92da084fefc9
6668573: CMS: reference processing crash if ParallelCMSThreads > ParallelGCThreads
ysr
parents:
1972
diff
changeset
|
52 |
0 | 53 // Forward declarations of classes defined here |
54 | |
55 class WorkGang; | |
56 class GangWorker; | |
57 class YieldingFlexibleGangWorker; | |
58 class YieldingFlexibleGangTask; | |
59 class WorkData; | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
60 class AbstractWorkGang; |
0 | 61 |
62 // An abstract task to be worked on by a gang. | |
63 // You subclass this to supply your own work() method | |
549
fe3d7c11b4b7
6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents:
342
diff
changeset
|
64 class AbstractGangTask VALUE_OBJ_CLASS_SPEC { |
0 | 65 public: |
66 // The abstract work method. | |
67 // The argument tells you which member of the gang you are. | |
68 virtual void work(int i) = 0; | |
69 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
70 // This method configures the task for proper termination. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
71 // Some tasks do not have any requirements on termination |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
72 // and may inherit this method that does nothing. Some |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
73 // tasks do some coordination on termination and override |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
74 // this method to implement that coordination. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
75 virtual void set_for_termination(int active_workers) {}; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
76 |
0 | 77 // Debugging accessor for the name. |
78 const char* name() const PRODUCT_RETURN_(return NULL;); | |
79 int counter() { return _counter; } | |
80 void set_counter(int value) { _counter = value; } | |
81 int *address_of_counter() { return &_counter; } | |
82 | |
83 // RTTI | |
84 NOT_PRODUCT(virtual bool is_YieldingFlexibleGang_task() const { | |
85 return false; | |
86 }) | |
87 | |
88 private: | |
89 NOT_PRODUCT(const char* _name;) | |
90 // ??? Should a task have a priority associated with it? | |
91 // ??? Or can the run method adjust priority as needed? | |
92 int _counter; | |
93 | |
94 protected: | |
95 // Constructor and desctructor: only construct subclasses. | |
96 AbstractGangTask(const char* name) { | |
97 NOT_PRODUCT(_name = name); | |
98 _counter = 0; | |
99 } | |
100 virtual ~AbstractGangTask() { } | |
101 }; | |
102 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
103 class AbstractGangTaskWOopQueues : public AbstractGangTask { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
104 OopTaskQueueSet* _queues; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
105 ParallelTaskTerminator _terminator; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
106 public: |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
107 AbstractGangTaskWOopQueues(const char* name, OopTaskQueueSet* queues) : |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
108 AbstractGangTask(name), _queues(queues), _terminator(0, _queues) {} |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
109 ParallelTaskTerminator* terminator() { return &_terminator; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
110 virtual void set_for_termination(int active_workers) { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
111 terminator()->reset_for_reuse(active_workers); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
112 } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
113 OopTaskQueueSet* queues() { return _queues; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
114 }; |
0 | 115 |
116 // Class AbstractWorkGang: | |
117 // An abstract class representing a gang of workers. | |
118 // You subclass this to supply an implementation of run_task(). | |
119 class AbstractWorkGang: public CHeapObj { | |
120 // Here's the public interface to this class. | |
121 public: | |
122 // Constructor and destructor. | |
342 | 123 AbstractWorkGang(const char* name, bool are_GC_task_threads, |
124 bool are_ConcurrentGC_threads); | |
0 | 125 ~AbstractWorkGang(); |
126 // Run a task, returns when the task is done (or terminated). | |
127 virtual void run_task(AbstractGangTask* task) = 0; | |
128 // Stop and terminate all workers. | |
129 virtual void stop(); | |
130 public: | |
131 // Debugging. | |
132 const char* name() const; | |
133 protected: | |
134 // Initialize only instance data. | |
342 | 135 const bool _are_GC_task_threads; |
136 const bool _are_ConcurrentGC_threads; | |
0 | 137 // Printing support. |
138 const char* _name; | |
139 // The monitor which protects these data, | |
140 // and notifies of changes in it. | |
141 Monitor* _monitor; | |
142 // The count of the number of workers in the gang. | |
143 int _total_workers; | |
144 // Whether the workers should terminate. | |
145 bool _terminate; | |
146 // The array of worker threads for this gang. | |
147 // This is only needed for cleaning up. | |
148 GangWorker** _gang_workers; | |
149 // The task for this gang. | |
150 AbstractGangTask* _task; | |
151 // A sequence number for the current task. | |
152 int _sequence_number; | |
153 // The number of started workers. | |
154 int _started_workers; | |
155 // The number of finished workers. | |
156 int _finished_workers; | |
157 public: | |
158 // Accessors for fields | |
159 Monitor* monitor() const { | |
160 return _monitor; | |
161 } | |
162 int total_workers() const { | |
163 return _total_workers; | |
164 } | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
165 virtual int active_workers() const { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
166 return _total_workers; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
167 } |
0 | 168 bool terminate() const { |
169 return _terminate; | |
170 } | |
171 GangWorker** gang_workers() const { | |
172 return _gang_workers; | |
173 } | |
174 AbstractGangTask* task() const { | |
175 return _task; | |
176 } | |
177 int sequence_number() const { | |
178 return _sequence_number; | |
179 } | |
180 int started_workers() const { | |
181 return _started_workers; | |
182 } | |
183 int finished_workers() const { | |
184 return _finished_workers; | |
185 } | |
342 | 186 bool are_GC_task_threads() const { |
187 return _are_GC_task_threads; | |
188 } | |
189 bool are_ConcurrentGC_threads() const { | |
190 return _are_ConcurrentGC_threads; | |
0 | 191 } |
192 // Predicates. | |
193 bool is_idle() const { | |
194 return (task() == NULL); | |
195 } | |
196 // Return the Ith gang worker. | |
197 GangWorker* gang_worker(int i) const; | |
198 | |
199 void threads_do(ThreadClosure* tc) const; | |
200 | |
201 // Printing | |
202 void print_worker_threads_on(outputStream *st) const; | |
203 void print_worker_threads() const { | |
204 print_worker_threads_on(tty); | |
205 } | |
206 | |
207 protected: | |
208 friend class GangWorker; | |
209 friend class YieldingFlexibleGangWorker; | |
210 // Note activation and deactivation of workers. | |
211 // These methods should only be called with the mutex held. | |
212 void internal_worker_poll(WorkData* data) const; | |
213 void internal_note_start(); | |
214 void internal_note_finish(); | |
215 }; | |
216 | |
217 class WorkData: public StackObj { | |
218 // This would be a struct, but I want accessor methods. | |
219 private: | |
220 bool _terminate; | |
221 AbstractGangTask* _task; | |
222 int _sequence_number; | |
223 public: | |
224 // Constructor and destructor | |
225 WorkData() { | |
226 _terminate = false; | |
227 _task = NULL; | |
228 _sequence_number = 0; | |
229 } | |
230 ~WorkData() { | |
231 } | |
232 // Accessors and modifiers | |
233 bool terminate() const { return _terminate; } | |
234 void set_terminate(bool value) { _terminate = value; } | |
235 AbstractGangTask* task() const { return _task; } | |
236 void set_task(AbstractGangTask* value) { _task = value; } | |
237 int sequence_number() const { return _sequence_number; } | |
238 void set_sequence_number(int value) { _sequence_number = value; } | |
239 | |
240 YieldingFlexibleGangTask* yf_task() const { | |
241 return (YieldingFlexibleGangTask*)_task; | |
242 } | |
243 }; | |
244 | |
245 // Class WorkGang: | |
246 class WorkGang: public AbstractWorkGang { | |
247 public: | |
248 // Constructor | |
342 | 249 WorkGang(const char* name, int workers, |
250 bool are_GC_task_threads, bool are_ConcurrentGC_threads); | |
0 | 251 // Run a task, returns when the task is done (or terminated). |
252 virtual void run_task(AbstractGangTask* task); | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
253 void run_task(AbstractGangTask* task, uint no_of_parallel_workers); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
254 // Allocate a worker and return a pointer to it. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
255 virtual GangWorker* allocate_worker(int which); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
256 // Initialize workers in the gang. Return true if initialization |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
257 // succeeded. The type of the worker can be overridden in a derived |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
258 // class with the appropriate implementation of allocate_worker(). |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
259 bool initialize_workers(); |
0 | 260 }; |
261 | |
262 // Class GangWorker: | |
263 // Several instances of this class run in parallel as workers for a gang. | |
264 class GangWorker: public WorkerThread { | |
265 public: | |
266 // Constructors and destructor. | |
267 GangWorker(AbstractWorkGang* gang, uint id); | |
268 | |
269 // The only real method: run a task for the gang. | |
270 virtual void run(); | |
271 // Predicate for Thread | |
272 virtual bool is_GC_task_thread() const; | |
342 | 273 virtual bool is_ConcurrentGC_thread() const; |
0 | 274 // Printing |
275 void print_on(outputStream* st) const; | |
276 virtual void print() const { print_on(tty); } | |
277 protected: | |
278 AbstractWorkGang* _gang; | |
279 | |
280 virtual void initialize(); | |
281 virtual void loop(); | |
282 | |
283 public: | |
284 AbstractWorkGang* gang() const { return _gang; } | |
285 }; | |
286 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
287 class FlexibleWorkGang: public WorkGang { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
288 protected: |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
289 int _active_workers; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
290 public: |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
291 // Constructor and destructor. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
292 FlexibleWorkGang(const char* name, int workers, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
293 bool are_GC_task_threads, |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
294 bool are_ConcurrentGC_threads) : |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
295 WorkGang(name, workers, are_GC_task_threads, are_ConcurrentGC_threads) { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
296 _active_workers = ParallelGCThreads; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
297 }; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
298 // Accessors for fields |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
299 virtual int active_workers() const { return _active_workers; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
300 void set_active_workers(int v) { _active_workers = v; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
301 }; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
302 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
303 // Work gangs in garbage collectors: 2009-06-10 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
304 // |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
305 // SharedHeap - work gang for stop-the-world parallel collection. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
306 // Used by |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
307 // ParNewGeneration |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
308 // CMSParRemarkTask |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
309 // CMSRefProcTaskExecutor |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
310 // G1CollectedHeap |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
311 // G1ParFinalCountTask |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
312 // ConcurrentMark |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
313 // CMSCollector |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
314 |
0 | 315 // A class that acts as a synchronisation barrier. Workers enter |
316 // the barrier and must wait until all other workers have entered | |
317 // before any of them may leave. | |
318 | |
319 class WorkGangBarrierSync : public StackObj { | |
320 protected: | |
321 Monitor _monitor; | |
322 int _n_workers; | |
323 int _n_completed; | |
342 | 324 bool _should_reset; |
0 | 325 |
342 | 326 Monitor* monitor() { return &_monitor; } |
327 int n_workers() { return _n_workers; } | |
328 int n_completed() { return _n_completed; } | |
329 bool should_reset() { return _should_reset; } | |
0 | 330 |
342 | 331 void zero_completed() { _n_completed = 0; } |
332 void inc_completed() { _n_completed++; } | |
333 | |
334 void set_should_reset(bool v) { _should_reset = v; } | |
0 | 335 |
336 public: | |
337 WorkGangBarrierSync(); | |
338 WorkGangBarrierSync(int n_workers, const char* name); | |
339 | |
340 // Set the number of workers that will use the barrier. | |
341 // Must be called before any of the workers start running. | |
342 void set_n_workers(int n_workers); | |
343 | |
344 // Enter the barrier. A worker that enters the barrier will | |
345 // not be allowed to leave until all other threads have | |
346 // also entered the barrier. | |
347 void enter(); | |
348 }; | |
349 | |
350 // A class to manage claiming of subtasks within a group of tasks. The | |
351 // subtasks will be identified by integer indices, usually elements of an | |
352 // enumeration type. | |
353 | |
354 class SubTasksDone: public CHeapObj { | |
355 jint* _tasks; | |
356 int _n_tasks; | |
357 int _n_threads; | |
358 jint _threads_completed; | |
359 #ifdef ASSERT | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
360 volatile jint _claimed; |
0 | 361 #endif |
362 | |
363 // Set all tasks to unclaimed. | |
364 void clear(); | |
365 | |
366 public: | |
367 // Initializes "this" to a state in which there are "n" tasks to be | |
368 // processed, none of the which are originally claimed. The number of | |
369 // threads doing the tasks is initialized 1. | |
370 SubTasksDone(int n); | |
371 | |
372 // True iff the object is in a valid state. | |
373 bool valid(); | |
374 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
375 // Get/set the number of parallel threads doing the tasks to "t". Can only |
0 | 376 // be called before tasks start or after they are complete. |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
377 int n_threads() { return _n_threads; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
378 void set_n_threads(int t); |
0 | 379 |
380 // Returns "false" if the task "t" is unclaimed, and ensures that task is | |
381 // claimed. The task "t" is required to be within the range of "this". | |
382 bool is_task_claimed(int t); | |
383 | |
384 // The calling thread asserts that it has attempted to claim all the | |
385 // tasks that it will try to claim. Every thread in the parallel task | |
386 // must execute this. (When the last thread does so, the task array is | |
387 // cleared.) | |
388 void all_tasks_completed(); | |
389 | |
390 // Destructor. | |
391 ~SubTasksDone(); | |
392 }; | |
393 | |
394 // As above, but for sequential tasks, i.e. instead of claiming | |
395 // sub-tasks from a set (possibly an enumeration), claim sub-tasks | |
396 // in sequential order. This is ideal for claiming dynamically | |
397 // partitioned tasks (like striding in the parallel remembered | |
398 // set scanning). Note that unlike the above class this is | |
399 // a stack object - is there any reason for it not to be? | |
400 | |
401 class SequentialSubTasksDone : public StackObj { | |
402 protected: | |
403 jint _n_tasks; // Total number of tasks available. | |
404 jint _n_claimed; // Number of tasks claimed. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
405 // _n_threads is used to determine when a sub task is done. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
406 // See comments on SubTasksDone::_n_threads |
0 | 407 jint _n_threads; // Total number of parallel threads. |
408 jint _n_completed; // Number of completed threads. | |
409 | |
410 void clear(); | |
411 | |
412 public: | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
413 SequentialSubTasksDone() { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
414 clear(); |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
415 } |
0 | 416 ~SequentialSubTasksDone() {} |
417 | |
418 // True iff the object is in a valid state. | |
419 bool valid(); | |
420 | |
421 // number of tasks | |
422 jint n_tasks() const { return _n_tasks; } | |
423 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
424 // Get/set the number of parallel threads doing the tasks to t. |
0 | 425 // Should be called before the task starts but it is safe |
426 // to call this once a task is running provided that all | |
427 // threads agree on the number of threads. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
428 int n_threads() { return _n_threads; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
429 void set_n_threads(int t) { _n_threads = t; } |
0 | 430 |
431 // Set the number of tasks to be claimed to t. As above, | |
432 // should be called before the tasks start but it is safe | |
433 // to call this once a task is running provided all threads | |
434 // agree on the number of tasks. | |
435 void set_n_tasks(int t) { _n_tasks = t; } | |
436 | |
437 // Returns false if the next task in the sequence is unclaimed, | |
438 // and ensures that it is claimed. Will set t to be the index | |
439 // of the claimed task in the sequence. Will return true if | |
440 // the task cannot be claimed and there are none left to claim. | |
441 bool is_task_claimed(int& t); | |
442 | |
443 // The calling thread asserts that it has attempted to claim | |
444 // all the tasks it possibly can in the sequence. Every thread | |
445 // claiming tasks must promise call this. Returns true if this | |
446 // is the last thread to complete so that the thread can perform | |
447 // cleanup if necessary. | |
448 bool all_tasks_completed(); | |
449 }; | |
342 | 450 |
451 // Represents a set of free small integer ids. | |
452 class FreeIdSet { | |
453 enum { | |
454 end_of_list = -1, | |
455 claimed = -2 | |
456 }; | |
457 | |
458 int _sz; | |
459 Monitor* _mon; | |
460 | |
461 int* _ids; | |
462 int _hd; | |
463 int _waiters; | |
464 int _claimed; | |
465 | |
466 static bool _safepoint; | |
467 typedef FreeIdSet* FreeIdSetPtr; | |
468 static const int NSets = 10; | |
469 static FreeIdSetPtr _sets[NSets]; | |
470 static bool _stat_init; | |
471 int _index; | |
472 | |
473 public: | |
474 FreeIdSet(int sz, Monitor* mon); | |
475 ~FreeIdSet(); | |
476 | |
477 static void set_safepoint(bool b); | |
478 | |
479 // Attempt to claim the given id permanently. Returns "true" iff | |
480 // successful. | |
481 bool claim_perm_id(int i); | |
482 | |
483 // Returns an unclaimed parallel id (waiting for one to be released if | |
484 // necessary). Returns "-1" if a GC wakes up a wait for an id. | |
485 int claim_par_id(); | |
486 | |
487 void release_par_id(int id); | |
488 }; | |
1972 | 489 |
490 #endif // SHARE_VM_UTILITIES_WORKGROUP_HPP |