author | coleenp |
Wed, 14 Mar 2018 07:27:19 -0400 | |
changeset 49392 | 2956d0ece7a9 |
parent 47216 | 71c04702a3d5 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49392
2956d0ece7a9
8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
30764 | 25 |
#ifndef SHARE_VM_GC_PARALLEL_GCTASKMANAGER_HPP |
26 |
#define SHARE_VM_GC_PARALLEL_GCTASKMANAGER_HPP |
|
7397 | 27 |
|
28 |
#include "runtime/mutex.hpp" |
|
29 |
#include "utilities/growableArray.hpp" |
|
30 |
||
1 | 31 |
// |
32 |
// The GCTaskManager is a queue of GCTasks, and accessors |
|
33 |
// to allow the queue to be accessed from many threads. |
|
34 |
// |
|
35 |
||
36 |
// Forward declarations of types defined in this file. |
|
37 |
class GCTask; |
|
38 |
class GCTaskQueue; |
|
39 |
class SynchronizedGCTaskQueue; |
|
40 |
class GCTaskManager; |
|
41 |
// Some useful subclasses of GCTask. You can also make up your own. |
|
42 |
class NoopGCTask; |
|
43 |
class WaitForBarrierGCTask; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
44 |
class IdleGCTask; |
1 | 45 |
// A free list of Monitor*'s. |
46 |
class MonitorSupply; |
|
47 |
||
48 |
// Forward declarations of classes referenced in this file via pointer. |
|
49 |
class GCTaskThread; |
|
50 |
class Mutex; |
|
51 |
class Monitor; |
|
52 |
class ThreadClosure; |
|
53 |
||
54 |
// The abstract base GCTask. |
|
55 |
class GCTask : public ResourceObj { |
|
56 |
public: |
|
57 |
// Known kinds of GCTasks, for predicates. |
|
58 |
class Kind : AllStatic { |
|
59 |
public: |
|
60 |
enum kind { |
|
61 |
unknown_task, |
|
62 |
ordinary_task, |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
63 |
wait_for_barrier_task, |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
64 |
noop_task, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
65 |
idle_task |
1 | 66 |
}; |
67 |
static const char* to_string(kind value); |
|
68 |
}; |
|
69 |
private: |
|
70 |
// Instance state. |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
71 |
Kind::kind _kind; // For runtime type checking. |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
72 |
uint _affinity; // Which worker should run task. |
1 | 73 |
GCTask* _newer; // Tasks are on doubly-linked ... |
74 |
GCTask* _older; // ... lists. |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
75 |
uint _gc_id; // GC Id to use for the thread that executes this task |
1 | 76 |
public: |
77 |
virtual char* name() { return (char *)"task"; } |
|
78 |
||
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
79 |
uint gc_id() { return _gc_id; } |
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
80 |
|
1 | 81 |
// Abstract do_it method |
82 |
virtual void do_it(GCTaskManager* manager, uint which) = 0; |
|
83 |
// Accessors |
|
84 |
Kind::kind kind() const { |
|
85 |
return _kind; |
|
86 |
} |
|
87 |
uint affinity() const { |
|
88 |
return _affinity; |
|
89 |
} |
|
90 |
GCTask* newer() const { |
|
91 |
return _newer; |
|
92 |
} |
|
93 |
void set_newer(GCTask* n) { |
|
94 |
_newer = n; |
|
95 |
} |
|
96 |
GCTask* older() const { |
|
97 |
return _older; |
|
98 |
} |
|
99 |
void set_older(GCTask* p) { |
|
100 |
_older = p; |
|
101 |
} |
|
102 |
// Predicates. |
|
103 |
bool is_ordinary_task() const { |
|
104 |
return kind()==Kind::ordinary_task; |
|
105 |
} |
|
106 |
bool is_barrier_task() const { |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
107 |
return kind()==Kind::wait_for_barrier_task; |
1 | 108 |
} |
109 |
bool is_noop_task() const { |
|
110 |
return kind()==Kind::noop_task; |
|
111 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
112 |
bool is_idle_task() const { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
113 |
return kind()==Kind::idle_task; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
114 |
} |
1 | 115 |
void print(const char* message) const PRODUCT_RETURN; |
116 |
protected: |
|
117 |
// Constructors: Only create subclasses. |
|
118 |
// An ordinary GCTask. |
|
119 |
GCTask(); |
|
120 |
// A GCTask of a particular kind, usually barrier or noop. |
|
121 |
GCTask(Kind::kind kind); |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
122 |
GCTask(Kind::kind kind, uint gc_id); |
1 | 123 |
// We want a virtual destructor because virtual methods, |
124 |
// but since ResourceObj's don't have their destructors |
|
125 |
// called, we don't have one at all. Instead we have |
|
126 |
// this method, which gets called by subclasses to clean up. |
|
127 |
virtual void destruct(); |
|
128 |
// Methods. |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
129 |
void initialize(Kind::kind kind, uint gc_id); |
1 | 130 |
}; |
131 |
||
132 |
// A doubly-linked list of GCTasks. |
|
133 |
// The list is not synchronized, because sometimes we want to |
|
134 |
// build up a list and then make it available to other threads. |
|
135 |
// See also: SynchronizedGCTaskQueue. |
|
136 |
class GCTaskQueue : public ResourceObj { |
|
137 |
private: |
|
138 |
// Instance state. |
|
139 |
GCTask* _insert_end; // Tasks are enqueued at this end. |
|
140 |
GCTask* _remove_end; // Tasks are dequeued from this end. |
|
141 |
uint _length; // The current length of the queue. |
|
142 |
const bool _is_c_heap_obj; // Is this a CHeapObj? |
|
143 |
public: |
|
144 |
// Factory create and destroy methods. |
|
145 |
// Create as ResourceObj. |
|
146 |
static GCTaskQueue* create(); |
|
147 |
// Create as CHeapObj. |
|
148 |
static GCTaskQueue* create_on_c_heap(); |
|
149 |
// Destroyer. |
|
150 |
static void destroy(GCTaskQueue* that); |
|
151 |
// Accessors. |
|
152 |
// These just examine the state of the queue. |
|
153 |
bool is_empty() const { |
|
154 |
assert(((insert_end() == NULL && remove_end() == NULL) || |
|
155 |
(insert_end() != NULL && remove_end() != NULL)), |
|
156 |
"insert_end and remove_end don't match"); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
157 |
assert((insert_end() != NULL) || (_length == 0), "Not empty"); |
1 | 158 |
return insert_end() == NULL; |
159 |
} |
|
160 |
uint length() const { |
|
161 |
return _length; |
|
162 |
} |
|
163 |
// Methods. |
|
164 |
// Enqueue one task. |
|
165 |
void enqueue(GCTask* task); |
|
166 |
// Enqueue a list of tasks. Empties the argument list. |
|
167 |
void enqueue(GCTaskQueue* list); |
|
168 |
// Dequeue one task. |
|
169 |
GCTask* dequeue(); |
|
170 |
// Dequeue one task, preferring one with affinity. |
|
171 |
GCTask* dequeue(uint affinity); |
|
172 |
protected: |
|
173 |
// Constructor. Clients use factory, but there might be subclasses. |
|
174 |
GCTaskQueue(bool on_c_heap); |
|
175 |
// Destructor-like method. |
|
176 |
// Because ResourceMark doesn't call destructors. |
|
177 |
// This method cleans up like one. |
|
178 |
virtual void destruct(); |
|
179 |
// Accessors. |
|
180 |
GCTask* insert_end() const { |
|
181 |
return _insert_end; |
|
182 |
} |
|
183 |
void set_insert_end(GCTask* value) { |
|
184 |
_insert_end = value; |
|
185 |
} |
|
186 |
GCTask* remove_end() const { |
|
187 |
return _remove_end; |
|
188 |
} |
|
189 |
void set_remove_end(GCTask* value) { |
|
190 |
_remove_end = value; |
|
191 |
} |
|
192 |
void increment_length() { |
|
193 |
_length += 1; |
|
194 |
} |
|
195 |
void decrement_length() { |
|
196 |
_length -= 1; |
|
197 |
} |
|
198 |
void set_length(uint value) { |
|
199 |
_length = value; |
|
200 |
} |
|
201 |
bool is_c_heap_obj() const { |
|
202 |
return _is_c_heap_obj; |
|
203 |
} |
|
204 |
// Methods. |
|
205 |
void initialize(); |
|
206 |
GCTask* remove(); // Remove from remove end. |
|
207 |
GCTask* remove(GCTask* task); // Remove from the middle. |
|
208 |
void print(const char* message) const PRODUCT_RETURN; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
209 |
// Debug support |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
210 |
void verify_length() const PRODUCT_RETURN; |
1 | 211 |
}; |
212 |
||
213 |
// A GCTaskQueue that can be synchronized. |
|
214 |
// This "has-a" GCTaskQueue and a mutex to do the exclusion. |
|
13195 | 215 |
class SynchronizedGCTaskQueue : public CHeapObj<mtGC> { |
1 | 216 |
private: |
217 |
// Instance state. |
|
218 |
GCTaskQueue* _unsynchronized_queue; // Has-a unsynchronized queue. |
|
219 |
Monitor * _lock; // Lock to control access. |
|
220 |
public: |
|
221 |
// Factory create and destroy methods. |
|
222 |
static SynchronizedGCTaskQueue* create(GCTaskQueue* queue, Monitor * lock) { |
|
223 |
return new SynchronizedGCTaskQueue(queue, lock); |
|
224 |
} |
|
225 |
static void destroy(SynchronizedGCTaskQueue* that) { |
|
226 |
if (that != NULL) { |
|
227 |
delete that; |
|
228 |
} |
|
229 |
} |
|
230 |
// Accessors |
|
231 |
GCTaskQueue* unsynchronized_queue() const { |
|
232 |
return _unsynchronized_queue; |
|
233 |
} |
|
234 |
Monitor * lock() const { |
|
235 |
return _lock; |
|
236 |
} |
|
237 |
// GCTaskQueue wrapper methods. |
|
238 |
// These check that you hold the lock |
|
239 |
// and then call the method on the queue. |
|
240 |
bool is_empty() const { |
|
241 |
guarantee(own_lock(), "don't own the lock"); |
|
242 |
return unsynchronized_queue()->is_empty(); |
|
243 |
} |
|
244 |
void enqueue(GCTask* task) { |
|
245 |
guarantee(own_lock(), "don't own the lock"); |
|
246 |
unsynchronized_queue()->enqueue(task); |
|
247 |
} |
|
248 |
void enqueue(GCTaskQueue* list) { |
|
249 |
guarantee(own_lock(), "don't own the lock"); |
|
250 |
unsynchronized_queue()->enqueue(list); |
|
251 |
} |
|
252 |
GCTask* dequeue() { |
|
253 |
guarantee(own_lock(), "don't own the lock"); |
|
254 |
return unsynchronized_queue()->dequeue(); |
|
255 |
} |
|
256 |
GCTask* dequeue(uint affinity) { |
|
257 |
guarantee(own_lock(), "don't own the lock"); |
|
258 |
return unsynchronized_queue()->dequeue(affinity); |
|
259 |
} |
|
260 |
uint length() const { |
|
261 |
guarantee(own_lock(), "don't own the lock"); |
|
262 |
return unsynchronized_queue()->length(); |
|
263 |
} |
|
264 |
// For guarantees. |
|
265 |
bool own_lock() const { |
|
266 |
return lock()->owned_by_self(); |
|
267 |
} |
|
268 |
protected: |
|
269 |
// Constructor. Clients use factory, but there might be subclasses. |
|
270 |
SynchronizedGCTaskQueue(GCTaskQueue* queue, Monitor * lock); |
|
271 |
// Destructor. Not virtual because no virtuals. |
|
272 |
~SynchronizedGCTaskQueue(); |
|
273 |
}; |
|
274 |
||
49392
2956d0ece7a9
8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents:
47216
diff
changeset
|
275 |
class WaitHelper { |
33125 | 276 |
private: |
277 |
Monitor* _monitor; |
|
278 |
volatile bool _should_wait; |
|
279 |
public: |
|
280 |
WaitHelper(); |
|
281 |
~WaitHelper(); |
|
282 |
void wait_for(bool reset); |
|
283 |
void notify(); |
|
284 |
void set_should_wait(bool value) { |
|
285 |
_should_wait = value; |
|
286 |
} |
|
287 |
||
288 |
Monitor* monitor() const { |
|
289 |
return _monitor; |
|
290 |
} |
|
291 |
bool should_wait() const { |
|
292 |
return _should_wait; |
|
293 |
} |
|
294 |
void release_monitor(); |
|
295 |
}; |
|
296 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
297 |
// Dynamic number of GC threads |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
298 |
// |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
299 |
// GC threads wait in get_task() for work (i.e., a task) to perform. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
300 |
// When the number of GC threads was static, the number of tasks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
301 |
// created to do a job was equal to or greater than the maximum |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
302 |
// number of GC threads (ParallelGCThreads). The job might be divided |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
303 |
// into a number of tasks greater than the number of GC threads for |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
304 |
// load balancing (i.e., over partitioning). The last task to be |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
305 |
// executed by a GC thread in a job is a work stealing task. A |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
306 |
// GC thread that gets a work stealing task continues to execute |
22551 | 307 |
// that task until the job is done. In the static number of GC threads |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
308 |
// case, tasks are added to a queue (FIFO). The work stealing tasks are |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
309 |
// the last to be added. Once the tasks are added, the GC threads grab |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
310 |
// a task and go. A single thread can do all the non-work stealing tasks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
311 |
// and then execute a work stealing and wait for all the other GC threads |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
312 |
// to execute their work stealing task. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
313 |
// In the dynamic number of GC threads implementation, idle-tasks are |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
314 |
// created to occupy the non-participating or "inactive" threads. An |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
315 |
// idle-task makes the GC thread wait on a barrier that is part of the |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
316 |
// GCTaskManager. The GC threads that have been "idled" in a IdleGCTask |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
317 |
// are released once all the active GC threads have finished their work |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
318 |
// stealing tasks. The GCTaskManager does not wait for all the "idled" |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
319 |
// GC threads to resume execution. When those GC threads do resume |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
320 |
// execution in the course of the thread scheduling, they call get_tasks() |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
321 |
// as all the other GC threads do. Because all the "idled" threads are |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
322 |
// not required to execute in order to finish a job, it is possible for |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
323 |
// a GC thread to still be "idled" when the next job is started. Such |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
324 |
// a thread stays "idled" for the next job. This can result in a new |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
325 |
// job not having all the expected active workers. For example if on |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
326 |
// job requests 4 active workers out of a total of 10 workers so the |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
327 |
// remaining 6 are "idled", if the next job requests 6 active workers |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
328 |
// but all 6 of the "idled" workers are still idle, then the next job |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
329 |
// will only get 4 active workers. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
330 |
// The implementation for the parallel old compaction phase has an |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
331 |
// added complication. In the static case parold partitions the chunks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
332 |
// ready to be filled into stacks, one for each GC thread. A GC thread |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
333 |
// executing a draining task (drains the stack of ready chunks) |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
334 |
// claims a stack according to it's id (the unique ordinal value assigned |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
335 |
// to each GC thread). In the dynamic case not all GC threads will |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
336 |
// actively participate so stacks with ready to fill chunks can only be |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
337 |
// given to the active threads. An initial implementation chose stacks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
338 |
// number 1-n to get the ready chunks and required that GC threads |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
339 |
// 1-n be the active workers. This was undesirable because it required |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
340 |
// certain threads to participate. In the final implementation a |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
341 |
// list of stacks equal in number to the active workers are filled |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
342 |
// with ready chunks. GC threads that participate get a stack from |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
343 |
// the task (DrainStacksCompactionTask), empty the stack, and then add it to a |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
344 |
// recycling list at the end of the task. If the same GC thread gets |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
345 |
// a second task, it gets a second stack to drain and returns it. The |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
346 |
// stacks are added to a recycling list so that later stealing tasks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
347 |
// for this tasks can get a stack from the recycling list. Stealing tasks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
348 |
// use the stacks in its work in a way similar to the draining tasks. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
349 |
// A thread is not guaranteed to get anything but a stealing task and |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
350 |
// a thread that only gets a stealing task has to get a stack. A failed |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
351 |
// implementation tried to have the GC threads keep the stack they used |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
352 |
// during a draining task for later use in the stealing task but that didn't |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
353 |
// work because as noted a thread is not guaranteed to get a draining task. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
354 |
// |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
355 |
// For PSScavenge and ParCompactionManager the GC threads are |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
356 |
// held in the GCTaskThread** _thread array in GCTaskManager. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
357 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
358 |
|
13195 | 359 |
class GCTaskManager : public CHeapObj<mtGC> { |
1 | 360 |
friend class ParCompactionManager; |
361 |
friend class PSParallelCompact; |
|
362 |
friend class PSScavenge; |
|
363 |
friend class PSRefProcTaskExecutor; |
|
364 |
friend class RefProcTaskExecutor; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
365 |
friend class GCTaskThread; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
366 |
friend class IdleGCTask; |
1 | 367 |
private: |
368 |
// Instance state. |
|
369 |
const uint _workers; // Number of workers. |
|
370 |
Monitor* _monitor; // Notification of changes. |
|
371 |
SynchronizedGCTaskQueue* _queue; // Queue of tasks. |
|
372 |
GCTaskThread** _thread; // Array of worker threads. |
|
38216 | 373 |
uint _created_workers; // Number of workers created. |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
374 |
uint _active_workers; // Number of active workers. |
1 | 375 |
uint _busy_workers; // Number of busy workers. |
376 |
uint _blocking_worker; // The worker that's blocking. |
|
377 |
bool* _resource_flag; // Array of flag per threads. |
|
378 |
uint _delivered_tasks; // Count of delivered tasks. |
|
379 |
uint _completed_tasks; // Count of completed tasks. |
|
380 |
uint _barriers; // Count of barrier tasks. |
|
381 |
uint _emptied_queue; // Times we emptied the queue. |
|
382 |
NoopGCTask* _noop_task; // The NoopGCTask instance. |
|
33125 | 383 |
WaitHelper _wait_helper; // Used by inactive worker |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
384 |
volatile uint _idle_workers; // Number of idled workers |
38216 | 385 |
uint* _processor_assignment; // Worker to cpu mappings. May |
386 |
// be used lazily |
|
1 | 387 |
public: |
388 |
// Factory create and destroy methods. |
|
389 |
static GCTaskManager* create(uint workers) { |
|
390 |
return new GCTaskManager(workers); |
|
391 |
} |
|
392 |
static void destroy(GCTaskManager* that) { |
|
393 |
if (that != NULL) { |
|
394 |
delete that; |
|
395 |
} |
|
396 |
} |
|
397 |
// Accessors. |
|
398 |
uint busy_workers() const { |
|
399 |
return _busy_workers; |
|
400 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
401 |
volatile uint idle_workers() const { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
402 |
return _idle_workers; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
403 |
} |
1 | 404 |
// Pun between Monitor* and Mutex* |
405 |
Monitor* monitor() const { |
|
406 |
return _monitor; |
|
407 |
} |
|
408 |
Monitor * lock() const { |
|
409 |
return _monitor; |
|
410 |
} |
|
33125 | 411 |
WaitHelper* wait_helper() { |
412 |
return &_wait_helper; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
413 |
} |
1 | 414 |
// Methods. |
415 |
// Add the argument task to be run. |
|
416 |
void add_task(GCTask* task); |
|
417 |
// Add a list of tasks. Removes task from the argument list. |
|
418 |
void add_list(GCTaskQueue* list); |
|
419 |
// Claim a task for argument worker. |
|
420 |
GCTask* get_task(uint which); |
|
421 |
// Note the completion of a task by the argument worker. |
|
422 |
void note_completion(uint which); |
|
423 |
// Is the queue blocked from handing out new tasks? |
|
424 |
bool is_blocked() const { |
|
425 |
return (blocking_worker() != sentinel_worker()); |
|
426 |
} |
|
427 |
// Request that all workers release their resources. |
|
428 |
void release_all_resources(); |
|
429 |
// Ask if a particular worker should release its resources. |
|
430 |
bool should_release_resources(uint which); // Predicate. |
|
431 |
// Note the release of resources by the argument worker. |
|
432 |
void note_release(uint which); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
433 |
// Create IdleGCTasks for inactive workers and start workers |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
434 |
void task_idle_workers(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
435 |
// Release the workers in IdleGCTasks |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
436 |
void release_idle_workers(); |
1 | 437 |
// Constants. |
438 |
// A sentinel worker identifier. |
|
439 |
static uint sentinel_worker() { |
|
440 |
return (uint) -1; // Why isn't there a max_uint? |
|
441 |
} |
|
442 |
||
443 |
// Execute the task queue and wait for the completion. |
|
444 |
void execute_and_wait(GCTaskQueue* list); |
|
445 |
||
446 |
void print_task_time_stamps(); |
|
447 |
void print_threads_on(outputStream* st); |
|
448 |
void threads_do(ThreadClosure* tc); |
|
449 |
||
450 |
protected: |
|
451 |
// Constructors. Clients use factory, but there might be subclasses. |
|
452 |
// Create a GCTaskManager with the appropriate number of workers. |
|
453 |
GCTaskManager(uint workers); |
|
454 |
// Make virtual if necessary. |
|
455 |
~GCTaskManager(); |
|
456 |
// Accessors. |
|
457 |
uint workers() const { |
|
458 |
return _workers; |
|
459 |
} |
|
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
460 |
uint update_active_workers(uint v) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
461 |
assert(v <= _workers, "Trying to set more workers active than there are"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
462 |
_active_workers = MIN2(v, _workers); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
463 |
assert(v != 0, "Trying to set active workers to 0"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
464 |
_active_workers = MAX2(1U, _active_workers); |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
465 |
return _active_workers; |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
466 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
467 |
// Sets the number of threads that will be used in a collection |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
468 |
void set_active_gang(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
469 |
|
1 | 470 |
SynchronizedGCTaskQueue* queue() const { |
471 |
return _queue; |
|
472 |
} |
|
473 |
NoopGCTask* noop_task() const { |
|
474 |
return _noop_task; |
|
475 |
} |
|
476 |
// Bounds-checking per-thread data accessors. |
|
477 |
GCTaskThread* thread(uint which); |
|
478 |
void set_thread(uint which, GCTaskThread* value); |
|
479 |
bool resource_flag(uint which); |
|
480 |
void set_resource_flag(uint which, bool value); |
|
481 |
// Modifier methods with some semantics. |
|
482 |
// Is any worker blocking handing out new tasks? |
|
483 |
uint blocking_worker() const { |
|
484 |
return _blocking_worker; |
|
485 |
} |
|
486 |
void set_blocking_worker(uint value) { |
|
487 |
_blocking_worker = value; |
|
488 |
} |
|
489 |
void set_unblocked() { |
|
490 |
set_blocking_worker(sentinel_worker()); |
|
491 |
} |
|
492 |
// Count of busy workers. |
|
493 |
void reset_busy_workers() { |
|
494 |
_busy_workers = 0; |
|
495 |
} |
|
496 |
uint increment_busy_workers(); |
|
497 |
uint decrement_busy_workers(); |
|
498 |
// Count of tasks delivered to workers. |
|
499 |
uint delivered_tasks() const { |
|
500 |
return _delivered_tasks; |
|
501 |
} |
|
502 |
void increment_delivered_tasks() { |
|
503 |
_delivered_tasks += 1; |
|
504 |
} |
|
505 |
void reset_delivered_tasks() { |
|
506 |
_delivered_tasks = 0; |
|
507 |
} |
|
508 |
// Count of tasks completed by workers. |
|
509 |
uint completed_tasks() const { |
|
510 |
return _completed_tasks; |
|
511 |
} |
|
512 |
void increment_completed_tasks() { |
|
513 |
_completed_tasks += 1; |
|
514 |
} |
|
515 |
void reset_completed_tasks() { |
|
516 |
_completed_tasks = 0; |
|
517 |
} |
|
518 |
// Count of barrier tasks completed. |
|
519 |
uint barriers() const { |
|
520 |
return _barriers; |
|
521 |
} |
|
522 |
void increment_barriers() { |
|
523 |
_barriers += 1; |
|
524 |
} |
|
525 |
void reset_barriers() { |
|
526 |
_barriers = 0; |
|
527 |
} |
|
528 |
// Count of how many times the queue has emptied. |
|
529 |
uint emptied_queue() const { |
|
530 |
return _emptied_queue; |
|
531 |
} |
|
532 |
void increment_emptied_queue() { |
|
533 |
_emptied_queue += 1; |
|
534 |
} |
|
535 |
void reset_emptied_queue() { |
|
536 |
_emptied_queue = 0; |
|
537 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
538 |
void increment_idle_workers() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
539 |
_idle_workers++; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
540 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
541 |
void decrement_idle_workers() { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
542 |
_idle_workers--; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
543 |
} |
1 | 544 |
// Other methods. |
545 |
void initialize(); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
546 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
547 |
public: |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
548 |
// Return true if all workers are currently active. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
549 |
bool all_workers_active() { return workers() == active_workers(); } |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
550 |
uint active_workers() const { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
551 |
return _active_workers; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
552 |
} |
38216 | 553 |
uint created_workers() const { |
554 |
return _created_workers; |
|
555 |
} |
|
556 |
// Create a GC worker and install into GCTaskManager |
|
557 |
GCTaskThread* install_worker(uint worker_id); |
|
558 |
// Add GC workers as needed. |
|
559 |
void add_workers(bool initializing); |
|
39704 | 560 |
// Base name (without worker id #) of threads. |
561 |
const char* group_name(); |
|
1 | 562 |
}; |
563 |
||
564 |
// |
|
565 |
// Some exemplary GCTasks. |
|
566 |
// |
|
567 |
||
568 |
// A noop task that does nothing, |
|
569 |
// except take us around the GCTaskThread loop. |
|
570 |
class NoopGCTask : public GCTask { |
|
571 |
public: |
|
572 |
// Factory create and destroy methods. |
|
573 |
static NoopGCTask* create_on_c_heap(); |
|
574 |
static void destroy(NoopGCTask* that); |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
575 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
576 |
virtual char* name() { return (char *)"noop task"; } |
1 | 577 |
// Methods from GCTask. |
578 |
void do_it(GCTaskManager* manager, uint which) { |
|
579 |
// Nothing to do. |
|
580 |
} |
|
581 |
protected: |
|
582 |
// Constructor. |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
33125
diff
changeset
|
583 |
NoopGCTask(); |
1 | 584 |
// Destructor-like method. |
585 |
void destruct(); |
|
586 |
}; |
|
587 |
||
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
588 |
// A WaitForBarrierGCTask is a GCTask |
1 | 589 |
// with a method you can call to wait until |
590 |
// the BarrierGCTask is done. |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
591 |
class WaitForBarrierGCTask : public GCTask { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
592 |
friend class GCTaskManager; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
593 |
friend class IdleGCTask; |
1 | 594 |
private: |
595 |
// Instance state. |
|
33125 | 596 |
WaitHelper _wait_helper; |
597 |
WaitForBarrierGCTask(); |
|
1 | 598 |
public: |
599 |
virtual char* name() { return (char *) "waitfor-barrier-task"; } |
|
600 |
||
601 |
// Factory create and destroy methods. |
|
602 |
static WaitForBarrierGCTask* create(); |
|
603 |
static void destroy(WaitForBarrierGCTask* that); |
|
604 |
// Methods. |
|
605 |
void do_it(GCTaskManager* manager, uint which); |
|
606 |
protected: |
|
607 |
// Destructor-like method. |
|
608 |
void destruct(); |
|
33124
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
609 |
|
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
610 |
// Methods. |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
611 |
// Wait for this to be the only task running. |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
612 |
void do_it_internal(GCTaskManager* manager, uint which); |
e256f7a94c38
8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents:
30764
diff
changeset
|
613 |
|
33125 | 614 |
void wait_for(bool reset) { |
615 |
_wait_helper.wait_for(reset); |
|
1 | 616 |
} |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
617 |
}; |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
618 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
619 |
// Task that is used to idle a GC task when fewer than |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
620 |
// the maximum workers are wanted. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
621 |
class IdleGCTask : public GCTask { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
622 |
const bool _is_c_heap_obj; // Was allocated on the heap. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
623 |
public: |
1 | 624 |
bool is_c_heap_obj() { |
625 |
return _is_c_heap_obj; |
|
626 |
} |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
627 |
// Factory create and destroy methods. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
628 |
static IdleGCTask* create(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
629 |
static IdleGCTask* create_on_c_heap(); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
630 |
static void destroy(IdleGCTask* that); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
631 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
632 |
virtual char* name() { return (char *)"idle task"; } |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
633 |
// Methods from GCTask. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
634 |
virtual void do_it(GCTaskManager* manager, uint which); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
635 |
protected: |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
636 |
// Constructor. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
637 |
IdleGCTask(bool on_c_heap) : |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
638 |
GCTask(GCTask::Kind::idle_task), |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
639 |
_is_c_heap_obj(on_c_heap) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
640 |
// Nothing to do. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
641 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
642 |
// Destructor-like method. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
643 |
void destruct(); |
1 | 644 |
}; |
645 |
||
646 |
class MonitorSupply : public AllStatic { |
|
647 |
private: |
|
648 |
// State. |
|
649 |
// Control multi-threaded access. |
|
650 |
static Mutex* _lock; |
|
651 |
// The list of available Monitor*'s. |
|
652 |
static GrowableArray<Monitor*>* _freelist; |
|
653 |
public: |
|
654 |
// Reserve a Monitor*. |
|
655 |
static Monitor* reserve(); |
|
656 |
// Release a Monitor*. |
|
657 |
static void release(Monitor* instance); |
|
658 |
private: |
|
659 |
// Accessors. |
|
660 |
static Mutex* lock() { |
|
661 |
return _lock; |
|
662 |
} |
|
663 |
static GrowableArray<Monitor*>* freelist() { |
|
664 |
return _freelist; |
|
665 |
} |
|
666 |
}; |
|
7397 | 667 |
|
30764 | 668 |
#endif // SHARE_VM_GC_PARALLEL_GCTASKMANAGER_HPP |