< prev index next >

src/share/vm/gc/g1/concurrentG1RefineThread.cpp

Print this page
rev 12906 : [mq]: gc_interface


   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/concurrentG1Refine.hpp"
  27 #include "gc/g1/concurrentG1RefineThread.hpp"

  28 #include "gc/g1/g1CollectedHeap.inline.hpp"
  29 #include "gc/g1/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 ConcurrentG1RefineThread::
  36 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next,
  37                          CardTableEntryClosure* refine_closure,
  38                          uint worker_id_offset, uint worker_id,
  39                          size_t activate, size_t deactivate) :
  40   ConcurrentGCThread(),
  41   _refine_closure(refine_closure),
  42   _worker_id_offset(worker_id_offset),
  43   _worker_id(worker_id),
  44   _active(false),
  45   _next(next),
  46   _monitor(NULL),
  47   _cg1r(cg1r),


  64   // set name
  65   set_name("G1 Refine#%d", worker_id);
  66   create_and_start();
  67 }
  68 
  69 void ConcurrentG1RefineThread::update_thresholds(size_t activate,
  70                                                  size_t deactivate) {
  71   assert(deactivate < activate, "precondition");
  72   _activation_threshold = activate;
  73   _deactivation_threshold = deactivate;
  74 }
  75 
  76 void ConcurrentG1RefineThread::wait_for_completed_buffers() {
  77   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  78   while (!should_terminate() && !is_active()) {
  79     _monitor->wait(Mutex::_no_safepoint_check_flag);
  80   }
  81 }
  82 
  83 bool ConcurrentG1RefineThread::is_active() {
  84   DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
  85   return is_primary() ? dcqs.process_completed_buffers() : _active;
  86 }
  87 
  88 void ConcurrentG1RefineThread::activate() {
  89   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  90   if (!is_primary()) {
  91     set_active(true);
  92   } else {
  93     DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
  94     dcqs.set_process_completed(true);
  95   }
  96   _monitor->notify();
  97 }
  98 
  99 void ConcurrentG1RefineThread::deactivate() {
 100   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
 101   if (!is_primary()) {
 102     set_active(false);
 103   } else {
 104     DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 105     dcqs.set_process_completed(false);
 106   }
 107 }
 108 
 109 void ConcurrentG1RefineThread::run_service() {
 110   _vtime_start = os::elapsedVTime();
 111 
 112   while (!should_terminate()) {
 113     // Wait for work
 114     wait_for_completed_buffers();
 115     if (should_terminate()) {
 116       break;
 117     }
 118 
 119     size_t buffers_processed = 0;
 120     DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 121     log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
 122                           _worker_id, _activation_threshold, dcqs.completed_buffers_num());
 123 
 124     {
 125       SuspendibleThreadSetJoiner sts_join;
 126 
 127       while (!should_terminate()) {
 128         if (sts_join.should_yield()) {
 129           sts_join.yield();
 130           continue;             // Re-check for termination after yield delay.
 131         }
 132 
 133         size_t curr_buffer_num = dcqs.completed_buffers_num();
 134         // If the number of the buffers falls down into the yellow zone,
 135         // that means that the transition period after the evacuation pause has ended.
 136         if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
 137           dcqs.set_completed_queue_padding(0);
 138         }
 139 
 140         // Check if we need to activate the next thread.




   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/concurrentG1Refine.hpp"
  27 #include "gc/g1/concurrentG1RefineThread.hpp"
  28 #include "gc/g1/g1BarrierSet.hpp"
  29 #include "gc/g1/g1CollectedHeap.inline.hpp"
  30 #include "gc/g1/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 ConcurrentG1RefineThread::
  37 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next,
  38                          CardTableEntryClosure* refine_closure,
  39                          uint worker_id_offset, uint worker_id,
  40                          size_t activate, size_t deactivate) :
  41   ConcurrentGCThread(),
  42   _refine_closure(refine_closure),
  43   _worker_id_offset(worker_id_offset),
  44   _worker_id(worker_id),
  45   _active(false),
  46   _next(next),
  47   _monitor(NULL),
  48   _cg1r(cg1r),


  65   // set name
  66   set_name("G1 Refine#%d", worker_id);
  67   create_and_start();
  68 }
  69 
  70 void ConcurrentG1RefineThread::update_thresholds(size_t activate,
  71                                                  size_t deactivate) {
  72   assert(deactivate < activate, "precondition");
  73   _activation_threshold = activate;
  74   _deactivation_threshold = deactivate;
  75 }
  76 
  77 void ConcurrentG1RefineThread::wait_for_completed_buffers() {
  78   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  79   while (!should_terminate() && !is_active()) {
  80     _monitor->wait(Mutex::_no_safepoint_check_flag);
  81   }
  82 }
  83 
  84 bool ConcurrentG1RefineThread::is_active() {
  85   DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  86   return is_primary() ? dcqs.process_completed_buffers() : _active;
  87 }
  88 
  89 void ConcurrentG1RefineThread::activate() {
  90   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  91   if (!is_primary()) {
  92     set_active(true);
  93   } else {
  94     DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
  95     dcqs.set_process_completed(true);
  96   }
  97   _monitor->notify();
  98 }
  99 
 100 void ConcurrentG1RefineThread::deactivate() {
 101   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
 102   if (!is_primary()) {
 103     set_active(false);
 104   } else {
 105     DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
 106     dcqs.set_process_completed(false);
 107   }
 108 }
 109 
 110 void ConcurrentG1RefineThread::run_service() {
 111   _vtime_start = os::elapsedVTime();
 112 
 113   while (!should_terminate()) {
 114     // Wait for work
 115     wait_for_completed_buffers();
 116     if (should_terminate()) {
 117       break;
 118     }
 119 
 120     size_t buffers_processed = 0;
 121     DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
 122     log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
 123                           _worker_id, _activation_threshold, dcqs.completed_buffers_num());
 124 
 125     {
 126       SuspendibleThreadSetJoiner sts_join;
 127 
 128       while (!should_terminate()) {
 129         if (sts_join.should_yield()) {
 130           sts_join.yield();
 131           continue;             // Re-check for termination after yield delay.
 132         }
 133 
 134         size_t curr_buffer_num = dcqs.completed_buffers_num();
 135         // If the number of the buffers falls down into the yellow zone,
 136         // that means that the transition period after the evacuation pause has ended.
 137         if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
 138           dcqs.set_completed_queue_padding(0);
 139         }
 140 
 141         // Check if we need to activate the next thread.


< prev index next >