Path: blob/master/src/hotspot/share/gc/g1/g1CollectedHeap.hpp
66644 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// indicates whether we are in young or mixed GC mode288G1CollectorState _collector_state;289290// Keeps track of how many "old marking cycles" (i.e., Full GCs or291// concurrent cycles) we have started.292volatile uint _old_marking_cycles_started;293294// Keeps track of how many "old marking cycles" (i.e., Full GCs or295// concurrent cycles) we have completed.296volatile uint _old_marking_cycles_completed;297298// This is a non-product method that is helpful for testing. It is299// called at the end of a GC and artificially expands the heap by300// allocating a number of dead regions. This way we can induce very301// frequent marking cycles and stress the cleanup / concurrent302// cleanup code more (as all the regions that will be allocated by303// this method will be found dead by the marking cycle).304void allocate_dummy_regions() PRODUCT_RETURN;305306// If the HR printer is active, dump the state of the regions in the307// heap after a compaction.308void print_hrm_post_compaction();309310// Create a memory mapper for auxiliary data structures of the given size and311// translation factor.312static G1RegionToSpaceMapper* create_aux_memory_mapper(const char* description,313size_t size,314size_t translation_factor);315316void trace_heap(GCWhen::Type when, const GCTracer* tracer);317318// These are macros so that, if the assert fires, we get the correct319// line number, file, etc.320321#define heap_locking_asserts_params(_extra_message_) \322"%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \323(_extra_message_), \324BOOL_TO_STR(Heap_lock->owned_by_self()), \325BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), \326BOOL_TO_STR(Thread::current()->is_VM_thread())327328#define assert_heap_locked() \329do { \330assert(Heap_lock->owned_by_self(), \331heap_locking_asserts_params("should be holding the Heap_lock")); \332} while (0)333334#define assert_heap_locked_or_at_safepoint(_should_be_vm_thread_) \335do { \336assert(Heap_lock->owned_by_self() || \337(SafepointSynchronize::is_at_safepoint() && \338((_should_be_vm_thread_) == Thread::current()->is_VM_thread())), \339heap_locking_asserts_params("should be holding the Heap_lock or " \340"should be at a safepoint")); \341} while (0)342343#define assert_heap_locked_and_not_at_safepoint() \344do { \345assert(Heap_lock->owned_by_self() && \346!SafepointSynchronize::is_at_safepoint(), \347heap_locking_asserts_params("should be holding the Heap_lock and " \348"should not be at a safepoint")); \349} while (0)350351#define assert_heap_not_locked() \352do { \353assert(!Heap_lock->owned_by_self(), \354heap_locking_asserts_params("should not be holding the Heap_lock")); \355} while (0)356357#define assert_heap_not_locked_and_not_at_safepoint() \358do { \359assert(!Heap_lock->owned_by_self() && \360!SafepointSynchronize::is_at_safepoint(), \361heap_locking_asserts_params("should not be holding the Heap_lock and " \362"should not be at a safepoint")); \363} while (0)364365#define assert_at_safepoint_on_vm_thread() \366do { \367assert_at_safepoint(); \368assert(Thread::current_or_null() != NULL, "no current thread"); \369assert(Thread::current()->is_VM_thread(), "current thread is not VM thread"); \370} while (0)371372#ifdef ASSERT373#define assert_used_and_recalculate_used_equal(g1h) \374do { \375size_t cur_used_bytes = g1h->used(); \376size_t recal_used_bytes = g1h->recalculate_used(); \377assert(cur_used_bytes == recal_used_bytes, "Used(" SIZE_FORMAT ") is not" \378" same as recalculated used(" SIZE_FORMAT ").", \379cur_used_bytes, recal_used_bytes); \380} while (0)381#else382#define assert_used_and_recalculate_used_equal(g1h) do {} while(0)383#endif384385static const uint MaxYoungGCNameLength = 128;386// Sets given young_gc_name to the canonical young gc pause string. Young_gc_name387// must be at least of length MaxYoungGCNameLength.388void set_young_gc_name(char* young_gc_name);389390// The young region list.391G1EdenRegions _eden;392G1SurvivorRegions _survivor;393394STWGCTimer* _gc_timer_stw;395396G1NewTracer* _gc_tracer_stw;397398void gc_tracer_report_gc_start();399void gc_tracer_report_gc_end(bool concurrent_operation_is_full_mark, G1EvacuationInfo& evacuation_info);400401// The current policy object for the collector.402G1Policy* _policy;403G1HeapSizingPolicy* _heap_sizing_policy;404405G1CollectionSet _collection_set;406407// Try to allocate a single non-humongous HeapRegion sufficient for408// an allocation of the given word_size. If do_expand is true,409// attempt to expand the heap if necessary to satisfy the allocation410// request. 'type' takes the type of region to be allocated. (Use constants411// Old, Eden, Humongous, Survivor defined in HeapRegionType.)412HeapRegion* new_region(size_t word_size,413HeapRegionType type,414bool do_expand,415uint node_index = G1NUMA::AnyNodeIndex);416417// Initialize a contiguous set of free regions of length num_regions418// and starting at index first so that they appear as a single419// humongous region.420HeapWord* humongous_obj_allocate_initialize_regions(HeapRegion* first_hr,421uint num_regions,422size_t word_size);423424// Attempt to allocate a humongous object of the given size. Return425// NULL if unsuccessful.426HeapWord* humongous_obj_allocate(size_t word_size);427428// The following two methods, allocate_new_tlab() and429// mem_allocate(), are the two main entry points from the runtime430// into the G1's allocation routines. They have the following431// assumptions:432//433// * They should both be called outside safepoints.434//435// * They should both be called without holding the Heap_lock.436//437// * All allocation requests for new TLABs should go to438// allocate_new_tlab().439//440// * All non-TLAB allocation requests should go to mem_allocate().441//442// * If either call cannot satisfy the allocation request using the443// current allocating region, they will try to get a new one. If444// this fails, they will attempt to do an evacuation pause and445// retry the allocation.446//447// * If all allocation attempts fail, even after trying to schedule448// an evacuation pause, allocate_new_tlab() will return NULL,449// whereas mem_allocate() will attempt a heap expansion and/or450// schedule a Full GC.451//452// * We do not allow humongous-sized TLABs. So, allocate_new_tlab453// should never be called with word_size being humongous. All454// humongous allocation requests should go to mem_allocate() which455// will satisfy them with a special path.456457virtual HeapWord* allocate_new_tlab(size_t min_size,458size_t requested_size,459size_t* actual_size);460461virtual HeapWord* mem_allocate(size_t word_size,462bool* gc_overhead_limit_was_exceeded);463464// First-level mutator allocation attempt: try to allocate out of465// the mutator alloc region without taking the Heap_lock. This466// should only be used for non-humongous allocations.467inline HeapWord* attempt_allocation(size_t min_word_size,468size_t desired_word_size,469size_t* actual_word_size);470471// Second-level mutator allocation attempt: take the Heap_lock and472// retry the allocation attempt, potentially scheduling a GC473// pause. This should only be used for non-humongous allocations.474HeapWord* attempt_allocation_slow(size_t word_size);475476// Takes the Heap_lock and attempts a humongous allocation. It can477// potentially schedule a GC pause.478HeapWord* attempt_allocation_humongous(size_t word_size);479480// Allocation attempt that should be called during safepoints (e.g.,481// at the end of a successful GC). expect_null_mutator_alloc_region482// specifies whether the mutator alloc region is expected to be NULL483// or not.484HeapWord* attempt_allocation_at_safepoint(size_t word_size,485bool expect_null_mutator_alloc_region);486487// These methods are the "callbacks" from the G1AllocRegion class.488489// For mutator alloc regions.490HeapRegion* new_mutator_alloc_region(size_t word_size, bool force, uint node_index);491void retire_mutator_alloc_region(HeapRegion* alloc_region,492size_t allocated_bytes);493494// For GC alloc regions.495bool has_more_regions(G1HeapRegionAttr dest);496HeapRegion* new_gc_alloc_region(size_t word_size, G1HeapRegionAttr dest, uint node_index);497void retire_gc_alloc_region(HeapRegion* alloc_region,498size_t allocated_bytes, G1HeapRegionAttr dest);499500// - if explicit_gc is true, the GC is for a System.gc() etc,501// otherwise it's for a failed allocation.502// - if clear_all_soft_refs is true, all soft references should be503// cleared during the GC.504// - if do_maximum_compaction is true, full gc will do a maximally505// compacting collection, leaving no dead wood.506// - it returns false if it is unable to do the collection due to the507// GC locker being active, true otherwise.508bool do_full_collection(bool explicit_gc,509bool clear_all_soft_refs,510bool do_maximum_compaction);511512// Callback from VM_G1CollectFull operation, or collect_as_vm_thread.513virtual void do_full_collection(bool clear_all_soft_refs);514515// Helper to do a full collection that clears soft references.516bool upgrade_to_full_collection();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 maximum_compaction,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;869// Records for every region on the heap whether evacuation failed for it.870volatile bool* _regions_failed_evacuation;871872EvacuationFailedInfo* _evacuation_failed_info_array;873874PreservedMarksSet _preserved_marks_set;875876// Preserve the mark of "obj", if necessary, in preparation for its mark877// word being overwritten with a self-forwarding-pointer.878void preserve_mark_during_evac_failure(uint worker_id, oop obj, markWord m);879880#ifndef PRODUCT881// Support for forcing evacuation failures. Analogous to882// PromotionFailureALot for the other collectors.883884// Records whether G1EvacuationFailureALot should be in effect885// for the current GC886bool _evacuation_failure_alot_for_current_gc;887888// Used to record the GC number for interval checking when889// determining whether G1EvaucationFailureALot is in effect890// for the current GC.891size_t _evacuation_failure_alot_gc_number;892893// Count of the number of evacuations between failures.894volatile size_t _evacuation_failure_alot_count;895896// Set whether G1EvacuationFailureALot should be in effect897// for the current GC (based upon the type of GC and which898// command line flags are set);899inline bool evacuation_failure_alot_for_gc_type(bool for_young_gc,900bool during_concurrent_start,901bool mark_or_rebuild_in_progress);902903inline void set_evacuation_failure_alot_for_current_gc();904905// Return true if it's time to cause an evacuation failure.906inline bool evacuation_should_fail();907908// Reset the G1EvacuationFailureALot counters. Should be called at909// the end of an evacuation pause in which an evacuation failure occurred.910inline void reset_evacuation_should_fail();911#endif // !PRODUCT912913// ("Weak") Reference processing support.914//915// G1 has 2 instances of the reference processor class. One916// (_ref_processor_cm) handles reference object discovery917// and subsequent processing during concurrent marking cycles.918//919// The other (_ref_processor_stw) handles reference object920// discovery and processing during full GCs and incremental921// evacuation pauses.922//923// During an incremental pause, reference discovery will be924// temporarily disabled for _ref_processor_cm and will be925// enabled for _ref_processor_stw. At the end of the evacuation926// pause references discovered by _ref_processor_stw will be927// processed and discovery will be disabled. The previous928// setting for reference object discovery for _ref_processor_cm929// will be re-instated.930//931// At the start of marking:932// * Discovery by the CM ref processor is verified to be inactive933// and it's discovered lists are empty.934// * Discovery by the CM ref processor is then enabled.935//936// At the end of marking:937// * Any references on the CM ref processor's discovered938// lists are processed (possibly MT).939//940// At the start of full GC we:941// * Disable discovery by the CM ref processor and942// empty CM ref processor's discovered lists943// (without processing any entries).944// * Verify that the STW ref processor is inactive and it's945// discovered lists are empty.946// * Temporarily set STW ref processor discovery as single threaded.947// * Temporarily clear the STW ref processor's _is_alive_non_header948// field.949// * Finally enable discovery by the STW ref processor.950//951// The STW ref processor is used to record any discovered952// references during the full GC.953//954// At the end of a full GC we:955// * Enqueue any reference objects discovered by the STW ref processor956// that have non-live referents. This has the side-effect of957// making the STW ref processor inactive by disabling discovery.958// * Verify that the CM ref processor is still inactive959// and no references have been placed on it's discovered960// lists (also checked as a precondition during concurrent start).961962// The (stw) reference processor...963ReferenceProcessor* _ref_processor_stw;964965// During reference object discovery, the _is_alive_non_header966// closure (if non-null) is applied to the referent object to967// determine whether the referent is live. If so then the968// reference object does not need to be 'discovered' and can969// be treated as a regular oop. This has the benefit of reducing970// the number of 'discovered' reference objects that need to971// be processed.972//973// Instance of the is_alive closure for embedding into the974// STW reference processor as the _is_alive_non_header field.975// Supplying a value for the _is_alive_non_header field is976// optional but doing so prevents unnecessary additions to977// the discovered lists during reference discovery.978G1STWIsAliveClosure _is_alive_closure_stw;979980G1STWSubjectToDiscoveryClosure _is_subject_to_discovery_stw;981982// The (concurrent marking) reference processor...983ReferenceProcessor* _ref_processor_cm;984985// Instance of the concurrent mark is_alive closure for embedding986// into the Concurrent Marking reference processor as the987// _is_alive_non_header field. Supplying a value for the988// _is_alive_non_header field is optional but doing so prevents989// unnecessary additions to the discovered lists during reference990// discovery.991G1CMIsAliveClosure _is_alive_closure_cm;992993G1CMSubjectToDiscoveryClosure _is_subject_to_discovery_cm;994public:995996G1ScannerTasksQueue* task_queue(uint i) const;997998uint num_task_queues() const;9991000// Create a G1CollectedHeap.1001// Must call the initialize method afterwards.1002// May not return if something goes wrong.1003G1CollectedHeap();10041005private:1006jint initialize_concurrent_refinement();1007jint initialize_service_thread();1008public:1009// Initialize the G1CollectedHeap to have the initial and1010// maximum sizes and remembered and barrier sets1011// specified by the policy object.1012jint initialize();10131014virtual void stop();1015virtual void safepoint_synchronize_begin();1016virtual void safepoint_synchronize_end();10171018// Does operations required after initialization has been done.1019void post_initialize();10201021// Initialize weak reference processing.1022void ref_processing_init();10231024virtual Name kind() const {1025return CollectedHeap::G1;1026}10271028virtual const char* name() const {1029return "G1";1030}10311032const G1CollectorState* collector_state() const { return &_collector_state; }1033G1CollectorState* collector_state() { return &_collector_state; }10341035// The current policy object for the collector.1036G1Policy* policy() const { return _policy; }1037// The remembered set.1038G1RemSet* rem_set() const { return _rem_set; }10391040inline G1GCPhaseTimes* phase_times() const;10411042const G1CollectionSet* collection_set() const { return &_collection_set; }1043G1CollectionSet* collection_set() { return &_collection_set; }10441045virtual SoftRefPolicy* soft_ref_policy();10461047virtual void initialize_serviceability();1048virtual MemoryUsage memory_usage();1049virtual GrowableArray<GCMemoryManager*> memory_managers();1050virtual GrowableArray<MemoryPool*> memory_pools();10511052// Try to minimize the remembered set.1053void scrub_rem_set();10541055// Apply the given closure on all cards in the Hot Card Cache, emptying it.1056void iterate_hcc_closure(G1CardTableEntryClosure* cl, uint worker_id);10571058// The shared block offset table array.1059G1BlockOffsetTable* bot() const { return _bot; }10601061// Reference Processing accessors10621063// The STW reference processor....1064ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; }10651066G1NewTracer* gc_tracer_stw() const { return _gc_tracer_stw; }10671068// The Concurrent Marking reference processor...1069ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }10701071size_t unused_committed_regions_in_bytes() const;10721073virtual size_t capacity() const;1074virtual size_t used() const;1075// This should be called when we're not holding the heap lock. The1076// result might be a bit inaccurate.1077size_t used_unlocked() const;1078size_t recalculate_used() const;10791080// These virtual functions do the actual allocation.1081// Some heaps may offer a contiguous region for shared non-blocking1082// allocation, via inlined code (by exporting the address of the top and1083// end fields defining the extent of the contiguous allocation region.)1084// But G1CollectedHeap doesn't yet support this.10851086virtual bool is_maximal_no_gc() const {1087return _hrm.available() == 0;1088}10891090// Returns true if an incremental GC should be upgrade to a full gc. This1091// is done when there are no free regions and the heap can't be expanded.1092bool should_upgrade_to_full_gc() const {1093return is_maximal_no_gc() && num_free_regions() == 0;1094}10951096// The current number of regions in the heap.1097uint num_regions() const { return _hrm.length(); }10981099// The max number of regions reserved for the heap. Except for static array1100// sizing purposes you probably want to use max_regions().1101uint max_reserved_regions() const { return _hrm.reserved_length(); }11021103// Max number of regions that can be committed.1104uint max_regions() const { return _hrm.max_length(); }11051106// The number of regions that are completely free.1107uint num_free_regions() const { return _hrm.num_free_regions(); }11081109// The number of regions that can be allocated into.1110uint num_free_or_available_regions() const { return num_free_regions() + _hrm.available(); }11111112MemoryUsage get_auxiliary_data_memory_usage() const {1113return _hrm.get_auxiliary_data_memory_usage();1114}11151116// The number of regions that are not completely free.1117uint num_used_regions() const { return num_regions() - num_free_regions(); }11181119#ifdef ASSERT1120bool is_on_master_free_list(HeapRegion* hr) {1121return _hrm.is_free(hr);1122}1123#endif // ASSERT11241125inline void old_set_add(HeapRegion* hr);1126inline void old_set_remove(HeapRegion* hr);11271128inline void archive_set_add(HeapRegion* hr);11291130size_t non_young_capacity_bytes() {1131return (old_regions_count() + _archive_set.length() + humongous_regions_count()) * HeapRegion::GrainBytes;1132}11331134// Determine whether the given region is one that we are using as an1135// old GC alloc region.1136bool is_old_gc_alloc_region(HeapRegion* hr);11371138// Perform a collection of the heap; intended for use in implementing1139// "System.gc". This probably implies as full a collection as the1140// "CollectedHeap" supports.1141virtual void collect(GCCause::Cause cause);11421143// Perform a collection of the heap with the given cause.1144// Returns whether this collection actually executed.1145bool try_collect(GCCause::Cause cause);11461147// True iff an evacuation has failed in the most-recent collection.1148inline bool evacuation_failed() const;1149// True iff the given region encountered an evacuation failure in the most-recent1150// collection.1151inline bool evacuation_failed(uint region_idx) const;11521153inline uint num_regions_failed_evacuation() const;1154// Notify that the garbage collection encountered an evacuation failure in the1155// given region. Returns whether this has been the first occurrence of an evacuation1156// failure in that region.1157inline bool notify_region_failed_evacuation(uint const region_idx);11581159void remove_from_old_gen_sets(const uint old_regions_removed,1160const uint archive_regions_removed,1161const uint humongous_regions_removed);1162void prepend_to_freelist(FreeRegionList* list);1163void decrement_summary_bytes(size_t bytes);11641165virtual bool is_in(const void* p) const;11661167// Return "TRUE" iff the given object address is within the collection1168// set. Assumes that the reference points into the heap.1169inline bool is_in_cset(const HeapRegion *hr);1170inline bool is_in_cset(oop obj);1171inline bool is_in_cset(HeapWord* addr);11721173inline bool is_in_cset_or_humongous(const oop obj);11741175private:1176// This array is used for a quick test on whether a reference points into1177// the collection set or not. Each of the array's elements denotes whether the1178// corresponding region is in the collection set or not.1179G1HeapRegionAttrBiasedMappedArray _region_attr;11801181public:11821183inline G1HeapRegionAttr region_attr(const void* obj) const;1184inline G1HeapRegionAttr region_attr(uint idx) const;11851186MemRegion reserved() const {1187return _hrm.reserved();1188}11891190bool is_in_reserved(const void* addr) const {1191return reserved().contains(addr);1192}11931194G1HotCardCache* hot_card_cache() const { return _hot_card_cache; }11951196G1CardTable* card_table() const {1197return _card_table;1198}11991200// Iteration functions.12011202void object_iterate_parallel(ObjectClosure* cl, uint worker_id, HeapRegionClaimer* claimer);12031204// Iterate over all objects, calling "cl.do_object" on each.1205virtual void object_iterate(ObjectClosure* cl);12061207virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num);12081209// Keep alive an object that was loaded with AS_NO_KEEPALIVE.1210virtual void keep_alive(oop obj);12111212// Iterate over heap regions, in address order, terminating the1213// iteration early if the "do_heap_region" method returns "true".1214void heap_region_iterate(HeapRegionClosure* blk) const;12151216// Return the region with the given index. It assumes the index is valid.1217inline HeapRegion* region_at(uint index) const;1218inline HeapRegion* region_at_or_null(uint index) const;12191220// Return the next region (by index) that is part of the same1221// humongous object that hr is part of.1222inline HeapRegion* next_region_in_humongous(HeapRegion* hr) const;12231224// Calculate the region index of the given address. Given address must be1225// within the heap.1226inline uint addr_to_region(HeapWord* addr) const;12271228inline HeapWord* bottom_addr_for_region(uint index) const;12291230// Two functions to iterate over the heap regions in parallel. Threads1231// compete using the HeapRegionClaimer to claim the regions before1232// applying the closure on them.1233// The _from_worker_offset version uses the HeapRegionClaimer and1234// the worker id to calculate a start offset to prevent all workers to1235// start from the point.1236void heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,1237HeapRegionClaimer* hrclaimer,1238uint worker_id) const;12391240void heap_region_par_iterate_from_start(HeapRegionClosure* cl,1241HeapRegionClaimer* hrclaimer) const;12421243// Iterate over all regions in the collection set in parallel.1244void collection_set_par_iterate_all(HeapRegionClosure* cl,1245HeapRegionClaimer* hr_claimer,1246uint worker_id);12471248// Iterate over all regions currently in the current collection set.1249void collection_set_iterate_all(HeapRegionClosure* blk);12501251// Iterate over the regions in the current increment of the collection set.1252// Starts the iteration so that the start regions of a given worker id over the1253// set active_workers are evenly spread across the set of collection set regions1254// to be iterated.1255// The variant with the HeapRegionClaimer guarantees that the closure will be1256// applied to a particular region exactly once.1257void collection_set_iterate_increment_from(HeapRegionClosure *blk, uint worker_id) {1258collection_set_iterate_increment_from(blk, NULL, worker_id);1259}1260void collection_set_iterate_increment_from(HeapRegionClosure *blk, HeapRegionClaimer* hr_claimer, uint worker_id);12611262// Returns the HeapRegion that contains addr. addr must not be NULL.1263template <class T>1264inline HeapRegion* heap_region_containing(const T addr) const;12651266// Returns the HeapRegion that contains addr, or NULL if that is an uncommitted1267// region. addr must not be NULL.1268template <class T>1269inline HeapRegion* heap_region_containing_or_null(const T addr) const;12701271// A CollectedHeap is divided into a dense sequence of "blocks"; that is,1272// each address in the (reserved) heap is a member of exactly1273// one block. The defining characteristic of a block is that it is1274// possible to find its size, and thus to progress forward to the next1275// block. (Blocks may be of different sizes.) Thus, blocks may1276// represent Java objects, or they might be free blocks in a1277// free-list-based heap (or subheap), as long as the two kinds are1278// distinguishable and the size of each is determinable.12791280// Returns the address of the start of the "block" that contains the1281// address "addr". We say "blocks" instead of "object" since some heaps1282// may not pack objects densely; a chunk may either be an object or a1283// non-object.1284HeapWord* block_start(const void* addr) const;12851286// Requires "addr" to be the start of a block, and returns "TRUE" iff1287// the block is an object.1288bool block_is_obj(const HeapWord* addr) const;12891290// Section on thread-local allocation buffers (TLABs)1291// See CollectedHeap for semantics.12921293size_t tlab_capacity(Thread* ignored) const;1294size_t tlab_used(Thread* ignored) const;1295size_t max_tlab_size() const;1296size_t unsafe_max_tlab_alloc(Thread* ignored) const;12971298inline bool is_in_young(const oop obj);12991300// Returns "true" iff the given word_size is "very large".1301static bool is_humongous(size_t word_size) {1302// Note this has to be strictly greater-than as the TLABs1303// are capped at the humongous threshold and we want to1304// ensure that we don't try to allocate a TLAB as1305// humongous and that we don't allocate a humongous1306// object in a TLAB.1307return word_size > _humongous_object_threshold_in_words;1308}13091310// Returns the humongous threshold for a specific region size1311static size_t humongous_threshold_for(size_t region_size) {1312return (region_size / 2);1313}13141315// Returns the number of regions the humongous object of the given word size1316// requires.1317static size_t humongous_obj_size_in_regions(size_t word_size);13181319// Print the maximum heap capacity.1320virtual size_t max_capacity() const;13211322Tickspan time_since_last_collection() const { return Ticks::now() - _collection_pause_end; }13231324// Convenience function to be used in situations where the heap type can be1325// asserted to be this type.1326static G1CollectedHeap* heap() {1327return named_heap<G1CollectedHeap>(CollectedHeap::G1);1328}13291330void set_region_short_lived_locked(HeapRegion* hr);1331// add appropriate methods for any other surv rate groups13321333const G1SurvivorRegions* survivor() const { return &_survivor; }13341335uint eden_regions_count() const { return _eden.length(); }1336uint eden_regions_count(uint node_index) const { return _eden.regions_on_node(node_index); }1337uint survivor_regions_count() const { return _survivor.length(); }1338uint survivor_regions_count(uint node_index) const { return _survivor.regions_on_node(node_index); }1339size_t eden_regions_used_bytes() const { return _eden.used_bytes(); }1340size_t survivor_regions_used_bytes() const { return _survivor.used_bytes(); }1341uint young_regions_count() const { return _eden.length() + _survivor.length(); }1342uint old_regions_count() const { return _old_set.length(); }1343uint archive_regions_count() const { return _archive_set.length(); }1344uint humongous_regions_count() const { return _humongous_set.length(); }13451346#ifdef ASSERT1347bool check_young_list_empty();1348#endif13491350bool is_marked_next(oop obj) const;13511352// Determine if an object is dead, given the object and also1353// the region to which the object belongs.1354bool is_obj_dead(const oop obj, const HeapRegion* hr) const {1355return hr->is_obj_dead(obj, _cm->prev_mark_bitmap());1356}13571358// This function returns true when an object has been1359// around since the previous marking and hasn't yet1360// been marked during this marking, and is not in a closed archive region.1361bool is_obj_ill(const oop obj, const HeapRegion* hr) const {1362return1363!hr->obj_allocated_since_next_marking(obj) &&1364!is_marked_next(obj) &&1365!hr->is_closed_archive();1366}13671368// Determine if an object is dead, given only the object itself.1369// This will find the region to which the object belongs and1370// then call the region version of the same function.13711372// Added if it is NULL it isn't dead.13731374inline bool is_obj_dead(const oop obj) const;13751376inline bool is_obj_ill(const oop obj) const;13771378inline bool is_obj_dead_full(const oop obj, const HeapRegion* hr) const;1379inline bool is_obj_dead_full(const oop obj) const;13801381G1ConcurrentMark* concurrent_mark() const { return _cm; }13821383// Refinement13841385G1ConcurrentRefine* concurrent_refine() const { return _cr; }13861387// Optimized nmethod scanning support routines13881389// Register the given nmethod with the G1 heap.1390virtual void register_nmethod(nmethod* nm);13911392// Unregister the given nmethod from the G1 heap.1393virtual void unregister_nmethod(nmethod* nm);13941395// No nmethod flushing needed.1396virtual void flush_nmethod(nmethod* nm) {}13971398// No nmethod verification implemented.1399virtual void verify_nmethod(nmethod* nm) {}14001401// Recalculate amount of used memory after GC. Must be called after all allocation1402// has finished.1403void update_used_after_gc();1404// Reset and re-enable the hot card cache.1405// Note the counts for the cards in the regions in the1406// collection set are reset when the collection set is freed.1407void reset_hot_card_cache();1408// Free up superfluous code root memory.1409void purge_code_root_memory();14101411// Rebuild the strong code root lists for each region1412// after a full GC.1413void rebuild_strong_code_roots();14141415// Performs cleaning of data structures after class unloading.1416void complete_cleaning(BoolObjectClosure* is_alive, bool class_unloading_occurred);14171418// Verification14191420// Perform any cleanup actions necessary before allowing a verification.1421virtual void prepare_for_verify();14221423// Perform verification.14241425// vo == UsePrevMarking -> use "prev" marking information,1426// vo == UseNextMarking -> use "next" marking information1427// vo == UseFullMarking -> use "next" marking bitmap but no TAMS1428//1429// NOTE: Only the "prev" marking information is guaranteed to be1430// consistent most of the time, so most calls to this should use1431// vo == UsePrevMarking.1432// Currently, there is only one case where this is called with1433// vo == UseNextMarking, which is to verify the "next" marking1434// information at the end of remark.1435// Currently there is only one place where this is called with1436// vo == UseFullMarking, which is to verify the marking during a1437// full GC.1438void verify(VerifyOption vo);14391440// WhiteBox testing support.1441virtual bool supports_concurrent_gc_breakpoints() const;14421443virtual WorkGang* safepoint_workers() { return _workers; }14441445virtual bool is_archived_object(oop object) const;14461447// The methods below are here for convenience and dispatch the1448// appropriate method depending on value of the given VerifyOption1449// parameter. The values for that parameter, and their meanings,1450// are the same as those above.14511452bool is_obj_dead_cond(const oop obj,1453const HeapRegion* hr,1454const VerifyOption vo) const;14551456bool is_obj_dead_cond(const oop obj,1457const VerifyOption vo) const;14581459G1HeapSummary create_g1_heap_summary();1460G1EvacSummary create_g1_evac_summary(G1EvacStats* stats);14611462// Printing1463private:1464void print_heap_regions() const;1465void print_regions_on(outputStream* st) const;14661467public:1468virtual void print_on(outputStream* st) const;1469virtual void print_extended_on(outputStream* st) const;1470virtual void print_on_error(outputStream* st) const;14711472virtual void gc_threads_do(ThreadClosure* tc) const;14731474// Override1475void print_tracing_info() const;14761477// The following two methods are helpful for debugging RSet issues.1478void print_cset_rsets() PRODUCT_RETURN;1479void print_all_rsets() PRODUCT_RETURN;14801481// Used to print information about locations in the hs_err file.1482virtual bool print_location(outputStream* st, void* addr) const;1483};14841485class G1ParEvacuateFollowersClosure : public VoidClosure {1486private:1487double _start_term;1488double _term_time;1489size_t _term_attempts;14901491void start_term_time() { _term_attempts++; _start_term = os::elapsedTime(); }1492void end_term_time() { _term_time += (os::elapsedTime() - _start_term); }1493protected:1494G1CollectedHeap* _g1h;1495G1ParScanThreadState* _par_scan_state;1496G1ScannerTasksQueueSet* _queues;1497TaskTerminator* _terminator;1498G1GCPhaseTimes::GCParPhases _phase;14991500G1ParScanThreadState* par_scan_state() { return _par_scan_state; }1501G1ScannerTasksQueueSet* queues() { return _queues; }1502TaskTerminator* terminator() { return _terminator; }15031504public:1505G1ParEvacuateFollowersClosure(G1CollectedHeap* g1h,1506G1ParScanThreadState* par_scan_state,1507G1ScannerTasksQueueSet* queues,1508TaskTerminator* terminator,1509G1GCPhaseTimes::GCParPhases phase)1510: _start_term(0.0), _term_time(0.0), _term_attempts(0),1511_g1h(g1h), _par_scan_state(par_scan_state),1512_queues(queues), _terminator(terminator), _phase(phase) {}15131514void do_void();15151516double term_time() const { return _term_time; }1517size_t term_attempts() const { return _term_attempts; }15181519private:1520inline bool offer_termination();1521};15221523#endif // SHARE_GC_G1_G1COLLECTEDHEAP_HPP152415251526