< prev index next >

src/hotspot/share/gc/g1/g1AllocRegion.hpp

Print this page




  36 // full it will be retired and replaced with a new one. The
  37 // implementation assumes that fast-path allocations will be lock-free
  38 // and a lock will need to be taken when the active region needs to be
  39 // replaced.
  40 
  41 class G1AllocRegion VALUE_OBJ_CLASS_SPEC {
  42 
  43 private:
  44   // The active allocating region we are currently allocating out
  45   // of. The invariant is that if this object is initialized (i.e.,
  46   // init() has been called and release() has not) then _alloc_region
  47   // is either an active allocating region or the dummy region (i.e.,
  48   // it can never be NULL) and this object can be used to satisfy
  49   // allocation requests. If this object is not initialized
  50   // (i.e. init() has not been called or release() has been called)
  51   // then _alloc_region is NULL and this object should not be used to
  52   // satisfy allocation requests (it was done this way to force the
  53   // correct use of init() and release()).
  54   HeapRegion* volatile _alloc_region;
  55 
  56   // Allocation context associated with this alloc region.
  57   AllocationContext_t _allocation_context;
  58 
  59   // It keeps track of the distinct number of regions that are used
  60   // for allocation in the active interval of this object, i.e.,
  61   // between a call to init() and a call to release(). The count
  62   // mostly includes regions that are freshly allocated, as well as
  63   // the region that is re-used using the set() method. This count can
  64   // be used in any heuristics that might want to bound how many
  65   // distinct regions this object can used during an active interval.
  66   uint _count;
  67 
  68   // When we set up a new active region we save its used bytes in this
  69   // field so that, when we retire it, we can calculate how much space
  70   // we allocated in it.
  71   size_t _used_bytes_before;
  72 
  73   // When true, indicates that allocate calls should do BOT updates.
  74   const bool _bot_updates;
  75 
  76   // Useful for debugging and tracing.
  77   const char* _name;
  78 


 122   // Returns the number of bytes that have been filled up during retire.
 123   virtual size_t retire(bool fill_up);
 124 
 125   // For convenience as subclasses use it.
 126   static G1CollectedHeap* _g1h;
 127 
 128   virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
 129   virtual void retire_region(HeapRegion* alloc_region,
 130                              size_t allocated_bytes) = 0;
 131 
 132   G1AllocRegion(const char* name, bool bot_updates);
 133 
 134 public:
 135   static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
 136 
 137   HeapRegion* get() const {
 138     HeapRegion * hr = _alloc_region;
 139     // Make sure that the dummy region does not escape this class.
 140     return (hr == _dummy_region) ? NULL : hr;
 141   }
 142 
 143   void set_allocation_context(AllocationContext_t context) { _allocation_context = context; }
 144   AllocationContext_t  allocation_context() { return _allocation_context; }
 145 
 146   uint count() { return _count; }
 147 
 148   // The following two are the building blocks for the allocation method.
 149 
 150   // First-level allocation: Should be called without holding a
 151   // lock. It will try to allocate lock-free out of the active region,
 152   // or return NULL if it was unable to.
 153   inline HeapWord* attempt_allocation(size_t word_size);
 154   // Perform an allocation out of the current allocation region, with the given
 155   // minimum and desired size. Returns the actual size allocated (between
 156   // minimum and desired size) in actual_word_size if the allocation has been
 157   // successful.
 158   // Should be called without holding a lock. It will try to allocate lock-free
 159   // out of the active region, or return NULL if it was unable to.
 160   inline HeapWord* attempt_allocation(size_t min_word_size,
 161                                       size_t desired_word_size,
 162                                       size_t* actual_word_size);
 163 
 164   // Second-level allocation: Should be called while holding a




  36 // full it will be retired and replaced with a new one. The
  37 // implementation assumes that fast-path allocations will be lock-free
  38 // and a lock will need to be taken when the active region needs to be
  39 // replaced.
  40 
  41 class G1AllocRegion VALUE_OBJ_CLASS_SPEC {
  42 
  43 private:
  44   // The active allocating region we are currently allocating out
  45   // of. The invariant is that if this object is initialized (i.e.,
  46   // init() has been called and release() has not) then _alloc_region
  47   // is either an active allocating region or the dummy region (i.e.,
  48   // it can never be NULL) and this object can be used to satisfy
  49   // allocation requests. If this object is not initialized
  50   // (i.e. init() has not been called or release() has been called)
  51   // then _alloc_region is NULL and this object should not be used to
  52   // satisfy allocation requests (it was done this way to force the
  53   // correct use of init() and release()).
  54   HeapRegion* volatile _alloc_region;
  55 



  56   // It keeps track of the distinct number of regions that are used
  57   // for allocation in the active interval of this object, i.e.,
  58   // between a call to init() and a call to release(). The count
  59   // mostly includes regions that are freshly allocated, as well as
  60   // the region that is re-used using the set() method. This count can
  61   // be used in any heuristics that might want to bound how many
  62   // distinct regions this object can used during an active interval.
  63   uint _count;
  64 
  65   // When we set up a new active region we save its used bytes in this
  66   // field so that, when we retire it, we can calculate how much space
  67   // we allocated in it.
  68   size_t _used_bytes_before;
  69 
  70   // When true, indicates that allocate calls should do BOT updates.
  71   const bool _bot_updates;
  72 
  73   // Useful for debugging and tracing.
  74   const char* _name;
  75 


 119   // Returns the number of bytes that have been filled up during retire.
 120   virtual size_t retire(bool fill_up);
 121 
 122   // For convenience as subclasses use it.
 123   static G1CollectedHeap* _g1h;
 124 
 125   virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
 126   virtual void retire_region(HeapRegion* alloc_region,
 127                              size_t allocated_bytes) = 0;
 128 
 129   G1AllocRegion(const char* name, bool bot_updates);
 130 
 131 public:
 132   static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
 133 
 134   HeapRegion* get() const {
 135     HeapRegion * hr = _alloc_region;
 136     // Make sure that the dummy region does not escape this class.
 137     return (hr == _dummy_region) ? NULL : hr;
 138   }



 139 
 140   uint count() { return _count; }
 141 
 142   // The following two are the building blocks for the allocation method.
 143 
 144   // First-level allocation: Should be called without holding a
 145   // lock. It will try to allocate lock-free out of the active region,
 146   // or return NULL if it was unable to.
 147   inline HeapWord* attempt_allocation(size_t word_size);
 148   // Perform an allocation out of the current allocation region, with the given
 149   // minimum and desired size. Returns the actual size allocated (between
 150   // minimum and desired size) in actual_word_size if the allocation has been
 151   // successful.
 152   // Should be called without holding a lock. It will try to allocate lock-free
 153   // out of the active region, or return NULL if it was unable to.
 154   inline HeapWord* attempt_allocation(size_t min_word_size,
 155                                       size_t desired_word_size,
 156                                       size_t* actual_word_size);
 157 
 158   // Second-level allocation: Should be called while holding a


< prev index next >