< prev index next >

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

Print this page
rev 10309 : 8150390: Move rs length sampling data to the sampling thread
Reviewed-by:


   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/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1CollectorPolicy.hpp"
  28 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"


  29 #include "gc/g1/suspendibleThreadSet.hpp"
  30 #include "runtime/mutexLocker.hpp"
  31 
  32 void G1YoungRemSetSamplingThread::run() {
  33   initialize_in_thread();
  34   wait_for_universe_init();
  35 
  36   run_service();
  37 
  38   terminate();
  39 }
  40 
  41 void G1YoungRemSetSamplingThread::stop() {
  42   // it is ok to take late safepoints here, if needed
  43   {
  44     MutexLockerEx mu(Terminator_lock);
  45     _should_terminate = true;
  46   }
  47 
  48   stop_service();


  83       _vtime_accum = (os::elapsedVTime() - vtime_start);
  84     } else {
  85       _vtime_accum = 0.0;
  86     }
  87 
  88     sleep_before_next_cycle();
  89   }
  90 }
  91 
  92 void G1YoungRemSetSamplingThread::stop_service() {
  93   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  94   _monitor->notify();
  95 }
  96 
  97 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
  98   SuspendibleThreadSetJoiner sts;
  99   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 100   G1CollectorPolicy* g1p = g1h->g1_policy();
 101   if (g1p->adaptive_young_list_length()) {
 102     int regions_visited = 0;
 103     g1h->young_list()->rs_length_sampling_init();
 104     while (g1h->young_list()->rs_length_sampling_more()) {
 105       g1h->young_list()->rs_length_sampling_next();












 106       ++regions_visited;
 107 
 108       // we try to yield every time we visit 10 regions
 109       if (regions_visited == 10) {
 110         if (sts.should_yield()) {
 111           sts.yield();
 112           // we just abandon the iteration
 113           break;

 114         }
 115         regions_visited = 0;
 116       }

 117     }
 118 
 119     g1p->revise_young_list_target_length_if_necessary();
 120   }
 121 }


   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/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1CollectorPolicy.hpp"
  28 #include "gc/g1/g1YoungRemSetSamplingThread.hpp"
  29 #include "gc/g1/heapRegion.inline.hpp"
  30 #include "gc/g1/heapRegionRemSet.hpp"
  31 #include "gc/g1/suspendibleThreadSet.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 
  34 void G1YoungRemSetSamplingThread::run() {
  35   initialize_in_thread();
  36   wait_for_universe_init();
  37 
  38   run_service();
  39 
  40   terminate();
  41 }
  42 
  43 void G1YoungRemSetSamplingThread::stop() {
  44   // it is ok to take late safepoints here, if needed
  45   {
  46     MutexLockerEx mu(Terminator_lock);
  47     _should_terminate = true;
  48   }
  49 
  50   stop_service();


  85       _vtime_accum = (os::elapsedVTime() - vtime_start);
  86     } else {
  87       _vtime_accum = 0.0;
  88     }
  89 
  90     sleep_before_next_cycle();
  91   }
  92 }
  93 
  94 void G1YoungRemSetSamplingThread::stop_service() {
  95   MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
  96   _monitor->notify();
  97 }
  98 
  99 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
 100   SuspendibleThreadSetJoiner sts;
 101   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 102   G1CollectorPolicy* g1p = g1h->g1_policy();
 103   if (g1p->adaptive_young_list_length()) {
 104     int regions_visited = 0;
 105     HeapRegion* hr = g1h->young_list()->first_region();
 106     size_t sampled_rs_lengths = 0;
 107 
 108     while (hr != NULL) {
 109       size_t rs_length = hr->rem_set()->occupied();
 110       sampled_rs_lengths += rs_length;
 111 
 112       // The current region may not yet have been added to the
 113       // incremental collection set (it gets added when it is
 114       // retired as the current allocation region).
 115       if (hr->in_collection_set()) {
 116         // Update the collection set policy information for this region
 117         g1p->update_incremental_cset_info(hr, rs_length);
 118       }
 119 
 120       ++regions_visited;
 121 
 122       // we try to yield every time we visit 10 regions
 123       if (regions_visited == 10) {
 124         if (sts.should_yield()) {
 125           sts.yield();
 126           // A gc may have occurred and our sampling data is stale and further
 127           // traversal of the young list is unsafe
 128           return;
 129         }
 130         regions_visited = 0;
 131       }
 132       hr = hr->get_next_young_region();
 133     }
 134     g1p->revise_young_list_target_length_if_necessary(sampled_rs_lengths);

 135   }
 136 }
< prev index next >