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

Tue, 29 May 2018 20:20:25 +0800

author
aoqi
date
Tue, 29 May 2018 20:20:25 +0800
changeset 9122
024be04bb151
parent 9046
4edb0f406a2c
parent 8604
04d83ba48607
child 9448
73d689add964
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);
bdelsart@9046 517 // The assignment into _fine_grain_regions allows the prt to
bdelsart@9046 518 // start being used concurrently. In addition to
bdelsart@9046 519 // collision_list_next which must be visible (else concurrent
bdelsart@9046 520 // parsing of the list, if any, may fail to see other entries),
bdelsart@9046 521 // the content of the prt must be visible (else for instance
bdelsart@9046 522 // some mark bits may not yet seem cleared or a 'later' update
bdelsart@9046 523 // performed by a concurrent thread could be undone when the
bdelsart@9046 524 // zeroing becomes visible). This requires store ordering.
bdelsart@9046 525 OrderAccess::release_store_ptr((volatile PerRegionTable*)&_fine_grain_regions[ind], prt);
aoqi@0 526 _n_fine_entries++;
aoqi@0 527
aoqi@0 528 if (G1HRRSUseSparseTable) {
aoqi@0 529 // Transfer from sparse to fine-grain.
tschatzl@7106 530 SparsePRTEntry *sprt_entry = _sparse_table.get_entry(from_hrm_ind);
aoqi@0 531 assert(sprt_entry != NULL, "There should have been an entry");
aoqi@0 532 for (int i = 0; i < SparsePRTEntry::cards_num(); i++) {
aoqi@0 533 CardIdx_t c = sprt_entry->card(i);
aoqi@0 534 if (c != SparsePRTEntry::NullEntry) {
aoqi@0 535 prt->add_card(c);
aoqi@0 536 }
aoqi@0 537 }
aoqi@0 538 // Now we can delete the sparse entry.
tschatzl@7106 539 bool res = _sparse_table.delete_entry(from_hrm_ind);
aoqi@0 540 assert(res, "It should have been there.");
aoqi@0 541 }
aoqi@0 542 }
aoqi@0 543 assert(prt != NULL && prt->hr() == from_hr, "consequence");
aoqi@0 544 }
aoqi@0 545 // Note that we can't assert "prt->hr() == from_hr", because of the
aoqi@0 546 // possibility of concurrent reuse. But see head comment of
aoqi@0 547 // OtherRegionsTable for why this is OK.
aoqi@0 548 assert(prt != NULL, "Inv");
aoqi@0 549
aoqi@0 550 prt->add_reference(from);
aoqi@0 551
aoqi@0 552 if (G1RecordHRRSOops) {
aoqi@0 553 HeapRegionRemSet::record(hr(), from);
aoqi@0 554 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 555 gclog_or_tty->print("Added card " PTR_FORMAT " to region "
aoqi@0 556 "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
aoqi@0 557 align_size_down(uintptr_t(from),
aoqi@0 558 CardTableModRefBS::card_size),
aoqi@0 559 hr()->bottom(), from);
aoqi@0 560 }
aoqi@0 561 }
tschatzl@8281 562 assert(contains_reference(from), err_msg("We just added " PTR_FORMAT " to the PRT", from));
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 PerRegionTable*
aoqi@0 566 OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const {
aoqi@0 567 assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
aoqi@0 568 PerRegionTable* prt = _fine_grain_regions[ind];
aoqi@0 569 while (prt != NULL && prt->hr() != hr) {
aoqi@0 570 prt = prt->collision_list_next();
aoqi@0 571 }
aoqi@0 572 // Loop postcondition is the method postcondition.
aoqi@0 573 return prt;
aoqi@0 574 }
aoqi@0 575
aoqi@0 576 jint OtherRegionsTable::_n_coarsenings = 0;
aoqi@0 577
aoqi@0 578 PerRegionTable* OtherRegionsTable::delete_region_table() {
aoqi@0 579 assert(_m->owned_by_self(), "Precondition");
aoqi@0 580 assert(_n_fine_entries == _max_fine_entries, "Precondition");
aoqi@0 581 PerRegionTable* max = NULL;
aoqi@0 582 jint max_occ = 0;
csahu@8316 583 PerRegionTable** max_prev = NULL;
aoqi@0 584 size_t max_ind;
aoqi@0 585
aoqi@0 586 size_t i = _fine_eviction_start;
aoqi@0 587 for (size_t k = 0; k < _fine_eviction_sample_size; k++) {
aoqi@0 588 size_t ii = i;
aoqi@0 589 // Make sure we get a non-NULL sample.
aoqi@0 590 while (_fine_grain_regions[ii] == NULL) {
aoqi@0 591 ii++;
aoqi@0 592 if (ii == _max_fine_entries) ii = 0;
aoqi@0 593 guarantee(ii != i, "We must find one.");
aoqi@0 594 }
aoqi@0 595 PerRegionTable** prev = &_fine_grain_regions[ii];
aoqi@0 596 PerRegionTable* cur = *prev;
aoqi@0 597 while (cur != NULL) {
aoqi@0 598 jint cur_occ = cur->occupied();
aoqi@0 599 if (max == NULL || cur_occ > max_occ) {
aoqi@0 600 max = cur;
aoqi@0 601 max_prev = prev;
aoqi@0 602 max_ind = i;
aoqi@0 603 max_occ = cur_occ;
aoqi@0 604 }
aoqi@0 605 prev = cur->collision_list_next_addr();
aoqi@0 606 cur = cur->collision_list_next();
aoqi@0 607 }
aoqi@0 608 i = i + _fine_eviction_stride;
aoqi@0 609 if (i >= _n_fine_entries) i = i - _n_fine_entries;
aoqi@0 610 }
aoqi@0 611
aoqi@0 612 _fine_eviction_start++;
aoqi@0 613
aoqi@0 614 if (_fine_eviction_start >= _n_fine_entries) {
aoqi@0 615 _fine_eviction_start -= _n_fine_entries;
aoqi@0 616 }
aoqi@0 617
aoqi@0 618 guarantee(max != NULL, "Since _n_fine_entries > 0");
csahu@8316 619 guarantee(max_prev != NULL, "Since max != NULL.");
aoqi@0 620
aoqi@0 621 // Set the corresponding coarse bit.
tschatzl@7091 622 size_t max_hrm_index = (size_t) max->hr()->hrm_index();
tschatzl@7091 623 if (!_coarse_map.at(max_hrm_index)) {
tschatzl@7091 624 _coarse_map.at_put(max_hrm_index, true);
aoqi@0 625 _n_coarse_entries++;
aoqi@0 626 if (G1TraceHeapRegionRememberedSet) {
aoqi@0 627 gclog_or_tty->print("Coarsened entry in region [" PTR_FORMAT "...] "
aoqi@0 628 "for region [" PTR_FORMAT "...] (%d coarse entries).\n",
aoqi@0 629 hr()->bottom(),
aoqi@0 630 max->hr()->bottom(),
aoqi@0 631 _n_coarse_entries);
aoqi@0 632 }
aoqi@0 633 }
aoqi@0 634
aoqi@0 635 // Unsplice.
aoqi@0 636 *max_prev = max->collision_list_next();
aoqi@0 637 Atomic::inc(&_n_coarsenings);
aoqi@0 638 _n_fine_entries--;
aoqi@0 639 return max;
aoqi@0 640 }
aoqi@0 641
aoqi@0 642
aoqi@0 643 // At present, this must be called stop-world single-threaded.
aoqi@0 644 void OtherRegionsTable::scrub(CardTableModRefBS* ctbs,
aoqi@0 645 BitMap* region_bm, BitMap* card_bm) {
aoqi@0 646 // First eliminated garbage regions from the coarse map.
aoqi@0 647 if (G1RSScrubVerbose) {
tschatzl@7091 648 gclog_or_tty->print_cr("Scrubbing region %u:", hr()->hrm_index());
aoqi@0 649 }
aoqi@0 650
aoqi@0 651 assert(_coarse_map.size() == region_bm->size(), "Precondition");
aoqi@0 652 if (G1RSScrubVerbose) {
aoqi@0 653 gclog_or_tty->print(" Coarse map: before = "SIZE_FORMAT"...",
aoqi@0 654 _n_coarse_entries);
aoqi@0 655 }
aoqi@0 656 _coarse_map.set_intersection(*region_bm);
aoqi@0 657 _n_coarse_entries = _coarse_map.count_one_bits();
aoqi@0 658 if (G1RSScrubVerbose) {
aoqi@0 659 gclog_or_tty->print_cr(" after = "SIZE_FORMAT".", _n_coarse_entries);
aoqi@0 660 }
aoqi@0 661
aoqi@0 662 // Now do the fine-grained maps.
aoqi@0 663 for (size_t i = 0; i < _max_fine_entries; i++) {
aoqi@0 664 PerRegionTable* cur = _fine_grain_regions[i];
aoqi@0 665 PerRegionTable** prev = &_fine_grain_regions[i];
aoqi@0 666 while (cur != NULL) {
aoqi@0 667 PerRegionTable* nxt = cur->collision_list_next();
aoqi@0 668 // If the entire region is dead, eliminate.
aoqi@0 669 if (G1RSScrubVerbose) {
aoqi@0 670 gclog_or_tty->print_cr(" For other region %u:",
tschatzl@7091 671 cur->hr()->hrm_index());
aoqi@0 672 }
tschatzl@7091 673 if (!region_bm->at((size_t) cur->hr()->hrm_index())) {
aoqi@0 674 *prev = nxt;
aoqi@0 675 cur->set_collision_list_next(NULL);
aoqi@0 676 _n_fine_entries--;
aoqi@0 677 if (G1RSScrubVerbose) {
aoqi@0 678 gclog_or_tty->print_cr(" deleted via region map.");
aoqi@0 679 }
aoqi@0 680 unlink_from_all(cur);
aoqi@0 681 PerRegionTable::free(cur);
aoqi@0 682 } else {
aoqi@0 683 // Do fine-grain elimination.
aoqi@0 684 if (G1RSScrubVerbose) {
aoqi@0 685 gclog_or_tty->print(" occ: before = %4d.", cur->occupied());
aoqi@0 686 }
aoqi@0 687 cur->scrub(ctbs, card_bm);
aoqi@0 688 if (G1RSScrubVerbose) {
aoqi@0 689 gclog_or_tty->print_cr(" after = %4d.", cur->occupied());
aoqi@0 690 }
aoqi@0 691 // Did that empty the table completely?
aoqi@0 692 if (cur->occupied() == 0) {
aoqi@0 693 *prev = nxt;
aoqi@0 694 cur->set_collision_list_next(NULL);
aoqi@0 695 _n_fine_entries--;
aoqi@0 696 unlink_from_all(cur);
aoqi@0 697 PerRegionTable::free(cur);
aoqi@0 698 } else {
aoqi@0 699 prev = cur->collision_list_next_addr();
aoqi@0 700 }
aoqi@0 701 }
aoqi@0 702 cur = nxt;
aoqi@0 703 }
aoqi@0 704 }
aoqi@0 705 // Since we may have deleted a from_card_cache entry from the RS, clear
aoqi@0 706 // the FCC.
aoqi@0 707 clear_fcc();
aoqi@0 708 }
aoqi@0 709
tschatzl@7828 710 bool OtherRegionsTable::occupancy_less_or_equal_than(size_t limit) const {
tschatzl@7828 711 if (limit <= (size_t)G1RSetSparseRegionEntries) {
tschatzl@7828 712 return occ_coarse() == 0 && _first_all_fine_prts == NULL && occ_sparse() <= limit;
tschatzl@7828 713 } else {
tschatzl@7828 714 // Current uses of this method may only use values less than G1RSetSparseRegionEntries
tschatzl@7828 715 // for the limit. The solution, comparing against occupied() would be too slow
tschatzl@7828 716 // at this time.
tschatzl@7828 717 Unimplemented();
tschatzl@7828 718 return false;
tschatzl@7828 719 }
tschatzl@7828 720 }
tschatzl@7828 721
tschatzl@7010 722 bool OtherRegionsTable::is_empty() const {
tschatzl@7010 723 return occ_sparse() == 0 && occ_coarse() == 0 && _first_all_fine_prts == NULL;
tschatzl@7010 724 }
aoqi@0 725
aoqi@0 726 size_t OtherRegionsTable::occupied() const {
aoqi@0 727 size_t sum = occ_fine();
aoqi@0 728 sum += occ_sparse();
aoqi@0 729 sum += occ_coarse();
aoqi@0 730 return sum;
aoqi@0 731 }
aoqi@0 732
aoqi@0 733 size_t OtherRegionsTable::occ_fine() const {
aoqi@0 734 size_t sum = 0;
aoqi@0 735
aoqi@0 736 size_t num = 0;
aoqi@0 737 PerRegionTable * cur = _first_all_fine_prts;
aoqi@0 738 while (cur != NULL) {
aoqi@0 739 sum += cur->occupied();
aoqi@0 740 cur = cur->next();
aoqi@0 741 num++;
aoqi@0 742 }
aoqi@0 743 guarantee(num == _n_fine_entries, "just checking");
aoqi@0 744 return sum;
aoqi@0 745 }
aoqi@0 746
aoqi@0 747 size_t OtherRegionsTable::occ_coarse() const {
aoqi@0 748 return (_n_coarse_entries * HeapRegion::CardsPerRegion);
aoqi@0 749 }
aoqi@0 750
aoqi@0 751 size_t OtherRegionsTable::occ_sparse() const {
aoqi@0 752 return _sparse_table.occupied();
aoqi@0 753 }
aoqi@0 754
aoqi@0 755 size_t OtherRegionsTable::mem_size() const {
aoqi@0 756 size_t sum = 0;
aoqi@0 757 // all PRTs are of the same size so it is sufficient to query only one of them.
aoqi@0 758 if (_first_all_fine_prts != NULL) {
aoqi@0 759 assert(_last_all_fine_prts != NULL &&
aoqi@0 760 _first_all_fine_prts->mem_size() == _last_all_fine_prts->mem_size(), "check that mem_size() is constant");
aoqi@0 761 sum += _first_all_fine_prts->mem_size() * _n_fine_entries;
aoqi@0 762 }
aoqi@0 763 sum += (sizeof(PerRegionTable*) * _max_fine_entries);
aoqi@0 764 sum += (_coarse_map.size_in_words() * HeapWordSize);
aoqi@0 765 sum += (_sparse_table.mem_size());
tschatzl@6932 766 sum += sizeof(OtherRegionsTable) - sizeof(_sparse_table); // Avoid double counting above.
aoqi@0 767 return sum;
aoqi@0 768 }
aoqi@0 769
aoqi@0 770 size_t OtherRegionsTable::static_mem_size() {
aoqi@0 771 return FromCardCache::static_mem_size();
aoqi@0 772 }
aoqi@0 773
aoqi@0 774 size_t OtherRegionsTable::fl_mem_size() {
aoqi@0 775 return PerRegionTable::fl_mem_size();
aoqi@0 776 }
aoqi@0 777
aoqi@0 778 void OtherRegionsTable::clear_fcc() {
tschatzl@7091 779 FromCardCache::clear(hr()->hrm_index());
aoqi@0 780 }
aoqi@0 781
aoqi@0 782 void OtherRegionsTable::clear() {
aoqi@0 783 // if there are no entries, skip this step
aoqi@0 784 if (_first_all_fine_prts != NULL) {
aoqi@0 785 guarantee(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL, "just checking");
aoqi@0 786 PerRegionTable::bulk_free(_first_all_fine_prts, _last_all_fine_prts);
aoqi@0 787 memset(_fine_grain_regions, 0, _max_fine_entries * sizeof(_fine_grain_regions[0]));
aoqi@0 788 } else {
aoqi@0 789 guarantee(_first_all_fine_prts == NULL && _last_all_fine_prts == NULL, "just checking");
aoqi@0 790 }
aoqi@0 791
aoqi@0 792 _first_all_fine_prts = _last_all_fine_prts = NULL;
aoqi@0 793 _sparse_table.clear();
aoqi@0 794 _coarse_map.clear();
aoqi@0 795 _n_fine_entries = 0;
aoqi@0 796 _n_coarse_entries = 0;
aoqi@0 797
aoqi@0 798 clear_fcc();
aoqi@0 799 }
aoqi@0 800
aoqi@0 801 bool OtherRegionsTable::del_single_region_table(size_t ind,
aoqi@0 802 HeapRegion* hr) {
aoqi@0 803 assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
aoqi@0 804 PerRegionTable** prev_addr = &_fine_grain_regions[ind];
aoqi@0 805 PerRegionTable* prt = *prev_addr;
aoqi@0 806 while (prt != NULL && prt->hr() != hr) {
aoqi@0 807 prev_addr = prt->collision_list_next_addr();
aoqi@0 808 prt = prt->collision_list_next();
aoqi@0 809 }
aoqi@0 810 if (prt != NULL) {
aoqi@0 811 assert(prt->hr() == hr, "Loop postcondition.");
aoqi@0 812 *prev_addr = prt->collision_list_next();
aoqi@0 813 unlink_from_all(prt);
aoqi@0 814 PerRegionTable::free(prt);
aoqi@0 815 _n_fine_entries--;
aoqi@0 816 return true;
aoqi@0 817 } else {
aoqi@0 818 return false;
aoqi@0 819 }
aoqi@0 820 }
aoqi@0 821
aoqi@0 822 bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
aoqi@0 823 // Cast away const in this case.
aoqi@0 824 MutexLockerEx x((Mutex*)_m, Mutex::_no_safepoint_check_flag);
aoqi@0 825 return contains_reference_locked(from);
aoqi@0 826 }
aoqi@0 827
aoqi@0 828 bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
aoqi@0 829 HeapRegion* hr = _g1h->heap_region_containing_raw(from);
tschatzl@7091 830 RegionIdx_t hr_ind = (RegionIdx_t) hr->hrm_index();
aoqi@0 831 // Is this region in the coarse map?
aoqi@0 832 if (_coarse_map.at(hr_ind)) return true;
aoqi@0 833
aoqi@0 834 PerRegionTable* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
aoqi@0 835 hr);
aoqi@0 836 if (prt != NULL) {
aoqi@0 837 return prt->contains_reference(from);
aoqi@0 838
aoqi@0 839 } else {
aoqi@0 840 uintptr_t from_card =
aoqi@0 841 (uintptr_t(from) >> CardTableModRefBS::card_shift);
aoqi@0 842 uintptr_t hr_bot_card_index =
aoqi@0 843 uintptr_t(hr->bottom()) >> CardTableModRefBS::card_shift;
aoqi@0 844 assert(from_card >= hr_bot_card_index, "Inv");
aoqi@0 845 CardIdx_t card_index = from_card - hr_bot_card_index;
aoqi@0 846 assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
aoqi@0 847 "Must be in range.");
aoqi@0 848 return _sparse_table.contains_card(hr_ind, card_index);
aoqi@0 849 }
aoqi@0 850 }
aoqi@0 851
aoqi@0 852 void
aoqi@0 853 OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
aoqi@0 854 _sparse_table.do_cleanup_work(hrrs_cleanup_task);
aoqi@0 855 }
aoqi@0 856
aoqi@0 857 // Determines how many threads can add records to an rset in parallel.
aoqi@0 858 // This can be done by either mutator threads together with the
aoqi@0 859 // concurrent refinement threads or GC threads.
aoqi@0 860 uint HeapRegionRemSet::num_par_rem_sets() {
aoqi@0 861 return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), (uint)ParallelGCThreads);
aoqi@0 862 }
aoqi@0 863
aoqi@0 864 HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
aoqi@0 865 HeapRegion* hr)
aoqi@0 866 : _bosa(bosa),
tschatzl@7091 867 _m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true),
tschatzl@7051 868 _code_roots(), _other_regions(hr, &_m), _iter_state(Unclaimed), _iter_claimed(0) {
aoqi@0 869 reset_for_par_iteration();
aoqi@0 870 }
aoqi@0 871
aoqi@0 872 void HeapRegionRemSet::setup_remset_size() {
aoqi@0 873 // Setup sparse and fine-grain tables sizes.
aoqi@0 874 // table_size = base * (log(region_size / 1M) + 1)
aoqi@0 875 const int LOG_M = 20;
aoqi@0 876 int region_size_log_mb = MAX2(HeapRegion::LogOfHRGrainBytes - LOG_M, 0);
aoqi@0 877 if (FLAG_IS_DEFAULT(G1RSetSparseRegionEntries)) {
aoqi@0 878 G1RSetSparseRegionEntries = G1RSetSparseRegionEntriesBase * (region_size_log_mb + 1);
aoqi@0 879 }
aoqi@0 880 if (FLAG_IS_DEFAULT(G1RSetRegionEntries)) {
aoqi@0 881 G1RSetRegionEntries = G1RSetRegionEntriesBase * (region_size_log_mb + 1);
aoqi@0 882 }
aoqi@0 883 guarantee(G1RSetSparseRegionEntries > 0 && G1RSetRegionEntries > 0 , "Sanity");
aoqi@0 884 }
aoqi@0 885
aoqi@0 886 bool HeapRegionRemSet::claim_iter() {
aoqi@0 887 if (_iter_state != Unclaimed) return false;
aoqi@0 888 jint res = Atomic::cmpxchg(Claimed, (jint*)(&_iter_state), Unclaimed);
aoqi@0 889 return (res == Unclaimed);
aoqi@0 890 }
aoqi@0 891
aoqi@0 892 void HeapRegionRemSet::set_iter_complete() {
aoqi@0 893 _iter_state = Complete;
aoqi@0 894 }
aoqi@0 895
aoqi@0 896 bool HeapRegionRemSet::iter_is_complete() {
aoqi@0 897 return _iter_state == Complete;
aoqi@0 898 }
aoqi@0 899
aoqi@0 900 #ifndef PRODUCT
aoqi@0 901 void HeapRegionRemSet::print() {
aoqi@0 902 HeapRegionRemSetIterator iter(this);
aoqi@0 903 size_t card_index;
aoqi@0 904 while (iter.has_next(card_index)) {
aoqi@0 905 HeapWord* card_start =
aoqi@0 906 G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
aoqi@0 907 gclog_or_tty->print_cr(" Card " PTR_FORMAT, card_start);
aoqi@0 908 }
aoqi@0 909 if (iter.n_yielded() != occupied()) {
aoqi@0 910 gclog_or_tty->print_cr("Yielded disagrees with occupied:");
aoqi@0 911 gclog_or_tty->print_cr(" %6d yielded (%6d coarse, %6d fine).",
aoqi@0 912 iter.n_yielded(),
aoqi@0 913 iter.n_yielded_coarse(), iter.n_yielded_fine());
aoqi@0 914 gclog_or_tty->print_cr(" %6d occ (%6d coarse, %6d fine).",
aoqi@0 915 occupied(), occ_coarse(), occ_fine());
aoqi@0 916 }
aoqi@0 917 guarantee(iter.n_yielded() == occupied(),
aoqi@0 918 "We should have yielded all the represented cards.");
aoqi@0 919 }
aoqi@0 920 #endif
aoqi@0 921
aoqi@0 922 void HeapRegionRemSet::cleanup() {
aoqi@0 923 SparsePRT::cleanup_all();
aoqi@0 924 }
aoqi@0 925
aoqi@0 926 void HeapRegionRemSet::clear() {
aoqi@0 927 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
aoqi@0 928 clear_locked();
aoqi@0 929 }
aoqi@0 930
aoqi@0 931 void HeapRegionRemSet::clear_locked() {
aoqi@0 932 _code_roots.clear();
aoqi@0 933 _other_regions.clear();
aoqi@0 934 assert(occupied_locked() == 0, "Should be clear.");
aoqi@0 935 reset_for_par_iteration();
aoqi@0 936 }
aoqi@0 937
aoqi@0 938 void HeapRegionRemSet::reset_for_par_iteration() {
aoqi@0 939 _iter_state = Unclaimed;
aoqi@0 940 _iter_claimed = 0;
aoqi@0 941 // It's good to check this to make sure that the two methods are in sync.
aoqi@0 942 assert(verify_ready_for_par_iteration(), "post-condition");
aoqi@0 943 }
aoqi@0 944
aoqi@0 945 void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs,
aoqi@0 946 BitMap* region_bm, BitMap* card_bm) {
aoqi@0 947 _other_regions.scrub(ctbs, region_bm, card_bm);
aoqi@0 948 }
aoqi@0 949
aoqi@0 950 // Code roots support
mgerdin@7208 951 //
mgerdin@7208 952 // The code root set is protected by two separate locking schemes
mgerdin@7208 953 // When at safepoint the per-hrrs lock must be held during modifications
mgerdin@7208 954 // except when doing a full gc.
mgerdin@7208 955 // When not at safepoint the CodeCache_lock must be held during modifications.
mgerdin@7208 956 // When concurrent readers access the contains() function
mgerdin@7208 957 // (during the evacuation phase) no removals are allowed.
aoqi@0 958
aoqi@0 959 void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {
aoqi@0 960 assert(nm != NULL, "sanity");
mgerdin@7208 961 // Optimistic unlocked contains-check
mgerdin@7208 962 if (!_code_roots.contains(nm)) {
mgerdin@7208 963 MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag);
mgerdin@7208 964 add_strong_code_root_locked(nm);
mgerdin@7208 965 }
mgerdin@7208 966 }
mgerdin@7208 967
mgerdin@7208 968 void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) {
mgerdin@7208 969 assert(nm != NULL, "sanity");
aoqi@0 970 _code_roots.add(nm);
aoqi@0 971 }
aoqi@0 972
aoqi@0 973 void HeapRegionRemSet::remove_strong_code_root(nmethod* nm) {
aoqi@0 974 assert(nm != NULL, "sanity");
stefank@6992 975 assert_locked_or_safepoint(CodeCache_lock);
stefank@6992 976
mgerdin@7208 977 MutexLockerEx ml(CodeCache_lock->owned_by_self() ? NULL : &_m, Mutex::_no_safepoint_check_flag);
aoqi@0 978 _code_roots.remove(nm);
stefank@6992 979
aoqi@0 980 // Check that there were no duplicates
aoqi@0 981 guarantee(!_code_roots.contains(nm), "duplicate entry found");
aoqi@0 982 }
aoqi@0 983
aoqi@0 984 void HeapRegionRemSet::strong_code_roots_do(CodeBlobClosure* blk) const {
aoqi@0 985 _code_roots.nmethods_do(blk);
aoqi@0 986 }
aoqi@0 987
mgerdin@7208 988 void HeapRegionRemSet::clean_strong_code_roots(HeapRegion* hr) {
mgerdin@7208 989 _code_roots.clean(hr);
drchase@6680 990 }
drchase@6680 991
aoqi@0 992 size_t HeapRegionRemSet::strong_code_roots_mem_size() {
aoqi@0 993 return _code_roots.mem_size();
aoqi@0 994 }
aoqi@0 995
aoqi@0 996 HeapRegionRemSetIterator:: HeapRegionRemSetIterator(HeapRegionRemSet* hrrs) :
aoqi@0 997 _hrrs(hrrs),
aoqi@0 998 _g1h(G1CollectedHeap::heap()),
aoqi@0 999 _coarse_map(&hrrs->_other_regions._coarse_map),
aoqi@0 1000 _bosa(hrrs->bosa()),
aoqi@0 1001 _is(Sparse),
aoqi@0 1002 // Set these values so that we increment to the first region.
aoqi@0 1003 _coarse_cur_region_index(-1),
aoqi@0 1004 _coarse_cur_region_cur_card(HeapRegion::CardsPerRegion-1),
tschatzl@6927 1005 _cur_card_in_prt(HeapRegion::CardsPerRegion),
aoqi@0 1006 _fine_cur_prt(NULL),
aoqi@0 1007 _n_yielded_coarse(0),
aoqi@0 1008 _n_yielded_fine(0),
aoqi@0 1009 _n_yielded_sparse(0),
aoqi@0 1010 _sparse_iter(&hrrs->_other_regions._sparse_table) {}
aoqi@0 1011
aoqi@0 1012 bool HeapRegionRemSetIterator::coarse_has_next(size_t& card_index) {
aoqi@0 1013 if (_hrrs->_other_regions._n_coarse_entries == 0) return false;
aoqi@0 1014 // Go to the next card.
aoqi@0 1015 _coarse_cur_region_cur_card++;
aoqi@0 1016 // Was the last the last card in the current region?
aoqi@0 1017 if (_coarse_cur_region_cur_card == HeapRegion::CardsPerRegion) {
aoqi@0 1018 // Yes: find the next region. This may leave _coarse_cur_region_index
aoqi@0 1019 // Set to the last index, in which case there are no more coarse
aoqi@0 1020 // regions.
aoqi@0 1021 _coarse_cur_region_index =
aoqi@0 1022 (int) _coarse_map->get_next_one_offset(_coarse_cur_region_index + 1);
aoqi@0 1023 if ((size_t)_coarse_cur_region_index < _coarse_map->size()) {
aoqi@0 1024 _coarse_cur_region_cur_card = 0;
aoqi@0 1025 HeapWord* r_bot =
aoqi@0 1026 _g1h->region_at((uint) _coarse_cur_region_index)->bottom();
aoqi@0 1027 _cur_region_card_offset = _bosa->index_for(r_bot);
aoqi@0 1028 } else {
aoqi@0 1029 return false;
aoqi@0 1030 }
aoqi@0 1031 }
aoqi@0 1032 // If we didn't return false above, then we can yield a card.
aoqi@0 1033 card_index = _cur_region_card_offset + _coarse_cur_region_cur_card;
aoqi@0 1034 return true;
aoqi@0 1035 }
aoqi@0 1036
aoqi@0 1037 bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
aoqi@0 1038 if (fine_has_next()) {
tschatzl@6927 1039 _cur_card_in_prt =
tschatzl@6927 1040 _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
aoqi@0 1041 }
tschatzl@6927 1042 if (_cur_card_in_prt == HeapRegion::CardsPerRegion) {
tschatzl@6927 1043 // _fine_cur_prt may still be NULL in case if there are not PRTs at all for
tschatzl@6927 1044 // the remembered set.
tschatzl@6927 1045 if (_fine_cur_prt == NULL || _fine_cur_prt->next() == NULL) {
tschatzl@6927 1046 return false;
aoqi@0 1047 }
tschatzl@6927 1048 PerRegionTable* next_prt = _fine_cur_prt->next();
tschatzl@6927 1049 switch_to_prt(next_prt);
tschatzl@6927 1050 _cur_card_in_prt = _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
aoqi@0 1051 }
tschatzl@6927 1052
tschatzl@6927 1053 card_index = _cur_region_card_offset + _cur_card_in_prt;
tschatzl@6927 1054 guarantee(_cur_card_in_prt < HeapRegion::CardsPerRegion,
tschatzl@6927 1055 err_msg("Card index "SIZE_FORMAT" must be within the region", _cur_card_in_prt));
aoqi@0 1056 return true;
aoqi@0 1057 }
aoqi@0 1058
aoqi@0 1059 bool HeapRegionRemSetIterator::fine_has_next() {
tschatzl@6927 1060 return _cur_card_in_prt != HeapRegion::CardsPerRegion;
tschatzl@6927 1061 }
tschatzl@6927 1062
tschatzl@6927 1063 void HeapRegionRemSetIterator::switch_to_prt(PerRegionTable* prt) {
tschatzl@6927 1064 assert(prt != NULL, "Cannot switch to NULL prt");
tschatzl@6927 1065 _fine_cur_prt = prt;
tschatzl@6927 1066
tschatzl@6927 1067 HeapWord* r_bot = _fine_cur_prt->hr()->bottom();
tschatzl@6927 1068 _cur_region_card_offset = _bosa->index_for(r_bot);
tschatzl@6927 1069
tschatzl@6927 1070 // The bitmap scan for the PRT always scans from _cur_region_cur_card + 1.
tschatzl@6927 1071 // To avoid special-casing this start case, and not miss the first bitmap
tschatzl@6927 1072 // entry, initialize _cur_region_cur_card with -1 instead of 0.
tschatzl@6927 1073 _cur_card_in_prt = (size_t)-1;
aoqi@0 1074 }
aoqi@0 1075
aoqi@0 1076 bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
aoqi@0 1077 switch (_is) {
tschatzl@6927 1078 case Sparse: {
aoqi@0 1079 if (_sparse_iter.has_next(card_index)) {
aoqi@0 1080 _n_yielded_sparse++;
aoqi@0 1081 return true;
aoqi@0 1082 }
aoqi@0 1083 // Otherwise, deliberate fall-through
aoqi@0 1084 _is = Fine;
tschatzl@6927 1085 PerRegionTable* initial_fine_prt = _hrrs->_other_regions._first_all_fine_prts;
tschatzl@6927 1086 if (initial_fine_prt != NULL) {
tschatzl@6927 1087 switch_to_prt(_hrrs->_other_regions._first_all_fine_prts);
tschatzl@6927 1088 }
tschatzl@6927 1089 }
aoqi@0 1090 case Fine:
aoqi@0 1091 if (fine_has_next(card_index)) {
aoqi@0 1092 _n_yielded_fine++;
aoqi@0 1093 return true;
aoqi@0 1094 }
aoqi@0 1095 // Otherwise, deliberate fall-through
aoqi@0 1096 _is = Coarse;
aoqi@0 1097 case Coarse:
aoqi@0 1098 if (coarse_has_next(card_index)) {
aoqi@0 1099 _n_yielded_coarse++;
aoqi@0 1100 return true;
aoqi@0 1101 }
aoqi@0 1102 // Otherwise...
aoqi@0 1103 break;
aoqi@0 1104 }
aoqi@0 1105 assert(ParallelGCThreads > 1 ||
aoqi@0 1106 n_yielded() == _hrrs->occupied(),
aoqi@0 1107 "Should have yielded all the cards in the rem set "
aoqi@0 1108 "(in the non-par case).");
aoqi@0 1109 return false;
aoqi@0 1110 }
aoqi@0 1111
aoqi@0 1112
aoqi@0 1113
aoqi@0 1114 OopOrNarrowOopStar* HeapRegionRemSet::_recorded_oops = NULL;
aoqi@0 1115 HeapWord** HeapRegionRemSet::_recorded_cards = NULL;
aoqi@0 1116 HeapRegion** HeapRegionRemSet::_recorded_regions = NULL;
aoqi@0 1117 int HeapRegionRemSet::_n_recorded = 0;
aoqi@0 1118
aoqi@0 1119 HeapRegionRemSet::Event* HeapRegionRemSet::_recorded_events = NULL;
aoqi@0 1120 int* HeapRegionRemSet::_recorded_event_index = NULL;
aoqi@0 1121 int HeapRegionRemSet::_n_recorded_events = 0;
aoqi@0 1122
aoqi@0 1123 void HeapRegionRemSet::record(HeapRegion* hr, OopOrNarrowOopStar f) {
aoqi@0 1124 if (_recorded_oops == NULL) {
aoqi@0 1125 assert(_n_recorded == 0
aoqi@0 1126 && _recorded_cards == NULL
aoqi@0 1127 && _recorded_regions == NULL,
aoqi@0 1128 "Inv");
aoqi@0 1129 _recorded_oops = NEW_C_HEAP_ARRAY(OopOrNarrowOopStar, MaxRecorded, mtGC);
aoqi@0 1130 _recorded_cards = NEW_C_HEAP_ARRAY(HeapWord*, MaxRecorded, mtGC);
aoqi@0 1131 _recorded_regions = NEW_C_HEAP_ARRAY(HeapRegion*, MaxRecorded, mtGC);
aoqi@0 1132 }
aoqi@0 1133 if (_n_recorded == MaxRecorded) {
aoqi@0 1134 gclog_or_tty->print_cr("Filled up 'recorded' (%d).", MaxRecorded);
aoqi@0 1135 } else {
aoqi@0 1136 _recorded_cards[_n_recorded] =
aoqi@0 1137 (HeapWord*)align_size_down(uintptr_t(f),
aoqi@0 1138 CardTableModRefBS::card_size);
aoqi@0 1139 _recorded_oops[_n_recorded] = f;
aoqi@0 1140 _recorded_regions[_n_recorded] = hr;
aoqi@0 1141 _n_recorded++;
aoqi@0 1142 }
aoqi@0 1143 }
aoqi@0 1144
aoqi@0 1145 void HeapRegionRemSet::record_event(Event evnt) {
aoqi@0 1146 if (!G1RecordHRRSEvents) return;
aoqi@0 1147
aoqi@0 1148 if (_recorded_events == NULL) {
aoqi@0 1149 assert(_n_recorded_events == 0
aoqi@0 1150 && _recorded_event_index == NULL,
aoqi@0 1151 "Inv");
aoqi@0 1152 _recorded_events = NEW_C_HEAP_ARRAY(Event, MaxRecordedEvents, mtGC);
aoqi@0 1153 _recorded_event_index = NEW_C_HEAP_ARRAY(int, MaxRecordedEvents, mtGC);
aoqi@0 1154 }
aoqi@0 1155 if (_n_recorded_events == MaxRecordedEvents) {
aoqi@0 1156 gclog_or_tty->print_cr("Filled up 'recorded_events' (%d).", MaxRecordedEvents);
aoqi@0 1157 } else {
aoqi@0 1158 _recorded_events[_n_recorded_events] = evnt;
aoqi@0 1159 _recorded_event_index[_n_recorded_events] = _n_recorded;
aoqi@0 1160 _n_recorded_events++;
aoqi@0 1161 }
aoqi@0 1162 }
aoqi@0 1163
aoqi@0 1164 void HeapRegionRemSet::print_event(outputStream* str, Event evnt) {
aoqi@0 1165 switch (evnt) {
aoqi@0 1166 case Event_EvacStart:
aoqi@0 1167 str->print("Evac Start");
aoqi@0 1168 break;
aoqi@0 1169 case Event_EvacEnd:
aoqi@0 1170 str->print("Evac End");
aoqi@0 1171 break;
aoqi@0 1172 case Event_RSUpdateEnd:
aoqi@0 1173 str->print("RS Update End");
aoqi@0 1174 break;
aoqi@0 1175 }
aoqi@0 1176 }
aoqi@0 1177
aoqi@0 1178 void HeapRegionRemSet::print_recorded() {
aoqi@0 1179 int cur_evnt = 0;
csahu@8316 1180 Event cur_evnt_kind = Event_illegal;
aoqi@0 1181 int cur_evnt_ind = 0;
aoqi@0 1182 if (_n_recorded_events > 0) {
aoqi@0 1183 cur_evnt_kind = _recorded_events[cur_evnt];
aoqi@0 1184 cur_evnt_ind = _recorded_event_index[cur_evnt];
aoqi@0 1185 }
aoqi@0 1186
aoqi@0 1187 for (int i = 0; i < _n_recorded; i++) {
aoqi@0 1188 while (cur_evnt < _n_recorded_events && i == cur_evnt_ind) {
aoqi@0 1189 gclog_or_tty->print("Event: ");
aoqi@0 1190 print_event(gclog_or_tty, cur_evnt_kind);
aoqi@0 1191 gclog_or_tty->cr();
aoqi@0 1192 cur_evnt++;
aoqi@0 1193 if (cur_evnt < MaxRecordedEvents) {
aoqi@0 1194 cur_evnt_kind = _recorded_events[cur_evnt];
aoqi@0 1195 cur_evnt_ind = _recorded_event_index[cur_evnt];
aoqi@0 1196 }
aoqi@0 1197 }
aoqi@0 1198 gclog_or_tty->print("Added card " PTR_FORMAT " to region [" PTR_FORMAT "...]"
aoqi@0 1199 " for ref " PTR_FORMAT ".\n",
aoqi@0 1200 _recorded_cards[i], _recorded_regions[i]->bottom(),
aoqi@0 1201 _recorded_oops[i]);
aoqi@0 1202 }
aoqi@0 1203 }
aoqi@0 1204
aoqi@0 1205 void HeapRegionRemSet::reset_for_cleanup_tasks() {
aoqi@0 1206 SparsePRT::reset_for_cleanup_tasks();
aoqi@0 1207 }
aoqi@0 1208
aoqi@0 1209 void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
aoqi@0 1210 _other_regions.do_cleanup_work(hrrs_cleanup_task);
aoqi@0 1211 }
aoqi@0 1212
aoqi@0 1213 void
aoqi@0 1214 HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) {
aoqi@0 1215 SparsePRT::finish_cleanup_task(hrrs_cleanup_task);
aoqi@0 1216 }
aoqi@0 1217
aoqi@0 1218 #ifndef PRODUCT
aoqi@0 1219 void PerRegionTable::test_fl_mem_size() {
aoqi@0 1220 PerRegionTable* dummy = alloc(NULL);
tschatzl@6932 1221
tschatzl@6932 1222 size_t min_prt_size = sizeof(void*) + dummy->bm()->size_in_words() * HeapWordSize;
tschatzl@6932 1223 assert(dummy->mem_size() > min_prt_size,
tschatzl@6932 1224 err_msg("PerRegionTable memory usage is suspiciously small, only has "SIZE_FORMAT" bytes. "
tschatzl@6932 1225 "Should be at least "SIZE_FORMAT" bytes.", dummy->mem_size(), min_prt_size));
aoqi@0 1226 free(dummy);
aoqi@0 1227 guarantee(dummy->mem_size() == fl_mem_size(), "fl_mem_size() does not return the correct element size");
aoqi@0 1228 // try to reset the state
aoqi@0 1229 _free_list = NULL;
aoqi@0 1230 delete dummy;
aoqi@0 1231 }
aoqi@0 1232
aoqi@0 1233 void HeapRegionRemSet::test_prt() {
aoqi@0 1234 PerRegionTable::test_fl_mem_size();
aoqi@0 1235 }
aoqi@0 1236
aoqi@0 1237 void HeapRegionRemSet::test() {
aoqi@0 1238 os::sleep(Thread::current(), (jlong)5000, false);
aoqi@0 1239 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 1240
aoqi@0 1241 // Run with "-XX:G1LogRSetRegionEntries=2", so that 1 and 5 end up in same
aoqi@0 1242 // hash bucket.
aoqi@0 1243 HeapRegion* hr0 = g1h->region_at(0);
aoqi@0 1244 HeapRegion* hr1 = g1h->region_at(1);
aoqi@0 1245 HeapRegion* hr2 = g1h->region_at(5);
aoqi@0 1246 HeapRegion* hr3 = g1h->region_at(6);
aoqi@0 1247 HeapRegion* hr4 = g1h->region_at(7);
aoqi@0 1248 HeapRegion* hr5 = g1h->region_at(8);
aoqi@0 1249
aoqi@0 1250 HeapWord* hr1_start = hr1->bottom();
aoqi@0 1251 HeapWord* hr1_mid = hr1_start + HeapRegion::GrainWords/2;
aoqi@0 1252 HeapWord* hr1_last = hr1->end() - 1;
aoqi@0 1253
aoqi@0 1254 HeapWord* hr2_start = hr2->bottom();
aoqi@0 1255 HeapWord* hr2_mid = hr2_start + HeapRegion::GrainWords/2;
aoqi@0 1256 HeapWord* hr2_last = hr2->end() - 1;
aoqi@0 1257
aoqi@0 1258 HeapWord* hr3_start = hr3->bottom();
aoqi@0 1259 HeapWord* hr3_mid = hr3_start + HeapRegion::GrainWords/2;
aoqi@0 1260 HeapWord* hr3_last = hr3->end() - 1;
aoqi@0 1261
aoqi@0 1262 HeapRegionRemSet* hrrs = hr0->rem_set();
aoqi@0 1263
aoqi@0 1264 // Make three references from region 0x101...
aoqi@0 1265 hrrs->add_reference((OopOrNarrowOopStar)hr1_start);
aoqi@0 1266 hrrs->add_reference((OopOrNarrowOopStar)hr1_mid);
aoqi@0 1267 hrrs->add_reference((OopOrNarrowOopStar)hr1_last);
aoqi@0 1268
aoqi@0 1269 hrrs->add_reference((OopOrNarrowOopStar)hr2_start);
aoqi@0 1270 hrrs->add_reference((OopOrNarrowOopStar)hr2_mid);
aoqi@0 1271 hrrs->add_reference((OopOrNarrowOopStar)hr2_last);
aoqi@0 1272
aoqi@0 1273 hrrs->add_reference((OopOrNarrowOopStar)hr3_start);
aoqi@0 1274 hrrs->add_reference((OopOrNarrowOopStar)hr3_mid);
aoqi@0 1275 hrrs->add_reference((OopOrNarrowOopStar)hr3_last);
aoqi@0 1276
aoqi@0 1277 // Now cause a coarsening.
aoqi@0 1278 hrrs->add_reference((OopOrNarrowOopStar)hr4->bottom());
aoqi@0 1279 hrrs->add_reference((OopOrNarrowOopStar)hr5->bottom());
aoqi@0 1280
aoqi@0 1281 // Now, does iteration yield these three?
aoqi@0 1282 HeapRegionRemSetIterator iter(hrrs);
aoqi@0 1283 size_t sum = 0;
aoqi@0 1284 size_t card_index;
aoqi@0 1285 while (iter.has_next(card_index)) {
aoqi@0 1286 HeapWord* card_start =
aoqi@0 1287 G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
aoqi@0 1288 gclog_or_tty->print_cr(" Card " PTR_FORMAT ".", card_start);
aoqi@0 1289 sum++;
aoqi@0 1290 }
aoqi@0 1291 guarantee(sum == 11 - 3 + 2048, "Failure");
aoqi@0 1292 guarantee(sum == hrrs->occupied(), "Failure");
aoqi@0 1293 }
aoqi@0 1294 #endif

mercurial