/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "gc_implementation/g1/concurrentMark.hpp"
#include "gc_implementation/g1/evacuationInfo.hpp"
#include "gc_implementation/g1/g1AllocRegion.hpp"
#include "gc_implementation/g1/g1HRPrinter.hpp"
#include "gc_implementation/g1/g1MonitoringSupport.hpp"
#include "gc_implementation/g1/g1RemSet.hpp"
#include "gc_implementation/g1/g1YCTypes.hpp"
#include "gc_implementation/g1/heapRegionSeq.hpp"
#include "gc_implementation/g1/heapRegionSets.hpp"
#include "gc_implementation/shared/hSpaceCounters.hpp"
#include "gc_implementation/shared/parGCAllocBuffer.hpp"
#include "memory/barrierSet.hpp"
#include "memory/memRegion.hpp"
#include "memory/sharedHeap.hpp"
// A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
// It uses the "Garbage First" heap organization and algorithm, which
// may combine concurrent marking with parallel, incremental compaction of
// heap subsets that will yield large amounts of garbage.
class HeapRegion;
class HRRSCleanupTask;
class PermanentGenerationSpec;
class GenerationSpec;
class OopsInHeapRegionClosure;
class G1ScanHeapEvacClosure;
class ObjectClosure;
class SpaceClosure;
class CompactibleSpaceClosure;
class Space;
class G1CollectorPolicy;
class GenRemSet;
class G1RemSet;
class HeapRegionRemSetIterator;
class ConcurrentMark;
class ConcurrentMarkThread;
class ConcurrentG1Refine;
class ConcurrentGCTimer;
class GenerationCounters;
class STWGCTimer;
class G1NewTracer;
class G1OldTracer;
class EvacuationFailedInfo;
enum GCAllocPurpose {
};
private:
public:
void empty_list();
// Currently we do not keep track of the used byte sum for the
// young list and the survivors and it'd be quite a lot of work to
// do so. When we'll eventually replace the young list with
// instances of HeapRegionLinkedList we'll get that for free. So,
// we'll report the more accurate information then.
}
}
void rs_length_sampling_init();
bool rs_length_sampling_more();
void rs_length_sampling_next();
void reset_sampled_info() {
}
// for development purposes
void reset_auxilary_lists();
void clear_survivors() {
_survivor_length = 0;
}
// debugging
bool check_list_well_formed();
bool check_list_empty(bool check_sample = true);
void print();
};
protected:
public:
};
// The G1 STW is alive closure.
// An instance is embedded into the G1CH and used as the
// (optional) _is_alive_non_header closure in the STW
// reference processor. It is also extensively used during
// reference processing during STW evacuation pauses.
public:
bool do_object_b(oop p);
};
protected:
public:
};
protected:
public:
};
class RefineCardTableEntryClosure;
friend class VM_G1CollectForAllocation;
friend class VM_GenCollectForPermanentAllocation;
friend class VM_G1CollectFull;
friend class VM_G1IncCollectionPause;
friend class VMStructs;
friend class MutatorAllocRegion;
friend class SurvivorGCAllocRegion;
friend class OldGCAllocRegion;
// Closures used in implementation.
friend class G1ParCopyClosure;
friend class G1IsAliveClosure;
friend class G1EvacuateFollowersClosure;
friend class G1ParScanThreadState;
friend class G1ParScanClosureSuper;
friend class G1ParEvacuateFollowersClosure;
friend class G1ParTask;
friend class G1FreeGarbageRegionClosure;
friend class RefineCardTableEntryClosure;
friend class G1PrepareCompactClosure;
friend class RegionSorter;
friend class RegionResetter;
friend class CountRCClosure;
friend class EvacPopObjClosure;
friend class G1ParCleanupCTTask;
// Other related classes.
friend class G1MarkSweep;
private:
// The one and only G1CollectedHeap, so static functions can find it.
// Storage for the G1 heap (excludes the permanent generation).
// The part of _g1_storage that is currently committed.
// The master free list. It will satisfy all new region allocations.
// The secondary free list which contains regions that have been
// freed up during the cleanup process. This will be appended to the
// master free list when appropriate.
// It keeps track of the old regions.
// It keeps track of the humongous regions.
// The number of regions we could create by expansion.
// The block offset table for the G1 heap.
// Tears down the region sets / lists so that they are empty and the
// regions on the heap do not belong to a region set / list. The
// only exception is the humongous set which we leave unaltered. If
// free_list_only is true, it will only tear down the master free
// list. It is called before a Full GC (free_list_only == false) or
// before heap shrinking (free_list_only == true).
void tear_down_region_sets(bool free_list_only);
// Rebuilds the region sets / lists so that they are repopulated to
// reflect the contents of the heap. The only exception is the
// humongous set which was not torn down in the first place. If
// free_list_only is true, it will only rebuild the master free
// list. It is called after a Full GC (free_list_only == false) or
// after heap shrinking (free_list_only == true).
void rebuild_region_sets(bool free_list_only);
// The sequence of all heap regions in the heap.
// Alloc region used to satisfy mutator allocation requests.
// Alloc region used to satisfy allocation requests by the GC for
// survivor objects.
// PLAB sizing policy for survivors.
// Alloc region used to satisfy allocation requests by the GC for
// old objects.
// PLAB sizing policy for tenured objects.
switch (purpose) {
case GCAllocForSurvived:
break;
case GCAllocForTenured:
stats = &_old_plab_stats;
break;
default:
assert(false, "unrecognized GCAllocPurpose");
}
return stats;
}
// The last old region we allocated to during the last GC.
// Typically, it is not full so we should re-use it during the next GC.
// It specifies whether we should attempt to expand the heap after a
// region allocation failure. If heap expansion fails we set this to
// false so that we don't re-attempt the heap expansion (it's likely
// that subsequent expansion attempts will also fail if one fails).
// Currently, it is only consulted during GC and it's reset at the
// start of each GC.
// It resets the mutator alloc region before new allocations can take place.
void init_mutator_alloc_region();
// It releases the mutator alloc region.
void release_mutator_alloc_region();
// It initializes the GC alloc regions at the start of a GC.
// It releases the GC alloc regions at the end of a GC.
// It does any cleanup that needs to be done on the GC alloc regions
// before a Full GC.
void abandon_gc_alloc_regions();
// Helper for monitoring and management support.
// Determines PLAB size for a particular allocation purpose.
// Outside of GC pauses, the number of bytes used in all regions other
// than the current allocation region.
// This is used for a quick test on whether a reference points into
// the collection set or not. Basically, we have an array, with one
// byte per region, and that byte denotes whether the corresponding
// region is in the collection set or not. The entry corresponding
// the bottom of the heap, i.e., region 0, is pointed to by
// _in_cset_fast_test_base. The _in_cset_fast_test field has been
// biased so that it actually points to address 0 of the address
// space, to make the test as fast as possible (we can simply shift
// the address to address into it, instead of having to subtract the
// bottom of the heap from the address before shifting it; basically
// it works in the same way the card table works).
bool* _in_cset_fast_test;
// The allocated array used for the fast test on whether a reference
// points into the collection set or not. This field is also used to
// free the array.
bool* _in_cset_fast_test_base;
// The length of the _in_cset_fast_test_base array.
volatile unsigned _gc_time_stamp;
void setup_surviving_young_words();
void cleanup_surviving_young_words();
// It decides whether an explicit GC should start a concurrent cycle
// instead of doing a STW GC. Currently, a concurrent cycle is
// explicitly started if:
// (a) cause == _gc_locker and +GCLockerInvokesConcurrent, or
// (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent.
// (c) cause == _g1_humongous_allocation
// Keeps track of how many "old marking cycles" (i.e., Full GCs or
// concurrent cycles) we have started.
volatile unsigned int _old_marking_cycles_started;
// Keeps track of how many "old marking cycles" (i.e., Full GCs or
// concurrent cycles) we have completed.
volatile unsigned int _old_marking_cycles_completed;
// This is a non-product method that is helpful for testing. It is
// called at the end of a GC and artificially expands the heap by
// allocating a number of dead regions. This way we can induce very
// frequent marking cycles and stress the cleanup / concurrent
// cleanup code more (as all the regions that will be allocated by
// this method will be found dead by the marking cycle).
// Clear RSets after a compaction. It also resets the GC time stamps.
void clear_rsets_post_compaction();
// If the HR printer is active, dump the state of the regions in the
// heap after a compaction.
void print_hrs_post_compaction();
void verify_before_gc();
void verify_after_gc();
void log_gc_header();
void log_gc_footer(double pause_time_sec);
// These are macros so that, if the assert fires, we get the correct
// line number, file, etc.
err_msg("%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \
(_extra_message_), \
#define assert_heap_locked() \
do { \
heap_locking_asserts_err_msg("should be holding the Heap_lock")); \
} while (0)
do { \
(SafepointSynchronize::is_at_safepoint() && \
heap_locking_asserts_err_msg("should be holding the Heap_lock or " \
"should be at a safepoint")); \
} while (0)
#define assert_heap_locked_and_not_at_safepoint() \
do { \
heap_locking_asserts_err_msg("should be holding the Heap_lock and " \
"should not be at a safepoint")); \
} while (0)
#define assert_heap_not_locked() \
do { \
heap_locking_asserts_err_msg("should not be holding the Heap_lock")); \
} while (0)
#define assert_heap_not_locked_and_not_at_safepoint() \
do { \
heap_locking_asserts_err_msg("should not be holding the Heap_lock and " \
"should not be at a safepoint")); \
} while (0)
do { \
heap_locking_asserts_err_msg("should be at a safepoint")); \
} while (0)
#define assert_not_at_safepoint() \
do { \
heap_locking_asserts_err_msg("should not be at a safepoint")); \
} while (0)
protected:
// The young region list.
// The current policy object for the collector.
// This is the second level of trying to allocate a new region. If
// new_region() didn't find a region on the free_list, this call will
// check whether there's anything available on the
// that list, if _free_regions_coming is set.
// Try to allocate a single non-humongous HeapRegion sufficient for
// an allocation of the given word_size. If do_expand is true,
// attempt to expand the heap if necessary to satisfy the allocation
// request.
// Attempt to satisfy a humongous allocation request of the given
// size by finding a contiguous set of free regions of num_regions
// length and remove them from the master free list. Return the
// index of the first region or G1_NULL_HRS_INDEX if the search
// was unsuccessful.
// Initialize a contiguous set of free regions of length num_regions
// and starting at index first so that they appear as a single
// humongous region.
// Attempt to allocate a humongous object of the given size. Return
// NULL if unsuccessful.
// The following two methods, allocate_new_tlab() and
// mem_allocate(), are the two main entry points from the runtime
// into the G1's allocation routines. They have the following
// assumptions:
//
// * They should both be called outside safepoints.
//
// * They should both be called without holding the Heap_lock.
//
// * All allocation requests for new TLABs should go to
// allocate_new_tlab().
//
// * All non-TLAB allocation requests should go to mem_allocate().
//
// * If either call cannot satisfy the allocation request using the
// current allocating region, they will try to get a new one. If
// this fails, they will attempt to do an evacuation pause and
// retry the allocation.
//
// * If all allocation attempts fail, even after trying to schedule
// an evacuation pause, allocate_new_tlab() will return NULL,
// schedule a Full GC.
//
// * We do not allow humongous-sized TLABs. So, allocate_new_tlab
// should never be called with word_size being humongous. All
// humongous allocation requests should go to mem_allocate() which
// will satisfy them with a special path.
bool* gc_overhead_limit_was_exceeded);
// The following three methods take a gc_count_before_ret
// parameter which is used to return the GC count if the method
// returns NULL. Given that we are required to read the GC count
// while holding the Heap_lock, and these paths will take the
// Heap_lock at some point, it's easier to get them to read the GC
// count while holding the Heap_lock before they return NULL instead
// of the caller (namely: mem_allocate()) having to also take the
// Heap_lock just to read the GC count.
// First-level mutator allocation attempt: try to allocate out of
// the mutator alloc region without taking the Heap_lock. This
// should only be used for non-humongous allocations.
unsigned int* gc_count_before_ret);
// Second-level mutator allocation attempt: take the Heap_lock and
// retry the allocation attempt, potentially scheduling a GC
// pause. This should only be used for non-humongous allocations.
unsigned int* gc_count_before_ret);
// Takes the Heap_lock and attempts a humongous allocation. It can
// potentially schedule a GC pause.
unsigned int* gc_count_before_ret);
// Allocation attempt that should be called during safepoints (e.g.,
// at the end of a successful GC). expect_null_mutator_alloc_region
// specifies whether the mutator alloc region is expected to be NULL
// or not.
// It dirties the cards that cover the block so that so that the post
// write barrier never queues anything when updating objects on this
// block. It is assumed (and in fact we assert) that the block
// belongs to a young region.
// Allocate blocks during garbage collection. Will ensure an
// allocation region, either by picking one or expanding the
// heap, and then allocate a block of the given size. The block
// may not be a humongous - it must fit into a single heap region.
bool par,
// Ensure that no further allocations can happen in "r", bearing in mind
// that parallel threads might be attempting allocations.
void par_allocate_remaining_space(HeapRegion* r);
// Allocation attempt during GC for a survivor object / PLAB.
// Allocation attempt during GC for an old object / PLAB.
// These methods are the "callbacks" from the G1AllocRegion class.
// For mutator alloc regions.
// For GC alloc regions.
// - if explicit_gc is true, the GC is for a System.gc() or a heap
// inspection request and should collect the entire heap
// - if clear_all_soft_refs is true, all soft references should be
// cleared during the GC
// - if explicit_gc is false, word_size describes the allocation that
// the GC should attempt (at least) to satisfy
// - it returns false if it is unable to do the collection due to the
// GC locker being active, true otherwise
bool do_collection(bool explicit_gc,
bool clear_all_soft_refs,
// Callback from VM_G1CollectFull operation.
// Perform a full collection.
void do_full_collection(bool clear_all_soft_refs);
// Resize the heap if necessary after a full collection. If this is
// after a collect-for allocation, "word_size" is the allocation size,
// and will be considered part of the used portion of the heap.
// Callback from VM_G1CollectForAllocation operation.
// failed allocation request (including collection, expansion, etc.)
// Attempting to expand the heap sufficiently
// to support an allocation of the given "word_size". If
// successful, perform the allocation and return the address of the
// allocated block, or else "NULL".
// Process any reference objects discovered during
// an incremental evacuation pause.
// Enqueue any remaining discovered references
// after processing.
public:
return _g1mm;
}
// Expand the garbage-first heap by at least the given size (in bytes!).
// Returns true if the heap was expanded by the requested amount;
// false otherwise.
// (Rounds up to a HeapRegion boundary.)
// Do anything common to GC's.
virtual void gc_prologue(bool full);
virtual void gc_epilogue(bool full);
// We register a region with the fast "in collection set" test. We
// simply set to true the array slot corresponding to this region.
_in_cset_fast_test_base[index] = true;
}
// This is a fast test on whether a reference points into the
// collection set or not. It does not assume that the reference
// points into the heap; if it doesn't, it will return false.
// no need to subtract the bottom of the heap from obj,
// _in_cset_fast_test is biased
// let's make sure the result is consistent with what the slower
// test returns
return ret;
} else {
return false;
}
}
void clear_cset_fast_test() {
memset(_in_cset_fast_test_base, false,
(size_t) _in_cset_fast_test_length * sizeof(bool));
}
// This is called at the start of either a concurrent cycle or a Full
// GC to update the number of old marking cycles started.
// This is called at the end of either a concurrent cycle or a Full
// GC to update the number of old marking cycles completed. Those two
// can happen in a nested fashion, i.e., we start a concurrent
// cycle, a Full GC happens half-way through it which ends first,
// and then the cycle notices that a Full GC happened and ends
// too. The concurrent parameter is a boolean to help us do a bit
// tighter consistency checking in the method. If concurrent is
// false, the caller is the inner caller in the nesting (i.e., the
// Full GC). If concurrent is true, the caller is the outer caller
// in this nesting (i.e., the concurrent cycle). Further nesting is
// not currently supported. The end of this call also notifies
// the FullGCCount_lock in case a Java thread is waiting for a full
// GC to happen (e.g., it called System.gc() with
// +ExplicitGCInvokesConcurrent).
void increment_old_marking_cycles_completed(bool concurrent);
unsigned int old_marking_cycles_completed() {
return _old_marking_cycles_completed;
}
void register_concurrent_cycle_end();
protected:
// Shrink the garbage-first heap by at most the given size (in bytes!).
// (Rounds down to a HeapRegion boundary.)
#if TASKQUEUE_STATS
void reset_taskqueue_stats();
#endif // TASKQUEUE_STATS
// Schedule the VM operation that will do an evacuation pause to
// satisfy an allocation request of word_size. *succeeded will
// return whether the VM operation was successful (it did do an
// evacuation pause) or not (another thread beat us to it or the GC
// locker was active). Given that we should not be holding the
// Heap_lock when we enter this method, we will pass the
// gc_count_before (i.e., total_collections()) as a parameter since
// it has to be read while holding the Heap_lock. Currently, both
// methods that call do_collection_pause() release the Heap_lock
// before the call, so it's easy to read gc_count_before just before.
unsigned int gc_count_before,
bool* succeeded);
// The guts of the incremental collection pause, executed by the vm
// thread. It returns false if it is unable to do the collection due
// to the GC locker being active, true otherwise
bool do_collection_pause_at_safepoint(double target_pause_time_ms);
// Actually do the work of evacuating the collection set.
// The g1 remembered set of the heap.
// And it's mod ref barrier set, used to track updates for the above.
// A set of cards that cover the objects for which the Rsets should be updated
// concurrently after the collection.
// The Heap Region Rem Set Iterator.
// The closure used to refine a single card.
// A function to check the consistency of dirty card logs.
void check_ct_logs_at_safepoint();
// A DirtyCardQueueSet that is used to hold cards that contain
// references into the current collection set. This is used to
// update the remembered sets of the regions in the collection
// set in the event of an evacuation failure.
// After a collection pause, make the regions in the CS into free
// regions.
// Abandon the current collection set without recording policy
// statistics or updating free lists.
// Applies "scan_non_heap_roots" to roots outside the heap,
// "scan_rs" to roots inside the heap (having done "set_region" to
// indicate the region in which the root resides), and does "scan_perm"
// (setting the generation to the perm generation.) If "scan_rs" is
// NULL, then this step is skipped. The "worker_i"
// param is for use with parallel roots processing, and should be
// the "i" of the calling parallel worker thread's work(i) function.
// In the sequential case this param will be ignored.
void g1_process_strong_roots(bool collecting_perm_gen,
int worker_i);
// Apply "blk" to all the weak roots of the system. These include
// JNI weak roots, the code cache, system dictionary, symbol table,
// string table, and referents of reachable weak refs.
// Frees a non-humongous region by initializing its contents and
// adding it to the free list that's passed as a parameter (this is
// usually a local list which will be appended to the master free
// list later). The used bytes of freed regions are accumulated in
// pre_used. If par is true, the region's RSet will not be freed
// up. The assumption is that this will be done later.
bool par);
// Frees a humongous region by collapsing it into individual regions
// and calling free_region() for each of them. The freed regions
// will be added to the free list that's passed as a parameter (this
// is usually a local list which will be appended to the master free
// list later). The used bytes of freed regions are accumulated in
// pre_used. If par is true, the region's RSet will not be freed
// up. The assumption is that this will be done later.
bool par);
// Notifies all the necessary spaces that the committed space has
// been updated (either expanded or shrunk). It should be called
// after _g1_storage is updated.
// The concurrent marker (and the thread it runs in.)
bool _mark_in_progress;
// The concurrent refiner.
// The parallel task queues
// True iff a evacuation has failed in the current collection.
bool _evacuation_failed;
// Failed evacuations cause some logical from-space objects to have
// forwarding pointers to themselves. Reset them.
void remove_self_forwarding_pointers();
// Together, these store an object with a preserved mark, and its mark value.
// Preserve the mark of "obj", if necessary, in preparation for its mark
// word being overwritten with a self-forwarding-pointer.
// The stack of evac-failure objects left to be scanned.
// The closure to apply to evac-failure objects.
// Set the field above.
void
}
// Push "obj" on the scan stack.
// Process scan stack entries until the stack is empty.
void drain_evac_failure_scan_stack();
// True iff an invocation of "drain_scan_stack" is in progress; to
// prevent unnecessary recursion.
bool _drain_in_progress;
// Do any necessary initialization for evacuation-failure handling.
// "cl" is the closure that will be used to process evac-failure
// objects.
// Do any necessary cleanup for evacuation-failure handling data
// structures.
void finalize_for_evac_failure();
// An attempt to evacuate "obj" has failed; take necessary steps.
#ifndef PRODUCT
// Support for forcing evacuation failures. Analogous to
// PromotionFailureALot for the other collectors.
// Records whether G1EvacuationFailureALot should be in effect
// for the current GC
// Used to record the GC number for interval checking when
// determining whether G1EvaucationFailureALot is in effect
// for the current GC.
// Count of the number of evacuations between failures.
volatile size_t _evacuation_failure_alot_count;
// Set whether G1EvacuationFailureALot should be in effect
// for the current GC (based upon the type of GC and which
// command line flags are set);
inline bool evacuation_failure_alot_for_gc_type(bool gcs_are_young,
bool during_initial_mark,
bool during_marking);
inline void set_evacuation_failure_alot_for_current_gc();
// Return true if it's time to cause an evacuation failure.
inline bool evacuation_should_fail();
// Reset the G1EvacuationFailureALot counters. Should be called at
// the end of an evacuation pause in which an evacuation failure occurred.
inline void reset_evacuation_should_fail();
#endif // !PRODUCT
// ("Weak") Reference processing support.
//
// G1 has 2 instances of the reference processor class. One
// (_ref_processor_cm) handles reference object discovery
// and subsequent processing during concurrent marking cycles.
//
// The other (_ref_processor_stw) handles reference object
// discovery and processing during full GCs and incremental
// evacuation pauses.
//
// During an incremental pause, reference discovery will be
// temporarily disabled for _ref_processor_cm and will be
// enabled for _ref_processor_stw. At the end of the evacuation
// pause references discovered by _ref_processor_stw will be
// processed and discovery will be disabled. The previous
// setting for reference object discovery for _ref_processor_cm
// will be re-instated.
//
// At the start of marking:
// * Discovery by the CM ref processor is verified to be inactive
// and it's discovered lists are empty.
// * Discovery by the CM ref processor is then enabled.
//
// At the end of marking:
// * Any references on the CM ref processor's discovered
// lists are processed (possibly MT).
//
// At the start of full GC we:
// * Disable discovery by the CM ref processor and
// empty CM ref processor's discovered lists
// (without processing any entries).
// * Verify that the STW ref processor is inactive and it's
// discovered lists are empty.
// * Temporarily set STW ref processor discovery as single threaded.
// * Temporarily clear the STW ref processor's _is_alive_non_header
// field.
// * Finally enable discovery by the STW ref processor.
//
// The STW ref processor is used to record any discovered
// references during the full GC.
//
// At the end of a full GC we:
// * Enqueue any reference objects discovered by the STW ref processor
// that have non-live referents. This has the side-effect of
// making the STW ref processor inactive by disabling discovery.
// * Verify that the CM ref processor is still inactive
// and no references have been placed on it's discovered
// lists (also checked as a precondition during initial marking).
// The (stw) reference processor...
// During reference object discovery, the _is_alive_non_header
// closure (if non-null) is applied to the referent object to
// determine whether the referent is live. If so then the
// reference object does not need to be 'discovered' and can
// be treated as a regular oop. This has the benefit of reducing
// the number of 'discovered' reference objects that need to
// be processed.
//
// Instance of the is_alive closure for embedding into the
// STW reference processor as the _is_alive_non_header field.
// Supplying a value for the _is_alive_non_header field is
// optional but doing so prevents unnecessary additions to
// the discovered lists during reference discovery.
// The (concurrent marking) reference processor...
// Instance of the concurrent mark is_alive closure for embedding
// into the Concurrent Marking reference processor as the
// _is_alive_non_header field. Supplying a value for the
// _is_alive_non_header field is optional but doing so prevents
// unnecessary additions to the discovered lists during reference
// discovery.
// Cache used by G1CollectedHeap::start_cset_region_for_worker().
// Time stamp to validate the regions recorded in the cache
// used by G1CollectedHeap::start_cset_region_for_worker().
// The heap region entry for a given worker is valid iff
// the associated time stamp value matches the current value
// of G1CollectedHeap::_gc_time_stamp.
unsigned int* _worker_cset_start_region_time_stamp;
// Leave this one last.
};
volatile bool _free_regions_coming;
public:
void set_refine_cte_cl_concurrency(bool concurrent);
RefToScanQueue *task_queue(int i) const;
// A set of cards where updates happened during the GC
// A DirtyCardQueueSet that is used to hold cards that contain
// references into the current collection set. This is used to
// update the remembered sets of the regions in the collection
// set in the event of an evacuation failure.
{ return _into_cset_dirty_card_queue_set; }
// Create a G1CollectedHeap with the specified policy.
// Must call the initialize method afterwards.
// May not return if something goes wrong.
// Initialize the G1CollectedHeap to have the initial and
// maximum sizes, permanent generation, and remembered and barrier sets
// specified by the policy object.
jint initialize();
// Initialize weak reference processing.
virtual void ref_processing_init();
void set_par_threads(uint t) {
// Done in SharedHeap but oddly there are
// two _process_strong_tasks's in a G1CollectedHeap
// so do it here too.
}
// Set _n_par_threads according to a policy TBD.
void set_par_threads();
void set_n_termination(int t) {
}
return CollectedHeap::G1CollectedHeap;
}
// The current policy object for the collector.
// Adaptive size policy. No such thing for g1.
// The rem set and barrier set.
// The rem set iterator.
HeapRegionRemSetIterator* rem_set_iterator(int i) {
return _rem_set_iterator[i];
}
return _rem_set_iterator[0];
}
unsigned get_gc_time_stamp() {
return _gc_time_stamp;
}
void reset_gc_time_stamp() {
_gc_time_stamp = 0;
OrderAccess::fence();
// Clear the cached CSet starting regions and time stamps.
// Their validity is dependent on the GC timestamp.
}
void check_gc_time_stamps() PRODUCT_RETURN;
void increment_gc_time_stamp() {
OrderAccess::fence();
}
// Reset the given region's GC timestamp. If it's starts humongous,
// also reset the GC timestamp of its corresponding
// continues humongous regions too.
bool concurrent, int worker_i);
// The shared block offset table array.
// Reference Processing accessors
// The STW reference processor....
// The Concurrent Marking reference processor...
// This should be called when we're not holding the heap lock. The
// result might be a bit inaccurate.
size_t used_unlocked() const;
size_t recalculate_used() const;
// These virtual functions do the actual allocation.
// Some heaps may offer a contiguous region for shared non-blocking
// allocation, via inlined code (by exporting the address of the top and
// end fields defining the extent of the contiguous allocation region.)
// But G1CollectedHeap doesn't yet support this.
// Return an estimate of the maximum allocation that could be performed
// without triggering any collection or expansion activity. In a
// generational collector, for example, this is probably the largest
// allocation that could be supported (without expansion) in the youngest
// generation. It is "unsafe" because no locks are taken; the result
// should be treated as an approximation, not a guarantee, for use in
// heuristic resizing decisions.
virtual size_t unsafe_max_alloc();
virtual bool is_maximal_no_gc() const {
return _g1_storage.uncommitted_size() == 0;
}
// The total number of regions in the heap.
// The max number of regions in the heap.
// The number of regions that are completely free.
// The number of regions that are not completely free.
// The number of regions available for "regular" expansion.
// Factory method for HeapRegion instances. It will return NULL if
// the allocation fails.
// verify_region_sets() performs verification over the region
// lists. It will be compiled in the product code to be used when
// necessary (i.e., during heap verification).
void verify_region_sets();
// verify_region_sets_optional() is planted in the code for
// list verification in non-product builds (and it can be enabled in
// product builds by defining HEAP_REGION_SET_FORCE_VERIFY to be 1).
void verify_region_sets_optional() {
}
#else // HEAP_REGION_SET_FORCE_VERIFY
void verify_region_sets_optional() { }
#endif // HEAP_REGION_SET_FORCE_VERIFY
#ifdef ASSERT
}
}
#endif // ASSERT
// Wrapper for the region list operations that can be called from
// methods outside this class.
}
void append_secondary_free_list() {
}
// If the secondary free list looks empty there's no reason to
// take the lock and then try to append it.
if (!_secondary_free_list.is_empty()) {
}
}
}
}
void set_free_regions_coming();
void reset_free_regions_coming();
bool free_regions_coming() { return _free_regions_coming; }
void wait_while_free_regions_coming();
// Determine whether the given region is one that we are using as an
// old GC alloc region.
return hr == _retained_old_gc_alloc_region;
}
// Perform a collection of the heap; intended for use in implementing
// "System.gc". This probably implies as full a collection as the
// "CollectedHeap" supports.
// The same as above but assume that the caller holds the Heap_lock.
// This interface assumes that it's being called by the
// vm thread. It collects the heap assuming that the
// heap lock is already held and that we are executing in
// the context of the vm thread.
// True iff an evacuation has failed in the most-recent collection.
bool evacuation_failed() { return _evacuation_failed; }
// It will free a region if it has allocated objects in it that are
// all dead. It calls either free_region() or
// free_humongous_region() depending on the type of the region that
// is passed to it.
bool par);
// It appends the free list to the master free list and updates the
// master humongous list according to the contents of the proxy
// list. It also adjusts the total used bytes according to pre_used
// (if par is true, it will do so by taking the ParGCRareEvent_lock).
bool par);
// Returns "TRUE" iff "p" points into the committed areas of the heap.
virtual bool is_in(const void* p) const;
// Return "TRUE" iff the given object address is within the collection
// set.
// Return "TRUE" iff the given object address is in the reserved
// region of g1 (excluding the permanent generation).
bool is_in_g1_reserved(const void* p) const {
return _g1_reserved.contains(p);
}
// Returns a MemRegion that corresponds to the space that has been
// reserved for the heap
MemRegion g1_reserved() {
return _g1_reserved;
}
// Returns a MemRegion that corresponds to the space that has been
// committed in the heap
return _g1_committed;
}
virtual bool is_in_closed_subset(const void* p) const;
// This resets the card table to all zeros. It is used after
// a collection pause which used the card table to claim cards.
void cleanUpCardTable();
// Iteration functions.
// Iterate over all the ref-containing fields of all objects, calling
// "cl.do_oop" on each.
oop_iterate(cl, true);
}
// Same as above, restricted to a memory region.
}
// Iterate over all objects, calling "cl.do_object" on each.
object_iterate(cl, true);
}
object_iterate(cl, true);
}
// Iterate over all objects allocated since the last collection, calling
// "cl.do_object" on each. The heap must have been initialized properly
// to support this function, or else this call will fail.
// Iterate over all spaces in use in the heap, in ascending address order.
// Iterate over heap regions, in address order, terminating the
// iteration early if the "doHeapRegion" method returns "true".
// Return the region with the given index. It assumes the index is valid.
// Divide the heap region sequence into "chunks" of some size (the number
// of regions divided by the number of parallel threads times some
// overpartition factor, currently 4). Assumes that this will be called
// in parallel by ParallelGCThreads worker threads with discinct worker
// ids in the range [0..max(ParallelGCThreads-1, 1)], that all parallel
// calls will use the same "claim_value", and that that claim value is
// different from the claim_value of any heap region before the start of
// the iteration. Applies "blk->doHeapRegion" to each of the regions, by
// attempting to claim the first region in each chunk, and, if
// successful, applying the closure to each region in the chunk (and
// setting the claim value of the second and subsequent regions of the
// chunk.) For now requires that "doHeapRegion" always returns "false",
// i.e., that a closure never attempt to abort a traversal.
// It resets all the region claim values to the default.
void reset_heap_region_claim_values();
// Resets the claim values of regions in the current
// collection set to the default.
#ifdef ASSERT
// Same as the routine above but only checks regions in the
// current collection set.
#endif // ASSERT
// Clear the cached cset start regions and (more importantly)
// the time stamps. Called when we reset the GC time stamp.
void clear_cset_start_regions();
// Given the id of a worker, obtain or calculate a suitable
// starting region for iterating over the current collection set.
// This is a convenience method that is used by the
// HeapRegionIterator classes to calculate the starting region for
// each worker so that they do not all start from the same region.
// Iterate over the regions (if any) in the current collection set.
// As above but starting from region r
// Returns the first (lowest address) compactible space in the heap.
virtual CompactibleSpace* first_compactible_space();
// A CollectedHeap will contain some number of spaces. This finds the
// space containing a given address, or else returns NULL.
// A G1CollectedHeap will contain some number of heap regions. This
// finds the region containing a given address, or else returns NULL.
template <class T>
// Like the above, but requires "addr" to be in the heap (to avoid a
// null-check), and unlike the above, may return an continuing humongous
// region.
template <class T>
// A CollectedHeap is divided into a dense sequence of "blocks"; that is,
// each address in the (reserved) heap is a member of exactly
// one block. The defining characteristic of a block is that it is
// possible to find its size, and thus to progress forward to the next
// block. (Blocks may be of different sizes.) Thus, blocks may
// represent Java objects, or they might be free blocks in a
// free-list-based heap (or subheap), as long as the two kinds are
// distinguishable and the size of each is determinable.
// Returns the address of the start of the "block" that contains the
// address "addr". We say "blocks" instead of "object" since some heaps
// may not pack objects densely; a chunk may either be an object or a
// non-object.
// Requires "addr" to be the start of a chunk, and returns its size.
// "addr + size" is required to be the start of a new chunk, or the end
// of the active area of the heap.
// Requires "addr" to be the start of a block, and returns "TRUE" iff
// the block is an object.
// Does this heap support heap inspection? (+PrintClassHistogram)
virtual bool supports_heap_inspection() const { return true; }
// Section on thread-local allocation buffers (TLABs)
// See CollectedHeap for semantics.
virtual bool supports_tlab_allocation() const;
// Can a compiler initialize a new object without store barriers?
// This permission only extends from the creation of a new object
// via a TLAB up to the first subsequent safepoint. If such permission
// is granted for this heap type, the compiler promises to call
// defer_store_barrier() below on any slow path allocation of
// a new object for which such initializing store barriers will
// have been elided. G1, like CMS, allows this, but should be
// ready to provide a compensating write barrier as necessary
// if that storage came out of a non-young region. The efficiency
// of this implementation depends crucially on being able to
// answer very efficiently in constant time whether a piece of
// storage in the heap comes from a young region or not.
// See ReduceInitialCardMarks.
virtual bool can_elide_tlab_store_barriers() const {
return true;
}
virtual bool card_mark_must_follow_store() const {
return true;
}
}
#ifdef ASSERT
virtual bool is_in_partial_collection(const void* p);
#endif
virtual bool is_scavengable(const void* addr);
// We don't need barriers for initializing stores to objects
// in the young gen: for the SATB pre-barrier, there is no
// pre-value that needs to be remembered; for the remembered-set
// update logging post-barrier, we don't maintain remembered set
// information for young gen objects.
return is_in_young(new_obj);
}
// Can a compiler elide a store barrier when it writes
// a permanent oop into the heap? Applies when the compiler
// is storing x to the heap, where x->is_perm() is true.
virtual bool can_elide_permanent_oop_store_barriers() const {
// At least until perm gen collection is also G1-ified, at
// which point this should return false.
return true;
}
// Returns "true" iff the given word_size is "very large".
// Note this has to be strictly greater-than as the TLABs
// are capped at the humongous thresold and we want to
// ensure that we don't try to allocate a TLAB as
// humongous and that we don't allocate a humongous
// object in a TLAB.
}
// Update mod union table with the set of dirty cards.
void updateModUnion();
// Set the mod union bits corresponding to the given memRegion. Note
// that this is always a safe operation, since it doesn't clear any
// bits.
// Records the fact that a marking phase is no longer in progress.
void set_marking_complete() {
_mark_in_progress = false;
}
void set_marking_started() {
_mark_in_progress = true;
}
bool mark_in_progress() {
return _mark_in_progress;
}
// Print the maximum heap capacity.
virtual size_t max_capacity() const;
virtual jlong millis_since_last_gc();
// Perform any cleanup actions necessary before allowing a verification.
virtual void prepare_for_verify();
// Perform verification.
// vo == UsePrevMarking -> use "prev" marking information,
// vo == UseNextMarking -> use "next" marking information
// vo == UseMarkWord -> use the mark word in the object header
//
// NOTE: Only the "prev" marking information is guaranteed to be
// consistent most of the time, so most calls to this should use
// vo == UsePrevMarking.
// Currently, there is only one case where this is called with
// vo == UseNextMarking, which is to verify the "next" marking
// information at the end of remark.
// Currently there is only one place where this is called with
// vo == UseMarkWord, which is to verify the marking during a
// full GC.
// Override; it uses the "prev" marking information
// Override
void print_tracing_info() const;
// The following two methods are helpful for debugging RSet issues.
void print_cset_rsets() PRODUCT_RETURN;
void print_all_rsets() PRODUCT_RETURN;
// Convenience function to be used in situations where the heap type can be
// asserted to be this type.
static G1CollectedHeap* heap();
// add appropriate methods for any other surv rate groups
// debugging
bool check_young_list_well_formed() {
return _young_list->check_list_well_formed();
}
bool check_young_list_empty(bool check_heap,
bool check_sample = true);
// *** Stuff related to concurrent marking. It's not clear to me that so
// many of these need to be public.
// The functions below are helper functions that a subclass of
// "CollectedHeap" can use in the implementation of its virtual
// functions.
// This performs a concurrent marking of the live objects in a
// bitmap off to the side.
void doConcurrentMark();
// Determine if an object is dead, given the object and also
// the region to which the object belongs. An object is dead
// iff a) it was not allocated since the last mark and b) it
// is not marked.
return
!isMarkedPrev(obj);
}
// This function returns true when an object has been
// around since the previous marking and hasn't yet
// been marked during this marking.
return
!isMarkedNext(obj);
}
// Determine if an object is dead, given only the object itself.
// This will find the region to which the object belongs and
// then call the region version of the same function.
// Added if it is in permanent gen it isn't dead.
// Added if it is NULL it isn't dead.
return false;
else return true;
}
}
return false;
else return true;
}
}
// The methods below are here for convenience and dispatch the
// appropriate method depending on value of the given VerifyOption
// parameter. The options for that parameter are:
//
// vo == UsePrevMarking -> use "prev" marking information,
// vo == UseNextMarking -> use "next" marking information,
// vo == UseMarkWord -> use mark word from object header
const HeapRegion* hr,
const VerifyOption vo) const {
switch (vo) {
default: ShouldNotReachHere();
}
return false; // keep some compilers happy
}
const VerifyOption vo) const {
switch (vo) {
default: ShouldNotReachHere();
}
return false; // keep some compilers happy
}
// The following is just to alert the verification code
// that a full collection has occurred and that the
// remembered sets are no longer up to date.
bool _full_collection;
void set_full_collection() { _full_collection = true;}
void clear_full_collection() {_full_collection = false;}
bool full_collection() {return _full_collection;}
// The dirty cards region list is used to record a subset of regions
// whose cards need clearing. The list if populated during the
// remembered set scanning and drained during the card table
// cleanup. Although the methods are reentrant, population/draining
// phases must not overlap. For synchronization purposes the last
// element on the list points to itself.
public:
void stop_conc_gc_threads();
protected:
};
class G1ParGCAllocBuffer: public ParGCAllocBuffer {
private:
bool _retired;
public:
_retired = false;
}
if (_retired)
return;
_retired = true;
}
};
class G1ParScanThreadState : public StackObj {
protected:
int _hash_seed;
double _start;
double _start_strong_roots;
double _strong_roots_time;
double _start_term;
double _term_time;
// Map from young-age-index (0 == not young, 1 is youngest) to
// surviving words. base is what we get back from the malloc call
// this points into the array, as we use the first few entries for padding
if (!from->is_survivor()) {
}
}
// If the new value of the field points to the same region or
// is the to-space, we don't need to include it in the Rset updates.
// If the card hasn't been added to the buffer, do it.
}
}
}
public:
~G1ParScanThreadState() {
}
return _alloc_buffers[purpose];
}
#ifdef ASSERT
#endif // ASSERT
template <class T> void push_on_queue(T* ref) {
}
if (G1DeferredRSUpdate) {
} else {
}
}
// Otherwise.
} else {
}
return obj;
}
}
"should contain whole object");
} else {
}
}
}
return _evac_failure_cl;
}
}
}
int* hash_seed() { return &_hash_seed; }
void note_term_attempt() { _term_attempts++; }
void start_strong_roots() {
}
void end_strong_roots() {
}
double strong_roots_time() const { return _strong_roots_time; }
void start_term_time() {
}
void end_term_time() {
}
double term_time() const { return _term_time; }
double elapsed_time() const {
}
static void
void
// We add on to hide entry 0 which accumulates surviving words for
// age -1 regions (i.e. non-young ones)
return _surviving_young_words;
}
void retire_alloc_buffers() {
true /* end_of_gc */,
false /* retain */);
}
}
template <class T> void deal_with_reference(T* ref_to_scan) {
if (has_partial_array_mask(ref_to_scan)) {
} else {
// Note: we can use "raw" versions of "region_containing" because
// "obj_to_scan" is definitely in the heap, and is not in a
// humongous region.
_evac_cl->set_region(r);
}
}
} else {
}
}
void trim_queue();
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP