annotate src/share/vm/gc_implementation/g1/heapRegionRemSet.hpp @ 3456:7994a5a35fcf

6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets Summary: Remove the per-thread expansion tables (PosParPRT) and associated expansion and compaction from the fine grain RSet entries. This code has been unused for a while. Reviewed-by: johnc, brutisso Contributed-by: Thomas Schatzl <thomas.schatzl@jku.at>
author johnc
date Mon, 25 Jun 2012 16:00:55 -0700
parents 720b6a76dd9d
children 24b9c7f4cae6
rev   line source
ysr@342 1 /*
johnc@3456 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
ysr@342 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@342 4 *
ysr@342 5 * This code is free software; you can redistribute it and/or modify it
ysr@342 6 * under the terms of the GNU General Public License version 2 only, as
ysr@342 7 * published by the Free Software Foundation.
ysr@342 8 *
ysr@342 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@342 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@342 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@342 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@342 13 * accompanied this code).
ysr@342 14 *
ysr@342 15 * You should have received a copy of the GNU General Public License version
ysr@342 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@342 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@342 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
ysr@342 22 *
ysr@342 23 */
ysr@342 24
stefank@1879 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP
stefank@1879 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP
stefank@1879 27
stefank@1879 28 #include "gc_implementation/g1/sparsePRT.hpp"
stefank@1879 29
ysr@342 30 // Remembered set for a heap region. Represent a set of "cards" that
ysr@342 31 // contain pointers into the owner heap region. Cards are defined somewhat
ysr@342 32 // abstractly, in terms of what the "BlockOffsetTable" in use can parse.
ysr@342 33
ysr@342 34 class G1CollectedHeap;
ysr@342 35 class G1BlockOffsetSharedArray;
ysr@342 36 class HeapRegion;
ysr@342 37 class HeapRegionRemSetIterator;
johnc@3456 38 class PerRegionTable;
ysr@342 39 class SparsePRT;
ysr@342 40
tonyp@2058 41 // Essentially a wrapper around SparsePRTCleanupTask. See
tonyp@2058 42 // sparsePRT.hpp for more details.
tonyp@2058 43 class HRRSCleanupTask : public SparsePRTCleanupTask {
tonyp@2058 44 };
ysr@342 45
ysr@342 46 // The "_coarse_map" is a bitmap with one bit for each region, where set
ysr@342 47 // bits indicate that the corresponding region may contain some pointer
ysr@342 48 // into the owning region.
ysr@342 49
ysr@342 50 // The "_fine_grain_entries" array is an open hash table of PerRegionTables
ysr@342 51 // (PRTs), indicating regions for which we're keeping the RS as a set of
ysr@342 52 // cards. The strategy is to cap the size of the fine-grain table,
ysr@342 53 // deleting an entry and setting the corresponding coarse-grained bit when
ysr@342 54 // we would overflow this cap.
ysr@342 55
ysr@342 56 // We use a mixture of locking and lock-free techniques here. We allow
ysr@342 57 // threads to locate PRTs without locking, but threads attempting to alter
ysr@342 58 // a bucket list obtain a lock. This means that any failing attempt to
ysr@342 59 // find a PRT must be retried with the lock. It might seem dangerous that
ysr@342 60 // a read can find a PRT that is concurrently deleted. This is all right,
ysr@342 61 // because:
ysr@342 62 //
ysr@342 63 // 1) We only actually free PRT's at safe points (though we reuse them at
ysr@342 64 // other times).
ysr@342 65 // 2) We find PRT's in an attempt to add entries. If a PRT is deleted,
ysr@342 66 // it's _coarse_map bit is set, so the that we were attempting to add
ysr@342 67 // is represented. If a deleted PRT is re-used, a thread adding a bit,
ysr@342 68 // thinking the PRT is for a different region, does no harm.
ysr@342 69
apetrusenko@549 70 class OtherRegionsTable VALUE_OBJ_CLASS_SPEC {
ysr@342 71 friend class HeapRegionRemSetIterator;
ysr@342 72
ysr@342 73 G1CollectedHeap* _g1h;
ysr@342 74 Mutex _m;
ysr@342 75 HeapRegion* _hr;
ysr@342 76
ysr@342 77 // These are protected by "_m".
ysr@342 78 BitMap _coarse_map;
ysr@342 79 size_t _n_coarse_entries;
ysr@342 80 static jint _n_coarsenings;
ysr@342 81
johnc@3456 82 PerRegionTable** _fine_grain_regions;
johnc@3456 83 size_t _n_fine_entries;
ysr@342 84
johnc@3456 85 // Used to sample a subset of the fine grain PRTs to determine which
johnc@3456 86 // PRT to evict and coarsen.
ysr@342 87 size_t _fine_eviction_start;
ysr@342 88 static size_t _fine_eviction_stride;
ysr@342 89 static size_t _fine_eviction_sample_size;
ysr@342 90
ysr@342 91 SparsePRT _sparse_table;
ysr@342 92
ysr@342 93 // These are static after init.
ysr@342 94 static size_t _max_fine_entries;
ysr@342 95 static size_t _mod_max_fine_entries_mask;
ysr@342 96
ysr@342 97 // Requires "prt" to be the first element of the bucket list appropriate
ysr@342 98 // for "hr". If this list contains an entry for "hr", return it,
ysr@342 99 // otherwise return "NULL".
johnc@3456 100 PerRegionTable* find_region_table(size_t ind, HeapRegion* hr) const;
ysr@342 101
johnc@3456 102 // Find, delete, and return a candidate PerRegionTable, if any exists,
ysr@342 103 // adding the deleted region to the coarse bitmap. Requires the caller
ysr@342 104 // to hold _m, and the fine-grain table to be full.
johnc@3456 105 PerRegionTable* delete_region_table();
ysr@342 106
ysr@342 107 // If a PRT for "hr" is in the bucket list indicated by "ind" (which must
ysr@342 108 // be the correct index for "hr"), delete it and return true; else return
ysr@342 109 // false.
ysr@342 110 bool del_single_region_table(size_t ind, HeapRegion* hr);
ysr@342 111
ysr@342 112 // Indexed by thread X heap region, to minimize thread contention.
ysr@342 113 static int** _from_card_cache;
ysr@342 114 static size_t _from_card_cache_max_regions;
ysr@342 115 static size_t _from_card_cache_mem_size;
ysr@342 116
ysr@342 117 public:
ysr@342 118 OtherRegionsTable(HeapRegion* hr);
ysr@342 119
ysr@342 120 HeapRegion* hr() const { return _hr; }
ysr@342 121
ysr@342 122 // For now. Could "expand" some tables in the future, so that this made
ysr@342 123 // sense.
ysr@845 124 void add_reference(OopOrNarrowOopStar from, int tid);
ysr@342 125
ysr@342 126 // Removes any entries shown by the given bitmaps to contain only dead
ysr@342 127 // objects.
ysr@342 128 void scrub(CardTableModRefBS* ctbs, BitMap* region_bm, BitMap* card_bm);
ysr@342 129
ysr@342 130 // Not const because it takes a lock.
ysr@342 131 size_t occupied() const;
ysr@342 132 size_t occ_fine() const;
ysr@342 133 size_t occ_coarse() const;
ysr@342 134 size_t occ_sparse() const;
ysr@342 135
ysr@342 136 static jint n_coarsenings() { return _n_coarsenings; }
ysr@342 137
ysr@342 138 // Returns size in bytes.
ysr@342 139 // Not const because it takes a lock.
ysr@342 140 size_t mem_size() const;
ysr@342 141 static size_t static_mem_size();
ysr@342 142 static size_t fl_mem_size();
ysr@342 143
ysr@845 144 bool contains_reference(OopOrNarrowOopStar from) const;
ysr@845 145 bool contains_reference_locked(OopOrNarrowOopStar from) const;
ysr@342 146
ysr@342 147 void clear();
ysr@342 148
ysr@342 149 // Specifically clear the from_card_cache.
ysr@342 150 void clear_fcc();
ysr@342 151
ysr@342 152 // "from_hr" is being cleared; remove any entries from it.
ysr@342 153 void clear_incoming_entry(HeapRegion* from_hr);
ysr@342 154
tonyp@2058 155 void do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task);
tonyp@2058 156
ysr@342 157 // Declare the heap size (in # of regions) to the OtherRegionsTable.
ysr@342 158 // (Uses it to initialize from_card_cache).
ysr@342 159 static void init_from_card_cache(size_t max_regions);
ysr@342 160
ysr@342 161 // Declares that only regions i s.t. 0 <= i < new_n_regs are in use.
ysr@342 162 // Make sure any entries for higher regions are invalid.
ysr@342 163 static void shrink_from_card_cache(size_t new_n_regs);
ysr@342 164
ysr@342 165 static void print_from_card_cache();
ysr@342 166 };
ysr@342 167
ysr@342 168 class HeapRegionRemSet : public CHeapObj {
ysr@342 169 friend class VMStructs;
ysr@342 170 friend class HeapRegionRemSetIterator;
ysr@342 171
ysr@342 172 public:
ysr@342 173 enum Event {
ysr@342 174 Event_EvacStart, Event_EvacEnd, Event_RSUpdateEnd
ysr@342 175 };
ysr@342 176
ysr@342 177 private:
ysr@342 178 G1BlockOffsetSharedArray* _bosa;
ysr@342 179 G1BlockOffsetSharedArray* bosa() const { return _bosa; }
ysr@342 180
ysr@342 181 OtherRegionsTable _other_regions;
ysr@342 182
ysr@342 183 enum ParIterState { Unclaimed, Claimed, Complete };
iveresov@1261 184 volatile ParIterState _iter_state;
iveresov@1261 185 volatile jlong _iter_claimed;
ysr@342 186
ysr@342 187 // Unused unless G1RecordHRRSOops is true.
ysr@342 188
ysr@342 189 static const int MaxRecorded = 1000000;
ysr@845 190 static OopOrNarrowOopStar* _recorded_oops;
ysr@845 191 static HeapWord** _recorded_cards;
ysr@845 192 static HeapRegion** _recorded_regions;
ysr@845 193 static int _n_recorded;
ysr@342 194
ysr@342 195 static const int MaxRecordedEvents = 1000;
ysr@342 196 static Event* _recorded_events;
ysr@342 197 static int* _recorded_event_index;
ysr@342 198 static int _n_recorded_events;
ysr@342 199
ysr@342 200 static void print_event(outputStream* str, Event evnt);
ysr@342 201
ysr@342 202 public:
ysr@342 203 HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
ysr@342 204 HeapRegion* hr);
ysr@342 205
ysr@342 206 static int num_par_rem_sets();
iveresov@1261 207 static void setup_remset_size();
ysr@342 208
ysr@342 209 HeapRegion* hr() const {
ysr@342 210 return _other_regions.hr();
ysr@342 211 }
ysr@342 212
ysr@342 213 size_t occupied() const {
ysr@342 214 return _other_regions.occupied();
ysr@342 215 }
ysr@342 216 size_t occ_fine() const {
ysr@342 217 return _other_regions.occ_fine();
ysr@342 218 }
ysr@342 219 size_t occ_coarse() const {
ysr@342 220 return _other_regions.occ_coarse();
ysr@342 221 }
ysr@342 222 size_t occ_sparse() const {
ysr@342 223 return _other_regions.occ_sparse();
ysr@342 224 }
ysr@342 225
ysr@342 226 static jint n_coarsenings() { return OtherRegionsTable::n_coarsenings(); }
ysr@342 227
johnc@3456 228 // Used in the sequential case.
ysr@845 229 void add_reference(OopOrNarrowOopStar from) {
johnc@3456 230 _other_regions.add_reference(from, 0);
ysr@342 231 }
ysr@342 232
johnc@3456 233 // Used in the parallel case.
ysr@845 234 void add_reference(OopOrNarrowOopStar from, int tid) {
ysr@342 235 _other_regions.add_reference(from, tid);
ysr@342 236 }
ysr@342 237
ysr@342 238 // Removes any entries shown by the given bitmaps to contain only dead
ysr@342 239 // objects.
ysr@342 240 void scrub(CardTableModRefBS* ctbs, BitMap* region_bm, BitMap* card_bm);
ysr@342 241
ysr@342 242 // The region is being reclaimed; clear its remset, and any mention of
ysr@342 243 // entries for this region in other remsets.
ysr@342 244 void clear();
ysr@342 245
ysr@342 246 // Attempt to claim the region. Returns true iff this call caused an
ysr@342 247 // atomic transition from Unclaimed to Claimed.
ysr@342 248 bool claim_iter();
ysr@342 249 // Sets the iteration state to "complete".
ysr@342 250 void set_iter_complete();
ysr@342 251 // Returns "true" iff the region's iteration is complete.
ysr@342 252 bool iter_is_complete();
ysr@342 253
iveresov@1261 254 // Support for claiming blocks of cards during iteration
iveresov@1261 255 size_t iter_claimed() const { return (size_t)_iter_claimed; }
iveresov@1261 256 // Claim the next block of cards
iveresov@1261 257 size_t iter_claimed_next(size_t step) {
iveresov@1261 258 size_t current, next;
iveresov@1261 259 do {
iveresov@1261 260 current = iter_claimed();
iveresov@1261 261 next = current + step;
iveresov@1261 262 } while (Atomic::cmpxchg((jlong)next, &_iter_claimed, (jlong)current) != (jlong)current);
iveresov@1261 263 return current;
iveresov@1261 264 }
tonyp@2539 265 void reset_for_par_iteration();
tonyp@2539 266
tonyp@2539 267 bool verify_ready_for_par_iteration() {
tonyp@2539 268 return (_iter_state == Unclaimed) && (_iter_claimed == 0);
tonyp@2539 269 }
iveresov@1261 270
ysr@342 271 // Initialize the given iterator to iterate over this rem set.
ysr@342 272 void init_iterator(HeapRegionRemSetIterator* iter) const;
ysr@342 273
ysr@342 274 // The actual # of bytes this hr_remset takes up.
ysr@342 275 size_t mem_size() {
ysr@342 276 return _other_regions.mem_size()
ysr@342 277 // This correction is necessary because the above includes the second
ysr@342 278 // part.
ysr@342 279 + sizeof(this) - sizeof(OtherRegionsTable);
ysr@342 280 }
ysr@342 281
ysr@342 282 // Returns the memory occupancy of all static data structures associated
ysr@342 283 // with remembered sets.
ysr@342 284 static size_t static_mem_size() {
ysr@342 285 return OtherRegionsTable::static_mem_size();
ysr@342 286 }
ysr@342 287
ysr@342 288 // Returns the memory occupancy of all free_list data structures associated
ysr@342 289 // with remembered sets.
ysr@342 290 static size_t fl_mem_size() {
ysr@342 291 return OtherRegionsTable::fl_mem_size();
ysr@342 292 }
ysr@342 293
ysr@845 294 bool contains_reference(OopOrNarrowOopStar from) const {
ysr@342 295 return _other_regions.contains_reference(from);
ysr@342 296 }
ysr@342 297 void print() const;
ysr@342 298
ysr@342 299 // Called during a stop-world phase to perform any deferred cleanups.
ysr@342 300 static void cleanup();
ysr@342 301
ysr@342 302 // Declare the heap size (in # of regions) to the HeapRegionRemSet(s).
ysr@342 303 // (Uses it to initialize from_card_cache).
tonyp@3278 304 static void init_heap(uint max_regions) {
tonyp@3278 305 OtherRegionsTable::init_from_card_cache((size_t) max_regions);
ysr@342 306 }
ysr@342 307
ysr@342 308 // Declares that only regions i s.t. 0 <= i < new_n_regs are in use.
tonyp@3278 309 static void shrink_heap(uint new_n_regs) {
tonyp@3278 310 OtherRegionsTable::shrink_from_card_cache((size_t) new_n_regs);
ysr@342 311 }
ysr@342 312
ysr@342 313 #ifndef PRODUCT
ysr@342 314 static void print_from_card_cache() {
ysr@342 315 OtherRegionsTable::print_from_card_cache();
ysr@342 316 }
ysr@342 317 #endif
ysr@342 318
ysr@845 319 static void record(HeapRegion* hr, OopOrNarrowOopStar f);
ysr@342 320 static void print_recorded();
ysr@342 321 static void record_event(Event evnt);
ysr@342 322
tonyp@2058 323 // These are wrappers for the similarly-named methods on
tonyp@2058 324 // SparsePRT. Look at sparsePRT.hpp for more details.
tonyp@2058 325 static void reset_for_cleanup_tasks();
tonyp@2058 326 void do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task);
tonyp@2058 327 static void finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task);
tonyp@2058 328
ysr@342 329 // Run unit tests.
ysr@342 330 #ifndef PRODUCT
ysr@342 331 static void test();
ysr@342 332 #endif
ysr@342 333 };
ysr@342 334
ysr@342 335 class HeapRegionRemSetIterator : public CHeapObj {
ysr@342 336
ysr@342 337 // The region over which we're iterating.
ysr@342 338 const HeapRegionRemSet* _hrrs;
ysr@342 339
ysr@342 340 // Local caching of HRRS fields.
ysr@342 341 const BitMap* _coarse_map;
johnc@3456 342 PerRegionTable** _fine_grain_regions;
ysr@342 343
ysr@342 344 G1BlockOffsetSharedArray* _bosa;
ysr@342 345 G1CollectedHeap* _g1h;
ysr@342 346
ysr@342 347 // The number yielded since initialization.
ysr@342 348 size_t _n_yielded_fine;
ysr@342 349 size_t _n_yielded_coarse;
ysr@342 350 size_t _n_yielded_sparse;
ysr@342 351
ysr@342 352 // If true we're iterating over the coarse table; if false the fine
ysr@342 353 // table.
ysr@342 354 enum IterState {
ysr@342 355 Sparse,
ysr@342 356 Fine,
ysr@342 357 Coarse
ysr@342 358 };
ysr@342 359 IterState _is;
ysr@342 360
ysr@342 361 // In both kinds of iteration, heap offset of first card of current
ysr@342 362 // region.
ysr@342 363 size_t _cur_region_card_offset;
ysr@342 364 // Card offset within cur region.
ysr@342 365 size_t _cur_region_cur_card;
ysr@342 366
ysr@342 367 // Coarse table iteration fields:
ysr@342 368
ysr@342 369 // Current region index;
johnc@2747 370 int _coarse_cur_region_index;
johnc@2747 371 size_t _coarse_cur_region_cur_card;
ysr@342 372
ysr@342 373 bool coarse_has_next(size_t& card_index);
ysr@342 374
ysr@342 375 // Fine table iteration fields:
ysr@342 376
ysr@342 377 // Index of bucket-list we're working on.
ysr@342 378 int _fine_array_index;
johnc@3456 379
ysr@342 380 // Per Region Table we're doing within current bucket list.
johnc@3456 381 PerRegionTable* _fine_cur_prt;
ysr@342 382
ysr@342 383 /* SparsePRT::*/ SparsePRTIter _sparse_iter;
ysr@342 384
ysr@342 385 void fine_find_next_non_null_prt();
ysr@342 386
ysr@342 387 bool fine_has_next();
ysr@342 388 bool fine_has_next(size_t& card_index);
ysr@342 389
ysr@342 390 public:
ysr@342 391 // We require an iterator to be initialized before use, so the
ysr@342 392 // constructor does little.
ysr@342 393 HeapRegionRemSetIterator();
ysr@342 394
ysr@342 395 void initialize(const HeapRegionRemSet* hrrs);
ysr@342 396
ysr@342 397 // If there remains one or more cards to be yielded, returns true and
ysr@342 398 // sets "card_index" to one of those cards (which is then considered
ysr@342 399 // yielded.) Otherwise, returns false (and leaves "card_index"
ysr@342 400 // undefined.)
ysr@342 401 bool has_next(size_t& card_index);
ysr@342 402
ysr@342 403 size_t n_yielded_fine() { return _n_yielded_fine; }
ysr@342 404 size_t n_yielded_coarse() { return _n_yielded_coarse; }
ysr@342 405 size_t n_yielded_sparse() { return _n_yielded_sparse; }
ysr@342 406 size_t n_yielded() {
ysr@342 407 return n_yielded_fine() + n_yielded_coarse() + n_yielded_sparse();
ysr@342 408 }
ysr@342 409 };
ysr@342 410
stefank@1879 411 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP