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

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 980
58054a18d735
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

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

mercurial