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

Wed, 30 Sep 2009 14:50:51 -0400

author
tonyp
date
Wed, 30 Sep 2009 14:50:51 -0400
changeset 1479
6270f80a7331
parent 1377
2c79770d1f6e
child 1694
9eee977dd1a9
permissions
-rw-r--r--

6890137: G1: revamp reachable object dump
Summary: Revamp the reachable object dump debugging facility.
Reviewed-by: jmasa, apetrusenko

ysr@777 1 /*
xdono@1014 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/_heapRegionRemSet.cpp.incl"
ysr@777 27
ysr@777 28 #define HRRS_VERBOSE 0
ysr@777 29
ysr@777 30 #define PRT_COUNT_OCCUPIED 1
ysr@777 31
ysr@777 32 // OtherRegionsTable
ysr@777 33
ysr@777 34 class PerRegionTable: public CHeapObj {
ysr@777 35 friend class OtherRegionsTable;
ysr@777 36 friend class HeapRegionRemSetIterator;
ysr@777 37
ysr@777 38 HeapRegion* _hr;
ysr@777 39 BitMap _bm;
ysr@777 40 #if PRT_COUNT_OCCUPIED
ysr@777 41 jint _occupied;
ysr@777 42 #endif
ysr@777 43 PerRegionTable* _next_free;
ysr@777 44
ysr@777 45 PerRegionTable* next_free() { return _next_free; }
ysr@777 46 void set_next_free(PerRegionTable* prt) { _next_free = prt; }
ysr@777 47
ysr@777 48
ysr@777 49 static PerRegionTable* _free_list;
ysr@777 50
ysr@777 51 #ifdef _MSC_VER
ysr@777 52 // For some reason even though the classes are marked as friend they are unable
ysr@777 53 // to access CardsPerRegion when private/protected. Only the windows c++ compiler
ysr@777 54 // says this Sun CC and linux gcc don't have a problem with access when private
ysr@777 55
ysr@777 56 public:
ysr@777 57
ysr@777 58 #endif // _MSC_VER
ysr@777 59
ysr@777 60 protected:
ysr@777 61 // We need access in order to union things into the base table.
ysr@777 62 BitMap* bm() { return &_bm; }
ysr@777 63
apetrusenko@980 64 #if PRT_COUNT_OCCUPIED
ysr@777 65 void recount_occupied() {
ysr@777 66 _occupied = (jint) bm()->count_one_bits();
ysr@777 67 }
apetrusenko@980 68 #endif
ysr@777 69
ysr@777 70 PerRegionTable(HeapRegion* hr) :
ysr@777 71 _hr(hr),
ysr@777 72 #if PRT_COUNT_OCCUPIED
ysr@777 73 _occupied(0),
ysr@777 74 #endif
tonyp@1377 75 _bm(HeapRegion::CardsPerRegion, false /* in-resource-area */)
ysr@777 76 {}
ysr@777 77
ysr@777 78 static void free(PerRegionTable* prt) {
ysr@777 79 while (true) {
ysr@777 80 PerRegionTable* fl = _free_list;
ysr@777 81 prt->set_next_free(fl);
ysr@777 82 PerRegionTable* res =
ysr@777 83 (PerRegionTable*)
ysr@777 84 Atomic::cmpxchg_ptr(prt, &_free_list, fl);
ysr@777 85 if (res == fl) return;
ysr@777 86 }
ysr@777 87 ShouldNotReachHere();
ysr@777 88 }
ysr@777 89
ysr@777 90 static PerRegionTable* alloc(HeapRegion* hr) {
ysr@777 91 PerRegionTable* fl = _free_list;
ysr@777 92 while (fl != NULL) {
ysr@777 93 PerRegionTable* nxt = fl->next_free();
ysr@777 94 PerRegionTable* res =
ysr@777 95 (PerRegionTable*)
ysr@777 96 Atomic::cmpxchg_ptr(nxt, &_free_list, fl);
ysr@777 97 if (res == fl) {
ysr@777 98 fl->init(hr);
ysr@777 99 return fl;
ysr@777 100 } else {
ysr@777 101 fl = _free_list;
ysr@777 102 }
ysr@777 103 }
ysr@777 104 assert(fl == NULL, "Loop condition.");
ysr@777 105 return new PerRegionTable(hr);
ysr@777 106 }
ysr@777 107
johnc@1242 108 void add_card_work(CardIdx_t from_card, bool par) {
ysr@777 109 if (!_bm.at(from_card)) {
ysr@777 110 if (par) {
ysr@777 111 if (_bm.par_at_put(from_card, 1)) {
ysr@777 112 #if PRT_COUNT_OCCUPIED
ysr@777 113 Atomic::inc(&_occupied);
ysr@777 114 #endif
ysr@777 115 }
ysr@777 116 } else {
ysr@777 117 _bm.at_put(from_card, 1);
ysr@777 118 #if PRT_COUNT_OCCUPIED
ysr@777 119 _occupied++;
ysr@777 120 #endif
ysr@777 121 }
ysr@777 122 }
ysr@777 123 }
ysr@777 124
ysr@1280 125 void add_reference_work(OopOrNarrowOopStar from, bool par) {
ysr@777 126 // Must make this robust in case "from" is not in "_hr", because of
ysr@777 127 // concurrency.
ysr@777 128
ysr@777 129 #if HRRS_VERBOSE
ysr@777 130 gclog_or_tty->print_cr(" PRT::Add_reference_work(" PTR_FORMAT "->" PTR_FORMAT").",
ysr@777 131 from, *from);
ysr@777 132 #endif
ysr@777 133
ysr@777 134 HeapRegion* loc_hr = hr();
ysr@777 135 // If the test below fails, then this table was reused concurrently
ysr@777 136 // with this operation. This is OK, since the old table was coarsened,
ysr@777 137 // and adding a bit to the new table is never incorrect.
ysr@777 138 if (loc_hr->is_in_reserved(from)) {
ysr@777 139 size_t hw_offset = pointer_delta((HeapWord*)from, loc_hr->bottom());
johnc@1242 140 CardIdx_t from_card = (CardIdx_t)
johnc@1242 141 hw_offset >> (CardTableModRefBS::card_shift - LogHeapWordSize);
ysr@777 142
tonyp@1377 143 assert(0 <= from_card && from_card < HeapRegion::CardsPerRegion,
tonyp@1377 144 "Must be in range.");
johnc@1242 145 add_card_work(from_card, par);
ysr@777 146 }
ysr@777 147 }
ysr@777 148
ysr@777 149 public:
ysr@777 150
ysr@777 151 HeapRegion* hr() const { return _hr; }
ysr@777 152
ysr@777 153 #if PRT_COUNT_OCCUPIED
ysr@777 154 jint occupied() const {
ysr@777 155 // Overkill, but if we ever need it...
ysr@777 156 // guarantee(_occupied == _bm.count_one_bits(), "Check");
ysr@777 157 return _occupied;
ysr@777 158 }
ysr@777 159 #else
ysr@777 160 jint occupied() const {
ysr@777 161 return _bm.count_one_bits();
ysr@777 162 }
ysr@777 163 #endif
ysr@777 164
ysr@777 165 void init(HeapRegion* hr) {
ysr@777 166 _hr = hr;
ysr@777 167 #if PRT_COUNT_OCCUPIED
ysr@777 168 _occupied = 0;
ysr@777 169 #endif
ysr@777 170 _bm.clear();
ysr@777 171 }
ysr@777 172
ysr@1280 173 void add_reference(OopOrNarrowOopStar from) {
ysr@777 174 add_reference_work(from, /*parallel*/ true);
ysr@777 175 }
ysr@777 176
ysr@1280 177 void seq_add_reference(OopOrNarrowOopStar from) {
ysr@777 178 add_reference_work(from, /*parallel*/ false);
ysr@777 179 }
ysr@777 180
ysr@777 181 void scrub(CardTableModRefBS* ctbs, BitMap* card_bm) {
ysr@777 182 HeapWord* hr_bot = hr()->bottom();
swamyv@924 183 size_t hr_first_card_index = ctbs->index_for(hr_bot);
ysr@777 184 bm()->set_intersection_at_offset(*card_bm, hr_first_card_index);
ysr@777 185 #if PRT_COUNT_OCCUPIED
ysr@777 186 recount_occupied();
ysr@777 187 #endif
ysr@777 188 }
ysr@777 189
johnc@1242 190 void add_card(CardIdx_t from_card_index) {
ysr@777 191 add_card_work(from_card_index, /*parallel*/ true);
ysr@777 192 }
ysr@777 193
johnc@1242 194 void seq_add_card(CardIdx_t from_card_index) {
ysr@777 195 add_card_work(from_card_index, /*parallel*/ false);
ysr@777 196 }
ysr@777 197
ysr@777 198 // (Destructively) union the bitmap of the current table into the given
ysr@777 199 // bitmap (which is assumed to be of the same size.)
ysr@777 200 void union_bitmap_into(BitMap* bm) {
ysr@777 201 bm->set_union(_bm);
ysr@777 202 }
ysr@777 203
ysr@777 204 // Mem size in bytes.
ysr@777 205 size_t mem_size() const {
ysr@777 206 return sizeof(this) + _bm.size_in_words() * HeapWordSize;
ysr@777 207 }
ysr@777 208
ysr@777 209 static size_t fl_mem_size() {
ysr@777 210 PerRegionTable* cur = _free_list;
ysr@777 211 size_t res = 0;
ysr@777 212 while (cur != NULL) {
ysr@777 213 res += sizeof(PerRegionTable);
ysr@777 214 cur = cur->next_free();
ysr@777 215 }
ysr@777 216 return res;
ysr@777 217 }
ysr@777 218
ysr@777 219 // Requires "from" to be in "hr()".
ysr@1280 220 bool contains_reference(OopOrNarrowOopStar from) const {
ysr@777 221 assert(hr()->is_in_reserved(from), "Precondition.");
ysr@777 222 size_t card_ind = pointer_delta(from, hr()->bottom(),
ysr@777 223 CardTableModRefBS::card_size);
ysr@777 224 return _bm.at(card_ind);
ysr@777 225 }
ysr@777 226 };
ysr@777 227
ysr@777 228 PerRegionTable* PerRegionTable::_free_list = NULL;
ysr@777 229
ysr@777 230
ysr@777 231 #define COUNT_PAR_EXPANDS 0
ysr@777 232
ysr@777 233 #if COUNT_PAR_EXPANDS
ysr@777 234 static jint n_par_expands = 0;
ysr@777 235 static jint n_par_contracts = 0;
ysr@777 236 static jint par_expand_list_len = 0;
ysr@777 237 static jint max_par_expand_list_len = 0;
ysr@777 238
ysr@777 239 static void print_par_expand() {
ysr@777 240 Atomic::inc(&n_par_expands);
ysr@777 241 Atomic::inc(&par_expand_list_len);
ysr@777 242 if (par_expand_list_len > max_par_expand_list_len) {
ysr@777 243 max_par_expand_list_len = par_expand_list_len;
ysr@777 244 }
ysr@777 245 if ((n_par_expands % 10) == 0) {
ysr@777 246 gclog_or_tty->print_cr("\n\n%d par expands: %d contracts, "
ysr@777 247 "len = %d, max_len = %d\n.",
ysr@777 248 n_par_expands, n_par_contracts, par_expand_list_len,
ysr@777 249 max_par_expand_list_len);
ysr@777 250 }
ysr@777 251 }
ysr@777 252 #endif
ysr@777 253
ysr@777 254 class PosParPRT: public PerRegionTable {
ysr@777 255 PerRegionTable** _par_tables;
ysr@777 256
ysr@777 257 enum SomePrivateConstants {
ysr@777 258 ReserveParTableExpansion = 1
ysr@777 259 };
ysr@777 260
ysr@777 261 void par_expand() {
ysr@777 262 int n = HeapRegionRemSet::num_par_rem_sets()-1;
ysr@777 263 if (n <= 0) return;
ysr@777 264 if (_par_tables == NULL) {
ysr@777 265 PerRegionTable* res =
ysr@777 266 (PerRegionTable*)
ysr@777 267 Atomic::cmpxchg_ptr((PerRegionTable*)ReserveParTableExpansion,
ysr@777 268 &_par_tables, NULL);
ysr@777 269 if (res != NULL) return;
ysr@777 270 // Otherwise, we reserved the right to do the expansion.
ysr@777 271
ysr@777 272 PerRegionTable** ptables = NEW_C_HEAP_ARRAY(PerRegionTable*, n);
ysr@777 273 for (int i = 0; i < n; i++) {
ysr@777 274 PerRegionTable* ptable = PerRegionTable::alloc(hr());
ysr@777 275 ptables[i] = ptable;
ysr@777 276 }
ysr@777 277 // Here we do not need an atomic.
ysr@777 278 _par_tables = ptables;
ysr@777 279 #if COUNT_PAR_EXPANDS
ysr@777 280 print_par_expand();
ysr@777 281 #endif
ysr@777 282 // We must put this table on the expanded list.
ysr@777 283 PosParPRT* exp_head = _par_expanded_list;
ysr@777 284 while (true) {
ysr@777 285 set_next_par_expanded(exp_head);
ysr@777 286 PosParPRT* res =
ysr@777 287 (PosParPRT*)
ysr@777 288 Atomic::cmpxchg_ptr(this, &_par_expanded_list, exp_head);
ysr@777 289 if (res == exp_head) return;
ysr@777 290 // Otherwise.
ysr@777 291 exp_head = res;
ysr@777 292 }
ysr@777 293 ShouldNotReachHere();
ysr@777 294 }
ysr@777 295 }
ysr@777 296
ysr@777 297 void par_contract() {
ysr@777 298 assert(_par_tables != NULL, "Precondition.");
ysr@777 299 int n = HeapRegionRemSet::num_par_rem_sets()-1;
ysr@777 300 for (int i = 0; i < n; i++) {
ysr@777 301 _par_tables[i]->union_bitmap_into(bm());
ysr@777 302 PerRegionTable::free(_par_tables[i]);
ysr@777 303 _par_tables[i] = NULL;
ysr@777 304 }
ysr@777 305 #if PRT_COUNT_OCCUPIED
ysr@777 306 // We must recount the "occupied."
ysr@777 307 recount_occupied();
ysr@777 308 #endif
ysr@777 309 FREE_C_HEAP_ARRAY(PerRegionTable*, _par_tables);
ysr@777 310 _par_tables = NULL;
ysr@777 311 #if COUNT_PAR_EXPANDS
ysr@777 312 Atomic::inc(&n_par_contracts);
ysr@777 313 Atomic::dec(&par_expand_list_len);
ysr@777 314 #endif
ysr@777 315 }
ysr@777 316
ysr@777 317 static PerRegionTable** _par_table_fl;
ysr@777 318
ysr@777 319 PosParPRT* _next;
ysr@777 320
ysr@777 321 static PosParPRT* _free_list;
ysr@777 322
ysr@777 323 PerRegionTable** par_tables() const {
ysr@777 324 assert(uintptr_t(NULL) == 0, "Assumption.");
ysr@777 325 if (uintptr_t(_par_tables) <= ReserveParTableExpansion)
ysr@777 326 return NULL;
ysr@777 327 else
ysr@777 328 return _par_tables;
ysr@777 329 }
ysr@777 330
ysr@777 331 PosParPRT* _next_par_expanded;
ysr@777 332 PosParPRT* next_par_expanded() { return _next_par_expanded; }
ysr@777 333 void set_next_par_expanded(PosParPRT* ppprt) { _next_par_expanded = ppprt; }
ysr@777 334 static PosParPRT* _par_expanded_list;
ysr@777 335
ysr@777 336 public:
ysr@777 337
ysr@777 338 PosParPRT(HeapRegion* hr) : PerRegionTable(hr), _par_tables(NULL) {}
ysr@777 339
ysr@777 340 jint occupied() const {
ysr@777 341 jint res = PerRegionTable::occupied();
ysr@777 342 if (par_tables() != NULL) {
ysr@777 343 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
ysr@777 344 res += par_tables()[i]->occupied();
ysr@777 345 }
ysr@777 346 }
ysr@777 347 return res;
ysr@777 348 }
ysr@777 349
ysr@777 350 void init(HeapRegion* hr) {
ysr@777 351 PerRegionTable::init(hr);
ysr@777 352 _next = NULL;
ysr@777 353 if (par_tables() != NULL) {
ysr@777 354 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
ysr@777 355 par_tables()[i]->init(hr);
ysr@777 356 }
ysr@777 357 }
ysr@777 358 }
ysr@777 359
ysr@777 360 static void free(PosParPRT* prt) {
ysr@777 361 while (true) {
ysr@777 362 PosParPRT* fl = _free_list;
ysr@777 363 prt->set_next(fl);
ysr@777 364 PosParPRT* res =
ysr@777 365 (PosParPRT*)
ysr@777 366 Atomic::cmpxchg_ptr(prt, &_free_list, fl);
ysr@777 367 if (res == fl) return;
ysr@777 368 }
ysr@777 369 ShouldNotReachHere();
ysr@777 370 }
ysr@777 371
ysr@777 372 static PosParPRT* alloc(HeapRegion* hr) {
ysr@777 373 PosParPRT* fl = _free_list;
ysr@777 374 while (fl != NULL) {
ysr@777 375 PosParPRT* nxt = fl->next();
ysr@777 376 PosParPRT* res =
ysr@777 377 (PosParPRT*)
ysr@777 378 Atomic::cmpxchg_ptr(nxt, &_free_list, fl);
ysr@777 379 if (res == fl) {
ysr@777 380 fl->init(hr);
ysr@777 381 return fl;
ysr@777 382 } else {
ysr@777 383 fl = _free_list;
ysr@777 384 }
ysr@777 385 }
ysr@777 386 assert(fl == NULL, "Loop condition.");
ysr@777 387 return new PosParPRT(hr);
ysr@777 388 }
ysr@777 389
ysr@777 390 PosParPRT* next() const { return _next; }
ysr@777 391 void set_next(PosParPRT* nxt) { _next = nxt; }
ysr@777 392 PosParPRT** next_addr() { return &_next; }
ysr@777 393
ysr@1280 394 void add_reference(OopOrNarrowOopStar from, int tid) {
ysr@777 395 // Expand if necessary.
ysr@777 396 PerRegionTable** pt = par_tables();
ysr@777 397 if (par_tables() == NULL && tid > 0 && hr()->is_gc_alloc_region()) {
ysr@777 398 par_expand();
ysr@777 399 pt = par_tables();
ysr@777 400 }
ysr@777 401 if (pt != NULL) {
ysr@777 402 // We always have to assume that mods to table 0 are in parallel,
ysr@777 403 // because of the claiming scheme in parallel expansion. A thread
ysr@777 404 // with tid != 0 that finds the table to be NULL, but doesn't succeed
ysr@777 405 // in claiming the right of expanding it, will end up in the else
ysr@777 406 // clause of the above if test. That thread could be delayed, and a
ysr@777 407 // thread 0 add reference could see the table expanded, and come
ysr@777 408 // here. Both threads would be adding in parallel. But we get to
ysr@777 409 // not use atomics for tids > 0.
ysr@777 410 if (tid == 0) {
ysr@777 411 PerRegionTable::add_reference(from);
ysr@777 412 } else {
ysr@777 413 pt[tid-1]->seq_add_reference(from);
ysr@777 414 }
ysr@777 415 } else {
ysr@777 416 // Not expanded -- add to the base table.
ysr@777 417 PerRegionTable::add_reference(from);
ysr@777 418 }
ysr@777 419 }
ysr@777 420
ysr@777 421 void scrub(CardTableModRefBS* ctbs, BitMap* card_bm) {
ysr@777 422 assert(_par_tables == NULL, "Precondition");
ysr@777 423 PerRegionTable::scrub(ctbs, card_bm);
ysr@777 424 }
ysr@777 425
ysr@777 426 size_t mem_size() const {
ysr@777 427 size_t res =
ysr@777 428 PerRegionTable::mem_size() + sizeof(this) - sizeof(PerRegionTable);
ysr@777 429 if (_par_tables != NULL) {
ysr@777 430 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
ysr@777 431 res += _par_tables[i]->mem_size();
ysr@777 432 }
ysr@777 433 }
ysr@777 434 return res;
ysr@777 435 }
ysr@777 436
ysr@777 437 static size_t fl_mem_size() {
ysr@777 438 PosParPRT* cur = _free_list;
ysr@777 439 size_t res = 0;
ysr@777 440 while (cur != NULL) {
ysr@777 441 res += sizeof(PosParPRT);
ysr@777 442 cur = cur->next();
ysr@777 443 }
ysr@777 444 return res;
ysr@777 445 }
ysr@777 446
ysr@1280 447 bool contains_reference(OopOrNarrowOopStar from) const {
ysr@777 448 if (PerRegionTable::contains_reference(from)) return true;
ysr@777 449 if (_par_tables != NULL) {
ysr@777 450 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
ysr@777 451 if (_par_tables[i]->contains_reference(from)) return true;
ysr@777 452 }
ysr@777 453 }
ysr@777 454 return false;
ysr@777 455 }
ysr@777 456
ysr@777 457 static void par_contract_all();
ysr@777 458
ysr@777 459 };
ysr@777 460
ysr@777 461 void PosParPRT::par_contract_all() {
ysr@777 462 PosParPRT* hd = _par_expanded_list;
ysr@777 463 while (hd != NULL) {
ysr@777 464 PosParPRT* nxt = hd->next_par_expanded();
ysr@777 465 PosParPRT* res =
ysr@777 466 (PosParPRT*)
ysr@777 467 Atomic::cmpxchg_ptr(nxt, &_par_expanded_list, hd);
ysr@777 468 if (res == hd) {
ysr@777 469 // We claimed the right to contract this table.
ysr@777 470 hd->set_next_par_expanded(NULL);
ysr@777 471 hd->par_contract();
ysr@777 472 hd = _par_expanded_list;
ysr@777 473 } else {
ysr@777 474 hd = res;
ysr@777 475 }
ysr@777 476 }
ysr@777 477 }
ysr@777 478
ysr@777 479 PosParPRT* PosParPRT::_free_list = NULL;
ysr@777 480 PosParPRT* PosParPRT::_par_expanded_list = NULL;
ysr@777 481
ysr@777 482 jint OtherRegionsTable::_cache_probes = 0;
ysr@777 483 jint OtherRegionsTable::_cache_hits = 0;
ysr@777 484
ysr@777 485 size_t OtherRegionsTable::_max_fine_entries = 0;
ysr@777 486 size_t OtherRegionsTable::_mod_max_fine_entries_mask = 0;
ysr@777 487 #if SAMPLE_FOR_EVICTION
ysr@777 488 size_t OtherRegionsTable::_fine_eviction_stride = 0;
ysr@777 489 size_t OtherRegionsTable::_fine_eviction_sample_size = 0;
ysr@777 490 #endif
ysr@777 491
ysr@777 492 OtherRegionsTable::OtherRegionsTable(HeapRegion* hr) :
ysr@777 493 _g1h(G1CollectedHeap::heap()),
ysr@777 494 _m(Mutex::leaf, "An OtherRegionsTable lock", true),
ysr@777 495 _hr(hr),
ysr@777 496 _coarse_map(G1CollectedHeap::heap()->max_regions(),
ysr@777 497 false /* in-resource-area */),
ysr@777 498 _fine_grain_regions(NULL),
ysr@777 499 _n_fine_entries(0), _n_coarse_entries(0),
ysr@777 500 #if SAMPLE_FOR_EVICTION
ysr@777 501 _fine_eviction_start(0),
ysr@777 502 #endif
ysr@777 503 _sparse_table(hr)
ysr@777 504 {
ysr@777 505 typedef PosParPRT* PosParPRTPtr;
ysr@777 506 if (_max_fine_entries == 0) {
ysr@777 507 assert(_mod_max_fine_entries_mask == 0, "Both or none.");
kvn@1080 508 _max_fine_entries = (size_t)(1 << G1LogRSRegionEntries);
ysr@777 509 _mod_max_fine_entries_mask = _max_fine_entries - 1;
ysr@777 510 #if SAMPLE_FOR_EVICTION
ysr@777 511 assert(_fine_eviction_sample_size == 0
ysr@777 512 && _fine_eviction_stride == 0, "All init at same time.");
ysr@777 513 _fine_eviction_sample_size = MAX2((size_t)4, (size_t)G1LogRSRegionEntries);
ysr@777 514 _fine_eviction_stride = _max_fine_entries / _fine_eviction_sample_size;
ysr@777 515 #endif
ysr@777 516 }
ysr@777 517 _fine_grain_regions = new PosParPRTPtr[_max_fine_entries];
ysr@777 518 if (_fine_grain_regions == NULL)
ysr@777 519 vm_exit_out_of_memory(sizeof(void*)*_max_fine_entries,
ysr@777 520 "Failed to allocate _fine_grain_entries.");
ysr@777 521 for (size_t i = 0; i < _max_fine_entries; i++) {
ysr@777 522 _fine_grain_regions[i] = NULL;
ysr@777 523 }
ysr@777 524 }
ysr@777 525
ysr@777 526 int** OtherRegionsTable::_from_card_cache = NULL;
ysr@777 527 size_t OtherRegionsTable::_from_card_cache_max_regions = 0;
ysr@777 528 size_t OtherRegionsTable::_from_card_cache_mem_size = 0;
ysr@777 529
ysr@777 530 void OtherRegionsTable::init_from_card_cache(size_t max_regions) {
ysr@777 531 _from_card_cache_max_regions = max_regions;
ysr@777 532
ysr@777 533 int n_par_rs = HeapRegionRemSet::num_par_rem_sets();
ysr@777 534 _from_card_cache = NEW_C_HEAP_ARRAY(int*, n_par_rs);
ysr@777 535 for (int i = 0; i < n_par_rs; i++) {
ysr@777 536 _from_card_cache[i] = NEW_C_HEAP_ARRAY(int, max_regions);
ysr@777 537 for (size_t j = 0; j < max_regions; j++) {
ysr@777 538 _from_card_cache[i][j] = -1; // An invalid value.
ysr@777 539 }
ysr@777 540 }
ysr@777 541 _from_card_cache_mem_size = n_par_rs * max_regions * sizeof(int);
ysr@777 542 }
ysr@777 543
ysr@777 544 void OtherRegionsTable::shrink_from_card_cache(size_t new_n_regs) {
ysr@777 545 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
ysr@777 546 assert(new_n_regs <= _from_card_cache_max_regions, "Must be within max.");
ysr@777 547 for (size_t j = new_n_regs; j < _from_card_cache_max_regions; j++) {
ysr@777 548 _from_card_cache[i][j] = -1; // An invalid value.
ysr@777 549 }
ysr@777 550 }
ysr@777 551 }
ysr@777 552
ysr@777 553 #ifndef PRODUCT
ysr@777 554 void OtherRegionsTable::print_from_card_cache() {
ysr@777 555 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
ysr@777 556 for (size_t j = 0; j < _from_card_cache_max_regions; j++) {
ysr@777 557 gclog_or_tty->print_cr("_from_card_cache[%d][%d] = %d.",
ysr@777 558 i, j, _from_card_cache[i][j]);
ysr@777 559 }
ysr@777 560 }
ysr@777 561 }
ysr@777 562 #endif
ysr@777 563
ysr@1280 564 void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, int tid) {
ysr@777 565 size_t cur_hrs_ind = hr()->hrs_index();
ysr@777 566
ysr@777 567 #if HRRS_VERBOSE
ysr@777 568 gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").",
ysr@1280 569 from,
ysr@1280 570 UseCompressedOops
ysr@1280 571 ? oopDesc::load_decode_heap_oop((narrowOop*)from)
ysr@1280 572 : oopDesc::load_decode_heap_oop((oop*)from));
ysr@777 573 #endif
ysr@777 574
ysr@777 575 int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift);
ysr@777 576
ysr@777 577 #if HRRS_VERBOSE
ysr@777 578 gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = %d)",
ysr@777 579 hr()->bottom(), from_card,
ysr@777 580 _from_card_cache[tid][cur_hrs_ind]);
ysr@777 581 #endif
ysr@777 582
ysr@777 583 #define COUNT_CACHE 0
ysr@777 584 #if COUNT_CACHE
ysr@777 585 jint p = Atomic::add(1, &_cache_probes);
ysr@777 586 if ((p % 10000) == 0) {
ysr@777 587 jint hits = _cache_hits;
ysr@777 588 gclog_or_tty->print_cr("%d/%d = %5.2f%% RS cache hits.",
ysr@777 589 _cache_hits, p, 100.0* (float)hits/(float)p);
ysr@777 590 }
ysr@777 591 #endif
ysr@777 592 if (from_card == _from_card_cache[tid][cur_hrs_ind]) {
ysr@777 593 #if HRRS_VERBOSE
ysr@777 594 gclog_or_tty->print_cr(" from-card cache hit.");
ysr@777 595 #endif
ysr@777 596 #if COUNT_CACHE
ysr@777 597 Atomic::inc(&_cache_hits);
ysr@777 598 #endif
ysr@777 599 assert(contains_reference(from), "We just added it!");
ysr@777 600 return;
ysr@777 601 } else {
ysr@777 602 _from_card_cache[tid][cur_hrs_ind] = from_card;
ysr@777 603 }
ysr@777 604
ysr@777 605 // Note that this may be a continued H region.
ysr@777 606 HeapRegion* from_hr = _g1h->heap_region_containing_raw(from);
johnc@1242 607 RegionIdx_t from_hrs_ind = (RegionIdx_t) from_hr->hrs_index();
ysr@777 608
ysr@777 609 // If the region is already coarsened, return.
ysr@777 610 if (_coarse_map.at(from_hrs_ind)) {
ysr@777 611 #if HRRS_VERBOSE
ysr@777 612 gclog_or_tty->print_cr(" coarse map hit.");
ysr@777 613 #endif
ysr@777 614 assert(contains_reference(from), "We just added it!");
ysr@777 615 return;
ysr@777 616 }
ysr@777 617
ysr@777 618 // Otherwise find a per-region table to add it to.
ysr@777 619 size_t ind = from_hrs_ind & _mod_max_fine_entries_mask;
ysr@777 620 PosParPRT* prt = find_region_table(ind, from_hr);
ysr@777 621 if (prt == NULL) {
ysr@777 622 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
ysr@777 623 // Confirm that it's really not there...
ysr@777 624 prt = find_region_table(ind, from_hr);
ysr@777 625 if (prt == NULL) {
ysr@777 626
ysr@777 627 uintptr_t from_hr_bot_card_index =
ysr@777 628 uintptr_t(from_hr->bottom())
ysr@777 629 >> CardTableModRefBS::card_shift;
johnc@1242 630 CardIdx_t card_index = from_card - from_hr_bot_card_index;
tonyp@1377 631 assert(0 <= card_index && card_index < HeapRegion::CardsPerRegion,
ysr@777 632 "Must be in range.");
ysr@777 633 if (G1HRRSUseSparseTable &&
johnc@1242 634 _sparse_table.add_card(from_hrs_ind, card_index)) {
ysr@777 635 if (G1RecordHRRSOops) {
ysr@777 636 HeapRegionRemSet::record(hr(), from);
ysr@777 637 #if HRRS_VERBOSE
ysr@777 638 gclog_or_tty->print(" Added card " PTR_FORMAT " to region "
ysr@777 639 "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
ysr@777 640 align_size_down(uintptr_t(from),
ysr@777 641 CardTableModRefBS::card_size),
ysr@777 642 hr()->bottom(), from);
ysr@777 643 #endif
ysr@777 644 }
ysr@777 645 #if HRRS_VERBOSE
ysr@777 646 gclog_or_tty->print_cr(" added card to sparse table.");
ysr@777 647 #endif
ysr@777 648 assert(contains_reference_locked(from), "We just added it!");
ysr@777 649 return;
ysr@777 650 } else {
ysr@777 651 #if HRRS_VERBOSE
ysr@777 652 gclog_or_tty->print_cr(" [tid %d] sparse table entry "
ysr@777 653 "overflow(f: %d, t: %d)",
ysr@777 654 tid, from_hrs_ind, cur_hrs_ind);
ysr@777 655 #endif
ysr@777 656 }
ysr@777 657
ysr@777 658 // Otherwise, transfer from sparse to fine-grain.
johnc@1242 659 CardIdx_t cards[SparsePRTEntry::CardsPerEntry];
ysr@777 660 if (G1HRRSUseSparseTable) {
johnc@1242 661 bool res = _sparse_table.get_cards(from_hrs_ind, &cards[0]);
ysr@777 662 assert(res, "There should have been an entry");
ysr@777 663 }
ysr@777 664
ysr@777 665 if (_n_fine_entries == _max_fine_entries) {
ysr@777 666 prt = delete_region_table();
ysr@777 667 } else {
ysr@777 668 prt = PosParPRT::alloc(from_hr);
ysr@777 669 }
ysr@777 670 prt->init(from_hr);
ysr@777 671 // Record the outgoing pointer in the from_region's outgoing bitmap.
ysr@777 672 from_hr->rem_set()->add_outgoing_reference(hr());
ysr@777 673
ysr@777 674 PosParPRT* first_prt = _fine_grain_regions[ind];
ysr@777 675 prt->set_next(first_prt); // XXX Maybe move to init?
ysr@777 676 _fine_grain_regions[ind] = prt;
ysr@777 677 _n_fine_entries++;
ysr@777 678
ysr@777 679 // Add in the cards from the sparse table.
ysr@777 680 if (G1HRRSUseSparseTable) {
ysr@777 681 for (int i = 0; i < SparsePRTEntry::CardsPerEntry; i++) {
johnc@1242 682 CardIdx_t c = cards[i];
ysr@777 683 if (c != SparsePRTEntry::NullEntry) {
ysr@777 684 prt->add_card(c);
ysr@777 685 }
ysr@777 686 }
ysr@777 687 // Now we can delete the sparse entry.
johnc@1242 688 bool res = _sparse_table.delete_entry(from_hrs_ind);
ysr@777 689 assert(res, "It should have been there.");
ysr@777 690 }
ysr@777 691 }
ysr@777 692 assert(prt != NULL && prt->hr() == from_hr, "consequence");
ysr@777 693 }
ysr@777 694 // Note that we can't assert "prt->hr() == from_hr", because of the
ysr@777 695 // possibility of concurrent reuse. But see head comment of
ysr@777 696 // OtherRegionsTable for why this is OK.
ysr@777 697 assert(prt != NULL, "Inv");
ysr@777 698
ysr@777 699 prt->add_reference(from, tid);
ysr@777 700 if (G1RecordHRRSOops) {
ysr@777 701 HeapRegionRemSet::record(hr(), from);
ysr@777 702 #if HRRS_VERBOSE
ysr@777 703 gclog_or_tty->print("Added card " PTR_FORMAT " to region "
ysr@777 704 "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
ysr@777 705 align_size_down(uintptr_t(from),
ysr@777 706 CardTableModRefBS::card_size),
ysr@777 707 hr()->bottom(), from);
ysr@777 708 #endif
ysr@777 709 }
ysr@777 710 assert(contains_reference(from), "We just added it!");
ysr@777 711 }
ysr@777 712
ysr@777 713 PosParPRT*
ysr@777 714 OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const {
ysr@777 715 assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
ysr@777 716 PosParPRT* prt = _fine_grain_regions[ind];
ysr@777 717 while (prt != NULL && prt->hr() != hr) {
ysr@777 718 prt = prt->next();
ysr@777 719 }
ysr@777 720 // Loop postcondition is the method postcondition.
ysr@777 721 return prt;
ysr@777 722 }
ysr@777 723
ysr@777 724
ysr@777 725 #define DRT_CENSUS 0
ysr@777 726
ysr@777 727 #if DRT_CENSUS
ysr@777 728 static const int HistoSize = 6;
ysr@777 729 static int global_histo[HistoSize] = { 0, 0, 0, 0, 0, 0 };
ysr@777 730 static int coarsenings = 0;
ysr@777 731 static int occ_sum = 0;
ysr@777 732 #endif
ysr@777 733
ysr@777 734 jint OtherRegionsTable::_n_coarsenings = 0;
ysr@777 735
ysr@777 736 PosParPRT* OtherRegionsTable::delete_region_table() {
ysr@777 737 #if DRT_CENSUS
ysr@777 738 int histo[HistoSize] = { 0, 0, 0, 0, 0, 0 };
ysr@777 739 const int histo_limits[] = { 1, 4, 16, 64, 256, 2048 };
ysr@777 740 #endif
ysr@777 741
ysr@777 742 assert(_m.owned_by_self(), "Precondition");
ysr@777 743 assert(_n_fine_entries == _max_fine_entries, "Precondition");
ysr@777 744 PosParPRT* max = NULL;
ysr@777 745 jint max_occ = 0;
ysr@777 746 PosParPRT** max_prev;
ysr@777 747 size_t max_ind;
ysr@777 748
ysr@777 749 #if SAMPLE_FOR_EVICTION
ysr@777 750 size_t i = _fine_eviction_start;
ysr@777 751 for (size_t k = 0; k < _fine_eviction_sample_size; k++) {
ysr@777 752 size_t ii = i;
ysr@777 753 // Make sure we get a non-NULL sample.
ysr@777 754 while (_fine_grain_regions[ii] == NULL) {
ysr@777 755 ii++;
ysr@777 756 if (ii == _max_fine_entries) ii = 0;
ysr@777 757 guarantee(ii != i, "We must find one.");
ysr@777 758 }
ysr@777 759 PosParPRT** prev = &_fine_grain_regions[ii];
ysr@777 760 PosParPRT* cur = *prev;
ysr@777 761 while (cur != NULL) {
ysr@777 762 jint cur_occ = cur->occupied();
ysr@777 763 if (max == NULL || cur_occ > max_occ) {
ysr@777 764 max = cur;
ysr@777 765 max_prev = prev;
ysr@777 766 max_ind = i;
ysr@777 767 max_occ = cur_occ;
ysr@777 768 }
ysr@777 769 prev = cur->next_addr();
ysr@777 770 cur = cur->next();
ysr@777 771 }
ysr@777 772 i = i + _fine_eviction_stride;
ysr@777 773 if (i >= _n_fine_entries) i = i - _n_fine_entries;
ysr@777 774 }
ysr@777 775 _fine_eviction_start++;
ysr@777 776 if (_fine_eviction_start >= _n_fine_entries)
ysr@777 777 _fine_eviction_start -= _n_fine_entries;
ysr@777 778 #else
ysr@777 779 for (int i = 0; i < _max_fine_entries; i++) {
ysr@777 780 PosParPRT** prev = &_fine_grain_regions[i];
ysr@777 781 PosParPRT* cur = *prev;
ysr@777 782 while (cur != NULL) {
ysr@777 783 jint cur_occ = cur->occupied();
ysr@777 784 #if DRT_CENSUS
ysr@777 785 for (int k = 0; k < HistoSize; k++) {
ysr@777 786 if (cur_occ <= histo_limits[k]) {
ysr@777 787 histo[k]++; global_histo[k]++; break;
ysr@777 788 }
ysr@777 789 }
ysr@777 790 #endif
ysr@777 791 if (max == NULL || cur_occ > max_occ) {
ysr@777 792 max = cur;
ysr@777 793 max_prev = prev;
ysr@777 794 max_ind = i;
ysr@777 795 max_occ = cur_occ;
ysr@777 796 }
ysr@777 797 prev = cur->next_addr();
ysr@777 798 cur = cur->next();
ysr@777 799 }
ysr@777 800 }
ysr@777 801 #endif
ysr@777 802 // XXX
ysr@777 803 guarantee(max != NULL, "Since _n_fine_entries > 0");
ysr@777 804 #if DRT_CENSUS
ysr@777 805 gclog_or_tty->print_cr("In a coarsening: histo of occs:");
ysr@777 806 for (int k = 0; k < HistoSize; k++) {
ysr@777 807 gclog_or_tty->print_cr(" <= %4d: %5d.", histo_limits[k], histo[k]);
ysr@777 808 }
ysr@777 809 coarsenings++;
ysr@777 810 occ_sum += max_occ;
ysr@777 811 if ((coarsenings % 100) == 0) {
ysr@777 812 gclog_or_tty->print_cr("\ncoarsenings = %d; global summary:", coarsenings);
ysr@777 813 for (int k = 0; k < HistoSize; k++) {
ysr@777 814 gclog_or_tty->print_cr(" <= %4d: %5d.", histo_limits[k], global_histo[k]);
ysr@777 815 }
ysr@777 816 gclog_or_tty->print_cr("Avg occ of deleted region = %6.2f.",
ysr@777 817 (float)occ_sum/(float)coarsenings);
ysr@777 818 }
ysr@777 819 #endif
ysr@777 820
ysr@777 821 // Set the corresponding coarse bit.
ysr@777 822 int max_hrs_index = max->hr()->hrs_index();
ysr@777 823 if (!_coarse_map.at(max_hrs_index)) {
ysr@777 824 _coarse_map.at_put(max_hrs_index, true);
ysr@777 825 _n_coarse_entries++;
ysr@777 826 #if 0
ysr@777 827 gclog_or_tty->print("Coarsened entry in region [" PTR_FORMAT "...] "
ysr@777 828 "for region [" PTR_FORMAT "...] (%d coarse entries).\n",
ysr@777 829 hr()->bottom(),
ysr@777 830 max->hr()->bottom(),
ysr@777 831 _n_coarse_entries);
ysr@777 832 #endif
ysr@777 833 }
ysr@777 834
ysr@777 835 // Unsplice.
ysr@777 836 *max_prev = max->next();
ysr@777 837 Atomic::inc(&_n_coarsenings);
ysr@777 838 _n_fine_entries--;
ysr@777 839 return max;
ysr@777 840 }
ysr@777 841
ysr@777 842
ysr@777 843 // At present, this must be called stop-world single-threaded.
ysr@777 844 void OtherRegionsTable::scrub(CardTableModRefBS* ctbs,
ysr@777 845 BitMap* region_bm, BitMap* card_bm) {
ysr@777 846 // First eliminated garbage regions from the coarse map.
ysr@777 847 if (G1RSScrubVerbose)
ysr@777 848 gclog_or_tty->print_cr("Scrubbing region %d:", hr()->hrs_index());
ysr@777 849
ysr@777 850 assert(_coarse_map.size() == region_bm->size(), "Precondition");
ysr@777 851 if (G1RSScrubVerbose)
ysr@777 852 gclog_or_tty->print(" Coarse map: before = %d...", _n_coarse_entries);
ysr@777 853 _coarse_map.set_intersection(*region_bm);
ysr@777 854 _n_coarse_entries = _coarse_map.count_one_bits();
ysr@777 855 if (G1RSScrubVerbose)
ysr@777 856 gclog_or_tty->print_cr(" after = %d.", _n_coarse_entries);
ysr@777 857
ysr@777 858 // Now do the fine-grained maps.
ysr@777 859 for (size_t i = 0; i < _max_fine_entries; i++) {
ysr@777 860 PosParPRT* cur = _fine_grain_regions[i];
ysr@777 861 PosParPRT** prev = &_fine_grain_regions[i];
ysr@777 862 while (cur != NULL) {
ysr@777 863 PosParPRT* nxt = cur->next();
ysr@777 864 // If the entire region is dead, eliminate.
ysr@777 865 if (G1RSScrubVerbose)
ysr@777 866 gclog_or_tty->print_cr(" For other region %d:", cur->hr()->hrs_index());
ysr@777 867 if (!region_bm->at(cur->hr()->hrs_index())) {
ysr@777 868 *prev = nxt;
ysr@777 869 cur->set_next(NULL);
ysr@777 870 _n_fine_entries--;
ysr@777 871 if (G1RSScrubVerbose)
ysr@777 872 gclog_or_tty->print_cr(" deleted via region map.");
ysr@777 873 PosParPRT::free(cur);
ysr@777 874 } else {
ysr@777 875 // Do fine-grain elimination.
ysr@777 876 if (G1RSScrubVerbose)
ysr@777 877 gclog_or_tty->print(" occ: before = %4d.", cur->occupied());
ysr@777 878 cur->scrub(ctbs, card_bm);
ysr@777 879 if (G1RSScrubVerbose)
ysr@777 880 gclog_or_tty->print_cr(" after = %4d.", cur->occupied());
ysr@777 881 // Did that empty the table completely?
ysr@777 882 if (cur->occupied() == 0) {
ysr@777 883 *prev = nxt;
ysr@777 884 cur->set_next(NULL);
ysr@777 885 _n_fine_entries--;
ysr@777 886 PosParPRT::free(cur);
ysr@777 887 } else {
ysr@777 888 prev = cur->next_addr();
ysr@777 889 }
ysr@777 890 }
ysr@777 891 cur = nxt;
ysr@777 892 }
ysr@777 893 }
ysr@777 894 // Since we may have deleted a from_card_cache entry from the RS, clear
ysr@777 895 // the FCC.
ysr@777 896 clear_fcc();
ysr@777 897 }
ysr@777 898
ysr@777 899
ysr@777 900 size_t OtherRegionsTable::occupied() const {
ysr@777 901 // Cast away const in this case.
ysr@777 902 MutexLockerEx x((Mutex*)&_m, Mutex::_no_safepoint_check_flag);
ysr@777 903 size_t sum = occ_fine();
ysr@777 904 sum += occ_sparse();
ysr@777 905 sum += occ_coarse();
ysr@777 906 return sum;
ysr@777 907 }
ysr@777 908
ysr@777 909 size_t OtherRegionsTable::occ_fine() const {
ysr@777 910 size_t sum = 0;
ysr@777 911 for (size_t i = 0; i < _max_fine_entries; i++) {
ysr@777 912 PosParPRT* cur = _fine_grain_regions[i];
ysr@777 913 while (cur != NULL) {
ysr@777 914 sum += cur->occupied();
ysr@777 915 cur = cur->next();
ysr@777 916 }
ysr@777 917 }
ysr@777 918 return sum;
ysr@777 919 }
ysr@777 920
ysr@777 921 size_t OtherRegionsTable::occ_coarse() const {
tonyp@1377 922 return (_n_coarse_entries * HeapRegion::CardsPerRegion);
ysr@777 923 }
ysr@777 924
ysr@777 925 size_t OtherRegionsTable::occ_sparse() const {
ysr@777 926 return _sparse_table.occupied();
ysr@777 927 }
ysr@777 928
ysr@777 929 size_t OtherRegionsTable::mem_size() const {
ysr@777 930 // Cast away const in this case.
ysr@777 931 MutexLockerEx x((Mutex*)&_m, Mutex::_no_safepoint_check_flag);
ysr@777 932 size_t sum = 0;
ysr@777 933 for (size_t i = 0; i < _max_fine_entries; i++) {
ysr@777 934 PosParPRT* cur = _fine_grain_regions[i];
ysr@777 935 while (cur != NULL) {
ysr@777 936 sum += cur->mem_size();
ysr@777 937 cur = cur->next();
ysr@777 938 }
ysr@777 939 }
ysr@777 940 sum += (sizeof(PosParPRT*) * _max_fine_entries);
ysr@777 941 sum += (_coarse_map.size_in_words() * HeapWordSize);
ysr@777 942 sum += (_sparse_table.mem_size());
ysr@777 943 sum += sizeof(*this) - sizeof(_sparse_table); // Avoid double counting above.
ysr@777 944 return sum;
ysr@777 945 }
ysr@777 946
ysr@777 947 size_t OtherRegionsTable::static_mem_size() {
ysr@777 948 return _from_card_cache_mem_size;
ysr@777 949 }
ysr@777 950
ysr@777 951 size_t OtherRegionsTable::fl_mem_size() {
ysr@777 952 return PerRegionTable::fl_mem_size() + PosParPRT::fl_mem_size();
ysr@777 953 }
ysr@777 954
ysr@777 955 void OtherRegionsTable::clear_fcc() {
ysr@777 956 for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
ysr@777 957 _from_card_cache[i][hr()->hrs_index()] = -1;
ysr@777 958 }
ysr@777 959 }
ysr@777 960
ysr@777 961 void OtherRegionsTable::clear() {
ysr@777 962 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
ysr@777 963 for (size_t i = 0; i < _max_fine_entries; i++) {
ysr@777 964 PosParPRT* cur = _fine_grain_regions[i];
ysr@777 965 while (cur != NULL) {
ysr@777 966 PosParPRT* nxt = cur->next();
ysr@777 967 PosParPRT::free(cur);
ysr@777 968 cur = nxt;
ysr@777 969 }
ysr@777 970 _fine_grain_regions[i] = NULL;
ysr@777 971 }
ysr@777 972 _sparse_table.clear();
ysr@777 973 _coarse_map.clear();
ysr@777 974 _n_fine_entries = 0;
ysr@777 975 _n_coarse_entries = 0;
ysr@777 976
ysr@777 977 clear_fcc();
ysr@777 978 }
ysr@777 979
ysr@777 980 void OtherRegionsTable::clear_incoming_entry(HeapRegion* from_hr) {
ysr@777 981 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
ysr@777 982 size_t hrs_ind = (size_t)from_hr->hrs_index();
ysr@777 983 size_t ind = hrs_ind & _mod_max_fine_entries_mask;
ysr@777 984 if (del_single_region_table(ind, from_hr)) {
ysr@777 985 assert(!_coarse_map.at(hrs_ind), "Inv");
ysr@777 986 } else {
ysr@777 987 _coarse_map.par_at_put(hrs_ind, 0);
ysr@777 988 }
ysr@777 989 // Check to see if any of the fcc entries come from here.
ysr@777 990 int hr_ind = hr()->hrs_index();
ysr@777 991 for (int tid = 0; tid < HeapRegionRemSet::num_par_rem_sets(); tid++) {
ysr@777 992 int fcc_ent = _from_card_cache[tid][hr_ind];
ysr@777 993 if (fcc_ent != -1) {
ysr@777 994 HeapWord* card_addr = (HeapWord*)
ysr@777 995 (uintptr_t(fcc_ent) << CardTableModRefBS::card_shift);
ysr@777 996 if (hr()->is_in_reserved(card_addr)) {
ysr@777 997 // Clear the from card cache.
ysr@777 998 _from_card_cache[tid][hr_ind] = -1;
ysr@777 999 }
ysr@777 1000 }
ysr@777 1001 }
ysr@777 1002 }
ysr@777 1003
ysr@777 1004 bool OtherRegionsTable::del_single_region_table(size_t ind,
ysr@777 1005 HeapRegion* hr) {
ysr@777 1006 assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
ysr@777 1007 PosParPRT** prev_addr = &_fine_grain_regions[ind];
ysr@777 1008 PosParPRT* prt = *prev_addr;
ysr@777 1009 while (prt != NULL && prt->hr() != hr) {
ysr@777 1010 prev_addr = prt->next_addr();
ysr@777 1011 prt = prt->next();
ysr@777 1012 }
ysr@777 1013 if (prt != NULL) {
ysr@777 1014 assert(prt->hr() == hr, "Loop postcondition.");
ysr@777 1015 *prev_addr = prt->next();
ysr@777 1016 PosParPRT::free(prt);
ysr@777 1017 _n_fine_entries--;
ysr@777 1018 return true;
ysr@777 1019 } else {
ysr@777 1020 return false;
ysr@777 1021 }
ysr@777 1022 }
ysr@777 1023
ysr@1280 1024 bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
ysr@777 1025 // Cast away const in this case.
ysr@777 1026 MutexLockerEx x((Mutex*)&_m, Mutex::_no_safepoint_check_flag);
ysr@777 1027 return contains_reference_locked(from);
ysr@777 1028 }
ysr@777 1029
ysr@1280 1030 bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
ysr@777 1031 HeapRegion* hr = _g1h->heap_region_containing_raw(from);
ysr@777 1032 if (hr == NULL) return false;
johnc@1242 1033 RegionIdx_t hr_ind = (RegionIdx_t) hr->hrs_index();
ysr@777 1034 // Is this region in the coarse map?
ysr@777 1035 if (_coarse_map.at(hr_ind)) return true;
ysr@777 1036
ysr@777 1037 PosParPRT* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
ysr@777 1038 hr);
ysr@777 1039 if (prt != NULL) {
ysr@777 1040 return prt->contains_reference(from);
ysr@777 1041
ysr@777 1042 } else {
ysr@777 1043 uintptr_t from_card =
ysr@777 1044 (uintptr_t(from) >> CardTableModRefBS::card_shift);
ysr@777 1045 uintptr_t hr_bot_card_index =
ysr@777 1046 uintptr_t(hr->bottom()) >> CardTableModRefBS::card_shift;
ysr@777 1047 assert(from_card >= hr_bot_card_index, "Inv");
johnc@1242 1048 CardIdx_t card_index = from_card - hr_bot_card_index;
tonyp@1377 1049 assert(0 <= card_index && card_index < HeapRegion::CardsPerRegion,
tonyp@1377 1050 "Must be in range.");
johnc@1242 1051 return _sparse_table.contains_card(hr_ind, card_index);
ysr@777 1052 }
ysr@777 1053
ysr@777 1054
ysr@777 1055 }
ysr@777 1056
iveresov@1230 1057 // Determines how many threads can add records to an rset in parallel.
iveresov@1230 1058 // This can be done by either mutator threads together with the
iveresov@1230 1059 // concurrent refinement threads or GC threads.
ysr@777 1060 int HeapRegionRemSet::num_par_rem_sets() {
iveresov@1230 1061 return (int)MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
ysr@777 1062 }
ysr@777 1063
ysr@777 1064 HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
ysr@777 1065 HeapRegion* hr)
ysr@777 1066 : _bosa(bosa), _other_regions(hr),
ysr@777 1067 _outgoing_region_map(G1CollectedHeap::heap()->max_regions(),
ysr@777 1068 false /* in-resource-area */),
ysr@777 1069 _iter_state(Unclaimed)
ysr@777 1070 {}
ysr@777 1071
ysr@777 1072
ysr@777 1073 void HeapRegionRemSet::init_for_par_iteration() {
ysr@777 1074 _iter_state = Unclaimed;
ysr@777 1075 }
ysr@777 1076
ysr@777 1077 bool HeapRegionRemSet::claim_iter() {
ysr@777 1078 if (_iter_state != Unclaimed) return false;
ysr@777 1079 jint res = Atomic::cmpxchg(Claimed, (jint*)(&_iter_state), Unclaimed);
ysr@777 1080 return (res == Unclaimed);
ysr@777 1081 }
ysr@777 1082
ysr@777 1083 void HeapRegionRemSet::set_iter_complete() {
ysr@777 1084 _iter_state = Complete;
ysr@777 1085 }
ysr@777 1086
ysr@777 1087 bool HeapRegionRemSet::iter_is_complete() {
ysr@777 1088 return _iter_state == Complete;
ysr@777 1089 }
ysr@777 1090
ysr@777 1091
ysr@777 1092 void HeapRegionRemSet::init_iterator(HeapRegionRemSetIterator* iter) const {
ysr@777 1093 iter->initialize(this);
ysr@777 1094 }
ysr@777 1095
ysr@777 1096 #ifndef PRODUCT
ysr@777 1097 void HeapRegionRemSet::print() const {
ysr@777 1098 HeapRegionRemSetIterator iter;
ysr@777 1099 init_iterator(&iter);
ysr@777 1100 size_t card_index;
ysr@777 1101 while (iter.has_next(card_index)) {
ysr@777 1102 HeapWord* card_start =
ysr@777 1103 G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
ysr@777 1104 gclog_or_tty->print_cr(" Card " PTR_FORMAT ".", card_start);
ysr@777 1105 }
ysr@777 1106 // XXX
ysr@777 1107 if (iter.n_yielded() != occupied()) {
ysr@777 1108 gclog_or_tty->print_cr("Yielded disagrees with occupied:");
ysr@777 1109 gclog_or_tty->print_cr(" %6d yielded (%6d coarse, %6d fine).",
ysr@777 1110 iter.n_yielded(),
ysr@777 1111 iter.n_yielded_coarse(), iter.n_yielded_fine());
ysr@777 1112 gclog_or_tty->print_cr(" %6d occ (%6d coarse, %6d fine).",
ysr@777 1113 occupied(), occ_coarse(), occ_fine());
ysr@777 1114 }
ysr@777 1115 guarantee(iter.n_yielded() == occupied(),
ysr@777 1116 "We should have yielded all the represented cards.");
ysr@777 1117 }
ysr@777 1118 #endif
ysr@777 1119
ysr@777 1120 void HeapRegionRemSet::cleanup() {
ysr@777 1121 SparsePRT::cleanup_all();
ysr@777 1122 }
ysr@777 1123
ysr@777 1124 void HeapRegionRemSet::par_cleanup() {
ysr@777 1125 PosParPRT::par_contract_all();
ysr@777 1126 }
ysr@777 1127
ysr@777 1128 void HeapRegionRemSet::add_outgoing_reference(HeapRegion* to_hr) {
ysr@777 1129 _outgoing_region_map.par_at_put(to_hr->hrs_index(), 1);
ysr@777 1130 }
ysr@777 1131
ysr@777 1132 void HeapRegionRemSet::clear() {
ysr@777 1133 clear_outgoing_entries();
ysr@777 1134 _outgoing_region_map.clear();
ysr@777 1135 _other_regions.clear();
ysr@777 1136 assert(occupied() == 0, "Should be clear.");
ysr@777 1137 }
ysr@777 1138
ysr@777 1139 void HeapRegionRemSet::clear_outgoing_entries() {
ysr@777 1140 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 1141 size_t i = _outgoing_region_map.get_next_one_offset(0);
ysr@777 1142 while (i < _outgoing_region_map.size()) {
ysr@777 1143 HeapRegion* to_region = g1h->region_at(i);
apetrusenko@980 1144 if (!to_region->in_collection_set()) {
apetrusenko@980 1145 to_region->rem_set()->clear_incoming_entry(hr());
apetrusenko@980 1146 }
ysr@777 1147 i = _outgoing_region_map.get_next_one_offset(i+1);
ysr@777 1148 }
ysr@777 1149 }
ysr@777 1150
ysr@777 1151
ysr@777 1152 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs,
ysr@777 1153 BitMap* region_bm, BitMap* card_bm) {
ysr@777 1154 _other_regions.scrub(ctbs, region_bm, card_bm);
ysr@777 1155 }
ysr@777 1156
ysr@777 1157 //-------------------- Iteration --------------------
ysr@777 1158
ysr@777 1159 HeapRegionRemSetIterator::
ysr@777 1160 HeapRegionRemSetIterator() :
ysr@777 1161 _hrrs(NULL),
ysr@777 1162 _g1h(G1CollectedHeap::heap()),
ysr@777 1163 _bosa(NULL),
ysr@777 1164 _sparse_iter(size_t(G1CollectedHeap::heap()->reserved_region().start())
ysr@777 1165 >> CardTableModRefBS::card_shift)
ysr@777 1166 {}
ysr@777 1167
ysr@777 1168 void HeapRegionRemSetIterator::initialize(const HeapRegionRemSet* hrrs) {
ysr@777 1169 _hrrs = hrrs;
ysr@777 1170 _coarse_map = &_hrrs->_other_regions._coarse_map;
ysr@777 1171 _fine_grain_regions = _hrrs->_other_regions._fine_grain_regions;
ysr@777 1172 _bosa = _hrrs->bosa();
ysr@777 1173
ysr@777 1174 _is = Sparse;
ysr@777 1175 // Set these values so that we increment to the first region.
ysr@777 1176 _coarse_cur_region_index = -1;
tonyp@1377 1177 _coarse_cur_region_cur_card = (HeapRegion::CardsPerRegion-1);;
ysr@777 1178
ysr@777 1179 _cur_region_cur_card = 0;
ysr@777 1180
ysr@777 1181 _fine_array_index = -1;
ysr@777 1182 _fine_cur_prt = NULL;
ysr@777 1183
ysr@777 1184 _n_yielded_coarse = 0;
ysr@777 1185 _n_yielded_fine = 0;
ysr@777 1186 _n_yielded_sparse = 0;
ysr@777 1187
ysr@777 1188 _sparse_iter.init(&hrrs->_other_regions._sparse_table);
ysr@777 1189 }
ysr@777 1190
ysr@777 1191 bool HeapRegionRemSetIterator::coarse_has_next(size_t& card_index) {
ysr@777 1192 if (_hrrs->_other_regions._n_coarse_entries == 0) return false;
ysr@777 1193 // Go to the next card.
ysr@777 1194 _coarse_cur_region_cur_card++;
ysr@777 1195 // Was the last the last card in the current region?
tonyp@1377 1196 if (_coarse_cur_region_cur_card == HeapRegion::CardsPerRegion) {
ysr@777 1197 // Yes: find the next region. This may leave _coarse_cur_region_index
ysr@777 1198 // Set to the last index, in which case there are no more coarse
ysr@777 1199 // regions.
ysr@777 1200 _coarse_cur_region_index =
ysr@777 1201 (int) _coarse_map->get_next_one_offset(_coarse_cur_region_index + 1);
ysr@777 1202 if ((size_t)_coarse_cur_region_index < _coarse_map->size()) {
ysr@777 1203 _coarse_cur_region_cur_card = 0;
ysr@777 1204 HeapWord* r_bot =
ysr@777 1205 _g1h->region_at(_coarse_cur_region_index)->bottom();
ysr@777 1206 _cur_region_card_offset = _bosa->index_for(r_bot);
ysr@777 1207 } else {
ysr@777 1208 return false;
ysr@777 1209 }
ysr@777 1210 }
ysr@777 1211 // If we didn't return false above, then we can yield a card.
ysr@777 1212 card_index = _cur_region_card_offset + _coarse_cur_region_cur_card;
ysr@777 1213 return true;
ysr@777 1214 }
ysr@777 1215
ysr@777 1216 void HeapRegionRemSetIterator::fine_find_next_non_null_prt() {
ysr@777 1217 // Otherwise, find the next bucket list in the array.
ysr@777 1218 _fine_array_index++;
ysr@777 1219 while (_fine_array_index < (int) OtherRegionsTable::_max_fine_entries) {
ysr@777 1220 _fine_cur_prt = _fine_grain_regions[_fine_array_index];
ysr@777 1221 if (_fine_cur_prt != NULL) return;
ysr@777 1222 else _fine_array_index++;
ysr@777 1223 }
ysr@777 1224 assert(_fine_cur_prt == NULL, "Loop post");
ysr@777 1225 }
ysr@777 1226
ysr@777 1227 bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
ysr@777 1228 if (fine_has_next()) {
ysr@777 1229 _cur_region_cur_card =
ysr@777 1230 _fine_cur_prt->_bm.get_next_one_offset(_cur_region_cur_card + 1);
ysr@777 1231 }
ysr@777 1232 while (!fine_has_next()) {
tonyp@1377 1233 if (_cur_region_cur_card == (size_t) HeapRegion::CardsPerRegion) {
ysr@777 1234 _cur_region_cur_card = 0;
ysr@777 1235 _fine_cur_prt = _fine_cur_prt->next();
ysr@777 1236 }
ysr@777 1237 if (_fine_cur_prt == NULL) {
ysr@777 1238 fine_find_next_non_null_prt();
ysr@777 1239 if (_fine_cur_prt == NULL) return false;
ysr@777 1240 }
ysr@777 1241 assert(_fine_cur_prt != NULL && _cur_region_cur_card == 0,
ysr@777 1242 "inv.");
ysr@777 1243 HeapWord* r_bot =
ysr@777 1244 _fine_cur_prt->hr()->bottom();
ysr@777 1245 _cur_region_card_offset = _bosa->index_for(r_bot);
ysr@777 1246 _cur_region_cur_card = _fine_cur_prt->_bm.get_next_one_offset(0);
ysr@777 1247 }
ysr@777 1248 assert(fine_has_next(), "Or else we exited the loop via the return.");
ysr@777 1249 card_index = _cur_region_card_offset + _cur_region_cur_card;
ysr@777 1250 return true;
ysr@777 1251 }
ysr@777 1252
ysr@777 1253 bool HeapRegionRemSetIterator::fine_has_next() {
ysr@777 1254 return
ysr@777 1255 _fine_cur_prt != NULL &&
tonyp@1377 1256 _cur_region_cur_card < (size_t) HeapRegion::CardsPerRegion;
ysr@777 1257 }
ysr@777 1258
ysr@777 1259 bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
ysr@777 1260 switch (_is) {
ysr@777 1261 case Sparse:
ysr@777 1262 if (_sparse_iter.has_next(card_index)) {
ysr@777 1263 _n_yielded_sparse++;
ysr@777 1264 return true;
ysr@777 1265 }
ysr@777 1266 // Otherwise, deliberate fall-through
ysr@777 1267 _is = Fine;
ysr@777 1268 case Fine:
ysr@777 1269 if (fine_has_next(card_index)) {
ysr@777 1270 _n_yielded_fine++;
ysr@777 1271 return true;
ysr@777 1272 }
ysr@777 1273 // Otherwise, deliberate fall-through
ysr@777 1274 _is = Coarse;
ysr@777 1275 case Coarse:
ysr@777 1276 if (coarse_has_next(card_index)) {
ysr@777 1277 _n_yielded_coarse++;
ysr@777 1278 return true;
ysr@777 1279 }
ysr@777 1280 // Otherwise...
ysr@777 1281 break;
ysr@777 1282 }
ysr@777 1283 assert(ParallelGCThreads > 1 ||
ysr@777 1284 n_yielded() == _hrrs->occupied(),
ysr@777 1285 "Should have yielded all the cards in the rem set "
ysr@777 1286 "(in the non-par case).");
ysr@777 1287 return false;
ysr@777 1288 }
ysr@777 1289
ysr@777 1290
ysr@777 1291
ysr@1280 1292 OopOrNarrowOopStar* HeapRegionRemSet::_recorded_oops = NULL;
ysr@1280 1293 HeapWord** HeapRegionRemSet::_recorded_cards = NULL;
ysr@1280 1294 HeapRegion** HeapRegionRemSet::_recorded_regions = NULL;
ysr@1280 1295 int HeapRegionRemSet::_n_recorded = 0;
ysr@777 1296
ysr@777 1297 HeapRegionRemSet::Event* HeapRegionRemSet::_recorded_events = NULL;
ysr@777 1298 int* HeapRegionRemSet::_recorded_event_index = NULL;
ysr@777 1299 int HeapRegionRemSet::_n_recorded_events = 0;
ysr@777 1300
ysr@1280 1301 void HeapRegionRemSet::record(HeapRegion* hr, OopOrNarrowOopStar f) {
ysr@777 1302 if (_recorded_oops == NULL) {
ysr@777 1303 assert(_n_recorded == 0
ysr@777 1304 && _recorded_cards == NULL
ysr@777 1305 && _recorded_regions == NULL,
ysr@777 1306 "Inv");
ysr@1280 1307 _recorded_oops = NEW_C_HEAP_ARRAY(OopOrNarrowOopStar, MaxRecorded);
ysr@1280 1308 _recorded_cards = NEW_C_HEAP_ARRAY(HeapWord*, MaxRecorded);
ysr@1280 1309 _recorded_regions = NEW_C_HEAP_ARRAY(HeapRegion*, MaxRecorded);
ysr@777 1310 }
ysr@777 1311 if (_n_recorded == MaxRecorded) {
ysr@777 1312 gclog_or_tty->print_cr("Filled up 'recorded' (%d).", MaxRecorded);
ysr@777 1313 } else {
ysr@777 1314 _recorded_cards[_n_recorded] =
ysr@777 1315 (HeapWord*)align_size_down(uintptr_t(f),
ysr@777 1316 CardTableModRefBS::card_size);
ysr@777 1317 _recorded_oops[_n_recorded] = f;
ysr@777 1318 _recorded_regions[_n_recorded] = hr;
ysr@777 1319 _n_recorded++;
ysr@777 1320 }
ysr@777 1321 }
ysr@777 1322
ysr@777 1323 void HeapRegionRemSet::record_event(Event evnt) {
ysr@777 1324 if (!G1RecordHRRSEvents) return;
ysr@777 1325
ysr@777 1326 if (_recorded_events == NULL) {
ysr@777 1327 assert(_n_recorded_events == 0
ysr@777 1328 && _recorded_event_index == NULL,
ysr@777 1329 "Inv");
ysr@777 1330 _recorded_events = NEW_C_HEAP_ARRAY(Event, MaxRecordedEvents);
ysr@777 1331 _recorded_event_index = NEW_C_HEAP_ARRAY(int, MaxRecordedEvents);
ysr@777 1332 }
ysr@777 1333 if (_n_recorded_events == MaxRecordedEvents) {
ysr@777 1334 gclog_or_tty->print_cr("Filled up 'recorded_events' (%d).", MaxRecordedEvents);
ysr@777 1335 } else {
ysr@777 1336 _recorded_events[_n_recorded_events] = evnt;
ysr@777 1337 _recorded_event_index[_n_recorded_events] = _n_recorded;
ysr@777 1338 _n_recorded_events++;
ysr@777 1339 }
ysr@777 1340 }
ysr@777 1341
ysr@777 1342 void HeapRegionRemSet::print_event(outputStream* str, Event evnt) {
ysr@777 1343 switch (evnt) {
ysr@777 1344 case Event_EvacStart:
ysr@777 1345 str->print("Evac Start");
ysr@777 1346 break;
ysr@777 1347 case Event_EvacEnd:
ysr@777 1348 str->print("Evac End");
ysr@777 1349 break;
ysr@777 1350 case Event_RSUpdateEnd:
ysr@777 1351 str->print("RS Update End");
ysr@777 1352 break;
ysr@777 1353 }
ysr@777 1354 }
ysr@777 1355
ysr@777 1356 void HeapRegionRemSet::print_recorded() {
ysr@777 1357 int cur_evnt = 0;
ysr@777 1358 Event cur_evnt_kind;
ysr@777 1359 int cur_evnt_ind = 0;
ysr@777 1360 if (_n_recorded_events > 0) {
ysr@777 1361 cur_evnt_kind = _recorded_events[cur_evnt];
ysr@777 1362 cur_evnt_ind = _recorded_event_index[cur_evnt];
ysr@777 1363 }
ysr@777 1364
ysr@777 1365 for (int i = 0; i < _n_recorded; i++) {
ysr@777 1366 while (cur_evnt < _n_recorded_events && i == cur_evnt_ind) {
ysr@777 1367 gclog_or_tty->print("Event: ");
ysr@777 1368 print_event(gclog_or_tty, cur_evnt_kind);
ysr@777 1369 gclog_or_tty->print_cr("");
ysr@777 1370 cur_evnt++;
ysr@777 1371 if (cur_evnt < MaxRecordedEvents) {
ysr@777 1372 cur_evnt_kind = _recorded_events[cur_evnt];
ysr@777 1373 cur_evnt_ind = _recorded_event_index[cur_evnt];
ysr@777 1374 }
ysr@777 1375 }
ysr@777 1376 gclog_or_tty->print("Added card " PTR_FORMAT " to region [" PTR_FORMAT "...]"
ysr@777 1377 " for ref " PTR_FORMAT ".\n",
ysr@777 1378 _recorded_cards[i], _recorded_regions[i]->bottom(),
ysr@777 1379 _recorded_oops[i]);
ysr@777 1380 }
ysr@777 1381 }
ysr@777 1382
ysr@777 1383 #ifndef PRODUCT
ysr@777 1384 void HeapRegionRemSet::test() {
ysr@777 1385 os::sleep(Thread::current(), (jlong)5000, false);
ysr@777 1386 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 1387
ysr@777 1388 // Run with "-XX:G1LogRSRegionEntries=2", so that 1 and 5 end up in same
ysr@777 1389 // hash bucket.
ysr@777 1390 HeapRegion* hr0 = g1h->region_at(0);
ysr@777 1391 HeapRegion* hr1 = g1h->region_at(1);
ysr@777 1392 HeapRegion* hr2 = g1h->region_at(5);
ysr@777 1393 HeapRegion* hr3 = g1h->region_at(6);
ysr@777 1394 HeapRegion* hr4 = g1h->region_at(7);
ysr@777 1395 HeapRegion* hr5 = g1h->region_at(8);
ysr@777 1396
ysr@777 1397 HeapWord* hr1_start = hr1->bottom();
ysr@777 1398 HeapWord* hr1_mid = hr1_start + HeapRegion::GrainWords/2;
ysr@777 1399 HeapWord* hr1_last = hr1->end() - 1;
ysr@777 1400
ysr@777 1401 HeapWord* hr2_start = hr2->bottom();
ysr@777 1402 HeapWord* hr2_mid = hr2_start + HeapRegion::GrainWords/2;
ysr@777 1403 HeapWord* hr2_last = hr2->end() - 1;
ysr@777 1404
ysr@777 1405 HeapWord* hr3_start = hr3->bottom();
ysr@777 1406 HeapWord* hr3_mid = hr3_start + HeapRegion::GrainWords/2;
ysr@777 1407 HeapWord* hr3_last = hr3->end() - 1;
ysr@777 1408
ysr@777 1409 HeapRegionRemSet* hrrs = hr0->rem_set();
ysr@777 1410
ysr@777 1411 // Make three references from region 0x101...
ysr@1280 1412 hrrs->add_reference((OopOrNarrowOopStar)hr1_start);
ysr@1280 1413 hrrs->add_reference((OopOrNarrowOopStar)hr1_mid);
ysr@1280 1414 hrrs->add_reference((OopOrNarrowOopStar)hr1_last);
ysr@777 1415
ysr@1280 1416 hrrs->add_reference((OopOrNarrowOopStar)hr2_start);
ysr@1280 1417 hrrs->add_reference((OopOrNarrowOopStar)hr2_mid);
ysr@1280 1418 hrrs->add_reference((OopOrNarrowOopStar)hr2_last);
ysr@777 1419
ysr@1280 1420 hrrs->add_reference((OopOrNarrowOopStar)hr3_start);
ysr@1280 1421 hrrs->add_reference((OopOrNarrowOopStar)hr3_mid);
ysr@1280 1422 hrrs->add_reference((OopOrNarrowOopStar)hr3_last);
ysr@777 1423
ysr@777 1424 // Now cause a coarsening.
ysr@1280 1425 hrrs->add_reference((OopOrNarrowOopStar)hr4->bottom());
ysr@1280 1426 hrrs->add_reference((OopOrNarrowOopStar)hr5->bottom());
ysr@777 1427
ysr@777 1428 // Now, does iteration yield these three?
ysr@777 1429 HeapRegionRemSetIterator iter;
ysr@777 1430 hrrs->init_iterator(&iter);
ysr@777 1431 size_t sum = 0;
ysr@777 1432 size_t card_index;
ysr@777 1433 while (iter.has_next(card_index)) {
ysr@777 1434 HeapWord* card_start =
ysr@777 1435 G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
ysr@777 1436 gclog_or_tty->print_cr(" Card " PTR_FORMAT ".", card_start);
ysr@777 1437 sum++;
ysr@777 1438 }
ysr@777 1439 guarantee(sum == 11 - 3 + 2048, "Failure");
ysr@777 1440 guarantee(sum == hrrs->occupied(), "Failure");
ysr@777 1441 }
ysr@777 1442 #endif

mercurial