< prev index next >

src/share/vm/gc/g1/g1Allocator.hpp

Print this page
rev 8687 : 8131166: Remove additional whitespace in G1Allocator
Reviewed-by:
rev 8688 : 8131319: Move G1Allocator::_summary_bytes_used back to G1CollectedHeap
Reviewed-by:


  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_G1_G1ALLOCATOR_HPP
  26 #define SHARE_VM_GC_G1_G1ALLOCATOR_HPP
  27 
  28 #include "gc/g1/g1AllocRegion.hpp"
  29 #include "gc/g1/g1AllocationContext.hpp"
  30 #include "gc/g1/g1InCSetState.hpp"
  31 #include "gc/shared/collectedHeap.hpp"
  32 #include "gc/shared/plab.hpp"
  33 
  34 class EvacuationInfo;
  35 
  36 // Base class for G1 allocators.
  37 class G1Allocator : public CHeapObj<mtGC> {
  38   friend class VMStructs;
  39 protected:
  40   G1CollectedHeap* _g1h;
  41 
  42   // Outside of GC pauses, the number of bytes used in all regions other
  43   // than the current allocation region.
  44   size_t _summary_bytes_used;
  45 
  46 public:
  47   G1Allocator(G1CollectedHeap* heap) :
  48     _g1h(heap), _summary_bytes_used(0) { }
  49 
  50   static G1Allocator* create_allocator(G1CollectedHeap* g1h);
  51 
  52   virtual void init_mutator_alloc_region() = 0;
  53   virtual void release_mutator_alloc_region() = 0;
  54 
  55   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  56   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  57   virtual void abandon_gc_alloc_regions() = 0;
  58 
  59   virtual MutatorAllocRegion*    mutator_alloc_region(AllocationContext_t context) = 0;
  60   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
  61   virtual OldGCAllocRegion*      old_gc_alloc_region(AllocationContext_t context) = 0;
  62   virtual size_t                 used() = 0;
  63   virtual bool                   is_retained_old_region(HeapRegion* hr) = 0;
  64 
  65   void                           reuse_retained_old_region(EvacuationInfo& evacuation_info,
  66                                                            OldGCAllocRegion* old,
  67                                                            HeapRegion** retained);
  68 
  69   size_t used_unlocked() const {
  70     return _summary_bytes_used;
  71   }
  72 
  73   void increase_used(size_t bytes) {
  74     _summary_bytes_used += bytes;
  75   }
  76 
  77   void decrease_used(size_t bytes) {
  78     assert(_summary_bytes_used >= bytes,
  79            err_msg("invariant: _summary_bytes_used: " SIZE_FORMAT " should be >= bytes: " SIZE_FORMAT,
  80                _summary_bytes_used, bytes));
  81     _summary_bytes_used -= bytes;
  82   }
  83 
  84   void set_used(size_t bytes) {
  85     _summary_bytes_used = bytes;
  86   }
  87 
  88   virtual HeapRegion* new_heap_region(uint hrs_index,
  89                                       G1BlockOffsetSharedArray* sharedOffsetArray,
  90                                       MemRegion mr) {
  91     return new HeapRegion(hrs_index, sharedOffsetArray, mr);
  92   }
  93 };
  94 
  95 // The default allocator for G1.
  96 class G1DefaultAllocator : public G1Allocator {
  97 protected:
  98   // Alloc region used to satisfy mutator allocation requests.
  99   MutatorAllocRegion _mutator_alloc_region;
 100 
 101   // Alloc region used to satisfy allocation requests by the GC for
 102   // survivor objects.
 103   SurvivorGCAllocRegion _survivor_gc_alloc_region;
 104 
 105   // Alloc region used to satisfy allocation requests by the GC for
 106   // old objects.
 107   OldGCAllocRegion _old_gc_alloc_region;


 116   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
 117   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
 118   virtual void abandon_gc_alloc_regions();
 119 
 120   virtual bool is_retained_old_region(HeapRegion* hr) {
 121     return _retained_old_gc_alloc_region == hr;
 122   }
 123 
 124   virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
 125     return &_mutator_alloc_region;
 126   }
 127 
 128   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) {
 129     return &_survivor_gc_alloc_region;
 130   }
 131 
 132   virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) {
 133     return &_old_gc_alloc_region;
 134   }
 135 
 136   virtual size_t used() {
 137     assert(Heap_lock->owner() != NULL,
 138            "Should be owned on this thread's behalf.");
 139     size_t result = _summary_bytes_used;
 140 
 141     // Read only once in case it is set to NULL concurrently
 142     HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get();
 143     if (hr != NULL) {
 144       result += hr->used();
 145     }
 146     return result;
 147   }
 148 };
 149 
 150 class G1PLAB: public PLAB {
 151 private:
 152   bool _retired;
 153 
 154 public:
 155   G1PLAB(size_t gclab_word_size);
 156   virtual ~G1PLAB() {
 157     guarantee(_retired, "Allocation buffer has not been retired");
 158   }
 159 




  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_G1_G1ALLOCATOR_HPP
  26 #define SHARE_VM_GC_G1_G1ALLOCATOR_HPP
  27 
  28 #include "gc/g1/g1AllocRegion.hpp"
  29 #include "gc/g1/g1AllocationContext.hpp"
  30 #include "gc/g1/g1InCSetState.hpp"
  31 #include "gc/shared/collectedHeap.hpp"
  32 #include "gc/shared/plab.hpp"
  33 
  34 class EvacuationInfo;
  35 
  36 // Base class for G1 allocators.
  37 class G1Allocator : public CHeapObj<mtGC> {
  38   friend class VMStructs;
  39 protected:
  40   G1CollectedHeap* _g1h;
  41 




  42 public:
  43   G1Allocator(G1CollectedHeap* heap) : _g1h(heap) { }

  44 
  45   static G1Allocator* create_allocator(G1CollectedHeap* g1h);
  46 
  47   virtual void init_mutator_alloc_region() = 0;
  48   virtual void release_mutator_alloc_region() = 0;
  49 
  50   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  51   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  52   virtual void abandon_gc_alloc_regions() = 0;
  53 
  54   virtual MutatorAllocRegion*    mutator_alloc_region(AllocationContext_t context) = 0;
  55   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
  56   virtual OldGCAllocRegion*      old_gc_alloc_region(AllocationContext_t context) = 0;
  57   virtual size_t                 used_in_alloc_regions() = 0;
  58   virtual bool                   is_retained_old_region(HeapRegion* hr) = 0;
  59 
  60   void                           reuse_retained_old_region(EvacuationInfo& evacuation_info,
  61                                                            OldGCAllocRegion* old,
  62                                                            HeapRegion** retained);
  63 



















  64   virtual HeapRegion* new_heap_region(uint hrs_index,
  65                                       G1BlockOffsetSharedArray* sharedOffsetArray,
  66                                       MemRegion mr) {
  67     return new HeapRegion(hrs_index, sharedOffsetArray, mr);
  68   }
  69 };
  70 
  71 // The default allocator for G1.
  72 class G1DefaultAllocator : public G1Allocator {
  73 protected:
  74   // Alloc region used to satisfy mutator allocation requests.
  75   MutatorAllocRegion _mutator_alloc_region;
  76 
  77   // Alloc region used to satisfy allocation requests by the GC for
  78   // survivor objects.
  79   SurvivorGCAllocRegion _survivor_gc_alloc_region;
  80 
  81   // Alloc region used to satisfy allocation requests by the GC for
  82   // old objects.
  83   OldGCAllocRegion _old_gc_alloc_region;


  92   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
  93   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
  94   virtual void abandon_gc_alloc_regions();
  95 
  96   virtual bool is_retained_old_region(HeapRegion* hr) {
  97     return _retained_old_gc_alloc_region == hr;
  98   }
  99 
 100   virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
 101     return &_mutator_alloc_region;
 102   }
 103 
 104   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) {
 105     return &_survivor_gc_alloc_region;
 106   }
 107 
 108   virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) {
 109     return &_old_gc_alloc_region;
 110   }
 111 
 112   virtual size_t used_in_alloc_regions() {
 113     assert(Heap_lock->owner() != NULL,
 114            "Should be owned on this thread's behalf.");
 115     size_t result = 0;
 116 
 117     // Read only once in case it is set to NULL concurrently
 118     HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get();
 119     if (hr != NULL) {
 120       result += hr->used();
 121     }
 122     return result;
 123   }
 124 };
 125 
 126 class G1PLAB: public PLAB {
 127 private:
 128   bool _retired;
 129 
 130 public:
 131   G1PLAB(size_t gclab_word_size);
 132   virtual ~G1PLAB() {
 133     guarantee(_retired, "Allocation buffer has not been retired");
 134   }
 135 


< prev index next >