< prev index next >

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

Print this page




  21  * questions.
  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 // Interface to keep track of which regions G1 is currently allocating into. Provides
  37 // some accessors (e.g. allocating into them, or getting their occupancy).
  38 // Also keeps track of retained regions across GCs.
  39 class G1Allocator : public CHeapObj<mtGC> {
  40   friend class VMStructs;
  41 private:
  42   bool _survivor_is_full;
  43   bool _old_is_full;
  44 protected:
  45   G1CollectedHeap* _g1h;
  46 
  47   virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
  48 
  49   virtual bool survivor_is_full(AllocationContext_t context) const;
  50   virtual bool old_is_full(AllocationContext_t context) const;
  51 
  52   virtual void set_survivor_full(AllocationContext_t context);
  53   virtual void set_old_full(AllocationContext_t context);
  54 
  55   // Accessors to the allocation regions.
  56   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
  57   virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
  58 
  59   // Allocation attempt during GC for a survivor object / PLAB.
  60   inline HeapWord* survivor_attempt_allocation(size_t min_word_size,
  61                                                size_t desired_word_size,
  62                                                size_t* actual_word_size,
  63                                                AllocationContext_t context);
  64   // Allocation attempt during GC for an old object / PLAB.
  65   inline HeapWord* old_attempt_allocation(size_t min_word_size,
  66                                           size_t desired_word_size,
  67                                           size_t* actual_word_size,
  68                                           AllocationContext_t context);
  69 public:
  70   G1Allocator(G1CollectedHeap* heap) : _g1h(heap), _survivor_is_full(false), _old_is_full(false) { }
  71   virtual ~G1Allocator() { }
  72 
  73   static G1Allocator* create_allocator(G1CollectedHeap* g1h);
  74 
  75 #ifdef ASSERT
  76   // Do we currently have an active mutator region to allocate into?
  77   bool has_mutator_alloc_region(AllocationContext_t context) { return mutator_alloc_region(context)->get() != NULL; }
  78 #endif
  79   virtual void init_mutator_alloc_region() = 0;
  80   virtual void release_mutator_alloc_region() = 0;
  81 
  82   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
  83   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  84   virtual void abandon_gc_alloc_regions() = 0;
  85 
  86   // Management of retained regions.
  87 
  88   virtual bool is_retained_old_region(HeapRegion* hr) = 0;
  89   void reuse_retained_old_region(EvacuationInfo& evacuation_info,
  90                                  OldGCAllocRegion* old,
  91                                  HeapRegion** retained);
  92 
  93   // Allocate blocks of memory during mutator time.
  94 
  95   inline HeapWord* attempt_allocation(size_t word_size, AllocationContext_t context);
  96   inline HeapWord* attempt_allocation_locked(size_t word_size, AllocationContext_t context);
  97   inline HeapWord* attempt_allocation_force(size_t word_size, AllocationContext_t context);
  98 
  99   size_t unsafe_max_tlab_alloc(AllocationContext_t context);
 100 
 101   // Allocate blocks of memory during garbage collection. Will ensure an
 102   // allocation region, either by picking one or expanding the
 103   // heap, and then allocate a block of the given size. The block
 104   // may not be a humongous - it must fit into a single heap region.
 105   HeapWord* par_allocate_during_gc(InCSetState dest,
 106                                    size_t word_size,
 107                                    AllocationContext_t context);
 108 
 109   HeapWord* par_allocate_during_gc(InCSetState dest,
 110                                    size_t min_word_size,
 111                                    size_t desired_word_size,
 112                                    size_t* actual_word_size,
 113                                    AllocationContext_t context);
 114 
 115   virtual size_t used_in_alloc_regions() = 0;
 116 };
 117 
 118 // The default allocation region manager for G1. Provides a single mutator, survivor
 119 // and old generation allocation region.
 120 // Can retain the (single) old generation allocation region across GCs.
 121 class G1DefaultAllocator : public G1Allocator {



 122 protected:
 123   // Alloc region used to satisfy mutator allocation requests.
 124   MutatorAllocRegion _mutator_alloc_region;
 125 
 126   // Alloc region used to satisfy allocation requests by the GC for
 127   // survivor objects.
 128   SurvivorGCAllocRegion _survivor_gc_alloc_region;
 129 
 130   // Alloc region used to satisfy allocation requests by the GC for
 131   // old objects.
 132   OldGCAllocRegion _old_gc_alloc_region;
 133 
 134   HeapRegion* _retained_old_gc_alloc_region;
 135 public:
 136   G1DefaultAllocator(G1CollectedHeap* heap);






 137 
 138   virtual void init_mutator_alloc_region();
 139   virtual void release_mutator_alloc_region();
 140 
 141   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
 142   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
 143   virtual void abandon_gc_alloc_regions();
 144 
 145   virtual bool is_retained_old_region(HeapRegion* hr) {
 146     return _retained_old_gc_alloc_region == hr;
 147   }
 148 
 149   virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
 150     return &_mutator_alloc_region;
 151   }
 152 
 153   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) {
 154     return &_survivor_gc_alloc_region;
 155   }
 156 




  21  * questions.
  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 // Interface to keep track of which regions G1 is currently allocating into. Provides
  37 // some accessors (e.g. allocating into them, or getting their occupancy).
  38 // Also keeps track of retained regions across GCs.
  39 class G1Allocator : public CHeapObj<mtGC> {
  40   friend class VMStructs;



  41 protected:
  42   G1CollectedHeap* _g1h;
  43 
  44   virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0;
  45 
  46   virtual bool survivor_is_full(AllocationContext_t context) const = 0;
  47   virtual bool old_is_full(AllocationContext_t context) const = 0;
  48 
  49   virtual void set_survivor_full(AllocationContext_t context) = 0;
  50   virtual void set_old_full(AllocationContext_t context) = 0;
  51 
  52   // Accessors to the allocation regions.
  53   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0;
  54   virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0;
  55 
  56   // Allocation attempt during GC for a survivor object / PLAB.
  57   inline HeapWord* survivor_attempt_allocation(size_t min_word_size,
  58                                                size_t desired_word_size,
  59                                                size_t* actual_word_size,
  60                                                AllocationContext_t context);
  61   // Allocation attempt during GC for an old object / PLAB.
  62   inline HeapWord* old_attempt_allocation(size_t min_word_size,
  63                                           size_t desired_word_size,
  64                                           size_t* actual_word_size,
  65                                           AllocationContext_t context);
  66 public:
  67   G1Allocator(G1CollectedHeap* heap) : _g1h(heap) { }
  68   virtual ~G1Allocator() { }
  69 
  70   static G1Allocator* create_allocator(G1CollectedHeap* g1h);
  71 
  72 #ifdef ASSERT
  73   // Do we currently have an active mutator region to allocate into?
  74   bool has_mutator_alloc_region(AllocationContext_t context) { return mutator_alloc_region(context)->get() != NULL; }
  75 #endif
  76   virtual void init_mutator_alloc_region() = 0;
  77   virtual void release_mutator_alloc_region() = 0;
  78 
  79   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  80   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0;
  81   virtual void abandon_gc_alloc_regions() = 0;
  82 
  83   // Management of retained regions.
  84 
  85   virtual bool is_retained_old_region(HeapRegion* hr) = 0;
  86   void reuse_retained_old_region(EvacuationInfo& evacuation_info,
  87                                  OldGCAllocRegion* old,
  88                                  HeapRegion** retained);
  89 
  90   // Allocate blocks of memory during mutator time.
  91 
  92   inline HeapWord* attempt_allocation(size_t word_size, AllocationContext_t context);
  93   inline HeapWord* attempt_allocation_locked(size_t word_size, AllocationContext_t context);
  94   inline HeapWord* attempt_allocation_force(size_t word_size, AllocationContext_t context);
  95 
  96   size_t unsafe_max_tlab_alloc(AllocationContext_t context);
  97 
  98   // Allocate blocks of memory during garbage collection. Will ensure an
  99   // allocation region, either by picking one or expanding the
 100   // heap, and then allocate a block of the given size. The block
 101   // may not be a humongous - it must fit into a single heap region.
 102   HeapWord* par_allocate_during_gc(InCSetState dest,
 103                                    size_t word_size,
 104                                    AllocationContext_t context);
 105 
 106   HeapWord* par_allocate_during_gc(InCSetState dest,
 107                                    size_t min_word_size,
 108                                    size_t desired_word_size,
 109                                    size_t* actual_word_size,
 110                                    AllocationContext_t context);
 111 
 112   virtual size_t used_in_alloc_regions() = 0;
 113 };
 114 
 115 // The default allocation region manager for G1. Provides a single mutator, survivor
 116 // and old generation allocation region.
 117 // Can retain the (single) old generation allocation region across GCs.
 118 class G1DefaultAllocator : public G1Allocator {
 119 private:
 120   bool _survivor_is_full;
 121   bool _old_is_full;
 122 protected:
 123   // Alloc region used to satisfy mutator allocation requests.
 124   MutatorAllocRegion _mutator_alloc_region;
 125 
 126   // Alloc region used to satisfy allocation requests by the GC for
 127   // survivor objects.
 128   SurvivorGCAllocRegion _survivor_gc_alloc_region;
 129 
 130   // Alloc region used to satisfy allocation requests by the GC for
 131   // old objects.
 132   OldGCAllocRegion _old_gc_alloc_region;
 133 
 134   HeapRegion* _retained_old_gc_alloc_region;
 135 public:
 136   G1DefaultAllocator(G1CollectedHeap* heap);
 137 
 138   virtual bool survivor_is_full(AllocationContext_t context) const;
 139   virtual bool old_is_full(AllocationContext_t context) const ;
 140 
 141   virtual void set_survivor_full(AllocationContext_t context);
 142   virtual void set_old_full(AllocationContext_t context);
 143 
 144   virtual void init_mutator_alloc_region();
 145   virtual void release_mutator_alloc_region();
 146 
 147   virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info);
 148   virtual void release_gc_alloc_regions(EvacuationInfo& evacuation_info);
 149   virtual void abandon_gc_alloc_regions();
 150 
 151   virtual bool is_retained_old_region(HeapRegion* hr) {
 152     return _retained_old_gc_alloc_region == hr;
 153   }
 154 
 155   virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) {
 156     return &_mutator_alloc_region;
 157   }
 158 
 159   virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) {
 160     return &_survivor_gc_alloc_region;
 161   }
 162 


< prev index next >