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

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7208
7baf47cb97cb
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "gc_implementation/g1/concurrentG1Refine.hpp"
aoqi@0 27 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
aoqi@0 28 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 29 #include "gc_implementation/g1/heapRegionRemSet.hpp"
tschatzl@7091 30 #include "gc_implementation/g1/heapRegionManager.inline.hpp"
aoqi@0 31 #include "memory/allocation.hpp"
aoqi@0 32 #include "memory/padded.inline.hpp"
aoqi@0 33 #include "memory/space.inline.hpp"
aoqi@0 34 #include "oops/oop.inline.hpp"
aoqi@0 35 #include "utilities/bitMap.inline.hpp"
aoqi@0 36 #include "utilities/globalDefinitions.hpp"
aoqi@0 37 #include "utilities/growableArray.hpp"
aoqi@0 38
aoqi@0 39 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 40
aoqi@0 41 class PerRegionTable: public CHeapObj<mtGC> {
aoqi@0 42 friend class OtherRegionsTable;
aoqi@0 43 friend class HeapRegionRemSetIterator;
aoqi@0 44
aoqi@0 45 HeapRegion* _hr;
aoqi@0 46 BitMap _bm;
aoqi@0 47 jint _occupied;
aoqi@0 48
aoqi@0 49 // next pointer for free/allocated 'all' list
aoqi@0 50 PerRegionTable* _next;
aoqi@0 51
aoqi@0 52 // prev pointer for the allocated 'all' list
aoqi@0 53 PerRegionTable* _prev;
aoqi@0 54
aoqi@0 55 // next pointer in collision list
aoqi@0 56 PerRegionTable * _collision_list_next;
aoqi@0 57
aoqi@0 58 // Global free list of PRTs
aoqi@0 59 static PerRegionTable* _free_list;
aoqi@0 60
aoqi@0 61 protected:
aoqi@0 62 // We need access in order to union things into the base table.
aoqi@0 63 BitMap* bm() { return &_bm; }
aoqi@0 64
aoqi@0 65 void recount_occupied() {
aoqi@0 66 _occupied = (jint) bm()->count_one_bits();
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 PerRegionTable(HeapRegion* hr) :
aoqi@0 70 _hr(hr),
aoqi@0 71 _occupied(0),
aoqi@0 72 _bm(HeapRegion::CardsPerRegion, false /* in-resource-area */),
aoqi@0 73 _collision_list_next(NULL), _next(NULL), _prev(NULL)
aoqi@0 74 {}
aoqi@0 75
aoqi@0 76 void add_card_work(CardIdx_t from_card, bool par) {
aoqi@0 77 if (!_bm.at(from_card)) {
aoqi@0 78 if (par) {
aoqi@0 79 if (_bm.par_at_put(from_card, 1)) {
aoqi@0 80 Atomic::inc(&_occupied);
aoqi@0 81 }
aoqi@0 82 } else {
aoqi@0 83 _bm.at_put(from_card, 1);
aoqi@0 84 _occupied++;
aoqi@0 85 }
aoqi@0 86 }
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 void add_reference_work(OopOrNarrowOopStar from, bool par) {
aoqi@0 90 // Must make this robust in case "from" is not in "_hr", because of
aoqi@0 91 // concurrency.
aoqi@0 92
aoqi@0 93 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 94 gclog_or_tty->print_cr(" PRT::Add_reference_work(" PTR_FORMAT "->" PTR_FORMAT").",
aoqi@0 95 from,
aoqi@0 96 UseCompressedOops
aoqi@0 97 ? (void *)oopDesc::load_decode_heap_oop((narrowOop*)from)
aoqi@0 98 : (void *)oopDesc::load_decode_heap_oop((oop*)from));
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 HeapRegion* loc_hr = hr();
aoqi@0 102 // If the test below fails, then this table was reused concurrently
aoqi@0 103 // with this operation. This is OK, since the old table was coarsened,
aoqi@0 104 // and adding a bit to the new table is never incorrect.
aoqi@0 105 // If the table used to belong to a continues humongous region and is
aoqi@0 106 // now reused for the corresponding start humongous region, we need to
aoqi@0 107 // make sure that we detect this. Thus, we call is_in_reserved_raw()
aoqi@0 108 // instead of just is_in_reserved() here.
aoqi@0 109 if (loc_hr->is_in_reserved_raw(from)) {
aoqi@0 110 size_t hw_offset = pointer_delta((HeapWord*)from, loc_hr->bottom());
aoqi@0 111 CardIdx_t from_card = (CardIdx_t)
aoqi@0 112 hw_offset >> (CardTableModRefBS::card_shift - LogHeapWordSize);
aoqi@0 113
aoqi@0 114 assert(0 <= from_card && (size_t)from_card < HeapRegion::CardsPerRegion,
aoqi@0 115 "Must be in range.");
aoqi@0 116 add_card_work(from_card, par);
aoqi@0 117 }
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 public:
aoqi@0 121
aoqi@0 122 HeapRegion* hr() const { return _hr; }
aoqi@0 123
aoqi@0 124 jint occupied() const {
aoqi@0 125 // Overkill, but if we ever need it...
aoqi@0 126 // guarantee(_occupied == _bm.count_one_bits(), "Check");
aoqi@0 127 return _occupied;
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 void init(HeapRegion* hr, bool clear_links_to_all_list) {
aoqi@0 131 if (clear_links_to_all_list) {
aoqi@0 132 set_next(NULL);
aoqi@0 133 set_prev(NULL);
aoqi@0 134 }
aoqi@0 135 _hr = hr;
aoqi@0 136 _collision_list_next = NULL;
aoqi@0 137 _occupied = 0;
aoqi@0 138 _bm.clear();
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 void add_reference(OopOrNarrowOopStar from) {
aoqi@0 142 add_reference_work(from, /*parallel*/ true);
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 void seq_add_reference(OopOrNarrowOopStar from) {
aoqi@0 146 add_reference_work(from, /*parallel*/ false);
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 void scrub(CardTableModRefBS* ctbs, BitMap* card_bm) {
aoqi@0 150 HeapWord* hr_bot = hr()->bottom();
aoqi@0 151 size_t hr_first_card_index = ctbs->index_for(hr_bot);
aoqi@0 152 bm()->set_intersection_at_offset(*card_bm, hr_first_card_index);
aoqi@0 153 recount_occupied();
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 void add_card(CardIdx_t from_card_index) {
aoqi@0 157 add_card_work(from_card_index, /*parallel*/ true);
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 void seq_add_card(CardIdx_t from_card_index) {
aoqi@0 161 add_card_work(from_card_index, /*parallel*/ false);
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 // (Destructively) union the bitmap of the current table into the given
aoqi@0 165 // bitmap (which is assumed to be of the same size.)
aoqi@0 166 void union_bitmap_into(BitMap* bm) {
aoqi@0 167 bm->set_union(_bm);
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 // Mem size in bytes.
aoqi@0 171 size_t mem_size() const {
tschatzl@6932 172 return sizeof(PerRegionTable) + _bm.size_in_words() * HeapWordSize;
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 // Requires "from" to be in "hr()".
aoqi@0 176 bool contains_reference(OopOrNarrowOopStar from) const {
aoqi@0 177 assert(hr()->is_in_reserved(from), "Precondition.");
aoqi@0 178 size_t card_ind = pointer_delta(from, hr()->bottom(),
aoqi@0 179 CardTableModRefBS::card_size);
aoqi@0 180 return _bm.at(card_ind);
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 // Bulk-free the PRTs from prt to last, assumes that they are
aoqi@0 184 // linked together using their _next field.
aoqi@0 185 static void bulk_free(PerRegionTable* prt, PerRegionTable* last) {
aoqi@0 186 while (true) {
aoqi@0 187 PerRegionTable* fl = _free_list;
aoqi@0 188 last->set_next(fl);
aoqi@0 189 PerRegionTable* res = (PerRegionTable*) Atomic::cmpxchg_ptr(prt, &_free_list, fl);
aoqi@0 190 if (res == fl) {
aoqi@0 191 return;
aoqi@0 192 }
aoqi@0 193 }
aoqi@0 194 ShouldNotReachHere();
aoqi@0 195 }
aoqi@0 196
aoqi@0 197 static void free(PerRegionTable* prt) {
aoqi@0 198 bulk_free(prt, prt);
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 // Returns an initialized PerRegionTable instance.
aoqi@0 202 static PerRegionTable* alloc(HeapRegion* hr) {
aoqi@0 203 PerRegionTable* fl = _free_list;
aoqi@0 204 while (fl != NULL) {
aoqi@0 205 PerRegionTable* nxt = fl->next();
aoqi@0 206 PerRegionTable* res =
aoqi@0 207 (PerRegionTable*)
aoqi@0 208 Atomic::cmpxchg_ptr(nxt, &_free_list, fl);
aoqi@0 209 if (res == fl) {
aoqi@0 210 fl->init(hr, true);
aoqi@0 211 return fl;
aoqi@0 212 } else {
aoqi@0 213 fl = _free_list;
aoqi@0 214 }
aoqi@0 215 }
aoqi@0 216 assert(fl == NULL, "Loop condition.");
aoqi@0 217 return new PerRegionTable(hr);
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 PerRegionTable* next() const { return _next; }
aoqi@0 221 void set_next(PerRegionTable* next) { _next = next; }
aoqi@0 222 PerRegionTable* prev() const { return _prev; }
aoqi@0 223 void set_prev(PerRegionTable* prev) { _prev = prev; }
aoqi@0 224
aoqi@0 225 // Accessor and Modification routines for the pointer for the
aoqi@0 226 // singly linked collision list that links the PRTs within the
aoqi@0 227 // OtherRegionsTable::_fine_grain_regions hash table.
aoqi@0 228 //
aoqi@0 229 // It might be useful to also make the collision list doubly linked
aoqi@0 230 // to avoid iteration over the collisions list during scrubbing/deletion.
aoqi@0 231 // OTOH there might not be many collisions.
aoqi@0 232
aoqi@0 233 PerRegionTable* collision_list_next() const {
aoqi@0 234 return _collision_list_next;
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 void set_collision_list_next(PerRegionTable* next) {
aoqi@0 238 _collision_list_next = next;
aoqi@0 239 }
aoqi@0 240
aoqi@0 241 PerRegionTable** collision_list_next_addr() {
aoqi@0 242 return &_collision_list_next;
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 static size_t fl_mem_size() {
aoqi@0 246 PerRegionTable* cur = _free_list;
aoqi@0 247 size_t res = 0;
aoqi@0 248 while (cur != NULL) {
aoqi@0 249 res += cur->mem_size();
aoqi@0 250 cur = cur->next();
aoqi@0 251 }
aoqi@0 252 return res;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 static void test_fl_mem_size();
aoqi@0 256 };
aoqi@0 257
aoqi@0 258 PerRegionTable* PerRegionTable::_free_list = NULL;
aoqi@0 259
aoqi@0 260 size_t OtherRegionsTable::_max_fine_entries = 0;
aoqi@0 261 size_t OtherRegionsTable::_mod_max_fine_entries_mask = 0;
aoqi@0 262 size_t OtherRegionsTable::_fine_eviction_stride = 0;
aoqi@0 263 size_t OtherRegionsTable::_fine_eviction_sample_size = 0;
aoqi@0 264
aoqi@0 265 OtherRegionsTable::OtherRegionsTable(HeapRegion* hr, Mutex* m) :
aoqi@0 266 _g1h(G1CollectedHeap::heap()),
aoqi@0 267 _hr(hr), _m(m),
aoqi@0 268 _coarse_map(G1CollectedHeap::heap()->max_regions(),
aoqi@0 269 false /* in-resource-area */),
aoqi@0 270 _fine_grain_regions(NULL),
aoqi@0 271 _first_all_fine_prts(NULL), _last_all_fine_prts(NULL),
aoqi@0 272 _n_fine_entries(0), _n_coarse_entries(0),
aoqi@0 273 _fine_eviction_start(0),
aoqi@0 274 _sparse_table(hr)
aoqi@0 275 {
aoqi@0 276 typedef PerRegionTable* PerRegionTablePtr;
aoqi@0 277
aoqi@0 278 if (_max_fine_entries == 0) {
aoqi@0 279 assert(_mod_max_fine_entries_mask == 0, "Both or none.");
aoqi@0 280 size_t max_entries_log = (size_t)log2_long((jlong)G1RSetRegionEntries);
aoqi@0 281 _max_fine_entries = (size_t)1 << max_entries_log;
aoqi@0 282 _mod_max_fine_entries_mask = _max_fine_entries - 1;
aoqi@0 283
aoqi@0 284 assert(_fine_eviction_sample_size == 0
aoqi@0 285 && _fine_eviction_stride == 0, "All init at same time.");
aoqi@0 286 _fine_eviction_sample_size = MAX2((size_t)4, max_entries_log);
aoqi@0 287 _fine_eviction_stride = _max_fine_entries / _fine_eviction_sample_size;
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 _fine_grain_regions = NEW_C_HEAP_ARRAY3(PerRegionTablePtr, _max_fine_entries,
zgu@7074 291 mtGC, CURRENT_PC, AllocFailStrategy::RETURN_NULL);
aoqi@0 292
aoqi@0 293 if (_fine_grain_regions == NULL) {
aoqi@0 294 vm_exit_out_of_memory(sizeof(void*)*_max_fine_entries, OOM_MALLOC_ERROR,
aoqi@0 295 "Failed to allocate _fine_grain_entries.");
aoqi@0 296 }
aoqi@0 297
aoqi@0 298 for (size_t i = 0; i < _max_fine_entries; i++) {
aoqi@0 299 _fine_grain_regions[i] = NULL;
aoqi@0 300 }
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 void OtherRegionsTable::link_to_all(PerRegionTable* prt) {
aoqi@0 304 // We always append to the beginning of the list for convenience;
aoqi@0 305 // the order of entries in this list does not matter.
aoqi@0 306 if (_first_all_fine_prts != NULL) {
aoqi@0 307 assert(_first_all_fine_prts->prev() == NULL, "invariant");
aoqi@0 308 _first_all_fine_prts->set_prev(prt);
aoqi@0 309 prt->set_next(_first_all_fine_prts);
aoqi@0 310 } else {
aoqi@0 311 // this is the first element we insert. Adjust the "last" pointer
aoqi@0 312 _last_all_fine_prts = prt;
aoqi@0 313 assert(prt->next() == NULL, "just checking");
aoqi@0 314 }
aoqi@0 315 // the new element is always the first element without a predecessor
aoqi@0 316 prt->set_prev(NULL);
aoqi@0 317 _first_all_fine_prts = prt;
aoqi@0 318
aoqi@0 319 assert(prt->prev() == NULL, "just checking");
aoqi@0 320 assert(_first_all_fine_prts == prt, "just checking");
aoqi@0 321 assert((_first_all_fine_prts == NULL && _last_all_fine_prts == NULL) ||
aoqi@0 322 (_first_all_fine_prts != NULL && _last_all_fine_prts != NULL),
aoqi@0 323 "just checking");
aoqi@0 324 assert(_last_all_fine_prts == NULL || _last_all_fine_prts->next() == NULL,
aoqi@0 325 "just checking");
aoqi@0 326 assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL,
aoqi@0 327 "just checking");
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 void OtherRegionsTable::unlink_from_all(PerRegionTable* prt) {
aoqi@0 331 if (prt->prev() != NULL) {
aoqi@0 332 assert(_first_all_fine_prts != prt, "just checking");
aoqi@0 333 prt->prev()->set_next(prt->next());
aoqi@0 334 // removing the last element in the list?
aoqi@0 335 if (_last_all_fine_prts == prt) {
aoqi@0 336 _last_all_fine_prts = prt->prev();
aoqi@0 337 }
aoqi@0 338 } else {
aoqi@0 339 assert(_first_all_fine_prts == prt, "just checking");
aoqi@0 340 _first_all_fine_prts = prt->next();
aoqi@0 341 // list is empty now?
aoqi@0 342 if (_first_all_fine_prts == NULL) {
aoqi@0 343 _last_all_fine_prts = NULL;
aoqi@0 344 }
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 if (prt->next() != NULL) {
aoqi@0 348 prt->next()->set_prev(prt->prev());
aoqi@0 349 }
aoqi@0 350
aoqi@0 351 prt->set_next(NULL);
aoqi@0 352 prt->set_prev(NULL);
aoqi@0 353
aoqi@0 354 assert((_first_all_fine_prts == NULL && _last_all_fine_prts == NULL) ||
aoqi@0 355 (_first_all_fine_prts != NULL && _last_all_fine_prts != NULL),
aoqi@0 356 "just checking");
aoqi@0 357 assert(_last_all_fine_prts == NULL || _last_all_fine_prts->next() == NULL,
aoqi@0 358 "just checking");
aoqi@0 359 assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL,
aoqi@0 360 "just checking");
aoqi@0 361 }
aoqi@0 362
aoqi@0 363 int** FromCardCache::_cache = NULL;
aoqi@0 364 uint FromCardCache::_max_regions = 0;
aoqi@0 365 size_t FromCardCache::_static_mem_size = 0;
aoqi@0 366
aoqi@0 367 void FromCardCache::initialize(uint n_par_rs, uint max_num_regions) {
aoqi@0 368 guarantee(_cache == NULL, "Should not call this multiple times");
aoqi@0 369
aoqi@0 370 _max_regions = max_num_regions;
aoqi@0 371 _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs,
aoqi@0 372 _max_regions,
aoqi@0 373 &_static_mem_size);
aoqi@0 374
tschatzl@7051 375 invalidate(0, _max_regions);
aoqi@0 376 }
aoqi@0 377
tschatzl@7051 378 void FromCardCache::invalidate(uint start_idx, size_t new_num_regions) {
tschatzl@7051 379 guarantee((size_t)start_idx + new_num_regions <= max_uintx,
tschatzl@7051 380 err_msg("Trying to invalidate beyond maximum region, from %u size "SIZE_FORMAT,
tschatzl@7051 381 start_idx, new_num_regions));
aoqi@0 382 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
tschatzl@7051 383 uint end_idx = (start_idx + (uint)new_num_regions);
tschatzl@7051 384 assert(end_idx <= _max_regions, "Must be within max.");
tschatzl@7051 385 for (uint j = start_idx; j < end_idx; j++) {
aoqi@0 386 set(i, j, InvalidCard);
aoqi@0 387 }
aoqi@0 388 }
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 #ifndef PRODUCT
aoqi@0 392 void FromCardCache::print(outputStream* out) {
aoqi@0 393 for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
aoqi@0 394 for (uint j = 0; j < _max_regions; j++) {
aoqi@0 395 out->print_cr("_from_card_cache["UINT32_FORMAT"]["UINT32_FORMAT"] = "INT32_FORMAT".",
aoqi@0 396 i, j, at(i, j));
aoqi@0 397 }
aoqi@0 398 }
aoqi@0 399 }
aoqi@0 400 #endif
aoqi@0 401
aoqi@0 402 void FromCardCache::clear(uint region_idx) {
aoqi@0 403 uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets();
aoqi@0 404 for (uint i = 0; i < num_par_remsets; i++) {
aoqi@0 405 set(i, region_idx, InvalidCard);
aoqi@0 406 }
aoqi@0 407 }
aoqi@0 408
tschatzl@7051 409 void OtherRegionsTable::initialize(uint max_regions) {
aoqi@0 410 FromCardCache::initialize(HeapRegionRemSet::num_par_rem_sets(), max_regions);
aoqi@0 411 }
aoqi@0 412
tschatzl@7051 413 void OtherRegionsTable::invalidate(uint start_idx, size_t num_regions) {
tschatzl@7051 414 FromCardCache::invalidate(start_idx, num_regions);
aoqi@0 415 }
aoqi@0 416
aoqi@0 417 void OtherRegionsTable::print_from_card_cache() {
aoqi@0 418 FromCardCache::print();
aoqi@0 419 }
aoqi@0 420
aoqi@0 421 void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, int tid) {
tschatzl@7091 422 uint cur_hrm_ind = hr()->hrm_index();
aoqi@0 423
aoqi@0 424 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 425 gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").",
aoqi@0 426 from,
aoqi@0 427 UseCompressedOops
aoqi@0 428 ? (void *)oopDesc::load_decode_heap_oop((narrowOop*)from)
aoqi@0 429 : (void *)oopDesc::load_decode_heap_oop((oop*)from));
aoqi@0 430 }
aoqi@0 431
aoqi@0 432 int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift);
aoqi@0 433
aoqi@0 434 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 435 gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = "INT32_FORMAT")",
aoqi@0 436 hr()->bottom(), from_card,
tschatzl@7091 437 FromCardCache::at((uint)tid, cur_hrm_ind));
aoqi@0 438 }
aoqi@0 439
tschatzl@7091 440 if (FromCardCache::contains_or_replace((uint)tid, cur_hrm_ind, from_card)) {
aoqi@0 441 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 442 gclog_or_tty->print_cr(" from-card cache hit.");
aoqi@0 443 }
aoqi@0 444 assert(contains_reference(from), "We just added it!");
aoqi@0 445 return;
aoqi@0 446 }
aoqi@0 447
aoqi@0 448 // Note that this may be a continued H region.
aoqi@0 449 HeapRegion* from_hr = _g1h->heap_region_containing_raw(from);
tschatzl@7106 450 RegionIdx_t from_hrm_ind = (RegionIdx_t) from_hr->hrm_index();
aoqi@0 451
aoqi@0 452 // If the region is already coarsened, return.
tschatzl@7106 453 if (_coarse_map.at(from_hrm_ind)) {
aoqi@0 454 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 455 gclog_or_tty->print_cr(" coarse map hit.");
aoqi@0 456 }
aoqi@0 457 assert(contains_reference(from), "We just added it!");
aoqi@0 458 return;
aoqi@0 459 }
aoqi@0 460
aoqi@0 461 // Otherwise find a per-region table to add it to.
tschatzl@7106 462 size_t ind = from_hrm_ind & _mod_max_fine_entries_mask;
aoqi@0 463 PerRegionTable* prt = find_region_table(ind, from_hr);
aoqi@0 464 if (prt == NULL) {
aoqi@0 465 MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag);
aoqi@0 466 // Confirm that it's really not there...
aoqi@0 467 prt = find_region_table(ind, from_hr);
aoqi@0 468 if (prt == NULL) {
aoqi@0 469
aoqi@0 470 uintptr_t from_hr_bot_card_index =
aoqi@0 471 uintptr_t(from_hr->bottom())
aoqi@0 472 >> CardTableModRefBS::card_shift;
aoqi@0 473 CardIdx_t card_index = from_card - from_hr_bot_card_index;
aoqi@0 474 assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
aoqi@0 475 "Must be in range.");
aoqi@0 476 if (G1HRRSUseSparseTable &&
tschatzl@7106 477 _sparse_table.add_card(from_hrm_ind, card_index)) {
aoqi@0 478 if (G1RecordHRRSOops) {
aoqi@0 479 HeapRegionRemSet::record(hr(), from);
aoqi@0 480 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 481 gclog_or_tty->print(" Added card " PTR_FORMAT " to region "
aoqi@0 482 "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
aoqi@0 483 align_size_down(uintptr_t(from),
aoqi@0 484 CardTableModRefBS::card_size),
aoqi@0 485 hr()->bottom(), from);
aoqi@0 486 }
aoqi@0 487 }
aoqi@0 488 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 489 gclog_or_tty->print_cr(" added card to sparse table.");
aoqi@0 490 }
aoqi@0 491 assert(contains_reference_locked(from), "We just added it!");
aoqi@0 492 return;
aoqi@0 493 } else {
aoqi@0 494 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 495 gclog_or_tty->print_cr(" [tid %d] sparse table entry "
tschatzl@7091 496 "overflow(f: %d, t: %u)",
tschatzl@7106 497 tid, from_hrm_ind, cur_hrm_ind);
aoqi@0 498 }
aoqi@0 499 }
aoqi@0 500
aoqi@0 501 if (_n_fine_entries == _max_fine_entries) {
aoqi@0 502 prt = delete_region_table();
aoqi@0 503 // There is no need to clear the links to the 'all' list here:
aoqi@0 504 // prt will be reused immediately, i.e. remain in the 'all' list.
aoqi@0 505 prt->init(from_hr, false /* clear_links_to_all_list */);
aoqi@0 506 } else {
aoqi@0 507 prt = PerRegionTable::alloc(from_hr);
aoqi@0 508 link_to_all(prt);
aoqi@0 509 }
aoqi@0 510
aoqi@0 511 PerRegionTable* first_prt = _fine_grain_regions[ind];
aoqi@0 512 prt->set_collision_list_next(first_prt);
aoqi@0 513 _fine_grain_regions[ind] = prt;
aoqi@0 514 _n_fine_entries++;
aoqi@0 515
aoqi@0 516 if (G1HRRSUseSparseTable) {
aoqi@0 517 // Transfer from sparse to fine-grain.
tschatzl@7106 518 SparsePRTEntry *sprt_entry = _sparse_table.get_entry(from_hrm_ind);
aoqi@0 519 assert(sprt_entry != NULL, "There should have been an entry");
aoqi@0 520 for (int i = 0; i < SparsePRTEntry::cards_num(); i++) {
aoqi@0 521 CardIdx_t c = sprt_entry->card(i);
aoqi@0 522 if (c != SparsePRTEntry::NullEntry) {
aoqi@0 523 prt->add_card(c);
aoqi@0 524 }
aoqi@0 525 }
aoqi@0 526 // Now we can delete the sparse entry.
tschatzl@7106 527 bool res = _sparse_table.delete_entry(from_hrm_ind);
aoqi@0 528 assert(res, "It should have been there.");
aoqi@0 529 }
aoqi@0 530 }
aoqi@0 531 assert(prt != NULL && prt->hr() == from_hr, "consequence");
aoqi@0 532 }
aoqi@0 533 // Note that we can't assert "prt->hr() == from_hr", because of the
aoqi@0 534 // possibility of concurrent reuse. But see head comment of
aoqi@0 535 // OtherRegionsTable for why this is OK.
aoqi@0 536 assert(prt != NULL, "Inv");
aoqi@0 537
aoqi@0 538 prt->add_reference(from);
aoqi@0 539
aoqi@0 540 if (G1RecordHRRSOops) {
aoqi@0 541 HeapRegionRemSet::record(hr(), from);
aoqi@0 542 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 543 gclog_or_tty->print("Added card " PTR_FORMAT " to region "
aoqi@0 544 "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
aoqi@0 545 align_size_down(uintptr_t(from),
aoqi@0 546 CardTableModRefBS::card_size),
aoqi@0 547 hr()->bottom(), from);
aoqi@0 548 }
aoqi@0 549 }
aoqi@0 550 assert(contains_reference(from), "We just added it!");
aoqi@0 551 }
aoqi@0 552
aoqi@0 553 PerRegionTable*
aoqi@0 554 OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const {
aoqi@0 555 assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
aoqi@0 556 PerRegionTable* prt = _fine_grain_regions[ind];
aoqi@0 557 while (prt != NULL && prt->hr() != hr) {
aoqi@0 558 prt = prt->collision_list_next();
aoqi@0 559 }
aoqi@0 560 // Loop postcondition is the method postcondition.
aoqi@0 561 return prt;
aoqi@0 562 }
aoqi@0 563
aoqi@0 564 jint OtherRegionsTable::_n_coarsenings = 0;
aoqi@0 565
aoqi@0 566 PerRegionTable* OtherRegionsTable::delete_region_table() {
aoqi@0 567 assert(_m->owned_by_self(), "Precondition");
aoqi@0 568 assert(_n_fine_entries == _max_fine_entries, "Precondition");
aoqi@0 569 PerRegionTable* max = NULL;
aoqi@0 570 jint max_occ = 0;
aoqi@0 571 PerRegionTable** max_prev;
aoqi@0 572 size_t max_ind;
aoqi@0 573
aoqi@0 574 size_t i = _fine_eviction_start;
aoqi@0 575 for (size_t k = 0; k < _fine_eviction_sample_size; k++) {
aoqi@0 576 size_t ii = i;
aoqi@0 577 // Make sure we get a non-NULL sample.
aoqi@0 578 while (_fine_grain_regions[ii] == NULL) {
aoqi@0 579 ii++;
aoqi@0 580 if (ii == _max_fine_entries) ii = 0;
aoqi@0 581 guarantee(ii != i, "We must find one.");
aoqi@0 582 }
aoqi@0 583 PerRegionTable** prev = &_fine_grain_regions[ii];
aoqi@0 584 PerRegionTable* cur = *prev;
aoqi@0 585 while (cur != NULL) {
aoqi@0 586 jint cur_occ = cur->occupied();
aoqi@0 587 if (max == NULL || cur_occ > max_occ) {
aoqi@0 588 max = cur;
aoqi@0 589 max_prev = prev;
aoqi@0 590 max_ind = i;
aoqi@0 591 max_occ = cur_occ;
aoqi@0 592 }
aoqi@0 593 prev = cur->collision_list_next_addr();
aoqi@0 594 cur = cur->collision_list_next();
aoqi@0 595 }
aoqi@0 596 i = i + _fine_eviction_stride;
aoqi@0 597 if (i >= _n_fine_entries) i = i - _n_fine_entries;
aoqi@0 598 }
aoqi@0 599
aoqi@0 600 _fine_eviction_start++;
aoqi@0 601
aoqi@0 602 if (_fine_eviction_start >= _n_fine_entries) {
aoqi@0 603 _fine_eviction_start -= _n_fine_entries;
aoqi@0 604 }
aoqi@0 605
aoqi@0 606 guarantee(max != NULL, "Since _n_fine_entries > 0");
aoqi@0 607
aoqi@0 608 // Set the corresponding coarse bit.
tschatzl@7091 609 size_t max_hrm_index = (size_t) max->hr()->hrm_index();
tschatzl@7091 610 if (!_coarse_map.at(max_hrm_index)) {
tschatzl@7091 611 _coarse_map.at_put(max_hrm_index, true);
aoqi@0 612 _n_coarse_entries++;
aoqi@0 613 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 614 gclog_or_tty->print("Coarsened entry in region [" PTR_FORMAT "...] "
aoqi@0 615 "for region [" PTR_FORMAT "...] (%d coarse entries).\n",
aoqi@0 616 hr()->bottom(),
aoqi@0 617 max->hr()->bottom(),
aoqi@0 618 _n_coarse_entries);
aoqi@0 619 }
aoqi@0 620 }
aoqi@0 621
aoqi@0 622 // Unsplice.
aoqi@0 623 *max_prev = max->collision_list_next();
aoqi@0 624 Atomic::inc(&_n_coarsenings);
aoqi@0 625 _n_fine_entries--;
aoqi@0 626 return max;
aoqi@0 627 }
aoqi@0 628
aoqi@0 629
aoqi@0 630 // At present, this must be called stop-world single-threaded.
aoqi@0 631 void OtherRegionsTable::scrub(CardTableModRefBS* ctbs,
aoqi@0 632 BitMap* region_bm, BitMap* card_bm) {
aoqi@0 633 // First eliminated garbage regions from the coarse map.
aoqi@0 634 if (G1RSScrubVerbose) {
tschatzl@7091 635 gclog_or_tty->print_cr("Scrubbing region %u:", hr()->hrm_index());
aoqi@0 636 }
aoqi@0 637
aoqi@0 638 assert(_coarse_map.size() == region_bm->size(), "Precondition");
aoqi@0 639 if (G1RSScrubVerbose) {
aoqi@0 640 gclog_or_tty->print(" Coarse map: before = "SIZE_FORMAT"...",
aoqi@0 641 _n_coarse_entries);
aoqi@0 642 }
aoqi@0 643 _coarse_map.set_intersection(*region_bm);
aoqi@0 644 _n_coarse_entries = _coarse_map.count_one_bits();
aoqi@0 645 if (G1RSScrubVerbose) {
aoqi@0 646 gclog_or_tty->print_cr(" after = "SIZE_FORMAT".", _n_coarse_entries);
aoqi@0 647 }
aoqi@0 648
aoqi@0 649 // Now do the fine-grained maps.
aoqi@0 650 for (size_t i = 0; i < _max_fine_entries; i++) {
aoqi@0 651 PerRegionTable* cur = _fine_grain_regions[i];
aoqi@0 652 PerRegionTable** prev = &_fine_grain_regions[i];
aoqi@0 653 while (cur != NULL) {
aoqi@0 654 PerRegionTable* nxt = cur->collision_list_next();
aoqi@0 655 // If the entire region is dead, eliminate.
aoqi@0 656 if (G1RSScrubVerbose) {
aoqi@0 657 gclog_or_tty->print_cr(" For other region %u:",
tschatzl@7091 658 cur->hr()->hrm_index());
aoqi@0 659 }
tschatzl@7091 660 if (!region_bm->at((size_t) cur->hr()->hrm_index())) {
aoqi@0 661 *prev = nxt;
aoqi@0 662 cur->set_collision_list_next(NULL);
aoqi@0 663 _n_fine_entries--;
aoqi@0 664 if (G1RSScrubVerbose) {
aoqi@0 665 gclog_or_tty->print_cr(" deleted via region map.");
aoqi@0 666 }
aoqi@0 667 unlink_from_all(cur);
aoqi@0 668 PerRegionTable::free(cur);
aoqi@0 669 } else {
aoqi@0 670 // Do fine-grain elimination.
aoqi@0 671 if (G1RSScrubVerbose) {
aoqi@0 672 gclog_or_tty->print(" occ: before = %4d.", cur->occupied());
aoqi@0 673 }
aoqi@0 674 cur->scrub(ctbs, card_bm);
aoqi@0 675 if (G1RSScrubVerbose) {
aoqi@0 676 gclog_or_tty->print_cr(" after = %4d.", cur->occupied());
aoqi@0 677 }
aoqi@0 678 // Did that empty the table completely?
aoqi@0 679 if (cur->occupied() == 0) {
aoqi@0 680 *prev = nxt;
aoqi@0 681 cur->set_collision_list_next(NULL);
aoqi@0 682 _n_fine_entries--;
aoqi@0 683 unlink_from_all(cur);
aoqi@0 684 PerRegionTable::free(cur);
aoqi@0 685 } else {
aoqi@0 686 prev = cur->collision_list_next_addr();
aoqi@0 687 }
aoqi@0 688 }
aoqi@0 689 cur = nxt;
aoqi@0 690 }
aoqi@0 691 }
aoqi@0 692 // Since we may have deleted a from_card_cache entry from the RS, clear
aoqi@0 693 // the FCC.
aoqi@0 694 clear_fcc();
aoqi@0 695 }
aoqi@0 696
tschatzl@7010 697 bool OtherRegionsTable::is_empty() const {
tschatzl@7010 698 return occ_sparse() == 0 && occ_coarse() == 0 && _first_all_fine_prts == NULL;
tschatzl@7010 699 }
aoqi@0 700
aoqi@0 701 size_t OtherRegionsTable::occupied() const {
aoqi@0 702 size_t sum = occ_fine();
aoqi@0 703 sum += occ_sparse();
aoqi@0 704 sum += occ_coarse();
aoqi@0 705 return sum;
aoqi@0 706 }
aoqi@0 707
aoqi@0 708 size_t OtherRegionsTable::occ_fine() const {
aoqi@0 709 size_t sum = 0;
aoqi@0 710
aoqi@0 711 size_t num = 0;
aoqi@0 712 PerRegionTable * cur = _first_all_fine_prts;
aoqi@0 713 while (cur != NULL) {
aoqi@0 714 sum += cur->occupied();
aoqi@0 715 cur = cur->next();
aoqi@0 716 num++;
aoqi@0 717 }
aoqi@0 718 guarantee(num == _n_fine_entries, "just checking");
aoqi@0 719 return sum;
aoqi@0 720 }
aoqi@0 721
aoqi@0 722 size_t OtherRegionsTable::occ_coarse() const {
aoqi@0 723 return (_n_coarse_entries * HeapRegion::CardsPerRegion);
aoqi@0 724 }
aoqi@0 725
aoqi@0 726 size_t OtherRegionsTable::occ_sparse() const {
aoqi@0 727 return _sparse_table.occupied();
aoqi@0 728 }
aoqi@0 729
aoqi@0 730 size_t OtherRegionsTable::mem_size() const {
aoqi@0 731 size_t sum = 0;
aoqi@0 732 // all PRTs are of the same size so it is sufficient to query only one of them.
aoqi@0 733 if (_first_all_fine_prts != NULL) {
aoqi@0 734 assert(_last_all_fine_prts != NULL &&
aoqi@0 735 _first_all_fine_prts->mem_size() == _last_all_fine_prts->mem_size(), "check that mem_size() is constant");
aoqi@0 736 sum += _first_all_fine_prts->mem_size() * _n_fine_entries;
aoqi@0 737 }
aoqi@0 738 sum += (sizeof(PerRegionTable*) * _max_fine_entries);
aoqi@0 739 sum += (_coarse_map.size_in_words() * HeapWordSize);
aoqi@0 740 sum += (_sparse_table.mem_size());
tschatzl@6932 741 sum += sizeof(OtherRegionsTable) - sizeof(_sparse_table); // Avoid double counting above.
aoqi@0 742 return sum;
aoqi@0 743 }
aoqi@0 744
aoqi@0 745 size_t OtherRegionsTable::static_mem_size() {
aoqi@0 746 return FromCardCache::static_mem_size();
aoqi@0 747 }
aoqi@0 748
aoqi@0 749 size_t OtherRegionsTable::fl_mem_size() {
aoqi@0 750 return PerRegionTable::fl_mem_size();
aoqi@0 751 }
aoqi@0 752
aoqi@0 753 void OtherRegionsTable::clear_fcc() {
tschatzl@7091 754 FromCardCache::clear(hr()->hrm_index());
aoqi@0 755 }
aoqi@0 756
aoqi@0 757 void OtherRegionsTable::clear() {
aoqi@0 758 // if there are no entries, skip this step
aoqi@0 759 if (_first_all_fine_prts != NULL) {
aoqi@0 760 guarantee(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL, "just checking");
aoqi@0 761 PerRegionTable::bulk_free(_first_all_fine_prts, _last_all_fine_prts);
aoqi@0 762 memset(_fine_grain_regions, 0, _max_fine_entries * sizeof(_fine_grain_regions[0]));
aoqi@0 763 } else {
aoqi@0 764 guarantee(_first_all_fine_prts == NULL && _last_all_fine_prts == NULL, "just checking");
aoqi@0 765 }
aoqi@0 766
aoqi@0 767 _first_all_fine_prts = _last_all_fine_prts = NULL;
aoqi@0 768 _sparse_table.clear();
aoqi@0 769 _coarse_map.clear();
aoqi@0 770 _n_fine_entries = 0;
aoqi@0 771 _n_coarse_entries = 0;
aoqi@0 772
aoqi@0 773 clear_fcc();
aoqi@0 774 }
aoqi@0 775
aoqi@0 776 bool OtherRegionsTable::del_single_region_table(size_t ind,
aoqi@0 777 HeapRegion* hr) {
aoqi@0 778 assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
aoqi@0 779 PerRegionTable** prev_addr = &_fine_grain_regions[ind];
aoqi@0 780 PerRegionTable* prt = *prev_addr;
aoqi@0 781 while (prt != NULL && prt->hr() != hr) {
aoqi@0 782 prev_addr = prt->collision_list_next_addr();
aoqi@0 783 prt = prt->collision_list_next();
aoqi@0 784 }
aoqi@0 785 if (prt != NULL) {
aoqi@0 786 assert(prt->hr() == hr, "Loop postcondition.");
aoqi@0 787 *prev_addr = prt->collision_list_next();
aoqi@0 788 unlink_from_all(prt);
aoqi@0 789 PerRegionTable::free(prt);
aoqi@0 790 _n_fine_entries--;
aoqi@0 791 return true;
aoqi@0 792 } else {
aoqi@0 793 return false;
aoqi@0 794 }
aoqi@0 795 }
aoqi@0 796
aoqi@0 797 bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
aoqi@0 798 // Cast away const in this case.
aoqi@0 799 MutexLockerEx x((Mutex*)_m, Mutex::_no_safepoint_check_flag);
aoqi@0 800 return contains_reference_locked(from);
aoqi@0 801 }
aoqi@0 802
aoqi@0 803 bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
aoqi@0 804 HeapRegion* hr = _g1h->heap_region_containing_raw(from);
tschatzl@7091 805 RegionIdx_t hr_ind = (RegionIdx_t) hr->hrm_index();
aoqi@0 806 // Is this region in the coarse map?
aoqi@0 807 if (_coarse_map.at(hr_ind)) return true;
aoqi@0 808
aoqi@0 809 PerRegionTable* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
aoqi@0 810 hr);
aoqi@0 811 if (prt != NULL) {
aoqi@0 812 return prt->contains_reference(from);
aoqi@0 813
aoqi@0 814 } else {
aoqi@0 815 uintptr_t from_card =
aoqi@0 816 (uintptr_t(from) >> CardTableModRefBS::card_shift);
aoqi@0 817 uintptr_t hr_bot_card_index =
aoqi@0 818 uintptr_t(hr->bottom()) >> CardTableModRefBS::card_shift;
aoqi@0 819 assert(from_card >= hr_bot_card_index, "Inv");
aoqi@0 820 CardIdx_t card_index = from_card - hr_bot_card_index;
aoqi@0 821 assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
aoqi@0 822 "Must be in range.");
aoqi@0 823 return _sparse_table.contains_card(hr_ind, card_index);
aoqi@0 824 }
aoqi@0 825 }
aoqi@0 826
aoqi@0 827 void
aoqi@0 828 OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
aoqi@0 829 _sparse_table.do_cleanup_work(hrrs_cleanup_task);
aoqi@0 830 }
aoqi@0 831
aoqi@0 832 // Determines how many threads can add records to an rset in parallel.
aoqi@0 833 // This can be done by either mutator threads together with the
aoqi@0 834 // concurrent refinement threads or GC threads.
aoqi@0 835 uint HeapRegionRemSet::num_par_rem_sets() {
aoqi@0 836 return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), (uint)ParallelGCThreads);
aoqi@0 837 }
aoqi@0 838
aoqi@0 839 HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
aoqi@0 840 HeapRegion* hr)
aoqi@0 841 : _bosa(bosa),
tschatzl@7091 842 _m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true),
tschatzl@7051 843 _code_roots(), _other_regions(hr, &_m), _iter_state(Unclaimed), _iter_claimed(0) {
aoqi@0 844 reset_for_par_iteration();
aoqi@0 845 }
aoqi@0 846
aoqi@0 847 void HeapRegionRemSet::setup_remset_size() {
aoqi@0 848 // Setup sparse and fine-grain tables sizes.
aoqi@0 849 // table_size = base * (log(region_size / 1M) + 1)
aoqi@0 850 const int LOG_M = 20;
aoqi@0 851 int region_size_log_mb = MAX2(HeapRegion::LogOfHRGrainBytes - LOG_M, 0);
aoqi@0 852 if (FLAG_IS_DEFAULT(G1RSetSparseRegionEntries)) {
aoqi@0 853 G1RSetSparseRegionEntries = G1RSetSparseRegionEntriesBase * (region_size_log_mb + 1);
aoqi@0 854 }
aoqi@0 855 if (FLAG_IS_DEFAULT(G1RSetRegionEntries)) {
aoqi@0 856 G1RSetRegionEntries = G1RSetRegionEntriesBase * (region_size_log_mb + 1);
aoqi@0 857 }
aoqi@0 858 guarantee(G1RSetSparseRegionEntries > 0 && G1RSetRegionEntries > 0 , "Sanity");
aoqi@0 859 }
aoqi@0 860
aoqi@0 861 bool HeapRegionRemSet::claim_iter() {
aoqi@0 862 if (_iter_state != Unclaimed) return false;
aoqi@0 863 jint res = Atomic::cmpxchg(Claimed, (jint*)(&_iter_state), Unclaimed);
aoqi@0 864 return (res == Unclaimed);
aoqi@0 865 }
aoqi@0 866
aoqi@0 867 void HeapRegionRemSet::set_iter_complete() {
aoqi@0 868 _iter_state = Complete;
aoqi@0 869 }
aoqi@0 870
aoqi@0 871 bool HeapRegionRemSet::iter_is_complete() {
aoqi@0 872 return _iter_state == Complete;
aoqi@0 873 }
aoqi@0 874
aoqi@0 875 #ifndef PRODUCT
aoqi@0 876 void HeapRegionRemSet::print() {
aoqi@0 877 HeapRegionRemSetIterator iter(this);
aoqi@0 878 size_t card_index;
aoqi@0 879 while (iter.has_next(card_index)) {
aoqi@0 880 HeapWord* card_start =
aoqi@0 881 G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
aoqi@0 882 gclog_or_tty->print_cr(" Card " PTR_FORMAT, card_start);
aoqi@0 883 }
aoqi@0 884 if (iter.n_yielded() != occupied()) {
aoqi@0 885 gclog_or_tty->print_cr("Yielded disagrees with occupied:");
aoqi@0 886 gclog_or_tty->print_cr(" %6d yielded (%6d coarse, %6d fine).",
aoqi@0 887 iter.n_yielded(),
aoqi@0 888 iter.n_yielded_coarse(), iter.n_yielded_fine());
aoqi@0 889 gclog_or_tty->print_cr(" %6d occ (%6d coarse, %6d fine).",
aoqi@0 890 occupied(), occ_coarse(), occ_fine());
aoqi@0 891 }
aoqi@0 892 guarantee(iter.n_yielded() == occupied(),
aoqi@0 893 "We should have yielded all the represented cards.");
aoqi@0 894 }
aoqi@0 895 #endif
aoqi@0 896
aoqi@0 897 void HeapRegionRemSet::cleanup() {
aoqi@0 898 SparsePRT::cleanup_all();
aoqi@0 899 }
aoqi@0 900
aoqi@0 901 void HeapRegionRemSet::clear() {
aoqi@0 902 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
aoqi@0 903 clear_locked();
aoqi@0 904 }
aoqi@0 905
aoqi@0 906 void HeapRegionRemSet::clear_locked() {
aoqi@0 907 _code_roots.clear();
aoqi@0 908 _other_regions.clear();
aoqi@0 909 assert(occupied_locked() == 0, "Should be clear.");
aoqi@0 910 reset_for_par_iteration();
aoqi@0 911 }
aoqi@0 912
aoqi@0 913 void HeapRegionRemSet::reset_for_par_iteration() {
aoqi@0 914 _iter_state = Unclaimed;
aoqi@0 915 _iter_claimed = 0;
aoqi@0 916 // It's good to check this to make sure that the two methods are in sync.
aoqi@0 917 assert(verify_ready_for_par_iteration(), "post-condition");
aoqi@0 918 }
aoqi@0 919
aoqi@0 920 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs,
aoqi@0 921 BitMap* region_bm, BitMap* card_bm) {
aoqi@0 922 _other_regions.scrub(ctbs, region_bm, card_bm);
aoqi@0 923 }
aoqi@0 924
aoqi@0 925 // Code roots support
mgerdin@7208 926 //
mgerdin@7208 927 // The code root set is protected by two separate locking schemes
mgerdin@7208 928 // When at safepoint the per-hrrs lock must be held during modifications
mgerdin@7208 929 // except when doing a full gc.
mgerdin@7208 930 // When not at safepoint the CodeCache_lock must be held during modifications.
mgerdin@7208 931 // When concurrent readers access the contains() function
mgerdin@7208 932 // (during the evacuation phase) no removals are allowed.
aoqi@0 933
aoqi@0 934 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {
aoqi@0 935 assert(nm != NULL, "sanity");
mgerdin@7208 936 // Optimistic unlocked contains-check
mgerdin@7208 937 if (!_code_roots.contains(nm)) {
mgerdin@7208 938 MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag);
mgerdin@7208 939 add_strong_code_root_locked(nm);
mgerdin@7208 940 }
mgerdin@7208 941 }
mgerdin@7208 942
mgerdin@7208 943 void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) {
mgerdin@7208 944 assert(nm != NULL, "sanity");
aoqi@0 945 _code_roots.add(nm);
aoqi@0 946 }
aoqi@0 947
aoqi@0 948 void HeapRegionRemSet::remove_strong_code_root(nmethod* nm) {
aoqi@0 949 assert(nm != NULL, "sanity");
stefank@6992 950 assert_locked_or_safepoint(CodeCache_lock);
stefank@6992 951
mgerdin@7208 952 MutexLockerEx ml(CodeCache_lock->owned_by_self() ? NULL : &_m, Mutex::_no_safepoint_check_flag);
aoqi@0 953 _code_roots.remove(nm);
stefank@6992 954
aoqi@0 955 // Check that there were no duplicates
aoqi@0 956 guarantee(!_code_roots.contains(nm), "duplicate entry found");
aoqi@0 957 }
aoqi@0 958
aoqi@0 959 void HeapRegionRemSet::strong_code_roots_do(CodeBlobClosure* blk) const {
aoqi@0 960 _code_roots.nmethods_do(blk);
aoqi@0 961 }
aoqi@0 962
mgerdin@7208 963 void HeapRegionRemSet::clean_strong_code_roots(HeapRegion* hr) {
mgerdin@7208 964 _code_roots.clean(hr);
drchase@6680 965 }
drchase@6680 966
aoqi@0 967 size_t HeapRegionRemSet::strong_code_roots_mem_size() {
aoqi@0 968 return _code_roots.mem_size();
aoqi@0 969 }
aoqi@0 970
aoqi@0 971 HeapRegionRemSetIterator:: HeapRegionRemSetIterator(HeapRegionRemSet* hrrs) :
aoqi@0 972 _hrrs(hrrs),
aoqi@0 973 _g1h(G1CollectedHeap::heap()),
aoqi@0 974 _coarse_map(&hrrs->_other_regions._coarse_map),
aoqi@0 975 _bosa(hrrs->bosa()),
aoqi@0 976 _is(Sparse),
aoqi@0 977 // Set these values so that we increment to the first region.
aoqi@0 978 _coarse_cur_region_index(-1),
aoqi@0 979 _coarse_cur_region_cur_card(HeapRegion::CardsPerRegion-1),
tschatzl@6927 980 _cur_card_in_prt(HeapRegion::CardsPerRegion),
aoqi@0 981 _fine_cur_prt(NULL),
aoqi@0 982 _n_yielded_coarse(0),
aoqi@0 983 _n_yielded_fine(0),
aoqi@0 984 _n_yielded_sparse(0),
aoqi@0 985 _sparse_iter(&hrrs->_other_regions._sparse_table) {}
aoqi@0 986
aoqi@0 987 bool HeapRegionRemSetIterator::coarse_has_next(size_t& card_index) {
aoqi@0 988 if (_hrrs->_other_regions._n_coarse_entries == 0) return false;
aoqi@0 989 // Go to the next card.
aoqi@0 990 _coarse_cur_region_cur_card++;
aoqi@0 991 // Was the last the last card in the current region?
aoqi@0 992 if (_coarse_cur_region_cur_card == HeapRegion::CardsPerRegion) {
aoqi@0 993 // Yes: find the next region. This may leave _coarse_cur_region_index
aoqi@0 994 // Set to the last index, in which case there are no more coarse
aoqi@0 995 // regions.
aoqi@0 996 _coarse_cur_region_index =
aoqi@0 997 (int) _coarse_map->get_next_one_offset(_coarse_cur_region_index + 1);
aoqi@0 998 if ((size_t)_coarse_cur_region_index < _coarse_map->size()) {
aoqi@0 999 _coarse_cur_region_cur_card = 0;
aoqi@0 1000 HeapWord* r_bot =
aoqi@0 1001 _g1h->region_at((uint) _coarse_cur_region_index)->bottom();
aoqi@0 1002 _cur_region_card_offset = _bosa->index_for(r_bot);
aoqi@0 1003 } else {
aoqi@0 1004 return false;
aoqi@0 1005 }
aoqi@0 1006 }
aoqi@0 1007 // If we didn't return false above, then we can yield a card.
aoqi@0 1008 card_index = _cur_region_card_offset + _coarse_cur_region_cur_card;
aoqi@0 1009 return true;
aoqi@0 1010 }
aoqi@0 1011
aoqi@0 1012 bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
aoqi@0 1013 if (fine_has_next()) {
tschatzl@6927 1014 _cur_card_in_prt =
tschatzl@6927 1015 _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
aoqi@0 1016 }
tschatzl@6927 1017 if (_cur_card_in_prt == HeapRegion::CardsPerRegion) {
tschatzl@6927 1018 // _fine_cur_prt may still be NULL in case if there are not PRTs at all for
tschatzl@6927 1019 // the remembered set.
tschatzl@6927 1020 if (_fine_cur_prt == NULL || _fine_cur_prt->next() == NULL) {
tschatzl@6927 1021 return false;
aoqi@0 1022 }
tschatzl@6927 1023 PerRegionTable* next_prt = _fine_cur_prt->next();
tschatzl@6927 1024 switch_to_prt(next_prt);
tschatzl@6927 1025 _cur_card_in_prt = _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
aoqi@0 1026 }
tschatzl@6927 1027
tschatzl@6927 1028 card_index = _cur_region_card_offset + _cur_card_in_prt;
tschatzl@6927 1029 guarantee(_cur_card_in_prt < HeapRegion::CardsPerRegion,
tschatzl@6927 1030 err_msg("Card index "SIZE_FORMAT" must be within the region", _cur_card_in_prt));
aoqi@0 1031 return true;
aoqi@0 1032 }
aoqi@0 1033
aoqi@0 1034 bool HeapRegionRemSetIterator::fine_has_next() {
tschatzl@6927 1035 return _cur_card_in_prt != HeapRegion::CardsPerRegion;
tschatzl@6927 1036 }
tschatzl@6927 1037
tschatzl@6927 1038 void HeapRegionRemSetIterator::switch_to_prt(PerRegionTable* prt) {
tschatzl@6927 1039 assert(prt != NULL, "Cannot switch to NULL prt");
tschatzl@6927 1040 _fine_cur_prt = prt;
tschatzl@6927 1041
tschatzl@6927 1042 HeapWord* r_bot = _fine_cur_prt->hr()->bottom();
tschatzl@6927 1043 _cur_region_card_offset = _bosa->index_for(r_bot);
tschatzl@6927 1044
tschatzl@6927 1045 // The bitmap scan for the PRT always scans from _cur_region_cur_card + 1.
tschatzl@6927 1046 // To avoid special-casing this start case, and not miss the first bitmap
tschatzl@6927 1047 // entry, initialize _cur_region_cur_card with -1 instead of 0.
tschatzl@6927 1048 _cur_card_in_prt = (size_t)-1;
aoqi@0 1049 }
aoqi@0 1050
aoqi@0 1051 bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
aoqi@0 1052 switch (_is) {
tschatzl@6927 1053 case Sparse: {
aoqi@0 1054 if (_sparse_iter.has_next(card_index)) {
aoqi@0 1055 _n_yielded_sparse++;
aoqi@0 1056 return true;
aoqi@0 1057 }
aoqi@0 1058 // Otherwise, deliberate fall-through
aoqi@0 1059 _is = Fine;
tschatzl@6927 1060 PerRegionTable* initial_fine_prt = _hrrs->_other_regions._first_all_fine_prts;
tschatzl@6927 1061 if (initial_fine_prt != NULL) {
tschatzl@6927 1062 switch_to_prt(_hrrs->_other_regions._first_all_fine_prts);
tschatzl@6927 1063 }
tschatzl@6927 1064 }
aoqi@0 1065 case Fine:
aoqi@0 1066 if (fine_has_next(card_index)) {
aoqi@0 1067 _n_yielded_fine++;
aoqi@0 1068 return true;
aoqi@0 1069 }
aoqi@0 1070 // Otherwise, deliberate fall-through
aoqi@0 1071 _is = Coarse;
aoqi@0 1072 case Coarse:
aoqi@0 1073 if (coarse_has_next(card_index)) {
aoqi@0 1074 _n_yielded_coarse++;
aoqi@0 1075 return true;
aoqi@0 1076 }
aoqi@0 1077 // Otherwise...
aoqi@0 1078 break;
aoqi@0 1079 }
aoqi@0 1080 assert(ParallelGCThreads > 1 ||
aoqi@0 1081 n_yielded() == _hrrs->occupied(),
aoqi@0 1082 "Should have yielded all the cards in the rem set "
aoqi@0 1083 "(in the non-par case).");
aoqi@0 1084 return false;
aoqi@0 1085 }
aoqi@0 1086
aoqi@0 1087
aoqi@0 1088
aoqi@0 1089 OopOrNarrowOopStar* HeapRegionRemSet::_recorded_oops = NULL;
aoqi@0 1090 HeapWord** HeapRegionRemSet::_recorded_cards = NULL;
aoqi@0 1091 HeapRegion** HeapRegionRemSet::_recorded_regions = NULL;
aoqi@0 1092 int HeapRegionRemSet::_n_recorded = 0;
aoqi@0 1093
aoqi@0 1094 HeapRegionRemSet::Event* HeapRegionRemSet::_recorded_events = NULL;
aoqi@0 1095 int* HeapRegionRemSet::_recorded_event_index = NULL;
aoqi@0 1096 int HeapRegionRemSet::_n_recorded_events = 0;
aoqi@0 1097
aoqi@0 1098 void HeapRegionRemSet::record(HeapRegion* hr, OopOrNarrowOopStar f) {
aoqi@0 1099 if (_recorded_oops == NULL) {
aoqi@0 1100 assert(_n_recorded == 0
aoqi@0 1101 && _recorded_cards == NULL
aoqi@0 1102 && _recorded_regions == NULL,
aoqi@0 1103 "Inv");
aoqi@0 1104 _recorded_oops = NEW_C_HEAP_ARRAY(OopOrNarrowOopStar, MaxRecorded, mtGC);
aoqi@0 1105 _recorded_cards = NEW_C_HEAP_ARRAY(HeapWord*, MaxRecorded, mtGC);
aoqi@0 1106 _recorded_regions = NEW_C_HEAP_ARRAY(HeapRegion*, MaxRecorded, mtGC);
aoqi@0 1107 }
aoqi@0 1108 if (_n_recorded == MaxRecorded) {
aoqi@0 1109 gclog_or_tty->print_cr("Filled up 'recorded' (%d).", MaxRecorded);
aoqi@0 1110 } else {
aoqi@0 1111 _recorded_cards[_n_recorded] =
aoqi@0 1112 (HeapWord*)align_size_down(uintptr_t(f),
aoqi@0 1113 CardTableModRefBS::card_size);
aoqi@0 1114 _recorded_oops[_n_recorded] = f;
aoqi@0 1115 _recorded_regions[_n_recorded] = hr;
aoqi@0 1116 _n_recorded++;
aoqi@0 1117 }
aoqi@0 1118 }
aoqi@0 1119
aoqi@0 1120 void HeapRegionRemSet::record_event(Event evnt) {
aoqi@0 1121 if (!G1RecordHRRSEvents) return;
aoqi@0 1122
aoqi@0 1123 if (_recorded_events == NULL) {
aoqi@0 1124 assert(_n_recorded_events == 0
aoqi@0 1125 && _recorded_event_index == NULL,
aoqi@0 1126 "Inv");
aoqi@0 1127 _recorded_events = NEW_C_HEAP_ARRAY(Event, MaxRecordedEvents, mtGC);
aoqi@0 1128 _recorded_event_index = NEW_C_HEAP_ARRAY(int, MaxRecordedEvents, mtGC);
aoqi@0 1129 }
aoqi@0 1130 if (_n_recorded_events == MaxRecordedEvents) {
aoqi@0 1131 gclog_or_tty->print_cr("Filled up 'recorded_events' (%d).", MaxRecordedEvents);
aoqi@0 1132 } else {
aoqi@0 1133 _recorded_events[_n_recorded_events] = evnt;
aoqi@0 1134 _recorded_event_index[_n_recorded_events] = _n_recorded;
aoqi@0 1135 _n_recorded_events++;
aoqi@0 1136 }
aoqi@0 1137 }
aoqi@0 1138
aoqi@0 1139 void HeapRegionRemSet::print_event(outputStream* str, Event evnt) {
aoqi@0 1140 switch (evnt) {
aoqi@0 1141 case Event_EvacStart:
aoqi@0 1142 str->print("Evac Start");
aoqi@0 1143 break;
aoqi@0 1144 case Event_EvacEnd:
aoqi@0 1145 str->print("Evac End");
aoqi@0 1146 break;
aoqi@0 1147 case Event_RSUpdateEnd:
aoqi@0 1148 str->print("RS Update End");
aoqi@0 1149 break;
aoqi@0 1150 }
aoqi@0 1151 }
aoqi@0 1152
aoqi@0 1153 void HeapRegionRemSet::print_recorded() {
aoqi@0 1154 int cur_evnt = 0;
aoqi@0 1155 Event cur_evnt_kind;
aoqi@0 1156 int cur_evnt_ind = 0;
aoqi@0 1157 if (_n_recorded_events > 0) {
aoqi@0 1158 cur_evnt_kind = _recorded_events[cur_evnt];
aoqi@0 1159 cur_evnt_ind = _recorded_event_index[cur_evnt];
aoqi@0 1160 }
aoqi@0 1161
aoqi@0 1162 for (int i = 0; i < _n_recorded; i++) {
aoqi@0 1163 while (cur_evnt < _n_recorded_events && i == cur_evnt_ind) {
aoqi@0 1164 gclog_or_tty->print("Event: ");
aoqi@0 1165 print_event(gclog_or_tty, cur_evnt_kind);
aoqi@0 1166 gclog_or_tty->cr();
aoqi@0 1167 cur_evnt++;
aoqi@0 1168 if (cur_evnt < MaxRecordedEvents) {
aoqi@0 1169 cur_evnt_kind = _recorded_events[cur_evnt];
aoqi@0 1170 cur_evnt_ind = _recorded_event_index[cur_evnt];
aoqi@0 1171 }
aoqi@0 1172 }
aoqi@0 1173 gclog_or_tty->print("Added card " PTR_FORMAT " to region [" PTR_FORMAT "...]"
aoqi@0 1174 " for ref " PTR_FORMAT ".\n",
aoqi@0 1175 _recorded_cards[i], _recorded_regions[i]->bottom(),
aoqi@0 1176 _recorded_oops[i]);
aoqi@0 1177 }
aoqi@0 1178 }
aoqi@0 1179
aoqi@0 1180 void HeapRegionRemSet::reset_for_cleanup_tasks() {
aoqi@0 1181 SparsePRT::reset_for_cleanup_tasks();
aoqi@0 1182 }
aoqi@0 1183
aoqi@0 1184 void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
aoqi@0 1185 _other_regions.do_cleanup_work(hrrs_cleanup_task);
aoqi@0 1186 }
aoqi@0 1187
aoqi@0 1188 void
aoqi@0 1189 HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) {
aoqi@0 1190 SparsePRT::finish_cleanup_task(hrrs_cleanup_task);
aoqi@0 1191 }
aoqi@0 1192
aoqi@0 1193 #ifndef PRODUCT
aoqi@0 1194 void PerRegionTable::test_fl_mem_size() {
aoqi@0 1195 PerRegionTable* dummy = alloc(NULL);
tschatzl@6932 1196
tschatzl@6932 1197 size_t min_prt_size = sizeof(void*) + dummy->bm()->size_in_words() * HeapWordSize;
tschatzl@6932 1198 assert(dummy->mem_size() > min_prt_size,
tschatzl@6932 1199 err_msg("PerRegionTable memory usage is suspiciously small, only has "SIZE_FORMAT" bytes. "
tschatzl@6932 1200 "Should be at least "SIZE_FORMAT" bytes.", dummy->mem_size(), min_prt_size));
aoqi@0 1201 free(dummy);
aoqi@0 1202 guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size");
aoqi@0 1203 // try to reset the state
aoqi@0 1204 _free_list = NULL;
aoqi@0 1205 delete dummy;
aoqi@0 1206 }
aoqi@0 1207
aoqi@0 1208 void HeapRegionRemSet::test_prt() {
aoqi@0 1209 PerRegionTable::test_fl_mem_size();
aoqi@0 1210 }
aoqi@0 1211
aoqi@0 1212 void HeapRegionRemSet::test() {
aoqi@0 1213 os::sleep(Thread::current(), (jlong)5000, false);
aoqi@0 1214 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 1215
aoqi@0 1216 // Run with "-XX:G1LogRSetRegionEntries=2", so that 1 and 5 end up in same
aoqi@0 1217 // hash bucket.
aoqi@0 1218 HeapRegion* hr0 = g1h->region_at(0);
aoqi@0 1219 HeapRegion* hr1 = g1h->region_at(1);
aoqi@0 1220 HeapRegion* hr2 = g1h->region_at(5);
aoqi@0 1221 HeapRegion* hr3 = g1h->region_at(6);
aoqi@0 1222 HeapRegion* hr4 = g1h->region_at(7);
aoqi@0 1223 HeapRegion* hr5 = g1h->region_at(8);
aoqi@0 1224
aoqi@0 1225 HeapWord* hr1_start = hr1->bottom();
aoqi@0 1226 HeapWord* hr1_mid = hr1_start + HeapRegion::GrainWords/2;
aoqi@0 1227 HeapWord* hr1_last = hr1->end() - 1;
aoqi@0 1228
aoqi@0 1229 HeapWord* hr2_start = hr2->bottom();
aoqi@0 1230 HeapWord* hr2_mid = hr2_start + HeapRegion::GrainWords/2;
aoqi@0 1231 HeapWord* hr2_last = hr2->end() - 1;
aoqi@0 1232
aoqi@0 1233 HeapWord* hr3_start = hr3->bottom();
aoqi@0 1234 HeapWord* hr3_mid = hr3_start + HeapRegion::GrainWords/2;
aoqi@0 1235 HeapWord* hr3_last = hr3->end() - 1;
aoqi@0 1236
aoqi@0 1237 HeapRegionRemSet* hrrs = hr0->rem_set();
aoqi@0 1238
aoqi@0 1239 // Make three references from region 0x101...
aoqi@0 1240 hrrs->add_reference((OopOrNarrowOopStar)hr1_start);
aoqi@0 1241 hrrs->add_reference((OopOrNarrowOopStar)hr1_mid);
aoqi@0 1242 hrrs->add_reference((OopOrNarrowOopStar)hr1_last);
aoqi@0 1243
aoqi@0 1244 hrrs->add_reference((OopOrNarrowOopStar)hr2_start);
aoqi@0 1245 hrrs->add_reference((OopOrNarrowOopStar)hr2_mid);
aoqi@0 1246 hrrs->add_reference((OopOrNarrowOopStar)hr2_last);
aoqi@0 1247
aoqi@0 1248 hrrs->add_reference((OopOrNarrowOopStar)hr3_start);
aoqi@0 1249 hrrs->add_reference((OopOrNarrowOopStar)hr3_mid);
aoqi@0 1250 hrrs->add_reference((OopOrNarrowOopStar)hr3_last);
aoqi@0 1251
aoqi@0 1252 // Now cause a coarsening.
aoqi@0 1253 hrrs->add_reference((OopOrNarrowOopStar)hr4->bottom());
aoqi@0 1254 hrrs->add_reference((OopOrNarrowOopStar)hr5->bottom());
aoqi@0 1255
aoqi@0 1256 // Now, does iteration yield these three?
aoqi@0 1257 HeapRegionRemSetIterator iter(hrrs);
aoqi@0 1258 size_t sum = 0;
aoqi@0 1259 size_t card_index;
aoqi@0 1260 while (iter.has_next(card_index)) {
aoqi@0 1261 HeapWord* card_start =
aoqi@0 1262 G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
aoqi@0 1263 gclog_or_tty->print_cr(" Card " PTR_FORMAT ".", card_start);
aoqi@0 1264 sum++;
aoqi@0 1265 }
aoqi@0 1266 guarantee(sum == 11 - 3 + 2048, "Failure");
aoqi@0 1267 guarantee(sum == hrrs->occupied(), "Failure");
aoqi@0 1268 }
aoqi@0 1269 #endif

mercurial