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

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

author
tonyp
date
Sat, 07 Mar 2009 11:07:37 -0500
changeset 1054
7ea5ca260b28
parent 777
37f87013dfd8
child 1072
25e146966e7c
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/_concurrentG1Refine.cpp.incl"
ysr@777 27
ysr@777 28 bool ConcurrentG1Refine::_enabled = false;
ysr@777 29
ysr@777 30 ConcurrentG1Refine::ConcurrentG1Refine() :
ysr@777 31 _pya(PYA_continue), _last_pya(PYA_continue),
ysr@777 32 _last_cards_during(), _first_traversal(false),
ysr@777 33 _card_counts(NULL), _cur_card_count_histo(NULL), _cum_card_count_histo(NULL),
ysr@777 34 _hot_cache(NULL),
ysr@777 35 _def_use_cache(false), _use_cache(false),
ysr@777 36 _n_periods(0), _total_cards(0), _total_travs(0)
ysr@777 37 {
ysr@777 38 if (G1ConcRefine) {
ysr@777 39 _cg1rThread = new ConcurrentG1RefineThread(this);
ysr@777 40 assert(cg1rThread() != NULL, "Conc refine should have been created");
ysr@777 41 assert(cg1rThread()->cg1r() == this,
ysr@777 42 "Conc refine thread should refer to this");
ysr@777 43 } else {
ysr@777 44 _cg1rThread = NULL;
ysr@777 45 }
ysr@777 46 }
ysr@777 47
ysr@777 48 void ConcurrentG1Refine::init() {
ysr@777 49 if (G1ConcRSLogCacheSize > 0 || G1ConcRSCountTraversals) {
ysr@777 50 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 51 _n_card_counts =
ysr@777 52 (unsigned) (g1h->g1_reserved_obj_bytes() >> CardTableModRefBS::card_shift);
ysr@777 53 _card_counts = NEW_C_HEAP_ARRAY(unsigned char, _n_card_counts);
ysr@777 54 for (size_t i = 0; i < _n_card_counts; i++) _card_counts[i] = 0;
ysr@777 55 ModRefBarrierSet* bs = g1h->mr_bs();
ysr@777 56 guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
ysr@777 57 CardTableModRefBS* ctbs = (CardTableModRefBS*)bs;
ysr@777 58 _ct_bot = ctbs->byte_for_const(g1h->reserved_region().start());
ysr@777 59 if (G1ConcRSCountTraversals) {
ysr@777 60 _cur_card_count_histo = NEW_C_HEAP_ARRAY(unsigned, 256);
ysr@777 61 _cum_card_count_histo = NEW_C_HEAP_ARRAY(unsigned, 256);
ysr@777 62 for (int i = 0; i < 256; i++) {
ysr@777 63 _cur_card_count_histo[i] = 0;
ysr@777 64 _cum_card_count_histo[i] = 0;
ysr@777 65 }
ysr@777 66 }
ysr@777 67 }
ysr@777 68 if (G1ConcRSLogCacheSize > 0) {
ysr@777 69 _def_use_cache = true;
ysr@777 70 _use_cache = true;
ysr@777 71 _hot_cache_size = (1 << G1ConcRSLogCacheSize);
ysr@777 72 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size);
ysr@777 73 _n_hot = 0;
ysr@777 74 _hot_cache_idx = 0;
ysr@777 75 }
ysr@777 76 }
ysr@777 77
ysr@777 78 ConcurrentG1Refine::~ConcurrentG1Refine() {
ysr@777 79 if (G1ConcRSLogCacheSize > 0 || G1ConcRSCountTraversals) {
ysr@777 80 assert(_card_counts != NULL, "Logic");
ysr@777 81 FREE_C_HEAP_ARRAY(unsigned char, _card_counts);
ysr@777 82 assert(_cur_card_count_histo != NULL, "Logic");
ysr@777 83 FREE_C_HEAP_ARRAY(unsigned, _cur_card_count_histo);
ysr@777 84 assert(_cum_card_count_histo != NULL, "Logic");
ysr@777 85 FREE_C_HEAP_ARRAY(unsigned, _cum_card_count_histo);
ysr@777 86 }
ysr@777 87 if (G1ConcRSLogCacheSize > 0) {
ysr@777 88 assert(_hot_cache != NULL, "Logic");
ysr@777 89 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache);
ysr@777 90 }
ysr@777 91 }
ysr@777 92
ysr@777 93 bool ConcurrentG1Refine::refine() {
ysr@777 94 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 95 unsigned cards_before = g1h->g1_rem_set()->conc_refine_cards();
ysr@777 96 clear_hot_cache(); // Any previous values in this are now invalid.
ysr@777 97 g1h->g1_rem_set()->concurrentRefinementPass(this);
ysr@777 98 _traversals++;
ysr@777 99 unsigned cards_after = g1h->g1_rem_set()->conc_refine_cards();
ysr@777 100 unsigned cards_during = cards_after-cards_before;
ysr@777 101 // If this is the first traversal in the current enabling
ysr@777 102 // and we did some cards, or if the number of cards found is decreasing
ysr@777 103 // sufficiently quickly, then keep going. Otherwise, sleep a while.
ysr@777 104 bool res =
ysr@777 105 (_first_traversal && cards_during > 0)
ysr@777 106 ||
ysr@777 107 (!_first_traversal && cards_during * 3 < _last_cards_during * 2);
ysr@777 108 _last_cards_during = cards_during;
ysr@777 109 _first_traversal = false;
ysr@777 110 return res;
ysr@777 111 }
ysr@777 112
ysr@777 113 void ConcurrentG1Refine::enable() {
ysr@777 114 MutexLocker x(G1ConcRefine_mon);
ysr@777 115 if (!_enabled) {
ysr@777 116 _enabled = true;
ysr@777 117 _first_traversal = true; _last_cards_during = 0;
ysr@777 118 G1ConcRefine_mon->notify_all();
ysr@777 119 }
ysr@777 120 }
ysr@777 121
ysr@777 122 unsigned ConcurrentG1Refine::disable() {
ysr@777 123 MutexLocker x(G1ConcRefine_mon);
ysr@777 124 if (_enabled) {
ysr@777 125 _enabled = false;
ysr@777 126 return _traversals;
ysr@777 127 } else {
ysr@777 128 return 0;
ysr@777 129 }
ysr@777 130 }
ysr@777 131
ysr@777 132 void ConcurrentG1Refine::wait_for_ConcurrentG1Refine_enabled() {
ysr@777 133 G1ConcRefine_mon->lock();
ysr@777 134 while (!_enabled) {
ysr@777 135 G1ConcRefine_mon->wait(Mutex::_no_safepoint_check_flag);
ysr@777 136 }
ysr@777 137 G1ConcRefine_mon->unlock();
ysr@777 138 _traversals = 0;
ysr@777 139 };
ysr@777 140
ysr@777 141 void ConcurrentG1Refine::set_pya_restart() {
ysr@777 142 // If we're using the log-based RS barrier, the above will cause
ysr@777 143 // in-progress traversals of completed log buffers to quit early; we will
ysr@777 144 // also abandon all other buffers.
ysr@777 145 if (G1RSBarrierUseQueue) {
ysr@777 146 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 147 dcqs.abandon_logs();
ysr@777 148 if (_cg1rThread->do_traversal()) {
ysr@777 149 _pya = PYA_restart;
ysr@777 150 } else {
ysr@777 151 _cg1rThread->set_do_traversal(true);
ysr@777 152 // Reset the post-yield actions.
ysr@777 153 _pya = PYA_continue;
ysr@777 154 _last_pya = PYA_continue;
ysr@777 155 }
ysr@777 156 } else {
ysr@777 157 _pya = PYA_restart;
ysr@777 158 }
ysr@777 159 }
ysr@777 160
ysr@777 161 void ConcurrentG1Refine::set_pya_cancel() {
ysr@777 162 _pya = PYA_cancel;
ysr@777 163 }
ysr@777 164
ysr@777 165 PostYieldAction ConcurrentG1Refine::get_pya() {
ysr@777 166 if (_pya != PYA_continue) {
ysr@777 167 jint val = _pya;
ysr@777 168 while (true) {
ysr@777 169 jint val_read = Atomic::cmpxchg(PYA_continue, &_pya, val);
ysr@777 170 if (val_read == val) {
ysr@777 171 PostYieldAction res = (PostYieldAction)val;
ysr@777 172 assert(res != PYA_continue, "Only the refine thread should reset.");
ysr@777 173 _last_pya = res;
ysr@777 174 return res;
ysr@777 175 } else {
ysr@777 176 val = val_read;
ysr@777 177 }
ysr@777 178 }
ysr@777 179 }
ysr@777 180 // QQQ WELL WHAT DO WE RETURN HERE???
ysr@777 181 // make up something!
ysr@777 182 return PYA_continue;
ysr@777 183 }
ysr@777 184
ysr@777 185 PostYieldAction ConcurrentG1Refine::get_last_pya() {
ysr@777 186 PostYieldAction res = _last_pya;
ysr@777 187 _last_pya = PYA_continue;
ysr@777 188 return res;
ysr@777 189 }
ysr@777 190
ysr@777 191 bool ConcurrentG1Refine::do_traversal() {
ysr@777 192 return _cg1rThread->do_traversal();
ysr@777 193 }
ysr@777 194
ysr@777 195 int ConcurrentG1Refine::add_card_count(jbyte* card_ptr) {
ysr@777 196 size_t card_num = (card_ptr - _ct_bot);
ysr@777 197 guarantee(0 <= card_num && card_num < _n_card_counts, "Bounds");
ysr@777 198 unsigned char cnt = _card_counts[card_num];
ysr@777 199 if (cnt < 255) _card_counts[card_num]++;
ysr@777 200 return cnt;
ysr@777 201 _total_travs++;
ysr@777 202 }
ysr@777 203
ysr@777 204 jbyte* ConcurrentG1Refine::cache_insert(jbyte* card_ptr) {
ysr@777 205 int count = add_card_count(card_ptr);
ysr@777 206 // Count previously unvisited cards.
ysr@777 207 if (count == 0) _total_cards++;
ysr@777 208 // We'll assume a traversal unless we store it in the cache.
ysr@777 209 if (count < G1ConcRSHotCardLimit) {
ysr@777 210 _total_travs++;
ysr@777 211 return card_ptr;
ysr@777 212 }
ysr@777 213 // Otherwise, it's hot.
ysr@777 214 jbyte* res = NULL;
ysr@777 215 MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
ysr@777 216 if (_n_hot == _hot_cache_size) {
ysr@777 217 _total_travs++;
ysr@777 218 res = _hot_cache[_hot_cache_idx];
ysr@777 219 _n_hot--;
ysr@777 220 }
ysr@777 221 // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx.
ysr@777 222 _hot_cache[_hot_cache_idx] = card_ptr;
ysr@777 223 _hot_cache_idx++;
ysr@777 224 if (_hot_cache_idx == _hot_cache_size) _hot_cache_idx = 0;
ysr@777 225 _n_hot++;
ysr@777 226 return res;
ysr@777 227 }
ysr@777 228
ysr@777 229
ysr@777 230 void ConcurrentG1Refine::clean_up_cache(int worker_i, G1RemSet* g1rs) {
ysr@777 231 assert(!use_cache(), "cache should be disabled");
ysr@777 232 int start_ind = _hot_cache_idx-1;
ysr@777 233 for (int i = 0; i < _n_hot; i++) {
ysr@777 234 int ind = start_ind - i;
ysr@777 235 if (ind < 0) ind = ind + _hot_cache_size;
ysr@777 236 jbyte* entry = _hot_cache[ind];
ysr@777 237 if (entry != NULL) {
ysr@777 238 g1rs->concurrentRefineOneCard(entry, worker_i);
ysr@777 239 }
ysr@777 240 }
ysr@777 241 _n_hot = 0;
ysr@777 242 _hot_cache_idx = 0;
ysr@777 243 }
ysr@777 244
ysr@777 245 void ConcurrentG1Refine::clear_and_record_card_counts() {
ysr@777 246 if (G1ConcRSLogCacheSize == 0 && !G1ConcRSCountTraversals) return;
ysr@777 247 _n_periods++;
ysr@777 248 if (G1ConcRSCountTraversals) {
ysr@777 249 for (size_t i = 0; i < _n_card_counts; i++) {
ysr@777 250 unsigned char bucket = _card_counts[i];
ysr@777 251 _cur_card_count_histo[bucket]++;
ysr@777 252 _card_counts[i] = 0;
ysr@777 253 }
ysr@777 254 gclog_or_tty->print_cr("Card counts:");
ysr@777 255 for (int i = 0; i < 256; i++) {
ysr@777 256 if (_cur_card_count_histo[i] > 0) {
ysr@777 257 gclog_or_tty->print_cr(" %3d: %9d", i, _cur_card_count_histo[i]);
ysr@777 258 _cum_card_count_histo[i] += _cur_card_count_histo[i];
ysr@777 259 _cur_card_count_histo[i] = 0;
ysr@777 260 }
ysr@777 261 }
ysr@777 262 } else {
ysr@777 263 assert(G1ConcRSLogCacheSize > 0, "Logic");
ysr@777 264 Copy::fill_to_words((HeapWord*)(&_card_counts[0]),
ysr@777 265 _n_card_counts / HeapWordSize);
ysr@777 266 }
ysr@777 267 }
ysr@777 268
ysr@777 269 void
ysr@777 270 ConcurrentG1Refine::
ysr@777 271 print_card_count_histo_range(unsigned* histo, int from, int to,
ysr@777 272 float& cum_card_pct,
ysr@777 273 float& cum_travs_pct) {
ysr@777 274 unsigned cards = 0;
ysr@777 275 unsigned travs = 0;
ysr@777 276 guarantee(to <= 256, "Precondition");
ysr@777 277 for (int i = from; i < to-1; i++) {
ysr@777 278 cards += histo[i];
ysr@777 279 travs += histo[i] * i;
ysr@777 280 }
ysr@777 281 if (to == 256) {
ysr@777 282 unsigned histo_card_sum = 0;
ysr@777 283 unsigned histo_trav_sum = 0;
ysr@777 284 for (int i = 1; i < 255; i++) {
ysr@777 285 histo_trav_sum += histo[i] * i;
ysr@777 286 }
ysr@777 287 cards += histo[255];
ysr@777 288 // correct traversals for the last one.
ysr@777 289 unsigned travs_255 = (unsigned) (_total_travs - histo_trav_sum);
ysr@777 290 travs += travs_255;
ysr@777 291
ysr@777 292 } else {
ysr@777 293 cards += histo[to-1];
ysr@777 294 travs += histo[to-1] * (to-1);
ysr@777 295 }
ysr@777 296 float fperiods = (float)_n_periods;
ysr@777 297 float f_tot_cards = (float)_total_cards/fperiods;
ysr@777 298 float f_tot_travs = (float)_total_travs/fperiods;
ysr@777 299 if (cards > 0) {
ysr@777 300 float fcards = (float)cards/fperiods;
ysr@777 301 float ftravs = (float)travs/fperiods;
ysr@777 302 if (to == 256) {
ysr@777 303 gclog_or_tty->print(" %4d- %10.2f%10.2f", from, fcards, ftravs);
ysr@777 304 } else {
ysr@777 305 gclog_or_tty->print(" %4d-%4d %10.2f%10.2f", from, to-1, fcards, ftravs);
ysr@777 306 }
ysr@777 307 float pct_cards = fcards*100.0/f_tot_cards;
ysr@777 308 cum_card_pct += pct_cards;
ysr@777 309 float pct_travs = ftravs*100.0/f_tot_travs;
ysr@777 310 cum_travs_pct += pct_travs;
ysr@777 311 gclog_or_tty->print_cr("%10.2f%10.2f%10.2f%10.2f",
ysr@777 312 pct_cards, cum_card_pct,
ysr@777 313 pct_travs, cum_travs_pct);
ysr@777 314 }
ysr@777 315 }
ysr@777 316
ysr@777 317 void ConcurrentG1Refine::print_final_card_counts() {
ysr@777 318 if (!G1ConcRSCountTraversals) return;
ysr@777 319
ysr@777 320 gclog_or_tty->print_cr("Did %d total traversals of %d distinct cards.",
ysr@777 321 _total_travs, _total_cards);
ysr@777 322 float fperiods = (float)_n_periods;
ysr@777 323 gclog_or_tty->print_cr(" This is an average of %8.2f traversals, %8.2f cards, "
ysr@777 324 "per collection.", (float)_total_travs/fperiods,
ysr@777 325 (float)_total_cards/fperiods);
ysr@777 326 gclog_or_tty->print_cr(" This is an average of %8.2f traversals/distinct "
ysr@777 327 "dirty card.\n",
ysr@777 328 _total_cards > 0 ?
ysr@777 329 (float)_total_travs/(float)_total_cards : 0.0);
ysr@777 330
ysr@777 331
ysr@777 332 gclog_or_tty->print_cr("Histogram:\n\n%10s %10s%10s%10s%10s%10s%10s",
ysr@777 333 "range", "# cards", "# travs", "% cards", "(cum)",
ysr@777 334 "% travs", "(cum)");
ysr@777 335 gclog_or_tty->print_cr("------------------------------------------------------------"
ysr@777 336 "-------------");
ysr@777 337 float cum_cards_pct = 0.0;
ysr@777 338 float cum_travs_pct = 0.0;
ysr@777 339 for (int i = 1; i < 10; i++) {
ysr@777 340 print_card_count_histo_range(_cum_card_count_histo, i, i+1,
ysr@777 341 cum_cards_pct, cum_travs_pct);
ysr@777 342 }
ysr@777 343 for (int i = 10; i < 100; i += 10) {
ysr@777 344 print_card_count_histo_range(_cum_card_count_histo, i, i+10,
ysr@777 345 cum_cards_pct, cum_travs_pct);
ysr@777 346 }
ysr@777 347 print_card_count_histo_range(_cum_card_count_histo, 100, 150,
ysr@777 348 cum_cards_pct, cum_travs_pct);
ysr@777 349 print_card_count_histo_range(_cum_card_count_histo, 150, 200,
ysr@777 350 cum_cards_pct, cum_travs_pct);
ysr@777 351 print_card_count_histo_range(_cum_card_count_histo, 150, 255,
ysr@777 352 cum_cards_pct, cum_travs_pct);
ysr@777 353 print_card_count_histo_range(_cum_card_count_histo, 255, 256,
ysr@777 354 cum_cards_pct, cum_travs_pct);
ysr@777 355 }

mercurial