< prev index next >

src/share/vm/gc/cms/yieldingWorkgroup.hpp

Print this page




  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
  26 #define SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
  27 
  28 #include "gc/shared/workgroup.hpp"
  29 #include "utilities/macros.hpp"
  30 
  31 // Forward declarations

  32 class YieldingFlexibleWorkGang;
  33 
  34 // Status of tasks
  35 enum Status {
  36     INACTIVE,
  37     ACTIVE,
  38     YIELDING,
  39     YIELDED,
  40     ABORTING,
  41     ABORTED,
  42     COMPLETING,
  43     COMPLETED
  44 };
  45 





















  46 // Class YieldingFlexibleGangWorker:
  47 //   Several instances of this class run in parallel as workers for a gang.
  48 class YieldingFlexibleGangWorker: public GangWorker {
  49 public:
  50   // Ctor
  51   YieldingFlexibleGangWorker(AbstractWorkGang* gang, int id) :
  52     GangWorker(gang, id) { }
  53 
  54 public:
  55   YieldingFlexibleWorkGang* yf_gang() const
  56     { return (YieldingFlexibleWorkGang*)gang(); }
  57 
  58 protected: // Override from parent class
  59   virtual void loop();
  60 };
  61 
  62 class FlexibleGangTask: public AbstractGangTask {
  63   int _actual_size;                      // size of gang obtained
  64 protected:
  65   int _requested_size;                   // size of gang requested
  66 public:
  67  FlexibleGangTask(const char* name): AbstractGangTask(name),
  68     _requested_size(0) {}
  69 
  70   // The abstract work method.
  71   // The argument tells you which member of the gang you are.
  72   virtual void work(uint worker_id) = 0;


 143 
 144   Status status()  const { return _status; }
 145   bool yielding()  const { return _status == YIELDING; }
 146   bool yielded()   const { return _status == YIELDED; }
 147   bool completed() const { return _status == COMPLETED; }
 148   bool aborted()   const { return _status == ABORTED; }
 149   bool active()    const { return _status == ACTIVE; }
 150 
 151   // This method configures the task for proper termination.
 152   // Some tasks do not have any requirements on termination
 153   // and may inherit this method that does nothing.  Some
 154   // tasks do some coordination on termination and override
 155   // this method to implement that coordination.
 156   virtual void set_for_termination(uint active_workers) {}
 157 };
 158 // Class YieldingWorkGang: A subclass of WorkGang.
 159 // In particular, a YieldingWorkGang is made up of
 160 // YieldingGangWorkers, and provides infrastructure
 161 // supporting yielding to the "GangOverseer",
 162 // being the thread that orchestrates the WorkGang via run_task().
 163 class YieldingFlexibleWorkGang: public FlexibleWorkGang {
 164   // Here's the public interface to this class.
 165 public:
 166   // Constructor and destructor.
 167   YieldingFlexibleWorkGang(const char* name, uint workers,
 168                            bool are_GC_task_threads);
 169 
 170   YieldingFlexibleGangTask* yielding_task() const {
 171     assert(task() == NULL || task()->is_YieldingFlexibleGang_task(),
 172            "Incorrect cast");
 173     return (YieldingFlexibleGangTask*)task();
 174   }
 175   // Allocate a worker and return a pointer to it.
 176   GangWorker* allocate_worker(uint which);
 177 
 178   // Run a task; returns when the task is done, or the workers yield,
 179   // or the task is aborted.
 180   // A task that has been yielded can be continued via this same interface
 181   // by using the same task repeatedly as the argument to the call.
 182   // It is expected that the YieldingFlexibleGangTask carries the appropriate
 183   // continuation information used by workers to continue the task
 184   // from its last yield point. Thus, a completed task will return
 185   // immediately with no actual work having been done by the workers.
 186   void run_task(AbstractGangTask* task) {
 187     guarantee(false, "Use start_task instead");
 188   }
 189   void start_task(YieldingFlexibleGangTask* new_task);
 190   void continue_task(YieldingFlexibleGangTask* gang_task);
 191 
 192   // Abort a currently running task, if any; returns when all the workers
 193   // have stopped working on the current task and have returned to their
 194   // waiting stations.
 195   void abort_task();
 196 


 199   void yield();
 200 
 201   // Abort: workers are expected to return to their waiting
 202   // stations, whence they are ready for the next task dispatched
 203   // by the overseer.
 204   void abort();
 205 
 206 private:
 207   uint _yielded_workers;
 208   void wait_for_gang();
 209 
 210 public:
 211   // Accessors for fields
 212   uint yielded_workers() const {
 213     return _yielded_workers;
 214   }
 215 
 216 private:
 217   friend class YieldingFlexibleGangWorker;
 218   void reset(); // NYI




































 219 };
 220 
 221 #endif // SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP


  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
  26 #define SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
  27 
  28 #include "gc/shared/workgroup.hpp"
  29 #include "utilities/macros.hpp"
  30 
  31 // Forward declarations
  32 class YieldingFlexibleGangTask;
  33 class YieldingFlexibleWorkGang;
  34 
  35 // Status of tasks
  36 enum Status {
  37     INACTIVE,
  38     ACTIVE,
  39     YIELDING,
  40     YIELDED,
  41     ABORTING,
  42     ABORTED,
  43     COMPLETING,
  44     COMPLETED
  45 };
  46 
  47 class YieldingWorkData: public StackObj {
  48   // This would be a struct, but I want accessor methods.
  49 private:
  50   AbstractGangTask* _task;
  51   int               _sequence_number;
  52 public:
  53   // Constructor and destructor
  54   YieldingWorkData() : _task(NULL), _sequence_number(0) {}
  55   ~YieldingWorkData() {}
  56 
  57   // Accessors and modifiers
  58   AbstractGangTask* task()               const { return _task; }
  59   void set_task(AbstractGangTask* value)       { _task = value; }
  60   int sequence_number()                  const { return _sequence_number; }
  61   void set_sequence_number(int value)          { _sequence_number = value; }
  62 
  63   YieldingFlexibleGangTask* yf_task()    const {
  64     return (YieldingFlexibleGangTask*)_task;
  65   }
  66 };
  67 
  68 // Class YieldingFlexibleGangWorker:
  69 //   Several instances of this class run in parallel as workers for a gang.
  70 class YieldingFlexibleGangWorker: public AbstractGangWorker {
  71 public:
  72   YieldingFlexibleGangWorker(YieldingFlexibleWorkGang* gang, int id);


  73 
  74 public:
  75   YieldingFlexibleWorkGang* yf_gang() const
  76     { return (YieldingFlexibleWorkGang*)gang(); }
  77 
  78 protected: // Override from parent class
  79   virtual void loop();
  80 };
  81 
  82 class FlexibleGangTask: public AbstractGangTask {
  83   int _actual_size;                      // size of gang obtained
  84 protected:
  85   int _requested_size;                   // size of gang requested
  86 public:
  87  FlexibleGangTask(const char* name): AbstractGangTask(name),
  88     _requested_size(0) {}
  89 
  90   // The abstract work method.
  91   // The argument tells you which member of the gang you are.
  92   virtual void work(uint worker_id) = 0;


 163 
 164   Status status()  const { return _status; }
 165   bool yielding()  const { return _status == YIELDING; }
 166   bool yielded()   const { return _status == YIELDED; }
 167   bool completed() const { return _status == COMPLETED; }
 168   bool aborted()   const { return _status == ABORTED; }
 169   bool active()    const { return _status == ACTIVE; }
 170 
 171   // This method configures the task for proper termination.
 172   // Some tasks do not have any requirements on termination
 173   // and may inherit this method that does nothing.  Some
 174   // tasks do some coordination on termination and override
 175   // this method to implement that coordination.
 176   virtual void set_for_termination(uint active_workers) {}
 177 };
 178 // Class YieldingWorkGang: A subclass of WorkGang.
 179 // In particular, a YieldingWorkGang is made up of
 180 // YieldingGangWorkers, and provides infrastructure
 181 // supporting yielding to the "GangOverseer",
 182 // being the thread that orchestrates the WorkGang via run_task().
 183 class YieldingFlexibleWorkGang: public AbstractWorkGang {
 184   // Here's the public interface to this class.
 185 public:
 186   // Constructor and destructor.
 187   YieldingFlexibleWorkGang(const char* name, uint workers,
 188                            bool are_GC_task_threads);
 189 
 190   YieldingFlexibleGangTask* yielding_task() const {
 191     assert(task() == NULL || task()->is_YieldingFlexibleGang_task(),
 192            "Incorrect cast");
 193     return (YieldingFlexibleGangTask*)task();
 194   }
 195   // Allocate a worker and return a pointer to it.
 196   AbstractGangWorker* allocate_worker(uint which);
 197 
 198   // Run a task; returns when the task is done, or the workers yield,
 199   // or the task is aborted.
 200   // A task that has been yielded can be continued via this same interface
 201   // by using the same task repeatedly as the argument to the call.
 202   // It is expected that the YieldingFlexibleGangTask carries the appropriate
 203   // continuation information used by workers to continue the task
 204   // from its last yield point. Thus, a completed task will return
 205   // immediately with no actual work having been done by the workers.
 206   void run_task(AbstractGangTask* task) {
 207     guarantee(false, "Use start_task instead");
 208   }
 209   void start_task(YieldingFlexibleGangTask* new_task);
 210   void continue_task(YieldingFlexibleGangTask* gang_task);
 211 
 212   // Abort a currently running task, if any; returns when all the workers
 213   // have stopped working on the current task and have returned to their
 214   // waiting stations.
 215   void abort_task();
 216 


 219   void yield();
 220 
 221   // Abort: workers are expected to return to their waiting
 222   // stations, whence they are ready for the next task dispatched
 223   // by the overseer.
 224   void abort();
 225 
 226 private:
 227   uint _yielded_workers;
 228   void wait_for_gang();
 229 
 230 public:
 231   // Accessors for fields
 232   uint yielded_workers() const {
 233     return _yielded_workers;
 234   }
 235 
 236 private:
 237   friend class YieldingFlexibleGangWorker;
 238   void reset(); // NYI
 239 
 240 
 241   // The monitor which protects these data,
 242   // and notifies of changes in it.
 243   Monitor*   _monitor;
 244   // Accessors for fields
 245   Monitor* monitor() const {
 246     return _monitor;
 247   }
 248 
 249   // The number of started workers.
 250   uint _started_workers;
 251   // The number of finished workers.
 252   uint _finished_workers;
 253 
 254   uint started_workers() const {
 255     return _started_workers;
 256   }
 257   uint finished_workers() const {
 258     return _finished_workers;
 259   }
 260 
 261   // A sequence number for the current task.
 262   int _sequence_number;
 263   int sequence_number() const {
 264     return _sequence_number;
 265   }
 266 
 267   YieldingFlexibleGangTask* _task;
 268   YieldingFlexibleGangTask* task() const {
 269     return _task;
 270   }
 271 
 272   void internal_worker_poll(YieldingWorkData* data) const;
 273   void internal_note_start();
 274   void internal_note_finish();
 275 };
 276 
 277 #endif // SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
< prev index next >