annotate src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @ 390:cc68c8e9b309

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