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

Thu, 30 Apr 2009 15:07:53 -0700

author
johnc
date
Thu, 30 Apr 2009 15:07:53 -0700
changeset 1186
20c6f43950b5
parent 1051
4f360ec815ba
child 1229
315a5d70b295
permissions
-rw-r--r--

6490395: G1: Tidy up command line flags.
Summary: Change G1 flag names to be more consistent and disable some in 'product' mode.
Reviewed-by: tonyp, iveresov

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
johnc@1186 56 if (G1TraceConcurrentRefinement) {
johnc@1186 57 gclog_or_tty->print_cr("G1-Refine starting pass");
johnc@1186 58 }
ysr@777 59 _sts.join();
ysr@777 60 bool no_sleep = _cg1r->refine();
ysr@777 61 _sts.leave();
ysr@777 62 if (!no_sleep) {
ysr@777 63 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
ysr@777 64 // We do this only for the timeout; we don't expect this to be signalled.
ysr@777 65 CGC_lock->wait(Mutex::_no_safepoint_check_flag, timeout);
ysr@777 66 }
ysr@777 67 }
ysr@777 68 }
ysr@777 69
ysr@777 70 void ConcurrentG1RefineThread::queueBasedRefinement() {
ysr@777 71 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 72 // Wait for completed log buffers to exist.
ysr@777 73 {
ysr@777 74 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
ysr@777 75 while (!_do_traversal && !dcqs.process_completed_buffers() &&
ysr@777 76 !_should_terminate) {
ysr@777 77 DirtyCardQ_CBL_mon->wait(Mutex::_no_safepoint_check_flag);
ysr@777 78 }
ysr@777 79 }
ysr@777 80
ysr@777 81 if (_should_terminate) {
ysr@777 82 return;
ysr@777 83 }
ysr@777 84
ysr@777 85 // Now we take them off (this doesn't hold locks while it applies
ysr@777 86 // closures.) (If we did a full collection, then we'll do a full
ysr@777 87 // traversal.
ysr@777 88 _sts.join();
ysr@777 89 if (_do_traversal) {
ysr@777 90 (void)_cg1r->refine();
ysr@777 91 switch (_cg1r->get_last_pya()) {
ysr@777 92 case PYA_cancel: case PYA_continue:
ysr@777 93 // Continue was caught and handled inside "refine". If it's still
ysr@777 94 // "continue" when we get here, we're done.
ysr@777 95 _do_traversal = false;
ysr@777 96 break;
ysr@777 97 case PYA_restart:
ysr@777 98 assert(_do_traversal, "Because of Full GC.");
ysr@777 99 break;
ysr@777 100 }
ysr@777 101 } else {
ysr@777 102 int n_logs = 0;
ysr@777 103 int lower_limit = 0;
ysr@777 104 double start_vtime_sec; // only used when G1SmoothConcRefine is on
ysr@777 105 int prev_buffer_num; // only used when G1SmoothConcRefine is on
ysr@777 106
ysr@777 107 if (G1SmoothConcRefine) {
ysr@777 108 lower_limit = 0;
ysr@777 109 start_vtime_sec = os::elapsedVTime();
ysr@777 110 prev_buffer_num = (int) dcqs.completed_buffers_num();
ysr@777 111 } else {
ysr@777 112 lower_limit = DCQBarrierProcessCompletedThreshold / 4; // For now.
ysr@777 113 }
ysr@777 114 while (dcqs.apply_closure_to_completed_buffer(0, lower_limit)) {
ysr@777 115 double end_vtime_sec;
ysr@777 116 double elapsed_vtime_sec;
ysr@777 117 int elapsed_vtime_ms;
ysr@777 118 int curr_buffer_num;
ysr@777 119
ysr@777 120 if (G1SmoothConcRefine) {
ysr@777 121 end_vtime_sec = os::elapsedVTime();
ysr@777 122 elapsed_vtime_sec = end_vtime_sec - start_vtime_sec;
ysr@777 123 elapsed_vtime_ms = (int) (elapsed_vtime_sec * 1000.0);
ysr@777 124 curr_buffer_num = (int) dcqs.completed_buffers_num();
ysr@777 125
ysr@777 126 if (curr_buffer_num > prev_buffer_num ||
ysr@777 127 curr_buffer_num > DCQBarrierProcessCompletedThreshold) {
ysr@777 128 decreaseInterval(elapsed_vtime_ms);
ysr@777 129 } else if (curr_buffer_num < prev_buffer_num) {
ysr@777 130 increaseInterval(elapsed_vtime_ms);
ysr@777 131 }
ysr@777 132 }
ysr@777 133
ysr@777 134 sample_young_list_rs_lengths();
ysr@777 135 _co_tracker.update(false);
ysr@777 136
ysr@777 137 if (G1SmoothConcRefine) {
ysr@777 138 prev_buffer_num = curr_buffer_num;
ysr@777 139 _sts.leave();
ysr@777 140 os::sleep(Thread::current(), (jlong) _interval_ms, false);
ysr@777 141 _sts.join();
iveresov@1051 142 start_vtime_sec = os::elapsedVTime();
ysr@777 143 }
ysr@777 144 n_logs++;
ysr@777 145 }
ysr@777 146 // Make sure we harvest the PYA, if any.
ysr@777 147 (void)_cg1r->get_pya();
ysr@777 148 }
ysr@777 149 _sts.leave();
ysr@777 150 }
ysr@777 151
ysr@777 152 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
ysr@777 153 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 154 G1CollectorPolicy* g1p = g1h->g1_policy();
ysr@777 155 if (g1p->adaptive_young_list_length()) {
ysr@777 156 int regions_visited = 0;
ysr@777 157
ysr@777 158 g1h->young_list_rs_length_sampling_init();
ysr@777 159 while (g1h->young_list_rs_length_sampling_more()) {
ysr@777 160 g1h->young_list_rs_length_sampling_next();
ysr@777 161 ++regions_visited;
ysr@777 162
ysr@777 163 // we try to yield every time we visit 10 regions
ysr@777 164 if (regions_visited == 10) {
ysr@777 165 if (_sts.should_yield()) {
ysr@777 166 _sts.yield("G1 refine");
ysr@777 167 // we just abandon the iteration
ysr@777 168 break;
ysr@777 169 }
ysr@777 170 regions_visited = 0;
ysr@777 171 }
ysr@777 172 }
ysr@777 173
ysr@777 174 g1p->check_prediction_validity();
ysr@777 175 }
ysr@777 176 }
ysr@777 177
ysr@777 178 void ConcurrentG1RefineThread::run() {
ysr@777 179 initialize_in_thread();
ysr@777 180 _vtime_start = os::elapsedVTime();
ysr@777 181 wait_for_universe_init();
ysr@777 182
ysr@777 183 _co_tracker.enable();
ysr@777 184 _co_tracker.start();
ysr@777 185
ysr@777 186 while (!_should_terminate) {
ysr@777 187 // wait until started is set.
ysr@777 188 if (G1RSBarrierUseQueue) {
ysr@777 189 queueBasedRefinement();
ysr@777 190 } else {
ysr@777 191 traversalBasedRefinement();
ysr@777 192 }
ysr@777 193 _sts.join();
ysr@777 194 _co_tracker.update();
ysr@777 195 _sts.leave();
ysr@777 196 if (os::supports_vtime()) {
ysr@777 197 _vtime_accum = (os::elapsedVTime() - _vtime_start);
ysr@777 198 } else {
ysr@777 199 _vtime_accum = 0.0;
ysr@777 200 }
ysr@777 201 }
ysr@777 202 _sts.join();
ysr@777 203 _co_tracker.update(true);
ysr@777 204 _sts.leave();
ysr@777 205 assert(_should_terminate, "just checking");
ysr@777 206
ysr@777 207 terminate();
ysr@777 208 }
ysr@777 209
ysr@777 210
ysr@777 211 void ConcurrentG1RefineThread::yield() {
johnc@1186 212 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield");
ysr@777 213 _sts.yield("G1 refine");
johnc@1186 214 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield-end");
ysr@777 215 }
ysr@777 216
ysr@777 217 void ConcurrentG1RefineThread::stop() {
ysr@777 218 // it is ok to take late safepoints here, if needed
ysr@777 219 {
ysr@777 220 MutexLockerEx mu(Terminator_lock);
ysr@777 221 _should_terminate = true;
ysr@777 222 }
ysr@777 223
ysr@777 224 {
ysr@777 225 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
ysr@777 226 DirtyCardQ_CBL_mon->notify_all();
ysr@777 227 }
ysr@777 228
ysr@777 229 {
ysr@777 230 MutexLockerEx mu(Terminator_lock);
ysr@777 231 while (!_has_terminated) {
ysr@777 232 Terminator_lock->wait();
ysr@777 233 }
ysr@777 234 }
johnc@1186 235 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-stop");
ysr@777 236 }
ysr@777 237
ysr@777 238 void ConcurrentG1RefineThread::print() {
ysr@777 239 gclog_or_tty->print("\"Concurrent G1 Refinement Thread\" ");
ysr@777 240 Thread::print();
ysr@777 241 gclog_or_tty->cr();
ysr@777 242 }
ysr@777 243
ysr@777 244 void ConcurrentG1RefineThread::set_do_traversal(bool b) {
ysr@777 245 _do_traversal = b;
ysr@777 246 }

mercurial