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

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 8316
626f594dffa6
child 8604
04d83ba48607
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

ysr@777 1 /*
tschatzl@6402 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP
stefank@2314 27
tschatzl@6402 28 #include "gc_implementation/g1/g1CodeCacheRemSet.hpp"
stefank@2314 29 #include "gc_implementation/g1/sparsePRT.hpp"
stefank@2314 30
ysr@777 31 // Remembered set for a heap region. Represent a set of "cards" that
ysr@777 32 // contain pointers into the owner heap region. Cards are defined somewhat
ysr@777 33 // abstractly, in terms of what the "BlockOffsetTable" in use can parse.
ysr@777 34
ysr@777 35 class G1CollectedHeap;
ysr@777 36 class G1BlockOffsetSharedArray;
ysr@777 37 class HeapRegion;
ysr@777 38 class HeapRegionRemSetIterator;
johnc@3891 39 class PerRegionTable;
ysr@777 40 class SparsePRT;
johnc@5548 41 class nmethod;
ysr@777 42
tonyp@2493 43 // Essentially a wrapper around SparsePRTCleanupTask. See
tonyp@2493 44 // sparsePRT.hpp for more details.
tonyp@2493 45 class HRRSCleanupTask : public SparsePRTCleanupTask {
tonyp@2493 46 };
ysr@777 47
tschatzl@6407 48 // The FromCardCache remembers the most recently processed card on the heap on
tschatzl@6407 49 // a per-region and per-thread basis.
tschatzl@6407 50 class FromCardCache : public AllStatic {
tschatzl@6407 51 private:
tschatzl@6407 52 // Array of card indices. Indexed by thread X and heap region to minimize
tschatzl@6407 53 // thread contention.
tschatzl@6407 54 static int** _cache;
tschatzl@6407 55 static uint _max_regions;
tschatzl@6407 56 static size_t _static_mem_size;
tschatzl@6407 57
tschatzl@6407 58 public:
tschatzl@6407 59 enum {
tschatzl@6407 60 InvalidCard = -1 // Card value of an invalid card, i.e. a card index not otherwise used.
tschatzl@6407 61 };
tschatzl@6407 62
tschatzl@6407 63 static void clear(uint region_idx);
tschatzl@6407 64
tschatzl@6407 65 // Returns true if the given card is in the cache at the given location, or
tschatzl@6407 66 // replaces the card at that location and returns false.
tschatzl@6407 67 static bool contains_or_replace(uint worker_id, uint region_idx, int card) {
tschatzl@6407 68 int card_in_cache = at(worker_id, region_idx);
tschatzl@6407 69 if (card_in_cache == card) {
tschatzl@6407 70 return true;
tschatzl@6407 71 } else {
tschatzl@6407 72 set(worker_id, region_idx, card);
tschatzl@6407 73 return false;
tschatzl@6407 74 }
tschatzl@6407 75 }
tschatzl@6407 76
tschatzl@6407 77 static int at(uint worker_id, uint region_idx) {
tschatzl@6407 78 return _cache[worker_id][region_idx];
tschatzl@6407 79 }
tschatzl@6407 80
tschatzl@6407 81 static void set(uint worker_id, uint region_idx, int val) {
tschatzl@6407 82 _cache[worker_id][region_idx] = val;
tschatzl@6407 83 }
tschatzl@6407 84
tschatzl@6407 85 static void initialize(uint n_par_rs, uint max_num_regions);
tschatzl@6407 86
tschatzl@7051 87 static void invalidate(uint start_idx, size_t num_regions);
tschatzl@6407 88
tschatzl@6407 89 static void print(outputStream* out = gclog_or_tty) PRODUCT_RETURN;
tschatzl@6407 90
tschatzl@6407 91 static size_t static_mem_size() {
tschatzl@6407 92 return _static_mem_size;
tschatzl@6407 93 }
tschatzl@6407 94 };
tschatzl@6407 95
ysr@777 96 // The "_coarse_map" is a bitmap with one bit for each region, where set
ysr@777 97 // bits indicate that the corresponding region may contain some pointer
ysr@777 98 // into the owning region.
ysr@777 99
ysr@777 100 // The "_fine_grain_entries" array is an open hash table of PerRegionTables
ysr@777 101 // (PRTs), indicating regions for which we're keeping the RS as a set of
ysr@777 102 // cards. The strategy is to cap the size of the fine-grain table,
ysr@777 103 // deleting an entry and setting the corresponding coarse-grained bit when
ysr@777 104 // we would overflow this cap.
ysr@777 105
ysr@777 106 // We use a mixture of locking and lock-free techniques here. We allow
ysr@777 107 // threads to locate PRTs without locking, but threads attempting to alter
ysr@777 108 // a bucket list obtain a lock. This means that any failing attempt to
ysr@777 109 // find a PRT must be retried with the lock. It might seem dangerous that
ysr@777 110 // a read can find a PRT that is concurrently deleted. This is all right,
ysr@777 111 // because:
ysr@777 112 //
ysr@777 113 // 1) We only actually free PRT's at safe points (though we reuse them at
ysr@777 114 // other times).
ysr@777 115 // 2) We find PRT's in an attempt to add entries. If a PRT is deleted,
ysr@777 116 // it's _coarse_map bit is set, so the that we were attempting to add
ysr@777 117 // is represented. If a deleted PRT is re-used, a thread adding a bit,
ysr@777 118 // thinking the PRT is for a different region, does no harm.
ysr@777 119
apetrusenko@984 120 class OtherRegionsTable VALUE_OBJ_CLASS_SPEC {
ysr@777 121 friend class HeapRegionRemSetIterator;
ysr@777 122
ysr@777 123 G1CollectedHeap* _g1h;
tschatzl@6402 124 Mutex* _m;
ysr@777 125 HeapRegion* _hr;
ysr@777 126
ysr@777 127 // These are protected by "_m".
ysr@777 128 BitMap _coarse_map;
ysr@777 129 size_t _n_coarse_entries;
ysr@777 130 static jint _n_coarsenings;
ysr@777 131
johnc@3891 132 PerRegionTable** _fine_grain_regions;
johnc@3891 133 size_t _n_fine_entries;
ysr@777 134
johnc@3956 135 // The fine grain remembered sets are doubly linked together using
johnc@3956 136 // their 'next' and 'prev' fields.
johnc@3956 137 // This allows fast bulk freeing of all the fine grain remembered
johnc@3956 138 // set entries, and fast finding of all of them without iterating
johnc@3956 139 // over the _fine_grain_regions table.
johnc@3956 140 PerRegionTable * _first_all_fine_prts;
johnc@3956 141 PerRegionTable * _last_all_fine_prts;
johnc@3956 142
johnc@3891 143 // Used to sample a subset of the fine grain PRTs to determine which
johnc@3891 144 // PRT to evict and coarsen.
ysr@777 145 size_t _fine_eviction_start;
ysr@777 146 static size_t _fine_eviction_stride;
ysr@777 147 static size_t _fine_eviction_sample_size;
ysr@777 148
ysr@777 149 SparsePRT _sparse_table;
ysr@777 150
ysr@777 151 // These are static after init.
ysr@777 152 static size_t _max_fine_entries;
ysr@777 153 static size_t _mod_max_fine_entries_mask;
ysr@777 154
ysr@777 155 // Requires "prt" to be the first element of the bucket list appropriate
ysr@777 156 // for "hr". If this list contains an entry for "hr", return it,
ysr@777 157 // otherwise return "NULL".
johnc@3891 158 PerRegionTable* find_region_table(size_t ind, HeapRegion* hr) const;
ysr@777 159
johnc@3891 160 // Find, delete, and return a candidate PerRegionTable, if any exists,
ysr@777 161 // adding the deleted region to the coarse bitmap. Requires the caller
ysr@777 162 // to hold _m, and the fine-grain table to be full.
johnc@3891 163 PerRegionTable* delete_region_table();
ysr@777 164
ysr@777 165 // If a PRT for "hr" is in the bucket list indicated by "ind" (which must
ysr@777 166 // be the correct index for "hr"), delete it and return true; else return
ysr@777 167 // false.
ysr@777 168 bool del_single_region_table(size_t ind, HeapRegion* hr);
ysr@777 169
johnc@3956 170 // link/add the given fine grain remembered set into the "all" list
johnc@3956 171 void link_to_all(PerRegionTable * prt);
johnc@3956 172 // unlink/remove the given fine grain remembered set into the "all" list
johnc@3956 173 void unlink_from_all(PerRegionTable * prt);
johnc@3956 174
ysr@777 175 public:
tschatzl@6402 176 OtherRegionsTable(HeapRegion* hr, Mutex* m);
ysr@777 177
ysr@777 178 HeapRegion* hr() const { return _hr; }
ysr@777 179
ysr@777 180 // For now. Could "expand" some tables in the future, so that this made
ysr@777 181 // sense.
ysr@1280 182 void add_reference(OopOrNarrowOopStar from, int tid);
ysr@777 183
tschatzl@7828 184 // Returns whether this remembered set (and all sub-sets) have an occupancy
tschatzl@7828 185 // that is less or equal than the given occupancy.
tschatzl@7828 186 bool occupancy_less_or_equal_than(size_t limit) const;
tschatzl@7828 187
ysr@777 188 // Removes any entries shown by the given bitmaps to contain only dead
ysr@777 189 // objects.
ysr@777 190 void scrub(CardTableModRefBS* ctbs, BitMap* region_bm, BitMap* card_bm);
ysr@777 191
tschatzl@7010 192 // Returns whether this remembered set (and all sub-sets) contain no entries.
tschatzl@7010 193 bool is_empty() const;
tschatzl@7010 194
ysr@777 195 size_t occupied() const;
ysr@777 196 size_t occ_fine() const;
ysr@777 197 size_t occ_coarse() const;
ysr@777 198 size_t occ_sparse() const;
ysr@777 199
ysr@777 200 static jint n_coarsenings() { return _n_coarsenings; }
ysr@777 201
ysr@777 202 // Returns size in bytes.
ysr@777 203 // Not const because it takes a lock.
ysr@777 204 size_t mem_size() const;
ysr@777 205 static size_t static_mem_size();
ysr@777 206 static size_t fl_mem_size();
ysr@777 207
ysr@1280 208 bool contains_reference(OopOrNarrowOopStar from) const;
ysr@1280 209 bool contains_reference_locked(OopOrNarrowOopStar from) const;
ysr@777 210
ysr@777 211 void clear();
ysr@777 212
ysr@777 213 // Specifically clear the from_card_cache.
ysr@777 214 void clear_fcc();
ysr@777 215
tonyp@2493 216 void do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task);
tonyp@2493 217
ysr@777 218 // Declare the heap size (in # of regions) to the OtherRegionsTable.
ysr@777 219 // (Uses it to initialize from_card_cache).
tschatzl@7051 220 static void initialize(uint max_regions);
ysr@777 221
tschatzl@7051 222 // Declares that regions between start_idx <= i < start_idx + num_regions are
tschatzl@7051 223 // not in use. Make sure that any entries for these regions are invalid.
tschatzl@7051 224 static void invalidate(uint start_idx, size_t num_regions);
ysr@777 225
ysr@777 226 static void print_from_card_cache();
ysr@777 227 };
ysr@777 228
zgu@3900 229 class HeapRegionRemSet : public CHeapObj<mtGC> {
ysr@777 230 friend class VMStructs;
ysr@777 231 friend class HeapRegionRemSetIterator;
ysr@777 232
ysr@777 233 public:
ysr@777 234 enum Event {
csahu@8316 235 Event_EvacStart, Event_EvacEnd, Event_RSUpdateEnd, Event_illegal
ysr@777 236 };
ysr@777 237
ysr@777 238 private:
ysr@777 239 G1BlockOffsetSharedArray* _bosa;
ysr@777 240 G1BlockOffsetSharedArray* bosa() const { return _bosa; }
ysr@777 241
tschatzl@6402 242 // A set of code blobs (nmethods) whose code contains pointers into
johnc@5548 243 // the region that owns this RSet.
tschatzl@6402 244 G1CodeRootSet _code_roots;
tschatzl@6402 245
tschatzl@6402 246 Mutex _m;
johnc@5548 247
ysr@777 248 OtherRegionsTable _other_regions;
ysr@777 249
ysr@777 250 enum ParIterState { Unclaimed, Claimed, Complete };
iveresov@1696 251 volatile ParIterState _iter_state;
iveresov@1696 252 volatile jlong _iter_claimed;
ysr@777 253
ysr@777 254 // Unused unless G1RecordHRRSOops is true.
ysr@777 255
ysr@777 256 static const int MaxRecorded = 1000000;
ysr@1280 257 static OopOrNarrowOopStar* _recorded_oops;
ysr@1280 258 static HeapWord** _recorded_cards;
ysr@1280 259 static HeapRegion** _recorded_regions;
ysr@1280 260 static int _n_recorded;
ysr@777 261
ysr@777 262 static const int MaxRecordedEvents = 1000;
ysr@777 263 static Event* _recorded_events;
ysr@777 264 static int* _recorded_event_index;
ysr@777 265 static int _n_recorded_events;
ysr@777 266
ysr@777 267 static void print_event(outputStream* str, Event evnt);
ysr@777 268
ysr@777 269 public:
tschatzl@6402 270 HeapRegionRemSet(G1BlockOffsetSharedArray* bosa, HeapRegion* hr);
ysr@777 271
tschatzl@6403 272 static uint num_par_rem_sets();
iveresov@1696 273 static void setup_remset_size();
ysr@777 274
ysr@777 275 HeapRegion* hr() const {
ysr@777 276 return _other_regions.hr();
ysr@777 277 }
ysr@777 278
tschatzl@7010 279 bool is_empty() const {
tschatzl@7010 280 return (strong_code_roots_list_length() == 0) && _other_regions.is_empty();
tschatzl@7010 281 }
tschatzl@7010 282
tschatzl@7828 283 bool occupancy_less_or_equal_than(size_t occ) const {
tschatzl@7828 284 return (strong_code_roots_list_length() == 0) && _other_regions.occupancy_less_or_equal_than(occ);
tschatzl@7828 285 }
tschatzl@7828 286
tschatzl@6402 287 size_t occupied() {
tschatzl@6402 288 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
tschatzl@6402 289 return occupied_locked();
tschatzl@6402 290 }
tschatzl@6402 291 size_t occupied_locked() {
ysr@777 292 return _other_regions.occupied();
ysr@777 293 }
ysr@777 294 size_t occ_fine() const {
ysr@777 295 return _other_regions.occ_fine();
ysr@777 296 }
ysr@777 297 size_t occ_coarse() const {
ysr@777 298 return _other_regions.occ_coarse();
ysr@777 299 }
ysr@777 300 size_t occ_sparse() const {
ysr@777 301 return _other_regions.occ_sparse();
ysr@777 302 }
ysr@777 303
ysr@777 304 static jint n_coarsenings() { return OtherRegionsTable::n_coarsenings(); }
ysr@777 305
johnc@3891 306 // Used in the sequential case.
ysr@1280 307 void add_reference(OopOrNarrowOopStar from) {
johnc@3891 308 _other_regions.add_reference(from, 0);
ysr@777 309 }
ysr@777 310
johnc@3891 311 // Used in the parallel case.
ysr@1280 312 void add_reference(OopOrNarrowOopStar from, int tid) {
ysr@777 313 _other_regions.add_reference(from, tid);
ysr@777 314 }
ysr@777 315
ysr@777 316 // Removes any entries shown by the given bitmaps to contain only dead
ysr@777 317 // objects.
ysr@777 318 void scrub(CardTableModRefBS* ctbs, BitMap* region_bm, BitMap* card_bm);
ysr@777 319
ysr@777 320 // The region is being reclaimed; clear its remset, and any mention of
ysr@777 321 // entries for this region in other remsets.
ysr@777 322 void clear();
tschatzl@6402 323 void clear_locked();
ysr@777 324
ysr@777 325 // Attempt to claim the region. Returns true iff this call caused an
ysr@777 326 // atomic transition from Unclaimed to Claimed.
ysr@777 327 bool claim_iter();
ysr@777 328 // Sets the iteration state to "complete".
ysr@777 329 void set_iter_complete();
ysr@777 330 // Returns "true" iff the region's iteration is complete.
ysr@777 331 bool iter_is_complete();
ysr@777 332
iveresov@1696 333 // Support for claiming blocks of cards during iteration
iveresov@1696 334 size_t iter_claimed() const { return (size_t)_iter_claimed; }
iveresov@1696 335 // Claim the next block of cards
iveresov@1696 336 size_t iter_claimed_next(size_t step) {
iveresov@1696 337 size_t current, next;
iveresov@1696 338 do {
iveresov@1696 339 current = iter_claimed();
iveresov@1696 340 next = current + step;
iveresov@1696 341 } while (Atomic::cmpxchg((jlong)next, &_iter_claimed, (jlong)current) != (jlong)current);
iveresov@1696 342 return current;
iveresov@1696 343 }
tonyp@2974 344 void reset_for_par_iteration();
tonyp@2974 345
tonyp@2974 346 bool verify_ready_for_par_iteration() {
tonyp@2974 347 return (_iter_state == Unclaimed) && (_iter_claimed == 0);
tonyp@2974 348 }
iveresov@1696 349
ysr@777 350 // The actual # of bytes this hr_remset takes up.
johnc@5548 351 // Note also includes the strong code root set.
ysr@777 352 size_t mem_size() {
tschatzl@6402 353 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
ysr@777 354 return _other_regions.mem_size()
ysr@777 355 // This correction is necessary because the above includes the second
ysr@777 356 // part.
tschatzl@6932 357 + (sizeof(HeapRegionRemSet) - sizeof(OtherRegionsTable))
johnc@5548 358 + strong_code_roots_mem_size();
ysr@777 359 }
ysr@777 360
ysr@777 361 // Returns the memory occupancy of all static data structures associated
ysr@777 362 // with remembered sets.
ysr@777 363 static size_t static_mem_size() {
mgerdin@7208 364 return OtherRegionsTable::static_mem_size() + G1CodeRootSet::static_mem_size();
ysr@777 365 }
ysr@777 366
ysr@777 367 // Returns the memory occupancy of all free_list data structures associated
ysr@777 368 // with remembered sets.
ysr@777 369 static size_t fl_mem_size() {
mgerdin@7208 370 return OtherRegionsTable::fl_mem_size();
ysr@777 371 }
ysr@777 372
ysr@1280 373 bool contains_reference(OopOrNarrowOopStar from) const {
ysr@777 374 return _other_regions.contains_reference(from);
ysr@777 375 }
johnc@5548 376
johnc@5548 377 // Routines for managing the list of code roots that point into
johnc@5548 378 // the heap region that owns this RSet.
johnc@5548 379 void add_strong_code_root(nmethod* nm);
mgerdin@7208 380 void add_strong_code_root_locked(nmethod* nm);
johnc@5548 381 void remove_strong_code_root(nmethod* nm);
johnc@5548 382
johnc@5548 383 // Applies blk->do_code_blob() to each of the entries in
johnc@5548 384 // the strong code roots list
johnc@5548 385 void strong_code_roots_do(CodeBlobClosure* blk) const;
johnc@5548 386
mgerdin@7208 387 void clean_strong_code_roots(HeapRegion* hr);
mgerdin@7208 388
johnc@5548 389 // Returns the number of elements in the strong code roots list
tschatzl@7010 390 size_t strong_code_roots_list_length() const {
tschatzl@6402 391 return _code_roots.length();
johnc@5548 392 }
johnc@5548 393
johnc@5548 394 // Returns true if the strong code roots contains the given
johnc@5548 395 // nmethod.
johnc@5548 396 bool strong_code_roots_list_contains(nmethod* nm) {
tschatzl@6402 397 return _code_roots.contains(nm);
johnc@5548 398 }
johnc@5548 399
johnc@5548 400 // Returns the amount of memory, in bytes, currently
johnc@5548 401 // consumed by the strong code roots.
johnc@5548 402 size_t strong_code_roots_mem_size();
johnc@5548 403
tschatzl@6402 404 void print() PRODUCT_RETURN;
ysr@777 405
ysr@777 406 // Called during a stop-world phase to perform any deferred cleanups.
ysr@777 407 static void cleanup();
ysr@777 408
ysr@777 409 // Declare the heap size (in # of regions) to the HeapRegionRemSet(s).
ysr@777 410 // (Uses it to initialize from_card_cache).
tonyp@3713 411 static void init_heap(uint max_regions) {
tschatzl@7051 412 OtherRegionsTable::initialize(max_regions);
ysr@777 413 }
ysr@777 414
tschatzl@7051 415 static void invalidate(uint start_idx, uint num_regions) {
tschatzl@7051 416 OtherRegionsTable::invalidate(start_idx, num_regions);
ysr@777 417 }
ysr@777 418
ysr@777 419 #ifndef PRODUCT
ysr@777 420 static void print_from_card_cache() {
ysr@777 421 OtherRegionsTable::print_from_card_cache();
ysr@777 422 }
ysr@777 423 #endif
ysr@777 424
ysr@1280 425 static void record(HeapRegion* hr, OopOrNarrowOopStar f);
ysr@777 426 static void print_recorded();
ysr@777 427 static void record_event(Event evnt);
ysr@777 428
tonyp@2493 429 // These are wrappers for the similarly-named methods on
tonyp@2493 430 // SparsePRT. Look at sparsePRT.hpp for more details.
tonyp@2493 431 static void reset_for_cleanup_tasks();
tonyp@2493 432 void do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task);
tonyp@2493 433 static void finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task);
tonyp@2493 434
ysr@777 435 // Run unit tests.
ysr@777 436 #ifndef PRODUCT
tschatzl@5165 437 static void test_prt();
ysr@777 438 static void test();
ysr@777 439 #endif
ysr@777 440 };
ysr@777 441
johnc@5014 442 class HeapRegionRemSetIterator : public StackObj {
tschatzl@6927 443 private:
tschatzl@6927 444 // The region RSet over which we are iterating.
tschatzl@6402 445 HeapRegionRemSet* _hrrs;
ysr@777 446
ysr@777 447 // Local caching of HRRS fields.
ysr@777 448 const BitMap* _coarse_map;
ysr@777 449
ysr@777 450 G1BlockOffsetSharedArray* _bosa;
ysr@777 451 G1CollectedHeap* _g1h;
ysr@777 452
tschatzl@6927 453 // The number of cards yielded since initialization.
ysr@777 454 size_t _n_yielded_fine;
ysr@777 455 size_t _n_yielded_coarse;
ysr@777 456 size_t _n_yielded_sparse;
ysr@777 457
tschatzl@6927 458 // Indicates what granularity of table that we are currently iterating over.
johnc@5014 459 // We start iterating over the sparse table, progress to the fine grain
johnc@5014 460 // table, and then finish with the coarse table.
ysr@777 461 enum IterState {
ysr@777 462 Sparse,
ysr@777 463 Fine,
ysr@777 464 Coarse
ysr@777 465 };
ysr@777 466 IterState _is;
ysr@777 467
tschatzl@6927 468 // For both Coarse and Fine remembered set iteration this contains the
tschatzl@6927 469 // first card number of the heap region we currently iterate over.
ysr@777 470 size_t _cur_region_card_offset;
ysr@777 471
tschatzl@6927 472 // Current region index for the Coarse remembered set iteration.
johnc@3182 473 int _coarse_cur_region_index;
johnc@3182 474 size_t _coarse_cur_region_cur_card;
ysr@777 475
ysr@777 476 bool coarse_has_next(size_t& card_index);
ysr@777 477
tschatzl@6927 478 // The PRT we are currently iterating over.
tschatzl@6927 479 PerRegionTable* _fine_cur_prt;
tschatzl@6927 480 // Card offset within the current PRT.
tschatzl@6927 481 size_t _cur_card_in_prt;
ysr@777 482
tschatzl@6927 483 // Update internal variables when switching to the given PRT.
tschatzl@6927 484 void switch_to_prt(PerRegionTable* prt);
ysr@777 485 bool fine_has_next();
ysr@777 486 bool fine_has_next(size_t& card_index);
ysr@777 487
tschatzl@6927 488 // The Sparse remembered set iterator.
tschatzl@6927 489 SparsePRTIter _sparse_iter;
tschatzl@6927 490
tschatzl@6927 491 public:
tschatzl@6402 492 HeapRegionRemSetIterator(HeapRegionRemSet* hrrs);
ysr@777 493
ysr@777 494 // If there remains one or more cards to be yielded, returns true and
ysr@777 495 // sets "card_index" to one of those cards (which is then considered
ysr@777 496 // yielded.) Otherwise, returns false (and leaves "card_index"
ysr@777 497 // undefined.)
ysr@777 498 bool has_next(size_t& card_index);
ysr@777 499
ysr@777 500 size_t n_yielded_fine() { return _n_yielded_fine; }
ysr@777 501 size_t n_yielded_coarse() { return _n_yielded_coarse; }
ysr@777 502 size_t n_yielded_sparse() { return _n_yielded_sparse; }
ysr@777 503 size_t n_yielded() {
ysr@777 504 return n_yielded_fine() + n_yielded_coarse() + n_yielded_sparse();
ysr@777 505 }
ysr@777 506 };
ysr@777 507
stefank@2314 508 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP

mercurial