Mercurial > hg > truffle
annotate src/share/vm/utilities/yieldingWorkgroup.hpp @ 6862:8a5ea0a9ccc4
7127708: G1: change task num types from int to uint in concurrent mark
Summary: Change the type of various task num fields, parameters etc to unsigned and rename them to be more consistent with the other collectors. Code changes were also reviewed by Vitaly Davidovich.
Reviewed-by: johnc
Contributed-by: Kaushik Srenevasan <kaushik@twitter.com>
author | johnc |
---|---|
date | Sat, 06 Oct 2012 01:17:44 -0700 |
parents | 441e946dc1af |
children | 32164d89fe9c |
rev | line source |
---|---|
0 | 1 /* |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1833
diff
changeset
|
2 * Copyright (c) 2005, 2010, 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:
342
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
342
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:
342
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |
26 #define SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP | |
27 | |
28 #ifndef SERIALGC | |
29 #include "utilities/workgroup.hpp" | |
30 #endif | |
31 | |
0 | 32 |
33 // Forward declarations | |
34 class YieldingFlexibleWorkGang; | |
35 | |
36 // Status of tasks | |
37 enum Status { | |
38 INACTIVE, | |
39 ACTIVE, | |
40 YIELDING, | |
41 YIELDED, | |
42 ABORTING, | |
43 ABORTED, | |
44 COMPLETING, | |
45 COMPLETED | |
46 }; | |
47 | |
48 // Class YieldingFlexibleGangWorker: | |
49 // Several instances of this class run in parallel as workers for a gang. | |
50 class YieldingFlexibleGangWorker: public GangWorker { | |
51 public: | |
52 // Ctor | |
53 YieldingFlexibleGangWorker(AbstractWorkGang* gang, int id) : | |
54 GangWorker(gang, id) { } | |
55 | |
56 public: | |
57 YieldingFlexibleWorkGang* yf_gang() const | |
58 { return (YieldingFlexibleWorkGang*)gang(); } | |
59 | |
60 protected: // Override from parent class | |
61 virtual void loop(); | |
62 }; | |
63 | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
64 class FlexibleGangTask: public AbstractGangTask { |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
65 int _actual_size; // size of gang obtained |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
66 protected: |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
67 int _requested_size; // size of gang requested |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
68 public: |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
69 FlexibleGangTask(const char* name): AbstractGangTask(name), |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
70 _requested_size(0) {} |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
71 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
72 // The abstract work method. |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
73 // The argument tells you which member of the gang you are. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
74 virtual void work(uint worker_id) = 0; |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
75 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
76 int requested_size() const { return _requested_size; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
77 int actual_size() const { return _actual_size; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
78 |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
79 void set_requested_size(int sz) { _requested_size = sz; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
80 void set_actual_size(int sz) { _actual_size = sz; } |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
81 }; |
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
82 |
0 | 83 // An abstract task to be worked on by a flexible work gang, |
84 // and where the workers will periodically yield, usually | |
85 // in response to some condition that is signalled by means | |
86 // that are specific to the task at hand. | |
87 // You subclass this to supply your own work() method. | |
88 // A second feature of this kind of work gang is that | |
89 // it allows for the signalling of certain exceptional | |
90 // conditions that may be encountered during the performance | |
91 // of the task and that may require the task at hand to be | |
92 // `aborted' forthwith. Finally, these gangs are `flexible' | |
93 // in that they can operate at partial capacity with some | |
94 // gang workers waiting on the bench; in other words, the | |
95 // size of the active worker pool can flex (up to an apriori | |
96 // maximum) in response to task requests at certain points. | |
97 // The last part (the flexible part) has not yet been fully | |
98 // fleshed out and is a work in progress. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
99 class YieldingFlexibleGangTask: public FlexibleGangTask { |
0 | 100 Status _status; |
101 YieldingFlexibleWorkGang* _gang; | |
102 | |
103 protected: | |
104 // Constructor and desctructor: only construct subclasses. | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
105 YieldingFlexibleGangTask(const char* name): FlexibleGangTask(name), |
0 | 106 _status(INACTIVE), |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
107 _gang(NULL) { } |
0 | 108 |
109 virtual ~YieldingFlexibleGangTask() { } | |
110 | |
111 friend class YieldingFlexibleWorkGang; | |
112 friend class YieldingFlexibleGangWorker; | |
113 NOT_PRODUCT(virtual bool is_YieldingFlexibleGang_task() const { | |
114 return true; | |
115 }) | |
116 | |
117 void set_status(Status s) { | |
118 _status = s; | |
119 } | |
120 YieldingFlexibleWorkGang* gang() { | |
121 return _gang; | |
122 } | |
123 void set_gang(YieldingFlexibleWorkGang* gang) { | |
124 assert(_gang == NULL || gang == NULL, "Clobber without intermediate reset?"); | |
125 _gang = gang; | |
126 } | |
127 | |
128 public: | |
129 // The abstract work method. | |
130 // The argument tells you which member of the gang you are. | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
131 virtual void work(uint worker_id) = 0; |
0 | 132 |
133 // Subclasses should call the parent's yield() method | |
134 // after having done any work specific to the subclass. | |
135 virtual void yield(); | |
136 | |
137 // An abstract method supplied by | |
138 // a concrete sub-class which is used by the coordinator | |
139 // to do any "central yielding" work. | |
140 virtual void coordinator_yield() = 0; | |
141 | |
142 // Subclasses should call the parent's abort() method | |
143 // after having done any work specific to the sunbclass. | |
144 virtual void abort(); | |
145 | |
146 Status status() const { return _status; } | |
1837
c99c53f07c14
6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents:
1833
diff
changeset
|
147 bool yielding() const { return _status == YIELDING; } |
0 | 148 bool yielded() const { return _status == YIELDED; } |
149 bool completed() const { return _status == COMPLETED; } | |
150 bool aborted() const { return _status == ABORTED; } | |
151 bool active() const { return _status == ACTIVE; } | |
152 }; | |
153 // Class YieldingWorkGang: A subclass of WorkGang. | |
154 // In particular, a YieldingWorkGang is made up of | |
155 // YieldingGangWorkers, and provides infrastructure | |
156 // supporting yielding to the "GangOverseer", | |
157 // being the thread that orchestrates the WorkGang via run_task(). | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
158 class YieldingFlexibleWorkGang: public FlexibleWorkGang { |
0 | 159 // Here's the public interface to this class. |
160 public: | |
161 // Constructor and destructor. | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
162 YieldingFlexibleWorkGang(const char* name, uint workers, |
342 | 163 bool are_GC_task_threads); |
0 | 164 |
165 YieldingFlexibleGangTask* yielding_task() const { | |
166 assert(task() == NULL || task()->is_YieldingFlexibleGang_task(), | |
167 "Incorrect cast"); | |
168 return (YieldingFlexibleGangTask*)task(); | |
169 } | |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
170 // Allocate a worker and return a pointer to it. |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
171 GangWorker* allocate_worker(uint which); |
1833
8b10f48633dc
6984287: Regularize how GC parallel workers are specified.
jmasa
parents:
1552
diff
changeset
|
172 |
0 | 173 // Run a task; returns when the task is done, or the workers yield, |
174 // or the task is aborted, or the work gang is terminated via stop(). | |
175 // A task that has been yielded can be continued via this same interface | |
176 // by using the same task repeatedly as the argument to the call. | |
177 // It is expected that the YieldingFlexibleGangTask carries the appropriate | |
178 // continuation information used by workers to continue the task | |
179 // from its last yield point. Thus, a completed task will return | |
180 // immediately with no actual work having been done by the workers. | |
181 void run_task(AbstractGangTask* task) { | |
182 guarantee(false, "Use start_task instead"); | |
183 } | |
184 void start_task(YieldingFlexibleGangTask* new_task); | |
185 void continue_task(YieldingFlexibleGangTask* gang_task); | |
186 | |
187 // Abort a currently running task, if any; returns when all the workers | |
188 // have stopped working on the current task and have returned to their | |
189 // waiting stations. | |
190 void abort_task(); | |
191 | |
192 // Yield: workers wait at their current working stations | |
193 // until signalled to proceed by the overseer. | |
194 void yield(); | |
195 | |
196 // Abort: workers are expected to return to their waiting | |
197 // stations, whence they are ready for the next task dispatched | |
198 // by the overseer. | |
199 void abort(); | |
200 | |
201 private: | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
202 uint _yielded_workers; |
0 | 203 void wait_for_gang(); |
204 | |
205 public: | |
206 // Accessors for fields | |
4728
441e946dc1af
7121618: Change type of number of GC workers to unsigned int.
jmasa
parents:
4095
diff
changeset
|
207 uint yielded_workers() const { |
0 | 208 return _yielded_workers; |
209 } | |
210 | |
211 private: | |
212 friend class YieldingFlexibleGangWorker; | |
213 void reset(); // NYI | |
214 }; | |
1972 | 215 |
216 #endif // SHARE_VM_UTILITIES_YIELDINGWORKGROUP_HPP |