Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
38920 views
/*1* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP25#define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP2627#include "gc_implementation/g1/g1AllocationContext.hpp"28#include "gc_implementation/g1/g1Allocator.hpp"29#include "gc_implementation/g1/concurrentMark.hpp"30#include "gc_implementation/g1/evacuationInfo.hpp"31#include "gc_implementation/g1/g1AllocRegion.hpp"32#include "gc_implementation/g1/g1BiasedArray.hpp"33#include "gc_implementation/g1/g1HRPrinter.hpp"34#include "gc_implementation/g1/g1InCSetState.hpp"35#include "gc_implementation/g1/g1MonitoringSupport.hpp"36#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"37#include "gc_implementation/g1/g1YCTypes.hpp"38#include "gc_implementation/g1/heapRegionManager.hpp"39#include "gc_implementation/g1/heapRegionSet.hpp"40#include "gc_implementation/shared/gcHeapSummary.hpp"41#include "gc_implementation/shared/hSpaceCounters.hpp"42#include "gc_implementation/shared/parGCAllocBuffer.hpp"43#include "memory/barrierSet.hpp"44#include "memory/memRegion.hpp"45#include "memory/sharedHeap.hpp"46#include "utilities/macros.hpp"47#include "utilities/stack.hpp"4849// A "G1CollectedHeap" is an implementation of a java heap for HotSpot.50// It uses the "Garbage First" heap organization and algorithm, which51// may combine concurrent marking with parallel, incremental compaction of52// heap subsets that will yield large amounts of garbage.5354// Forward declarations55class HeapRegion;56class HRRSCleanupTask;57class GenerationSpec;58class OopsInHeapRegionClosure;59class G1KlassScanClosure;60class G1ScanHeapEvacClosure;61class ObjectClosure;62class SpaceClosure;63class CompactibleSpaceClosure;64class Space;65class G1CollectorPolicy;66class GenRemSet;67class G1RemSet;68class HeapRegionRemSetIterator;69class ConcurrentMark;70class ConcurrentMarkThread;71class ConcurrentG1Refine;72class ConcurrentGCTimer;73class GenerationCounters;74class STWGCTimer;75class G1NewTracer;76class G1OldTracer;77class EvacuationFailedInfo;78class nmethod;7980typedef OverflowTaskQueue<StarTask, mtGC> RefToScanQueue;81typedef GenericTaskQueueSet<RefToScanQueue, mtGC> RefToScanQueueSet;8283typedef int RegionIdx_t; // needs to hold [ 0..max_regions() )84typedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion )8586class YoungList : public CHeapObj<mtGC> {87private:88G1CollectedHeap* _g1h;8990HeapRegion* _head;9192HeapRegion* _survivor_head;93HeapRegion* _survivor_tail;9495HeapRegion* _curr;9697uint _length;98uint _survivor_length;99100size_t _last_sampled_rs_lengths;101size_t _sampled_rs_lengths;102103void empty_list(HeapRegion* list);104105public:106YoungList(G1CollectedHeap* g1h);107108void push_region(HeapRegion* hr);109void add_survivor_region(HeapRegion* hr);110111void empty_list();112bool is_empty() { return _length == 0; }113uint length() { return _length; }114uint survivor_length() { return _survivor_length; }115116// Currently we do not keep track of the used byte sum for the117// young list and the survivors and it'd be quite a lot of work to118// do so. When we'll eventually replace the young list with119// instances of HeapRegionLinkedList we'll get that for free. So,120// we'll report the more accurate information then.121size_t eden_used_bytes() {122assert(length() >= survivor_length(), "invariant");123return (size_t) (length() - survivor_length()) * HeapRegion::GrainBytes;124}125size_t survivor_used_bytes() {126return (size_t) survivor_length() * HeapRegion::GrainBytes;127}128129void rs_length_sampling_init();130bool rs_length_sampling_more();131void rs_length_sampling_next();132133void reset_sampled_info() {134_last_sampled_rs_lengths = 0;135}136size_t sampled_rs_lengths() { return _last_sampled_rs_lengths; }137138// for development purposes139void reset_auxilary_lists();140void clear() { _head = NULL; _length = 0; }141142void clear_survivors() {143_survivor_head = NULL;144_survivor_tail = NULL;145_survivor_length = 0;146}147148HeapRegion* first_region() { return _head; }149HeapRegion* first_survivor_region() { return _survivor_head; }150HeapRegion* last_survivor_region() { return _survivor_tail; }151152// debugging153bool check_list_well_formed();154bool check_list_empty(bool check_sample = true);155void print();156};157158// The G1 STW is alive closure.159// An instance is embedded into the G1CH and used as the160// (optional) _is_alive_non_header closure in the STW161// reference processor. It is also extensively used during162// reference processing during STW evacuation pauses.163class G1STWIsAliveClosure: public BoolObjectClosure {164G1CollectedHeap* _g1;165public:166G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {}167bool do_object_b(oop p);168};169170class RefineCardTableEntryClosure;171172class G1RegionMappingChangedListener : public G1MappingChangedListener {173private:174void reset_from_card_cache(uint start_idx, size_t num_regions);175public:176virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);177};178179class G1CollectedHeap : public SharedHeap {180friend class VM_CollectForMetadataAllocation;181friend class VM_G1CollectForAllocation;182friend class VM_G1CollectFull;183friend class VM_G1IncCollectionPause;184friend class VMStructs;185friend class MutatorAllocRegion;186friend class SurvivorGCAllocRegion;187friend class OldGCAllocRegion;188friend class G1Allocator;189friend class G1DefaultAllocator;190friend class G1ResManAllocator;191192// Closures used in implementation.193template <G1Barrier barrier, G1Mark do_mark_object>194friend class G1ParCopyClosure;195friend class G1IsAliveClosure;196friend class G1EvacuateFollowersClosure;197friend class G1ParScanThreadState;198friend class G1ParScanClosureSuper;199friend class G1ParEvacuateFollowersClosure;200friend class G1ParTask;201friend class G1ParGCAllocator;202friend class G1DefaultParGCAllocator;203friend class G1FreeGarbageRegionClosure;204friend class RefineCardTableEntryClosure;205friend class G1PrepareCompactClosure;206friend class RegionSorter;207friend class RegionResetter;208friend class CountRCClosure;209friend class EvacPopObjClosure;210friend class G1ParCleanupCTTask;211212friend class G1FreeHumongousRegionClosure;213// Other related classes.214friend class G1MarkSweep;215216// Testing classes.217friend class G1CheckCSetFastTableClosure;218219private:220// The one and only G1CollectedHeap, so static functions can find it.221static G1CollectedHeap* _g1h;222223static size_t _humongous_object_threshold_in_words;224225// The secondary free list which contains regions that have been226// freed up during the cleanup process. This will be appended to227// the master free list when appropriate.228FreeRegionList _secondary_free_list;229230// It keeps track of the old regions.231HeapRegionSet _old_set;232233// It keeps track of the humongous regions.234HeapRegionSet _humongous_set;235236void eagerly_reclaim_humongous_regions();237238// The number of regions we could create by expansion.239uint _expansion_regions;240241// The block offset table for the G1 heap.242G1BlockOffsetSharedArray* _bot_shared;243244// Tears down the region sets / lists so that they are empty and the245// regions on the heap do not belong to a region set / list. The246// only exception is the humongous set which we leave unaltered. If247// free_list_only is true, it will only tear down the master free248// list. It is called before a Full GC (free_list_only == false) or249// before heap shrinking (free_list_only == true).250void tear_down_region_sets(bool free_list_only);251252// Rebuilds the region sets / lists so that they are repopulated to253// reflect the contents of the heap. The only exception is the254// humongous set which was not torn down in the first place. If255// free_list_only is true, it will only rebuild the master free256// list. It is called after a Full GC (free_list_only == false) or257// after heap shrinking (free_list_only == true).258void rebuild_region_sets(bool free_list_only);259260// Callback for region mapping changed events.261G1RegionMappingChangedListener _listener;262263// The sequence of all heap regions in the heap.264HeapRegionManager _hrm;265266// Class that handles the different kinds of allocations.267G1Allocator* _allocator;268269// Statistics for each allocation context270AllocationContextStats _allocation_context_stats;271272// PLAB sizing policy for survivors.273PLABStats _survivor_plab_stats;274275// PLAB sizing policy for tenured objects.276PLABStats _old_plab_stats;277278// It specifies whether we should attempt to expand the heap after a279// region allocation failure. If heap expansion fails we set this to280// false so that we don't re-attempt the heap expansion (it's likely281// that subsequent expansion attempts will also fail if one fails).282// Currently, it is only consulted during GC and it's reset at the283// start of each GC.284bool _expand_heap_after_alloc_failure;285286// It resets the mutator alloc region before new allocations can take place.287void init_mutator_alloc_region();288289// It releases the mutator alloc region.290void release_mutator_alloc_region();291292// It initializes the GC alloc regions at the start of a GC.293void init_gc_alloc_regions(EvacuationInfo& evacuation_info);294295// It releases the GC alloc regions at the end of a GC.296void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info);297298// It does any cleanup that needs to be done on the GC alloc regions299// before a Full GC.300void abandon_gc_alloc_regions();301302// Helper for monitoring and management support.303G1MonitoringSupport* _g1mm;304305// Records whether the region at the given index is (still) a306// candidate for eager reclaim. Only valid for humongous start307// regions; other regions have unspecified values. Humongous start308// regions are initialized at start of collection pause, with309// candidates removed from the set as they are found reachable from310// roots or the young generation.311class HumongousReclaimCandidates : public G1BiasedMappedArray<bool> {312protected:313bool default_value() const { return false; }314public:315void clear() { G1BiasedMappedArray<bool>::clear(); }316void set_candidate(uint region, bool value) {317set_by_index(region, value);318}319bool is_candidate(uint region) {320return get_by_index(region);321}322};323324HumongousReclaimCandidates _humongous_reclaim_candidates;325// Stores whether during humongous object registration we found candidate regions.326// If not, we can skip a few steps.327bool _has_humongous_reclaim_candidates;328329volatile unsigned _gc_time_stamp;330331size_t* _surviving_young_words;332333G1HRPrinter _hr_printer;334335void setup_surviving_young_words();336void update_surviving_young_words(size_t* surv_young_words);337void cleanup_surviving_young_words();338339// It decides whether an explicit GC should start a concurrent cycle340// instead of doing a STW GC. Currently, a concurrent cycle is341// explicitly started if:342// (a) cause == _gc_locker and +GCLockerInvokesConcurrent, or343// (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent.344// (c) cause == _g1_humongous_allocation345bool should_do_concurrent_full_gc(GCCause::Cause cause);346347// Keeps track of how many "old marking cycles" (i.e., Full GCs or348// concurrent cycles) we have started.349volatile uint _old_marking_cycles_started;350351// Keeps track of how many "old marking cycles" (i.e., Full GCs or352// concurrent cycles) we have completed.353volatile uint _old_marking_cycles_completed;354355bool _concurrent_cycle_started;356bool _heap_summary_sent;357358// This is a non-product method that is helpful for testing. It is359// called at the end of a GC and artificially expands the heap by360// allocating a number of dead regions. This way we can induce very361// frequent marking cycles and stress the cleanup / concurrent362// cleanup code more (as all the regions that will be allocated by363// this method will be found dead by the marking cycle).364void allocate_dummy_regions() PRODUCT_RETURN;365366// Clear RSets after a compaction. It also resets the GC time stamps.367void clear_rsets_post_compaction();368369// If the HR printer is active, dump the state of the regions in the370// heap after a compaction.371void print_hrm_post_compaction();372373// Create a memory mapper for auxiliary data structures of the given size and374// translation factor.375static G1RegionToSpaceMapper* create_aux_memory_mapper(const char* description,376size_t size,377size_t translation_factor);378379void trace_heap(GCWhen::Type when, GCTracer* tracer);380381double verify(bool guard, const char* msg);382void verify_before_gc();383void verify_after_gc();384385void log_gc_header();386void log_gc_footer(double pause_time_sec);387388// These are macros so that, if the assert fires, we get the correct389// line number, file, etc.390391#define heap_locking_asserts_err_msg(_extra_message_) \392err_msg("%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \393(_extra_message_), \394BOOL_TO_STR(Heap_lock->owned_by_self()), \395BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), \396BOOL_TO_STR(Thread::current()->is_VM_thread()))397398#define assert_heap_locked() \399do { \400assert(Heap_lock->owned_by_self(), \401heap_locking_asserts_err_msg("should be holding the Heap_lock")); \402} while (0)403404#define assert_heap_locked_or_at_safepoint(_should_be_vm_thread_) \405do { \406assert(Heap_lock->owned_by_self() || \407(SafepointSynchronize::is_at_safepoint() && \408((_should_be_vm_thread_) == Thread::current()->is_VM_thread())), \409heap_locking_asserts_err_msg("should be holding the Heap_lock or " \410"should be at a safepoint")); \411} while (0)412413#define assert_heap_locked_and_not_at_safepoint() \414do { \415assert(Heap_lock->owned_by_self() && \416!SafepointSynchronize::is_at_safepoint(), \417heap_locking_asserts_err_msg("should be holding the Heap_lock and " \418"should not be at a safepoint")); \419} while (0)420421#define assert_heap_not_locked() \422do { \423assert(!Heap_lock->owned_by_self(), \424heap_locking_asserts_err_msg("should not be holding the Heap_lock")); \425} while (0)426427#define assert_heap_not_locked_and_not_at_safepoint() \428do { \429assert(!Heap_lock->owned_by_self() && \430!SafepointSynchronize::is_at_safepoint(), \431heap_locking_asserts_err_msg("should not be holding the Heap_lock and " \432"should not be at a safepoint")); \433} while (0)434435#define assert_at_safepoint(_should_be_vm_thread_) \436do { \437assert(SafepointSynchronize::is_at_safepoint() && \438((_should_be_vm_thread_) == Thread::current()->is_VM_thread()), \439heap_locking_asserts_err_msg("should be at a safepoint")); \440} while (0)441442#define assert_not_at_safepoint() \443do { \444assert(!SafepointSynchronize::is_at_safepoint(), \445heap_locking_asserts_err_msg("should not be at a safepoint")); \446} while (0)447448protected:449450// The young region list.451YoungList* _young_list;452453// The current policy object for the collector.454G1CollectorPolicy* _g1_policy;455456// This is the second level of trying to allocate a new region. If457// new_region() didn't find a region on the free_list, this call will458// check whether there's anything available on the459// secondary_free_list and/or wait for more regions to appear on460// that list, if _free_regions_coming is set.461HeapRegion* new_region_try_secondary_free_list(bool is_old);462463// Try to allocate a single non-humongous HeapRegion sufficient for464// an allocation of the given word_size. If do_expand is true,465// attempt to expand the heap if necessary to satisfy the allocation466// request. If the region is to be used as an old region or for a467// humongous object, set is_old to true. If not, to false.468HeapRegion* new_region(size_t word_size, bool is_old, bool do_expand);469470// Initialize a contiguous set of free regions of length num_regions471// and starting at index first so that they appear as a single472// humongous region.473HeapWord* humongous_obj_allocate_initialize_regions(uint first,474uint num_regions,475size_t word_size,476AllocationContext_t context);477478// Attempt to allocate a humongous object of the given size. Return479// NULL if unsuccessful.480HeapWord* humongous_obj_allocate(size_t word_size, AllocationContext_t context);481482// The following two methods, allocate_new_tlab() and483// mem_allocate(), are the two main entry points from the runtime484// into the G1's allocation routines. They have the following485// assumptions:486//487// * They should both be called outside safepoints.488//489// * They should both be called without holding the Heap_lock.490//491// * All allocation requests for new TLABs should go to492// allocate_new_tlab().493//494// * All non-TLAB allocation requests should go to mem_allocate().495//496// * If either call cannot satisfy the allocation request using the497// current allocating region, they will try to get a new one. If498// this fails, they will attempt to do an evacuation pause and499// retry the allocation.500//501// * If all allocation attempts fail, even after trying to schedule502// an evacuation pause, allocate_new_tlab() will return NULL,503// whereas mem_allocate() will attempt a heap expansion and/or504// schedule a Full GC.505//506// * We do not allow humongous-sized TLABs. So, allocate_new_tlab507// should never be called with word_size being humongous. All508// humongous allocation requests should go to mem_allocate() which509// will satisfy them with a special path.510511virtual HeapWord* allocate_new_tlab(size_t word_size);512513virtual HeapWord* mem_allocate(size_t word_size,514bool* gc_overhead_limit_was_exceeded);515516// The following three methods take a gc_count_before_ret517// parameter which is used to return the GC count if the method518// returns NULL. Given that we are required to read the GC count519// while holding the Heap_lock, and these paths will take the520// Heap_lock at some point, it's easier to get them to read the GC521// count while holding the Heap_lock before they return NULL instead522// of the caller (namely: mem_allocate()) having to also take the523// Heap_lock just to read the GC count.524525// First-level mutator allocation attempt: try to allocate out of526// the mutator alloc region without taking the Heap_lock. This527// should only be used for non-humongous allocations.528inline HeapWord* attempt_allocation(size_t word_size,529uint* gc_count_before_ret,530uint* gclocker_retry_count_ret);531532// Second-level mutator allocation attempt: take the Heap_lock and533// retry the allocation attempt, potentially scheduling a GC534// pause. This should only be used for non-humongous allocations.535HeapWord* attempt_allocation_slow(size_t word_size,536AllocationContext_t context,537uint* gc_count_before_ret,538uint* gclocker_retry_count_ret);539540// Takes the Heap_lock and attempts a humongous allocation. It can541// potentially schedule a GC pause.542HeapWord* attempt_allocation_humongous(size_t word_size,543uint* gc_count_before_ret,544uint* gclocker_retry_count_ret);545546// Allocation attempt that should be called during safepoints (e.g.,547// at the end of a successful GC). expect_null_mutator_alloc_region548// specifies whether the mutator alloc region is expected to be NULL549// or not.550HeapWord* attempt_allocation_at_safepoint(size_t word_size,551AllocationContext_t context,552bool expect_null_mutator_alloc_region);553554// It dirties the cards that cover the block so that so that the post555// write barrier never queues anything when updating objects on this556// block. It is assumed (and in fact we assert) that the block557// belongs to a young region.558inline void dirty_young_block(HeapWord* start, size_t word_size);559560// Allocate blocks during garbage collection. Will ensure an561// allocation region, either by picking one or expanding the562// heap, and then allocate a block of the given size. The block563// may not be a humongous - it must fit into a single heap region.564inline HeapWord* par_allocate_during_gc(InCSetState dest,565size_t word_size,566AllocationContext_t context);567// Ensure that no further allocations can happen in "r", bearing in mind568// that parallel threads might be attempting allocations.569void par_allocate_remaining_space(HeapRegion* r);570571// Allocation attempt during GC for a survivor object / PLAB.572inline HeapWord* survivor_attempt_allocation(size_t word_size,573AllocationContext_t context);574575// Allocation attempt during GC for an old object / PLAB.576inline HeapWord* old_attempt_allocation(size_t word_size,577AllocationContext_t context);578579// These methods are the "callbacks" from the G1AllocRegion class.580581// For mutator alloc regions.582HeapRegion* new_mutator_alloc_region(size_t word_size, bool force);583void retire_mutator_alloc_region(HeapRegion* alloc_region,584size_t allocated_bytes);585586// For GC alloc regions.587HeapRegion* new_gc_alloc_region(size_t word_size, uint count,588InCSetState dest);589void retire_gc_alloc_region(HeapRegion* alloc_region,590size_t allocated_bytes, InCSetState dest);591592// - if explicit_gc is true, the GC is for a System.gc() or a heap593// inspection request and should collect the entire heap594// - if clear_all_soft_refs is true, all soft references should be595// cleared during the GC596// - if explicit_gc is false, word_size describes the allocation that597// the GC should attempt (at least) to satisfy598// - it returns false if it is unable to do the collection due to the599// GC locker being active, true otherwise600bool do_collection(bool explicit_gc,601bool clear_all_soft_refs,602size_t word_size);603604// Callback from VM_G1CollectFull operation.605// Perform a full collection.606virtual void do_full_collection(bool clear_all_soft_refs);607608// Resize the heap if necessary after a full collection. If this is609// after a collect-for allocation, "word_size" is the allocation size,610// and will be considered part of the used portion of the heap.611void resize_if_necessary_after_full_collection(size_t word_size);612613// Callback from VM_G1CollectForAllocation operation.614// This function does everything necessary/possible to satisfy a615// failed allocation request (including collection, expansion, etc.)616HeapWord* satisfy_failed_allocation(size_t word_size,617AllocationContext_t context,618bool* succeeded);619620// Attempting to expand the heap sufficiently621// to support an allocation of the given "word_size". If622// successful, perform the allocation and return the address of the623// allocated block, or else "NULL".624HeapWord* expand_and_allocate(size_t word_size, AllocationContext_t context);625626// Process any reference objects discovered during627// an incremental evacuation pause.628void process_discovered_references(uint no_of_gc_workers);629630// Enqueue any remaining discovered references631// after processing.632void enqueue_discovered_references(uint no_of_gc_workers);633634public:635636G1Allocator* allocator() {637return _allocator;638}639640G1MonitoringSupport* g1mm() {641assert(_g1mm != NULL, "should have been initialized");642return _g1mm;643}644645// Expand the garbage-first heap by at least the given size (in bytes!).646// Returns true if the heap was expanded by the requested amount;647// false otherwise.648// (Rounds up to a HeapRegion boundary.)649bool expand(size_t expand_bytes);650651// Returns the PLAB statistics for a given destination.652inline PLABStats* alloc_buffer_stats(InCSetState dest);653654// Determines PLAB size for a given destination.655inline size_t desired_plab_sz(InCSetState dest);656657inline AllocationContextStats& allocation_context_stats();658659// Do anything common to GC's.660virtual void gc_prologue(bool full);661virtual void gc_epilogue(bool full);662663// Modify the reclaim candidate set and test for presence.664// These are only valid for starts_humongous regions.665inline void set_humongous_reclaim_candidate(uint region, bool value);666inline bool is_humongous_reclaim_candidate(uint region);667668// Remove from the reclaim candidate set. Also remove from the669// collection set so that later encounters avoid the slow path.670inline void set_humongous_is_live(oop obj);671672// Register the given region to be part of the collection set.673inline void register_humongous_region_with_in_cset_fast_test(uint index);674// Register regions with humongous objects (actually on the start region) in675// the in_cset_fast_test table.676void register_humongous_regions_with_in_cset_fast_test();677// We register a region with the fast "in collection set" test. We678// simply set to true the array slot corresponding to this region.679void register_young_region_with_in_cset_fast_test(HeapRegion* r) {680_in_cset_fast_test.set_in_young(r->hrm_index());681}682void register_old_region_with_in_cset_fast_test(HeapRegion* r) {683_in_cset_fast_test.set_in_old(r->hrm_index());684}685686// This is a fast test on whether a reference points into the687// collection set or not. Assume that the reference688// points into the heap.689inline bool in_cset_fast_test(oop obj);690691void clear_cset_fast_test() {692_in_cset_fast_test.clear();693}694695// This is called at the start of either a concurrent cycle or a Full696// GC to update the number of old marking cycles started.697void increment_old_marking_cycles_started();698699// This is called at the end of either a concurrent cycle or a Full700// GC to update the number of old marking cycles completed. Those two701// can happen in a nested fashion, i.e., we start a concurrent702// cycle, a Full GC happens half-way through it which ends first,703// and then the cycle notices that a Full GC happened and ends704// too. The concurrent parameter is a boolean to help us do a bit705// tighter consistency checking in the method. If concurrent is706// false, the caller is the inner caller in the nesting (i.e., the707// Full GC). If concurrent is true, the caller is the outer caller708// in this nesting (i.e., the concurrent cycle). Further nesting is709// not currently supported. The end of this call also notifies710// the FullGCCount_lock in case a Java thread is waiting for a full711// GC to happen (e.g., it called System.gc() with712// +ExplicitGCInvokesConcurrent).713void increment_old_marking_cycles_completed(bool concurrent);714715uint old_marking_cycles_completed() {716return _old_marking_cycles_completed;717}718719void register_concurrent_cycle_start(const Ticks& start_time);720void register_concurrent_cycle_end();721void trace_heap_after_concurrent_cycle();722723G1YCType yc_type();724725G1HRPrinter* hr_printer() { return &_hr_printer; }726727// Frees a non-humongous region by initializing its contents and728// adding it to the free list that's passed as a parameter (this is729// usually a local list which will be appended to the master free730// list later). The used bytes of freed regions are accumulated in731// pre_used. If par is true, the region's RSet will not be freed732// up. The assumption is that this will be done later.733// The locked parameter indicates if the caller has already taken734// care of proper synchronization. This may allow some optimizations.735void free_region(HeapRegion* hr,736FreeRegionList* free_list,737bool par,738bool locked = false);739740// Frees a humongous region by collapsing it into individual regions741// and calling free_region() for each of them. The freed regions742// will be added to the free list that's passed as a parameter (this743// is usually a local list which will be appended to the master free744// list later). The used bytes of freed regions are accumulated in745// pre_used. If par is true, the region's RSet will not be freed746// up. The assumption is that this will be done later.747void free_humongous_region(HeapRegion* hr,748FreeRegionList* free_list,749bool par);750protected:751752// Shrink the garbage-first heap by at most the given size (in bytes!).753// (Rounds down to a HeapRegion boundary.)754virtual void shrink(size_t expand_bytes);755void shrink_helper(size_t expand_bytes);756757#if TASKQUEUE_STATS758static void print_taskqueue_stats_hdr(outputStream* const st = gclog_or_tty);759void print_taskqueue_stats(outputStream* const st = gclog_or_tty) const;760void reset_taskqueue_stats();761#endif // TASKQUEUE_STATS762763// Schedule the VM operation that will do an evacuation pause to764// satisfy an allocation request of word_size. *succeeded will765// return whether the VM operation was successful (it did do an766// evacuation pause) or not (another thread beat us to it or the GC767// locker was active). Given that we should not be holding the768// Heap_lock when we enter this method, we will pass the769// gc_count_before (i.e., total_collections()) as a parameter since770// it has to be read while holding the Heap_lock. Currently, both771// methods that call do_collection_pause() release the Heap_lock772// before the call, so it's easy to read gc_count_before just before.773HeapWord* do_collection_pause(size_t word_size,774uint gc_count_before,775bool* succeeded,776GCCause::Cause gc_cause);777778// The guts of the incremental collection pause, executed by the vm779// thread. It returns false if it is unable to do the collection due780// to the GC locker being active, true otherwise781bool do_collection_pause_at_safepoint(double target_pause_time_ms);782783// Actually do the work of evacuating the collection set.784void evacuate_collection_set(EvacuationInfo& evacuation_info);785786// The g1 remembered set of the heap.787G1RemSet* _g1_rem_set;788789// A set of cards that cover the objects for which the Rsets should be updated790// concurrently after the collection.791DirtyCardQueueSet _dirty_card_queue_set;792793// The closure used to refine a single card.794RefineCardTableEntryClosure* _refine_cte_cl;795796// A function to check the consistency of dirty card logs.797void check_ct_logs_at_safepoint();798799// A DirtyCardQueueSet that is used to hold cards that contain800// references into the current collection set. This is used to801// update the remembered sets of the regions in the collection802// set in the event of an evacuation failure.803DirtyCardQueueSet _into_cset_dirty_card_queue_set;804805// After a collection pause, make the regions in the CS into free806// regions.807void free_collection_set(HeapRegion* cs_head, EvacuationInfo& evacuation_info);808809// Abandon the current collection set without recording policy810// statistics or updating free lists.811void abandon_collection_set(HeapRegion* cs_head);812813// The concurrent marker (and the thread it runs in.)814ConcurrentMark* _cm;815ConcurrentMarkThread* _cmThread;816bool _mark_in_progress;817818// The concurrent refiner.819ConcurrentG1Refine* _cg1r;820821// The parallel task queues822RefToScanQueueSet *_task_queues;823824// True iff a evacuation has failed in the current collection.825bool _evacuation_failed;826827EvacuationFailedInfo* _evacuation_failed_info_array;828829// Failed evacuations cause some logical from-space objects to have830// forwarding pointers to themselves. Reset them.831void remove_self_forwarding_pointers();832833// Together, these store an object with a preserved mark, and its mark value.834Stack<oop, mtGC> _objs_with_preserved_marks;835Stack<markOop, mtGC> _preserved_marks_of_objs;836837// Preserve the mark of "obj", if necessary, in preparation for its mark838// word being overwritten with a self-forwarding-pointer.839void preserve_mark_if_necessary(oop obj, markOop m);840841// The stack of evac-failure objects left to be scanned.842GrowableArray<oop>* _evac_failure_scan_stack;843// The closure to apply to evac-failure objects.844845OopsInHeapRegionClosure* _evac_failure_closure;846// Set the field above.847void848set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_closure) {849_evac_failure_closure = evac_failure_closure;850}851852// Push "obj" on the scan stack.853void push_on_evac_failure_scan_stack(oop obj);854// Process scan stack entries until the stack is empty.855void drain_evac_failure_scan_stack();856// True iff an invocation of "drain_scan_stack" is in progress; to857// prevent unnecessary recursion.858bool _drain_in_progress;859860// Do any necessary initialization for evacuation-failure handling.861// "cl" is the closure that will be used to process evac-failure862// objects.863void init_for_evac_failure(OopsInHeapRegionClosure* cl);864// Do any necessary cleanup for evacuation-failure handling data865// structures.866void finalize_for_evac_failure();867868// An attempt to evacuate "obj" has failed; take necessary steps.869oop handle_evacuation_failure_par(G1ParScanThreadState* _par_scan_state, oop obj);870void handle_evacuation_failure_common(oop obj, markOop m);871872#ifndef PRODUCT873// Support for forcing evacuation failures. Analogous to874// PromotionFailureALot for the other collectors.875876// Records whether G1EvacuationFailureALot should be in effect877// for the current GC878bool _evacuation_failure_alot_for_current_gc;879880// Used to record the GC number for interval checking when881// determining whether G1EvaucationFailureALot is in effect882// for the current GC.883size_t _evacuation_failure_alot_gc_number;884885// Count of the number of evacuations between failures.886volatile size_t _evacuation_failure_alot_count;887888// Set whether G1EvacuationFailureALot should be in effect889// for the current GC (based upon the type of GC and which890// command line flags are set);891inline bool evacuation_failure_alot_for_gc_type(bool gcs_are_young,892bool during_initial_mark,893bool during_marking);894895inline void set_evacuation_failure_alot_for_current_gc();896897// Return true if it's time to cause an evacuation failure.898inline bool evacuation_should_fail();899900// Reset the G1EvacuationFailureALot counters. Should be called at901// the end of an evacuation pause in which an evacuation failure occurred.902inline void reset_evacuation_should_fail();903#endif // !PRODUCT904905// ("Weak") Reference processing support.906//907// G1 has 2 instances of the reference processor class. One908// (_ref_processor_cm) handles reference object discovery909// and subsequent processing during concurrent marking cycles.910//911// The other (_ref_processor_stw) handles reference object912// discovery and processing during full GCs and incremental913// evacuation pauses.914//915// During an incremental pause, reference discovery will be916// temporarily disabled for _ref_processor_cm and will be917// enabled for _ref_processor_stw. At the end of the evacuation918// pause references discovered by _ref_processor_stw will be919// processed and discovery will be disabled. The previous920// setting for reference object discovery for _ref_processor_cm921// will be re-instated.922//923// At the start of marking:924// * Discovery by the CM ref processor is verified to be inactive925// and it's discovered lists are empty.926// * Discovery by the CM ref processor is then enabled.927//928// At the end of marking:929// * Any references on the CM ref processor's discovered930// lists are processed (possibly MT).931//932// At the start of full GC we:933// * Disable discovery by the CM ref processor and934// empty CM ref processor's discovered lists935// (without processing any entries).936// * Verify that the STW ref processor is inactive and it's937// discovered lists are empty.938// * Temporarily set STW ref processor discovery as single threaded.939// * Temporarily clear the STW ref processor's _is_alive_non_header940// field.941// * Finally enable discovery by the STW ref processor.942//943// The STW ref processor is used to record any discovered944// references during the full GC.945//946// At the end of a full GC we:947// * Enqueue any reference objects discovered by the STW ref processor948// that have non-live referents. This has the side-effect of949// making the STW ref processor inactive by disabling discovery.950// * Verify that the CM ref processor is still inactive951// and no references have been placed on it's discovered952// lists (also checked as a precondition during initial marking).953954// The (stw) reference processor...955ReferenceProcessor* _ref_processor_stw;956957STWGCTimer* _gc_timer_stw;958ConcurrentGCTimer* _gc_timer_cm;959960G1OldTracer* _gc_tracer_cm;961G1NewTracer* _gc_tracer_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;977978// The (concurrent marking) reference processor...979ReferenceProcessor* _ref_processor_cm;980981// Instance of the concurrent mark is_alive closure for embedding982// into the Concurrent Marking reference processor as the983// _is_alive_non_header field. Supplying a value for the984// _is_alive_non_header field is optional but doing so prevents985// unnecessary additions to the discovered lists during reference986// discovery.987G1CMIsAliveClosure _is_alive_closure_cm;988989// Cache used by G1CollectedHeap::start_cset_region_for_worker().990HeapRegion** _worker_cset_start_region;991992// Time stamp to validate the regions recorded in the cache993// used by G1CollectedHeap::start_cset_region_for_worker().994// The heap region entry for a given worker is valid iff995// the associated time stamp value matches the current value996// of G1CollectedHeap::_gc_time_stamp.997uint* _worker_cset_start_region_time_stamp;998999volatile bool _free_regions_coming;10001001public:10021003void set_refine_cte_cl_concurrency(bool concurrent);10041005RefToScanQueue *task_queue(int i) const;10061007// A set of cards where updates happened during the GC1008DirtyCardQueueSet& dirty_card_queue_set() { return _dirty_card_queue_set; }10091010// A DirtyCardQueueSet that is used to hold cards that contain1011// references into the current collection set. This is used to1012// update the remembered sets of the regions in the collection1013// set in the event of an evacuation failure.1014DirtyCardQueueSet& into_cset_dirty_card_queue_set()1015{ return _into_cset_dirty_card_queue_set; }10161017// Create a G1CollectedHeap with the specified policy.1018// Must call the initialize method afterwards.1019// May not return if something goes wrong.1020G1CollectedHeap(G1CollectorPolicy* policy);10211022// Initialize the G1CollectedHeap to have the initial and1023// maximum sizes and remembered and barrier sets1024// specified by the policy object.1025jint initialize();10261027virtual void stop();10281029// Return the (conservative) maximum heap alignment for any G1 heap1030static size_t conservative_max_heap_alignment();10311032// Initialize weak reference processing.1033virtual void ref_processing_init();10341035// Explicitly import set_par_threads into this scope1036using SharedHeap::set_par_threads;1037// Set _n_par_threads according to a policy TBD.1038void set_par_threads();10391040virtual CollectedHeap::Name kind() const {1041return CollectedHeap::G1CollectedHeap;1042}10431044// The current policy object for the collector.1045G1CollectorPolicy* g1_policy() const { return _g1_policy; }10461047virtual CollectorPolicy* collector_policy() const { return (CollectorPolicy*) g1_policy(); }10481049// Adaptive size policy. No such thing for g1.1050virtual AdaptiveSizePolicy* size_policy() { return NULL; }10511052// The rem set and barrier set.1053G1RemSet* g1_rem_set() const { return _g1_rem_set; }10541055unsigned get_gc_time_stamp() {1056return _gc_time_stamp;1057}10581059inline void reset_gc_time_stamp();10601061void check_gc_time_stamps() PRODUCT_RETURN;10621063inline void increment_gc_time_stamp();10641065// Reset the given region's GC timestamp. If it's starts humongous,1066// also reset the GC timestamp of its corresponding1067// continues humongous regions too.1068void reset_gc_time_stamps(HeapRegion* hr);10691070void iterate_dirty_card_closure(CardTableEntryClosure* cl,1071DirtyCardQueue* into_cset_dcq,1072bool concurrent, uint worker_i);10731074// The shared block offset table array.1075G1BlockOffsetSharedArray* bot_shared() const { return _bot_shared; }10761077// Reference Processing accessors10781079// The STW reference processor....1080ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; }10811082// The Concurrent Marking reference processor...1083ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }10841085ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; }1086G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; }10871088virtual size_t capacity() const;1089virtual size_t used() const;1090// This should be called when we're not holding the heap lock. The1091// result might be a bit inaccurate.1092size_t used_unlocked() const;1093size_t recalculate_used() const;10941095// These virtual functions do the actual allocation.1096// Some heaps may offer a contiguous region for shared non-blocking1097// allocation, via inlined code (by exporting the address of the top and1098// end fields defining the extent of the contiguous allocation region.)1099// But G1CollectedHeap doesn't yet support this.11001101virtual bool is_maximal_no_gc() const {1102return _hrm.available() == 0;1103}11041105// The current number of regions in the heap.1106uint num_regions() const { return _hrm.length(); }11071108// The max number of regions in the heap.1109uint max_regions() const { return _hrm.max_length(); }11101111// The number of regions that are completely free.1112uint num_free_regions() const { return _hrm.num_free_regions(); }11131114MemoryUsage get_auxiliary_data_memory_usage() const {1115return _hrm.get_auxiliary_data_memory_usage();1116}11171118// The number of regions that are not completely free.1119uint num_used_regions() const { return num_regions() - num_free_regions(); }11201121void verify_not_dirty_region(HeapRegion* hr) PRODUCT_RETURN;1122void verify_dirty_region(HeapRegion* hr) PRODUCT_RETURN;1123void verify_dirty_young_list(HeapRegion* head) PRODUCT_RETURN;1124void verify_dirty_young_regions() PRODUCT_RETURN;11251126#ifndef PRODUCT1127// Make sure that the given bitmap has no marked objects in the1128// range [from,limit). If it does, print an error message and return1129// false. Otherwise, just return true. bitmap_name should be "prev"1130// or "next".1131bool verify_no_bits_over_tams(const char* bitmap_name, CMBitMapRO* bitmap,1132HeapWord* from, HeapWord* limit);11331134// Verify that the prev / next bitmap range [tams,end) for the given1135// region has no marks. Return true if all is well, false if errors1136// are detected.1137bool verify_bitmaps(const char* caller, HeapRegion* hr);1138#endif // PRODUCT11391140// If G1VerifyBitmaps is set, verify that the marking bitmaps for1141// the given region do not have any spurious marks. If errors are1142// detected, print appropriate error messages and crash.1143void check_bitmaps(const char* caller, HeapRegion* hr) PRODUCT_RETURN;11441145// If G1VerifyBitmaps is set, verify that the marking bitmaps do not1146// have any spurious marks. If errors are detected, print1147// appropriate error messages and crash.1148void check_bitmaps(const char* caller) PRODUCT_RETURN;11491150// Do sanity check on the contents of the in-cset fast test table.1151bool check_cset_fast_test() PRODUCT_RETURN_( return true; );11521153void verify_region_sets();11541155// verify_region_sets_optional() is planted in the code for1156// list verification in debug builds.1157void verify_region_sets_optional() { DEBUG_ONLY(verify_region_sets();) }11581159#ifdef ASSERT1160bool is_on_master_free_list(HeapRegion* hr) {1161return _hrm.is_free(hr);1162}1163#endif // ASSERT11641165// Wrapper for the region list operations that can be called from1166// methods outside this class.11671168void secondary_free_list_add(FreeRegionList* list) {1169_secondary_free_list.add_ordered(list);1170}11711172void append_secondary_free_list() {1173_hrm.insert_list_into_free_list(&_secondary_free_list);1174}11751176void append_secondary_free_list_if_not_empty_with_lock() {1177// If the secondary free list looks empty there's no reason to1178// take the lock and then try to append it.1179if (!_secondary_free_list.is_empty()) {1180MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);1181append_secondary_free_list();1182}1183}11841185inline void old_set_remove(HeapRegion* hr);11861187size_t non_young_capacity_bytes() {1188return _old_set.total_capacity_bytes() + _humongous_set.total_capacity_bytes();1189}11901191void set_free_regions_coming();1192void reset_free_regions_coming();1193bool free_regions_coming() { return _free_regions_coming; }1194void wait_while_free_regions_coming();11951196// Determine whether the given region is one that we are using as an1197// old GC alloc region.1198bool is_old_gc_alloc_region(HeapRegion* hr) {1199return _allocator->is_retained_old_region(hr);1200}12011202// Perform a collection of the heap; intended for use in implementing1203// "System.gc". This probably implies as full a collection as the1204// "CollectedHeap" supports.1205virtual void collect(GCCause::Cause cause);12061207// The same as above but assume that the caller holds the Heap_lock.1208void collect_locked(GCCause::Cause cause);12091210virtual bool copy_allocation_context_stats(const jint* contexts,1211jlong* totals,1212jbyte* accuracy,1213jint len);12141215// True iff an evacuation has failed in the most-recent collection.1216bool evacuation_failed() { return _evacuation_failed; }12171218void remove_from_old_sets(const HeapRegionSetCount& old_regions_removed, const HeapRegionSetCount& humongous_regions_removed);1219void prepend_to_freelist(FreeRegionList* list);1220void decrement_summary_bytes(size_t bytes);12211222// Returns "TRUE" iff "p" points into the committed areas of the heap.1223virtual bool is_in(const void* p) const;1224#ifdef ASSERT1225// Returns whether p is in one of the available areas of the heap. Slow but1226// extensive version.1227bool is_in_exact(const void* p) const;1228#endif12291230// Return "TRUE" iff the given object address is within the collection1231// set. Slow implementation.1232inline bool obj_in_cs(oop obj);12331234inline bool is_in_cset(oop obj);12351236inline bool is_in_cset_or_humongous(const oop obj);12371238private:1239// This array is used for a quick test on whether a reference points into1240// the collection set or not. Each of the array's elements denotes whether the1241// corresponding region is in the collection set or not.1242G1InCSetStateFastTestBiasedMappedArray _in_cset_fast_test;12431244public:12451246inline InCSetState in_cset_state(const oop obj);12471248// Return "TRUE" iff the given object address is in the reserved1249// region of g1.1250bool is_in_g1_reserved(const void* p) const {1251return _hrm.reserved().contains(p);1252}12531254// Returns a MemRegion that corresponds to the space that has been1255// reserved for the heap1256MemRegion g1_reserved() const {1257return _hrm.reserved();1258}12591260virtual bool is_in_closed_subset(const void* p) const;12611262G1SATBCardTableLoggingModRefBS* g1_barrier_set() {1263return (G1SATBCardTableLoggingModRefBS*) barrier_set();1264}12651266// This resets the card table to all zeros. It is used after1267// a collection pause which used the card table to claim cards.1268void cleanUpCardTable();12691270// Iteration functions.12711272// Iterate over all the ref-containing fields of all objects, calling1273// "cl.do_oop" on each.1274virtual void oop_iterate(ExtendedOopClosure* cl);12751276// Iterate over all objects, calling "cl.do_object" on each.1277virtual void object_iterate(ObjectClosure* cl);12781279virtual void safe_object_iterate(ObjectClosure* cl) {1280object_iterate(cl);1281}12821283// Iterate over all spaces in use in the heap, in ascending address order.1284virtual void space_iterate(SpaceClosure* cl);12851286// Iterate over heap regions, in address order, terminating the1287// iteration early if the "doHeapRegion" method returns "true".1288void heap_region_iterate(HeapRegionClosure* blk) const;12891290// Return the region with the given index. It assumes the index is valid.1291inline HeapRegion* region_at(uint index) const;12921293// Calculate the region index of the given address. Given address must be1294// within the heap.1295inline uint addr_to_region(HeapWord* addr) const;12961297inline HeapWord* bottom_addr_for_region(uint index) const;12981299// Divide the heap region sequence into "chunks" of some size (the number1300// of regions divided by the number of parallel threads times some1301// overpartition factor, currently 4). Assumes that this will be called1302// in parallel by ParallelGCThreads worker threads with discinct worker1303// ids in the range [0..max(ParallelGCThreads-1, 1)], that all parallel1304// calls will use the same "claim_value", and that that claim value is1305// different from the claim_value of any heap region before the start of1306// the iteration. Applies "blk->doHeapRegion" to each of the regions, by1307// attempting to claim the first region in each chunk, and, if1308// successful, applying the closure to each region in the chunk (and1309// setting the claim value of the second and subsequent regions of the1310// chunk.) For now requires that "doHeapRegion" always returns "false",1311// i.e., that a closure never attempt to abort a traversal.1312void heap_region_par_iterate_chunked(HeapRegionClosure* cl,1313uint worker_id,1314uint num_workers,1315jint claim_value) const;13161317// It resets all the region claim values to the default.1318void reset_heap_region_claim_values();13191320// Resets the claim values of regions in the current1321// collection set to the default.1322void reset_cset_heap_region_claim_values();13231324#ifdef ASSERT1325bool check_heap_region_claim_values(jint claim_value);13261327// Same as the routine above but only checks regions in the1328// current collection set.1329bool check_cset_heap_region_claim_values(jint claim_value);1330#endif // ASSERT13311332// Clear the cached cset start regions and (more importantly)1333// the time stamps. Called when we reset the GC time stamp.1334void clear_cset_start_regions();13351336// Given the id of a worker, obtain or calculate a suitable1337// starting region for iterating over the current collection set.1338HeapRegion* start_cset_region_for_worker(uint worker_i);13391340// Iterate over the regions (if any) in the current collection set.1341void collection_set_iterate(HeapRegionClosure* blk);13421343// As above but starting from region r1344void collection_set_iterate_from(HeapRegion* r, HeapRegionClosure *blk);13451346HeapRegion* next_compaction_region(const HeapRegion* from) const;13471348// A CollectedHeap will contain some number of spaces. This finds the1349// space containing a given address, or else returns NULL.1350virtual Space* space_containing(const void* addr) const;13511352// Returns the HeapRegion that contains addr. addr must not be NULL.1353template <class T>1354inline HeapRegion* heap_region_containing_raw(const T addr) const;13551356// Returns the HeapRegion that contains addr. addr must not be NULL.1357// If addr is within a humongous continues region, it returns its humongous start region.1358template <class T>1359inline HeapRegion* heap_region_containing(const T addr) const;13601361// A CollectedHeap is divided into a dense sequence of "blocks"; that is,1362// each address in the (reserved) heap is a member of exactly1363// one block. The defining characteristic of a block is that it is1364// possible to find its size, and thus to progress forward to the next1365// block. (Blocks may be of different sizes.) Thus, blocks may1366// represent Java objects, or they might be free blocks in a1367// free-list-based heap (or subheap), as long as the two kinds are1368// distinguishable and the size of each is determinable.13691370// Returns the address of the start of the "block" that contains the1371// address "addr". We say "blocks" instead of "object" since some heaps1372// may not pack objects densely; a chunk may either be an object or a1373// non-object.1374virtual HeapWord* block_start(const void* addr) const;13751376// Requires "addr" to be the start of a chunk, and returns its size.1377// "addr + size" is required to be the start of a new chunk, or the end1378// of the active area of the heap.1379virtual size_t block_size(const HeapWord* addr) const;13801381// Requires "addr" to be the start of a block, and returns "TRUE" iff1382// the block is an object.1383virtual bool block_is_obj(const HeapWord* addr) const;13841385// Does this heap support heap inspection? (+PrintClassHistogram)1386virtual bool supports_heap_inspection() const { return true; }13871388// Section on thread-local allocation buffers (TLABs)1389// See CollectedHeap for semantics.13901391bool supports_tlab_allocation() const;1392size_t tlab_capacity(Thread* ignored) const;1393size_t tlab_used(Thread* ignored) const;1394size_t max_tlab_size() const;1395size_t unsafe_max_tlab_alloc(Thread* ignored) const;13961397// Can a compiler initialize a new object without store barriers?1398// This permission only extends from the creation of a new object1399// via a TLAB up to the first subsequent safepoint. If such permission1400// is granted for this heap type, the compiler promises to call1401// defer_store_barrier() below on any slow path allocation of1402// a new object for which such initializing store barriers will1403// have been elided. G1, like CMS, allows this, but should be1404// ready to provide a compensating write barrier as necessary1405// if that storage came out of a non-young region. The efficiency1406// of this implementation depends crucially on being able to1407// answer very efficiently in constant time whether a piece of1408// storage in the heap comes from a young region or not.1409// See ReduceInitialCardMarks.1410virtual bool can_elide_tlab_store_barriers() const {1411return true;1412}14131414virtual bool card_mark_must_follow_store() const {1415return true;1416}14171418inline bool is_in_young(const oop obj);14191420#ifdef ASSERT1421virtual bool is_in_partial_collection(const void* p);1422#endif14231424virtual bool is_scavengable(const void* addr);14251426// We don't need barriers for initializing stores to objects1427// in the young gen: for the SATB pre-barrier, there is no1428// pre-value that needs to be remembered; for the remembered-set1429// update logging post-barrier, we don't maintain remembered set1430// information for young gen objects.1431virtual inline bool can_elide_initializing_store_barrier(oop new_obj);14321433// Returns "true" iff the given word_size is "very large".1434static bool isHumongous(size_t word_size) {1435// Note this has to be strictly greater-than as the TLABs1436// are capped at the humongous thresold and we want to1437// ensure that we don't try to allocate a TLAB as1438// humongous and that we don't allocate a humongous1439// object in a TLAB.1440return word_size > _humongous_object_threshold_in_words;1441}14421443// Update mod union table with the set of dirty cards.1444void updateModUnion();14451446// Set the mod union bits corresponding to the given memRegion. Note1447// that this is always a safe operation, since it doesn't clear any1448// bits.1449void markModUnionRange(MemRegion mr);14501451// Records the fact that a marking phase is no longer in progress.1452void set_marking_complete() {1453_mark_in_progress = false;1454}1455void set_marking_started() {1456_mark_in_progress = true;1457}1458bool mark_in_progress() {1459return _mark_in_progress;1460}14611462// Print the maximum heap capacity.1463virtual size_t max_capacity() const;14641465virtual jlong millis_since_last_gc();146614671468// Convenience function to be used in situations where the heap type can be1469// asserted to be this type.1470static G1CollectedHeap* heap();14711472void set_region_short_lived_locked(HeapRegion* hr);1473// add appropriate methods for any other surv rate groups14741475YoungList* young_list() const { return _young_list; }14761477// debugging1478bool check_young_list_well_formed() {1479return _young_list->check_list_well_formed();1480}14811482bool check_young_list_empty(bool check_heap,1483bool check_sample = true);14841485// *** Stuff related to concurrent marking. It's not clear to me that so1486// many of these need to be public.14871488// The functions below are helper functions that a subclass of1489// "CollectedHeap" can use in the implementation of its virtual1490// functions.1491// This performs a concurrent marking of the live objects in a1492// bitmap off to the side.1493void doConcurrentMark();14941495bool isMarkedPrev(oop obj) const;1496bool isMarkedNext(oop obj) const;14971498// Determine if an object is dead, given the object and also1499// the region to which the object belongs. An object is dead1500// iff a) it was not allocated since the last mark and b) it1501// is not marked.1502bool is_obj_dead(const oop obj, const HeapRegion* hr) const {1503return1504!hr->obj_allocated_since_prev_marking(obj) &&1505!isMarkedPrev(obj);1506}15071508// This function returns true when an object has been1509// around since the previous marking and hasn't yet1510// been marked during this marking.1511bool is_obj_ill(const oop obj, const HeapRegion* hr) const {1512return1513!hr->obj_allocated_since_next_marking(obj) &&1514!isMarkedNext(obj);1515}15161517// Determine if an object is dead, given only the object itself.1518// This will find the region to which the object belongs and1519// then call the region version of the same function.15201521// Added if it is NULL it isn't dead.15221523inline bool is_obj_dead(const oop obj) const;15241525inline bool is_obj_ill(const oop obj) const;15261527inline bool requires_marking(const void* entry) const;15281529bool allocated_since_marking(oop obj, HeapRegion* hr, VerifyOption vo);1530HeapWord* top_at_mark_start(HeapRegion* hr, VerifyOption vo);1531bool is_marked(oop obj, VerifyOption vo);1532const char* top_at_mark_start_str(VerifyOption vo);15331534ConcurrentMark* concurrent_mark() const { return _cm; }15351536// Refinement15371538ConcurrentG1Refine* concurrent_g1_refine() const { return _cg1r; }15391540// The dirty cards region list is used to record a subset of regions1541// whose cards need clearing. The list if populated during the1542// remembered set scanning and drained during the card table1543// cleanup. Although the methods are reentrant, population/draining1544// phases must not overlap. For synchronization purposes the last1545// element on the list points to itself.1546HeapRegion* _dirty_cards_region_list;1547void push_dirty_cards_region(HeapRegion* hr);1548HeapRegion* pop_dirty_cards_region();15491550// Optimized nmethod scanning support routines15511552// Register the given nmethod with the G1 heap1553virtual void register_nmethod(nmethod* nm);15541555// Unregister the given nmethod from the G1 heap1556virtual void unregister_nmethod(nmethod* nm);15571558// Free up superfluous code root memory.1559void purge_code_root_memory();15601561// Rebuild the stong code root lists for each region1562// after a full GC1563void rebuild_strong_code_roots();15641565// Delete entries for dead interned string and clean up unreferenced symbols1566// in symbol table, possibly in parallel.1567void unlink_string_and_symbol_table(BoolObjectClosure* is_alive, bool unlink_strings = true, bool unlink_symbols = true);15681569// Parallel phase of unloading/cleaning after G1 concurrent mark.1570void parallel_cleaning(BoolObjectClosure* is_alive, bool process_strings, bool process_symbols, bool class_unloading_occurred);15711572// Redirty logged cards in the refinement queue.1573void redirty_logged_cards();1574// Verification15751576// The following is just to alert the verification code1577// that a full collection has occurred and that the1578// remembered sets are no longer up to date.1579bool _full_collection;1580void set_full_collection() { _full_collection = true;}1581void clear_full_collection() {_full_collection = false;}1582bool full_collection() {return _full_collection;}15831584// Perform any cleanup actions necessary before allowing a verification.1585virtual void prepare_for_verify();15861587// Perform verification.15881589// vo == UsePrevMarking -> use "prev" marking information,1590// vo == UseNextMarking -> use "next" marking information1591// vo == UseMarkWord -> use the mark word in the object header1592//1593// NOTE: Only the "prev" marking information is guaranteed to be1594// consistent most of the time, so most calls to this should use1595// vo == UsePrevMarking.1596// Currently, there is only one case where this is called with1597// vo == UseNextMarking, which is to verify the "next" marking1598// information at the end of remark.1599// Currently there is only one place where this is called with1600// vo == UseMarkWord, which is to verify the marking during a1601// full GC.1602void verify(bool silent, VerifyOption vo);16031604// Override; it uses the "prev" marking information1605virtual void verify(bool silent);16061607// The methods below are here for convenience and dispatch the1608// appropriate method depending on value of the given VerifyOption1609// parameter. The values for that parameter, and their meanings,1610// are the same as those above.16111612bool is_obj_dead_cond(const oop obj,1613const HeapRegion* hr,1614const VerifyOption vo) const;16151616bool is_obj_dead_cond(const oop obj,1617const VerifyOption vo) const;16181619G1HeapSummary create_g1_heap_summary();16201621// Printing16221623virtual void print_on(outputStream* st) const;1624virtual void print_extended_on(outputStream* st) const;1625virtual void print_on_error(outputStream* st) const;16261627virtual void print_gc_threads_on(outputStream* st) const;1628virtual void gc_threads_do(ThreadClosure* tc) const;16291630// Override1631void print_tracing_info() const;16321633// The following two methods are helpful for debugging RSet issues.1634void print_cset_rsets() PRODUCT_RETURN;1635void print_all_rsets() PRODUCT_RETURN;16361637public:1638size_t pending_card_num();1639size_t cards_scanned();16401641protected:1642size_t _max_heap_capacity;1643};16441645#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP164616471648