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

Fri, 16 Jan 2009 13:02:20 -0500

author
tonyp
date
Fri, 16 Jan 2009 13:02:20 -0500
changeset 961
818efdefcc99
parent 954
65de26b5ea82
child 980
58054a18d735
permissions
-rw-r--r--

6484956: G1: improve evacuation pause efficiency
Summary: A bunch of performance optimizations to decrease GC pause times in G1.
Reviewed-by: apetrusenko, jmasa, iveresov

ysr@777 1 /*
xdono@905 2 * Copyright 2001-2008 Sun Microsystems, Inc. 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 *
ysr@777 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@777 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@777 21 * have any questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 // A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
ysr@777 26 // It uses the "Garbage First" heap organization and algorithm, which
ysr@777 27 // may combine concurrent marking with parallel, incremental compaction of
ysr@777 28 // heap subsets that will yield large amounts of garbage.
ysr@777 29
ysr@777 30 class HeapRegion;
ysr@777 31 class HeapRegionSeq;
ysr@777 32 class HeapRegionList;
ysr@777 33 class PermanentGenerationSpec;
ysr@777 34 class GenerationSpec;
ysr@777 35 class OopsInHeapRegionClosure;
ysr@777 36 class G1ScanHeapEvacClosure;
ysr@777 37 class ObjectClosure;
ysr@777 38 class SpaceClosure;
ysr@777 39 class CompactibleSpaceClosure;
ysr@777 40 class Space;
ysr@777 41 class G1CollectorPolicy;
ysr@777 42 class GenRemSet;
ysr@777 43 class G1RemSet;
ysr@777 44 class HeapRegionRemSetIterator;
ysr@777 45 class ConcurrentMark;
ysr@777 46 class ConcurrentMarkThread;
ysr@777 47 class ConcurrentG1Refine;
ysr@777 48 class ConcurrentZFThread;
ysr@777 49
ysr@777 50 // If want to accumulate detailed statistics on work queues
ysr@777 51 // turn this on.
ysr@777 52 #define G1_DETAILED_STATS 0
ysr@777 53
ysr@777 54 #if G1_DETAILED_STATS
ysr@777 55 # define IF_G1_DETAILED_STATS(code) code
ysr@777 56 #else
ysr@777 57 # define IF_G1_DETAILED_STATS(code)
ysr@777 58 #endif
ysr@777 59
ysr@777 60 typedef GenericTaskQueue<oop*> RefToScanQueue;
ysr@777 61 typedef GenericTaskQueueSet<oop*> RefToScanQueueSet;
ysr@777 62
ysr@777 63 enum G1GCThreadGroups {
ysr@777 64 G1CRGroup = 0,
ysr@777 65 G1ZFGroup = 1,
ysr@777 66 G1CMGroup = 2,
ysr@777 67 G1CLGroup = 3
ysr@777 68 };
ysr@777 69
ysr@777 70 enum GCAllocPurpose {
ysr@777 71 GCAllocForTenured,
ysr@777 72 GCAllocForSurvived,
ysr@777 73 GCAllocPurposeCount
ysr@777 74 };
ysr@777 75
ysr@777 76 class YoungList : public CHeapObj {
ysr@777 77 private:
ysr@777 78 G1CollectedHeap* _g1h;
ysr@777 79
ysr@777 80 HeapRegion* _head;
ysr@777 81
ysr@777 82 HeapRegion* _scan_only_head;
ysr@777 83 HeapRegion* _scan_only_tail;
ysr@777 84 size_t _length;
ysr@777 85 size_t _scan_only_length;
ysr@777 86
ysr@777 87 size_t _last_sampled_rs_lengths;
ysr@777 88 size_t _sampled_rs_lengths;
ysr@777 89 HeapRegion* _curr;
ysr@777 90 HeapRegion* _curr_scan_only;
ysr@777 91
ysr@777 92 HeapRegion* _survivor_head;
ysr@777 93 HeapRegion* _survivors_tail;
ysr@777 94 size_t _survivor_length;
ysr@777 95
ysr@777 96 void empty_list(HeapRegion* list);
ysr@777 97
ysr@777 98 public:
ysr@777 99 YoungList(G1CollectedHeap* g1h);
ysr@777 100
ysr@777 101 void push_region(HeapRegion* hr);
ysr@777 102 void add_survivor_region(HeapRegion* hr);
ysr@777 103 HeapRegion* pop_region();
ysr@777 104 void empty_list();
ysr@777 105 bool is_empty() { return _length == 0; }
ysr@777 106 size_t length() { return _length; }
ysr@777 107 size_t scan_only_length() { return _scan_only_length; }
ysr@777 108
ysr@777 109 void rs_length_sampling_init();
ysr@777 110 bool rs_length_sampling_more();
ysr@777 111 void rs_length_sampling_next();
ysr@777 112
ysr@777 113 void reset_sampled_info() {
ysr@777 114 _last_sampled_rs_lengths = 0;
ysr@777 115 }
ysr@777 116 size_t sampled_rs_lengths() { return _last_sampled_rs_lengths; }
ysr@777 117
ysr@777 118 // for development purposes
ysr@777 119 void reset_auxilary_lists();
ysr@777 120 HeapRegion* first_region() { return _head; }
ysr@777 121 HeapRegion* first_scan_only_region() { return _scan_only_head; }
ysr@777 122 HeapRegion* first_survivor_region() { return _survivor_head; }
ysr@777 123 HeapRegion* par_get_next_scan_only_region() {
ysr@777 124 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
ysr@777 125 HeapRegion* ret = _curr_scan_only;
ysr@777 126 if (ret != NULL)
ysr@777 127 _curr_scan_only = ret->get_next_young_region();
ysr@777 128 return ret;
ysr@777 129 }
ysr@777 130
ysr@777 131 // debugging
ysr@777 132 bool check_list_well_formed();
ysr@777 133 bool check_list_empty(bool ignore_scan_only_list,
ysr@777 134 bool check_sample = true);
ysr@777 135 void print();
ysr@777 136 };
ysr@777 137
ysr@777 138 class RefineCardTableEntryClosure;
ysr@777 139 class G1CollectedHeap : public SharedHeap {
ysr@777 140 friend class VM_G1CollectForAllocation;
ysr@777 141 friend class VM_GenCollectForPermanentAllocation;
ysr@777 142 friend class VM_G1CollectFull;
ysr@777 143 friend class VM_G1IncCollectionPause;
ysr@777 144 friend class VM_G1PopRegionCollectionPause;
ysr@777 145 friend class VMStructs;
ysr@777 146
ysr@777 147 // Closures used in implementation.
ysr@777 148 friend class G1ParCopyHelper;
ysr@777 149 friend class G1IsAliveClosure;
ysr@777 150 friend class G1EvacuateFollowersClosure;
ysr@777 151 friend class G1ParScanThreadState;
ysr@777 152 friend class G1ParScanClosureSuper;
ysr@777 153 friend class G1ParEvacuateFollowersClosure;
ysr@777 154 friend class G1ParTask;
ysr@777 155 friend class G1FreeGarbageRegionClosure;
ysr@777 156 friend class RefineCardTableEntryClosure;
ysr@777 157 friend class G1PrepareCompactClosure;
ysr@777 158 friend class RegionSorter;
ysr@777 159 friend class CountRCClosure;
ysr@777 160 friend class EvacPopObjClosure;
ysr@777 161
ysr@777 162 // Other related classes.
ysr@777 163 friend class G1MarkSweep;
ysr@777 164
ysr@777 165 private:
ysr@777 166 enum SomePrivateConstants {
ysr@777 167 VeryLargeInBytes = HeapRegion::GrainBytes/2,
ysr@777 168 VeryLargeInWords = VeryLargeInBytes/HeapWordSize,
ysr@777 169 MinHeapDeltaBytes = 10 * HeapRegion::GrainBytes, // FIXME
ysr@777 170 NumAPIs = HeapRegion::MaxAge
ysr@777 171 };
ysr@777 172
ysr@777 173
ysr@777 174 // The one and only G1CollectedHeap, so static functions can find it.
ysr@777 175 static G1CollectedHeap* _g1h;
ysr@777 176
ysr@777 177 // Storage for the G1 heap (excludes the permanent generation).
ysr@777 178 VirtualSpace _g1_storage;
ysr@777 179 MemRegion _g1_reserved;
ysr@777 180
ysr@777 181 // The part of _g1_storage that is currently committed.
ysr@777 182 MemRegion _g1_committed;
ysr@777 183
ysr@777 184 // The maximum part of _g1_storage that has ever been committed.
ysr@777 185 MemRegion _g1_max_committed;
ysr@777 186
ysr@777 187 // The number of regions that are completely free.
ysr@777 188 size_t _free_regions;
ysr@777 189
ysr@777 190 // The number of regions we could create by expansion.
ysr@777 191 size_t _expansion_regions;
ysr@777 192
ysr@777 193 // Return the number of free regions in the heap (by direct counting.)
ysr@777 194 size_t count_free_regions();
ysr@777 195 // Return the number of free regions on the free and unclean lists.
ysr@777 196 size_t count_free_regions_list();
ysr@777 197
ysr@777 198 // The block offset table for the G1 heap.
ysr@777 199 G1BlockOffsetSharedArray* _bot_shared;
ysr@777 200
ysr@777 201 // Move all of the regions off the free lists, then rebuild those free
ysr@777 202 // lists, before and after full GC.
ysr@777 203 void tear_down_region_lists();
ysr@777 204 void rebuild_region_lists();
ysr@777 205 // This sets all non-empty regions to need zero-fill (which they will if
ysr@777 206 // they are empty after full collection.)
ysr@777 207 void set_used_regions_to_need_zero_fill();
ysr@777 208
ysr@777 209 // The sequence of all heap regions in the heap.
ysr@777 210 HeapRegionSeq* _hrs;
ysr@777 211
ysr@777 212 // The region from which normal-sized objects are currently being
ysr@777 213 // allocated. May be NULL.
ysr@777 214 HeapRegion* _cur_alloc_region;
ysr@777 215
ysr@777 216 // Postcondition: cur_alloc_region == NULL.
ysr@777 217 void abandon_cur_alloc_region();
ysr@777 218
ysr@777 219 // The to-space memory regions into which objects are being copied during
ysr@777 220 // a GC.
ysr@777 221 HeapRegion* _gc_alloc_regions[GCAllocPurposeCount];
ysr@777 222 uint _gc_alloc_region_counts[GCAllocPurposeCount];
ysr@777 223
ysr@777 224 // A list of the regions that have been set to be alloc regions in the
ysr@777 225 // current collection.
ysr@777 226 HeapRegion* _gc_alloc_region_list;
ysr@777 227
ysr@777 228 // When called by par thread, require par_alloc_during_gc_lock() to be held.
ysr@777 229 void push_gc_alloc_region(HeapRegion* hr);
ysr@777 230
ysr@777 231 // This should only be called single-threaded. Undeclares all GC alloc
ysr@777 232 // regions.
ysr@777 233 void forget_alloc_region_list();
ysr@777 234
ysr@777 235 // Should be used to set an alloc region, because there's other
ysr@777 236 // associated bookkeeping.
ysr@777 237 void set_gc_alloc_region(int purpose, HeapRegion* r);
ysr@777 238
ysr@777 239 // Check well-formedness of alloc region list.
ysr@777 240 bool check_gc_alloc_regions();
ysr@777 241
ysr@777 242 // Outside of GC pauses, the number of bytes used in all regions other
ysr@777 243 // than the current allocation region.
ysr@777 244 size_t _summary_bytes_used;
ysr@777 245
ysr@777 246 // Summary information about popular objects; method to print it.
ysr@777 247 NumberSeq _pop_obj_rc_at_copy;
ysr@777 248 void print_popularity_summary_info() const;
ysr@777 249
tonyp@961 250 // This is used for a quick test on whether a reference points into
tonyp@961 251 // the collection set or not. Basically, we have an array, with one
tonyp@961 252 // byte per region, and that byte denotes whether the corresponding
tonyp@961 253 // region is in the collection set or not. The entry corresponding
tonyp@961 254 // the bottom of the heap, i.e., region 0, is pointed to by
tonyp@961 255 // _in_cset_fast_test_base. The _in_cset_fast_test field has been
tonyp@961 256 // biased so that it actually points to address 0 of the address
tonyp@961 257 // space, to make the test as fast as possible (we can simply shift
tonyp@961 258 // the address to address into it, instead of having to subtract the
tonyp@961 259 // bottom of the heap from the address before shifting it; basically
tonyp@961 260 // it works in the same way the card table works).
tonyp@961 261 bool* _in_cset_fast_test;
tonyp@961 262
tonyp@961 263 // The allocated array used for the fast test on whether a reference
tonyp@961 264 // points into the collection set or not. This field is also used to
tonyp@961 265 // free the array.
tonyp@961 266 bool* _in_cset_fast_test_base;
tonyp@961 267
tonyp@961 268 // The length of the _in_cset_fast_test_base array.
tonyp@961 269 size_t _in_cset_fast_test_length;
tonyp@961 270
iveresov@788 271 volatile unsigned _gc_time_stamp;
ysr@777 272
ysr@777 273 size_t* _surviving_young_words;
ysr@777 274
ysr@777 275 void setup_surviving_young_words();
ysr@777 276 void update_surviving_young_words(size_t* surv_young_words);
ysr@777 277 void cleanup_surviving_young_words();
ysr@777 278
ysr@777 279 protected:
ysr@777 280
ysr@777 281 // Returns "true" iff none of the gc alloc regions have any allocations
ysr@777 282 // since the last call to "save_marks".
ysr@777 283 bool all_alloc_regions_no_allocs_since_save_marks();
ysr@777 284 // Calls "note_end_of_copying on all gc alloc_regions.
ysr@777 285 void all_alloc_regions_note_end_of_copying();
ysr@777 286
ysr@777 287 // The number of regions allocated to hold humongous objects.
ysr@777 288 int _num_humongous_regions;
ysr@777 289 YoungList* _young_list;
ysr@777 290
ysr@777 291 // The current policy object for the collector.
ysr@777 292 G1CollectorPolicy* _g1_policy;
ysr@777 293
ysr@777 294 // Parallel allocation lock to protect the current allocation region.
ysr@777 295 Mutex _par_alloc_during_gc_lock;
ysr@777 296 Mutex* par_alloc_during_gc_lock() { return &_par_alloc_during_gc_lock; }
ysr@777 297
ysr@777 298 // If possible/desirable, allocate a new HeapRegion for normal object
ysr@777 299 // allocation sufficient for an allocation of the given "word_size".
ysr@777 300 // If "do_expand" is true, will attempt to expand the heap if necessary
ysr@777 301 // to to satisfy the request. If "zero_filled" is true, requires a
ysr@777 302 // zero-filled region.
ysr@777 303 // (Returning NULL will trigger a GC.)
ysr@777 304 virtual HeapRegion* newAllocRegion_work(size_t word_size,
ysr@777 305 bool do_expand,
ysr@777 306 bool zero_filled);
ysr@777 307
ysr@777 308 virtual HeapRegion* newAllocRegion(size_t word_size,
ysr@777 309 bool zero_filled = true) {
ysr@777 310 return newAllocRegion_work(word_size, false, zero_filled);
ysr@777 311 }
ysr@777 312 virtual HeapRegion* newAllocRegionWithExpansion(int purpose,
ysr@777 313 size_t word_size,
ysr@777 314 bool zero_filled = true);
ysr@777 315
ysr@777 316 // Attempt to allocate an object of the given (very large) "word_size".
ysr@777 317 // Returns "NULL" on failure.
ysr@777 318 virtual HeapWord* humongousObjAllocate(size_t word_size);
ysr@777 319
ysr@777 320 // If possible, allocate a block of the given word_size, else return "NULL".
ysr@777 321 // Returning NULL will trigger GC or heap expansion.
ysr@777 322 // These two methods have rather awkward pre- and
ysr@777 323 // post-conditions. If they are called outside a safepoint, then
ysr@777 324 // they assume that the caller is holding the heap lock. Upon return
ysr@777 325 // they release the heap lock, if they are returning a non-NULL
ysr@777 326 // value. attempt_allocation_slow() also dirties the cards of a
ysr@777 327 // newly-allocated young region after it releases the heap
ysr@777 328 // lock. This change in interface was the neatest way to achieve
ysr@777 329 // this card dirtying without affecting mem_allocate(), which is a
ysr@777 330 // more frequently called method. We tried two or three different
ysr@777 331 // approaches, but they were even more hacky.
ysr@777 332 HeapWord* attempt_allocation(size_t word_size,
ysr@777 333 bool permit_collection_pause = true);
ysr@777 334
ysr@777 335 HeapWord* attempt_allocation_slow(size_t word_size,
ysr@777 336 bool permit_collection_pause = true);
ysr@777 337
ysr@777 338 // Allocate blocks during garbage collection. Will ensure an
ysr@777 339 // allocation region, either by picking one or expanding the
ysr@777 340 // heap, and then allocate a block of the given size. The block
ysr@777 341 // may not be a humongous - it must fit into a single heap region.
ysr@777 342 HeapWord* allocate_during_gc(GCAllocPurpose purpose, size_t word_size);
ysr@777 343 HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size);
ysr@777 344
ysr@777 345 HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose,
ysr@777 346 HeapRegion* alloc_region,
ysr@777 347 bool par,
ysr@777 348 size_t word_size);
ysr@777 349
ysr@777 350 // Ensure that no further allocations can happen in "r", bearing in mind
ysr@777 351 // that parallel threads might be attempting allocations.
ysr@777 352 void par_allocate_remaining_space(HeapRegion* r);
ysr@777 353
ysr@777 354 // Helper function for two callbacks below.
ysr@777 355 // "full", if true, indicates that the GC is for a System.gc() request,
ysr@777 356 // and should collect the entire heap. If "clear_all_soft_refs" is true,
ysr@777 357 // all soft references are cleared during the GC. If "full" is false,
ysr@777 358 // "word_size" describes the allocation that the GC should
ysr@777 359 // attempt (at least) to satisfy.
ysr@777 360 void do_collection(bool full, bool clear_all_soft_refs,
ysr@777 361 size_t word_size);
ysr@777 362
ysr@777 363 // Callback from VM_G1CollectFull operation.
ysr@777 364 // Perform a full collection.
ysr@777 365 void do_full_collection(bool clear_all_soft_refs);
ysr@777 366
ysr@777 367 // Resize the heap if necessary after a full collection. If this is
ysr@777 368 // after a collect-for allocation, "word_size" is the allocation size,
ysr@777 369 // and will be considered part of the used portion of the heap.
ysr@777 370 void resize_if_necessary_after_full_collection(size_t word_size);
ysr@777 371
ysr@777 372 // Callback from VM_G1CollectForAllocation operation.
ysr@777 373 // This function does everything necessary/possible to satisfy a
ysr@777 374 // failed allocation request (including collection, expansion, etc.)
ysr@777 375 HeapWord* satisfy_failed_allocation(size_t word_size);
ysr@777 376
ysr@777 377 // Attempting to expand the heap sufficiently
ysr@777 378 // to support an allocation of the given "word_size". If
ysr@777 379 // successful, perform the allocation and return the address of the
ysr@777 380 // allocated block, or else "NULL".
ysr@777 381 virtual HeapWord* expand_and_allocate(size_t word_size);
ysr@777 382
ysr@777 383 public:
ysr@777 384 // Expand the garbage-first heap by at least the given size (in bytes!).
ysr@777 385 // (Rounds up to a HeapRegion boundary.)
ysr@777 386 virtual void expand(size_t expand_bytes);
ysr@777 387
ysr@777 388 // Do anything common to GC's.
ysr@777 389 virtual void gc_prologue(bool full);
ysr@777 390 virtual void gc_epilogue(bool full);
ysr@777 391
tonyp@961 392 // We register a region with the fast "in collection set" test. We
tonyp@961 393 // simply set to true the array slot corresponding to this region.
tonyp@961 394 void register_region_with_in_cset_fast_test(HeapRegion* r) {
tonyp@961 395 assert(_in_cset_fast_test_base != NULL, "sanity");
tonyp@961 396 assert(r->in_collection_set(), "invariant");
tonyp@961 397 int index = r->hrs_index();
tonyp@961 398 assert(0 <= (size_t) index && (size_t) index < _in_cset_fast_test_length,
tonyp@961 399 "invariant");
tonyp@961 400 assert(!_in_cset_fast_test_base[index], "invariant");
tonyp@961 401 _in_cset_fast_test_base[index] = true;
tonyp@961 402 }
tonyp@961 403
tonyp@961 404 // This is a fast test on whether a reference points into the
tonyp@961 405 // collection set or not. It does not assume that the reference
tonyp@961 406 // points into the heap; if it doesn't, it will return false.
tonyp@961 407 bool in_cset_fast_test(oop obj) {
tonyp@961 408 assert(_in_cset_fast_test != NULL, "sanity");
tonyp@961 409 if (_g1_committed.contains((HeapWord*) obj)) {
tonyp@961 410 // no need to subtract the bottom of the heap from obj,
tonyp@961 411 // _in_cset_fast_test is biased
tonyp@961 412 size_t index = ((size_t) obj) >> HeapRegion::LogOfHRGrainBytes;
tonyp@961 413 bool ret = _in_cset_fast_test[index];
tonyp@961 414 // let's make sure the result is consistent with what the slower
tonyp@961 415 // test returns
tonyp@961 416 assert( ret || !obj_in_cs(obj), "sanity");
tonyp@961 417 assert(!ret || obj_in_cs(obj), "sanity");
tonyp@961 418 return ret;
tonyp@961 419 } else {
tonyp@961 420 return false;
tonyp@961 421 }
tonyp@961 422 }
tonyp@961 423
ysr@777 424 protected:
ysr@777 425
ysr@777 426 // Shrink the garbage-first heap by at most the given size (in bytes!).
ysr@777 427 // (Rounds down to a HeapRegion boundary.)
ysr@777 428 virtual void shrink(size_t expand_bytes);
ysr@777 429 void shrink_helper(size_t expand_bytes);
ysr@777 430
ysr@777 431 // Do an incremental collection: identify a collection set, and evacuate
ysr@777 432 // its live objects elsewhere.
ysr@777 433 virtual void do_collection_pause();
ysr@777 434
ysr@777 435 // The guts of the incremental collection pause, executed by the vm
ysr@777 436 // thread. If "popular_region" is non-NULL, this pause should evacuate
ysr@777 437 // this single region whose remembered set has gotten large, moving
ysr@777 438 // any popular objects to one of the popular regions.
ysr@777 439 virtual void do_collection_pause_at_safepoint(HeapRegion* popular_region);
ysr@777 440
ysr@777 441 // Actually do the work of evacuating the collection set.
ysr@777 442 virtual void evacuate_collection_set();
ysr@777 443
ysr@777 444 // If this is an appropriate right time, do a collection pause.
ysr@777 445 // The "word_size" argument, if non-zero, indicates the size of an
ysr@777 446 // allocation request that is prompting this query.
ysr@777 447 void do_collection_pause_if_appropriate(size_t word_size);
ysr@777 448
ysr@777 449 // The g1 remembered set of the heap.
ysr@777 450 G1RemSet* _g1_rem_set;
ysr@777 451 // And it's mod ref barrier set, used to track updates for the above.
ysr@777 452 ModRefBarrierSet* _mr_bs;
ysr@777 453
ysr@777 454 // The Heap Region Rem Set Iterator.
ysr@777 455 HeapRegionRemSetIterator** _rem_set_iterator;
ysr@777 456
ysr@777 457 // The closure used to refine a single card.
ysr@777 458 RefineCardTableEntryClosure* _refine_cte_cl;
ysr@777 459
ysr@777 460 // A function to check the consistency of dirty card logs.
ysr@777 461 void check_ct_logs_at_safepoint();
ysr@777 462
ysr@777 463 // After a collection pause, make the regions in the CS into free
ysr@777 464 // regions.
ysr@777 465 void free_collection_set(HeapRegion* cs_head);
ysr@777 466
ysr@777 467 // Applies "scan_non_heap_roots" to roots outside the heap,
ysr@777 468 // "scan_rs" to roots inside the heap (having done "set_region" to
ysr@777 469 // indicate the region in which the root resides), and does "scan_perm"
ysr@777 470 // (setting the generation to the perm generation.) If "scan_rs" is
ysr@777 471 // NULL, then this step is skipped. The "worker_i"
ysr@777 472 // param is for use with parallel roots processing, and should be
ysr@777 473 // the "i" of the calling parallel worker thread's work(i) function.
ysr@777 474 // In the sequential case this param will be ignored.
ysr@777 475 void g1_process_strong_roots(bool collecting_perm_gen,
ysr@777 476 SharedHeap::ScanningOption so,
ysr@777 477 OopClosure* scan_non_heap_roots,
ysr@777 478 OopsInHeapRegionClosure* scan_rs,
ysr@777 479 OopsInHeapRegionClosure* scan_so,
ysr@777 480 OopsInGenClosure* scan_perm,
ysr@777 481 int worker_i);
ysr@777 482
ysr@777 483 void scan_scan_only_set(OopsInHeapRegionClosure* oc,
ysr@777 484 int worker_i);
ysr@777 485 void scan_scan_only_region(HeapRegion* hr,
ysr@777 486 OopsInHeapRegionClosure* oc,
ysr@777 487 int worker_i);
ysr@777 488
ysr@777 489 // Apply "blk" to all the weak roots of the system. These include
ysr@777 490 // JNI weak roots, the code cache, system dictionary, symbol table,
ysr@777 491 // string table, and referents of reachable weak refs.
ysr@777 492 void g1_process_weak_roots(OopClosure* root_closure,
ysr@777 493 OopClosure* non_root_closure);
ysr@777 494
ysr@777 495 // Invoke "save_marks" on all heap regions.
ysr@777 496 void save_marks();
ysr@777 497
ysr@777 498 // Free a heap region.
ysr@777 499 void free_region(HeapRegion* hr);
ysr@777 500 // A component of "free_region", exposed for 'batching'.
ysr@777 501 // All the params after "hr" are out params: the used bytes of the freed
ysr@777 502 // region(s), the number of H regions cleared, the number of regions
ysr@777 503 // freed, and pointers to the head and tail of a list of freed contig
ysr@777 504 // regions, linked throught the "next_on_unclean_list" field.
ysr@777 505 void free_region_work(HeapRegion* hr,
ysr@777 506 size_t& pre_used,
ysr@777 507 size_t& cleared_h,
ysr@777 508 size_t& freed_regions,
ysr@777 509 UncleanRegionList* list,
ysr@777 510 bool par = false);
ysr@777 511
ysr@777 512
ysr@777 513 // The concurrent marker (and the thread it runs in.)
ysr@777 514 ConcurrentMark* _cm;
ysr@777 515 ConcurrentMarkThread* _cmThread;
ysr@777 516 bool _mark_in_progress;
ysr@777 517
ysr@777 518 // The concurrent refiner.
ysr@777 519 ConcurrentG1Refine* _cg1r;
ysr@777 520
ysr@777 521 // The concurrent zero-fill thread.
ysr@777 522 ConcurrentZFThread* _czft;
ysr@777 523
ysr@777 524 // The parallel task queues
ysr@777 525 RefToScanQueueSet *_task_queues;
ysr@777 526
ysr@777 527 // True iff a evacuation has failed in the current collection.
ysr@777 528 bool _evacuation_failed;
ysr@777 529
ysr@777 530 // Set the attribute indicating whether evacuation has failed in the
ysr@777 531 // current collection.
ysr@777 532 void set_evacuation_failed(bool b) { _evacuation_failed = b; }
ysr@777 533
ysr@777 534 // Failed evacuations cause some logical from-space objects to have
ysr@777 535 // forwarding pointers to themselves. Reset them.
ysr@777 536 void remove_self_forwarding_pointers();
ysr@777 537
ysr@777 538 // When one is non-null, so is the other. Together, they each pair is
ysr@777 539 // an object with a preserved mark, and its mark value.
ysr@777 540 GrowableArray<oop>* _objs_with_preserved_marks;
ysr@777 541 GrowableArray<markOop>* _preserved_marks_of_objs;
ysr@777 542
ysr@777 543 // Preserve the mark of "obj", if necessary, in preparation for its mark
ysr@777 544 // word being overwritten with a self-forwarding-pointer.
ysr@777 545 void preserve_mark_if_necessary(oop obj, markOop m);
ysr@777 546
ysr@777 547 // The stack of evac-failure objects left to be scanned.
ysr@777 548 GrowableArray<oop>* _evac_failure_scan_stack;
ysr@777 549 // The closure to apply to evac-failure objects.
ysr@777 550
ysr@777 551 OopsInHeapRegionClosure* _evac_failure_closure;
ysr@777 552 // Set the field above.
ysr@777 553 void
ysr@777 554 set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_closure) {
ysr@777 555 _evac_failure_closure = evac_failure_closure;
ysr@777 556 }
ysr@777 557
ysr@777 558 // Push "obj" on the scan stack.
ysr@777 559 void push_on_evac_failure_scan_stack(oop obj);
ysr@777 560 // Process scan stack entries until the stack is empty.
ysr@777 561 void drain_evac_failure_scan_stack();
ysr@777 562 // True iff an invocation of "drain_scan_stack" is in progress; to
ysr@777 563 // prevent unnecessary recursion.
ysr@777 564 bool _drain_in_progress;
ysr@777 565
ysr@777 566 // Do any necessary initialization for evacuation-failure handling.
ysr@777 567 // "cl" is the closure that will be used to process evac-failure
ysr@777 568 // objects.
ysr@777 569 void init_for_evac_failure(OopsInHeapRegionClosure* cl);
ysr@777 570 // Do any necessary cleanup for evacuation-failure handling data
ysr@777 571 // structures.
ysr@777 572 void finalize_for_evac_failure();
ysr@777 573
ysr@777 574 // An attempt to evacuate "obj" has failed; take necessary steps.
ysr@777 575 void handle_evacuation_failure(oop obj);
ysr@777 576 oop handle_evacuation_failure_par(OopsInHeapRegionClosure* cl, oop obj);
ysr@777 577 void handle_evacuation_failure_common(oop obj, markOop m);
ysr@777 578
ysr@777 579
ysr@777 580 // Ensure that the relevant gc_alloc regions are set.
ysr@777 581 void get_gc_alloc_regions();
ysr@777 582 // We're done with GC alloc regions; release them, as appropriate.
ysr@777 583 void release_gc_alloc_regions();
ysr@777 584
ysr@777 585 // ("Weak") Reference processing support
ysr@777 586 ReferenceProcessor* _ref_processor;
ysr@777 587
ysr@777 588 enum G1H_process_strong_roots_tasks {
ysr@777 589 G1H_PS_mark_stack_oops_do,
ysr@777 590 G1H_PS_refProcessor_oops_do,
ysr@777 591 // Leave this one last.
ysr@777 592 G1H_PS_NumElements
ysr@777 593 };
ysr@777 594
ysr@777 595 SubTasksDone* _process_strong_tasks;
ysr@777 596
ysr@777 597 // Allocate space to hold a popular object. Result is guaranteed below
ysr@777 598 // "popular_object_boundary()". Note: CURRENTLY halts the system if we
ysr@777 599 // run out of space to hold popular objects.
ysr@777 600 HeapWord* allocate_popular_object(size_t word_size);
ysr@777 601
ysr@777 602 // The boundary between popular and non-popular objects.
ysr@777 603 HeapWord* _popular_object_boundary;
ysr@777 604
ysr@777 605 HeapRegionList* _popular_regions_to_be_evacuated;
ysr@777 606
ysr@777 607 // Compute which objects in "single_region" are popular. If any are,
ysr@777 608 // evacuate them to a popular region, leaving behind forwarding pointers,
ysr@777 609 // and select "popular_region" as the single collection set region.
ysr@777 610 // Otherwise, leave the collection set null.
ysr@777 611 void popularity_pause_preamble(HeapRegion* populer_region);
ysr@777 612
ysr@777 613 // Compute which objects in "single_region" are popular, and evacuate
ysr@777 614 // them to a popular region, leaving behind forwarding pointers.
ysr@777 615 // Returns "true" if at least one popular object is discovered and
ysr@777 616 // evacuated. In any case, "*max_rc" is set to the maximum reference
ysr@777 617 // count of an object in the region.
ysr@777 618 bool compute_reference_counts_and_evac_popular(HeapRegion* populer_region,
ysr@777 619 size_t* max_rc);
ysr@777 620 // Subroutines used in the above.
ysr@777 621 bool _rc_region_above;
ysr@777 622 size_t _rc_region_diff;
ysr@777 623 jint* obj_rc_addr(oop obj) {
ysr@777 624 uintptr_t obj_addr = (uintptr_t)obj;
ysr@777 625 if (_rc_region_above) {
ysr@777 626 jint* res = (jint*)(obj_addr + _rc_region_diff);
ysr@777 627 assert((uintptr_t)res > obj_addr, "RC region is above.");
ysr@777 628 return res;
ysr@777 629 } else {
ysr@777 630 jint* res = (jint*)(obj_addr - _rc_region_diff);
ysr@777 631 assert((uintptr_t)res < obj_addr, "RC region is below.");
ysr@777 632 return res;
ysr@777 633 }
ysr@777 634 }
ysr@777 635 jint obj_rc(oop obj) {
ysr@777 636 return *obj_rc_addr(obj);
ysr@777 637 }
ysr@777 638 void inc_obj_rc(oop obj) {
ysr@777 639 (*obj_rc_addr(obj))++;
ysr@777 640 }
ysr@777 641 void atomic_inc_obj_rc(oop obj);
ysr@777 642
ysr@777 643
ysr@777 644 // Number of popular objects and bytes (latter is cheaper!).
ysr@777 645 size_t pop_object_used_objs();
ysr@777 646 size_t pop_object_used_bytes();
ysr@777 647
ysr@777 648 // Index of the popular region in which allocation is currently being
ysr@777 649 // done.
ysr@777 650 int _cur_pop_hr_index;
ysr@777 651
ysr@777 652 // List of regions which require zero filling.
ysr@777 653 UncleanRegionList _unclean_region_list;
ysr@777 654 bool _unclean_regions_coming;
ysr@777 655
ysr@777 656 bool check_age_cohort_well_formed_work(int a, HeapRegion* hr);
ysr@777 657
ysr@777 658 public:
ysr@777 659 void set_refine_cte_cl_concurrency(bool concurrent);
ysr@777 660
ysr@777 661 RefToScanQueue *task_queue(int i);
ysr@777 662
ysr@777 663 // Create a G1CollectedHeap with the specified policy.
ysr@777 664 // Must call the initialize method afterwards.
ysr@777 665 // May not return if something goes wrong.
ysr@777 666 G1CollectedHeap(G1CollectorPolicy* policy);
ysr@777 667
ysr@777 668 // Initialize the G1CollectedHeap to have the initial and
ysr@777 669 // maximum sizes, permanent generation, and remembered and barrier sets
ysr@777 670 // specified by the policy object.
ysr@777 671 jint initialize();
ysr@777 672
ysr@777 673 void ref_processing_init();
ysr@777 674
ysr@777 675 void set_par_threads(int t) {
ysr@777 676 SharedHeap::set_par_threads(t);
ysr@777 677 _process_strong_tasks->set_par_threads(t);
ysr@777 678 }
ysr@777 679
ysr@777 680 virtual CollectedHeap::Name kind() const {
ysr@777 681 return CollectedHeap::G1CollectedHeap;
ysr@777 682 }
ysr@777 683
ysr@777 684 // The current policy object for the collector.
ysr@777 685 G1CollectorPolicy* g1_policy() const { return _g1_policy; }
ysr@777 686
ysr@777 687 // Adaptive size policy. No such thing for g1.
ysr@777 688 virtual AdaptiveSizePolicy* size_policy() { return NULL; }
ysr@777 689
ysr@777 690 // The rem set and barrier set.
ysr@777 691 G1RemSet* g1_rem_set() const { return _g1_rem_set; }
ysr@777 692 ModRefBarrierSet* mr_bs() const { return _mr_bs; }
ysr@777 693
ysr@777 694 // The rem set iterator.
ysr@777 695 HeapRegionRemSetIterator* rem_set_iterator(int i) {
ysr@777 696 return _rem_set_iterator[i];
ysr@777 697 }
ysr@777 698
ysr@777 699 HeapRegionRemSetIterator* rem_set_iterator() {
ysr@777 700 return _rem_set_iterator[0];
ysr@777 701 }
ysr@777 702
ysr@777 703 unsigned get_gc_time_stamp() {
ysr@777 704 return _gc_time_stamp;
ysr@777 705 }
ysr@777 706
ysr@777 707 void reset_gc_time_stamp() {
ysr@777 708 _gc_time_stamp = 0;
iveresov@788 709 OrderAccess::fence();
iveresov@788 710 }
iveresov@788 711
iveresov@788 712 void increment_gc_time_stamp() {
iveresov@788 713 ++_gc_time_stamp;
iveresov@788 714 OrderAccess::fence();
ysr@777 715 }
ysr@777 716
ysr@777 717 void iterate_dirty_card_closure(bool concurrent, int worker_i);
ysr@777 718
ysr@777 719 // The shared block offset table array.
ysr@777 720 G1BlockOffsetSharedArray* bot_shared() const { return _bot_shared; }
ysr@777 721
ysr@777 722 // Reference Processing accessor
ysr@777 723 ReferenceProcessor* ref_processor() { return _ref_processor; }
ysr@777 724
ysr@777 725 // Reserved (g1 only; super method includes perm), capacity and the used
ysr@777 726 // portion in bytes.
ysr@777 727 size_t g1_reserved_obj_bytes() { return _g1_reserved.byte_size(); }
ysr@777 728 virtual size_t capacity() const;
ysr@777 729 virtual size_t used() const;
ysr@777 730 size_t recalculate_used() const;
ysr@777 731 #ifndef PRODUCT
ysr@777 732 size_t recalculate_used_regions() const;
ysr@777 733 #endif // PRODUCT
ysr@777 734
ysr@777 735 // These virtual functions do the actual allocation.
ysr@777 736 virtual HeapWord* mem_allocate(size_t word_size,
ysr@777 737 bool is_noref,
ysr@777 738 bool is_tlab,
ysr@777 739 bool* gc_overhead_limit_was_exceeded);
ysr@777 740
ysr@777 741 // Some heaps may offer a contiguous region for shared non-blocking
ysr@777 742 // allocation, via inlined code (by exporting the address of the top and
ysr@777 743 // end fields defining the extent of the contiguous allocation region.)
ysr@777 744 // But G1CollectedHeap doesn't yet support this.
ysr@777 745
ysr@777 746 // Return an estimate of the maximum allocation that could be performed
ysr@777 747 // without triggering any collection or expansion activity. In a
ysr@777 748 // generational collector, for example, this is probably the largest
ysr@777 749 // allocation that could be supported (without expansion) in the youngest
ysr@777 750 // generation. It is "unsafe" because no locks are taken; the result
ysr@777 751 // should be treated as an approximation, not a guarantee, for use in
ysr@777 752 // heuristic resizing decisions.
ysr@777 753 virtual size_t unsafe_max_alloc();
ysr@777 754
ysr@777 755 virtual bool is_maximal_no_gc() const {
ysr@777 756 return _g1_storage.uncommitted_size() == 0;
ysr@777 757 }
ysr@777 758
ysr@777 759 // The total number of regions in the heap.
ysr@777 760 size_t n_regions();
ysr@777 761
ysr@777 762 // The number of regions that are completely free.
ysr@777 763 size_t max_regions();
ysr@777 764
ysr@777 765 // The number of regions that are completely free.
ysr@777 766 size_t free_regions();
ysr@777 767
ysr@777 768 // The number of regions that are not completely free.
ysr@777 769 size_t used_regions() { return n_regions() - free_regions(); }
ysr@777 770
ysr@777 771 // True iff the ZF thread should run.
ysr@777 772 bool should_zf();
ysr@777 773
ysr@777 774 // The number of regions available for "regular" expansion.
ysr@777 775 size_t expansion_regions() { return _expansion_regions; }
ysr@777 776
ysr@777 777 #ifndef PRODUCT
ysr@777 778 bool regions_accounted_for();
ysr@777 779 bool print_region_accounting_info();
ysr@777 780 void print_region_counts();
ysr@777 781 #endif
ysr@777 782
ysr@777 783 HeapRegion* alloc_region_from_unclean_list(bool zero_filled);
ysr@777 784 HeapRegion* alloc_region_from_unclean_list_locked(bool zero_filled);
ysr@777 785
ysr@777 786 void put_region_on_unclean_list(HeapRegion* r);
ysr@777 787 void put_region_on_unclean_list_locked(HeapRegion* r);
ysr@777 788
ysr@777 789 void prepend_region_list_on_unclean_list(UncleanRegionList* list);
ysr@777 790 void prepend_region_list_on_unclean_list_locked(UncleanRegionList* list);
ysr@777 791
ysr@777 792 void set_unclean_regions_coming(bool b);
ysr@777 793 void set_unclean_regions_coming_locked(bool b);
ysr@777 794 // Wait for cleanup to be complete.
ysr@777 795 void wait_for_cleanup_complete();
ysr@777 796 // Like above, but assumes that the calling thread owns the Heap_lock.
ysr@777 797 void wait_for_cleanup_complete_locked();
ysr@777 798
ysr@777 799 // Return the head of the unclean list.
ysr@777 800 HeapRegion* peek_unclean_region_list_locked();
ysr@777 801 // Remove and return the head of the unclean list.
ysr@777 802 HeapRegion* pop_unclean_region_list_locked();
ysr@777 803
ysr@777 804 // List of regions which are zero filled and ready for allocation.
ysr@777 805 HeapRegion* _free_region_list;
ysr@777 806 // Number of elements on the free list.
ysr@777 807 size_t _free_region_list_size;
ysr@777 808
ysr@777 809 // If the head of the unclean list is ZeroFilled, move it to the free
ysr@777 810 // list.
ysr@777 811 bool move_cleaned_region_to_free_list_locked();
ysr@777 812 bool move_cleaned_region_to_free_list();
ysr@777 813
ysr@777 814 void put_free_region_on_list_locked(HeapRegion* r);
ysr@777 815 void put_free_region_on_list(HeapRegion* r);
ysr@777 816
ysr@777 817 // Remove and return the head element of the free list.
ysr@777 818 HeapRegion* pop_free_region_list_locked();
ysr@777 819
ysr@777 820 // If "zero_filled" is true, we first try the free list, then we try the
ysr@777 821 // unclean list, zero-filling the result. If "zero_filled" is false, we
ysr@777 822 // first try the unclean list, then the zero-filled list.
ysr@777 823 HeapRegion* alloc_free_region_from_lists(bool zero_filled);
ysr@777 824
ysr@777 825 // Verify the integrity of the region lists.
ysr@777 826 void remove_allocated_regions_from_lists();
ysr@777 827 bool verify_region_lists();
ysr@777 828 bool verify_region_lists_locked();
ysr@777 829 size_t unclean_region_list_length();
ysr@777 830 size_t free_region_list_length();
ysr@777 831
ysr@777 832 // Perform a collection of the heap; intended for use in implementing
ysr@777 833 // "System.gc". This probably implies as full a collection as the
ysr@777 834 // "CollectedHeap" supports.
ysr@777 835 virtual void collect(GCCause::Cause cause);
ysr@777 836
ysr@777 837 // The same as above but assume that the caller holds the Heap_lock.
ysr@777 838 void collect_locked(GCCause::Cause cause);
ysr@777 839
ysr@777 840 // This interface assumes that it's being called by the
ysr@777 841 // vm thread. It collects the heap assuming that the
ysr@777 842 // heap lock is already held and that we are executing in
ysr@777 843 // the context of the vm thread.
ysr@777 844 virtual void collect_as_vm_thread(GCCause::Cause cause);
ysr@777 845
ysr@777 846 // True iff a evacuation has failed in the most-recent collection.
ysr@777 847 bool evacuation_failed() { return _evacuation_failed; }
ysr@777 848
ysr@777 849 // Free a region if it is totally full of garbage. Returns the number of
ysr@777 850 // bytes freed (0 ==> didn't free it).
ysr@777 851 size_t free_region_if_totally_empty(HeapRegion *hr);
ysr@777 852 void free_region_if_totally_empty_work(HeapRegion *hr,
ysr@777 853 size_t& pre_used,
ysr@777 854 size_t& cleared_h_regions,
ysr@777 855 size_t& freed_regions,
ysr@777 856 UncleanRegionList* list,
ysr@777 857 bool par = false);
ysr@777 858
ysr@777 859 // If we've done free region work that yields the given changes, update
ysr@777 860 // the relevant global variables.
ysr@777 861 void finish_free_region_work(size_t pre_used,
ysr@777 862 size_t cleared_h_regions,
ysr@777 863 size_t freed_regions,
ysr@777 864 UncleanRegionList* list);
ysr@777 865
ysr@777 866
ysr@777 867 // Returns "TRUE" iff "p" points into the allocated area of the heap.
ysr@777 868 virtual bool is_in(const void* p) const;
ysr@777 869
ysr@777 870 // Return "TRUE" iff the given object address is within the collection
ysr@777 871 // set.
ysr@777 872 inline bool obj_in_cs(oop obj);
ysr@777 873
ysr@777 874 // Return "TRUE" iff the given object address is in the reserved
ysr@777 875 // region of g1 (excluding the permanent generation).
ysr@777 876 bool is_in_g1_reserved(const void* p) const {
ysr@777 877 return _g1_reserved.contains(p);
ysr@777 878 }
ysr@777 879
ysr@777 880 // Returns a MemRegion that corresponds to the space that has been
ysr@777 881 // committed in the heap
ysr@777 882 MemRegion g1_committed() {
ysr@777 883 return _g1_committed;
ysr@777 884 }
ysr@777 885
ysr@777 886 NOT_PRODUCT( bool is_in_closed_subset(const void* p) const; )
ysr@777 887
ysr@777 888 // Dirty card table entries covering a list of young regions.
ysr@777 889 void dirtyCardsForYoungRegions(CardTableModRefBS* ct_bs, HeapRegion* list);
ysr@777 890
ysr@777 891 // This resets the card table to all zeros. It is used after
ysr@777 892 // a collection pause which used the card table to claim cards.
ysr@777 893 void cleanUpCardTable();
ysr@777 894
ysr@777 895 // Iteration functions.
ysr@777 896
ysr@777 897 // Iterate over all the ref-containing fields of all objects, calling
ysr@777 898 // "cl.do_oop" on each.
ysr@777 899 virtual void oop_iterate(OopClosure* cl);
ysr@777 900
ysr@777 901 // Same as above, restricted to a memory region.
ysr@777 902 virtual void oop_iterate(MemRegion mr, OopClosure* cl);
ysr@777 903
ysr@777 904 // Iterate over all objects, calling "cl.do_object" on each.
ysr@777 905 virtual void object_iterate(ObjectClosure* cl);
jmasa@952 906 virtual void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); }
ysr@777 907
ysr@777 908 // Iterate over all objects allocated since the last collection, calling
ysr@777 909 // "cl.do_object" on each. The heap must have been initialized properly
ysr@777 910 // to support this function, or else this call will fail.
ysr@777 911 virtual void object_iterate_since_last_GC(ObjectClosure* cl);
ysr@777 912
ysr@777 913 // Iterate over all spaces in use in the heap, in ascending address order.
ysr@777 914 virtual void space_iterate(SpaceClosure* cl);
ysr@777 915
ysr@777 916 // Iterate over heap regions, in address order, terminating the
ysr@777 917 // iteration early if the "doHeapRegion" method returns "true".
ysr@777 918 void heap_region_iterate(HeapRegionClosure* blk);
ysr@777 919
ysr@777 920 // Iterate over heap regions starting with r (or the first region if "r"
ysr@777 921 // is NULL), in address order, terminating early if the "doHeapRegion"
ysr@777 922 // method returns "true".
ysr@777 923 void heap_region_iterate_from(HeapRegion* r, HeapRegionClosure* blk);
ysr@777 924
ysr@777 925 // As above but starting from the region at index idx.
ysr@777 926 void heap_region_iterate_from(int idx, HeapRegionClosure* blk);
ysr@777 927
ysr@777 928 HeapRegion* region_at(size_t idx);
ysr@777 929
ysr@777 930 // Divide the heap region sequence into "chunks" of some size (the number
ysr@777 931 // of regions divided by the number of parallel threads times some
ysr@777 932 // overpartition factor, currently 4). Assumes that this will be called
ysr@777 933 // in parallel by ParallelGCThreads worker threads with discinct worker
ysr@777 934 // ids in the range [0..max(ParallelGCThreads-1, 1)], that all parallel
ysr@777 935 // calls will use the same "claim_value", and that that claim value is
ysr@777 936 // different from the claim_value of any heap region before the start of
ysr@777 937 // the iteration. Applies "blk->doHeapRegion" to each of the regions, by
ysr@777 938 // attempting to claim the first region in each chunk, and, if
ysr@777 939 // successful, applying the closure to each region in the chunk (and
ysr@777 940 // setting the claim value of the second and subsequent regions of the
ysr@777 941 // chunk.) For now requires that "doHeapRegion" always returns "false",
ysr@777 942 // i.e., that a closure never attempt to abort a traversal.
ysr@777 943 void heap_region_par_iterate_chunked(HeapRegionClosure* blk,
ysr@777 944 int worker,
ysr@777 945 jint claim_value);
ysr@777 946
tonyp@825 947 // It resets all the region claim values to the default.
tonyp@825 948 void reset_heap_region_claim_values();
tonyp@825 949
tonyp@790 950 #ifdef ASSERT
tonyp@790 951 bool check_heap_region_claim_values(jint claim_value);
tonyp@790 952 #endif // ASSERT
tonyp@790 953
ysr@777 954 // Iterate over the regions (if any) in the current collection set.
ysr@777 955 void collection_set_iterate(HeapRegionClosure* blk);
ysr@777 956
ysr@777 957 // As above but starting from region r
ysr@777 958 void collection_set_iterate_from(HeapRegion* r, HeapRegionClosure *blk);
ysr@777 959
ysr@777 960 // Returns the first (lowest address) compactible space in the heap.
ysr@777 961 virtual CompactibleSpace* first_compactible_space();
ysr@777 962
ysr@777 963 // A CollectedHeap will contain some number of spaces. This finds the
ysr@777 964 // space containing a given address, or else returns NULL.
ysr@777 965 virtual Space* space_containing(const void* addr) const;
ysr@777 966
ysr@777 967 // A G1CollectedHeap will contain some number of heap regions. This
ysr@777 968 // finds the region containing a given address, or else returns NULL.
ysr@777 969 HeapRegion* heap_region_containing(const void* addr) const;
ysr@777 970
ysr@777 971 // Like the above, but requires "addr" to be in the heap (to avoid a
ysr@777 972 // null-check), and unlike the above, may return an continuing humongous
ysr@777 973 // region.
ysr@777 974 HeapRegion* heap_region_containing_raw(const void* addr) const;
ysr@777 975
ysr@777 976 // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
ysr@777 977 // each address in the (reserved) heap is a member of exactly
ysr@777 978 // one block. The defining characteristic of a block is that it is
ysr@777 979 // possible to find its size, and thus to progress forward to the next
ysr@777 980 // block. (Blocks may be of different sizes.) Thus, blocks may
ysr@777 981 // represent Java objects, or they might be free blocks in a
ysr@777 982 // free-list-based heap (or subheap), as long as the two kinds are
ysr@777 983 // distinguishable and the size of each is determinable.
ysr@777 984
ysr@777 985 // Returns the address of the start of the "block" that contains the
ysr@777 986 // address "addr". We say "blocks" instead of "object" since some heaps
ysr@777 987 // may not pack objects densely; a chunk may either be an object or a
ysr@777 988 // non-object.
ysr@777 989 virtual HeapWord* block_start(const void* addr) const;
ysr@777 990
ysr@777 991 // Requires "addr" to be the start of a chunk, and returns its size.
ysr@777 992 // "addr + size" is required to be the start of a new chunk, or the end
ysr@777 993 // of the active area of the heap.
ysr@777 994 virtual size_t block_size(const HeapWord* addr) const;
ysr@777 995
ysr@777 996 // Requires "addr" to be the start of a block, and returns "TRUE" iff
ysr@777 997 // the block is an object.
ysr@777 998 virtual bool block_is_obj(const HeapWord* addr) const;
ysr@777 999
ysr@777 1000 // Does this heap support heap inspection? (+PrintClassHistogram)
ysr@777 1001 virtual bool supports_heap_inspection() const { return true; }
ysr@777 1002
ysr@777 1003 // Section on thread-local allocation buffers (TLABs)
ysr@777 1004 // See CollectedHeap for semantics.
ysr@777 1005
ysr@777 1006 virtual bool supports_tlab_allocation() const;
ysr@777 1007 virtual size_t tlab_capacity(Thread* thr) const;
ysr@777 1008 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
ysr@777 1009 virtual HeapWord* allocate_new_tlab(size_t size);
ysr@777 1010
ysr@777 1011 // Can a compiler initialize a new object without store barriers?
ysr@777 1012 // This permission only extends from the creation of a new object
ysr@777 1013 // via a TLAB up to the first subsequent safepoint.
ysr@777 1014 virtual bool can_elide_tlab_store_barriers() const {
ysr@777 1015 // Since G1's TLAB's may, on occasion, come from non-young regions
ysr@777 1016 // as well. (Is there a flag controlling that? XXX)
ysr@777 1017 return false;
ysr@777 1018 }
ysr@777 1019
ysr@777 1020 // Can a compiler elide a store barrier when it writes
ysr@777 1021 // a permanent oop into the heap? Applies when the compiler
ysr@777 1022 // is storing x to the heap, where x->is_perm() is true.
ysr@777 1023 virtual bool can_elide_permanent_oop_store_barriers() const {
ysr@777 1024 // At least until perm gen collection is also G1-ified, at
ysr@777 1025 // which point this should return false.
ysr@777 1026 return true;
ysr@777 1027 }
ysr@777 1028
ysr@777 1029 virtual bool allocs_are_zero_filled();
ysr@777 1030
ysr@777 1031 // The boundary between a "large" and "small" array of primitives, in
ysr@777 1032 // words.
ysr@777 1033 virtual size_t large_typearray_limit();
ysr@777 1034
ysr@777 1035 // All popular objects are guaranteed to have addresses below this
ysr@777 1036 // boundary.
ysr@777 1037 HeapWord* popular_object_boundary() {
ysr@777 1038 return _popular_object_boundary;
ysr@777 1039 }
ysr@777 1040
ysr@777 1041 // Declare the region as one that should be evacuated because its
ysr@777 1042 // remembered set is too large.
ysr@777 1043 void schedule_popular_region_evac(HeapRegion* r);
ysr@777 1044 // If there is a popular region to evacuate it, remove it from the list
ysr@777 1045 // and return it.
ysr@777 1046 HeapRegion* popular_region_to_evac();
ysr@777 1047 // Evacuate the given popular region.
ysr@777 1048 void evac_popular_region(HeapRegion* r);
ysr@777 1049
ysr@777 1050 // Returns "true" iff the given word_size is "very large".
ysr@777 1051 static bool isHumongous(size_t word_size) {
ysr@777 1052 return word_size >= VeryLargeInWords;
ysr@777 1053 }
ysr@777 1054
ysr@777 1055 // Update mod union table with the set of dirty cards.
ysr@777 1056 void updateModUnion();
ysr@777 1057
ysr@777 1058 // Set the mod union bits corresponding to the given memRegion. Note
ysr@777 1059 // that this is always a safe operation, since it doesn't clear any
ysr@777 1060 // bits.
ysr@777 1061 void markModUnionRange(MemRegion mr);
ysr@777 1062
ysr@777 1063 // Records the fact that a marking phase is no longer in progress.
ysr@777 1064 void set_marking_complete() {
ysr@777 1065 _mark_in_progress = false;
ysr@777 1066 }
ysr@777 1067 void set_marking_started() {
ysr@777 1068 _mark_in_progress = true;
ysr@777 1069 }
ysr@777 1070 bool mark_in_progress() {
ysr@777 1071 return _mark_in_progress;
ysr@777 1072 }
ysr@777 1073
ysr@777 1074 // Print the maximum heap capacity.
ysr@777 1075 virtual size_t max_capacity() const;
ysr@777 1076
ysr@777 1077 virtual jlong millis_since_last_gc();
ysr@777 1078
ysr@777 1079 // Perform any cleanup actions necessary before allowing a verification.
ysr@777 1080 virtual void prepare_for_verify();
ysr@777 1081
ysr@777 1082 // Perform verification.
ysr@777 1083 virtual void verify(bool allow_dirty, bool silent);
ysr@777 1084 virtual void print() const;
ysr@777 1085 virtual void print_on(outputStream* st) const;
ysr@777 1086
ysr@777 1087 virtual void print_gc_threads_on(outputStream* st) const;
ysr@777 1088 virtual void gc_threads_do(ThreadClosure* tc) const;
ysr@777 1089
ysr@777 1090 // Override
ysr@777 1091 void print_tracing_info() const;
ysr@777 1092
ysr@777 1093 // If "addr" is a pointer into the (reserved?) heap, returns a positive
ysr@777 1094 // number indicating the "arena" within the heap in which "addr" falls.
ysr@777 1095 // Or else returns 0.
ysr@777 1096 virtual int addr_to_arena_id(void* addr) const;
ysr@777 1097
ysr@777 1098 // Convenience function to be used in situations where the heap type can be
ysr@777 1099 // asserted to be this type.
ysr@777 1100 static G1CollectedHeap* heap();
ysr@777 1101
ysr@777 1102 void empty_young_list();
ysr@777 1103 bool should_set_young_locked();
ysr@777 1104
ysr@777 1105 void set_region_short_lived_locked(HeapRegion* hr);
ysr@777 1106 // add appropriate methods for any other surv rate groups
ysr@777 1107
ysr@777 1108 void young_list_rs_length_sampling_init() {
ysr@777 1109 _young_list->rs_length_sampling_init();
ysr@777 1110 }
ysr@777 1111 bool young_list_rs_length_sampling_more() {
ysr@777 1112 return _young_list->rs_length_sampling_more();
ysr@777 1113 }
ysr@777 1114 void young_list_rs_length_sampling_next() {
ysr@777 1115 _young_list->rs_length_sampling_next();
ysr@777 1116 }
ysr@777 1117 size_t young_list_sampled_rs_lengths() {
ysr@777 1118 return _young_list->sampled_rs_lengths();
ysr@777 1119 }
ysr@777 1120
ysr@777 1121 size_t young_list_length() { return _young_list->length(); }
ysr@777 1122 size_t young_list_scan_only_length() {
ysr@777 1123 return _young_list->scan_only_length(); }
ysr@777 1124
ysr@777 1125 HeapRegion* pop_region_from_young_list() {
ysr@777 1126 return _young_list->pop_region();
ysr@777 1127 }
ysr@777 1128
ysr@777 1129 HeapRegion* young_list_first_region() {
ysr@777 1130 return _young_list->first_region();
ysr@777 1131 }
ysr@777 1132
ysr@777 1133 // debugging
ysr@777 1134 bool check_young_list_well_formed() {
ysr@777 1135 return _young_list->check_list_well_formed();
ysr@777 1136 }
ysr@777 1137 bool check_young_list_empty(bool ignore_scan_only_list,
ysr@777 1138 bool check_sample = true);
ysr@777 1139
ysr@777 1140 // *** Stuff related to concurrent marking. It's not clear to me that so
ysr@777 1141 // many of these need to be public.
ysr@777 1142
ysr@777 1143 // The functions below are helper functions that a subclass of
ysr@777 1144 // "CollectedHeap" can use in the implementation of its virtual
ysr@777 1145 // functions.
ysr@777 1146 // This performs a concurrent marking of the live objects in a
ysr@777 1147 // bitmap off to the side.
ysr@777 1148 void doConcurrentMark();
ysr@777 1149
ysr@777 1150 // This is called from the marksweep collector which then does
ysr@777 1151 // a concurrent mark and verifies that the results agree with
ysr@777 1152 // the stop the world marking.
ysr@777 1153 void checkConcurrentMark();
ysr@777 1154 void do_sync_mark();
ysr@777 1155
ysr@777 1156 bool isMarkedPrev(oop obj) const;
ysr@777 1157 bool isMarkedNext(oop obj) const;
ysr@777 1158
ysr@777 1159 // Determine if an object is dead, given the object and also
ysr@777 1160 // the region to which the object belongs. An object is dead
ysr@777 1161 // iff a) it was not allocated since the last mark and b) it
ysr@777 1162 // is not marked.
ysr@777 1163
ysr@777 1164 bool is_obj_dead(const oop obj, const HeapRegion* hr) const {
ysr@777 1165 return
ysr@777 1166 !hr->obj_allocated_since_prev_marking(obj) &&
ysr@777 1167 !isMarkedPrev(obj);
ysr@777 1168 }
ysr@777 1169
ysr@777 1170 // This is used when copying an object to survivor space.
ysr@777 1171 // If the object is marked live, then we mark the copy live.
ysr@777 1172 // If the object is allocated since the start of this mark
ysr@777 1173 // cycle, then we mark the copy live.
ysr@777 1174 // If the object has been around since the previous mark
ysr@777 1175 // phase, and hasn't been marked yet during this phase,
ysr@777 1176 // then we don't mark it, we just wait for the
ysr@777 1177 // current marking cycle to get to it.
ysr@777 1178
ysr@777 1179 // This function returns true when an object has been
ysr@777 1180 // around since the previous marking and hasn't yet
ysr@777 1181 // been marked during this marking.
ysr@777 1182
ysr@777 1183 bool is_obj_ill(const oop obj, const HeapRegion* hr) const {
ysr@777 1184 return
ysr@777 1185 !hr->obj_allocated_since_next_marking(obj) &&
ysr@777 1186 !isMarkedNext(obj);
ysr@777 1187 }
ysr@777 1188
ysr@777 1189 // Determine if an object is dead, given only the object itself.
ysr@777 1190 // This will find the region to which the object belongs and
ysr@777 1191 // then call the region version of the same function.
ysr@777 1192
ysr@777 1193 // Added if it is in permanent gen it isn't dead.
ysr@777 1194 // Added if it is NULL it isn't dead.
ysr@777 1195
ysr@777 1196 bool is_obj_dead(oop obj) {
ysr@777 1197 HeapRegion* hr = heap_region_containing(obj);
ysr@777 1198 if (hr == NULL) {
ysr@777 1199 if (Universe::heap()->is_in_permanent(obj))
ysr@777 1200 return false;
ysr@777 1201 else if (obj == NULL) return false;
ysr@777 1202 else return true;
ysr@777 1203 }
ysr@777 1204 else return is_obj_dead(obj, hr);
ysr@777 1205 }
ysr@777 1206
ysr@777 1207 bool is_obj_ill(oop obj) {
ysr@777 1208 HeapRegion* hr = heap_region_containing(obj);
ysr@777 1209 if (hr == NULL) {
ysr@777 1210 if (Universe::heap()->is_in_permanent(obj))
ysr@777 1211 return false;
ysr@777 1212 else if (obj == NULL) return false;
ysr@777 1213 else return true;
ysr@777 1214 }
ysr@777 1215 else return is_obj_ill(obj, hr);
ysr@777 1216 }
ysr@777 1217
ysr@777 1218 // The following is just to alert the verification code
ysr@777 1219 // that a full collection has occurred and that the
ysr@777 1220 // remembered sets are no longer up to date.
ysr@777 1221 bool _full_collection;
ysr@777 1222 void set_full_collection() { _full_collection = true;}
ysr@777 1223 void clear_full_collection() {_full_collection = false;}
ysr@777 1224 bool full_collection() {return _full_collection;}
ysr@777 1225
ysr@777 1226 ConcurrentMark* concurrent_mark() const { return _cm; }
ysr@777 1227 ConcurrentG1Refine* concurrent_g1_refine() const { return _cg1r; }
ysr@777 1228
ysr@777 1229 public:
ysr@777 1230 void stop_conc_gc_threads();
ysr@777 1231
ysr@777 1232 // <NEW PREDICTION>
ysr@777 1233
ysr@777 1234 double predict_region_elapsed_time_ms(HeapRegion* hr, bool young);
ysr@777 1235 void check_if_region_is_too_expensive(double predicted_time_ms);
ysr@777 1236 size_t pending_card_num();
ysr@777 1237 size_t max_pending_card_num();
ysr@777 1238 size_t cards_scanned();
ysr@777 1239
ysr@777 1240 // </NEW PREDICTION>
ysr@777 1241
ysr@777 1242 protected:
ysr@777 1243 size_t _max_heap_capacity;
ysr@777 1244
ysr@777 1245 // debug_only(static void check_for_valid_allocation_state();)
ysr@777 1246
ysr@777 1247 public:
ysr@777 1248 // Temporary: call to mark things unimplemented for the G1 heap (e.g.,
ysr@777 1249 // MemoryService). In productization, we can make this assert false
ysr@777 1250 // to catch such places (as well as searching for calls to this...)
ysr@777 1251 static void g1_unimplemented();
ysr@777 1252
ysr@777 1253 };
ysr@777 1254
ysr@777 1255 // Local Variables: ***
ysr@777 1256 // c-indentation-style: gnu ***
ysr@777 1257 // End: ***

mercurial