342N/A/*
3063N/A * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP
1879N/A
1879N/A#include "gc_implementation/g1/concurrentMark.hpp"
4362N/A#include "gc_implementation/g1/evacuationInfo.hpp"
2280N/A#include "gc_implementation/g1/g1AllocRegion.hpp"
2603N/A#include "gc_implementation/g1/g1HRPrinter.hpp"
4141N/A#include "gc_implementation/g1/g1MonitoringSupport.hpp"
1879N/A#include "gc_implementation/g1/g1RemSet.hpp"
4141N/A#include "gc_implementation/g1/g1YCTypes.hpp"
2591N/A#include "gc_implementation/g1/heapRegionSeq.hpp"
2037N/A#include "gc_implementation/g1/heapRegionSets.hpp"
2386N/A#include "gc_implementation/shared/hSpaceCounters.hpp"
3945N/A#include "gc_implementation/shared/parGCAllocBuffer.hpp"
1879N/A#include "memory/barrierSet.hpp"
1879N/A#include "memory/memRegion.hpp"
1879N/A#include "memory/sharedHeap.hpp"
4199N/A#include "utilities/stack.hpp"
1879N/A
342N/A// A "G1CollectedHeap" is an implementation of a java heap for HotSpot.
342N/A// It uses the "Garbage First" heap organization and algorithm, which
342N/A// may combine concurrent marking with parallel, incremental compaction of
342N/A// heap subsets that will yield large amounts of garbage.
342N/A
342N/Aclass HeapRegion;
2058N/Aclass HRRSCleanupTask;
342N/Aclass PermanentGenerationSpec;
342N/Aclass GenerationSpec;
342N/Aclass OopsInHeapRegionClosure;
342N/Aclass G1ScanHeapEvacClosure;
342N/Aclass ObjectClosure;
342N/Aclass SpaceClosure;
342N/Aclass CompactibleSpaceClosure;
342N/Aclass Space;
342N/Aclass G1CollectorPolicy;
342N/Aclass GenRemSet;
342N/Aclass G1RemSet;
342N/Aclass HeapRegionRemSetIterator;
342N/Aclass ConcurrentMark;
342N/Aclass ConcurrentMarkThread;
342N/Aclass ConcurrentG1Refine;
4141N/Aclass ConcurrentGCTimer;
2386N/Aclass GenerationCounters;
4141N/Aclass STWGCTimer;
4141N/Aclass G1NewTracer;
4141N/Aclass G1OldTracer;
4419N/Aclass EvacuationFailedInfo;
342N/A
3863N/Atypedef OverflowTaskQueue<StarTask, mtGC> RefToScanQueue;
3863N/Atypedef GenericTaskQueueSet<RefToScanQueue, mtGC> RefToScanQueueSet;
342N/A
807N/Atypedef int RegionIdx_t; // needs to hold [ 0..max_regions() )
807N/Atypedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion )
807N/A
342N/Aenum GCAllocPurpose {
342N/A GCAllocForTenured,
342N/A GCAllocForSurvived,
342N/A GCAllocPurposeCount
342N/A};
342N/A
3863N/Aclass YoungList : public CHeapObj<mtGC> {
342N/Aprivate:
342N/A G1CollectedHeap* _g1h;
342N/A
342N/A HeapRegion* _head;
342N/A
1394N/A HeapRegion* _survivor_head;
1394N/A HeapRegion* _survivor_tail;
1394N/A
1394N/A HeapRegion* _curr;
1394N/A
3681N/A uint _length;
3681N/A uint _survivor_length;
342N/A
342N/A size_t _last_sampled_rs_lengths;
342N/A size_t _sampled_rs_lengths;
342N/A
1394N/A void empty_list(HeapRegion* list);
342N/A
342N/Apublic:
342N/A YoungList(G1CollectedHeap* g1h);
342N/A
1394N/A void push_region(HeapRegion* hr);
1394N/A void add_survivor_region(HeapRegion* hr);
1394N/A
1394N/A void empty_list();
1394N/A bool is_empty() { return _length == 0; }
3681N/A uint length() { return _length; }
3681N/A uint survivor_length() { return _survivor_length; }
342N/A
2589N/A // Currently we do not keep track of the used byte sum for the
2589N/A // young list and the survivors and it'd be quite a lot of work to
2589N/A // do so. When we'll eventually replace the young list with
2589N/A // instances of HeapRegionLinkedList we'll get that for free. So,
2589N/A // we'll report the more accurate information then.
2589N/A size_t eden_used_bytes() {
2589N/A assert(length() >= survivor_length(), "invariant");
3681N/A return (size_t) (length() - survivor_length()) * HeapRegion::GrainBytes;
2589N/A }
2589N/A size_t survivor_used_bytes() {
3681N/A return (size_t) survivor_length() * HeapRegion::GrainBytes;
2589N/A }
2589N/A
342N/A void rs_length_sampling_init();
342N/A bool rs_length_sampling_more();
342N/A void rs_length_sampling_next();
342N/A
342N/A void reset_sampled_info() {
342N/A _last_sampled_rs_lengths = 0;
342N/A }
342N/A size_t sampled_rs_lengths() { return _last_sampled_rs_lengths; }
342N/A
342N/A // for development purposes
342N/A void reset_auxilary_lists();
1394N/A void clear() { _head = NULL; _length = 0; }
1394N/A
1394N/A void clear_survivors() {
1394N/A _survivor_head = NULL;
1394N/A _survivor_tail = NULL;
1394N/A _survivor_length = 0;
1394N/A }
1394N/A
342N/A HeapRegion* first_region() { return _head; }
342N/A HeapRegion* first_survivor_region() { return _survivor_head; }
545N/A HeapRegion* last_survivor_region() { return _survivor_tail; }
342N/A
342N/A // debugging
342N/A bool check_list_well_formed();
1394N/A bool check_list_empty(bool check_sample = true);
342N/A void print();
342N/A};
342N/A
2280N/Aclass MutatorAllocRegion : public G1AllocRegion {
2280N/Aprotected:
2280N/A virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
2280N/A virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
2280N/Apublic:
2280N/A MutatorAllocRegion()
2280N/A : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { }
2280N/A};
2280N/A
2815N/A// The G1 STW is alive closure.
2815N/A// An instance is embedded into the G1CH and used as the
2815N/A// (optional) _is_alive_non_header closure in the STW
2815N/A// reference processor. It is also extensively used during
4419N/A// reference processing during STW evacuation pauses.
2815N/Aclass G1STWIsAliveClosure: public BoolObjectClosure {
2815N/A G1CollectedHeap* _g1;
2815N/Apublic:
2815N/A G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {}
2815N/A void do_object(oop p) { assert(false, "Do not call."); }
2815N/A bool do_object_b(oop p);
2815N/A};
2815N/A
2655N/Aclass SurvivorGCAllocRegion : public G1AllocRegion {
2655N/Aprotected:
2655N/A virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
2655N/A virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
2655N/Apublic:
2655N/A SurvivorGCAllocRegion()
2655N/A : G1AllocRegion("Survivor GC Alloc Region", false /* bot_updates */) { }
2655N/A};
2655N/A
2655N/Aclass OldGCAllocRegion : public G1AllocRegion {
2655N/Aprotected:
2655N/A virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
2655N/A virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
2655N/Apublic:
2655N/A OldGCAllocRegion()
2655N/A : G1AllocRegion("Old GC Alloc Region", true /* bot_updates */) { }
2655N/A};
2655N/A
342N/Aclass RefineCardTableEntryClosure;
2815N/A
342N/Aclass G1CollectedHeap : public SharedHeap {
342N/A friend class VM_G1CollectForAllocation;
342N/A friend class VM_GenCollectForPermanentAllocation;
342N/A friend class VM_G1CollectFull;
342N/A friend class VM_G1IncCollectionPause;
342N/A friend class VMStructs;
2280N/A friend class MutatorAllocRegion;
2655N/A friend class SurvivorGCAllocRegion;
2655N/A friend class OldGCAllocRegion;
342N/A
342N/A // Closures used in implementation.
3658N/A template <bool do_gen_barrier, G1Barrier barrier, bool do_mark_object>
3658N/A friend class G1ParCopyClosure;
342N/A friend class G1IsAliveClosure;
342N/A friend class G1EvacuateFollowersClosure;
342N/A friend class G1ParScanThreadState;
342N/A friend class G1ParScanClosureSuper;
342N/A friend class G1ParEvacuateFollowersClosure;
342N/A friend class G1ParTask;
342N/A friend class G1FreeGarbageRegionClosure;
342N/A friend class RefineCardTableEntryClosure;
342N/A friend class G1PrepareCompactClosure;
342N/A friend class RegionSorter;
2037N/A friend class RegionResetter;
342N/A friend class CountRCClosure;
342N/A friend class EvacPopObjClosure;
796N/A friend class G1ParCleanupCTTask;
342N/A
342N/A // Other related classes.
342N/A friend class G1MarkSweep;
342N/A
342N/Aprivate:
342N/A // The one and only G1CollectedHeap, so static functions can find it.
342N/A static G1CollectedHeap* _g1h;
342N/A
942N/A static size_t _humongous_object_threshold_in_words;
942N/A
342N/A // Storage for the G1 heap (excludes the permanent generation).
342N/A VirtualSpace _g1_storage;
342N/A MemRegion _g1_reserved;
342N/A
342N/A // The part of _g1_storage that is currently committed.
342N/A MemRegion _g1_committed;
342N/A
2037N/A // The master free list. It will satisfy all new region allocations.
2037N/A MasterFreeRegionList _free_list;
2037N/A
2037N/A // The secondary free list which contains regions that have been
2037N/A // freed up during the cleanup process. This will be appended to the
2037N/A // master free list when appropriate.
2037N/A SecondaryFreeRegionList _secondary_free_list;
2037N/A
2910N/A // It keeps track of the old regions.
2910N/A MasterOldRegionSet _old_set;
2910N/A
2037N/A // It keeps track of the humongous regions.
2037N/A MasterHumongousRegionSet _humongous_set;
342N/A
342N/A // The number of regions we could create by expansion.
3681N/A uint _expansion_regions;
342N/A
342N/A // The block offset table for the G1 heap.
342N/A G1BlockOffsetSharedArray* _bot_shared;
342N/A
2910N/A // Tears down the region sets / lists so that they are empty and the
2910N/A // regions on the heap do not belong to a region set / list. The
2910N/A // only exception is the humongous set which we leave unaltered. If
2910N/A // free_list_only is true, it will only tear down the master free
2910N/A // list. It is called before a Full GC (free_list_only == false) or
2910N/A // before heap shrinking (free_list_only == true).
2910N/A void tear_down_region_sets(bool free_list_only);
2910N/A
2910N/A // Rebuilds the region sets / lists so that they are repopulated to
2910N/A // reflect the contents of the heap. The only exception is the
2910N/A // humongous set which was not torn down in the first place. If
2910N/A // free_list_only is true, it will only rebuild the master free
2910N/A // list. It is called after a Full GC (free_list_only == false) or
2910N/A // after heap shrinking (free_list_only == true).
2910N/A void rebuild_region_sets(bool free_list_only);
342N/A
342N/A // The sequence of all heap regions in the heap.
2591N/A HeapRegionSeq _hrs;
342N/A
2280N/A // Alloc region used to satisfy mutator allocation requests.
2280N/A MutatorAllocRegion _mutator_alloc_region;
342N/A
2655N/A // Alloc region used to satisfy allocation requests by the GC for
2655N/A // survivor objects.
2655N/A SurvivorGCAllocRegion _survivor_gc_alloc_region;
2655N/A
3945N/A // PLAB sizing policy for survivors.
3945N/A PLABStats _survivor_plab_stats;
3945N/A
2655N/A // Alloc region used to satisfy allocation requests by the GC for
2655N/A // old objects.
2655N/A OldGCAllocRegion _old_gc_alloc_region;
2655N/A
3945N/A // PLAB sizing policy for tenured objects.
3945N/A PLABStats _old_plab_stats;
3945N/A
3945N/A PLABStats* stats_for_purpose(GCAllocPurpose purpose) {
3945N/A PLABStats* stats = NULL;
3945N/A
3945N/A switch (purpose) {
3945N/A case GCAllocForSurvived:
3945N/A stats = &_survivor_plab_stats;
3945N/A break;
3945N/A case GCAllocForTenured:
3945N/A stats = &_old_plab_stats;
3945N/A break;
3945N/A default:
3945N/A assert(false, "unrecognized GCAllocPurpose");
3945N/A }
3945N/A
3945N/A return stats;
3945N/A }
3945N/A
2655N/A // The last old region we allocated to during the last GC.
2655N/A // Typically, it is not full so we should re-use it during the next GC.
2655N/A HeapRegion* _retained_old_gc_alloc_region;
2655N/A
3061N/A // It specifies whether we should attempt to expand the heap after a
3061N/A // region allocation failure. If heap expansion fails we set this to
3061N/A // false so that we don't re-attempt the heap expansion (it's likely
3061N/A // that subsequent expansion attempts will also fail if one fails).
3061N/A // Currently, it is only consulted during GC and it's reset at the
3061N/A // start of each GC.
3061N/A bool _expand_heap_after_alloc_failure;
3061N/A
2280N/A // It resets the mutator alloc region before new allocations can take place.
2280N/A void init_mutator_alloc_region();
2280N/A
2280N/A // It releases the mutator alloc region.
2280N/A void release_mutator_alloc_region();
2280N/A
2655N/A // It initializes the GC alloc regions at the start of a GC.
4362N/A void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
342N/A
2655N/A // It releases the GC alloc regions at the end of a GC.
4362N/A void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info);
342N/A
2655N/A // It does any cleanup that needs to be done on the GC alloc regions
2655N/A // before a Full GC.
2655N/A void abandon_gc_alloc_regions();
342N/A
2386N/A // Helper for monitoring and management support.
2386N/A G1MonitoringSupport* _g1mm;
2386N/A
1391N/A // Determines PLAB size for a particular allocation purpose.
3945N/A size_t desired_plab_sz(GCAllocPurpose purpose);
1391N/A
342N/A // Outside of GC pauses, the number of bytes used in all regions other
342N/A // than the current allocation region.
342N/A size_t _summary_bytes_used;
342N/A
526N/A // This is used for a quick test on whether a reference points into
526N/A // the collection set or not. Basically, we have an array, with one
526N/A // byte per region, and that byte denotes whether the corresponding
526N/A // region is in the collection set or not. The entry corresponding
526N/A // the bottom of the heap, i.e., region 0, is pointed to by
526N/A // _in_cset_fast_test_base. The _in_cset_fast_test field has been
526N/A // biased so that it actually points to address 0 of the address
526N/A // space, to make the test as fast as possible (we can simply shift
526N/A // the address to address into it, instead of having to subtract the
526N/A // bottom of the heap from the address before shifting it; basically
526N/A // it works in the same way the card table works).
526N/A bool* _in_cset_fast_test;
526N/A
526N/A // The allocated array used for the fast test on whether a reference
526N/A // points into the collection set or not. This field is also used to
526N/A // free the array.
526N/A bool* _in_cset_fast_test_base;
526N/A
526N/A // The length of the _in_cset_fast_test_base array.
3681N/A uint _in_cset_fast_test_length;
526N/A
353N/A volatile unsigned _gc_time_stamp;
342N/A
342N/A size_t* _surviving_young_words;
342N/A
2603N/A G1HRPrinter _hr_printer;
2603N/A
342N/A void setup_surviving_young_words();
342N/A void update_surviving_young_words(size_t* surv_young_words);
342N/A void cleanup_surviving_young_words();
342N/A
1576N/A // It decides whether an explicit GC should start a concurrent cycle
1576N/A // instead of doing a STW GC. Currently, a concurrent cycle is
1576N/A // explicitly started if:
1576N/A // (a) cause == _gc_locker and +GCLockerInvokesConcurrent, or
1576N/A // (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent.
3112N/A // (c) cause == _g1_humongous_allocation
1576N/A bool should_do_concurrent_full_gc(GCCause::Cause cause);
1576N/A
3787N/A // Keeps track of how many "old marking cycles" (i.e., Full GCs or
3787N/A // concurrent cycles) we have started.
3787N/A volatile unsigned int _old_marking_cycles_started;
3787N/A
3787N/A // Keeps track of how many "old marking cycles" (i.e., Full GCs or
3787N/A // concurrent cycles) we have completed.
3787N/A volatile unsigned int _old_marking_cycles_completed;
1576N/A
4141N/A bool _concurrent_cycle_started;
4141N/A
2382N/A // This is a non-product method that is helpful for testing. It is
2382N/A // called at the end of a GC and artificially expands the heap by
2382N/A // allocating a number of dead regions. This way we can induce very
2382N/A // frequent marking cycles and stress the cleanup / concurrent
2382N/A // cleanup code more (as all the regions that will be allocated by
2382N/A // this method will be found dead by the marking cycle).
2382N/A void allocate_dummy_regions() PRODUCT_RETURN;
2382N/A
3920N/A // Clear RSets after a compaction. It also resets the GC time stamps.
3920N/A void clear_rsets_post_compaction();
3920N/A
3920N/A // If the HR printer is active, dump the state of the regions in the
3920N/A // heap after a compaction.
3920N/A void print_hrs_post_compaction();
3920N/A
3978N/A double verify(bool guard, const char* msg);
3978N/A void verify_before_gc();
3978N/A void verify_after_gc();
3978N/A
4004N/A void log_gc_header();
4004N/A void log_gc_footer(double pause_time_sec);
4004N/A
1880N/A // These are macros so that, if the assert fires, we get the correct
1880N/A // line number, file, etc.
1880N/A
2208N/A#define heap_locking_asserts_err_msg(_extra_message_) \
2037N/A err_msg("%s : Heap_lock locked: %s, at safepoint: %s, is VM thread: %s", \
2208N/A (_extra_message_), \
2037N/A BOOL_TO_STR(Heap_lock->owned_by_self()), \
2037N/A BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()), \
2037N/A BOOL_TO_STR(Thread::current()->is_VM_thread()))
1880N/A
1880N/A#define assert_heap_locked() \
1880N/A do { \
1880N/A assert(Heap_lock->owned_by_self(), \
1880N/A heap_locking_asserts_err_msg("should be holding the Heap_lock")); \
1880N/A } while (0)
1880N/A
2208N/A#define assert_heap_locked_or_at_safepoint(_should_be_vm_thread_) \
1880N/A do { \
1880N/A assert(Heap_lock->owned_by_self() || \
2037N/A (SafepointSynchronize::is_at_safepoint() && \
2208N/A ((_should_be_vm_thread_) == Thread::current()->is_VM_thread())), \
1880N/A heap_locking_asserts_err_msg("should be holding the Heap_lock or " \
1880N/A "should be at a safepoint")); \
1880N/A } while (0)
1880N/A
1880N/A#define assert_heap_locked_and_not_at_safepoint() \
1880N/A do { \
1880N/A assert(Heap_lock->owned_by_self() && \
1880N/A !SafepointSynchronize::is_at_safepoint(), \
1880N/A heap_locking_asserts_err_msg("should be holding the Heap_lock and " \
1880N/A "should not be at a safepoint")); \
1880N/A } while (0)
1880N/A
1880N/A#define assert_heap_not_locked() \
1880N/A do { \
1880N/A assert(!Heap_lock->owned_by_self(), \
1880N/A heap_locking_asserts_err_msg("should not be holding the Heap_lock")); \
1880N/A } while (0)
1880N/A
1880N/A#define assert_heap_not_locked_and_not_at_safepoint() \
1880N/A do { \
1880N/A assert(!Heap_lock->owned_by_self() && \
1880N/A !SafepointSynchronize::is_at_safepoint(), \
1880N/A heap_locking_asserts_err_msg("should not be holding the Heap_lock and " \
1880N/A "should not be at a safepoint")); \
1880N/A } while (0)
1880N/A
2208N/A#define assert_at_safepoint(_should_be_vm_thread_) \
1880N/A do { \
2037N/A assert(SafepointSynchronize::is_at_safepoint() && \
2208N/A ((_should_be_vm_thread_) == Thread::current()->is_VM_thread()), \
1880N/A heap_locking_asserts_err_msg("should be at a safepoint")); \
1880N/A } while (0)
1880N/A
1880N/A#define assert_not_at_safepoint() \
1880N/A do { \
1880N/A assert(!SafepointSynchronize::is_at_safepoint(), \
1880N/A heap_locking_asserts_err_msg("should not be at a safepoint")); \
1880N/A } while (0)
1880N/A
342N/Aprotected:
342N/A
2648N/A // The young region list.
342N/A YoungList* _young_list;
342N/A
342N/A // The current policy object for the collector.
342N/A G1CollectorPolicy* _g1_policy;
342N/A
2037N/A // This is the second level of trying to allocate a new region. If
2280N/A // new_region() didn't find a region on the free_list, this call will
2280N/A // check whether there's anything available on the
2280N/A // secondary_free_list and/or wait for more regions to appear on
2280N/A // that list, if _free_regions_coming is set.
2208N/A HeapRegion* new_region_try_secondary_free_list();
342N/A
2208N/A // Try to allocate a single non-humongous HeapRegion sufficient for
2208N/A // an allocation of the given word_size. If do_expand is true,
2208N/A // attempt to expand the heap if necessary to satisfy the allocation
2208N/A // request.
2280N/A HeapRegion* new_region(size_t word_size, bool do_expand);
342N/A
2208N/A // Attempt to satisfy a humongous allocation request of the given
2208N/A // size by finding a contiguous set of free regions of num_regions
2208N/A // length and remove them from the master free list. Return the
2591N/A // index of the first region or G1_NULL_HRS_INDEX if the search
2591N/A // was unsuccessful.
3681N/A uint humongous_obj_allocate_find_first(uint num_regions,
3681N/A size_t word_size);
342N/A
2208N/A // Initialize a contiguous set of free regions of length num_regions
2208N/A // and starting at index first so that they appear as a single
2208N/A // humongous region.
3681N/A HeapWord* humongous_obj_allocate_initialize_regions(uint first,
3681N/A uint num_regions,
2208N/A size_t word_size);
2208N/A
2208N/A // Attempt to allocate a humongous object of the given size. Return
2208N/A // NULL if unsuccessful.
2037N/A HeapWord* humongous_obj_allocate(size_t word_size);
1880N/A
1880N/A // The following two methods, allocate_new_tlab() and
1880N/A // mem_allocate(), are the two main entry points from the runtime
1880N/A // into the G1's allocation routines. They have the following
1880N/A // assumptions:
1880N/A //
1880N/A // * They should both be called outside safepoints.
1880N/A //
1880N/A // * They should both be called without holding the Heap_lock.
1880N/A //
1880N/A // * All allocation requests for new TLABs should go to
1880N/A // allocate_new_tlab().
1880N/A //
2599N/A // * All non-TLAB allocation requests should go to mem_allocate().
1880N/A //
1880N/A // * If either call cannot satisfy the allocation request using the
1880N/A // current allocating region, they will try to get a new one. If
1880N/A // this fails, they will attempt to do an evacuation pause and
1880N/A // retry the allocation.
1880N/A //
1880N/A // * If all allocation attempts fail, even after trying to schedule
1880N/A // an evacuation pause, allocate_new_tlab() will return NULL,
1880N/A // whereas mem_allocate() will attempt a heap expansion and/or
1880N/A // schedule a Full GC.
1880N/A //
1880N/A // * We do not allow humongous-sized TLABs. So, allocate_new_tlab
1880N/A // should never be called with word_size being humongous. All
1880N/A // humongous allocation requests should go to mem_allocate() which
1880N/A // will satisfy them with a special path.
1880N/A
1880N/A virtual HeapWord* allocate_new_tlab(size_t word_size);
1880N/A
1880N/A virtual HeapWord* mem_allocate(size_t word_size,
1880N/A bool* gc_overhead_limit_was_exceeded);
342N/A
2280N/A // The following three methods take a gc_count_before_ret
2280N/A // parameter which is used to return the GC count if the method
2280N/A // returns NULL. Given that we are required to read the GC count
2280N/A // while holding the Heap_lock, and these paths will take the
2280N/A // Heap_lock at some point, it's easier to get them to read the GC
2280N/A // count while holding the Heap_lock before they return NULL instead
2280N/A // of the caller (namely: mem_allocate()) having to also take the
2280N/A // Heap_lock just to read the GC count.
2280N/A
2280N/A // First-level mutator allocation attempt: try to allocate out of
2280N/A // the mutator alloc region without taking the Heap_lock. This
2280N/A // should only be used for non-humongous allocations.
2280N/A inline HeapWord* attempt_allocation(size_t word_size,
2280N/A unsigned int* gc_count_before_ret);
342N/A
2280N/A // Second-level mutator allocation attempt: take the Heap_lock and
2280N/A // retry the allocation attempt, potentially scheduling a GC
2280N/A // pause. This should only be used for non-humongous allocations.
2280N/A HeapWord* attempt_allocation_slow(size_t word_size,
2280N/A unsigned int* gc_count_before_ret);
2019N/A
2280N/A // Takes the Heap_lock and attempts a humongous allocation. It can
2280N/A // potentially schedule a GC pause.
2280N/A HeapWord* attempt_allocation_humongous(size_t word_size,
2280N/A unsigned int* gc_count_before_ret);
1880N/A
2280N/A // Allocation attempt that should be called during safepoints (e.g.,
2280N/A // at the end of a successful GC). expect_null_mutator_alloc_region
2280N/A // specifies whether the mutator alloc region is expected to be NULL
2280N/A // or not.
1880N/A HeapWord* attempt_allocation_at_safepoint(size_t word_size,
2280N/A bool expect_null_mutator_alloc_region);
1880N/A
1880N/A // It dirties the cards that cover the block so that so that the post
1880N/A // write barrier never queues anything when updating objects on this
1880N/A // block. It is assumed (and in fact we assert) that the block
1880N/A // belongs to a young region.
1880N/A inline void dirty_young_block(HeapWord* start, size_t word_size);
342N/A
342N/A // Allocate blocks during garbage collection. Will ensure an
342N/A // allocation region, either by picking one or expanding the
342N/A // heap, and then allocate a block of the given size. The block
342N/A // may not be a humongous - it must fit into a single heap region.
342N/A HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size);
342N/A
342N/A HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose,
342N/A HeapRegion* alloc_region,
342N/A bool par,
342N/A size_t word_size);
342N/A
342N/A // Ensure that no further allocations can happen in "r", bearing in mind
342N/A // that parallel threads might be attempting allocations.
342N/A void par_allocate_remaining_space(HeapRegion* r);
342N/A
2655N/A // Allocation attempt during GC for a survivor object / PLAB.
2655N/A inline HeapWord* survivor_attempt_allocation(size_t word_size);
545N/A
2655N/A // Allocation attempt during GC for an old object / PLAB.
2655N/A inline HeapWord* old_attempt_allocation(size_t word_size);
2280N/A
2655N/A // These methods are the "callbacks" from the G1AllocRegion class.
2655N/A
2655N/A // For mutator alloc regions.
2280N/A HeapRegion* new_mutator_alloc_region(size_t word_size, bool force);
2280N/A void retire_mutator_alloc_region(HeapRegion* alloc_region,
2280N/A size_t allocated_bytes);
2280N/A
2655N/A // For GC alloc regions.
3681N/A HeapRegion* new_gc_alloc_region(size_t word_size, uint count,
2655N/A GCAllocPurpose ap);
2655N/A void retire_gc_alloc_region(HeapRegion* alloc_region,
2655N/A size_t allocated_bytes, GCAllocPurpose ap);
2655N/A
1576N/A // - if explicit_gc is true, the GC is for a System.gc() or a heap
1880N/A // inspection request and should collect the entire heap
1880N/A // - if clear_all_soft_refs is true, all soft references should be
1880N/A // cleared during the GC
1576N/A // - if explicit_gc is false, word_size describes the allocation that
1880N/A // the GC should attempt (at least) to satisfy
1880N/A // - it returns false if it is unable to do the collection due to the
1880N/A // GC locker being active, true otherwise
1880N/A bool do_collection(bool explicit_gc,
1576N/A bool clear_all_soft_refs,
342N/A size_t word_size);
342N/A
342N/A // Callback from VM_G1CollectFull operation.
342N/A // Perform a full collection.
342N/A void do_full_collection(bool clear_all_soft_refs);
342N/A
342N/A // Resize the heap if necessary after a full collection. If this is
342N/A // after a collect-for allocation, "word_size" is the allocation size,
342N/A // and will be considered part of the used portion of the heap.
342N/A void resize_if_necessary_after_full_collection(size_t word_size);
342N/A
342N/A // Callback from VM_G1CollectForAllocation operation.
342N/A // This function does everything necessary/possible to satisfy a
342N/A // failed allocation request (including collection, expansion, etc.)
1880N/A HeapWord* satisfy_failed_allocation(size_t word_size, bool* succeeded);
342N/A
342N/A // Attempting to expand the heap sufficiently
342N/A // to support an allocation of the given "word_size". If
342N/A // successful, perform the allocation and return the address of the
342N/A // allocated block, or else "NULL".
1880N/A HeapWord* expand_and_allocate(size_t word_size);
342N/A
2815N/A // Process any reference objects discovered during
2815N/A // an incremental evacuation pause.
4007N/A void process_discovered_references(uint no_of_gc_workers);
2815N/A
2815N/A // Enqueue any remaining discovered references
2815N/A // after processing.
4007N/A void enqueue_discovered_references(uint no_of_gc_workers);
2815N/A
342N/Apublic:
2386N/A
2816N/A G1MonitoringSupport* g1mm() {
2816N/A assert(_g1mm != NULL, "should have been initialized");
2816N/A return _g1mm;
2816N/A }
2386N/A
342N/A // Expand the garbage-first heap by at least the given size (in bytes!).
2069N/A // Returns true if the heap was expanded by the requested amount;
2069N/A // false otherwise.
342N/A // (Rounds up to a HeapRegion boundary.)
2069N/A bool expand(size_t expand_bytes);
342N/A
342N/A // Do anything common to GC's.
342N/A virtual void gc_prologue(bool full);
342N/A virtual void gc_epilogue(bool full);
342N/A
526N/A // We register a region with the fast "in collection set" test. We
526N/A // simply set to true the array slot corresponding to this region.
526N/A void register_region_with_in_cset_fast_test(HeapRegion* r) {
526N/A assert(_in_cset_fast_test_base != NULL, "sanity");
526N/A assert(r->in_collection_set(), "invariant");
3681N/A uint index = r->hrs_index();
2591N/A assert(index < _in_cset_fast_test_length, "invariant");
526N/A assert(!_in_cset_fast_test_base[index], "invariant");
526N/A _in_cset_fast_test_base[index] = true;
526N/A }
526N/A
526N/A // This is a fast test on whether a reference points into the
526N/A // collection set or not. It does not assume that the reference
526N/A // points into the heap; if it doesn't, it will return false.
526N/A bool in_cset_fast_test(oop obj) {
526N/A assert(_in_cset_fast_test != NULL, "sanity");
526N/A if (_g1_committed.contains((HeapWord*) obj)) {
526N/A // no need to subtract the bottom of the heap from obj,
526N/A // _in_cset_fast_test is biased
3681N/A uintx index = (uintx) obj >> HeapRegion::LogOfHRGrainBytes;
526N/A bool ret = _in_cset_fast_test[index];
526N/A // let's make sure the result is consistent with what the slower
526N/A // test returns
526N/A assert( ret || !obj_in_cs(obj), "sanity");
526N/A assert(!ret || obj_in_cs(obj), "sanity");
526N/A return ret;
526N/A } else {
526N/A return false;
526N/A }
526N/A }
526N/A
1394N/A void clear_cset_fast_test() {
1394N/A assert(_in_cset_fast_test_base != NULL, "sanity");
1394N/A memset(_in_cset_fast_test_base, false,
3681N/A (size_t) _in_cset_fast_test_length * sizeof(bool));
1394N/A }
1394N/A
3787N/A // This is called at the start of either a concurrent cycle or a Full
3787N/A // GC to update the number of old marking cycles started.
3787N/A void increment_old_marking_cycles_started();
3787N/A
1576N/A // This is called at the end of either a concurrent cycle or a Full
3787N/A // GC to update the number of old marking cycles completed. Those two
1576N/A // can happen in a nested fashion, i.e., we start a concurrent
1576N/A // cycle, a Full GC happens half-way through it which ends first,
1576N/A // and then the cycle notices that a Full GC happened and ends
1937N/A // too. The concurrent parameter is a boolean to help us do a bit
1937N/A // tighter consistency checking in the method. If concurrent is
1937N/A // false, the caller is the inner caller in the nesting (i.e., the
1937N/A // Full GC). If concurrent is true, the caller is the outer caller
1937N/A // in this nesting (i.e., the concurrent cycle). Further nesting is
3787N/A // not currently supported. The end of this call also notifies
1937N/A // the FullGCCount_lock in case a Java thread is waiting for a full
1937N/A // GC to happen (e.g., it called System.gc() with
1576N/A // +ExplicitGCInvokesConcurrent).
3787N/A void increment_old_marking_cycles_completed(bool concurrent);
1576N/A
3787N/A unsigned int old_marking_cycles_completed() {
3787N/A return _old_marking_cycles_completed;
1576N/A }
1576N/A
4141N/A void register_concurrent_cycle_start(jlong start_time);
4141N/A void register_concurrent_cycle_end();
4141N/A void trace_heap_after_concurrent_cycle();
4141N/A
4141N/A G1YCType yc_type();
4141N/A
2603N/A G1HRPrinter* hr_printer() { return &_hr_printer; }
2603N/A
342N/Aprotected:
342N/A
342N/A // Shrink the garbage-first heap by at most the given size (in bytes!).
342N/A // (Rounds down to a HeapRegion boundary.)
342N/A virtual void shrink(size_t expand_bytes);
342N/A void shrink_helper(size_t expand_bytes);
342N/A
1629N/A #if TASKQUEUE_STATS
1629N/A static void print_taskqueue_stats_hdr(outputStream* const st = gclog_or_tty);
1629N/A void print_taskqueue_stats(outputStream* const st = gclog_or_tty) const;
1629N/A void reset_taskqueue_stats();
1629N/A #endif // TASKQUEUE_STATS
1629N/A
1880N/A // Schedule the VM operation that will do an evacuation pause to
1880N/A // satisfy an allocation request of word_size. *succeeded will
1880N/A // return whether the VM operation was successful (it did do an
1880N/A // evacuation pause) or not (another thread beat us to it or the GC
1880N/A // locker was active). Given that we should not be holding the
1880N/A // Heap_lock when we enter this method, we will pass the
1880N/A // gc_count_before (i.e., total_collections()) as a parameter since
1880N/A // it has to be read while holding the Heap_lock. Currently, both
1880N/A // methods that call do_collection_pause() release the Heap_lock
1880N/A // before the call, so it's easy to read gc_count_before just before.
1880N/A HeapWord* do_collection_pause(size_t word_size,
1880N/A unsigned int gc_count_before,
1880N/A bool* succeeded);
342N/A
342N/A // The guts of the incremental collection pause, executed by the vm
1880N/A // thread. It returns false if it is unable to do the collection due
1880N/A // to the GC locker being active, true otherwise
1880N/A bool do_collection_pause_at_safepoint(double target_pause_time_ms);
342N/A
342N/A // Actually do the work of evacuating the collection set.
4362N/A void evacuate_collection_set(EvacuationInfo& evacuation_info);
342N/A
342N/A // The g1 remembered set of the heap.
342N/A G1RemSet* _g1_rem_set;
342N/A // And it's mod ref barrier set, used to track updates for the above.
342N/A ModRefBarrierSet* _mr_bs;
342N/A
616N/A // A set of cards that cover the objects for which the Rsets should be updated
616N/A // concurrently after the collection.
616N/A DirtyCardQueueSet _dirty_card_queue_set;
616N/A
342N/A // The Heap Region Rem Set Iterator.
342N/A HeapRegionRemSetIterator** _rem_set_iterator;
342N/A
342N/A // The closure used to refine a single card.
342N/A RefineCardTableEntryClosure* _refine_cte_cl;
342N/A
342N/A // A function to check the consistency of dirty card logs.
342N/A void check_ct_logs_at_safepoint();
342N/A
1625N/A // A DirtyCardQueueSet that is used to hold cards that contain
1625N/A // references into the current collection set. This is used to
1625N/A // update the remembered sets of the regions in the collection
1625N/A // set in the event of an evacuation failure.
1625N/A DirtyCardQueueSet _into_cset_dirty_card_queue_set;
1625N/A
342N/A // After a collection pause, make the regions in the CS into free
342N/A // regions.
4362N/A void free_collection_set(HeapRegion* cs_head, EvacuationInfo& evacuation_info);
342N/A
1394N/A // Abandon the current collection set without recording policy
1394N/A // statistics or updating free lists.
1394N/A void abandon_collection_set(HeapRegion* cs_head);
1394N/A
342N/A // Applies "scan_non_heap_roots" to roots outside the heap,
342N/A // "scan_rs" to roots inside the heap (having done "set_region" to
342N/A // indicate the region in which the root resides), and does "scan_perm"
342N/A // (setting the generation to the perm generation.) If "scan_rs" is
342N/A // NULL, then this step is skipped. The "worker_i"
342N/A // param is for use with parallel roots processing, and should be
342N/A // the "i" of the calling parallel worker thread's work(i) function.
342N/A // In the sequential case this param will be ignored.
342N/A void g1_process_strong_roots(bool collecting_perm_gen,
3199N/A ScanningOption so,
342N/A OopClosure* scan_non_heap_roots,
342N/A OopsInHeapRegionClosure* scan_rs,
342N/A OopsInGenClosure* scan_perm,
342N/A int worker_i);
342N/A
342N/A // Apply "blk" to all the weak roots of the system. These include
342N/A // JNI weak roots, the code cache, system dictionary, symbol table,
342N/A // string table, and referents of reachable weak refs.
342N/A void g1_process_weak_roots(OopClosure* root_closure,
342N/A OopClosure* non_root_closure);
342N/A
2208N/A // Frees a non-humongous region by initializing its contents and
2037N/A // adding it to the free list that's passed as a parameter (this is
2037N/A // usually a local list which will be appended to the master free
2037N/A // list later). The used bytes of freed regions are accumulated in
2037N/A // pre_used. If par is true, the region's RSet will not be freed
2037N/A // up. The assumption is that this will be done later.
2037N/A void free_region(HeapRegion* hr,
2037N/A size_t* pre_used,
2037N/A FreeRegionList* free_list,
2037N/A bool par);
342N/A
2208N/A // Frees a humongous region by collapsing it into individual regions
2208N/A // and calling free_region() for each of them. The freed regions
2208N/A // will be added to the free list that's passed as a parameter (this
2208N/A // is usually a local list which will be appended to the master free
2208N/A // list later). The used bytes of freed regions are accumulated in
2208N/A // pre_used. If par is true, the region's RSet will not be freed
2208N/A // up. The assumption is that this will be done later.
2037N/A void free_humongous_region(HeapRegion* hr,
2037N/A size_t* pre_used,
2037N/A FreeRegionList* free_list,
2037N/A HumongousRegionSet* humongous_proxy_set,
2037N/A bool par);
342N/A
2591N/A // Notifies all the necessary spaces that the committed space has
2591N/A // been updated (either expanded or shrunk). It should be called
2591N/A // after _g1_storage is updated.
2591N/A void update_committed_space(HeapWord* old_end, HeapWord* new_end);
2591N/A
342N/A // The concurrent marker (and the thread it runs in.)
342N/A ConcurrentMark* _cm;
342N/A ConcurrentMarkThread* _cmThread;
342N/A bool _mark_in_progress;
342N/A
342N/A // The concurrent refiner.
342N/A ConcurrentG1Refine* _cg1r;
342N/A
342N/A // The parallel task queues
342N/A RefToScanQueueSet *_task_queues;
342N/A
342N/A // True iff a evacuation has failed in the current collection.
342N/A bool _evacuation_failed;
342N/A
4419N/A EvacuationFailedInfo* _evacuation_failed_info_array;
342N/A
342N/A // Failed evacuations cause some logical from-space objects to have
342N/A // forwarding pointers to themselves. Reset them.
342N/A void remove_self_forwarding_pointers();
342N/A
4199N/A // Together, these store an object with a preserved mark, and its mark value.
4199N/A Stack<oop, mtGC> _objs_with_preserved_marks;
4199N/A Stack<markOop, mtGC> _preserved_marks_of_objs;
342N/A
342N/A // Preserve the mark of "obj", if necessary, in preparation for its mark
342N/A // word being overwritten with a self-forwarding-pointer.
342N/A void preserve_mark_if_necessary(oop obj, markOop m);
342N/A
342N/A // The stack of evac-failure objects left to be scanned.
342N/A GrowableArray<oop>* _evac_failure_scan_stack;
342N/A // The closure to apply to evac-failure objects.
342N/A
342N/A OopsInHeapRegionClosure* _evac_failure_closure;
342N/A // Set the field above.
342N/A void
342N/A set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_closure) {
342N/A _evac_failure_closure = evac_failure_closure;
342N/A }
342N/A
342N/A // Push "obj" on the scan stack.
342N/A void push_on_evac_failure_scan_stack(oop obj);
342N/A // Process scan stack entries until the stack is empty.
342N/A void drain_evac_failure_scan_stack();
342N/A // True iff an invocation of "drain_scan_stack" is in progress; to
342N/A // prevent unnecessary recursion.
342N/A bool _drain_in_progress;
342N/A
342N/A // Do any necessary initialization for evacuation-failure handling.
342N/A // "cl" is the closure that will be used to process evac-failure
342N/A // objects.
342N/A void init_for_evac_failure(OopsInHeapRegionClosure* cl);
342N/A // Do any necessary cleanup for evacuation-failure handling data
342N/A // structures.
342N/A void finalize_for_evac_failure();
342N/A
342N/A // An attempt to evacuate "obj" has failed; take necessary steps.
4419N/A oop handle_evacuation_failure_par(G1ParScanThreadState* _par_scan_state, oop obj);
342N/A void handle_evacuation_failure_common(oop obj, markOop m);
342N/A
3979N/A#ifndef PRODUCT
3979N/A // Support for forcing evacuation failures. Analogous to
3979N/A // PromotionFailureALot for the other collectors.
3979N/A
3979N/A // Records whether G1EvacuationFailureALot should be in effect
3979N/A // for the current GC
3979N/A bool _evacuation_failure_alot_for_current_gc;
3979N/A
3979N/A // Used to record the GC number for interval checking when
3979N/A // determining whether G1EvaucationFailureALot is in effect
3979N/A // for the current GC.
3979N/A size_t _evacuation_failure_alot_gc_number;
3979N/A
3979N/A // Count of the number of evacuations between failures.
3979N/A volatile size_t _evacuation_failure_alot_count;
3979N/A
3979N/A // Set whether G1EvacuationFailureALot should be in effect
3979N/A // for the current GC (based upon the type of GC and which
3979N/A // command line flags are set);
3979N/A inline bool evacuation_failure_alot_for_gc_type(bool gcs_are_young,
3979N/A bool during_initial_mark,
3979N/A bool during_marking);
3979N/A
3979N/A inline void set_evacuation_failure_alot_for_current_gc();
3979N/A
3979N/A // Return true if it's time to cause an evacuation failure.
3979N/A inline bool evacuation_should_fail();
3979N/A
3979N/A // Reset the G1EvacuationFailureALot counters. Should be called at
4419N/A // the end of an evacuation pause in which an evacuation failure occurred.
3979N/A inline void reset_evacuation_should_fail();
3979N/A#endif // !PRODUCT
3979N/A
2815N/A // ("Weak") Reference processing support.
2815N/A //
4419N/A // G1 has 2 instances of the reference processor class. One
2815N/A // (_ref_processor_cm) handles reference object discovery
2815N/A // and subsequent processing during concurrent marking cycles.
2815N/A //
2815N/A // The other (_ref_processor_stw) handles reference object
2815N/A // discovery and processing during full GCs and incremental
2815N/A // evacuation pauses.
2815N/A //
2815N/A // During an incremental pause, reference discovery will be
2815N/A // temporarily disabled for _ref_processor_cm and will be
2815N/A // enabled for _ref_processor_stw. At the end of the evacuation
2815N/A // pause references discovered by _ref_processor_stw will be
2815N/A // processed and discovery will be disabled. The previous
2815N/A // setting for reference object discovery for _ref_processor_cm
2815N/A // will be re-instated.
2815N/A //
2815N/A // At the start of marking:
2815N/A // * Discovery by the CM ref processor is verified to be inactive
2815N/A // and it's discovered lists are empty.
2815N/A // * Discovery by the CM ref processor is then enabled.
2815N/A //
2815N/A // At the end of marking:
2815N/A // * Any references on the CM ref processor's discovered
2815N/A // lists are processed (possibly MT).
2815N/A //
2815N/A // At the start of full GC we:
2815N/A // * Disable discovery by the CM ref processor and
2815N/A // empty CM ref processor's discovered lists
2815N/A // (without processing any entries).
2815N/A // * Verify that the STW ref processor is inactive and it's
2815N/A // discovered lists are empty.
2815N/A // * Temporarily set STW ref processor discovery as single threaded.
2815N/A // * Temporarily clear the STW ref processor's _is_alive_non_header
2815N/A // field.
2815N/A // * Finally enable discovery by the STW ref processor.
2815N/A //
2815N/A // The STW ref processor is used to record any discovered
2815N/A // references during the full GC.
2815N/A //
2815N/A // At the end of a full GC we:
2815N/A // * Enqueue any reference objects discovered by the STW ref processor
2815N/A // that have non-live referents. This has the side-effect of
2815N/A // making the STW ref processor inactive by disabling discovery.
2815N/A // * Verify that the CM ref processor is still inactive
2815N/A // and no references have been placed on it's discovered
2815N/A // lists (also checked as a precondition during initial marking).
2815N/A
2815N/A // The (stw) reference processor...
2815N/A ReferenceProcessor* _ref_processor_stw;
2815N/A
4141N/A STWGCTimer* _gc_timer_stw;
4141N/A ConcurrentGCTimer* _gc_timer_cm;
4141N/A
4141N/A G1OldTracer* _gc_tracer_cm;
4141N/A G1NewTracer* _gc_tracer_stw;
4141N/A
2815N/A // During reference object discovery, the _is_alive_non_header
2815N/A // closure (if non-null) is applied to the referent object to
2815N/A // determine whether the referent is live. If so then the
2815N/A // reference object does not need to be 'discovered' and can
2815N/A // be treated as a regular oop. This has the benefit of reducing
2815N/A // the number of 'discovered' reference objects that need to
2815N/A // be processed.
2815N/A //
2815N/A // Instance of the is_alive closure for embedding into the
2815N/A // STW reference processor as the _is_alive_non_header field.
2815N/A // Supplying a value for the _is_alive_non_header field is
2815N/A // optional but doing so prevents unnecessary additions to
2815N/A // the discovered lists during reference discovery.
2815N/A G1STWIsAliveClosure _is_alive_closure_stw;
2815N/A
2815N/A // The (concurrent marking) reference processor...
2815N/A ReferenceProcessor* _ref_processor_cm;
2815N/A
1944N/A // Instance of the concurrent mark is_alive closure for embedding
2815N/A // into the Concurrent Marking reference processor as the
2815N/A // _is_alive_non_header field. Supplying a value for the
2815N/A // _is_alive_non_header field is optional but doing so prevents
2815N/A // unnecessary additions to the discovered lists during reference
2815N/A // discovery.
2815N/A G1CMIsAliveClosure _is_alive_closure_cm;
342N/A
2985N/A // Cache used by G1CollectedHeap::start_cset_region_for_worker().
2985N/A HeapRegion** _worker_cset_start_region;
2985N/A
2985N/A // Time stamp to validate the regions recorded in the cache
2985N/A // used by G1CollectedHeap::start_cset_region_for_worker().
2985N/A // The heap region entry for a given worker is valid iff
2985N/A // the associated time stamp value matches the current value
2985N/A // of G1CollectedHeap::_gc_time_stamp.
2985N/A unsigned int* _worker_cset_start_region_time_stamp;
2985N/A
342N/A enum G1H_process_strong_roots_tasks {
3067N/A G1H_PS_filter_satb_buffers,
342N/A G1H_PS_refProcessor_oops_do,
342N/A // Leave this one last.
342N/A G1H_PS_NumElements
342N/A };
342N/A
342N/A SubTasksDone* _process_strong_tasks;
342N/A
2037N/A volatile bool _free_regions_coming;
342N/A
342N/Apublic:
1753N/A
1753N/A SubTasksDone* process_strong_tasks() { return _process_strong_tasks; }
1753N/A
342N/A void set_refine_cte_cl_concurrency(bool concurrent);
342N/A
1629N/A RefToScanQueue *task_queue(int i) const;
342N/A
616N/A // A set of cards where updates happened during the GC
616N/A DirtyCardQueueSet& dirty_card_queue_set() { return _dirty_card_queue_set; }
616N/A
1625N/A // A DirtyCardQueueSet that is used to hold cards that contain
1625N/A // references into the current collection set. This is used to
1625N/A // update the remembered sets of the regions in the collection
1625N/A // set in the event of an evacuation failure.
1625N/A DirtyCardQueueSet& into_cset_dirty_card_queue_set()
1625N/A { return _into_cset_dirty_card_queue_set; }
1625N/A
342N/A // Create a G1CollectedHeap with the specified policy.
342N/A // Must call the initialize method afterwards.
342N/A // May not return if something goes wrong.
342N/A G1CollectedHeap(G1CollectorPolicy* policy);
342N/A
342N/A // Initialize the G1CollectedHeap to have the initial and
342N/A // maximum sizes, permanent generation, and remembered and barrier sets
342N/A // specified by the policy object.
342N/A jint initialize();
342N/A
2815N/A // Initialize weak reference processing.
1944N/A virtual void ref_processing_init();
342N/A
3008N/A void set_par_threads(uint t) {
342N/A SharedHeap::set_par_threads(t);
2941N/A // Done in SharedHeap but oddly there are
2941N/A // two _process_strong_tasks's in a G1CollectedHeap
2941N/A // so do it here too.
2941N/A _process_strong_tasks->set_n_threads(t);
2941N/A }
2941N/A
2941N/A // Set _n_par_threads according to a policy TBD.
2941N/A void set_par_threads();
2941N/A
2941N/A void set_n_termination(int t) {
1753N/A _process_strong_tasks->set_n_threads(t);
342N/A }
342N/A
342N/A virtual CollectedHeap::Name kind() const {
342N/A return CollectedHeap::G1CollectedHeap;
342N/A }
342N/A
342N/A // The current policy object for the collector.
342N/A G1CollectorPolicy* g1_policy() const { return _g1_policy; }
342N/A
342N/A // Adaptive size policy. No such thing for g1.
342N/A virtual AdaptiveSizePolicy* size_policy() { return NULL; }
342N/A
342N/A // The rem set and barrier set.
342N/A G1RemSet* g1_rem_set() const { return _g1_rem_set; }
342N/A ModRefBarrierSet* mr_bs() const { return _mr_bs; }
342N/A
342N/A // The rem set iterator.
342N/A HeapRegionRemSetIterator* rem_set_iterator(int i) {
342N/A return _rem_set_iterator[i];
342N/A }
342N/A
342N/A HeapRegionRemSetIterator* rem_set_iterator() {
342N/A return _rem_set_iterator[0];
342N/A }
342N/A
342N/A unsigned get_gc_time_stamp() {
342N/A return _gc_time_stamp;
342N/A }
342N/A
342N/A void reset_gc_time_stamp() {
342N/A _gc_time_stamp = 0;
353N/A OrderAccess::fence();
2985N/A // Clear the cached CSet starting regions and time stamps.
2985N/A // Their validity is dependent on the GC timestamp.
2985N/A clear_cset_start_regions();
353N/A }
353N/A
3920N/A void check_gc_time_stamps() PRODUCT_RETURN;
3920N/A
353N/A void increment_gc_time_stamp() {
353N/A ++_gc_time_stamp;
353N/A OrderAccess::fence();
342N/A }
342N/A
3920N/A // Reset the given region's GC timestamp. If it's starts humongous,
3920N/A // also reset the GC timestamp of its corresponding
3920N/A // continues humongous regions too.
3920N/A void reset_gc_time_stamps(HeapRegion* hr);
3920N/A
1625N/A void iterate_dirty_card_closure(CardTableEntryClosure* cl,
1625N/A DirtyCardQueue* into_cset_dcq,
1625N/A bool concurrent, int worker_i);
342N/A
342N/A // The shared block offset table array.
342N/A G1BlockOffsetSharedArray* bot_shared() const { return _bot_shared; }
342N/A
2815N/A // Reference Processing accessors
2815N/A
2815N/A // The STW reference processor....
2815N/A ReferenceProcessor* ref_processor_stw() const { return _ref_processor_stw; }
2815N/A
4362N/A // The Concurrent Marking reference processor...
2815N/A ReferenceProcessor* ref_processor_cm() const { return _ref_processor_cm; }
342N/A
4141N/A ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; }
4298N/A G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; }
4141N/A
342N/A virtual size_t capacity() const;
342N/A virtual size_t used() const;
846N/A // This should be called when we're not holding the heap lock. The
846N/A // result might be a bit inaccurate.
846N/A size_t used_unlocked() const;
342N/A size_t recalculate_used() const;
342N/A
342N/A // These virtual functions do the actual allocation.
342N/A // Some heaps may offer a contiguous region for shared non-blocking
342N/A // allocation, via inlined code (by exporting the address of the top and
342N/A // end fields defining the extent of the contiguous allocation region.)
342N/A // But G1CollectedHeap doesn't yet support this.
342N/A
342N/A // Return an estimate of the maximum allocation that could be performed
342N/A // without triggering any collection or expansion activity. In a
342N/A // generational collector, for example, this is probably the largest
342N/A // allocation that could be supported (without expansion) in the youngest
342N/A // generation. It is "unsafe" because no locks are taken; the result
342N/A // should be treated as an approximation, not a guarantee, for use in
342N/A // heuristic resizing decisions.
342N/A virtual size_t unsafe_max_alloc();
342N/A
342N/A virtual bool is_maximal_no_gc() const {
342N/A return _g1_storage.uncommitted_size() == 0;
342N/A }
342N/A
342N/A // The total number of regions in the heap.
3681N/A uint n_regions() { return _hrs.length(); }
2591N/A
2591N/A // The max number of regions in the heap.
3681N/A uint max_regions() { return _hrs.max_length(); }
342N/A
342N/A // The number of regions that are completely free.
3681N/A uint free_regions() { return _free_list.length(); }
342N/A
342N/A // The number of regions that are not completely free.
3681N/A uint used_regions() { return n_regions() - free_regions(); }
342N/A
342N/A // The number of regions available for "regular" expansion.
3681N/A uint expansion_regions() { return _expansion_regions; }
342N/A
2591N/A // Factory method for HeapRegion instances. It will return NULL if
2591N/A // the allocation fails.
3681N/A HeapRegion* new_heap_region(uint hrs_index, HeapWord* bottom);
2591N/A
2414N/A void verify_not_dirty_region(HeapRegion* hr) PRODUCT_RETURN;
2414N/A void verify_dirty_region(HeapRegion* hr) PRODUCT_RETURN;
2280N/A void verify_dirty_young_list(HeapRegion* head) PRODUCT_RETURN;
2280N/A void verify_dirty_young_regions() PRODUCT_RETURN;
2280N/A
2037N/A // verify_region_sets() performs verification over the region
2037N/A // lists. It will be compiled in the product code to be used when
2037N/A // necessary (i.e., during heap verification).
2037N/A void verify_region_sets();
342N/A
2037N/A // verify_region_sets_optional() is planted in the code for
2037N/A // list verification in non-product builds (and it can be enabled in
4419N/A // product builds by defining HEAP_REGION_SET_FORCE_VERIFY to be 1).
2037N/A#if HEAP_REGION_SET_FORCE_VERIFY
2037N/A void verify_region_sets_optional() {
2037N/A verify_region_sets();
2037N/A }
2037N/A#else // HEAP_REGION_SET_FORCE_VERIFY
2037N/A void verify_region_sets_optional() { }
2037N/A#endif // HEAP_REGION_SET_FORCE_VERIFY
342N/A
2037N/A#ifdef ASSERT
2208N/A bool is_on_master_free_list(HeapRegion* hr) {
2037N/A return hr->containing_set() == &_free_list;
2037N/A }
342N/A
2208N/A bool is_in_humongous_set(HeapRegion* hr) {
2037N/A return hr->containing_set() == &_humongous_set;
2208N/A }
2037N/A#endif // ASSERT
342N/A
2037N/A // Wrapper for the region list operations that can be called from
2037N/A // methods outside this class.
342N/A
2037N/A void secondary_free_list_add_as_tail(FreeRegionList* list) {
2037N/A _secondary_free_list.add_as_tail(list);
2037N/A }
342N/A
2037N/A void append_secondary_free_list() {
2279N/A _free_list.add_as_head(&_secondary_free_list);
2037N/A }
342N/A
2208N/A void append_secondary_free_list_if_not_empty_with_lock() {
2208N/A // If the secondary free list looks empty there's no reason to
2208N/A // take the lock and then try to append it.
2037N/A if (!_secondary_free_list.is_empty()) {
2037N/A MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
2037N/A append_secondary_free_list();
2037N/A }
2037N/A }
342N/A
2910N/A void old_set_remove(HeapRegion* hr) {
2910N/A _old_set.remove(hr);
2910N/A }
2910N/A
3112N/A size_t non_young_capacity_bytes() {
3112N/A return _old_set.total_capacity_bytes() + _humongous_set.total_capacity_bytes();
3112N/A }
3112N/A
2037N/A void set_free_regions_coming();
2037N/A void reset_free_regions_coming();
2037N/A bool free_regions_coming() { return _free_regions_coming; }
2037N/A void wait_while_free_regions_coming();
342N/A
3201N/A // Determine whether the given region is one that we are using as an
3201N/A // old GC alloc region.
3201N/A bool is_old_gc_alloc_region(HeapRegion* hr) {
3201N/A return hr == _retained_old_gc_alloc_region;
3201N/A }
3201N/A
342N/A // Perform a collection of the heap; intended for use in implementing
342N/A // "System.gc". This probably implies as full a collection as the
342N/A // "CollectedHeap" supports.
342N/A virtual void collect(GCCause::Cause cause);
342N/A
342N/A // The same as above but assume that the caller holds the Heap_lock.
342N/A void collect_locked(GCCause::Cause cause);
342N/A
342N/A // This interface assumes that it's being called by the
342N/A // vm thread. It collects the heap assuming that the
342N/A // heap lock is already held and that we are executing in
342N/A // the context of the vm thread.
342N/A virtual void collect_as_vm_thread(GCCause::Cause cause);
342N/A
4419N/A // True iff an evacuation has failed in the most-recent collection.
342N/A bool evacuation_failed() { return _evacuation_failed; }
342N/A
2037N/A // It will free a region if it has allocated objects in it that are
2037N/A // all dead. It calls either free_region() or
2037N/A // free_humongous_region() depending on the type of the region that
2037N/A // is passed to it.
2058N/A void free_region_if_empty(HeapRegion* hr,
2058N/A size_t* pre_used,
2058N/A FreeRegionList* free_list,
2910N/A OldRegionSet* old_proxy_set,
2058N/A HumongousRegionSet* humongous_proxy_set,
2058N/A HRRSCleanupTask* hrrs_cleanup_task,
2058N/A bool par);
342N/A
2037N/A // It appends the free list to the master free list and updates the
2037N/A // master humongous list according to the contents of the proxy
2037N/A // list. It also adjusts the total used bytes according to pre_used
2037N/A // (if par is true, it will do so by taking the ParGCRareEvent_lock).
2037N/A void update_sets_after_freeing_regions(size_t pre_used,
2037N/A FreeRegionList* free_list,
2910N/A OldRegionSet* old_proxy_set,
2037N/A HumongousRegionSet* humongous_proxy_set,
2037N/A bool par);
342N/A
2984N/A // Returns "TRUE" iff "p" points into the committed areas of the heap.
342N/A virtual bool is_in(const void* p) const;
342N/A
342N/A // Return "TRUE" iff the given object address is within the collection
342N/A // set.
342N/A inline bool obj_in_cs(oop obj);
342N/A
342N/A // Return "TRUE" iff the given object address is in the reserved
342N/A // region of g1 (excluding the permanent generation).
342N/A bool is_in_g1_reserved(const void* p) const {
342N/A return _g1_reserved.contains(p);
342N/A }
342N/A
2282N/A // Returns a MemRegion that corresponds to the space that has been
2282N/A // reserved for the heap
2282N/A MemRegion g1_reserved() {
2282N/A return _g1_reserved;
2282N/A }
2282N/A
2282N/A // Returns a MemRegion that corresponds to the space that has been
342N/A // committed in the heap
342N/A MemRegion g1_committed() {
342N/A return _g1_committed;
342N/A }
342N/A
2158N/A virtual bool is_in_closed_subset(const void* p) const;
342N/A
342N/A // This resets the card table to all zeros. It is used after
342N/A // a collection pause which used the card table to claim cards.
342N/A void cleanUpCardTable();
342N/A
342N/A // Iteration functions.
342N/A
342N/A // Iterate over all the ref-containing fields of all objects, calling
342N/A // "cl.do_oop" on each.
678N/A virtual void oop_iterate(OopClosure* cl) {
678N/A oop_iterate(cl, true);
678N/A }
678N/A void oop_iterate(OopClosure* cl, bool do_perm);
342N/A
342N/A // Same as above, restricted to a memory region.
678N/A virtual void oop_iterate(MemRegion mr, OopClosure* cl) {
678N/A oop_iterate(mr, cl, true);
678N/A }
678N/A void oop_iterate(MemRegion mr, OopClosure* cl, bool do_perm);
342N/A
342N/A // Iterate over all objects, calling "cl.do_object" on each.
678N/A virtual void object_iterate(ObjectClosure* cl) {
678N/A object_iterate(cl, true);
678N/A }
678N/A virtual void safe_object_iterate(ObjectClosure* cl) {
678N/A object_iterate(cl, true);
678N/A }
678N/A void object_iterate(ObjectClosure* cl, bool do_perm);
342N/A
342N/A // Iterate over all objects allocated since the last collection, calling
342N/A // "cl.do_object" on each. The heap must have been initialized properly
342N/A // to support this function, or else this call will fail.
342N/A virtual void object_iterate_since_last_GC(ObjectClosure* cl);
342N/A
342N/A // Iterate over all spaces in use in the heap, in ascending address order.
342N/A virtual void space_iterate(SpaceClosure* cl);
342N/A
342N/A // Iterate over heap regions, in address order, terminating the
342N/A // iteration early if the "doHeapRegion" method returns "true".
2591N/A void heap_region_iterate(HeapRegionClosure* blk) const;
342N/A
2591N/A // Return the region with the given index. It assumes the index is valid.
3681N/A HeapRegion* region_at(uint index) const { return _hrs.at(index); }
342N/A
342N/A // Divide the heap region sequence into "chunks" of some size (the number
342N/A // of regions divided by the number of parallel threads times some
342N/A // overpartition factor, currently 4). Assumes that this will be called
342N/A // in parallel by ParallelGCThreads worker threads with discinct worker
342N/A // ids in the range [0..max(ParallelGCThreads-1, 1)], that all parallel
342N/A // calls will use the same "claim_value", and that that claim value is
342N/A // different from the claim_value of any heap region before the start of
342N/A // the iteration. Applies "blk->doHeapRegion" to each of the regions, by
342N/A // attempting to claim the first region in each chunk, and, if
342N/A // successful, applying the closure to each region in the chunk (and
342N/A // setting the claim value of the second and subsequent regions of the
342N/A // chunk.) For now requires that "doHeapRegion" always returns "false",
342N/A // i.e., that a closure never attempt to abort a traversal.
342N/A void heap_region_par_iterate_chunked(HeapRegionClosure* blk,
3008N/A uint worker,
3008N/A uint no_of_par_workers,
342N/A jint claim_value);
342N/A
390N/A // It resets all the region claim values to the default.
390N/A void reset_heap_region_claim_values();
390N/A
3063N/A // Resets the claim values of regions in the current
3063N/A // collection set to the default.
3063N/A void reset_cset_heap_region_claim_values();
3063N/A
355N/A#ifdef ASSERT
355N/A bool check_heap_region_claim_values(jint claim_value);
2943N/A
2943N/A // Same as the routine above but only checks regions in the
2943N/A // current collection set.
2943N/A bool check_cset_heap_region_claim_values(jint claim_value);
355N/A#endif // ASSERT
355N/A
2985N/A // Clear the cached cset start regions and (more importantly)
2985N/A // the time stamps. Called when we reset the GC time stamp.
2985N/A void clear_cset_start_regions();
2985N/A
2985N/A // Given the id of a worker, obtain or calculate a suitable
2985N/A // starting region for iterating over the current collection set.
2943N/A HeapRegion* start_cset_region_for_worker(int worker_i);
2943N/A
3920N/A // This is a convenience method that is used by the
3920N/A // HeapRegionIterator classes to calculate the starting region for
3920N/A // each worker so that they do not all start from the same region.
3920N/A HeapRegion* start_region_for_worker(uint worker_i, uint no_of_par_workers);
3920N/A
342N/A // Iterate over the regions (if any) in the current collection set.
342N/A void collection_set_iterate(HeapRegionClosure* blk);
342N/A
342N/A // As above but starting from region r
342N/A void collection_set_iterate_from(HeapRegion* r, HeapRegionClosure *blk);
342N/A
342N/A // Returns the first (lowest address) compactible space in the heap.
342N/A virtual CompactibleSpace* first_compactible_space();
342N/A
342N/A // A CollectedHeap will contain some number of spaces. This finds the
342N/A // space containing a given address, or else returns NULL.
342N/A virtual Space* space_containing(const void* addr) const;
342N/A
342N/A // A G1CollectedHeap will contain some number of heap regions. This
342N/A // finds the region containing a given address, or else returns NULL.
2591N/A template <class T>
2591N/A inline HeapRegion* heap_region_containing(const T addr) const;
342N/A
342N/A // Like the above, but requires "addr" to be in the heap (to avoid a
342N/A // null-check), and unlike the above, may return an continuing humongous
342N/A // region.
2591N/A template <class T>
2591N/A inline HeapRegion* heap_region_containing_raw(const T addr) const;
342N/A
342N/A // A CollectedHeap is divided into a dense sequence of "blocks"; that is,
342N/A // each address in the (reserved) heap is a member of exactly
342N/A // one block. The defining characteristic of a block is that it is
342N/A // possible to find its size, and thus to progress forward to the next
342N/A // block. (Blocks may be of different sizes.) Thus, blocks may
342N/A // represent Java objects, or they might be free blocks in a
342N/A // free-list-based heap (or subheap), as long as the two kinds are
342N/A // distinguishable and the size of each is determinable.
342N/A
342N/A // Returns the address of the start of the "block" that contains the
342N/A // address "addr". We say "blocks" instead of "object" since some heaps
342N/A // may not pack objects densely; a chunk may either be an object or a
342N/A // non-object.
342N/A virtual HeapWord* block_start(const void* addr) const;
342N/A
342N/A // Requires "addr" to be the start of a chunk, and returns its size.
342N/A // "addr + size" is required to be the start of a new chunk, or the end
342N/A // of the active area of the heap.
342N/A virtual size_t block_size(const HeapWord* addr) const;
342N/A
342N/A // Requires "addr" to be the start of a block, and returns "TRUE" iff
342N/A // the block is an object.
342N/A virtual bool block_is_obj(const HeapWord* addr) const;
342N/A
342N/A // Does this heap support heap inspection? (+PrintClassHistogram)
342N/A virtual bool supports_heap_inspection() const { return true; }
342N/A
342N/A // Section on thread-local allocation buffers (TLABs)
342N/A // See CollectedHeap for semantics.
342N/A
342N/A virtual bool supports_tlab_allocation() const;
342N/A virtual size_t tlab_capacity(Thread* thr) const;
342N/A virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
342N/A
342N/A // Can a compiler initialize a new object without store barriers?
342N/A // This permission only extends from the creation of a new object
1027N/A // via a TLAB up to the first subsequent safepoint. If such permission
1027N/A // is granted for this heap type, the compiler promises to call
1027N/A // defer_store_barrier() below on any slow path allocation of
1027N/A // a new object for which such initializing store barriers will
1027N/A // have been elided. G1, like CMS, allows this, but should be
1027N/A // ready to provide a compensating write barrier as necessary
1027N/A // if that storage came out of a non-young region. The efficiency
1027N/A // of this implementation depends crucially on being able to
1027N/A // answer very efficiently in constant time whether a piece of
1027N/A // storage in the heap comes from a young region or not.
1027N/A // See ReduceInitialCardMarks.
342N/A virtual bool can_elide_tlab_store_barriers() const {
2824N/A return true;
1027N/A }
1027N/A
1166N/A virtual bool card_mark_must_follow_store() const {
1166N/A return true;
1166N/A }
1166N/A
2591N/A bool is_in_young(const oop obj) {
1027N/A HeapRegion* hr = heap_region_containing(obj);
1027N/A return hr != NULL && hr->is_young();
1027N/A }
1027N/A
2474N/A#ifdef ASSERT
2474N/A virtual bool is_in_partial_collection(const void* p);
2474N/A#endif
2474N/A
2474N/A virtual bool is_scavengable(const void* addr);
2474N/A
1027N/A // We don't need barriers for initializing stores to objects
1027N/A // in the young gen: for the SATB pre-barrier, there is no
1027N/A // pre-value that needs to be remembered; for the remembered-set
1027N/A // update logging post-barrier, we don't maintain remembered set
2695N/A // information for young gen objects.
1027N/A virtual bool can_elide_initializing_store_barrier(oop new_obj) {
1027N/A return is_in_young(new_obj);
342N/A }
342N/A
342N/A // Can a compiler elide a store barrier when it writes
342N/A // a permanent oop into the heap? Applies when the compiler
342N/A // is storing x to the heap, where x->is_perm() is true.
342N/A virtual bool can_elide_permanent_oop_store_barriers() const {
342N/A // At least until perm gen collection is also G1-ified, at
342N/A // which point this should return false.
342N/A return true;
342N/A }
342N/A
342N/A // Returns "true" iff the given word_size is "very large".
342N/A static bool isHumongous(size_t word_size) {
1313N/A // Note this has to be strictly greater-than as the TLABs
1313N/A // are capped at the humongous thresold and we want to
1313N/A // ensure that we don't try to allocate a TLAB as
1313N/A // humongous and that we don't allocate a humongous
1313N/A // object in a TLAB.
1313N/A return word_size > _humongous_object_threshold_in_words;
342N/A }
342N/A
342N/A // Update mod union table with the set of dirty cards.
342N/A void updateModUnion();
342N/A
342N/A // Set the mod union bits corresponding to the given memRegion. Note
342N/A // that this is always a safe operation, since it doesn't clear any
342N/A // bits.
342N/A void markModUnionRange(MemRegion mr);
342N/A
342N/A // Records the fact that a marking phase is no longer in progress.
342N/A void set_marking_complete() {
342N/A _mark_in_progress = false;
342N/A }
342N/A void set_marking_started() {
342N/A _mark_in_progress = true;
342N/A }
342N/A bool mark_in_progress() {
342N/A return _mark_in_progress;
342N/A }
342N/A
342N/A // Print the maximum heap capacity.
342N/A virtual size_t max_capacity() const;
342N/A
342N/A virtual jlong millis_since_last_gc();
342N/A
342N/A // Perform any cleanup actions necessary before allowing a verification.
342N/A virtual void prepare_for_verify();
342N/A
342N/A // Perform verification.
811N/A
2597N/A // vo == UsePrevMarking -> use "prev" marking information,
2597N/A // vo == UseNextMarking -> use "next" marking information
2597N/A // vo == UseMarkWord -> use the mark word in the object header
2597N/A //
811N/A // NOTE: Only the "prev" marking information is guaranteed to be
811N/A // consistent most of the time, so most calls to this should use
2597N/A // vo == UsePrevMarking.
2597N/A // Currently, there is only one case where this is called with
2597N/A // vo == UseNextMarking, which is to verify the "next" marking
2597N/A // information at the end of remark.
2597N/A // Currently there is only one place where this is called with
2597N/A // vo == UseMarkWord, which is to verify the marking during a
2597N/A // full GC.
3679N/A void verify(bool silent, VerifyOption vo);
811N/A
811N/A // Override; it uses the "prev" marking information
3679N/A virtual void verify(bool silent);
4141N/A
342N/A virtual void print_on(outputStream* st) const;
2911N/A virtual void print_extended_on(outputStream* st) const;
342N/A
342N/A virtual void print_gc_threads_on(outputStream* st) const;
342N/A virtual void gc_threads_do(ThreadClosure* tc) const;
342N/A
342N/A // Override
342N/A void print_tracing_info() const;
342N/A
2602N/A // The following two methods are helpful for debugging RSet issues.
2602N/A void print_cset_rsets() PRODUCT_RETURN;
2602N/A void print_all_rsets() PRODUCT_RETURN;
2602N/A
342N/A // Convenience function to be used in situations where the heap type can be
342N/A // asserted to be this type.
342N/A static G1CollectedHeap* heap();
342N/A
342N/A void set_region_short_lived_locked(HeapRegion* hr);
342N/A // add appropriate methods for any other surv rate groups
342N/A
1394N/A YoungList* young_list() { return _young_list; }
342N/A
342N/A // debugging
342N/A bool check_young_list_well_formed() {
342N/A return _young_list->check_list_well_formed();
342N/A }
1394N/A
1394N/A bool check_young_list_empty(bool check_heap,
342N/A bool check_sample = true);
342N/A
342N/A // *** Stuff related to concurrent marking. It's not clear to me that so
342N/A // many of these need to be public.
342N/A
342N/A // The functions below are helper functions that a subclass of
342N/A // "CollectedHeap" can use in the implementation of its virtual
342N/A // functions.
342N/A // This performs a concurrent marking of the live objects in a
342N/A // bitmap off to the side.
342N/A void doConcurrentMark();
342N/A
342N/A bool isMarkedPrev(oop obj) const;
342N/A bool isMarkedNext(oop obj) const;
342N/A
342N/A // Determine if an object is dead, given the object and also
342N/A // the region to which the object belongs. An object is dead
342N/A // iff a) it was not allocated since the last mark and b) it
342N/A // is not marked.
342N/A
342N/A bool is_obj_dead(const oop obj, const HeapRegion* hr) const {
342N/A return
342N/A !hr->obj_allocated_since_prev_marking(obj) &&
342N/A !isMarkedPrev(obj);
342N/A }
342N/A
342N/A // This function returns true when an object has been
342N/A // around since the previous marking and hasn't yet
342N/A // been marked during this marking.
342N/A
342N/A bool is_obj_ill(const oop obj, const HeapRegion* hr) const {
342N/A return
342N/A !hr->obj_allocated_since_next_marking(obj) &&
342N/A !isMarkedNext(obj);
342N/A }
342N/A
342N/A // Determine if an object is dead, given only the object itself.
342N/A // This will find the region to which the object belongs and
342N/A // then call the region version of the same function.
342N/A
342N/A // Added if it is in permanent gen it isn't dead.
342N/A // Added if it is NULL it isn't dead.
342N/A
2597N/A bool is_obj_dead(const oop obj) const {
811N/A const HeapRegion* hr = heap_region_containing(obj);
342N/A if (hr == NULL) {
342N/A if (Universe::heap()->is_in_permanent(obj))
342N/A return false;
342N/A else if (obj == NULL) return false;
342N/A else return true;
342N/A }
342N/A else return is_obj_dead(obj, hr);
342N/A }
342N/A
2597N/A bool is_obj_ill(const oop obj) const {
811N/A const HeapRegion* hr = heap_region_containing(obj);
342N/A if (hr == NULL) {
342N/A if (Universe::heap()->is_in_permanent(obj))
342N/A return false;
342N/A else if (obj == NULL) return false;
342N/A else return true;
342N/A }
342N/A else return is_obj_ill(obj, hr);
342N/A }
342N/A
3920N/A // The methods below are here for convenience and dispatch the
3920N/A // appropriate method depending on value of the given VerifyOption
3920N/A // parameter. The options for that parameter are:
3920N/A //
3920N/A // vo == UsePrevMarking -> use "prev" marking information,
3920N/A // vo == UseNextMarking -> use "next" marking information,
3920N/A // vo == UseMarkWord -> use mark word from object header
3920N/A
3920N/A bool is_obj_dead_cond(const oop obj,
3920N/A const HeapRegion* hr,
3920N/A const VerifyOption vo) const {
3920N/A switch (vo) {
3920N/A case VerifyOption_G1UsePrevMarking: return is_obj_dead(obj, hr);
3920N/A case VerifyOption_G1UseNextMarking: return is_obj_ill(obj, hr);
3920N/A case VerifyOption_G1UseMarkWord: return !obj->is_gc_marked();
3920N/A default: ShouldNotReachHere();
3920N/A }
3920N/A return false; // keep some compilers happy
3920N/A }
3920N/A
3920N/A bool is_obj_dead_cond(const oop obj,
3920N/A const VerifyOption vo) const {
3920N/A switch (vo) {
3920N/A case VerifyOption_G1UsePrevMarking: return is_obj_dead(obj);
3920N/A case VerifyOption_G1UseNextMarking: return is_obj_ill(obj);
3920N/A case VerifyOption_G1UseMarkWord: return !obj->is_gc_marked();
3920N/A default: ShouldNotReachHere();
3920N/A }
3920N/A return false; // keep some compilers happy
3920N/A }
3920N/A
3920N/A bool allocated_since_marking(oop obj, HeapRegion* hr, VerifyOption vo);
3920N/A HeapWord* top_at_mark_start(HeapRegion* hr, VerifyOption vo);
3920N/A bool is_marked(oop obj, VerifyOption vo);
3920N/A const char* top_at_mark_start_str(VerifyOption vo);
3920N/A
342N/A // The following is just to alert the verification code
342N/A // that a full collection has occurred and that the
342N/A // remembered sets are no longer up to date.
342N/A bool _full_collection;
342N/A void set_full_collection() { _full_collection = true;}
342N/A void clear_full_collection() {_full_collection = false;}
342N/A bool full_collection() {return _full_collection;}
342N/A
342N/A ConcurrentMark* concurrent_mark() const { return _cm; }
342N/A ConcurrentG1Refine* concurrent_g1_refine() const { return _cg1r; }
342N/A
796N/A // The dirty cards region list is used to record a subset of regions
796N/A // whose cards need clearing. The list if populated during the
796N/A // remembered set scanning and drained during the card table
796N/A // cleanup. Although the methods are reentrant, population/draining
796N/A // phases must not overlap. For synchronization purposes the last
796N/A // element on the list points to itself.
796N/A HeapRegion* _dirty_cards_region_list;
796N/A void push_dirty_cards_region(HeapRegion* hr);
796N/A HeapRegion* pop_dirty_cards_region();
796N/A
342N/Apublic:
342N/A void stop_conc_gc_threads();
342N/A
342N/A size_t pending_card_num();
342N/A size_t cards_scanned();
342N/A
342N/Aprotected:
342N/A size_t _max_heap_capacity;
342N/A};
342N/A
845N/Aclass G1ParGCAllocBuffer: public ParGCAllocBuffer {
845N/Aprivate:
845N/A bool _retired;
845N/A
845N/Apublic:
2720N/A G1ParGCAllocBuffer(size_t gclab_word_size);
845N/A
3067N/A void set_buf(HeapWord* buf) {
845N/A ParGCAllocBuffer::set_buf(buf);
845N/A _retired = false;
845N/A }
845N/A
3067N/A void retire(bool end_of_gc, bool retain) {
845N/A if (_retired)
845N/A return;
845N/A ParGCAllocBuffer::retire(end_of_gc, retain);
845N/A _retired = true;
845N/A }
845N/A};
845N/A
845N/Aclass G1ParScanThreadState : public StackObj {
845N/Aprotected:
845N/A G1CollectedHeap* _g1h;
845N/A RefToScanQueue* _refs;
845N/A DirtyCardQueue _dcq;
845N/A CardTableModRefBS* _ct_bs;
845N/A G1RemSet* _g1_rem;
845N/A
1391N/A G1ParGCAllocBuffer _surviving_alloc_buffer;
1391N/A G1ParGCAllocBuffer _tenured_alloc_buffer;
1391N/A G1ParGCAllocBuffer* _alloc_buffers[GCAllocPurposeCount];
1391N/A ageTable _age_table;
845N/A
845N/A size_t _alloc_buffer_waste;
845N/A size_t _undo_waste;
845N/A
845N/A OopsInHeapRegionClosure* _evac_failure_cl;
845N/A G1ParScanHeapEvacClosure* _evac_cl;
845N/A G1ParScanPartialArrayClosure* _partial_scan_cl;
845N/A
4419N/A int _hash_seed;
3119N/A uint _queue_num;
845N/A
1531N/A size_t _term_attempts;
845N/A
845N/A double _start;
845N/A double _start_strong_roots;
845N/A double _strong_roots_time;
845N/A double _start_term;
845N/A double _term_time;
845N/A
845N/A // Map from young-age-index (0 == not young, 1 is youngest) to
845N/A // surviving words. base is what we get back from the malloc call
845N/A size_t* _surviving_young_words_base;
845N/A // this points into the array, as we use the first few entries for padding
845N/A size_t* _surviving_young_words;
845N/A
1629N/A#define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t))
845N/A
845N/A void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; }
845N/A
845N/A void add_to_undo_waste(size_t waste) { _undo_waste += waste; }
845N/A
845N/A DirtyCardQueue& dirty_card_queue() { return _dcq; }
845N/A CardTableModRefBS* ctbs() { return _ct_bs; }
845N/A
845N/A template <class T> void immediate_rs_update(HeapRegion* from, T* p, int tid) {
845N/A if (!from->is_survivor()) {
845N/A _g1_rem->par_write_ref(from, p, tid);
845N/A }
845N/A }
845N/A
845N/A template <class T> void deferred_rs_update(HeapRegion* from, T* p, int tid) {
845N/A // If the new value of the field points to the same region or
845N/A // is the to-space, we don't need to include it in the Rset updates.
845N/A if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) {
845N/A size_t card_index = ctbs()->index_for(p);
845N/A // If the card hasn't been added to the buffer, do it.
845N/A if (ctbs()->mark_card_deferred(card_index)) {
845N/A dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index));
845N/A }
845N/A }
845N/A }
845N/A
845N/Apublic:
3119N/A G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num);
845N/A
845N/A ~G1ParScanThreadState() {
3863N/A FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_base, mtGC);
845N/A }
845N/A
845N/A RefToScanQueue* refs() { return _refs; }
845N/A ageTable* age_table() { return &_age_table; }
845N/A
845N/A G1ParGCAllocBuffer* alloc_buffer(GCAllocPurpose purpose) {
1391N/A return _alloc_buffers[purpose];
845N/A }
845N/A
1629N/A size_t alloc_buffer_waste() const { return _alloc_buffer_waste; }
1629N/A size_t undo_waste() const { return _undo_waste; }
845N/A
1782N/A#ifdef ASSERT
1782N/A bool verify_ref(narrowOop* ref) const;
1782N/A bool verify_ref(oop* ref) const;
1782N/A bool verify_task(StarTask ref) const;
1782N/A#endif // ASSERT
1782N/A
845N/A template <class T> void push_on_queue(T* ref) {
1782N/A assert(verify_ref(ref), "sanity");
1629N/A refs()->push(ref);
845N/A }
845N/A
845N/A template <class T> void update_rs(HeapRegion* from, T* p, int tid) {
845N/A if (G1DeferredRSUpdate) {
845N/A deferred_rs_update(from, p, tid);
845N/A } else {
845N/A immediate_rs_update(from, p, tid);
845N/A }
845N/A }
845N/A
845N/A HeapWord* allocate_slow(GCAllocPurpose purpose, size_t word_sz) {
845N/A HeapWord* obj = NULL;
1391N/A size_t gclab_word_size = _g1h->desired_plab_sz(purpose);
1391N/A if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) {
845N/A G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose);
845N/A add_to_alloc_buffer_waste(alloc_buf->words_remaining());
4006N/A alloc_buf->retire(false /* end_of_gc */, false /* retain */);
845N/A
1391N/A HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size);
845N/A if (buf == NULL) return NULL; // Let caller handle allocation failure.
845N/A // Otherwise.
3945N/A alloc_buf->set_word_size(gclab_word_size);
845N/A alloc_buf->set_buf(buf);
845N/A
845N/A obj = alloc_buf->allocate(word_sz);
845N/A assert(obj != NULL, "buffer was definitely big enough...");
845N/A } else {
845N/A obj = _g1h->par_allocate_during_gc(purpose, word_sz);
845N/A }
845N/A return obj;
845N/A }
845N/A
845N/A HeapWord* allocate(GCAllocPurpose purpose, size_t word_sz) {
845N/A HeapWord* obj = alloc_buffer(purpose)->allocate(word_sz);
845N/A if (obj != NULL) return obj;
845N/A return allocate_slow(purpose, word_sz);
845N/A }
845N/A
845N/A void undo_allocation(GCAllocPurpose purpose, HeapWord* obj, size_t word_sz) {
845N/A if (alloc_buffer(purpose)->contains(obj)) {
845N/A assert(alloc_buffer(purpose)->contains(obj + word_sz - 1),
845N/A "should contain whole object");
845N/A alloc_buffer(purpose)->undo_allocation(obj, word_sz);
845N/A } else {
845N/A CollectedHeap::fill_with_object(obj, word_sz);
845N/A add_to_undo_waste(word_sz);
845N/A }
845N/A }
845N/A
845N/A void set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_cl) {
845N/A _evac_failure_cl = evac_failure_cl;
845N/A }
845N/A OopsInHeapRegionClosure* evac_failure_closure() {
845N/A return _evac_failure_cl;
845N/A }
845N/A
845N/A void set_evac_closure(G1ParScanHeapEvacClosure* evac_cl) {
845N/A _evac_cl = evac_cl;
845N/A }
845N/A
845N/A void set_partial_scan_closure(G1ParScanPartialArrayClosure* partial_scan_cl) {
845N/A _partial_scan_cl = partial_scan_cl;
845N/A }
845N/A
845N/A int* hash_seed() { return &_hash_seed; }
3119N/A uint queue_num() { return _queue_num; }
845N/A
1629N/A size_t term_attempts() const { return _term_attempts; }
1531N/A void note_term_attempt() { _term_attempts++; }
845N/A
845N/A void start_strong_roots() {
845N/A _start_strong_roots = os::elapsedTime();
845N/A }
845N/A void end_strong_roots() {
845N/A _strong_roots_time += (os::elapsedTime() - _start_strong_roots);
845N/A }
1629N/A double strong_roots_time() const { return _strong_roots_time; }
845N/A
845N/A void start_term_time() {
845N/A note_term_attempt();
845N/A _start_term = os::elapsedTime();
845N/A }
845N/A void end_term_time() {
845N/A _term_time += (os::elapsedTime() - _start_term);
845N/A }
1629N/A double term_time() const { return _term_time; }
845N/A
1629N/A double elapsed_time() const {
845N/A return os::elapsedTime() - _start;
845N/A }
845N/A
1629N/A static void
1629N/A print_termination_stats_hdr(outputStream* const st = gclog_or_tty);
1629N/A void
1629N/A print_termination_stats(int i, outputStream* const st = gclog_or_tty) const;
1629N/A
845N/A size_t* surviving_young_words() {
845N/A // We add on to hide entry 0 which accumulates surviving words for
845N/A // age -1 regions (i.e. non-young ones)
845N/A return _surviving_young_words;
845N/A }
845N/A
845N/A void retire_alloc_buffers() {
845N/A for (int ap = 0; ap < GCAllocPurposeCount; ++ap) {
1391N/A size_t waste = _alloc_buffers[ap]->words_remaining();
845N/A add_to_alloc_buffer_waste(waste);
3945N/A _alloc_buffers[ap]->flush_stats_and_retire(_g1h->stats_for_purpose((GCAllocPurpose)ap),
3945N/A true /* end_of_gc */,
3945N/A false /* retain */);
845N/A }
845N/A }
845N/A
845N/A template <class T> void deal_with_reference(T* ref_to_scan) {
845N/A if (has_partial_array_mask(ref_to_scan)) {
845N/A _partial_scan_cl->do_oop_nv(ref_to_scan);
845N/A } else {
845N/A // Note: we can use "raw" versions of "region_containing" because
845N/A // "obj_to_scan" is definitely in the heap, and is not in a
845N/A // humongous region.
845N/A HeapRegion* r = _g1h->heap_region_containing_raw(ref_to_scan);
845N/A _evac_cl->set_region(r);
845N/A _evac_cl->do_oop_nv(ref_to_scan);
845N/A }
845N/A }
845N/A
1782N/A void deal_with_reference(StarTask ref) {
1782N/A assert(verify_task(ref), "sanity");
1782N/A if (ref.is_narrow()) {
1782N/A deal_with_reference((narrowOop*)ref);
1782N/A } else {
1782N/A deal_with_reference((oop*)ref);
845N/A }
845N/A }
1782N/A
1782N/A void trim_queue();
845N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP