diff -r 8ec8971f511a -r 227a9e5e4b4a src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Thu Sep 04 16:53:27 2014 -0700 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Fri Sep 05 09:49:19 2014 +0200 @@ -25,6 +25,8 @@ #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP #define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP +#include "gc_implementation/g1/g1AllocationContext.hpp" +#include "gc_implementation/g1/g1Allocator.hpp" #include "gc_implementation/g1/concurrentMark.hpp" #include "gc_implementation/g1/evacuationInfo.hpp" #include "gc_implementation/g1/g1AllocRegion.hpp" @@ -80,12 +82,6 @@ typedef int RegionIdx_t; // needs to hold [ 0..max_regions() ) typedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion ) -enum GCAllocPurpose { - GCAllocForTenured, - GCAllocForSurvived, - GCAllocPurposeCount -}; - class YoungList : public CHeapObj { private: G1CollectedHeap* _g1h; @@ -158,40 +154,6 @@ void print(); }; -class MutatorAllocRegion : public G1AllocRegion { -protected: - virtual HeapRegion* allocate_new_region(size_t word_size, bool force); - virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes); -public: - MutatorAllocRegion() - : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { } -}; - -class SurvivorGCAllocRegion : public G1AllocRegion { -protected: - virtual HeapRegion* allocate_new_region(size_t word_size, bool force); - virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes); -public: - SurvivorGCAllocRegion() - : G1AllocRegion("Survivor GC Alloc Region", false /* bot_updates */) { } -}; - -class OldGCAllocRegion : public G1AllocRegion { -protected: - virtual HeapRegion* allocate_new_region(size_t word_size, bool force); - virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes); -public: - OldGCAllocRegion() - : G1AllocRegion("Old GC Alloc Region", true /* bot_updates */) { } - - // This specialization of release() makes sure that the last card that has been - // allocated into has been completely filled by a dummy object. - // This avoids races when remembered set scanning wants to update the BOT of the - // last card in the retained old gc alloc region, and allocation threads - // allocating into that card at the same time. - virtual HeapRegion* release(); -}; - // 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 @@ -222,6 +184,9 @@ friend class MutatorAllocRegion; friend class SurvivorGCAllocRegion; friend class OldGCAllocRegion; + friend class G1Allocator; + friend class G1DefaultAllocator; + friend class G1ResManAllocator; // Closures used in implementation. template @@ -232,6 +197,8 @@ friend class G1ParScanClosureSuper; friend class G1ParEvacuateFollowersClosure; friend class G1ParTask; + friend class G1ParGCAllocator; + friend class G1DefaultParGCAllocator; friend class G1FreeGarbageRegionClosure; friend class RefineCardTableEntryClosure; friend class G1PrepareCompactClosure; @@ -293,44 +260,15 @@ // The sequence of all heap regions in the heap. HeapRegionManager _hrm; - // Alloc region used to satisfy mutator allocation requests. - MutatorAllocRegion _mutator_alloc_region; - - // Alloc region used to satisfy allocation requests by the GC for - // survivor objects. - SurvivorGCAllocRegion _survivor_gc_alloc_region; + // Class that handles the different kinds of allocations. + G1Allocator* _allocator; // PLAB sizing policy for survivors. PLABStats _survivor_plab_stats; - // Alloc region used to satisfy allocation requests by the GC for - // old objects. - OldGCAllocRegion _old_gc_alloc_region; - // PLAB sizing policy for tenured objects. PLABStats _old_plab_stats; - PLABStats* stats_for_purpose(GCAllocPurpose purpose) { - PLABStats* stats = NULL; - - switch (purpose) { - case GCAllocForSurvived: - stats = &_survivor_plab_stats; - 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. - HeapRegion* _retained_old_gc_alloc_region; - // 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 @@ -348,9 +286,6 @@ // It initializes the GC alloc regions at the start of a GC. void init_gc_alloc_regions(EvacuationInfo& evacuation_info); - // Setup the retained old gc alloc region as the currrent old gc alloc region. - void use_retained_old_gc_alloc_region(EvacuationInfo& evacuation_info); - // It releases the GC alloc regions at the end of a GC. void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info); @@ -361,13 +296,6 @@ // Helper for monitoring and management support. G1MonitoringSupport* _g1mm; - // Determines PLAB size for a particular allocation purpose. - size_t desired_plab_sz(GCAllocPurpose purpose); - - // Outside of GC pauses, the number of bytes used in all regions other - // than the current allocation region. - size_t _summary_bytes_used; - // Records whether the region at the given index is kept live by roots or // references from the young generation. class HumongousIsLiveBiasedMappedArray : public G1BiasedMappedArray { @@ -525,11 +453,12 @@ // humongous region. HeapWord* humongous_obj_allocate_initialize_regions(uint first, uint num_regions, - size_t word_size); + size_t word_size, + AllocationContext_t context); // Attempt to allocate a humongous object of the given size. Return // NULL if unsuccessful. - HeapWord* humongous_obj_allocate(size_t word_size); + HeapWord* humongous_obj_allocate(size_t word_size, AllocationContext_t context); // The following two methods, allocate_new_tlab() and // mem_allocate(), are the two main entry points from the runtime @@ -585,6 +514,7 @@ // retry the allocation attempt, potentially scheduling a GC // pause. This should only be used for non-humongous allocations. HeapWord* attempt_allocation_slow(size_t word_size, + AllocationContext_t context, unsigned int* gc_count_before_ret, int* gclocker_retry_count_ret); @@ -599,7 +529,8 @@ // specifies whether the mutator alloc region is expected to be NULL // or not. HeapWord* attempt_allocation_at_safepoint(size_t word_size, - bool expect_null_mutator_alloc_region); + AllocationContext_t context, + bool expect_null_mutator_alloc_region); // It dirties the cards that cover the block so that so that the post // write barrier never queues anything when updating objects on this @@ -611,7 +542,9 @@ // 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. - HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, size_t word_size); + HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, + size_t word_size, + AllocationContext_t context); HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose, HeapRegion* alloc_region, @@ -623,10 +556,12 @@ void par_allocate_remaining_space(HeapRegion* r); // Allocation attempt during GC for a survivor object / PLAB. - inline HeapWord* survivor_attempt_allocation(size_t word_size); + inline HeapWord* survivor_attempt_allocation(size_t word_size, + AllocationContext_t context); // Allocation attempt during GC for an old object / PLAB. - inline HeapWord* old_attempt_allocation(size_t word_size); + inline HeapWord* old_attempt_allocation(size_t word_size, + AllocationContext_t context); // These methods are the "callbacks" from the G1AllocRegion class. @@ -665,13 +600,15 @@ // Callback from VM_G1CollectForAllocation operation. // This function does everything necessary/possible to satisfy a // failed allocation request (including collection, expansion, etc.) - HeapWord* satisfy_failed_allocation(size_t word_size, bool* succeeded); + HeapWord* satisfy_failed_allocation(size_t word_size, + AllocationContext_t context, + bool* succeeded); // 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". - HeapWord* expand_and_allocate(size_t word_size); + HeapWord* expand_and_allocate(size_t word_size, AllocationContext_t context); // Process any reference objects discovered during // an incremental evacuation pause. @@ -694,6 +631,27 @@ // (Rounds up to a HeapRegion boundary.) bool expand(size_t expand_bytes); + // Returns the PLAB statistics given a purpose. + PLABStats* stats_for_purpose(GCAllocPurpose purpose) { + PLABStats* stats = NULL; + + switch (purpose) { + case GCAllocForSurvived: + stats = &_survivor_plab_stats; + break; + case GCAllocForTenured: + stats = &_old_plab_stats; + break; + default: + assert(false, "unrecognized GCAllocPurpose"); + } + + return stats; + } + + // Determines PLAB size for a particular allocation purpose. + size_t desired_plab_sz(GCAllocPurpose purpose); + // Do anything common to GC's. virtual void gc_prologue(bool full); virtual void gc_epilogue(bool full); @@ -1271,7 +1229,7 @@ // Determine whether the given region is one that we are using as an // old GC alloc region. bool is_old_gc_alloc_region(HeapRegion* hr) { - return hr == _retained_old_gc_alloc_region; + return _allocator->is_retained_old_region(hr); } // Perform a collection of the heap; intended for use in implementing @@ -1752,28 +1710,4 @@ size_t _max_heap_capacity; }; -class G1ParGCAllocBuffer: public ParGCAllocBuffer { -private: - bool _retired; - -public: - G1ParGCAllocBuffer(size_t gclab_word_size); - virtual ~G1ParGCAllocBuffer() { - guarantee(_retired, "Allocation buffer has not been retired"); - } - - virtual void set_buf(HeapWord* buf) { - ParGCAllocBuffer::set_buf(buf); - _retired = false; - } - - virtual void retire(bool end_of_gc, bool retain) { - if (_retired) { - return; - } - ParGCAllocBuffer::retire(end_of_gc, retain); - _retired = true; - } -}; - #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_HPP