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

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8316
626f594dffa6
parent 7994
04ff2f6cd0eb
child 9122
024be04bb151
permissions
-rw-r--r--

Merge

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

mercurial