src/share/vm/utilities/yieldingWorkgroup.hpp

Wed, 11 Sep 2013 00:38:18 -0400

author
dholmes
date
Wed, 11 Sep 2013 00:38:18 -0400
changeset 5689
de88570fabfc
parent 4542
db9981fd3124
child 6876
710a3c8b516e
permissions
-rw-r--r--

8024256: Minimal VM build is broken with PCH disabled
Reviewed-by: coleenp, twisti

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

mercurial