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

Sat, 07 Mar 2009 11:07:37 -0500

author
tonyp
date
Sat, 07 Mar 2009 11:07:37 -0500
changeset 1054
7ea5ca260b28
parent 1051
4f360ec815ba
child 1186
20c6f43950b5
permissions
-rw-r--r--

6814467: G1: small fixes related to concurrent marking verboseness
Summary: A few small fixes to remove some inconsistencies in the concurrent mark-related verbose GC output.
Reviewed-by: jmasa

ysr@777 1 /*
ysr@777 2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
ysr@777 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@777 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@777 21 * have any questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 #include "incls/_precompiled.incl"
ysr@777 26 #include "incls/_concurrentG1RefineThread.cpp.incl"
ysr@777 27
ysr@777 28 // ======= Concurrent Mark Thread ========
ysr@777 29
ysr@777 30 // The CM thread is created when the G1 garbage collector is used
ysr@777 31
ysr@777 32 ConcurrentG1RefineThread::
ysr@777 33 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r) :
ysr@777 34 ConcurrentGCThread(),
ysr@777 35 _cg1r(cg1r),
ysr@777 36 _started(false),
ysr@777 37 _in_progress(false),
ysr@777 38 _do_traversal(false),
ysr@777 39 _vtime_accum(0.0),
ysr@777 40 _co_tracker(G1CRGroup),
ysr@777 41 _interval_ms(5.0)
ysr@777 42 {
ysr@777 43 create_and_start();
ysr@777 44 }
ysr@777 45
ysr@777 46 const long timeout = 200; // ms.
ysr@777 47
ysr@777 48 void ConcurrentG1RefineThread::traversalBasedRefinement() {
ysr@777 49 _cg1r->wait_for_ConcurrentG1Refine_enabled();
ysr@777 50 MutexLocker x(G1ConcRefine_mon);
ysr@777 51 while (_cg1r->enabled()) {
ysr@777 52 MutexUnlocker ux(G1ConcRefine_mon);
ysr@777 53 ResourceMark rm;
ysr@777 54 HandleMark hm;
ysr@777 55
ysr@777 56 if (TraceG1Refine) gclog_or_tty->print_cr("G1-Refine starting pass");
ysr@777 57 _sts.join();
ysr@777 58 bool no_sleep = _cg1r->refine();
ysr@777 59 _sts.leave();
ysr@777 60 if (!no_sleep) {
ysr@777 61 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
ysr@777 62 // We do this only for the timeout; we don't expect this to be signalled.
ysr@777 63 CGC_lock->wait(Mutex::_no_safepoint_check_flag, timeout);
ysr@777 64 }
ysr@777 65 }
ysr@777 66 }
ysr@777 67
ysr@777 68 void ConcurrentG1RefineThread::queueBasedRefinement() {
ysr@777 69 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 70 // Wait for completed log buffers to exist.
ysr@777 71 {
ysr@777 72 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
ysr@777 73 while (!_do_traversal && !dcqs.process_completed_buffers() &&
ysr@777 74 !_should_terminate) {
ysr@777 75 DirtyCardQ_CBL_mon->wait(Mutex::_no_safepoint_check_flag);
ysr@777 76 }
ysr@777 77 }
ysr@777 78
ysr@777 79 if (_should_terminate) {
ysr@777 80 return;
ysr@777 81 }
ysr@777 82
ysr@777 83 // Now we take them off (this doesn't hold locks while it applies
ysr@777 84 // closures.) (If we did a full collection, then we'll do a full
ysr@777 85 // traversal.
ysr@777 86 _sts.join();
ysr@777 87 if (_do_traversal) {
ysr@777 88 (void)_cg1r->refine();
ysr@777 89 switch (_cg1r->get_last_pya()) {
ysr@777 90 case PYA_cancel: case PYA_continue:
ysr@777 91 // Continue was caught and handled inside "refine". If it's still
ysr@777 92 // "continue" when we get here, we're done.
ysr@777 93 _do_traversal = false;
ysr@777 94 break;
ysr@777 95 case PYA_restart:
ysr@777 96 assert(_do_traversal, "Because of Full GC.");
ysr@777 97 break;
ysr@777 98 }
ysr@777 99 } else {
ysr@777 100 int n_logs = 0;
ysr@777 101 int lower_limit = 0;
ysr@777 102 double start_vtime_sec; // only used when G1SmoothConcRefine is on
ysr@777 103 int prev_buffer_num; // only used when G1SmoothConcRefine is on
ysr@777 104
ysr@777 105 if (G1SmoothConcRefine) {
ysr@777 106 lower_limit = 0;
ysr@777 107 start_vtime_sec = os::elapsedVTime();
ysr@777 108 prev_buffer_num = (int) dcqs.completed_buffers_num();
ysr@777 109 } else {
ysr@777 110 lower_limit = DCQBarrierProcessCompletedThreshold / 4; // For now.
ysr@777 111 }
ysr@777 112 while (dcqs.apply_closure_to_completed_buffer(0, lower_limit)) {
ysr@777 113 double end_vtime_sec;
ysr@777 114 double elapsed_vtime_sec;
ysr@777 115 int elapsed_vtime_ms;
ysr@777 116 int curr_buffer_num;
ysr@777 117
ysr@777 118 if (G1SmoothConcRefine) {
ysr@777 119 end_vtime_sec = os::elapsedVTime();
ysr@777 120 elapsed_vtime_sec = end_vtime_sec - start_vtime_sec;
ysr@777 121 elapsed_vtime_ms = (int) (elapsed_vtime_sec * 1000.0);
ysr@777 122 curr_buffer_num = (int) dcqs.completed_buffers_num();
ysr@777 123
ysr@777 124 if (curr_buffer_num > prev_buffer_num ||
ysr@777 125 curr_buffer_num > DCQBarrierProcessCompletedThreshold) {
ysr@777 126 decreaseInterval(elapsed_vtime_ms);
ysr@777 127 } else if (curr_buffer_num < prev_buffer_num) {
ysr@777 128 increaseInterval(elapsed_vtime_ms);
ysr@777 129 }
ysr@777 130 }
ysr@777 131
ysr@777 132 sample_young_list_rs_lengths();
ysr@777 133 _co_tracker.update(false);
ysr@777 134
ysr@777 135 if (G1SmoothConcRefine) {
ysr@777 136 prev_buffer_num = curr_buffer_num;
ysr@777 137 _sts.leave();
ysr@777 138 os::sleep(Thread::current(), (jlong) _interval_ms, false);
ysr@777 139 _sts.join();
iveresov@1051 140 start_vtime_sec = os::elapsedVTime();
ysr@777 141 }
ysr@777 142 n_logs++;
ysr@777 143 }
ysr@777 144 // Make sure we harvest the PYA, if any.
ysr@777 145 (void)_cg1r->get_pya();
ysr@777 146 }
ysr@777 147 _sts.leave();
ysr@777 148 }
ysr@777 149
ysr@777 150 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
ysr@777 151 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 152 G1CollectorPolicy* g1p = g1h->g1_policy();
ysr@777 153 if (g1p->adaptive_young_list_length()) {
ysr@777 154 int regions_visited = 0;
ysr@777 155
ysr@777 156 g1h->young_list_rs_length_sampling_init();
ysr@777 157 while (g1h->young_list_rs_length_sampling_more()) {
ysr@777 158 g1h->young_list_rs_length_sampling_next();
ysr@777 159 ++regions_visited;
ysr@777 160
ysr@777 161 // we try to yield every time we visit 10 regions
ysr@777 162 if (regions_visited == 10) {
ysr@777 163 if (_sts.should_yield()) {
ysr@777 164 _sts.yield("G1 refine");
ysr@777 165 // we just abandon the iteration
ysr@777 166 break;
ysr@777 167 }
ysr@777 168 regions_visited = 0;
ysr@777 169 }
ysr@777 170 }
ysr@777 171
ysr@777 172 g1p->check_prediction_validity();
ysr@777 173 }
ysr@777 174 }
ysr@777 175
ysr@777 176 void ConcurrentG1RefineThread::run() {
ysr@777 177 initialize_in_thread();
ysr@777 178 _vtime_start = os::elapsedVTime();
ysr@777 179 wait_for_universe_init();
ysr@777 180
ysr@777 181 _co_tracker.enable();
ysr@777 182 _co_tracker.start();
ysr@777 183
ysr@777 184 while (!_should_terminate) {
ysr@777 185 // wait until started is set.
ysr@777 186 if (G1RSBarrierUseQueue) {
ysr@777 187 queueBasedRefinement();
ysr@777 188 } else {
ysr@777 189 traversalBasedRefinement();
ysr@777 190 }
ysr@777 191 _sts.join();
ysr@777 192 _co_tracker.update();
ysr@777 193 _sts.leave();
ysr@777 194 if (os::supports_vtime()) {
ysr@777 195 _vtime_accum = (os::elapsedVTime() - _vtime_start);
ysr@777 196 } else {
ysr@777 197 _vtime_accum = 0.0;
ysr@777 198 }
ysr@777 199 }
ysr@777 200 _sts.join();
ysr@777 201 _co_tracker.update(true);
ysr@777 202 _sts.leave();
ysr@777 203 assert(_should_terminate, "just checking");
ysr@777 204
ysr@777 205 terminate();
ysr@777 206 }
ysr@777 207
ysr@777 208
ysr@777 209 void ConcurrentG1RefineThread::yield() {
ysr@777 210 if (TraceG1Refine) gclog_or_tty->print_cr("G1-Refine-yield");
ysr@777 211 _sts.yield("G1 refine");
ysr@777 212 if (TraceG1Refine) gclog_or_tty->print_cr("G1-Refine-yield-end");
ysr@777 213 }
ysr@777 214
ysr@777 215 void ConcurrentG1RefineThread::stop() {
ysr@777 216 // it is ok to take late safepoints here, if needed
ysr@777 217 {
ysr@777 218 MutexLockerEx mu(Terminator_lock);
ysr@777 219 _should_terminate = true;
ysr@777 220 }
ysr@777 221
ysr@777 222 {
ysr@777 223 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
ysr@777 224 DirtyCardQ_CBL_mon->notify_all();
ysr@777 225 }
ysr@777 226
ysr@777 227 {
ysr@777 228 MutexLockerEx mu(Terminator_lock);
ysr@777 229 while (!_has_terminated) {
ysr@777 230 Terminator_lock->wait();
ysr@777 231 }
ysr@777 232 }
ysr@777 233 if (TraceG1Refine) gclog_or_tty->print_cr("G1-Refine-stop");
ysr@777 234 }
ysr@777 235
ysr@777 236 void ConcurrentG1RefineThread::print() {
ysr@777 237 gclog_or_tty->print("\"Concurrent G1 Refinement Thread\" ");
ysr@777 238 Thread::print();
ysr@777 239 gclog_or_tty->cr();
ysr@777 240 }
ysr@777 241
ysr@777 242 void ConcurrentG1RefineThread::set_do_traversal(bool b) {
ysr@777 243 _do_traversal = b;
ysr@777 244 }

mercurial