< prev index next >

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

Print this page
rev 8331 : 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
Reviewed-by:
   1 /*
   2  * Copyright (c) 2001, 2014, 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  *


  60   initialize();
  61   create_and_start();
  62 
  63   // set name
  64   set_name("G1 Refine#%d", worker_id);
  65 }
  66 
  67 void ConcurrentG1RefineThread::initialize() {
  68   if (_worker_id < cg1r()->worker_thread_num()) {
  69     // Current thread activation threshold
  70     _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(),
  71                            cg1r()->yellow_zone());
  72     // A thread deactivates once the number of buffer reached a deactivation threshold
  73     _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone());
  74   } else {
  75     set_active(true);
  76   }
  77 }
  78 
  79 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
  80   SuspendibleThreadSetJoiner sts;
  81   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  82   G1CollectorPolicy* g1p = g1h->g1_policy();
  83   if (g1p->adaptive_young_list_length()) {
  84     int regions_visited = 0;
  85     g1h->young_list()->rs_length_sampling_init();
  86     while (g1h->young_list()->rs_length_sampling_more()) {
  87       g1h->young_list()->rs_length_sampling_next();
  88       ++regions_visited;
  89 
  90       // we try to yield every time we visit 10 regions
  91       if (regions_visited == 10) {
  92         if (sts.should_yield()) {
  93           sts.yield();
  94           // we just abandon the iteration
  95           break;
  96         }
  97         regions_visited = 0;
  98       }
  99     }
 100 
 101     g1p->revise_young_list_target_length_if_necessary();
 102   }
 103 }
 104 
 105 void ConcurrentG1RefineThread::run_young_rs_sampling() {
 106   DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 107   _vtime_start = os::elapsedVTime();
 108   while(!_should_terminate) {
 109     sample_young_list_rs_lengths();
 110 
 111     if (os::supports_vtime()) {
 112       _vtime_accum = (os::elapsedVTime() - _vtime_start);
 113     } else {


 171   wait_for_universe_init();
 172 
 173   if (_worker_id >= cg1r()->worker_thread_num()) {
 174     run_young_rs_sampling();
 175     terminate();
 176     return;
 177   }
 178 
 179   _vtime_start = os::elapsedVTime();
 180   while (!_should_terminate) {
 181     DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 182 
 183     // Wait for work
 184     wait_for_completed_buffers();
 185 
 186     if (_should_terminate) {
 187       break;
 188     }
 189 
 190     {
 191       SuspendibleThreadSetJoiner sts;
 192 
 193       do {
 194         int curr_buffer_num = (int)dcqs.completed_buffers_num();
 195         // If the number of the buffers falls down into the yellow zone,
 196         // that means that the transition period after the evacuation pause has ended.
 197         if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
 198           dcqs.set_completed_queue_padding(0);
 199         }
 200 
 201         if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) {
 202           // If the number of the buffer has fallen below our threshold
 203           // we should deactivate. The predecessor will reactivate this
 204           // thread should the number of the buffers cross the threshold again.
 205           deactivate();
 206           break;
 207         }
 208 
 209         // Check if we need to activate the next thread.
 210         if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) {
 211           _next->activate();


   1 /*
   2  * Copyright (c) 2001, 2015, 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  *


  60   initialize();
  61   create_and_start();
  62 
  63   // set name
  64   set_name("G1 Refine#%d", worker_id);
  65 }
  66 
  67 void ConcurrentG1RefineThread::initialize() {
  68   if (_worker_id < cg1r()->worker_thread_num()) {
  69     // Current thread activation threshold
  70     _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(),
  71                            cg1r()->yellow_zone());
  72     // A thread deactivates once the number of buffer reached a deactivation threshold
  73     _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone());
  74   } else {
  75     set_active(true);
  76   }
  77 }
  78 
  79 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
  80   SuspendibleThreadSetJoiner sts_join;
  81   G1CollectedHeap* g1h = G1CollectedHeap::heap();
  82   G1CollectorPolicy* g1p = g1h->g1_policy();
  83   if (g1p->adaptive_young_list_length()) {
  84     int regions_visited = 0;
  85     g1h->young_list()->rs_length_sampling_init();
  86     while (g1h->young_list()->rs_length_sampling_more()) {
  87       g1h->young_list()->rs_length_sampling_next();
  88       ++regions_visited;
  89 
  90       // we try to yield every time we visit 10 regions
  91       if (regions_visited == 10) {
  92         if (sts_join.should_yield()) {
  93           sts_join.yield();
  94           // we just abandon the iteration
  95           break;
  96         }
  97         regions_visited = 0;
  98       }
  99     }
 100 
 101     g1p->revise_young_list_target_length_if_necessary();
 102   }
 103 }
 104 
 105 void ConcurrentG1RefineThread::run_young_rs_sampling() {
 106   DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 107   _vtime_start = os::elapsedVTime();
 108   while(!_should_terminate) {
 109     sample_young_list_rs_lengths();
 110 
 111     if (os::supports_vtime()) {
 112       _vtime_accum = (os::elapsedVTime() - _vtime_start);
 113     } else {


 171   wait_for_universe_init();
 172 
 173   if (_worker_id >= cg1r()->worker_thread_num()) {
 174     run_young_rs_sampling();
 175     terminate();
 176     return;
 177   }
 178 
 179   _vtime_start = os::elapsedVTime();
 180   while (!_should_terminate) {
 181     DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 182 
 183     // Wait for work
 184     wait_for_completed_buffers();
 185 
 186     if (_should_terminate) {
 187       break;
 188     }
 189 
 190     {
 191       SuspendibleThreadSetJoiner sts_join;
 192 
 193       do {
 194         int curr_buffer_num = (int)dcqs.completed_buffers_num();
 195         // If the number of the buffers falls down into the yellow zone,
 196         // that means that the transition period after the evacuation pause has ended.
 197         if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
 198           dcqs.set_completed_queue_padding(0);
 199         }
 200 
 201         if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) {
 202           // If the number of the buffer has fallen below our threshold
 203           // we should deactivate. The predecessor will reactivate this
 204           // thread should the number of the buffers cross the threshold again.
 205           deactivate();
 206           break;
 207         }
 208 
 209         // Check if we need to activate the next thread.
 210         if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) {
 211           _next->activate();


< prev index next >