< prev index next >

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

Print this page




   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  *
  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 #include "precompiled.hpp"
  26 #include "gc/cms/yieldingWorkgroup.hpp"
  27 #include "gc/shared/gcId.hpp"
  28 #include "utilities/macros.hpp"
  29 
  30 YieldingFlexibleGangWorker::YieldingFlexibleGangWorker(YieldingFlexibleWorkGang* gang, int id)
  31     : AbstractGangWorker(gang, id) {}
  32 
  33 YieldingFlexibleWorkGang::YieldingFlexibleWorkGang(
  34     const char* name, uint workers, bool are_GC_task_threads) :
  35          AbstractWorkGang(name, workers, are_GC_task_threads, false),
  36          _yielded_workers(0),
  37          _started_workers(0),
  38          _finished_workers(0),
  39          _sequence_number(0),
  40          _task(NULL) {
  41 
  42   // Other initialization.
  43   _monitor = new Monitor(/* priority */       Mutex::leaf,
  44                          /* name */           "WorkGroup monitor",
  45                          /* allow_vm_block */ are_GC_task_threads,
  46                                               Monitor::_safepoint_check_sometimes);
  47 


 324   int id;
 325   while (true) {
 326     // Check if there is work to do.
 327     yf_gang()->internal_worker_poll(&data);
 328     if (data.task() != NULL && data.sequence_number() != previous_sequence_number) {
 329       // There is work to be done.
 330       // First check if we need to become active or if there
 331       // are already the requisite number of workers
 332       if (yf_gang()->started_workers() == yf_gang()->active_workers()) {
 333         // There are already enough workers, we do not need to
 334         // to run; fall through and wait on monitor.
 335       } else {
 336         // We need to pitch in and do the work.
 337         assert(yf_gang()->started_workers() < yf_gang()->active_workers(),
 338                "Unexpected state");
 339         id = yf_gang()->started_workers();
 340         yf_gang()->internal_note_start();
 341         // Now, release the gang mutex and do the work.
 342         {
 343           MutexUnlockerEx mul(gang_monitor, Mutex::_no_safepoint_check_flag);
 344           GCIdMark gc_id_mark(data.task()->gc_id());
 345           data.task()->work(id);   // This might include yielding
 346         }
 347         // Reacquire monitor and note completion of this worker
 348         yf_gang()->internal_note_finish();
 349         // Update status of task based on whether all workers have
 350         // finished or some have yielded
 351         assert(data.task() == yf_gang()->task(), "Confused task binding");
 352         if (yf_gang()->finished_workers() == yf_gang()->active_workers()) {
 353           switch (data.yf_task()->status()) {
 354             case ABORTING: {
 355               data.yf_task()->set_status(ABORTED);
 356               break;
 357             }
 358             case ACTIVE:
 359             case COMPLETING: {
 360               data.yf_task()->set_status(COMPLETED);
 361               break;
 362             }
 363             default:
 364               ShouldNotReachHere();




   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  *
  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 #include "precompiled.hpp"
  26 #include "gc/cms/yieldingWorkgroup.hpp"

  27 #include "utilities/macros.hpp"
  28 
  29 YieldingFlexibleGangWorker::YieldingFlexibleGangWorker(YieldingFlexibleWorkGang* gang, int id)
  30     : AbstractGangWorker(gang, id) {}
  31 
  32 YieldingFlexibleWorkGang::YieldingFlexibleWorkGang(
  33     const char* name, uint workers, bool are_GC_task_threads) :
  34          AbstractWorkGang(name, workers, are_GC_task_threads, false),
  35          _yielded_workers(0),
  36          _started_workers(0),
  37          _finished_workers(0),
  38          _sequence_number(0),
  39          _task(NULL) {
  40 
  41   // Other initialization.
  42   _monitor = new Monitor(/* priority */       Mutex::leaf,
  43                          /* name */           "WorkGroup monitor",
  44                          /* allow_vm_block */ are_GC_task_threads,
  45                                               Monitor::_safepoint_check_sometimes);
  46 


 323   int id;
 324   while (true) {
 325     // Check if there is work to do.
 326     yf_gang()->internal_worker_poll(&data);
 327     if (data.task() != NULL && data.sequence_number() != previous_sequence_number) {
 328       // There is work to be done.
 329       // First check if we need to become active or if there
 330       // are already the requisite number of workers
 331       if (yf_gang()->started_workers() == yf_gang()->active_workers()) {
 332         // There are already enough workers, we do not need to
 333         // to run; fall through and wait on monitor.
 334       } else {
 335         // We need to pitch in and do the work.
 336         assert(yf_gang()->started_workers() < yf_gang()->active_workers(),
 337                "Unexpected state");
 338         id = yf_gang()->started_workers();
 339         yf_gang()->internal_note_start();
 340         // Now, release the gang mutex and do the work.
 341         {
 342           MutexUnlockerEx mul(gang_monitor, Mutex::_no_safepoint_check_flag);

 343           data.task()->work(id);   // This might include yielding
 344         }
 345         // Reacquire monitor and note completion of this worker
 346         yf_gang()->internal_note_finish();
 347         // Update status of task based on whether all workers have
 348         // finished or some have yielded
 349         assert(data.task() == yf_gang()->task(), "Confused task binding");
 350         if (yf_gang()->finished_workers() == yf_gang()->active_workers()) {
 351           switch (data.yf_task()->status()) {
 352             case ABORTING: {
 353               data.yf_task()->set_status(ABORTED);
 354               break;
 355             }
 356             case ACTIVE:
 357             case COMPLETING: {
 358               data.yf_task()->set_status(COMPLETED);
 359               break;
 360             }
 361             default:
 362               ShouldNotReachHere();


< prev index next >