< prev index next >
src/share/vm/gc_implementation/g1/g1Allocator.hpp
Print this page
rev 7902 : [mq]: 8073052-Rename-and-clean-up-the-allocation-manager-hierarchy-in-g1Allocator
rev 7903 : imported patch 8073013-add-detailed-information-about-plab-memory-usage
rev 7904 : imported patch 8040162-avoid-reallocating-plab-allocators
rev 7908 : [mq]: 8073317-move-region-level-allocation-into-allocregionmanager
*** 28,99 ****
#include "gc_implementation/g1/g1AllocationContext.hpp"
#include "gc_implementation/g1/g1AllocRegion.hpp"
#include "gc_implementation/g1/g1InCSetState.hpp"
#include "gc_implementation/shared/parGCAllocBuffer.hpp"
! // Base class for G1 allocators.
class G1Allocator : public CHeapObj<mtGC> {
friend class VMStructs;
! protected:
G1CollectedHeap* _g1h;
! // Outside of GC pauses, the number of bytes used in all regions other
! // than the current allocation region.
! size_t _summary_bytes_used;
!
! public:
! G1Allocator(G1CollectedHeap* heap) :
! _g1h(heap), _summary_bytes_used(0) { }
static G1Allocator* create_allocator(G1CollectedHeap* g1h);
virtual void init_mutator_alloc_region() = 0;
virtual void release_mutator_alloc_region() = 0;
virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info) = 0;
virtual void abandon_gc_alloc_regions() = 0;
! virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
! virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
! virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
! virtual size_t used() = 0;
! virtual bool is_retained_old_region(HeapRegion* hr) = 0;
! void reuse_retained_old_region(EvacuationInfo& evacuation_info,
! OldGCAllocRegion* old,
! HeapRegion** retained);
! size_t used_unlocked() const {
! return _summary_bytes_used;
}
! void increase_used(size_t bytes) {
! _summary_bytes_used += bytes;
}
! void decrease_used(size_t bytes) {
! assert(_summary_bytes_used >= bytes,
! err_msg("invariant: _summary_bytes_used: "SIZE_FORMAT" should be >= bytes: "SIZE_FORMAT,
! _summary_bytes_used, bytes));
! _summary_bytes_used -= bytes;
}
! void set_used(size_t bytes) {
! _summary_bytes_used = bytes;
}
! virtual HeapRegion* new_heap_region(uint hrs_index,
! G1BlockOffsetSharedArray* sharedOffsetArray,
! MemRegion mr) {
! return new HeapRegion(hrs_index, sharedOffsetArray, mr);
! }
};
! // The default allocator for G1.
class G1DefaultAllocator : public G1Allocator {
! protected:
// 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.
--- 28,122 ----
#include "gc_implementation/g1/g1AllocationContext.hpp"
#include "gc_implementation/g1/g1AllocRegion.hpp"
#include "gc_implementation/g1/g1InCSetState.hpp"
#include "gc_implementation/shared/parGCAllocBuffer.hpp"
! // Interface to keep track of which regions G1 is currently allocating into and
! // allowing access to it (e.g. allocating into them, or getting their occupancy).
! // Also keeps track of retained regions across GCs.
class G1Allocator : public CHeapObj<mtGC> {
friend class VMStructs;
! protected:
G1CollectedHeap* _g1h;
! virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
! virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
! virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
!
! // Allocation attempt during GC for a survivor object / PLAB.
! inline HeapWord* survivor_attempt_allocation(size_t min_word_size,
! size_t& word_size,
! AllocationContext_t context);
!
! // Allocation attempt during GC for an old object / PLAB.
! inline HeapWord* old_attempt_allocation(size_t min_word_size,
! size_t& word_size,
! AllocationContext_t context);
!
! void reuse_retained_old_region(EvacuationInfo& evacuation_info,
! OldGCAllocRegion* old,
! HeapRegion** retained);
!
! public:
! G1Allocator(G1CollectedHeap* heap) : _g1h(heap) { }
static G1Allocator* create_allocator(G1CollectedHeap* g1h);
virtual void init_mutator_alloc_region() = 0;
virtual void release_mutator_alloc_region() = 0;
virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info) = 0;
virtual void abandon_gc_alloc_regions() = 0;
! size_t desired_plab_size(InCSetState dest);
! virtual G1EvacStats* evac_stats(InCSetState dest) = 0;
! // Allocate blocks during garbage collection. Will ensure an allocation region
! // is available, either by picking one or getting a new one from 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(InCSetState dest,
! size_t min_word_size,
! size_t& word_size,
! AllocationContext_t context);
! HeapWord* par_allocate_during_gc(InCSetState dest, size_t word_size, AllocationContext_t context) {
! return par_allocate_during_gc(dest, word_size, word_size, context);
}
! HeapWord* par_allocate_during_mutator(size_t word_size, bool bot_updates, AllocationContext_t context) {
! return mutator_alloc_region(context)->attempt_allocation(word_size, bot_updates);
}
! HeapWord* par_allocate_during_mutator_locked(size_t word_size, bool bot_updates, AllocationContext_t context) {
! return mutator_alloc_region(context)->attempt_allocation_locked(word_size, bot_updates);
}
! HeapWord* par_allocate_during_mutator_force(size_t word_size, bool bot_updates, AllocationContext_t context) {
! return mutator_alloc_region(context)->attempt_allocation_force(word_size, bot_updates);
}
! size_t unsafe_max_tlab_alloc();
!
! virtual bool is_retained_old_region(HeapRegion* hr) = 0;
!
! // Returns the amount of memory that is in use by the managed allocation regions.
! virtual size_t used_in_alloc_regions() const = 0;
};
! // The default allocation region manager for G1. Provides a single mutator, survivor
! // and old generation allocation region.
! // Can retain the old generation allocation region across GCs.
class G1DefaultAllocator : public G1Allocator {
! private:
! // PLAB sizing policy for survivors.
! G1EvacStats _survivor_plab_stats;
! // PLAB sizing policy for tenured objects.
! G1EvacStats _old_plab_stats;
!
! protected:
// 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.
*** 102,124 ****
// Alloc region used to satisfy allocation requests by the GC for
// old objects.
OldGCAllocRegion _old_gc_alloc_region;
HeapRegion* _retained_old_gc_alloc_region;
- public:
- G1DefaultAllocator(G1CollectedHeap* heap) : G1Allocator(heap), _retained_old_gc_alloc_region(NULL) { }
-
- virtual void init_mutator_alloc_region();
- virtual void release_mutator_alloc_region();
! virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
! virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info);
! virtual void abandon_gc_alloc_regions();
!
! virtual bool is_retained_old_region(HeapRegion* hr) {
! return _retained_old_gc_alloc_region == hr;
! }
virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
return &_mutator_alloc_region;
}
--- 125,136 ----
// Alloc region used to satisfy allocation requests by the GC for
// old objects.
OldGCAllocRegion _old_gc_alloc_region;
HeapRegion* _retained_old_gc_alloc_region;
! G1EvacStats* evac_stats(InCSetState dest);
virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
return &_mutator_alloc_region;
}
*** 128,161 ****
virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) {
return &_old_gc_alloc_region;
}
! virtual size_t used() {
assert(Heap_lock->owner() != NULL,
"Should be owned on this thread's behalf.");
! size_t result = _summary_bytes_used;
// Read only once in case it is set to NULL concurrently
! HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get();
if (hr != NULL) {
result += hr->used();
}
return result;
}
};
! 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;
}
--- 140,192 ----
virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) {
return &_old_gc_alloc_region;
}
! public:
! G1DefaultAllocator(G1CollectedHeap* heap);
!
! virtual void init_mutator_alloc_region();
! virtual void release_mutator_alloc_region();
!
! virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
! virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info);
! virtual void abandon_gc_alloc_regions();
!
! virtual bool is_retained_old_region(HeapRegion* hr) {
! return _retained_old_gc_alloc_region == hr;
! }
!
! virtual size_t used_in_alloc_regions() const {
assert(Heap_lock->owner() != NULL,
"Should be owned on this thread's behalf.");
! size_t result = 0;
// Read only once in case it is set to NULL concurrently
! HeapRegion* hr = _mutator_alloc_region.get();
if (hr != NULL) {
result += hr->used();
}
return result;
}
};
! // A PLAB used during garbage collection that is specific to G1.
! class G1PLAB: public ParGCAllocBuffer {
! private:
bool _retired;
! public:
! G1PLAB(size_t gclab_word_size);
! virtual ~G1PLAB() {
guarantee(_retired, "Allocation buffer has not been retired");
}
+ // The amount of space in words wasted within the PLAB including
+ // waste due to refills and alignment.
+ size_t wasted() const { return _wasted; }
+
virtual void set_buf(HeapWord* buf) {
ParGCAllocBuffer::set_buf(buf);
_retired = false;
}
*** 166,195 ****
ParGCAllocBuffer::retire();
_retired = true;
}
};
! class G1ParGCAllocator : public CHeapObj<mtGC> {
friend class G1ParScanThreadState;
! protected:
! G1CollectedHeap* _g1h;
// The survivor alignment in effect in bytes.
// == 0 : don't align survivors
// != 0 : align survivors to that alignment
// These values were chosen to favor the non-alignment case since some
// architectures have a special compare against zero instructions.
const uint _survivor_alignment_bytes;
! size_t _alloc_buffer_waste;
! size_t _undo_waste;
! void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; }
! void add_to_undo_waste(size_t waste) { _undo_waste += waste; }
!
! virtual void retire_alloc_buffers() = 0;
! virtual G1ParGCAllocBuffer* alloc_buffer(InCSetState dest, AllocationContext_t context) = 0;
// Calculate the survivor space object alignment in bytes. Returns that or 0 if
// there are no restrictions on survivor alignment.
static uint calc_survivor_alignment_bytes() {
assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity");
--- 197,226 ----
ParGCAllocBuffer::retire();
_retired = true;
}
};
! // Manages the PLABs used during garbage collection. Interface for allocation from PLABs.
! // Needs to handle multiple contexts, extra alignment in any "survivor" area and some
! // statistics.
! class PLABAllocator : public CHeapObj<mtGC> {
friend class G1ParScanThreadState;
! protected:
! G1Allocator* _allocator;
// The survivor alignment in effect in bytes.
// == 0 : don't align survivors
// != 0 : align survivors to that alignment
// These values were chosen to favor the non-alignment case since some
// architectures have a special compare against zero instructions.
const uint _survivor_alignment_bytes;
! size_t _undo_waste[InCSetState::Num];
! size_t _inline_allocated[InCSetState::Num];
! virtual void flush_stats_and_retire() = 0;
! virtual G1PLAB* alloc_buffer(InCSetState dest, AllocationContext_t context) = 0;
// Calculate the survivor space object alignment in bytes. Returns that or 0 if
// there are no restrictions on survivor alignment.
static uint calc_survivor_alignment_bytes() {
assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity");
*** 201,220 ****
assert(SurvivorAlignmentInBytes > 0, "sanity");
return SurvivorAlignmentInBytes;
}
}
! public:
! G1ParGCAllocator(G1CollectedHeap* g1h) :
! _g1h(g1h), _survivor_alignment_bytes(calc_survivor_alignment_bytes()),
! _alloc_buffer_waste(0), _undo_waste(0) {
}
! static G1ParGCAllocator* create_allocator(G1CollectedHeap* g1h);
! size_t alloc_buffer_waste() { return _alloc_buffer_waste; }
! size_t undo_waste() {return _undo_waste; }
// Allocate word_sz words in dest, either directly into the regions or by
// allocating a new PLAB. Returns the address of the allocated memory, NULL if
// not successful.
HeapWord* allocate_direct_or_new_plab(InCSetState dest,
--- 232,260 ----
assert(SurvivorAlignmentInBytes > 0, "sanity");
return SurvivorAlignmentInBytes;
}
}
! public:
! PLABAllocator(G1Allocator* heap_manager) :
! _allocator(heap_manager), _survivor_alignment_bytes(calc_survivor_alignment_bytes()) {
! for (size_t i = 0; i < ARRAY_SIZE(_inline_allocated); i++) {
! _inline_allocated[i] = 0;
! }
! for (size_t i = 0; i < ARRAY_SIZE(_undo_waste); i++) {
! _undo_waste[i] = 0;
! }
}
! static PLABAllocator* create_allocator(G1Allocator* allocator);
! // Returns the number of words allocated inline for the given state so far.
! size_t inline_allocated(InCSetState value) const { return _inline_allocated[value.value()]; }
! // Returns the number of words wasted due to und for the given state so far.
! size_t lab_undo_waste(InCSetState value) const { return _undo_waste[value.value()]; }
! // Returns the number of words wasted due to alignment or LAB refills.
! virtual size_t lab_waste(InCSetState value) const = 0;
// Allocate word_sz words in dest, either directly into the regions or by
// allocating a new PLAB. Returns the address of the allocated memory, NULL if
// not successful.
HeapWord* allocate_direct_or_new_plab(InCSetState dest,
*** 224,234 ****
// Allocate word_sz words in the PLAB of dest. Returns the address of the
// allocated memory, NULL if not successful.
HeapWord* plab_allocate(InCSetState dest,
size_t word_sz,
AllocationContext_t context) {
! G1ParGCAllocBuffer* buffer = alloc_buffer(dest, context);
if (_survivor_alignment_bytes == 0) {
return buffer->allocate(word_sz);
} else {
return buffer->allocate_aligned(word_sz, _survivor_alignment_bytes);
}
--- 264,274 ----
// Allocate word_sz words in the PLAB of dest. Returns the address of the
// allocated memory, NULL if not successful.
HeapWord* plab_allocate(InCSetState dest,
size_t word_sz,
AllocationContext_t context) {
! G1PLAB* buffer = alloc_buffer(dest, context);
if (_survivor_alignment_bytes == 0) {
return buffer->allocate(word_sz);
} else {
return buffer->allocate_aligned(word_sz, _survivor_alignment_bytes);
}
*** 241,277 ****
return obj;
}
return allocate_direct_or_new_plab(dest, word_sz, context);
}
! void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) {
! if (alloc_buffer(dest, context)->contains(obj)) {
! assert(alloc_buffer(dest, context)->contains(obj + word_sz - 1),
! "should contain whole object");
! alloc_buffer(dest, context)->undo_allocation(obj, word_sz);
! } else {
! CollectedHeap::fill_with_object(obj, word_sz);
! add_to_undo_waste(word_sz);
! }
! }
};
! class G1DefaultParGCAllocator : public G1ParGCAllocator {
! G1ParGCAllocBuffer _surviving_alloc_buffer;
! G1ParGCAllocBuffer _tenured_alloc_buffer;
! G1ParGCAllocBuffer* _alloc_buffers[InCSetState::Num];
! public:
! G1DefaultParGCAllocator(G1CollectedHeap* g1h);
! virtual G1ParGCAllocBuffer* alloc_buffer(InCSetState dest, AllocationContext_t context) {
assert(dest.is_valid(),
err_msg("Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value()));
assert(_alloc_buffers[dest.value()] != NULL,
err_msg("Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value()));
return _alloc_buffers[dest.value()];
}
! virtual void retire_alloc_buffers() ;
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP
--- 281,312 ----
return obj;
}
return allocate_direct_or_new_plab(dest, word_sz, context);
}
! void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context);
};
! // The default PLAB allocator for G1. Keeps the current (single) PLAB for survivor
! // and old generation allocation.
! class DefaultPLABAllocator : public PLABAllocator {
! G1PLAB _surviving_alloc_buffer;
! G1PLAB _tenured_alloc_buffer;
! G1PLAB* _alloc_buffers[InCSetState::Num];
! public:
! DefaultPLABAllocator(G1Allocator* allocator);
! virtual G1PLAB* alloc_buffer(InCSetState dest, AllocationContext_t context) {
assert(dest.is_valid(),
err_msg("Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value()));
assert(_alloc_buffers[dest.value()] != NULL,
err_msg("Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value()));
return _alloc_buffers[dest.value()];
}
! virtual size_t lab_waste(InCSetState value) const;
!
! virtual void flush_stats_and_retire() ;
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP
< prev index next >