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

Fri, 02 Oct 2009 16:12:07 -0400

author
tonyp
date
Fri, 02 Oct 2009 16:12:07 -0400
changeset 1454
035d2e036a9b
parent 1371
e1fdf4fd34dc
child 1546
44f61c24ddab
permissions
-rw-r--r--

6885041: G1: inconsistent thread dump
Summary: When G1 is enabled, thread dumps are inconsistent as the info for some of the G1 threads is not formatted properly.
Reviewed-by: ysr, johnc

ysr@777 1 /*
xdono@1279 2 * Copyright 2001-2009 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::
iveresov@1230 33 ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next,
iveresov@1230 34 int worker_id_offset, int worker_id) :
ysr@777 35 ConcurrentGCThread(),
iveresov@1230 36 _worker_id_offset(worker_id_offset),
iveresov@1229 37 _worker_id(worker_id),
iveresov@1229 38 _active(false),
iveresov@1229 39 _next(next),
ysr@777 40 _cg1r(cg1r),
ysr@777 41 _vtime_accum(0.0),
ysr@777 42 _interval_ms(5.0)
ysr@777 43 {
ysr@777 44 create_and_start();
ysr@777 45 }
ysr@777 46
ysr@777 47 void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
ysr@777 48 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 49 G1CollectorPolicy* g1p = g1h->g1_policy();
ysr@777 50 if (g1p->adaptive_young_list_length()) {
ysr@777 51 int regions_visited = 0;
ysr@777 52
ysr@777 53 g1h->young_list_rs_length_sampling_init();
ysr@777 54 while (g1h->young_list_rs_length_sampling_more()) {
ysr@777 55 g1h->young_list_rs_length_sampling_next();
ysr@777 56 ++regions_visited;
ysr@777 57
ysr@777 58 // we try to yield every time we visit 10 regions
ysr@777 59 if (regions_visited == 10) {
ysr@777 60 if (_sts.should_yield()) {
ysr@777 61 _sts.yield("G1 refine");
ysr@777 62 // we just abandon the iteration
ysr@777 63 break;
ysr@777 64 }
ysr@777 65 regions_visited = 0;
ysr@777 66 }
ysr@777 67 }
ysr@777 68
ysr@777 69 g1p->check_prediction_validity();
ysr@777 70 }
ysr@777 71 }
ysr@777 72
ysr@777 73 void ConcurrentG1RefineThread::run() {
ysr@777 74 initialize_in_thread();
ysr@777 75 _vtime_start = os::elapsedVTime();
ysr@777 76 wait_for_universe_init();
ysr@777 77
ysr@777 78 while (!_should_terminate) {
iveresov@1229 79 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
iveresov@1229 80 // Wait for completed log buffers to exist.
iveresov@1229 81 {
iveresov@1229 82 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
iveresov@1229 83 while (((_worker_id == 0 && !dcqs.process_completed_buffers()) ||
iveresov@1229 84 (_worker_id > 0 && !is_active())) &&
iveresov@1229 85 !_should_terminate) {
iveresov@1229 86 DirtyCardQ_CBL_mon->wait(Mutex::_no_safepoint_check_flag);
iveresov@1229 87 }
iveresov@1229 88 }
iveresov@1229 89
iveresov@1229 90 if (_should_terminate) {
iveresov@1229 91 return;
iveresov@1229 92 }
iveresov@1229 93
iveresov@1229 94 // Now we take them off (this doesn't hold locks while it applies
iveresov@1229 95 // closures.) (If we did a full collection, then we'll do a full
iveresov@1229 96 // traversal.
iveresov@1229 97 _sts.join();
iveresov@1229 98 int n_logs = 0;
iveresov@1229 99 int lower_limit = 0;
iveresov@1229 100 double start_vtime_sec; // only used when G1SmoothConcRefine is on
iveresov@1229 101 int prev_buffer_num; // only used when G1SmoothConcRefine is on
iveresov@1229 102 // This thread activation threshold
tonyp@1318 103 int threshold = G1UpdateBufferQueueProcessingThreshold * _worker_id;
iveresov@1229 104 // Next thread activation threshold
tonyp@1318 105 int next_threshold = threshold + G1UpdateBufferQueueProcessingThreshold;
tonyp@1318 106 int deactivation_threshold = MAX2<int>(threshold - G1UpdateBufferQueueProcessingThreshold / 2, 0);
iveresov@1229 107
iveresov@1229 108 if (G1SmoothConcRefine) {
iveresov@1229 109 lower_limit = 0;
iveresov@1229 110 start_vtime_sec = os::elapsedVTime();
iveresov@1229 111 prev_buffer_num = (int) dcqs.completed_buffers_num();
ysr@777 112 } else {
tonyp@1318 113 lower_limit = G1UpdateBufferQueueProcessingThreshold / 4; // For now.
ysr@777 114 }
iveresov@1230 115 while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, lower_limit)) {
iveresov@1229 116 double end_vtime_sec;
iveresov@1229 117 double elapsed_vtime_sec;
iveresov@1229 118 int elapsed_vtime_ms;
iveresov@1229 119 int curr_buffer_num = (int) dcqs.completed_buffers_num();
iveresov@1229 120
iveresov@1229 121 if (G1SmoothConcRefine) {
iveresov@1229 122 end_vtime_sec = os::elapsedVTime();
iveresov@1229 123 elapsed_vtime_sec = end_vtime_sec - start_vtime_sec;
iveresov@1229 124 elapsed_vtime_ms = (int) (elapsed_vtime_sec * 1000.0);
iveresov@1229 125
iveresov@1229 126 if (curr_buffer_num > prev_buffer_num ||
iveresov@1229 127 curr_buffer_num > next_threshold) {
iveresov@1229 128 decreaseInterval(elapsed_vtime_ms);
iveresov@1229 129 } else if (curr_buffer_num < prev_buffer_num) {
iveresov@1229 130 increaseInterval(elapsed_vtime_ms);
iveresov@1229 131 }
iveresov@1229 132 }
iveresov@1229 133 if (_worker_id == 0) {
iveresov@1229 134 sample_young_list_rs_lengths();
iveresov@1229 135 } else if (curr_buffer_num < deactivation_threshold) {
iveresov@1229 136 // If the number of the buffer has fallen below our threshold
iveresov@1229 137 // we should deactivate. The predecessor will reactivate this
iveresov@1229 138 // thread should the number of the buffers cross the threshold again.
iveresov@1229 139 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
iveresov@1229 140 deactivate();
iveresov@1229 141 if (G1TraceConcurrentRefinement) {
iveresov@1229 142 gclog_or_tty->print_cr("G1-Refine-deactivated worker %d", _worker_id);
iveresov@1229 143 }
iveresov@1229 144 break;
iveresov@1229 145 }
iveresov@1229 146
iveresov@1229 147 // Check if we need to activate the next thread.
iveresov@1229 148 if (curr_buffer_num > next_threshold && _next != NULL && !_next->is_active()) {
iveresov@1229 149 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
iveresov@1229 150 _next->activate();
iveresov@1229 151 DirtyCardQ_CBL_mon->notify_all();
iveresov@1229 152 if (G1TraceConcurrentRefinement) {
iveresov@1229 153 gclog_or_tty->print_cr("G1-Refine-activated worker %d", _next->_worker_id);
iveresov@1229 154 }
iveresov@1229 155 }
iveresov@1229 156
iveresov@1229 157 if (G1SmoothConcRefine) {
iveresov@1229 158 prev_buffer_num = curr_buffer_num;
iveresov@1229 159 _sts.leave();
iveresov@1229 160 os::sleep(Thread::current(), (jlong) _interval_ms, false);
iveresov@1229 161 _sts.join();
iveresov@1229 162 start_vtime_sec = os::elapsedVTime();
iveresov@1229 163 }
iveresov@1229 164 n_logs++;
iveresov@1229 165 }
ysr@777 166 _sts.leave();
iveresov@1229 167
ysr@777 168 if (os::supports_vtime()) {
ysr@777 169 _vtime_accum = (os::elapsedVTime() - _vtime_start);
ysr@777 170 } else {
ysr@777 171 _vtime_accum = 0.0;
ysr@777 172 }
ysr@777 173 }
ysr@777 174 assert(_should_terminate, "just checking");
ysr@777 175
ysr@777 176 terminate();
ysr@777 177 }
ysr@777 178
ysr@777 179
ysr@777 180 void ConcurrentG1RefineThread::yield() {
johnc@1186 181 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield");
ysr@777 182 _sts.yield("G1 refine");
johnc@1186 183 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield-end");
ysr@777 184 }
ysr@777 185
ysr@777 186 void ConcurrentG1RefineThread::stop() {
ysr@777 187 // it is ok to take late safepoints here, if needed
ysr@777 188 {
ysr@777 189 MutexLockerEx mu(Terminator_lock);
ysr@777 190 _should_terminate = true;
ysr@777 191 }
ysr@777 192
ysr@777 193 {
ysr@777 194 MutexLockerEx x(DirtyCardQ_CBL_mon, Mutex::_no_safepoint_check_flag);
ysr@777 195 DirtyCardQ_CBL_mon->notify_all();
ysr@777 196 }
ysr@777 197
ysr@777 198 {
ysr@777 199 MutexLockerEx mu(Terminator_lock);
ysr@777 200 while (!_has_terminated) {
ysr@777 201 Terminator_lock->wait();
ysr@777 202 }
ysr@777 203 }
johnc@1186 204 if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-stop");
ysr@777 205 }
ysr@777 206
tonyp@1454 207 void ConcurrentG1RefineThread::print() const {
tonyp@1454 208 print_on(tty);
ysr@777 209 }
tonyp@1454 210
tonyp@1454 211 void ConcurrentG1RefineThread::print_on(outputStream* st) const {
tonyp@1454 212 st->print("\"G1 Concurrent Refinement Thread#%d\" ", _worker_id);
tonyp@1454 213 Thread::print_on(st);
tonyp@1454 214 st->cr();
tonyp@1454 215 }

mercurial