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