< prev index next >

src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp

Print this page
rev 53582 : imported patch rename
   1 /*
   2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
   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  *
  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/g1/g1BarrierSet.hpp"
  27 #include "gc/g1/g1ConcurrentRefine.hpp"
  28 #include "gc/g1/g1ConcurrentRefineThread.hpp"

  29 #include "gc/shared/suspendibleThreadSet.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/handles.inline.hpp"
  33 #include "runtime/mutexLocker.hpp"
  34 
  35 G1ConcurrentRefineThread::G1ConcurrentRefineThread(G1ConcurrentRefine* cr, uint worker_id) :
  36   ConcurrentGCThread(),
  37   _vtime_start(0.0),
  38   _vtime_accum(0.0),
  39   _worker_id(worker_id),
  40   _active(false),
  41   _monitor(NULL),
  42   _cr(cr)
  43 {
  44   // Each thread has its own monitor. The i-th thread is responsible for signaling
  45   // to thread i+1 if the number of buffers in the queue exceeds a threshold for this
  46   // thread. Monitors are also used to wake up the threads during termination.
  47   // The 0th (primary) worker is notified by mutator threads and has a special monitor.
  48   if (!is_primary()) {
  49     _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true,
  50                            Monitor::_safepoint_check_never);
  51   } else {
  52     _monitor = DirtyCardQ_CBL_mon;
  53   }
  54 
  55   // set name
  56   set_name("G1 Refine#%d", worker_id);
  57   create_and_start();
  58 }
  59 
  60 void G1ConcurrentRefineThread::wait_for_completed_buffers() {
  61   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  62   while (!should_terminate() && !is_active()) {
  63     _monitor->wait(Mutex::_no_safepoint_check_flag);
  64   }
  65 }
  66 
  67 bool G1ConcurrentRefineThread::is_active() {
  68   DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  69   return is_primary() ? dcqs.process_completed_buffers() : _active;
  70 }
  71 
  72 void G1ConcurrentRefineThread::activate() {
  73   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  74   if (!is_primary()) {
  75     set_active(true);
  76   } else {
  77     DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  78     dcqs.set_process_completed_buffers(true);
  79   }
  80   _monitor->notify();
  81 }
  82 
  83 void G1ConcurrentRefineThread::deactivate() {
  84   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  85   if (!is_primary()) {
  86     set_active(false);
  87   } else {
  88     DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  89     dcqs.set_process_completed_buffers(false);
  90   }
  91 }
  92 
  93 void G1ConcurrentRefineThread::run_service() {
  94   _vtime_start = os::elapsedVTime();
  95 
  96   while (!should_terminate()) {
  97     // Wait for work
  98     wait_for_completed_buffers();
  99     if (should_terminate()) {
 100       break;
 101     }
 102 
 103     size_t buffers_processed = 0;
 104     log_debug(gc, refine)("Activated worker %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
 105                           _worker_id, _cr->activation_threshold(_worker_id),
 106                            G1BarrierSet::dirty_card_queue_set().completed_buffers_num());
 107 
 108     {


   1 /*
   2  * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
   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  *
  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/g1/g1BarrierSet.hpp"
  27 #include "gc/g1/g1ConcurrentRefine.hpp"
  28 #include "gc/g1/g1ConcurrentRefineThread.hpp"
  29 #include "gc/g1/g1DirtyCardQueue.hpp"
  30 #include "gc/shared/suspendibleThreadSet.hpp"
  31 #include "logging/log.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "runtime/handles.inline.hpp"
  34 #include "runtime/mutexLocker.hpp"
  35 
  36 G1ConcurrentRefineThread::G1ConcurrentRefineThread(G1ConcurrentRefine* cr, uint worker_id) :
  37   ConcurrentGCThread(),
  38   _vtime_start(0.0),
  39   _vtime_accum(0.0),
  40   _worker_id(worker_id),
  41   _active(false),
  42   _monitor(NULL),
  43   _cr(cr)
  44 {
  45   // Each thread has its own monitor. The i-th thread is responsible for signaling
  46   // to thread i+1 if the number of buffers in the queue exceeds a threshold for this
  47   // thread. Monitors are also used to wake up the threads during termination.
  48   // The 0th (primary) worker is notified by mutator threads and has a special monitor.
  49   if (!is_primary()) {
  50     _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true,
  51                            Monitor::_safepoint_check_never);
  52   } else {
  53     _monitor = DirtyCardQ_CBL_mon;
  54   }
  55 
  56   // set name
  57   set_name("G1 Refine#%d", worker_id);
  58   create_and_start();
  59 }
  60 
  61 void G1ConcurrentRefineThread::wait_for_completed_buffers() {
  62   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  63   while (!should_terminate() && !is_active()) {
  64     _monitor->wait(Mutex::_no_safepoint_check_flag);
  65   }
  66 }
  67 
  68 bool G1ConcurrentRefineThread::is_active() {
  69   G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  70   return is_primary() ? dcqs.process_completed_buffers() : _active;
  71 }
  72 
  73 void G1ConcurrentRefineThread::activate() {
  74   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  75   if (!is_primary()) {
  76     set_active(true);
  77   } else {
  78     G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  79     dcqs.set_process_completed_buffers(true);
  80   }
  81   _monitor->notify();
  82 }
  83 
  84 void G1ConcurrentRefineThread::deactivate() {
  85   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  86   if (!is_primary()) {
  87     set_active(false);
  88   } else {
  89     G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  90     dcqs.set_process_completed_buffers(false);
  91   }
  92 }
  93 
  94 void G1ConcurrentRefineThread::run_service() {
  95   _vtime_start = os::elapsedVTime();
  96 
  97   while (!should_terminate()) {
  98     // Wait for work
  99     wait_for_completed_buffers();
 100     if (should_terminate()) {
 101       break;
 102     }
 103 
 104     size_t buffers_processed = 0;
 105     log_debug(gc, refine)("Activated worker %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
 106                           _worker_id, _cr->activation_threshold(_worker_id),
 107                            G1BarrierSet::dirty_card_queue_set().completed_buffers_num());
 108 
 109     {


< prev index next >