Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
48766 views
/*1* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP25#define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP2627#include "gc_implementation/g1/g1AllocationContext.hpp"28#include "gc_implementation/g1/g1Allocator.hpp"29#include "gc_implementation/g1/concurrentMark.hpp"30#include "gc_implementation/g1/evacuationInfo.hpp"31#include "gc_implementation/g1/g1AllocRegion.hpp"32#include "gc_implementation/g1/g1BiasedArray.hpp"33#include "gc_implementation/g1/g1HRPrinter.hpp"34#include "gc_implementation/g1/g1InCSetState.hpp"35#include "gc_implementation/g1/g1MonitoringSupport.hpp"36#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"37#include "gc_implementation/g1/g1YCTypes.hpp"38#include "gc_implementation/g1/heapRegionManager.hpp"39#include "gc_implementation/g1/heapRegionSet.hpp"40#include "gc_implementation/shared/gcHeapSummary.hpp"41#include "gc_implementation/shared/hSpaceCounters.hpp"42#include "gc_implementation/shared/parGCAllocBuffer.hpp"43#include "memory/barrierSet.hpp"44#include "memory/memRegion.hpp"45#include "memory/sharedHeap.hpp"46#include "utilities/stack.hpp"4748// A "G1CollectedHeap" is an implementation of a java heap for HotSpot.49// It uses the "Garbage First" heap organization and algorithm, which50// may combine concurrent marking with parallel, incremental compaction of51// heap subsets that will yield large amounts of garbage.5253// Forward declarations54class HeapRegion;55class HRRSCleanupTask;56class GenerationSpec;57class OopsInHeapRegionClosure;58class G1KlassScanClosure;59class G1ScanHeapEvacClosure;60class ObjectClosure;61class SpaceClosure;62class CompactibleSpaceClosure;63class Space;64class G1CollectorPolicy;65class GenRemSet;66class G1RemSet;67class HeapRegionRemSetIterator;68class ConcurrentMark;69class ConcurrentMarkThread;70class ConcurrentG1Refine;71class ConcurrentGCTimer;72class GenerationCounters;73class STWGCTimer;74class G1NewTracer;75class G1OldTracer;76class EvacuationFailedInfo;77class nmethod;7879typedef OverflowTaskQueue<StarTask, mtGC> RefToScanQueue;80typedef GenericTaskQueueSet<RefToScanQueue, mtGC> RefToScanQueueSet;8182typedef int RegionIdx_t; // needs to hold [ 0..max_regions() )83typedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion )8485class YoungList : public CHeapObj<mtGC> {86private:87G1CollectedHeap* _g1h;8889HeapRegion* _head;9091HeapRegion* _survivor_head;92HeapRegion* _survivor_tail;9394HeapRegion* _curr;9596uint _length;97uint _survivor_length;9899size_t _last_sampled_rs_lengths;100size_t _sampled_rs_lengths;101102void empty_list(HeapRegion* list);103104public:105YoungList(G1CollectedHeap* g1h);106107void push_region(HeapRegion* hr);108void add_survivor_region(HeapRegion* hr);109110void empty_list();111bool is_empty() { return _length == 0; }112uint length() { return _length; }113uint survivor_length() { return _survivor_length; }114115// Currently we do not keep track of the used byte sum for the116// young list and the survivors and it'd be quite a lot of work to117// do so. When we'll eventually replace the young list with118// instances of HeapRegionLinkedList we'll get that for free. So,119// we'll report the more accurate information then.120size_t eden_used_bytes() {121assert(length() >= survivor_length(), "invariant");122return (size_t) (length() - survivor_length()) * HeapRegion::GrainBytes;123}124size_t survivor_used_bytes() {125return (size_t) survivor_length() * HeapRegion::GrainBytes;126}127128void rs_length_sampling_init();129bool rs_length_sampling_more();130void rs_length_sampling_next();131132void reset_sampled_info() {133_last_sampled_rs_lengths = 0;134}135size_t sampled_rs_lengths() { return _last_sampled_rs_lengths; }136137// for development purposes138void reset_auxilary_lists();139void clear() { _head = NULL; _length = 0; }140141void clear_survivors() {142_survivor_head = NULL;143_survivor_tail = NULL;144_survivor_length = 0;145}146147HeapRegion* first_region() { return _head; }148HeapRegion* first_survivor_region() { return _survivor_head; }149HeapRegion* last_survivor_region() { return _survivor_tail; }150151// debugging152bool check_list_well_formed();153bool check_list_empty(bool check_sample = true);154void print();155};156157// The G1 STW is alive closure.158// An instance is embedded into the G1CH and used as the159// (optional) _is_alive_non_header closure in the STW160// reference processor. It is also extensively used during161// reference processing during STW evacuation pauses.162class G1STWIsAliveClosure: public BoolObjectClosure {163G1CollectedHeap* _g1;164public:165G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {}166bool do_object_b(oop p);167};168169class RefineCardTableEntryClosure;170171class G1RegionMappingChangedListener : public G1MappingChangedListener {172private:173void reset_from_card_cache(uint start_idx, size_t num_regions);174public:175virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);176};177178class G1CollectedHeap : public SharedHeap {179friend class VM_CollectForMetadataAllocation;180friend class VM_G1CollectForAllocation;181friend class VM_G1CollectFull;182friend class VM_G1IncCollectionPause;183friend class VMStructs;184friend class MutatorAllocRegion;185friend class SurvivorGCAllocRegion;186friend class OldGCAllocRegion;187friend class G1Allocator;188friend class G1DefaultAllocator;189friend class G1ResManAllocator;190191// Closures used in implementation.192template <G1Barrier barrier, G1Mark do_mark_object>193friend class G1ParCopyClosure;194friend class G1IsAliveClosure;195friend class G1EvacuateFollowersClosure;196friend class G1ParScanThreadState;197friend class G1ParScanClosureSuper;198friend class G1ParEvacuateFollowersClosure;199friend class G1ParTask;200friend class G1ParGCAllocator;201friend class G1DefaultParGCAllocator;202friend class G1FreeGarbageRegionClosure;203friend class RefineCardTableEntryClosure;204friend class G1PrepareCompactClosure;205friend class RegionSorter;206friend class RegionResetter;207friend class CountRCClosure;208friend class EvacPopObjClosure;209friend class G1ParCleanupCTTask;210211friend class G1FreeHumongousRegionClosure;212// Other related classes.213friend class G1MarkSweep;214215// Testing classes.216friend class G1CheckCSetFastTableClosure;217218private:219// The one and only G1CollectedHeap, so static functions can find it.220static G1CollectedHeap* _g1h;221222static size_t _humongous_object_threshold_in_words;223224// The secondary free list which contains regions that have been225// freed up during the cleanup process. This will be appended to226// the master free list when appropriate.227FreeRegionList _secondary_free_list;228229// It keeps track of the old regions.230HeapRegionSet _old_set;231232// It keeps track of the humongous regions.233HeapRegionSet _humongous_set;234235void eagerly_reclaim_humongous_regions();236237// The number of regions we could create by expansion.238uint _expansion_regions;239240// The block offset table for the G1 heap.241G1BlockOffsetSharedArray* _bot_shared;242243// Tears down the region sets / lists so that they are empty and the244// regions on the heap do not belong to a region set / list. The245// only exception is the humongous set which we leave unaltered. If246// free_list_only is true, it will only tear down the master free247// list. It is called before a Full GC (free_list_only == false) or248// before heap shrinking (free_list_only == true).249void tear_down_region_sets(bool free_list_only);250251// Rebuilds the region sets / lists so that they are repopulated to252// reflect the contents of the heap. The only exception is the253// humongous set which was not torn down in the first place. If254// free_list_only is true, it will only rebuild the master free255// list. It is called after a Full GC (free_list_only == false) or256// after heap shrinking (free_list_only == true).257void rebuild_region_sets(bool free_list_only);258259// Callback for region mapping changed events.260G1RegionMappingChangedListener _listener;261262// The sequence of all heap regions in the heap.263HeapRegionManager _hrm;264265// Class that handles the different kinds of allocations.266G1Allocator* _allocator;267268// Statistics for each allocation context269AllocationContextStats _allocation_context_stats;270271// PLAB sizing policy for survivors.272PLABStats _survivor_plab_stats;273274// PLAB sizing policy for tenured objects.275PLABStats _old_plab_stats;276277// It specifies whether we should attempt to expand the heap after a278// region allocation failure. If heap expansion fails we set this to279// false so that we don't re-attempt the heap expansion (it's likely280// that subsequent expansion attempts will also fail if one fails).281// Currently, it is only consulted during GC and it's reset at the282// start of each GC.283bool _expand_heap_after_alloc_failure;284285// It resets the mutator alloc region before new allocations can take place.286void init_mutator_alloc_region();287288// It releases the mutator alloc region.289void release_mutator_alloc_region();290291// It initializes the GC alloc regions at the start of a GC.292void init_gc_alloc_regions(EvacuationInfo& evacuation_info);293294// It releases the GC alloc regions at the end of a GC.295void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info);296297// It does any cleanup that needs to be done on the GC alloc regions298// before a Full GC.299void abandon_gc_alloc_regions();300301// Helper for monitoring and management support.302G1MonitoringSupport* _g1mm;303304// Records whether the region at the given index is (still) a305// candidate for eager reclaim. Only valid for humongous start306// regions; other regions have unspecified values. Humongous start307// regions are initialized at start of collection pause, with308// candidates removed from the set as they are found reachable from309// roots or the young generation.310class HumongousReclaimCandidates : public G1BiasedMappedArray<bool> {311protected:312bool default_value() const { return false; }313public:314void clear() { G1BiasedMappedArray<bool>::clear(); }315void set_candidate(uint region, bool value) {316set_by_index(region, value);317}318bool is_candidate(uint region) {319return get_by_index(region);320}321};322323HumongousReclaimCandidates _humongous_reclaim_candidates;324// Stores whether during humongous object registration we found candidate regions.325// If not, we can skip a few steps.326bool _has_humongous_reclaim_candidates;327328volatile unsigned _gc_time_stamp;329330size_t* _surviving_young_words;331332G1HRPrinter _hr_printer;333334void setup_surviving_young_words();335void update_surviving_young_words(size_t* surv_young_words);336void cleanup_surviving_young_words();337338// It decides whether an explicit GC should start a concurrent cycle339// instead of doing a STW GC. Currently, a concurrent cycle is340// explicitly started if:341// (a) cause == _gc_locker and +GCLockerInvokesConcurrent, or342// (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent.343// (c) cause == _g1_humongous_allocation344bool should_do_concurrent_full_gc(GCCause::Cause cause);345346// Keeps track of how many "old marking cycles" (i.e., Full GCs or347// concurrent cycles) we have started.348volatile uint _old_marking_cycles_started;349350// Keeps track of how many "old marking cycles" (i.e., Full GCs or351// concurrent cycles) we have completed.352volatile uint _old_marking_cycles_completed;353354bool _concurrent_cycle_started;355bool _heap_summary_sent;356357// This is a non-product method that is helpful for testing. It is358// called at the end of a GC and artificially expands the heap by359// allocating a number of dead regions. This way we can induce very360// frequent marking cycles and stress the cleanup / concurrent361// cleanup code more (as all the regions that will be allocated by362// this method will be found dead by the marking cycle).363void allocate_dummy_regions() PRODUCT_RETURN;364365// Clear RSets after a compaction. It also resets the GC time stamps.366void clear_rsets_post_compaction();367368// If the HR printer is active, dump the state of the regions in the369// heap after a compaction.370void print_hrm_post_compaction();371372// Create a memory mapper for auxiliary data structures of the given size and373// translation factor.374static G1RegionToSpaceMapper* create_aux_memory_mapper(const char* description,375size_t size,376size_t translation_factor);377378void trace_heap(GCWhen::Type when, GCTracer* tracer);379380double verify(bool guard, const char* msg);381void verify_before_gc();382void verify_after_gc();383384void log_gc_header();385void log_gc_footer(double pause_time_sec);386387// These are macros so that, if the assert fires, we get the correct388// line number, file, etc.389390#define heap_locking_asserts_err_msg(_extra_message_) \391err_msg("%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \392(_extra_message_), \393BOOL_TO_STR(Heap_lock->owned_by_self()), \394BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), \395BOOL_TO_STR(Thread::current()->is_VM_thread()))396397#define assert_heap_locked() \398do { \399assert(Heap_lock->owned_by_self(), \400heap_locking_asserts_err_msg("should be holding the Heap_lock")); \401} while (0)402403#define assert_heap_locked_or_at_safepoint(_should_be_vm_thread_) \404do { \405assert(Heap_lock->owned_by_self() || \406(SafepointSynchronize::is_at_safepoint() && \407((_should_be_vm_thread_) == Thread::current()->is_VM_thread())), \408heap_locking_asserts_err_msg("should be holding the Heap_lock or " \409"should be at a safepoint")); \410} while (0)411412#define assert_heap_locked_and_not_at_safepoint() \413do { \414assert(Heap_lock->owned_by_self() && \415!SafepointSynchronize::is_at_safepoint(), \416heap_locking_asserts_err_msg("should be holding the Heap_lock and " \417"should not be at a safepoint")); \418} while (0)419420#define assert_heap_not_locked() \421do { \422assert(!Heap_lock->owned_by_self(), \423heap_locking_asserts_err_msg("should not be holding the Heap_lock")); \424} while (0)425426#define assert_heap_not_locked_and_not_at_safepoint() \427do { \428assert(!Heap_lock->owned_by_self() && \429!SafepointSynchronize::is_at_safepoint(), \430heap_locking_asserts_err_msg("should not be holding the Heap_lock and " \431"should not be at a safepoint")); \432} while (0)433434#define assert_at_safepoint(_should_be_vm_thread_) \435do { \436assert(SafepointSynchronize::is_at_safepoint() && \437((_should_be_vm_thread_) == Thread::current()->is_VM_thread()), \438heap_locking_asserts_err_msg("should be at a safepoint")); \439} while (0)440441#define assert_not_at_safepoint() \442do { \443assert(!SafepointSynchronize::is_at_safepoint(), \444heap_locking_asserts_err_msg("should not be at a safepoint")); \445} while (0)446447protected:448449// The young region list.450YoungList* _young_list;451452// The current policy object for the collector.453G1CollectorPolicy* _g1_policy;454455// This is the second level of trying to allocate a new region. If456// new_region() didn't find a region on the free_list, this call will457// check whether there's anything available on the458// secondary_free_list and/or wait for more regions to appear on459// that list, if _free_regions_coming is set.460HeapRegion* new_region_try_secondary_free_list(bool is_old);461462// Try to allocate a single non-humongous HeapRegion sufficient for463// an allocation of the given word_size. If do_expand is true,464// attempt to expand the heap if necessary to satisfy the allocation465// request. If the region is to be used as an old region or for a466// humongous object, set is_old to true. If not, to false.467HeapRegion* new_region(size_t word_size, bool is_old, bool do_expand);468469// Initialize a contiguous set of free regions of length num_regions470// and starting at index first so that they appear as a single471// humongous region.472HeapWord* humongous_obj_allocate_initialize_regions(uint first,473uint num_regions,474size_t word_size,475AllocationContext_t context);476477// Attempt to allocate a humongous object of the given size. Return478// NULL if unsuccessful.479HeapWord* humongous_obj_allocate(size_t word_size, AllocationContext_t context);480481// The following two methods, allocate_new_tlab() and482// mem_allocate(), are the two main entry points from the runtime483// into the G1's allocation routines. They have the following484// assumptions:485//486// * They should both be called outside safepoints.487//488// * They should both be called without holding the Heap_lock.489//490// * All allocation requests for new TLABs should go to491// allocate_new_tlab().492//493// * All non-TLAB allocation requests should go to mem_allocate().494//495// * If either call cannot satisfy the allocation request using the496// current allocating region, they will try to get a new one. If497// this fails, they will attempt to do an evacuation pause and498// retry the allocation.499//500// * If all allocation attempts fail, even after trying to schedule501// an evacuation pause, allocate_new_tlab() will return NULL,502// whereas mem_allocate() will attempt a heap expansion and/or503// schedule a Full GC.504//505// * We do not allow humongous-sized TLABs. So, allocate_new_tlab506// should never be called with word_size being humongous. All507// humongous allocation requests should go to mem_allocate() which508// will satisfy them with a special path.509510virtual HeapWord* allocate_new_tlab(size_t word_size);511512virtual HeapWord* mem_allocate(size_t word_size,513bool* gc_overhead_limit_was_exceeded);514515// The following three methods take a gc_count_before_ret516// parameter which is used to return the GC count if the method517// returns NULL. Given that we are required to read the GC count518// while holding the Heap_lock, and these paths will take the519// Heap_lock at some point, it's easier to get them to read the GC520// count while holding the Heap_lock before they return NULL instead521// of the caller (namely: mem_allocate()) having to also take the522// Heap_lock just to read the GC count.523524// First-level mutator allocation attempt: try to allocate out of525// the mutator alloc region without taking the Heap_lock. This526// should only be used for non-humongous allocations.527inline HeapWord* attempt_allocation(size_t word_size,528uint* gc_count_before_ret,529uint* gclocker_retry_count_ret);530531// Second-level mutator allocation attempt: take the Heap_lock and532// retry the allocation attempt, potentially scheduling a GC533// pause. This should only be used for non-humongous allocations.534HeapWord* attempt_allocation_slow(size_t word_size,535AllocationContext_t context,536uint* gc_count_before_ret,537uint* gclocker_retry_count_ret);538539// Takes the Heap_lock and attempts a humongous allocation. It can540// potentially schedule a GC pause.541HeapWord* attempt_allocation_humongous(size_t word_size,542uint* gc_count_before_ret,543uint* gclocker_retry_count_ret);544545// Allocation attempt that should be called during safepoints (e.g.,546// at the end of a successful GC). expect_null_mutator_alloc_region547// specifies whether the mutator alloc region is expected to be NULL548// or not.549HeapWord* attempt_allocation_at_safepoint(size_t word_size,550AllocationContext_t context,551bool expect_null_mutator_alloc_region);552553// It dirties the cards that cover the block so that so that the post554// write barrier never queues anything when updating objects on this555// block. It is assumed (and in fact we assert) that the block556// belongs to a young region.557inline void dirty_young_block(HeapWord* start, size_t word_size);558559// Allocate blocks during garbage collection. Will ensure an560// allocation region, either by picking one or expanding the561// heap, and then allocate a block of the given size. The block562// may not be a humongous - it must fit into a single heap region.563inline HeapWord* par_allocate_during_gc(InCSetState dest,564size_t word_size,565AllocationContext_t context);566// Ensure that no further allocations can happen in "r", bearing in mind567// that parallel threads might be attempting allocations.568void par_allocate_remaining_space(HeapRegion* r);569570// Allocation attempt during GC for a survivor object / PLAB.571inline HeapWord* survivor_attempt_allocation(size_t word_size,572AllocationContext_t context);573574// Allocation attempt during GC for an old object / PLAB.575inline HeapWord* old_attempt_allocation(size_t word_size,576AllocationContext_t context);577578// These methods are the "callbacks" from the G1AllocRegion class.579580// For mutator alloc regions.581HeapRegion* new_mutator_alloc_region(size_t word_size, bool force);582void retire_mutator_alloc_region(HeapRegion* alloc_region,583size_t allocated_bytes);584585// For GC alloc regions.586HeapRegion* new_gc_alloc_region(size_t word_size, uint count,587InCSetState dest);588void retire_gc_alloc_region(HeapRegion* alloc_region,589size_t allocated_bytes, InCSetState dest);590591// - if explicit_gc is true, the GC is for a System.gc() or a heap592// inspection request and should collect the entire heap593// - if clear_all_soft_refs is true, all soft references should be594// cleared during the GC595// - if explicit_gc is false, word_size describes the allocation that596// the GC should attempt (at least) to satisfy597// - it returns false if it is unable to do the collection due to the598// GC locker being active, true otherwise599bool do_collection(bool explicit_gc,600bool clear_all_soft_refs,601size_t word_size);602603// Callback from VM_G1CollectFull operation.604// Perform a full collection.605virtual void do_full_collection(bool clear_all_soft_refs);606607// Resize the heap if necessary after a full collection. If this is608// after a collect-for allocation, "word_size" is the allocation size,609// and will be considered part of the used portion of the heap.610void resize_if_necessary_after_full_collection(size_t word_size);611612// Callback from VM_G1CollectForAllocation operation.613// This function does everything necessary/possible to satisfy a614// failed allocation request (including collection, expansion, etc.)615HeapWord* satisfy_failed_allocation(size_t word_size,616AllocationContext_t context,617bool* succeeded);618619// Attempting to expand the heap sufficiently620// to support an allocation of the given "word_size". If621// successful, perform the allocation and return the address of the622// allocated block, or else "NULL".623HeapWord* expand_and_allocate(size_t word_size, AllocationContext_t context);624625// Process any reference objects discovered during626// an incremental evacuation pause.627void process_discovered_references(uint no_of_gc_workers);628629// Enqueue any remaining discovered references630// after processing.631void enqueue_discovered_references(uint no_of_gc_workers);632633public:634635G1Allocator* allocator() {636return _allocator;637}638639G1MonitoringSupport* g1mm() {640assert(_g1mm != NULL, "should have been initialized");641return _g1mm;642}643644// Expand the garbage-first heap by at least the given size (in bytes!).645// Returns true if the heap was expanded by the requested amount;646// false otherwise.647// (Rounds up to a HeapRegion boundary.)648bool expand(size_t expand_bytes);649650// Returns the PLAB statistics for a given destination.651inline PLABStats* alloc_buffer_stats(InCSetState dest);652653// Determines PLAB size for a given destination.654inline size_t desired_plab_sz(InCSetState dest);655656inline AllocationContextStats& allocation_context_stats();657658// Do anything common to GC's.659virtual void gc_prologue(bool full);660virtual void gc_epilogue(bool full);661662// Modify the reclaim candidate set and test for presence.663// These are only valid for starts_humongous regions.664inline void set_humongous_reclaim_candidate(uint region, bool value);665inline bool is_humongous_reclaim_candidate(uint region);666667// Remove from the reclaim candidate set. Also remove from the668// collection set so that later encounters avoid the slow path.669inline void set_humongous_is_live(oop obj);670671// Register the given region to be part of the collection set.672inline void register_humongous_region_with_in_cset_fast_test(uint index);673// Register regions with humongous objects (actually on the start region) in674// the in_cset_fast_test table.675void register_humongous_regions_with_in_cset_fast_test();676// We register a region with the fast "in collection set" test. We677// simply set to true the array slot corresponding to this region.678void register_young_region_with_in_cset_fast_test(HeapRegion* r) {679_in_cset_fast_test.set_in_young(r->hrm_index());680}681void register_old_region_with_in_cset_fast_test(HeapRegion* r) {682_in_cset_fast_test.set_in_old(r->hrm_index());683}684685// This is a fast test on whether a reference points into the686// collection set or not. Assume that the reference687// points into the heap.688inline bool in_cset_fast_test(oop obj);689690void clear_cset_fast_test() {691_in_cset_fast_test.clear();692}693694// This is called at the start of either a concurrent cycle or a Full695// GC to update the number of old marking cycles started.696void increment_old_marking_cycles_started();697698// This is called at the end of either a concurrent cycle or a Full699// GC to update the number of old marking cycles completed. Those two700// can happen in a nested fashion, i.e., we start a concurrent701// cycle, a Full GC happens half-way through it which ends first,702// and then the cycle notices that a Full GC happened and ends703// too. The concurrent parameter is a boolean to help us do a bit704// tighter consistency checking in the method. If concurrent is705// false, the caller is the inner caller in the nesting (i.e., the706// Full GC). If concurrent is true, the caller is the outer caller707// in this nesting (i.e., the concurrent cycle). Further nesting is708// not currently supported. The end of this call also notifies709// the FullGCCount_lock in case a Java thread is waiting for a full710// GC to happen (e.g., it called System.gc() with711// +ExplicitGCInvokesConcurrent).712void increment_old_marking_cycles_completed(bool concurrent);713714uint old_marking_cycles_completed() {715return _old_marking_cycles_completed;716}717718void register_concurrent_cycle_start(const Ticks& start_time);719void register_concurrent_cycle_end();720void trace_heap_after_concurrent_cycle();721722G1YCType yc_type();723724G1HRPrinter* hr_printer() { return &_hr_printer; }725726// Frees a non-humongous region by initializing its contents and727// adding it to the free list that's passed as a parameter (this is728// usually a local list which will be appended to the master free729// list later). The used bytes of freed regions are accumulated in730// pre_used. If par is true, the region's RSet will not be freed731// up. The assumption is that this will be done later.732// The locked parameter indicates if the caller has already taken733// care of proper synchronization. This may allow some optimizations.734void free_region(HeapRegion* hr,735FreeRegionList* free_list,736bool par,737bool locked = false);738739// Frees a humongous region by collapsing it into individual regions740// and calling free_region() for each of them. The freed regions741// will be added to the free list that's passed as a parameter (this742// is usually a local list which will be appended to the master free743// list later). The used bytes of freed regions are accumulated in744// pre_used. If par is true, the region's RSet will not be freed745// up. The assumption is that this will be done later.746void free_humongous_region(HeapRegion* hr,747FreeRegionList* free_list,748bool par);749protected:750751// Shrink the garbage-first heap by at most the given size (in bytes!).752// (Rounds down to a HeapRegion boundary.)753virtual void shrink(size_t expand_bytes);754void shrink_helper(size_t expand_bytes);755756#if TASKQUEUE_STATS757static void print_taskqueue_stats_hdr(outputStream* const st = gclog_or_tty);758void print_taskqueue_stats(outputStream* const st = gclog_or_tty) const;759void reset_taskqueue_stats();760#endif // TASKQUEUE_STATS761762// Schedule the VM operation that will do an evacuation pause to763// satisfy an allocation request of word_size. *succeeded will764// return whether the VM operation was successful (it did do an765// evacuation pause) or not (another thread beat us to it or the GC766// locker was active). Given that we should not be holding the767// Heap_lock when we enter this method, we will pass the768// gc_count_before (i.e., total_collections()) as a parameter since769// it has to be read while holding the Heap_lock. Currently, both770// methods that call do_collection_pause() release the Heap_lock771// before the call, so it's easy to read gc_count_before just before.772HeapWord* do_collection_pause(size_t word_size,773uint gc_count_before,774bool* succeeded,775GCCause::Cause gc_cause);776777// The guts of the incremental collection pause, executed by the vm778// thread. It returns false if it is unable to do the collection due779// to the GC locker being active, true otherwise780bool do_collection_pause_at_safepoint(double target_pause_time_ms);781782// Actually do the work of evacuating the collection set.783void evacuate_collection_set(EvacuationInfo& evacuation_info);784785// The g1 remembered set of the heap.786G1RemSet* _g1_rem_set;787788// A set of cards that cover the objects for which the Rsets should be updated789// concurrently after the collection.790DirtyCardQueueSet _dirty_card_queue_set;791792// The closure used to refine a single card.793RefineCardTableEntryClosure* _refine_cte_cl;794795// A function to check the consistency of dirty card logs.796void check_ct_logs_at_safepoint();797798// A DirtyCardQueueSet that is used to hold cards that contain799// references into the current collection set. This is used to800// update the remembered sets of the regions in the collection801// set in the event of an evacuation failure.802DirtyCardQueueSet _into_cset_dirty_card_queue_set;803804// After a collection pause, make the regions in the CS into free805// regions.806void free_collection_set(HeapRegion* cs_head, EvacuationInfo& evacuation_info);807808// Abandon the current collection set without recording policy809// statistics or updating free lists.810void abandon_collection_set(HeapRegion* cs_head);811812// The concurrent marker (and the thread it runs in.)813ConcurrentMark* _cm;814ConcurrentMarkThread* _cmThread;815bool _mark_in_progress;816817// The concurrent refiner.818ConcurrentG1Refine* _cg1r;819820// The parallel task queues821RefToScanQueueSet *_task_queues;822823// True iff a evacuation has failed in the current collection.824bool _evacuation_failed;825826EvacuationFailedInfo* _evacuation_failed_info_array;827828// Failed evacuations cause some logical from-space objects to have829// forwarding pointers to themselves. Reset them.830void remove_self_forwarding_pointers();831832// Together, these store an object with a preserved mark, and its mark value.833Stack<oop, mtGC> _objs_with_preserved_marks;834Stack<markOop, mtGC> _preserved_marks_of_objs;835836// Preserve the mark of "obj", if necessary, in preparation for its mark837// word being overwritten with a self-forwarding-pointer.838void preserve_mark_if_necessary(oop obj, markOop m);839840// The stack of evac-failure objects left to be scanned.841GrowableArray<oop>* _evac_failure_scan_stack;842// The closure to apply to evac-failure objects.843844OopsInHeapRegionClosure* _evac_failure_closure;845// Set the field above.846void847set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_closure) {848_evac_failure_closure = evac_failure_closure;849}850851// Push "obj" on the scan stack.852void push_on_evac_failure_scan_stack(oop obj);853// Process scan stack entries until the stack is empty.854void drain_evac_failure_scan_stack();855// True iff an invocation of "drain_scan_stack" is in progress; to856// prevent unnecessary recursion.857bool _drain_in_progress;858859// Do any necessary initialization for evacuation-failure handling.860// "cl" is the closure that will be used to process evac-failure861// objects.862void init_for_evac_failure(OopsInHeapRegionClosure* cl);863// Do any necessary cleanup for evacuation-failure handling data864// structures.865void finalize_for_evac_failure();866867// An attempt to evacuate "obj" has failed; take necessary steps.868oop handle_evacuation_failure_par(G1ParScanThreadState* _par_scan_state, oop obj);869void handle_evacuation_failure_common(oop obj, markOop m);870871#ifndef PRODUCT872// Support for forcing evacuation failures. Analogous to873// PromotionFailureALot for the other collectors.874875// Records whether G1EvacuationFailureALot should be in effect876// for the current GC877bool _evacuation_failure_alot_for_current_gc;878879// Used to record the GC number for interval checking when880// determining whether G1EvaucationFailureALot is in effect881// for the current GC.882size_t _evacuation_failure_alot_gc_number;883884// Count of the number of evacuations between failures.885volatile size_t _evacuation_failure_alot_count;886887// Set whether G1EvacuationFailureALot should be in effect888// for the current GC (based upon the type of GC and which889// command line flags are set);890inline bool evacuation_failure_alot_for_gc_type(bool gcs_are_young,891bool during_initial_mark,892bool during_marking);893894inline void set_evacuation_failure_alot_for_current_gc();895896// Return true if it's time to cause an evacuation failure.897inline bool evacuation_should_fail();898899// Reset the G1EvacuationFailureALot counters. Should be called at900// the end of an evacuation pause in which an evacuation failure occurred.901inline void reset_evacuation_should_fail();902#endif // !PRODUCT903904// ("Weak") Reference processing support.905//906// G1 has 2 instances of the reference processor class. One907// (_ref_processor_cm) handles reference object discovery908// and subsequent processing during concurrent marking cycles.909//910// The other (_ref_processor_stw) handles reference object911// discovery and processing during full GCs and incremental912// evacuation pauses.913//914// During an incremental pause, reference discovery will be915// temporarily disabled for _ref_processor_cm and will be916// enabled for _ref_processor_stw. At the end of the evacuation917// pause references discovered by _ref_processor_stw will be918// processed and discovery will be disabled. The previous919// setting for reference object discovery for _ref_processor_cm920// will be re-instated.921//922// At the start of marking:923// * Discovery by the CM ref processor is verified to be inactive924// and it's discovered lists are empty.925// * Discovery by the CM ref processor is then enabled.926//927// At the end of marking:928// * Any references on the CM ref processor's discovered929// lists are processed (possibly MT).930//931// At the start of full GC we:932// * Disable discovery by the CM ref processor and933// empty CM ref processor's discovered lists934// (without processing any entries).935// * Verify that the STW ref processor is inactive and it's936// discovered lists are empty.937// * Temporarily set STW ref processor discovery as single threaded.938// * Temporarily clear the STW ref processor's _is_alive_non_header939// field.940// * Finally enable discovery by the STW ref processor.941//942// The STW ref processor is used to record any discovered943// references during the full GC.944//945// At the end of a full GC we:946// * Enqueue any reference objects discovered by the STW ref processor947// that have non-live referents. This has the side-effect of948// making the STW ref processor inactive by disabling discovery.949// * Verify that the CM ref processor is still inactive950// and no references have been placed on it's discovered951// lists (also checked as a precondition during initial marking).952953// The (stw) reference processor...954ReferenceProcessor* _ref_processor_stw;955956STWGCTimer* _gc_timer_stw;957ConcurrentGCTimer* _gc_timer_cm;958959G1OldTracer* _gc_tracer_cm;960G1NewTracer* _gc_tracer_stw;961962// During reference object discovery, the _is_alive_non_header963// closure (if non-null) is applied to the referent object to964// determine whether the referent is live. If so then the965// reference object does not need to be 'discovered' and can966// be treated as a regular oop. This has the benefit of reducing967// the number of 'discovered' reference objects that need to968// be processed.969//970// Instance of the is_alive closure for embedding into the971// STW reference processor as the _is_alive_non_header field.972// Supplying a value for the _is_alive_non_header field is973// optional but doing so prevents unnecessary additions to974// the discovered lists during reference discovery.975G1STWIsAliveClosure _is_alive_closure_stw;976977// The (concurrent marking) reference processor...978ReferenceProcessor* _ref_processor_cm;979980// Instance of the concurrent mark is_alive closure for embedding981// into the Concurrent Marking reference processor as the982// _is_alive_non_header field. Supplying a value for the983// _is_alive_non_header field is optional but doing so prevents984// unnecessary additions to the discovered lists during reference985// discovery.986G1CMIsAliveClosure _is_alive_closure_cm;987988// Cache used by G1CollectedHeap::start_cset_region_for_worker().989HeapRegion** _worker_cset_start_region;990991// Time stamp to validate the regions recorded in the cache992// used by G1CollectedHeap::start_cset_region_for_worker().993// The heap region entry for a given worker is valid iff994// the associated time stamp value matches the current value995// of G1CollectedHeap::_gc_time_stamp.996uint* _worker_cset_start_region_time_stamp;997998volatile bool _free_regions_coming;9991000public:10011002void set_refine_cte_cl_concurrency(bool concurrent);10031004RefToScanQueue *task_queue(int i) const;10051006// A set of cards where updates happened during the GC1007DirtyCardQueueSet& dirty_card_queue_set() { return _dirty_card_queue_set; }10081009// A DirtyCardQueueSet that is used to hold cards that contain1010// references into the current collection set. This is used to1011// update the remembered sets of the regions in the collection1012// set in the event of an evacuation failure.1013DirtyCardQueueSet& into_cset_dirty_card_queue_set()1014{ return _into_cset_dirty_card_queue_set; }10151016// Create a G1CollectedHeap with the specified policy.1017// Must call the initialize method afterwards.1018// May not return if something goes wrong.1019G1CollectedHeap(G1CollectorPolicy* policy);10201021// Initialize the G1CollectedHeap to have the initial and1022// maximum sizes and remembered and barrier sets1023// specified by the policy object.1024jint initialize();10251026virtual void stop();10271028// Return the (conservative) maximum heap alignment for any G1 heap1029static size_t conservative_max_heap_alignment();10301031// Initialize weak reference processing.1032virtual void ref_processing_init();10331034// Explicitly import set_par_threads into this scope1035using SharedHeap::set_par_threads;1036// Set _n_par_threads according to a policy TBD.1037void set_par_threads();10381039virtual CollectedHeap::Name kind() const {1040return CollectedHeap::G1CollectedHeap;1041}10421043// The current policy object for the collector.1044G1CollectorPolicy* g1_policy() const { return _g1_policy; }10451046virtual CollectorPolicy* collector_policy() const { return (CollectorPolicy*) g1_policy(); }10471048// Adaptive size policy. No such thing for g1.1049virtual AdaptiveSizePolicy* size_policy() { return NULL; }10501051// The rem set and barrier set.1052G1RemSet* g1_rem_set() const { return _g1_rem_set; }10531054unsigned get_gc_time_stamp() {1055return _gc_time_stamp;1056}10571058inline void reset_gc_time_stamp();10591060void check_gc_time_stamps() PRODUCT_RETURN;10611062inline void increment_gc_time_stamp();10631064// Reset the given region's GC timestamp. If it's starts humongous,1065// also reset the GC timestamp of its corresponding1066// continues humongous regions too.1067void reset_gc_time_stamps(HeapRegion* hr);10681069void iterate_dirty_card_closure(CardTableEntryClosure* cl,1070DirtyCardQueue* into_cset_dcq,1071bool concurrent, uint worker_i);10721073// The shared block offset table array.1074G1BlockOffsetSharedArray* bot_shared() const { return _bot_shared; }10751076// Reference Processing accessors10771078// The STW reference processor....1079ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; }10801081// The Concurrent Marking reference processor...1082ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }10831084ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; }1085G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; }10861087virtual size_t capacity() const;1088virtual size_t used() const;1089// This should be called when we're not holding the heap lock. The1090// result might be a bit inaccurate.1091size_t used_unlocked() const;1092size_t recalculate_used() const;10931094// These virtual functions do the actual allocation.1095// Some heaps may offer a contiguous region for shared non-blocking1096// allocation, via inlined code (by exporting the address of the top and1097// end fields defining the extent of the contiguous allocation region.)1098// But G1CollectedHeap doesn't yet support this.10991100virtual bool is_maximal_no_gc() const {1101return _hrm.available() == 0;1102}11031104// The current number of regions in the heap.1105uint num_regions() const { return _hrm.length(); }11061107// The max number of regions in the heap.1108uint max_regions() const { return _hrm.max_length(); }11091110// The number of regions that are completely free.1111uint num_free_regions() const { return _hrm.num_free_regions(); }11121113MemoryUsage get_auxiliary_data_memory_usage() const {1114return _hrm.get_auxiliary_data_memory_usage();1115}11161117// The number of regions that are not completely free.1118uint num_used_regions() const { return num_regions() - num_free_regions(); }11191120void verify_not_dirty_region(HeapRegion* hr) PRODUCT_RETURN;1121void verify_dirty_region(HeapRegion* hr) PRODUCT_RETURN;1122void verify_dirty_young_list(HeapRegion* head) PRODUCT_RETURN;1123void verify_dirty_young_regions() PRODUCT_RETURN;11241125#ifndef PRODUCT1126// Make sure that the given bitmap has no marked objects in the1127// range [from,limit). If it does, print an error message and return1128// false. Otherwise, just return true. bitmap_name should be "prev"1129// or "next".1130bool verify_no_bits_over_tams(const char* bitmap_name, CMBitMapRO* bitmap,1131HeapWord* from, HeapWord* limit);11321133// Verify that the prev / next bitmap range [tams,end) for the given1134// region has no marks. Return true if all is well, false if errors1135// are detected.1136bool verify_bitmaps(const char* caller, HeapRegion* hr);1137#endif // PRODUCT11381139// If G1VerifyBitmaps is set, verify that the marking bitmaps for1140// the given region do not have any spurious marks. If errors are1141// detected, print appropriate error messages and crash.1142void check_bitmaps(const char* caller, HeapRegion* hr) PRODUCT_RETURN;11431144// If G1VerifyBitmaps is set, verify that the marking bitmaps do not1145// have any spurious marks. If errors are detected, print1146// appropriate error messages and crash.1147void check_bitmaps(const char* caller) PRODUCT_RETURN;11481149// Do sanity check on the contents of the in-cset fast test table.1150bool check_cset_fast_test() PRODUCT_RETURN_( return true; );11511152// verify_region_sets() performs verification over the region1153// lists. It will be compiled in the product code to be used when1154// necessary (i.e., during heap verification).1155void verify_region_sets();11561157// verify_region_sets_optional() is planted in the code for1158// list verification in non-product builds (and it can be enabled in1159// product builds by defining HEAP_REGION_SET_FORCE_VERIFY to be 1).1160#if HEAP_REGION_SET_FORCE_VERIFY1161void verify_region_sets_optional() {1162verify_region_sets();1163}1164#else // HEAP_REGION_SET_FORCE_VERIFY1165void verify_region_sets_optional() { }1166#endif // HEAP_REGION_SET_FORCE_VERIFY11671168#ifdef ASSERT1169bool is_on_master_free_list(HeapRegion* hr) {1170return _hrm.is_free(hr);1171}1172#endif // ASSERT11731174// Wrapper for the region list operations that can be called from1175// methods outside this class.11761177void secondary_free_list_add(FreeRegionList* list) {1178_secondary_free_list.add_ordered(list);1179}11801181void append_secondary_free_list() {1182_hrm.insert_list_into_free_list(&_secondary_free_list);1183}11841185void append_secondary_free_list_if_not_empty_with_lock() {1186// If the secondary free list looks empty there's no reason to1187// take the lock and then try to append it.1188if (!_secondary_free_list.is_empty()) {1189MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);1190append_secondary_free_list();1191}1192}11931194inline void old_set_remove(HeapRegion* hr);11951196size_t non_young_capacity_bytes() {1197return _old_set.total_capacity_bytes() + _humongous_set.total_capacity_bytes();1198}11991200void set_free_regions_coming();1201void reset_free_regions_coming();1202bool free_regions_coming() { return _free_regions_coming; }1203void wait_while_free_regions_coming();12041205// Determine whether the given region is one that we are using as an1206// old GC alloc region.1207bool is_old_gc_alloc_region(HeapRegion* hr) {1208return _allocator->is_retained_old_region(hr);1209}12101211// Perform a collection of the heap; intended for use in implementing1212// "System.gc". This probably implies as full a collection as the1213// "CollectedHeap" supports.1214virtual void collect(GCCause::Cause cause);12151216// The same as above but assume that the caller holds the Heap_lock.1217void collect_locked(GCCause::Cause cause);12181219virtual bool copy_allocation_context_stats(const jint* contexts,1220jlong* totals,1221jbyte* accuracy,1222jint len);12231224// True iff an evacuation has failed in the most-recent collection.1225bool evacuation_failed() { return _evacuation_failed; }12261227void remove_from_old_sets(const HeapRegionSetCount& old_regions_removed, const HeapRegionSetCount& humongous_regions_removed);1228void prepend_to_freelist(FreeRegionList* list);1229void decrement_summary_bytes(size_t bytes);12301231// Returns "TRUE" iff "p" points into the committed areas of the heap.1232virtual bool is_in(const void* p) const;1233#ifdef ASSERT1234// Returns whether p is in one of the available areas of the heap. Slow but1235// extensive version.1236bool is_in_exact(const void* p) const;1237#endif12381239// Return "TRUE" iff the given object address is within the collection1240// set. Slow implementation.1241inline bool obj_in_cs(oop obj);12421243inline bool is_in_cset(oop obj);12441245inline bool is_in_cset_or_humongous(const oop obj);12461247private:1248// This array is used for a quick test on whether a reference points into1249// the collection set or not. Each of the array's elements denotes whether the1250// corresponding region is in the collection set or not.1251G1InCSetStateFastTestBiasedMappedArray _in_cset_fast_test;12521253public:12541255inline InCSetState in_cset_state(const oop obj);12561257// Return "TRUE" iff the given object address is in the reserved1258// region of g1.1259bool is_in_g1_reserved(const void* p) const {1260return _hrm.reserved().contains(p);1261}12621263// Returns a MemRegion that corresponds to the space that has been1264// reserved for the heap1265MemRegion g1_reserved() const {1266return _hrm.reserved();1267}12681269virtual bool is_in_closed_subset(const void* p) const;12701271G1SATBCardTableLoggingModRefBS* g1_barrier_set() {1272return (G1SATBCardTableLoggingModRefBS*) barrier_set();1273}12741275// This resets the card table to all zeros. It is used after1276// a collection pause which used the card table to claim cards.1277void cleanUpCardTable();12781279// Iteration functions.12801281// Iterate over all the ref-containing fields of all objects, calling1282// "cl.do_oop" on each.1283virtual void oop_iterate(ExtendedOopClosure* cl);12841285// Iterate over all objects, calling "cl.do_object" on each.1286virtual void object_iterate(ObjectClosure* cl);12871288virtual void safe_object_iterate(ObjectClosure* cl) {1289object_iterate(cl);1290}12911292// Iterate over all spaces in use in the heap, in ascending address order.1293virtual void space_iterate(SpaceClosure* cl);12941295// Iterate over heap regions, in address order, terminating the1296// iteration early if the "doHeapRegion" method returns "true".1297void heap_region_iterate(HeapRegionClosure* blk) const;12981299// Return the region with the given index. It assumes the index is valid.1300inline HeapRegion* region_at(uint index) const;13011302// Calculate the region index of the given address. Given address must be1303// within the heap.1304inline uint addr_to_region(HeapWord* addr) const;13051306inline HeapWord* bottom_addr_for_region(uint index) const;13071308// Divide the heap region sequence into "chunks" of some size (the number1309// of regions divided by the number of parallel threads times some1310// overpartition factor, currently 4). Assumes that this will be called1311// in parallel by ParallelGCThreads worker threads with discinct worker1312// ids in the range [0..max(ParallelGCThreads-1, 1)], that all parallel1313// calls will use the same "claim_value", and that that claim value is1314// different from the claim_value of any heap region before the start of1315// the iteration. Applies "blk->doHeapRegion" to each of the regions, by1316// attempting to claim the first region in each chunk, and, if1317// successful, applying the closure to each region in the chunk (and1318// setting the claim value of the second and subsequent regions of the1319// chunk.) For now requires that "doHeapRegion" always returns "false",1320// i.e., that a closure never attempt to abort a traversal.1321void heap_region_par_iterate_chunked(HeapRegionClosure* cl,1322uint worker_id,1323uint num_workers,1324jint claim_value) const;13251326// It resets all the region claim values to the default.1327void reset_heap_region_claim_values();13281329// Resets the claim values of regions in the current1330// collection set to the default.1331void reset_cset_heap_region_claim_values();13321333#ifdef ASSERT1334bool check_heap_region_claim_values(jint claim_value);13351336// Same as the routine above but only checks regions in the1337// current collection set.1338bool check_cset_heap_region_claim_values(jint claim_value);1339#endif // ASSERT13401341// Clear the cached cset start regions and (more importantly)1342// the time stamps. Called when we reset the GC time stamp.1343void clear_cset_start_regions();13441345// Given the id of a worker, obtain or calculate a suitable1346// starting region for iterating over the current collection set.1347HeapRegion* start_cset_region_for_worker(uint worker_i);13481349// Iterate over the regions (if any) in the current collection set.1350void collection_set_iterate(HeapRegionClosure* blk);13511352// As above but starting from region r1353void collection_set_iterate_from(HeapRegion* r, HeapRegionClosure *blk);13541355HeapRegion* next_compaction_region(const HeapRegion* from) const;13561357// A CollectedHeap will contain some number of spaces. This finds the1358// space containing a given address, or else returns NULL.1359virtual Space* space_containing(const void* addr) const;13601361// Returns the HeapRegion that contains addr. addr must not be NULL.1362template <class T>1363inline HeapRegion* heap_region_containing_raw(const T addr) const;13641365// Returns the HeapRegion that contains addr. addr must not be NULL.1366// If addr is within a humongous continues region, it returns its humongous start region.1367template <class T>1368inline HeapRegion* heap_region_containing(const T addr) const;13691370// A CollectedHeap is divided into a dense sequence of "blocks"; that is,1371// each address in the (reserved) heap is a member of exactly1372// one block. The defining characteristic of a block is that it is1373// possible to find its size, and thus to progress forward to the next1374// block. (Blocks may be of different sizes.) Thus, blocks may1375// represent Java objects, or they might be free blocks in a1376// free-list-based heap (or subheap), as long as the two kinds are1377// distinguishable and the size of each is determinable.13781379// Returns the address of the start of the "block" that contains the1380// address "addr". We say "blocks" instead of "object" since some heaps1381// may not pack objects densely; a chunk may either be an object or a1382// non-object.1383virtual HeapWord* block_start(const void* addr) const;13841385// Requires "addr" to be the start of a chunk, and returns its size.1386// "addr + size" is required to be the start of a new chunk, or the end1387// of the active area of the heap.1388virtual size_t block_size(const HeapWord* addr) const;13891390// Requires "addr" to be the start of a block, and returns "TRUE" iff1391// the block is an object.1392virtual bool block_is_obj(const HeapWord* addr) const;13931394// Does this heap support heap inspection? (+PrintClassHistogram)1395virtual bool supports_heap_inspection() const { return true; }13961397// Section on thread-local allocation buffers (TLABs)1398// See CollectedHeap for semantics.13991400bool supports_tlab_allocation() const;1401size_t tlab_capacity(Thread* ignored) const;1402size_t tlab_used(Thread* ignored) const;1403size_t max_tlab_size() const;1404size_t unsafe_max_tlab_alloc(Thread* ignored) const;14051406// Can a compiler initialize a new object without store barriers?1407// This permission only extends from the creation of a new object1408// via a TLAB up to the first subsequent safepoint. If such permission1409// is granted for this heap type, the compiler promises to call1410// defer_store_barrier() below on any slow path allocation of1411// a new object for which such initializing store barriers will1412// have been elided. G1, like CMS, allows this, but should be1413// ready to provide a compensating write barrier as necessary1414// if that storage came out of a non-young region. The efficiency1415// of this implementation depends crucially on being able to1416// answer very efficiently in constant time whether a piece of1417// storage in the heap comes from a young region or not.1418// See ReduceInitialCardMarks.1419virtual bool can_elide_tlab_store_barriers() const {1420return true;1421}14221423virtual bool card_mark_must_follow_store() const {1424return true;1425}14261427inline bool is_in_young(const oop obj);14281429#ifdef ASSERT1430virtual bool is_in_partial_collection(const void* p);1431#endif14321433virtual bool is_scavengable(const void* addr);14341435// We don't need barriers for initializing stores to objects1436// in the young gen: for the SATB pre-barrier, there is no1437// pre-value that needs to be remembered; for the remembered-set1438// update logging post-barrier, we don't maintain remembered set1439// information for young gen objects.1440virtual inline bool can_elide_initializing_store_barrier(oop new_obj);14411442// Returns "true" iff the given word_size is "very large".1443static bool isHumongous(size_t word_size) {1444// Note this has to be strictly greater-than as the TLABs1445// are capped at the humongous thresold and we want to1446// ensure that we don't try to allocate a TLAB as1447// humongous and that we don't allocate a humongous1448// object in a TLAB.1449return word_size > _humongous_object_threshold_in_words;1450}14511452// Update mod union table with the set of dirty cards.1453void updateModUnion();14541455// Set the mod union bits corresponding to the given memRegion. Note1456// that this is always a safe operation, since it doesn't clear any1457// bits.1458void markModUnionRange(MemRegion mr);14591460// Records the fact that a marking phase is no longer in progress.1461void set_marking_complete() {1462_mark_in_progress = false;1463}1464void set_marking_started() {1465_mark_in_progress = true;1466}1467bool mark_in_progress() {1468return _mark_in_progress;1469}14701471// Print the maximum heap capacity.1472virtual size_t max_capacity() const;14731474virtual jlong millis_since_last_gc();147514761477// Convenience function to be used in situations where the heap type can be1478// asserted to be this type.1479static G1CollectedHeap* heap();14801481void set_region_short_lived_locked(HeapRegion* hr);1482// add appropriate methods for any other surv rate groups14831484YoungList* young_list() const { return _young_list; }14851486// debugging1487bool check_young_list_well_formed() {1488return _young_list->check_list_well_formed();1489}14901491bool check_young_list_empty(bool check_heap,1492bool check_sample = true);14931494// *** Stuff related to concurrent marking. It's not clear to me that so1495// many of these need to be public.14961497// The functions below are helper functions that a subclass of1498// "CollectedHeap" can use in the implementation of its virtual1499// functions.1500// This performs a concurrent marking of the live objects in a1501// bitmap off to the side.1502void doConcurrentMark();15031504bool isMarkedPrev(oop obj) const;1505bool isMarkedNext(oop obj) const;15061507// Determine if an object is dead, given the object and also1508// the region to which the object belongs. An object is dead1509// iff a) it was not allocated since the last mark and b) it1510// is not marked.1511bool is_obj_dead(const oop obj, const HeapRegion* hr) const {1512return1513!hr->obj_allocated_since_prev_marking(obj) &&1514!isMarkedPrev(obj);1515}15161517// This function returns true when an object has been1518// around since the previous marking and hasn't yet1519// been marked during this marking.1520bool is_obj_ill(const oop obj, const HeapRegion* hr) const {1521return1522!hr->obj_allocated_since_next_marking(obj) &&1523!isMarkedNext(obj);1524}15251526// Determine if an object is dead, given only the object itself.1527// This will find the region to which the object belongs and1528// then call the region version of the same function.15291530// Added if it is NULL it isn't dead.15311532inline bool is_obj_dead(const oop obj) const;15331534inline bool is_obj_ill(const oop obj) const;15351536bool allocated_since_marking(oop obj, HeapRegion* hr, VerifyOption vo);1537HeapWord* top_at_mark_start(HeapRegion* hr, VerifyOption vo);1538bool is_marked(oop obj, VerifyOption vo);1539const char* top_at_mark_start_str(VerifyOption vo);15401541ConcurrentMark* concurrent_mark() const { return _cm; }15421543// Refinement15441545ConcurrentG1Refine* concurrent_g1_refine() const { return _cg1r; }15461547// The dirty cards region list is used to record a subset of regions1548// whose cards need clearing. The list if populated during the1549// remembered set scanning and drained during the card table1550// cleanup. Although the methods are reentrant, population/draining1551// phases must not overlap. For synchronization purposes the last1552// element on the list points to itself.1553HeapRegion* _dirty_cards_region_list;1554void push_dirty_cards_region(HeapRegion* hr);1555HeapRegion* pop_dirty_cards_region();15561557// Optimized nmethod scanning support routines15581559// Register the given nmethod with the G1 heap1560virtual void register_nmethod(nmethod* nm);15611562// Unregister the given nmethod from the G1 heap1563virtual void unregister_nmethod(nmethod* nm);15641565// Free up superfluous code root memory.1566void purge_code_root_memory();15671568// Rebuild the stong code root lists for each region1569// after a full GC1570void rebuild_strong_code_roots();15711572// Delete entries for dead interned string and clean up unreferenced symbols1573// in symbol table, possibly in parallel.1574void unlink_string_and_symbol_table(BoolObjectClosure* is_alive, bool unlink_strings = true, bool unlink_symbols = true);15751576// Parallel phase of unloading/cleaning after G1 concurrent mark.1577void parallel_cleaning(BoolObjectClosure* is_alive, bool process_strings, bool process_symbols, bool class_unloading_occurred);15781579// Redirty logged cards in the refinement queue.1580void redirty_logged_cards();1581// Verification15821583// The following is just to alert the verification code1584// that a full collection has occurred and that the1585// remembered sets are no longer up to date.1586bool _full_collection;1587void set_full_collection() { _full_collection = true;}1588void clear_full_collection() {_full_collection = false;}1589bool full_collection() {return _full_collection;}15901591// Perform any cleanup actions necessary before allowing a verification.1592virtual void prepare_for_verify();15931594// Perform verification.15951596// vo == UsePrevMarking -> use "prev" marking information,1597// vo == UseNextMarking -> use "next" marking information1598// vo == UseMarkWord -> use the mark word in the object header1599//1600// NOTE: Only the "prev" marking information is guaranteed to be1601// consistent most of the time, so most calls to this should use1602// vo == UsePrevMarking.1603// Currently, there is only one case where this is called with1604// vo == UseNextMarking, which is to verify the "next" marking1605// information at the end of remark.1606// Currently there is only one place where this is called with1607// vo == UseMarkWord, which is to verify the marking during a1608// full GC.1609void verify(bool silent, VerifyOption vo);16101611// Override; it uses the "prev" marking information1612virtual void verify(bool silent);16131614// The methods below are here for convenience and dispatch the1615// appropriate method depending on value of the given VerifyOption1616// parameter. The values for that parameter, and their meanings,1617// are the same as those above.16181619bool is_obj_dead_cond(const oop obj,1620const HeapRegion* hr,1621const VerifyOption vo) const;16221623bool is_obj_dead_cond(const oop obj,1624const VerifyOption vo) const;16251626G1HeapSummary create_g1_heap_summary();16271628// Printing16291630virtual void print_on(outputStream* st) const;1631virtual void print_extended_on(outputStream* st) const;1632virtual void print_on_error(outputStream* st) const;16331634virtual void print_gc_threads_on(outputStream* st) const;1635virtual void gc_threads_do(ThreadClosure* tc) const;16361637// Override1638void print_tracing_info() const;16391640// The following two methods are helpful for debugging RSet issues.1641void print_cset_rsets() PRODUCT_RETURN;1642void print_all_rsets() PRODUCT_RETURN;16431644public:1645size_t pending_card_num();1646size_t cards_scanned();16471648protected:1649size_t _max_heap_capacity;1650};16511652#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP165316541655