Path: blob/master/src/hotspot/share/gc/g1/g1CollectedHeap.hpp
40959 views
/*1* Copyright (c) 2001, 2021, 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_GC_G1_G1COLLECTEDHEAP_HPP25#define SHARE_GC_G1_G1COLLECTEDHEAP_HPP2627#include "gc/g1/g1BarrierSet.hpp"28#include "gc/g1/g1BiasedArray.hpp"29#include "gc/g1/g1CardTable.hpp"30#include "gc/g1/g1CollectionSet.hpp"31#include "gc/g1/g1CollectorState.hpp"32#include "gc/g1/g1ConcurrentMark.hpp"33#include "gc/g1/g1EdenRegions.hpp"34#include "gc/g1/g1EvacFailure.hpp"35#include "gc/g1/g1EvacStats.hpp"36#include "gc/g1/g1EvacuationInfo.hpp"37#include "gc/g1/g1GCPhaseTimes.hpp"38#include "gc/g1/g1GCPauseType.hpp"39#include "gc/g1/g1HeapTransition.hpp"40#include "gc/g1/g1HeapVerifier.hpp"41#include "gc/g1/g1HRPrinter.hpp"42#include "gc/g1/g1HeapRegionAttr.hpp"43#include "gc/g1/g1MonitoringSupport.hpp"44#include "gc/g1/g1NUMA.hpp"45#include "gc/g1/g1RedirtyCardsQueue.hpp"46#include "gc/g1/g1SurvivorRegions.hpp"47#include "gc/g1/heapRegionManager.hpp"48#include "gc/g1/heapRegionSet.hpp"49#include "gc/shared/barrierSet.hpp"50#include "gc/shared/collectedHeap.hpp"51#include "gc/shared/gcHeapSummary.hpp"52#include "gc/shared/plab.hpp"53#include "gc/shared/preservedMarks.hpp"54#include "gc/shared/softRefPolicy.hpp"55#include "gc/shared/taskqueue.hpp"56#include "memory/memRegion.hpp"57#include "utilities/stack.hpp"5859// A "G1CollectedHeap" is an implementation of a java heap for HotSpot.60// It uses the "Garbage First" heap organization and algorithm, which61// may combine concurrent marking with parallel, incremental compaction of62// heap subsets that will yield large amounts of garbage.6364// Forward declarations65class HeapRegion;66class GenerationSpec;67class G1ParScanThreadState;68class G1ParScanThreadStateSet;69class G1ParScanThreadState;70class MemoryPool;71class MemoryManager;72class ObjectClosure;73class SpaceClosure;74class CompactibleSpaceClosure;75class Space;76class G1BatchedGangTask;77class G1CardTableEntryClosure;78class G1CollectionSet;79class G1Policy;80class G1HotCardCache;81class G1RemSet;82class G1ServiceTask;83class G1ServiceThread;84class G1ConcurrentMark;85class G1ConcurrentMarkThread;86class G1ConcurrentRefine;87class GenerationCounters;88class STWGCTimer;89class G1NewTracer;90class EvacuationFailedInfo;91class nmethod;92class WorkGang;93class G1Allocator;94class G1ArchiveAllocator;95class G1FullGCScope;96class G1HeapVerifier;97class G1HeapSizingPolicy;98class G1HeapSummary;99class G1EvacSummary;100101typedef OverflowTaskQueue<ScannerTask, mtGC> G1ScannerTasksQueue;102typedef GenericTaskQueueSet<G1ScannerTasksQueue, mtGC> G1ScannerTasksQueueSet;103104typedef int RegionIdx_t; // needs to hold [ 0..max_reserved_regions() )105typedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion )106107// The G1 STW is alive closure.108// An instance is embedded into the G1CH and used as the109// (optional) _is_alive_non_header closure in the STW110// reference processor. It is also extensively used during111// reference processing during STW evacuation pauses.112class G1STWIsAliveClosure : public BoolObjectClosure {113G1CollectedHeap* _g1h;114public:115G1STWIsAliveClosure(G1CollectedHeap* g1h) : _g1h(g1h) {}116bool do_object_b(oop p);117};118119class G1STWSubjectToDiscoveryClosure : public BoolObjectClosure {120G1CollectedHeap* _g1h;121public:122G1STWSubjectToDiscoveryClosure(G1CollectedHeap* g1h) : _g1h(g1h) {}123bool do_object_b(oop p);124};125126class G1RegionMappingChangedListener : public G1MappingChangedListener {127private:128void reset_from_card_cache(uint start_idx, size_t num_regions);129public:130virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);131};132133class G1CollectedHeap : public CollectedHeap {134friend class VM_CollectForMetadataAllocation;135friend class VM_G1CollectForAllocation;136friend class VM_G1CollectFull;137friend class VM_G1TryInitiateConcMark;138friend class VMStructs;139friend class MutatorAllocRegion;140friend class G1FullCollector;141friend class G1GCAllocRegion;142friend class G1HeapVerifier;143144// Closures used in implementation.145friend class G1ParScanThreadState;146friend class G1ParScanThreadStateSet;147friend class G1EvacuateRegionsTask;148friend class G1PLABAllocator;149150// Other related classes.151friend class HeapRegionClaimer;152153// Testing classes.154friend class G1CheckRegionAttrTableClosure;155156private:157G1ServiceThread* _service_thread;158G1ServiceTask* _periodic_gc_task;159160WorkGang* _workers;161G1CardTable* _card_table;162163Ticks _collection_pause_end;164165SoftRefPolicy _soft_ref_policy;166167static size_t _humongous_object_threshold_in_words;168169// These sets keep track of old, archive and humongous regions respectively.170HeapRegionSet _old_set;171HeapRegionSet _archive_set;172HeapRegionSet _humongous_set;173174void rebuild_free_region_list();175// Start a new incremental collection set for the next pause.176void start_new_collection_set();177178// The block offset table for the G1 heap.179G1BlockOffsetTable* _bot;180181public:182void prepare_region_for_full_compaction(HeapRegion* hr);183184private:185// Rebuilds the region sets / lists so that they are repopulated to186// reflect the contents of the heap. The only exception is the187// humongous set which was not torn down in the first place. If188// free_list_only is true, it will only rebuild the free list.189void rebuild_region_sets(bool free_list_only);190191// Callback for region mapping changed events.192G1RegionMappingChangedListener _listener;193194// Handle G1 NUMA support.195G1NUMA* _numa;196197// The sequence of all heap regions in the heap.198HeapRegionManager _hrm;199200// Manages all allocations with regions except humongous object allocations.201G1Allocator* _allocator;202203// Manages all heap verification.204G1HeapVerifier* _verifier;205206// Outside of GC pauses, the number of bytes used in all regions other207// than the current allocation region(s).208volatile size_t _summary_bytes_used;209210void increase_used(size_t bytes);211void decrease_used(size_t bytes);212213void set_used(size_t bytes);214215// Number of bytes used in all regions during GC. Typically changed when216// retiring a GC alloc region.217size_t _bytes_used_during_gc;218219// Class that handles archive allocation ranges.220G1ArchiveAllocator* _archive_allocator;221222// GC allocation statistics policy for survivors.223G1EvacStats _survivor_evac_stats;224225// GC allocation statistics policy for tenured objects.226G1EvacStats _old_evac_stats;227228// It specifies whether we should attempt to expand the heap after a229// region allocation failure. If heap expansion fails we set this to230// false so that we don't re-attempt the heap expansion (it's likely231// that subsequent expansion attempts will also fail if one fails).232// Currently, it is only consulted during GC and it's reset at the233// start of each GC.234bool _expand_heap_after_alloc_failure;235236// Helper for monitoring and management support.237G1MonitoringSupport* _g1mm;238239// Records whether the region at the given index is (still) a240// candidate for eager reclaim. Only valid for humongous start241// regions; other regions have unspecified values. Humongous start242// regions are initialized at start of collection pause, with243// candidates removed from the set as they are found reachable from244// roots or the young generation.245class HumongousReclaimCandidates : public G1BiasedMappedArray<bool> {246protected:247bool default_value() const { return false; }248public:249void clear() { G1BiasedMappedArray<bool>::clear(); }250void set_candidate(uint region, bool value) {251set_by_index(region, value);252}253bool is_candidate(uint region) {254return get_by_index(region);255}256};257258HumongousReclaimCandidates _humongous_reclaim_candidates;259uint _num_humongous_objects; // Current amount of (all) humongous objects found in the heap.260uint _num_humongous_reclaim_candidates; // Number of humongous object eager reclaim candidates.261public:262uint num_humongous_objects() const { return _num_humongous_objects; }263uint num_humongous_reclaim_candidates() const { return _num_humongous_reclaim_candidates; }264bool has_humongous_reclaim_candidates() const { return _num_humongous_reclaim_candidates > 0; }265266bool should_do_eager_reclaim() const;267268private:269270G1HRPrinter _hr_printer;271272// Return true if an explicit GC should start a concurrent cycle instead273// of doing a STW full GC. A concurrent cycle should be started if:274// (a) cause == _g1_humongous_allocation,275// (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent,276// (c) cause == _dcmd_gc_run and +ExplicitGCInvokesConcurrent,277// (d) cause == _wb_conc_mark or _wb_breakpoint,278// (e) cause == _g1_periodic_collection and +G1PeriodicGCInvokesConcurrent.279bool should_do_concurrent_full_gc(GCCause::Cause cause);280281// Attempt to start a concurrent cycle with the indicated cause.282// precondition: should_do_concurrent_full_gc(cause)283bool try_collect_concurrently(GCCause::Cause cause,284uint gc_counter,285uint old_marking_started_before);286287// Return true if should upgrade to full gc after an incremental one.288bool should_upgrade_to_full_gc(GCCause::Cause cause);289290// indicates whether we are in young or mixed GC mode291G1CollectorState _collector_state;292293// Keeps track of how many "old marking cycles" (i.e., Full GCs or294// concurrent cycles) we have started.295volatile uint _old_marking_cycles_started;296297// Keeps track of how many "old marking cycles" (i.e., Full GCs or298// concurrent cycles) we have completed.299volatile uint _old_marking_cycles_completed;300301// This is a non-product method that is helpful for testing. It is302// called at the end of a GC and artificially expands the heap by303// allocating a number of dead regions. This way we can induce very304// frequent marking cycles and stress the cleanup / concurrent305// cleanup code more (as all the regions that will be allocated by306// this method will be found dead by the marking cycle).307void allocate_dummy_regions() PRODUCT_RETURN;308309// If the HR printer is active, dump the state of the regions in the310// heap after a compaction.311void print_hrm_post_compaction();312313// Create a memory mapper for auxiliary data structures of the given size and314// translation factor.315static G1RegionToSpaceMapper* create_aux_memory_mapper(const char* description,316size_t size,317size_t translation_factor);318319void trace_heap(GCWhen::Type when, const GCTracer* tracer);320321// These are macros so that, if the assert fires, we get the correct322// line number, file, etc.323324#define heap_locking_asserts_params(_extra_message_) \325"%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \326(_extra_message_), \327BOOL_TO_STR(Heap_lock->owned_by_self()), \328BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), \329BOOL_TO_STR(Thread::current()->is_VM_thread())330331#define assert_heap_locked() \332do { \333assert(Heap_lock->owned_by_self(), \334heap_locking_asserts_params("should be holding the Heap_lock")); \335} while (0)336337#define assert_heap_locked_or_at_safepoint(_should_be_vm_thread_) \338do { \339assert(Heap_lock->owned_by_self() || \340(SafepointSynchronize::is_at_safepoint() && \341((_should_be_vm_thread_) == Thread::current()->is_VM_thread())), \342heap_locking_asserts_params("should be holding the Heap_lock or " \343"should be at a safepoint")); \344} while (0)345346#define assert_heap_locked_and_not_at_safepoint() \347do { \348assert(Heap_lock->owned_by_self() && \349!SafepointSynchronize::is_at_safepoint(), \350heap_locking_asserts_params("should be holding the Heap_lock and " \351"should not be at a safepoint")); \352} while (0)353354#define assert_heap_not_locked() \355do { \356assert(!Heap_lock->owned_by_self(), \357heap_locking_asserts_params("should not be holding the Heap_lock")); \358} while (0)359360#define assert_heap_not_locked_and_not_at_safepoint() \361do { \362assert(!Heap_lock->owned_by_self() && \363!SafepointSynchronize::is_at_safepoint(), \364heap_locking_asserts_params("should not be holding the Heap_lock and " \365"should not be at a safepoint")); \366} while (0)367368#define assert_at_safepoint_on_vm_thread() \369do { \370assert_at_safepoint(); \371assert(Thread::current_or_null() != NULL, "no current thread"); \372assert(Thread::current()->is_VM_thread(), "current thread is not VM thread"); \373} while (0)374375#ifdef ASSERT376#define assert_used_and_recalculate_used_equal(g1h) \377do { \378size_t cur_used_bytes = g1h->used(); \379size_t recal_used_bytes = g1h->recalculate_used(); \380assert(cur_used_bytes == recal_used_bytes, "Used(" SIZE_FORMAT ") is not" \381" same as recalculated used(" SIZE_FORMAT ").", \382cur_used_bytes, recal_used_bytes); \383} while (0)384#else385#define assert_used_and_recalculate_used_equal(g1h) do {} while(0)386#endif387388static const uint MaxYoungGCNameLength = 128;389// Sets given young_gc_name to the canonical young gc pause string. Young_gc_name390// must be at least of length MaxYoungGCNameLength.391void set_young_gc_name(char* young_gc_name);392393// The young region list.394G1EdenRegions _eden;395G1SurvivorRegions _survivor;396397STWGCTimer* _gc_timer_stw;398399G1NewTracer* _gc_tracer_stw;400401void gc_tracer_report_gc_start();402void gc_tracer_report_gc_end(bool concurrent_operation_is_full_mark, G1EvacuationInfo& evacuation_info);403404// The current policy object for the collector.405G1Policy* _policy;406G1HeapSizingPolicy* _heap_sizing_policy;407408G1CollectionSet _collection_set;409410// Try to allocate a single non-humongous HeapRegion sufficient for411// an allocation of the given word_size. If do_expand is true,412// attempt to expand the heap if necessary to satisfy the allocation413// request. 'type' takes the type of region to be allocated. (Use constants414// Old, Eden, Humongous, Survivor defined in HeapRegionType.)415HeapRegion* new_region(size_t word_size,416HeapRegionType type,417bool do_expand,418uint node_index = G1NUMA::AnyNodeIndex);419420// Initialize a contiguous set of free regions of length num_regions421// and starting at index first so that they appear as a single422// humongous region.423HeapWord* humongous_obj_allocate_initialize_regions(HeapRegion* first_hr,424uint num_regions,425size_t word_size);426427// Attempt to allocate a humongous object of the given size. Return428// NULL if unsuccessful.429HeapWord* humongous_obj_allocate(size_t word_size);430431// The following two methods, allocate_new_tlab() and432// mem_allocate(), are the two main entry points from the runtime433// into the G1's allocation routines. They have the following434// assumptions:435//436// * They should both be called outside safepoints.437//438// * They should both be called without holding the Heap_lock.439//440// * All allocation requests for new TLABs should go to441// allocate_new_tlab().442//443// * All non-TLAB allocation requests should go to mem_allocate().444//445// * If either call cannot satisfy the allocation request using the446// current allocating region, they will try to get a new one. If447// this fails, they will attempt to do an evacuation pause and448// retry the allocation.449//450// * If all allocation attempts fail, even after trying to schedule451// an evacuation pause, allocate_new_tlab() will return NULL,452// whereas mem_allocate() will attempt a heap expansion and/or453// schedule a Full GC.454//455// * We do not allow humongous-sized TLABs. So, allocate_new_tlab456// should never be called with word_size being humongous. All457// humongous allocation requests should go to mem_allocate() which458// will satisfy them with a special path.459460virtual HeapWord* allocate_new_tlab(size_t min_size,461size_t requested_size,462size_t* actual_size);463464virtual HeapWord* mem_allocate(size_t word_size,465bool* gc_overhead_limit_was_exceeded);466467// First-level mutator allocation attempt: try to allocate out of468// the mutator alloc region without taking the Heap_lock. This469// should only be used for non-humongous allocations.470inline HeapWord* attempt_allocation(size_t min_word_size,471size_t desired_word_size,472size_t* actual_word_size);473474// Second-level mutator allocation attempt: take the Heap_lock and475// retry the allocation attempt, potentially scheduling a GC476// pause. This should only be used for non-humongous allocations.477HeapWord* attempt_allocation_slow(size_t word_size);478479// Takes the Heap_lock and attempts a humongous allocation. It can480// potentially schedule a GC pause.481HeapWord* attempt_allocation_humongous(size_t word_size);482483// Allocation attempt that should be called during safepoints (e.g.,484// at the end of a successful GC). expect_null_mutator_alloc_region485// specifies whether the mutator alloc region is expected to be NULL486// or not.487HeapWord* attempt_allocation_at_safepoint(size_t word_size,488bool expect_null_mutator_alloc_region);489490// These methods are the "callbacks" from the G1AllocRegion class.491492// For mutator alloc regions.493HeapRegion* new_mutator_alloc_region(size_t word_size, bool force, uint node_index);494void retire_mutator_alloc_region(HeapRegion* alloc_region,495size_t allocated_bytes);496497// For GC alloc regions.498bool has_more_regions(G1HeapRegionAttr dest);499HeapRegion* new_gc_alloc_region(size_t word_size, G1HeapRegionAttr dest, uint node_index);500void retire_gc_alloc_region(HeapRegion* alloc_region,501size_t allocated_bytes, G1HeapRegionAttr dest);502503// - if explicit_gc is true, the GC is for a System.gc() etc,504// otherwise it's for a failed allocation.505// - if clear_all_soft_refs is true, all soft references should be506// cleared during the GC.507// - if do_maximum_compaction is true, full gc will do a maximally508// compacting collection, leaving no dead wood.509// - it returns false if it is unable to do the collection due to the510// GC locker being active, true otherwise.511bool do_full_collection(bool explicit_gc,512bool clear_all_soft_refs,513bool do_maximum_compaction);514515// Callback from VM_G1CollectFull operation, or collect_as_vm_thread.516virtual void do_full_collection(bool clear_all_soft_refs);517518// Callback from VM_G1CollectForAllocation operation.519// This function does everything necessary/possible to satisfy a520// failed allocation request (including collection, expansion, etc.)521HeapWord* satisfy_failed_allocation(size_t word_size,522bool* succeeded);523// Internal helpers used during full GC to split it up to524// increase readability.525void abort_concurrent_cycle();526void verify_before_full_collection(bool explicit_gc);527void prepare_heap_for_full_collection();528void prepare_heap_for_mutators();529void abort_refinement();530void verify_after_full_collection();531void print_heap_after_full_collection(G1HeapTransition* heap_transition);532533// Helper method for satisfy_failed_allocation()534HeapWord* satisfy_failed_allocation_helper(size_t word_size,535bool do_gc,536bool clear_all_soft_refs,537bool expect_null_mutator_alloc_region,538bool* gc_succeeded);539540// Attempting to expand the heap sufficiently541// to support an allocation of the given "word_size". If542// successful, perform the allocation and return the address of the543// allocated block, or else "NULL".544HeapWord* expand_and_allocate(size_t word_size);545546// Process any reference objects discovered.547void process_discovered_references(G1ParScanThreadStateSet* per_thread_states);548549// If during a concurrent start pause we may install a pending list head which is not550// otherwise reachable, ensure that it is marked in the bitmap for concurrent marking551// to discover.552void make_pending_list_reachable();553554void verify_numa_regions(const char* desc);555556public:557G1ServiceThread* service_thread() const { return _service_thread; }558559WorkGang* workers() const { return _workers; }560561// Runs the given AbstractGangTask with the current active workers,562// returning the total time taken.563Tickspan run_task_timed(AbstractGangTask* task);564// Run the given batch task using the work gang.565void run_batch_task(G1BatchedGangTask* cl);566567G1Allocator* allocator() {568return _allocator;569}570571G1HeapVerifier* verifier() {572return _verifier;573}574575G1MonitoringSupport* g1mm() {576assert(_g1mm != NULL, "should have been initialized");577return _g1mm;578}579580void resize_heap_if_necessary();581582// Check if there is memory to uncommit and if so schedule a task to do it.583void uncommit_regions_if_necessary();584// Immediately uncommit uncommittable regions.585uint uncommit_regions(uint region_limit);586bool has_uncommittable_regions();587588G1NUMA* numa() const { return _numa; }589590// Expand the garbage-first heap by at least the given size (in bytes!).591// Returns true if the heap was expanded by the requested amount;592// false otherwise.593// (Rounds up to a HeapRegion boundary.)594bool expand(size_t expand_bytes, WorkGang* pretouch_workers = NULL, double* expand_time_ms = NULL);595bool expand_single_region(uint node_index);596597// Returns the PLAB statistics for a given destination.598inline G1EvacStats* alloc_buffer_stats(G1HeapRegionAttr dest);599600// Determines PLAB size for a given destination.601inline size_t desired_plab_sz(G1HeapRegionAttr dest);602603// Do anything common to GC's.604void gc_prologue(bool full);605void gc_epilogue(bool full);606607// Does the given region fulfill remembered set based eager reclaim candidate requirements?608bool is_potential_eager_reclaim_candidate(HeapRegion* r) const;609610// Modify the reclaim candidate set and test for presence.611// These are only valid for starts_humongous regions.612inline void set_humongous_reclaim_candidate(uint region, bool value);613inline bool is_humongous_reclaim_candidate(uint region);614615// Remove from the reclaim candidate set. Also remove from the616// collection set so that later encounters avoid the slow path.617inline void set_humongous_is_live(oop obj);618619// Register the given region to be part of the collection set.620inline void register_humongous_region_with_region_attr(uint index);621622// We register a region with the fast "in collection set" test. We623// simply set to true the array slot corresponding to this region.624void register_young_region_with_region_attr(HeapRegion* r) {625_region_attr.set_in_young(r->hrm_index());626}627inline void register_region_with_region_attr(HeapRegion* r);628inline void register_old_region_with_region_attr(HeapRegion* r);629inline void register_optional_region_with_region_attr(HeapRegion* r);630631void clear_region_attr(const HeapRegion* hr) {632_region_attr.clear(hr);633}634635void clear_region_attr() {636_region_attr.clear();637}638639// Verify that the G1RegionAttr remset tracking corresponds to actual remset tracking640// for all regions.641void verify_region_attr_remset_update() PRODUCT_RETURN;642643bool is_user_requested_concurrent_full_gc(GCCause::Cause cause);644645// This is called at the start of either a concurrent cycle or a Full646// GC to update the number of old marking cycles started.647void increment_old_marking_cycles_started();648649// This is called at the end of either a concurrent cycle or a Full650// GC to update the number of old marking cycles completed. Those two651// can happen in a nested fashion, i.e., we start a concurrent652// cycle, a Full GC happens half-way through it which ends first,653// and then the cycle notices that a Full GC happened and ends654// too. The concurrent parameter is a boolean to help us do a bit655// tighter consistency checking in the method. If concurrent is656// false, the caller is the inner caller in the nesting (i.e., the657// Full GC). If concurrent is true, the caller is the outer caller658// in this nesting (i.e., the concurrent cycle). Further nesting is659// not currently supported. The end of this call also notifies660// the G1OldGCCount_lock in case a Java thread is waiting for a full661// GC to happen (e.g., it called System.gc() with662// +ExplicitGCInvokesConcurrent).663// whole_heap_examined should indicate that during that old marking664// cycle the whole heap has been examined for live objects (as opposed665// to only parts, or aborted before completion).666void increment_old_marking_cycles_completed(bool concurrent, bool whole_heap_examined);667668uint old_marking_cycles_completed() {669return _old_marking_cycles_completed;670}671672G1HRPrinter* hr_printer() { return &_hr_printer; }673674// Allocates a new heap region instance.675HeapRegion* new_heap_region(uint hrs_index, MemRegion mr);676677// Allocate the highest free region in the reserved heap. This will commit678// regions as necessary.679HeapRegion* alloc_highest_free_region();680681// Frees a region by resetting its metadata and adding it to the free list682// passed as a parameter (this is usually a local list which will be appended683// to the master free list later or NULL if free list management is handled684// in another way).685// Callers must ensure they are the only one calling free on the given region686// at the same time.687void free_region(HeapRegion* hr, FreeRegionList* free_list);688689// It dirties the cards that cover the block so that the post690// write barrier never queues anything when updating objects on this691// block. It is assumed (and in fact we assert) that the block692// belongs to a young region.693inline void dirty_young_block(HeapWord* start, size_t word_size);694695// Frees a humongous region by collapsing it into individual regions696// and calling free_region() for each of them. The freed regions697// will be added to the free list that's passed as a parameter (this698// is usually a local list which will be appended to the master free699// list later).700// The method assumes that only a single thread is ever calling701// this for a particular region at once.702void free_humongous_region(HeapRegion* hr,703FreeRegionList* free_list);704705// Facility for allocating in 'archive' regions in high heap memory and706// recording the allocated ranges. These should all be called from the707// VM thread at safepoints, without the heap lock held. They can be used708// to create and archive a set of heap regions which can be mapped at the709// same fixed addresses in a subsequent JVM invocation.710void begin_archive_alloc_range(bool open = false);711712// Check if the requested size would be too large for an archive allocation.713bool is_archive_alloc_too_large(size_t word_size);714715// Allocate memory of the requested size from the archive region. This will716// return NULL if the size is too large or if no memory is available. It717// does not trigger a garbage collection.718HeapWord* archive_mem_allocate(size_t word_size);719720// Optionally aligns the end address and returns the allocated ranges in721// an array of MemRegions in order of ascending addresses.722void end_archive_alloc_range(GrowableArray<MemRegion>* ranges,723size_t end_alignment_in_bytes = 0);724725// Facility for allocating a fixed range within the heap and marking726// the containing regions as 'archive'. For use at JVM init time, when the727// caller may mmap archived heap data at the specified range(s).728// Verify that the MemRegions specified in the argument array are within the729// reserved heap.730bool check_archive_addresses(MemRegion* range, size_t count);731732// Commit the appropriate G1 regions containing the specified MemRegions733// and mark them as 'archive' regions. The regions in the array must be734// non-overlapping and in order of ascending address.735bool alloc_archive_regions(MemRegion* range, size_t count, bool open);736737// Insert any required filler objects in the G1 regions around the specified738// ranges to make the regions parseable. This must be called after739// alloc_archive_regions, and after class loading has occurred.740void fill_archive_regions(MemRegion* range, size_t count);741742// Populate the G1BlockOffsetTablePart for archived regions with the given743// memory ranges.744void populate_archive_regions_bot_part(MemRegion* range, size_t count);745746// For each of the specified MemRegions, uncommit the containing G1 regions747// which had been allocated by alloc_archive_regions. This should be called748// rather than fill_archive_regions at JVM init time if the archive file749// mapping failed, with the same non-overlapping and sorted MemRegion array.750void dealloc_archive_regions(MemRegion* range, size_t count);751752private:753754// Shrink the garbage-first heap by at most the given size (in bytes!).755// (Rounds down to a HeapRegion boundary.)756void shrink(size_t shrink_bytes);757void shrink_helper(size_t expand_bytes);758759#if TASKQUEUE_STATS760static void print_taskqueue_stats_hdr(outputStream* const st);761void print_taskqueue_stats() const;762void reset_taskqueue_stats();763#endif // TASKQUEUE_STATS764765// Start a concurrent cycle.766void start_concurrent_cycle(bool concurrent_operation_is_full_mark);767768// Schedule the VM operation that will do an evacuation pause to769// satisfy an allocation request of word_size. *succeeded will770// return whether the VM operation was successful (it did do an771// evacuation pause) or not (another thread beat us to it or the GC772// locker was active). Given that we should not be holding the773// Heap_lock when we enter this method, we will pass the774// gc_count_before (i.e., total_collections()) as a parameter since775// it has to be read while holding the Heap_lock. Currently, both776// methods that call do_collection_pause() release the Heap_lock777// before the call, so it's easy to read gc_count_before just before.778HeapWord* do_collection_pause(size_t word_size,779uint gc_count_before,780bool* succeeded,781GCCause::Cause gc_cause);782783void wait_for_root_region_scanning();784785// Perform an incremental collection at a safepoint, possibly786// followed by a by-policy upgrade to a full collection. Returns787// false if unable to do the collection due to the GC locker being788// active, true otherwise.789// precondition: at safepoint on VM thread790// precondition: !is_gc_active()791bool do_collection_pause_at_safepoint(double target_pause_time_ms);792793// Helper for do_collection_pause_at_safepoint, containing the guts794// of the incremental collection pause, executed by the vm thread.795void do_collection_pause_at_safepoint_helper(double target_pause_time_ms);796797G1HeapVerifier::G1VerifyType young_collection_verify_type() const;798void verify_before_young_collection(G1HeapVerifier::G1VerifyType type);799void verify_after_young_collection(G1HeapVerifier::G1VerifyType type);800801void calculate_collection_set(G1EvacuationInfo& evacuation_info, double target_pause_time_ms);802803// Actually do the work of evacuating the parts of the collection set.804// The has_optional_evacuation_work flag for the initial collection set805// evacuation indicates whether one or more optional evacuation steps may806// follow.807// If not set, G1 can avoid clearing the card tables of regions that we scan808// for roots from the heap: when scanning the card table for dirty cards after809// all remembered sets have been dumped onto it, for optional evacuation we810// mark these cards as "Scanned" to know that we do not need to re-scan them811// in the additional optional evacuation passes. This means that in the "Clear812// Card Table" phase we need to clear those marks. However, if there is no813// optional evacuation, g1 can immediately clean the dirty cards it encounters814// as nobody else will be looking at them again, saving the clear card table815// work later.816// This case is very common (young only collections and most mixed gcs), so817// depending on the ratio between scanned and evacuated regions (which g1 always818// needs to clear), this is a big win.819void evacuate_initial_collection_set(G1ParScanThreadStateSet* per_thread_states,820bool has_optional_evacuation_work);821void evacuate_optional_collection_set(G1ParScanThreadStateSet* per_thread_states);822private:823// Evacuate the next set of optional regions.824void evacuate_next_optional_regions(G1ParScanThreadStateSet* per_thread_states);825826public:827void pre_evacuate_collection_set(G1EvacuationInfo& evacuation_info, G1ParScanThreadStateSet* pss);828void post_evacuate_collection_set(G1EvacuationInfo& evacuation_info,829G1RedirtyCardsQueueSet* rdcqs,830G1ParScanThreadStateSet* pss);831832void expand_heap_after_young_collection();833// Update object copying statistics.834void record_obj_copy_mem_stats();835836// The hot card cache for remembered set insertion optimization.837G1HotCardCache* _hot_card_cache;838839// The g1 remembered set of the heap.840G1RemSet* _rem_set;841842void post_evacuate_cleanup_1(G1ParScanThreadStateSet* per_thread_states,843G1RedirtyCardsQueueSet* rdcqs);844void post_evacuate_cleanup_2(PreservedMarksSet* preserved_marks,845G1RedirtyCardsQueueSet* rdcqs,846G1EvacuationInfo* evacuation_info,847const size_t* surviving_young_words);848849// After a collection pause, reset eden and the collection set.850void clear_eden();851void clear_collection_set();852853// Abandon the current collection set without recording policy854// statistics or updating free lists.855void abandon_collection_set(G1CollectionSet* collection_set);856857// The concurrent marker (and the thread it runs in.)858G1ConcurrentMark* _cm;859G1ConcurrentMarkThread* _cm_thread;860861// The concurrent refiner.862G1ConcurrentRefine* _cr;863864// The parallel task queues865G1ScannerTasksQueueSet *_task_queues;866867// Number of regions evacuation failed in the current collection.868volatile uint _num_regions_failed_evacuation;869870EvacuationFailedInfo* _evacuation_failed_info_array;871872PreservedMarksSet _preserved_marks_set;873874// Preserve the mark of "obj", if necessary, in preparation for its mark875// word being overwritten with a self-forwarding-pointer.876void preserve_mark_during_evac_failure(uint worker_id, oop obj, markWord m);877878#ifndef PRODUCT879// Support for forcing evacuation failures. Analogous to880// PromotionFailureALot for the other collectors.881882// Records whether G1EvacuationFailureALot should be in effect883// for the current GC884bool _evacuation_failure_alot_for_current_gc;885886// Used to record the GC number for interval checking when887// determining whether G1EvaucationFailureALot is in effect888// for the current GC.889size_t _evacuation_failure_alot_gc_number;890891// Count of the number of evacuations between failures.892volatile size_t _evacuation_failure_alot_count;893894// Set whether G1EvacuationFailureALot should be in effect895// for the current GC (based upon the type of GC and which896// command line flags are set);897inline bool evacuation_failure_alot_for_gc_type(bool for_young_gc,898bool during_concurrent_start,899bool mark_or_rebuild_in_progress);900901inline void set_evacuation_failure_alot_for_current_gc();902903// Return true if it's time to cause an evacuation failure.904inline bool evacuation_should_fail();905906// Reset the G1EvacuationFailureALot counters. Should be called at907// the end of an evacuation pause in which an evacuation failure occurred.908inline void reset_evacuation_should_fail();909#endif // !PRODUCT910911// ("Weak") Reference processing support.912//913// G1 has 2 instances of the reference processor class. One914// (_ref_processor_cm) handles reference object discovery915// and subsequent processing during concurrent marking cycles.916//917// The other (_ref_processor_stw) handles reference object918// discovery and processing during full GCs and incremental919// evacuation pauses.920//921// During an incremental pause, reference discovery will be922// temporarily disabled for _ref_processor_cm and will be923// enabled for _ref_processor_stw. At the end of the evacuation924// pause references discovered by _ref_processor_stw will be925// processed and discovery will be disabled. The previous926// setting for reference object discovery for _ref_processor_cm927// will be re-instated.928//929// At the start of marking:930// * Discovery by the CM ref processor is verified to be inactive931// and it's discovered lists are empty.932// * Discovery by the CM ref processor is then enabled.933//934// At the end of marking:935// * Any references on the CM ref processor's discovered936// lists are processed (possibly MT).937//938// At the start of full GC we:939// * Disable discovery by the CM ref processor and940// empty CM ref processor's discovered lists941// (without processing any entries).942// * Verify that the STW ref processor is inactive and it's943// discovered lists are empty.944// * Temporarily set STW ref processor discovery as single threaded.945// * Temporarily clear the STW ref processor's _is_alive_non_header946// field.947// * Finally enable discovery by the STW ref processor.948//949// The STW ref processor is used to record any discovered950// references during the full GC.951//952// At the end of a full GC we:953// * Enqueue any reference objects discovered by the STW ref processor954// that have non-live referents. This has the side-effect of955// making the STW ref processor inactive by disabling discovery.956// * Verify that the CM ref processor is still inactive957// and no references have been placed on it's discovered958// lists (also checked as a precondition during concurrent start).959960// The (stw) reference processor...961ReferenceProcessor* _ref_processor_stw;962963// During reference object discovery, the _is_alive_non_header964// closure (if non-null) is applied to the referent object to965// determine whether the referent is live. If so then the966// reference object does not need to be 'discovered' and can967// be treated as a regular oop. This has the benefit of reducing968// the number of 'discovered' reference objects that need to969// be processed.970//971// Instance of the is_alive closure for embedding into the972// STW reference processor as the _is_alive_non_header field.973// Supplying a value for the _is_alive_non_header field is974// optional but doing so prevents unnecessary additions to975// the discovered lists during reference discovery.976G1STWIsAliveClosure _is_alive_closure_stw;977978G1STWSubjectToDiscoveryClosure _is_subject_to_discovery_stw;979980// The (concurrent marking) reference processor...981ReferenceProcessor* _ref_processor_cm;982983// Instance of the concurrent mark is_alive closure for embedding984// into the Concurrent Marking reference processor as the985// _is_alive_non_header field. Supplying a value for the986// _is_alive_non_header field is optional but doing so prevents987// unnecessary additions to the discovered lists during reference988// discovery.989G1CMIsAliveClosure _is_alive_closure_cm;990991G1CMSubjectToDiscoveryClosure _is_subject_to_discovery_cm;992public:993994G1ScannerTasksQueue* task_queue(uint i) const;995996uint num_task_queues() const;997998// Create a G1CollectedHeap.999// Must call the initialize method afterwards.1000// May not return if something goes wrong.1001G1CollectedHeap();10021003private:1004jint initialize_concurrent_refinement();1005jint initialize_service_thread();1006public:1007// Initialize the G1CollectedHeap to have the initial and1008// maximum sizes and remembered and barrier sets1009// specified by the policy object.1010jint initialize();10111012virtual void stop();1013virtual void safepoint_synchronize_begin();1014virtual void safepoint_synchronize_end();10151016// Does operations required after initialization has been done.1017void post_initialize();10181019// Initialize weak reference processing.1020void ref_processing_init();10211022virtual Name kind() const {1023return CollectedHeap::G1;1024}10251026virtual const char* name() const {1027return "G1";1028}10291030const G1CollectorState* collector_state() const { return &_collector_state; }1031G1CollectorState* collector_state() { return &_collector_state; }10321033// The current policy object for the collector.1034G1Policy* policy() const { return _policy; }1035// The remembered set.1036G1RemSet* rem_set() const { return _rem_set; }10371038inline G1GCPhaseTimes* phase_times() const;10391040const G1CollectionSet* collection_set() const { return &_collection_set; }1041G1CollectionSet* collection_set() { return &_collection_set; }10421043virtual SoftRefPolicy* soft_ref_policy();10441045virtual void initialize_serviceability();1046virtual MemoryUsage memory_usage();1047virtual GrowableArray<GCMemoryManager*> memory_managers();1048virtual GrowableArray<MemoryPool*> memory_pools();10491050// Try to minimize the remembered set.1051void scrub_rem_set();10521053// Apply the given closure on all cards in the Hot Card Cache, emptying it.1054void iterate_hcc_closure(G1CardTableEntryClosure* cl, uint worker_id);10551056// The shared block offset table array.1057G1BlockOffsetTable* bot() const { return _bot; }10581059// Reference Processing accessors10601061// The STW reference processor....1062ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; }10631064G1NewTracer* gc_tracer_stw() const { return _gc_tracer_stw; }10651066// The Concurrent Marking reference processor...1067ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }10681069size_t unused_committed_regions_in_bytes() const;10701071virtual size_t capacity() const;1072virtual size_t used() const;1073// This should be called when we're not holding the heap lock. The1074// result might be a bit inaccurate.1075size_t used_unlocked() const;1076size_t recalculate_used() const;10771078// These virtual functions do the actual allocation.1079// Some heaps may offer a contiguous region for shared non-blocking1080// allocation, via inlined code (by exporting the address of the top and1081// end fields defining the extent of the contiguous allocation region.)1082// But G1CollectedHeap doesn't yet support this.10831084virtual bool is_maximal_no_gc() const {1085return _hrm.available() == 0;1086}10871088// Returns whether there are any regions left in the heap for allocation.1089bool has_regions_left_for_allocation() const {1090return !is_maximal_no_gc() || num_free_regions() != 0;1091}10921093// The current number of regions in the heap.1094uint num_regions() const { return _hrm.length(); }10951096// The max number of regions reserved for the heap. Except for static array1097// sizing purposes you probably want to use max_regions().1098uint max_reserved_regions() const { return _hrm.reserved_length(); }10991100// Max number of regions that can be committed.1101uint max_regions() const { return _hrm.max_length(); }11021103// The number of regions that are completely free.1104uint num_free_regions() const { return _hrm.num_free_regions(); }11051106// The number of regions that can be allocated into.1107uint num_free_or_available_regions() const { return num_free_regions() + _hrm.available(); }11081109MemoryUsage get_auxiliary_data_memory_usage() const {1110return _hrm.get_auxiliary_data_memory_usage();1111}11121113// The number of regions that are not completely free.1114uint num_used_regions() const { return num_regions() - num_free_regions(); }11151116#ifdef ASSERT1117bool is_on_master_free_list(HeapRegion* hr) {1118return _hrm.is_free(hr);1119}1120#endif // ASSERT11211122inline void old_set_add(HeapRegion* hr);1123inline void old_set_remove(HeapRegion* hr);11241125inline void archive_set_add(HeapRegion* hr);11261127size_t non_young_capacity_bytes() {1128return (old_regions_count() + _archive_set.length() + humongous_regions_count()) * HeapRegion::GrainBytes;1129}11301131// Determine whether the given region is one that we are using as an1132// old GC alloc region.1133bool is_old_gc_alloc_region(HeapRegion* hr);11341135// Perform a collection of the heap; intended for use in implementing1136// "System.gc". This probably implies as full a collection as the1137// "CollectedHeap" supports.1138virtual void collect(GCCause::Cause cause);11391140// Perform a collection of the heap with the given cause.1141// Returns whether this collection actually executed.1142bool try_collect(GCCause::Cause cause);11431144// True iff an evacuation has failed in the most-recent collection.1145inline bool evacuation_failed() const;1146inline uint num_regions_failed_evacuation() const;1147// Notify that the garbage collection encountered an evacuation failure in a1148// region. Should only be called once per region.1149inline void notify_region_failed_evacuation();11501151void remove_from_old_gen_sets(const uint old_regions_removed,1152const uint archive_regions_removed,1153const uint humongous_regions_removed);1154void prepend_to_freelist(FreeRegionList* list);1155void decrement_summary_bytes(size_t bytes);11561157virtual bool is_in(const void* p) const;11581159// Return "TRUE" iff the given object address is within the collection1160// set. Assumes that the reference points into the heap.1161inline bool is_in_cset(const HeapRegion *hr);1162inline bool is_in_cset(oop obj);1163inline bool is_in_cset(HeapWord* addr);11641165inline bool is_in_cset_or_humongous(const oop obj);11661167private:1168// This array is used for a quick test on whether a reference points into1169// the collection set or not. Each of the array's elements denotes whether the1170// corresponding region is in the collection set or not.1171G1HeapRegionAttrBiasedMappedArray _region_attr;11721173public:11741175inline G1HeapRegionAttr region_attr(const void* obj) const;1176inline G1HeapRegionAttr region_attr(uint idx) const;11771178MemRegion reserved() const {1179return _hrm.reserved();1180}11811182bool is_in_reserved(const void* addr) const {1183return reserved().contains(addr);1184}11851186G1HotCardCache* hot_card_cache() const { return _hot_card_cache; }11871188G1CardTable* card_table() const {1189return _card_table;1190}11911192// Iteration functions.11931194void object_iterate_parallel(ObjectClosure* cl, uint worker_id, HeapRegionClaimer* claimer);11951196// Iterate over all objects, calling "cl.do_object" on each.1197virtual void object_iterate(ObjectClosure* cl);11981199virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num);12001201// Keep alive an object that was loaded with AS_NO_KEEPALIVE.1202virtual void keep_alive(oop obj);12031204// Iterate over heap regions, in address order, terminating the1205// iteration early if the "do_heap_region" method returns "true".1206void heap_region_iterate(HeapRegionClosure* blk) const;12071208// Return the region with the given index. It assumes the index is valid.1209inline HeapRegion* region_at(uint index) const;1210inline HeapRegion* region_at_or_null(uint index) const;12111212// Return the next region (by index) that is part of the same1213// humongous object that hr is part of.1214inline HeapRegion* next_region_in_humongous(HeapRegion* hr) const;12151216// Calculate the region index of the given address. Given address must be1217// within the heap.1218inline uint addr_to_region(HeapWord* addr) const;12191220inline HeapWord* bottom_addr_for_region(uint index) const;12211222// Two functions to iterate over the heap regions in parallel. Threads1223// compete using the HeapRegionClaimer to claim the regions before1224// applying the closure on them.1225// The _from_worker_offset version uses the HeapRegionClaimer and1226// the worker id to calculate a start offset to prevent all workers to1227// start from the point.1228void heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,1229HeapRegionClaimer* hrclaimer,1230uint worker_id) const;12311232void heap_region_par_iterate_from_start(HeapRegionClosure* cl,1233HeapRegionClaimer* hrclaimer) const;12341235// Iterate over all regions in the collection set in parallel.1236void collection_set_par_iterate_all(HeapRegionClosure* cl,1237HeapRegionClaimer* hr_claimer,1238uint worker_id);12391240// Iterate over all regions currently in the current collection set.1241void collection_set_iterate_all(HeapRegionClosure* blk);12421243// Iterate over the regions in the current increment of the collection set.1244// Starts the iteration so that the start regions of a given worker id over the1245// set active_workers are evenly spread across the set of collection set regions1246// to be iterated.1247// The variant with the HeapRegionClaimer guarantees that the closure will be1248// applied to a particular region exactly once.1249void collection_set_iterate_increment_from(HeapRegionClosure *blk, uint worker_id) {1250collection_set_iterate_increment_from(blk, NULL, worker_id);1251}1252void collection_set_iterate_increment_from(HeapRegionClosure *blk, HeapRegionClaimer* hr_claimer, uint worker_id);12531254// Returns the HeapRegion that contains addr. addr must not be NULL.1255template <class T>1256inline HeapRegion* heap_region_containing(const T addr) const;12571258// Returns the HeapRegion that contains addr, or NULL if that is an uncommitted1259// region. addr must not be NULL.1260template <class T>1261inline HeapRegion* heap_region_containing_or_null(const T addr) const;12621263// A CollectedHeap is divided into a dense sequence of "blocks"; that is,1264// each address in the (reserved) heap is a member of exactly1265// one block. The defining characteristic of a block is that it is1266// possible to find its size, and thus to progress forward to the next1267// block. (Blocks may be of different sizes.) Thus, blocks may1268// represent Java objects, or they might be free blocks in a1269// free-list-based heap (or subheap), as long as the two kinds are1270// distinguishable and the size of each is determinable.12711272// Returns the address of the start of the "block" that contains the1273// address "addr". We say "blocks" instead of "object" since some heaps1274// may not pack objects densely; a chunk may either be an object or a1275// non-object.1276HeapWord* block_start(const void* addr) const;12771278// Requires "addr" to be the start of a block, and returns "TRUE" iff1279// the block is an object.1280bool block_is_obj(const HeapWord* addr) const;12811282// Section on thread-local allocation buffers (TLABs)1283// See CollectedHeap for semantics.12841285size_t tlab_capacity(Thread* ignored) const;1286size_t tlab_used(Thread* ignored) const;1287size_t max_tlab_size() const;1288size_t unsafe_max_tlab_alloc(Thread* ignored) const;12891290inline bool is_in_young(const oop obj);12911292// Returns "true" iff the given word_size is "very large".1293static bool is_humongous(size_t word_size) {1294// Note this has to be strictly greater-than as the TLABs1295// are capped at the humongous threshold and we want to1296// ensure that we don't try to allocate a TLAB as1297// humongous and that we don't allocate a humongous1298// object in a TLAB.1299return word_size > _humongous_object_threshold_in_words;1300}13011302// Returns the humongous threshold for a specific region size1303static size_t humongous_threshold_for(size_t region_size) {1304return (region_size / 2);1305}13061307// Returns the number of regions the humongous object of the given word size1308// requires.1309static size_t humongous_obj_size_in_regions(size_t word_size);13101311// Print the maximum heap capacity.1312virtual size_t max_capacity() const;13131314Tickspan time_since_last_collection() const { return Ticks::now() - _collection_pause_end; }13151316// Convenience function to be used in situations where the heap type can be1317// asserted to be this type.1318static G1CollectedHeap* heap() {1319return named_heap<G1CollectedHeap>(CollectedHeap::G1);1320}13211322void set_region_short_lived_locked(HeapRegion* hr);1323// add appropriate methods for any other surv rate groups13241325const G1SurvivorRegions* survivor() const { return &_survivor; }13261327uint eden_regions_count() const { return _eden.length(); }1328uint eden_regions_count(uint node_index) const { return _eden.regions_on_node(node_index); }1329uint survivor_regions_count() const { return _survivor.length(); }1330uint survivor_regions_count(uint node_index) const { return _survivor.regions_on_node(node_index); }1331size_t eden_regions_used_bytes() const { return _eden.used_bytes(); }1332size_t survivor_regions_used_bytes() const { return _survivor.used_bytes(); }1333uint young_regions_count() const { return _eden.length() + _survivor.length(); }1334uint old_regions_count() const { return _old_set.length(); }1335uint archive_regions_count() const { return _archive_set.length(); }1336uint humongous_regions_count() const { return _humongous_set.length(); }13371338#ifdef ASSERT1339bool check_young_list_empty();1340#endif13411342bool is_marked_next(oop obj) const;13431344// Determine if an object is dead, given the object and also1345// the region to which the object belongs.1346bool is_obj_dead(const oop obj, const HeapRegion* hr) const {1347return hr->is_obj_dead(obj, _cm->prev_mark_bitmap());1348}13491350// This function returns true when an object has been1351// around since the previous marking and hasn't yet1352// been marked during this marking, and is not in a closed archive region.1353bool is_obj_ill(const oop obj, const HeapRegion* hr) const {1354return1355!hr->obj_allocated_since_next_marking(obj) &&1356!is_marked_next(obj) &&1357!hr->is_closed_archive();1358}13591360// Determine if an object is dead, given only the object itself.1361// This will find the region to which the object belongs and1362// then call the region version of the same function.13631364// Added if it is NULL it isn't dead.13651366inline bool is_obj_dead(const oop obj) const;13671368inline bool is_obj_ill(const oop obj) const;13691370inline bool is_obj_dead_full(const oop obj, const HeapRegion* hr) const;1371inline bool is_obj_dead_full(const oop obj) const;13721373G1ConcurrentMark* concurrent_mark() const { return _cm; }13741375// Refinement13761377G1ConcurrentRefine* concurrent_refine() const { return _cr; }13781379// Optimized nmethod scanning support routines13801381// Register the given nmethod with the G1 heap.1382virtual void register_nmethod(nmethod* nm);13831384// Unregister the given nmethod from the G1 heap.1385virtual void unregister_nmethod(nmethod* nm);13861387// No nmethod flushing needed.1388virtual void flush_nmethod(nmethod* nm) {}13891390// No nmethod verification implemented.1391virtual void verify_nmethod(nmethod* nm) {}13921393// Recalculate amount of used memory after GC. Must be called after all allocation1394// has finished.1395void update_used_after_gc();1396// Reset and re-enable the hot card cache.1397// Note the counts for the cards in the regions in the1398// collection set are reset when the collection set is freed.1399void reset_hot_card_cache();1400// Free up superfluous code root memory.1401void purge_code_root_memory();14021403// Rebuild the strong code root lists for each region1404// after a full GC.1405void rebuild_strong_code_roots();14061407// Performs cleaning of data structures after class unloading.1408void complete_cleaning(BoolObjectClosure* is_alive, bool class_unloading_occurred);14091410// Verification14111412// Perform any cleanup actions necessary before allowing a verification.1413virtual void prepare_for_verify();14141415// Perform verification.14161417// vo == UsePrevMarking -> use "prev" marking information,1418// vo == UseNextMarking -> use "next" marking information1419// vo == UseFullMarking -> use "next" marking bitmap but no TAMS1420//1421// NOTE: Only the "prev" marking information is guaranteed to be1422// consistent most of the time, so most calls to this should use1423// vo == UsePrevMarking.1424// Currently, there is only one case where this is called with1425// vo == UseNextMarking, which is to verify the "next" marking1426// information at the end of remark.1427// Currently there is only one place where this is called with1428// vo == UseFullMarking, which is to verify the marking during a1429// full GC.1430void verify(VerifyOption vo);14311432// WhiteBox testing support.1433virtual bool supports_concurrent_gc_breakpoints() const;14341435virtual WorkGang* safepoint_workers() { return _workers; }14361437virtual bool is_archived_object(oop object) const;14381439// The methods below are here for convenience and dispatch the1440// appropriate method depending on value of the given VerifyOption1441// parameter. The values for that parameter, and their meanings,1442// are the same as those above.14431444bool is_obj_dead_cond(const oop obj,1445const HeapRegion* hr,1446const VerifyOption vo) const;14471448bool is_obj_dead_cond(const oop obj,1449const VerifyOption vo) const;14501451G1HeapSummary create_g1_heap_summary();1452G1EvacSummary create_g1_evac_summary(G1EvacStats* stats);14531454// Printing1455private:1456void print_heap_regions() const;1457void print_regions_on(outputStream* st) const;14581459public:1460virtual void print_on(outputStream* st) const;1461virtual void print_extended_on(outputStream* st) const;1462virtual void print_on_error(outputStream* st) const;14631464virtual void gc_threads_do(ThreadClosure* tc) const;14651466// Override1467void print_tracing_info() const;14681469// The following two methods are helpful for debugging RSet issues.1470void print_cset_rsets() PRODUCT_RETURN;1471void print_all_rsets() PRODUCT_RETURN;14721473// Used to print information about locations in the hs_err file.1474virtual bool print_location(outputStream* st, void* addr) const;1475};14761477class G1ParEvacuateFollowersClosure : public VoidClosure {1478private:1479double _start_term;1480double _term_time;1481size_t _term_attempts;14821483void start_term_time() { _term_attempts++; _start_term = os::elapsedTime(); }1484void end_term_time() { _term_time += (os::elapsedTime() - _start_term); }1485protected:1486G1CollectedHeap* _g1h;1487G1ParScanThreadState* _par_scan_state;1488G1ScannerTasksQueueSet* _queues;1489TaskTerminator* _terminator;1490G1GCPhaseTimes::GCParPhases _phase;14911492G1ParScanThreadState* par_scan_state() { return _par_scan_state; }1493G1ScannerTasksQueueSet* queues() { return _queues; }1494TaskTerminator* terminator() { return _terminator; }14951496public:1497G1ParEvacuateFollowersClosure(G1CollectedHeap* g1h,1498G1ParScanThreadState* par_scan_state,1499G1ScannerTasksQueueSet* queues,1500TaskTerminator* terminator,1501G1GCPhaseTimes::GCParPhases phase)1502: _start_term(0.0), _term_time(0.0), _term_attempts(0),1503_g1h(g1h), _par_scan_state(par_scan_state),1504_queues(queues), _terminator(terminator), _phase(phase) {}15051506void do_void();15071508double term_time() const { return _term_time; }1509size_t term_attempts() const { return _term_attempts; }15101511private:1512inline bool offer_termination();1513};15141515#endif // SHARE_GC_G1_G1COLLECTEDHEAP_HPP151615171518