author | jlaskey |
Tue, 23 Jul 2013 12:00:29 -0300 | |
changeset 19089 | 51cfdcf21d35 |
parent 15482 | 470d0b0c09f1 |
child 19974 | 0d2f09f4643c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
6763
711b8a44c4dd
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
6759
diff
changeset
|
2 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1374
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1374
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1374
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |
26 |
#define SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |
|
27 |
||
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14841
diff
changeset
|
28 |
#include "utilities/macros.hpp" |
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14841
diff
changeset
|
29 |
#if INCLUDE_ALL_GCS |
7397 | 30 |
#include "utilities/workgroup.hpp" |
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14841
diff
changeset
|
31 |
#endif // INCLUDE_ALL_GCS |
7397 | 32 |
|
1 | 33 |
|
34 |
// Forward declarations |
|
35 |
class YieldingFlexibleWorkGang; |
|
36 |
||
37 |
// Status of tasks |
|
38 |
enum Status { |
|
39 |
INACTIVE, |
|
40 |
ACTIVE, |
|
41 |
YIELDING, |
|
42 |
YIELDED, |
|
43 |
ABORTING, |
|
44 |
ABORTED, |
|
45 |
COMPLETING, |
|
46 |
COMPLETED |
|
47 |
}; |
|
48 |
||
49 |
// Class YieldingFlexibleGangWorker: |
|
50 |
// Several instances of this class run in parallel as workers for a gang. |
|
51 |
class YieldingFlexibleGangWorker: public GangWorker { |
|
52 |
public: |
|
53 |
// Ctor |
|
54 |
YieldingFlexibleGangWorker(AbstractWorkGang* gang, int id) : |
|
55 |
GangWorker(gang, id) { } |
|
56 |
||
57 |
public: |
|
58 |
YieldingFlexibleWorkGang* yf_gang() const |
|
59 |
{ return (YieldingFlexibleWorkGang*)gang(); } |
|
60 |
||
61 |
protected: // Override from parent class |
|
62 |
virtual void loop(); |
|
63 |
}; |
|
64 |
||
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
65 |
class FlexibleGangTask: public AbstractGangTask { |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
66 |
int _actual_size; // size of gang obtained |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
67 |
protected: |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
68 |
int _requested_size; // size of gang requested |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
69 |
public: |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
70 |
FlexibleGangTask(const char* name): AbstractGangTask(name), |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
71 |
_requested_size(0) {} |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
72 |
|
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
73 |
// The abstract work method. |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
74 |
// 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
|
75 |
virtual void work(uint worker_id) = 0; |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
76 |
|
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
77 |
int requested_size() const { return _requested_size; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
78 |
int actual_size() const { return _actual_size; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
79 |
|
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
80 |
void set_requested_size(int sz) { _requested_size = sz; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
81 |
void set_actual_size(int sz) { _actual_size = sz; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
82 |
}; |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
83 |
|
1 | 84 |
// An abstract task to be worked on by a flexible work gang, |
85 |
// and where the workers will periodically yield, usually |
|
86 |
// in response to some condition that is signalled by means |
|
87 |
// that are specific to the task at hand. |
|
88 |
// You subclass this to supply your own work() method. |
|
89 |
// A second feature of this kind of work gang is that |
|
90 |
// it allows for the signalling of certain exceptional |
|
91 |
// conditions that may be encountered during the performance |
|
92 |
// of the task and that may require the task at hand to be |
|
93 |
// `aborted' forthwith. Finally, these gangs are `flexible' |
|
94 |
// in that they can operate at partial capacity with some |
|
95 |
// gang workers waiting on the bench; in other words, the |
|
96 |
// size of the active worker pool can flex (up to an apriori |
|
97 |
// maximum) in response to task requests at certain points. |
|
98 |
// The last part (the flexible part) has not yet been fully |
|
99 |
// fleshed out and is a work in progress. |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
100 |
class YieldingFlexibleGangTask: public FlexibleGangTask { |
1 | 101 |
Status _status; |
102 |
YieldingFlexibleWorkGang* _gang; |
|
103 |
||
104 |
protected: |
|
105 |
// Constructor and desctructor: only construct subclasses. |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
106 |
YieldingFlexibleGangTask(const char* name): FlexibleGangTask(name), |
1 | 107 |
_status(INACTIVE), |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
108 |
_gang(NULL) { } |
1 | 109 |
|
14841
d069f5506f71
8004845: Catch incorrect usage of new and delete during compile time for value objects and stack objects
brutisso
parents:
11396
diff
changeset
|
110 |
~YieldingFlexibleGangTask() { } |
1 | 111 |
|
112 |
friend class YieldingFlexibleWorkGang; |
|
113 |
friend class YieldingFlexibleGangWorker; |
|
114 |
NOT_PRODUCT(virtual bool is_YieldingFlexibleGang_task() const { |
|
115 |
return true; |
|
116 |
}) |
|
117 |
||
118 |
void set_status(Status s) { |
|
119 |
_status = s; |
|
120 |
} |
|
121 |
YieldingFlexibleWorkGang* gang() { |
|
122 |
return _gang; |
|
123 |
} |
|
124 |
void set_gang(YieldingFlexibleWorkGang* gang) { |
|
125 |
assert(_gang == NULL || gang == NULL, "Clobber without intermediate reset?"); |
|
126 |
_gang = gang; |
|
127 |
} |
|
128 |
||
129 |
public: |
|
130 |
// The abstract work method. |
|
131 |
// 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
|
132 |
virtual void work(uint worker_id) = 0; |
1 | 133 |
|
134 |
// Subclasses should call the parent's yield() method |
|
135 |
// after having done any work specific to the subclass. |
|
136 |
virtual void yield(); |
|
137 |
||
138 |
// An abstract method supplied by |
|
139 |
// a concrete sub-class which is used by the coordinator |
|
140 |
// to do any "central yielding" work. |
|
141 |
virtual void coordinator_yield() = 0; |
|
142 |
||
143 |
// Subclasses should call the parent's abort() method |
|
144 |
// after having done any work specific to the sunbclass. |
|
145 |
virtual void abort(); |
|
146 |
||
147 |
Status status() const { return _status; } |
|
6763
711b8a44c4dd
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
6759
diff
changeset
|
148 |
bool yielding() const { return _status == YIELDING; } |
1 | 149 |
bool yielded() const { return _status == YIELDED; } |
150 |
bool completed() const { return _status == COMPLETED; } |
|
151 |
bool aborted() const { return _status == ABORTED; } |
|
152 |
bool active() const { return _status == ACTIVE; } |
|
153 |
}; |
|
154 |
// Class YieldingWorkGang: A subclass of WorkGang. |
|
155 |
// In particular, a YieldingWorkGang is made up of |
|
156 |
// YieldingGangWorkers, and provides infrastructure |
|
157 |
// supporting yielding to the "GangOverseer", |
|
158 |
// being the thread that orchestrates the WorkGang via run_task(). |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
159 |
class YieldingFlexibleWorkGang: public FlexibleWorkGang { |
1 | 160 |
// Here's the public interface to this class. |
161 |
public: |
|
162 |
// Constructor and destructor. |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
163 |
YieldingFlexibleWorkGang(const char* name, uint workers, |
1374 | 164 |
bool are_GC_task_threads); |
1 | 165 |
|
166 |
YieldingFlexibleGangTask* yielding_task() const { |
|
167 |
assert(task() == NULL || task()->is_YieldingFlexibleGang_task(), |
|
168 |
"Incorrect cast"); |
|
169 |
return (YieldingFlexibleGangTask*)task(); |
|
170 |
} |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
171 |
// Allocate a worker and return a pointer to it. |
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
172 |
GangWorker* allocate_worker(uint which); |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
173 |
|
1 | 174 |
// Run a task; returns when the task is done, or the workers yield, |
175 |
// or the task is aborted, or the work gang is terminated via stop(). |
|
176 |
// A task that has been yielded can be continued via this same interface |
|
177 |
// by using the same task repeatedly as the argument to the call. |
|
178 |
// It is expected that the YieldingFlexibleGangTask carries the appropriate |
|
179 |
// continuation information used by workers to continue the task |
|
180 |
// from its last yield point. Thus, a completed task will return |
|
181 |
// immediately with no actual work having been done by the workers. |
|
182 |
void run_task(AbstractGangTask* task) { |
|
183 |
guarantee(false, "Use start_task instead"); |
|
184 |
} |
|
185 |
void start_task(YieldingFlexibleGangTask* new_task); |
|
186 |
void continue_task(YieldingFlexibleGangTask* gang_task); |
|
187 |
||
188 |
// Abort a currently running task, if any; returns when all the workers |
|
189 |
// have stopped working on the current task and have returned to their |
|
190 |
// waiting stations. |
|
191 |
void abort_task(); |
|
192 |
||
193 |
// Yield: workers wait at their current working stations |
|
194 |
// until signalled to proceed by the overseer. |
|
195 |
void yield(); |
|
196 |
||
197 |
// Abort: workers are expected to return to their waiting |
|
198 |
// stations, whence they are ready for the next task dispatched |
|
199 |
// by the overseer. |
|
200 |
void abort(); |
|
201 |
||
202 |
private: |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
203 |
uint _yielded_workers; |
1 | 204 |
void wait_for_gang(); |
205 |
||
206 |
public: |
|
207 |
// Accessors for fields |
|
11396
917d8673b5ef
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
11174
diff
changeset
|
208 |
uint yielded_workers() const { |
1 | 209 |
return _yielded_workers; |
210 |
} |
|
211 |
||
212 |
private: |
|
213 |
friend class YieldingFlexibleGangWorker; |
|
214 |
void reset(); // NYI |
|
215 |
}; |
|
7397 | 216 |
|
217 |
#endif // SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |