author | ysr |
Wed, 29 Sep 2010 16:17:02 -0700 | |
changeset 6763 | 711b8a44c4dd |
parent 6759 | 67b1a69ef5aa |
child 7397 | 5b173b4ca846 |
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 |
||
25 |
||
26 |
// Forward declarations |
|
27 |
class YieldingFlexibleWorkGang; |
|
28 |
||
29 |
// Status of tasks |
|
30 |
enum Status { |
|
31 |
INACTIVE, |
|
32 |
ACTIVE, |
|
33 |
YIELDING, |
|
34 |
YIELDED, |
|
35 |
ABORTING, |
|
36 |
ABORTED, |
|
37 |
COMPLETING, |
|
38 |
COMPLETED |
|
39 |
}; |
|
40 |
||
41 |
// Class YieldingFlexibleGangWorker: |
|
42 |
// Several instances of this class run in parallel as workers for a gang. |
|
43 |
class YieldingFlexibleGangWorker: public GangWorker { |
|
44 |
public: |
|
45 |
// Ctor |
|
46 |
YieldingFlexibleGangWorker(AbstractWorkGang* gang, int id) : |
|
47 |
GangWorker(gang, id) { } |
|
48 |
||
49 |
public: |
|
50 |
YieldingFlexibleWorkGang* yf_gang() const |
|
51 |
{ return (YieldingFlexibleWorkGang*)gang(); } |
|
52 |
||
53 |
protected: // Override from parent class |
|
54 |
virtual void loop(); |
|
55 |
}; |
|
56 |
||
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
57 |
class FlexibleGangTask: public AbstractGangTask { |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
58 |
int _actual_size; // size of gang obtained |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
59 |
protected: |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
60 |
int _requested_size; // size of gang requested |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
61 |
public: |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
62 |
FlexibleGangTask(const char* name): AbstractGangTask(name), |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
63 |
_requested_size(0) {} |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
64 |
|
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
65 |
// The abstract work method. |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
66 |
// The argument tells you which member of the gang you are. |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
67 |
virtual void work(int i) = 0; |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
68 |
|
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
69 |
int requested_size() const { return _requested_size; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
70 |
int actual_size() const { return _actual_size; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
71 |
|
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
72 |
void set_requested_size(int sz) { _requested_size = sz; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
73 |
void set_actual_size(int sz) { _actual_size = sz; } |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
74 |
}; |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
75 |
|
1 | 76 |
// An abstract task to be worked on by a flexible work gang, |
77 |
// and where the workers will periodically yield, usually |
|
78 |
// in response to some condition that is signalled by means |
|
79 |
// that are specific to the task at hand. |
|
80 |
// You subclass this to supply your own work() method. |
|
81 |
// A second feature of this kind of work gang is that |
|
82 |
// it allows for the signalling of certain exceptional |
|
83 |
// conditions that may be encountered during the performance |
|
84 |
// of the task and that may require the task at hand to be |
|
85 |
// `aborted' forthwith. Finally, these gangs are `flexible' |
|
86 |
// in that they can operate at partial capacity with some |
|
87 |
// gang workers waiting on the bench; in other words, the |
|
88 |
// size of the active worker pool can flex (up to an apriori |
|
89 |
// maximum) in response to task requests at certain points. |
|
90 |
// The last part (the flexible part) has not yet been fully |
|
91 |
// fleshed out and is a work in progress. |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
92 |
class YieldingFlexibleGangTask: public FlexibleGangTask { |
1 | 93 |
Status _status; |
94 |
YieldingFlexibleWorkGang* _gang; |
|
95 |
||
96 |
protected: |
|
97 |
// Constructor and desctructor: only construct subclasses. |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
98 |
YieldingFlexibleGangTask(const char* name): FlexibleGangTask(name), |
1 | 99 |
_status(INACTIVE), |
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
100 |
_gang(NULL) { } |
1 | 101 |
|
102 |
virtual ~YieldingFlexibleGangTask() { } |
|
103 |
||
104 |
friend class YieldingFlexibleWorkGang; |
|
105 |
friend class YieldingFlexibleGangWorker; |
|
106 |
NOT_PRODUCT(virtual bool is_YieldingFlexibleGang_task() const { |
|
107 |
return true; |
|
108 |
}) |
|
109 |
||
110 |
void set_status(Status s) { |
|
111 |
_status = s; |
|
112 |
} |
|
113 |
YieldingFlexibleWorkGang* gang() { |
|
114 |
return _gang; |
|
115 |
} |
|
116 |
void set_gang(YieldingFlexibleWorkGang* gang) { |
|
117 |
assert(_gang == NULL || gang == NULL, "Clobber without intermediate reset?"); |
|
118 |
_gang = gang; |
|
119 |
} |
|
120 |
||
121 |
public: |
|
122 |
// The abstract work method. |
|
123 |
// The argument tells you which member of the gang you are. |
|
124 |
virtual void work(int i) = 0; |
|
125 |
||
126 |
// Subclasses should call the parent's yield() method |
|
127 |
// after having done any work specific to the subclass. |
|
128 |
virtual void yield(); |
|
129 |
||
130 |
// An abstract method supplied by |
|
131 |
// a concrete sub-class which is used by the coordinator |
|
132 |
// to do any "central yielding" work. |
|
133 |
virtual void coordinator_yield() = 0; |
|
134 |
||
135 |
// Subclasses should call the parent's abort() method |
|
136 |
// after having done any work specific to the sunbclass. |
|
137 |
virtual void abort(); |
|
138 |
||
139 |
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
|
140 |
bool yielding() const { return _status == YIELDING; } |
1 | 141 |
bool yielded() const { return _status == YIELDED; } |
142 |
bool completed() const { return _status == COMPLETED; } |
|
143 |
bool aborted() const { return _status == ABORTED; } |
|
144 |
bool active() const { return _status == ACTIVE; } |
|
145 |
}; |
|
146 |
// Class YieldingWorkGang: A subclass of WorkGang. |
|
147 |
// In particular, a YieldingWorkGang is made up of |
|
148 |
// YieldingGangWorkers, and provides infrastructure |
|
149 |
// supporting yielding to the "GangOverseer", |
|
150 |
// 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
|
151 |
class YieldingFlexibleWorkGang: public FlexibleWorkGang { |
1 | 152 |
// Here's the public interface to this class. |
153 |
public: |
|
154 |
// Constructor and destructor. |
|
1374 | 155 |
YieldingFlexibleWorkGang(const char* name, int workers, |
156 |
bool are_GC_task_threads); |
|
1 | 157 |
|
158 |
YieldingFlexibleGangTask* yielding_task() const { |
|
159 |
assert(task() == NULL || task()->is_YieldingFlexibleGang_task(), |
|
160 |
"Incorrect cast"); |
|
161 |
return (YieldingFlexibleGangTask*)task(); |
|
162 |
} |
|
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
163 |
// Allocate a worker and return a pointer to it. |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
164 |
GangWorker* allocate_worker(int which); |
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
165 |
|
1 | 166 |
// Run a task; returns when the task is done, or the workers yield, |
167 |
// or the task is aborted, or the work gang is terminated via stop(). |
|
168 |
// A task that has been yielded can be continued via this same interface |
|
169 |
// by using the same task repeatedly as the argument to the call. |
|
170 |
// It is expected that the YieldingFlexibleGangTask carries the appropriate |
|
171 |
// continuation information used by workers to continue the task |
|
172 |
// from its last yield point. Thus, a completed task will return |
|
173 |
// immediately with no actual work having been done by the workers. |
|
174 |
void run_task(AbstractGangTask* task) { |
|
175 |
guarantee(false, "Use start_task instead"); |
|
176 |
} |
|
177 |
void start_task(YieldingFlexibleGangTask* new_task); |
|
178 |
void continue_task(YieldingFlexibleGangTask* gang_task); |
|
179 |
||
180 |
// Abort a currently running task, if any; returns when all the workers |
|
181 |
// have stopped working on the current task and have returned to their |
|
182 |
// waiting stations. |
|
183 |
void abort_task(); |
|
184 |
||
185 |
// Yield: workers wait at their current working stations |
|
186 |
// until signalled to proceed by the overseer. |
|
187 |
void yield(); |
|
188 |
||
189 |
// Abort: workers are expected to return to their waiting |
|
190 |
// stations, whence they are ready for the next task dispatched |
|
191 |
// by the overseer. |
|
192 |
void abort(); |
|
193 |
||
194 |
private: |
|
195 |
int _active_workers; |
|
196 |
int _yielded_workers; |
|
197 |
void wait_for_gang(); |
|
198 |
||
199 |
public: |
|
200 |
// Accessors for fields |
|
201 |
int active_workers() const { |
|
202 |
return _active_workers; |
|
203 |
} |
|
204 |
||
6759
67b1a69ef5aa
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
5547
diff
changeset
|
205 |
// Accessors for fields |
1 | 206 |
int yielded_workers() const { |
207 |
return _yielded_workers; |
|
208 |
} |
|
209 |
||
210 |
private: |
|
211 |
friend class YieldingFlexibleGangWorker; |
|
212 |
void reset(); // NYI |
|
213 |
}; |