< prev index next >

src/hotspot/share/gc/shared/workgroup.hpp

Print this page




  35 
  36 // Task class hierarchy:
  37 //   AbstractGangTask
  38 //
  39 // Gang/Group class hierarchy:
  40 //   AbstractWorkGang
  41 //     WorkGang
  42 //     YieldingFlexibleWorkGang (defined in another file)
  43 //
  44 // Worker class hierarchy:
  45 //   AbstractGangWorker (subclass of WorkerThread)
  46 //     GangWorker
  47 //     YieldingFlexibleGangWorker   (defined in another file)
  48 
  49 // Forward declarations of classes defined here
  50 
  51 class AbstractGangWorker;
  52 class Semaphore;
  53 class ThreadClosure;
  54 class WorkGang;

  55 
  56 // An abstract task to be worked on by a gang.
  57 // You subclass this to supply your own work() method
  58 class AbstractGangTask {
  59   const char* _name;
  60   const uint _gc_id;
  61 
  62  public:
  63   explicit AbstractGangTask(const char* name) :
  64     _name(name),
  65     _gc_id(GCId::current_or_undefined())
  66   {}
  67 
  68   // The abstract work method.
  69   // The argument tells you which member of the gang you are.
  70   virtual void work(uint worker_id) = 0;
  71 
  72   // Debugging accessor for the name.
  73   const char* name() const { return _name; }
  74   const uint gc_id() const { return _gc_id; }
  75 };
  76 
  77 struct WorkData {
  78   AbstractGangTask* _task;
  79   uint              _worker_id;
  80   WorkData(AbstractGangTask* task, uint worker_id) : _task(task), _worker_id(worker_id) {}
  81 };
  82 
  83 // Interface to handle the synchronization between the coordinator thread and the worker threads,
  84 // when a task is dispatched out to the worker threads.
  85 class GangTaskDispatcher : public CHeapObj<mtGC> {
  86  public:
  87   virtual ~GangTaskDispatcher() {}
  88 
  89   // Coordinator API.
  90 
  91   // Distributes the task out to num_workers workers.
  92   // Returns when the task has been completed by all workers.
  93   virtual void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers,
  94                                               bool add_foreground_work) = 0;
  95 
  96   // Worker API.
  97 
  98   // Waits for a task to become available to the worker.
  99   // Returns when the worker has been assigned a task.
 100   virtual WorkData worker_wait_for_task() = 0;
 101 
 102   // Signal to the coordinator that the worker is done with the assigned task.
 103   virtual void     worker_done_with_task() = 0;
 104 };
 105 
 106 // The work gang is the collection of workers to execute tasks.
 107 // The number of workers run for a task is "_active_workers"
 108 // while "_total_workers" is the number of available of workers.
 109 class AbstractWorkGang : public CHeapObj<mtInternal> {
 110  protected:
 111   // The array of worker threads for this gang.
 112   AbstractGangWorker** _workers;
 113   // The count of the number of workers in the gang.
 114   uint _total_workers;
 115   // The currently active workers in this gang.
 116   uint _active_workers;
 117   // The count of created workers in the gang.
 118   uint _created_workers;
 119   // Printing support.
 120   const char* _name;
 121 
 122   ~AbstractWorkGang() {}
 123 




  35 
  36 // Task class hierarchy:
  37 //   AbstractGangTask
  38 //
  39 // Gang/Group class hierarchy:
  40 //   AbstractWorkGang
  41 //     WorkGang
  42 //     YieldingFlexibleWorkGang (defined in another file)
  43 //
  44 // Worker class hierarchy:
  45 //   AbstractGangWorker (subclass of WorkerThread)
  46 //     GangWorker
  47 //     YieldingFlexibleGangWorker   (defined in another file)
  48 
  49 // Forward declarations of classes defined here
  50 
  51 class AbstractGangWorker;
  52 class Semaphore;
  53 class ThreadClosure;
  54 class WorkGang;
  55 class GangTaskDispatcher;
  56 
  57 // An abstract task to be worked on by a gang.
  58 // You subclass this to supply your own work() method
  59 class AbstractGangTask {
  60   const char* _name;
  61   const uint _gc_id;
  62 
  63  public:
  64   explicit AbstractGangTask(const char* name) :
  65     _name(name),
  66     _gc_id(GCId::current_or_undefined())
  67   {}
  68 
  69   // The abstract work method.
  70   // The argument tells you which member of the gang you are.
  71   virtual void work(uint worker_id) = 0;
  72 
  73   // Debugging accessor for the name.
  74   const char* name() const { return _name; }
  75   const uint gc_id() const { return _gc_id; }
  76 };
  77 
  78 struct WorkData {
  79   AbstractGangTask* _task;
  80   uint              _worker_id;
  81   WorkData(AbstractGangTask* task, uint worker_id) : _task(task), _worker_id(worker_id) {}























  82 };
  83 
  84 // The work gang is the collection of workers to execute tasks.
  85 // The number of workers run for a task is "_active_workers"
  86 // while "_total_workers" is the number of available of workers.
  87 class AbstractWorkGang : public CHeapObj<mtInternal> {
  88  protected:
  89   // The array of worker threads for this gang.
  90   AbstractGangWorker** _workers;
  91   // The count of the number of workers in the gang.
  92   uint _total_workers;
  93   // The currently active workers in this gang.
  94   uint _active_workers;
  95   // The count of created workers in the gang.
  96   uint _created_workers;
  97   // Printing support.
  98   const char* _name;
  99 
 100   ~AbstractWorkGang() {}
 101 


< prev index next >