< prev index next >

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

Print this page




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_G1_G1ALLOCREGION_HPP
  26 #define SHARE_VM_GC_G1_G1ALLOCREGION_HPP
  27 
  28 #include "gc/g1/heapRegion.hpp"
  29 #include "gc/g1/g1EvacStats.hpp"
  30 #include "gc/g1/g1InCSetState.hpp"
  31 
  32 class G1CollectedHeap;
  33 
  34 // 0 -> no tracing, 1 -> basic tracing, 2 -> basic + allocation tracing
  35 #define G1_ALLOC_REGION_TRACING 0
  36 
  37 class ar_ext_msg;
  38 
  39 // A class that holds a region that is active in satisfying allocation
  40 // requests, potentially issued in parallel. When the active region is
  41 // full it will be retired and replaced with a new one. The
  42 // implementation assumes that fast-path allocations will be lock-free
  43 // and a lock will need to be taken when the active region needs to be
  44 // replaced.
  45 
  46 class G1AllocRegion VALUE_OBJ_CLASS_SPEC {
  47   friend class ar_ext_msg;
  48 
  49 private:
  50   // The active allocating region we are currently allocating out
  51   // of. The invariant is that if this object is initialized (i.e.,
  52   // init() has been called and release() has not) then _alloc_region
  53   // is either an active allocating region or the dummy region (i.e.,
  54   // it can never be NULL) and this object can be used to satisfy
  55   // allocation requests. If this object is not initialized
  56   // (i.e. init() has not been called or release() has been called)
  57   // then _alloc_region is NULL and this object should not be used to
  58   // satisfy allocation requests (it was done this way to force the
  59   // correct use of init() and release()).
  60   HeapRegion* volatile _alloc_region;
  61 
  62   // Allocation context associated with this alloc region.
  63   AllocationContext_t _allocation_context;
  64 
  65   // It keeps track of the distinct number of regions that are used
  66   // for allocation in the active interval of this object, i.e.,
  67   // between a call to init() and a call to release(). The count


 114                                        size_t* actual_word_size,
 115                                        bool bot_updates);
 116 
 117   // Ensure that the region passed as a parameter has been filled up
 118   // so that noone else can allocate out of it any more.
 119   // Returns the number of bytes that have been wasted by filled up
 120   // the space.
 121   static size_t fill_up_remaining_space(HeapRegion* alloc_region,
 122                                         bool bot_updates);
 123 
 124   // After a region is allocated by alloc_new_region, this
 125   // method is used to set it as the active alloc_region
 126   void update_alloc_region(HeapRegion* alloc_region);
 127 
 128   // Allocate a new active region and use it to perform a word_size
 129   // allocation. The force parameter will be passed on to
 130   // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
 131   // to allocate a new region even if the max has been reached.
 132   HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
 133 
 134   void fill_in_ext_msg(ar_ext_msg* msg, const char* message);
 135 
 136 protected:
 137   // Retire the active allocating region. If fill_up is true then make
 138   // sure that the region is full before we retire it so that no one
 139   // else can allocate out of it.
 140   // Returns the number of bytes that have been filled up during retire.
 141   virtual size_t retire(bool fill_up);
 142 
 143   // For convenience as subclasses use it.
 144   static G1CollectedHeap* _g1h;
 145 
 146   virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
 147   virtual void retire_region(HeapRegion* alloc_region,
 148                              size_t allocated_bytes) = 0;
 149 
 150   G1AllocRegion(const char* name, bool bot_updates);
 151 
 152 public:
 153   static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
 154 
 155   HeapRegion* get() const {


 259   }
 260 };
 261 
 262 class SurvivorGCAllocRegion : public G1GCAllocRegion {
 263 public:
 264   SurvivorGCAllocRegion(G1EvacStats* stats)
 265   : G1GCAllocRegion("Survivor GC Alloc Region", false /* bot_updates */, stats, InCSetState::Young) { }
 266 };
 267 
 268 class OldGCAllocRegion : public G1GCAllocRegion {
 269 public:
 270   OldGCAllocRegion(G1EvacStats* stats)
 271   : G1GCAllocRegion("Old GC Alloc Region", true /* bot_updates */, stats, InCSetState::Old) { }
 272 
 273   // This specialization of release() makes sure that the last card that has
 274   // been allocated into has been completely filled by a dummy object.  This
 275   // avoids races when remembered set scanning wants to update the BOT of the
 276   // last card in the retained old gc alloc region, and allocation threads
 277   // allocating into that card at the same time.
 278   virtual HeapRegion* release();
 279 };
 280 
 281 class ar_ext_msg : public err_msg {
 282 public:
 283   ar_ext_msg(G1AllocRegion* alloc_region, const char *message) : err_msg("%s", "") {
 284     alloc_region->fill_in_ext_msg(this, message);
 285   }
 286 };
 287 
 288 #endif // SHARE_VM_GC_G1_G1ALLOCREGION_HPP


  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_G1_G1ALLOCREGION_HPP
  26 #define SHARE_VM_GC_G1_G1ALLOCREGION_HPP
  27 
  28 #include "gc/g1/heapRegion.hpp"
  29 #include "gc/g1/g1EvacStats.hpp"
  30 #include "gc/g1/g1InCSetState.hpp"
  31 
  32 class G1CollectedHeap;
  33 
  34 // 0 -> no tracing, 1 -> basic tracing, 2 -> basic + allocation tracing
  35 #define G1_ALLOC_REGION_TRACING 0
  36 


  37 // A class that holds a region that is active in satisfying allocation
  38 // requests, potentially issued in parallel. When the active region is
  39 // full it will be retired and replaced with a new one. The
  40 // implementation assumes that fast-path allocations will be lock-free
  41 // and a lock will need to be taken when the active region needs to be
  42 // replaced.
  43 
  44 class G1AllocRegion VALUE_OBJ_CLASS_SPEC {

  45 
  46 private:
  47   // The active allocating region we are currently allocating out
  48   // of. The invariant is that if this object is initialized (i.e.,
  49   // init() has been called and release() has not) then _alloc_region
  50   // is either an active allocating region or the dummy region (i.e.,
  51   // it can never be NULL) and this object can be used to satisfy
  52   // allocation requests. If this object is not initialized
  53   // (i.e. init() has not been called or release() has been called)
  54   // then _alloc_region is NULL and this object should not be used to
  55   // satisfy allocation requests (it was done this way to force the
  56   // correct use of init() and release()).
  57   HeapRegion* volatile _alloc_region;
  58 
  59   // Allocation context associated with this alloc region.
  60   AllocationContext_t _allocation_context;
  61 
  62   // It keeps track of the distinct number of regions that are used
  63   // for allocation in the active interval of this object, i.e.,
  64   // between a call to init() and a call to release(). The count


 111                                        size_t* actual_word_size,
 112                                        bool bot_updates);
 113 
 114   // Ensure that the region passed as a parameter has been filled up
 115   // so that noone else can allocate out of it any more.
 116   // Returns the number of bytes that have been wasted by filled up
 117   // the space.
 118   static size_t fill_up_remaining_space(HeapRegion* alloc_region,
 119                                         bool bot_updates);
 120 
 121   // After a region is allocated by alloc_new_region, this
 122   // method is used to set it as the active alloc_region
 123   void update_alloc_region(HeapRegion* alloc_region);
 124 
 125   // Allocate a new active region and use it to perform a word_size
 126   // allocation. The force parameter will be passed on to
 127   // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
 128   // to allocate a new region even if the max has been reached.
 129   HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
 130 


 131 protected:
 132   // Retire the active allocating region. If fill_up is true then make
 133   // sure that the region is full before we retire it so that no one
 134   // else can allocate out of it.
 135   // Returns the number of bytes that have been filled up during retire.
 136   virtual size_t retire(bool fill_up);
 137 
 138   // For convenience as subclasses use it.
 139   static G1CollectedHeap* _g1h;
 140 
 141   virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
 142   virtual void retire_region(HeapRegion* alloc_region,
 143                              size_t allocated_bytes) = 0;
 144 
 145   G1AllocRegion(const char* name, bool bot_updates);
 146 
 147 public:
 148   static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
 149 
 150   HeapRegion* get() const {


 254   }
 255 };
 256 
 257 class SurvivorGCAllocRegion : public G1GCAllocRegion {
 258 public:
 259   SurvivorGCAllocRegion(G1EvacStats* stats)
 260   : G1GCAllocRegion("Survivor GC Alloc Region", false /* bot_updates */, stats, InCSetState::Young) { }
 261 };
 262 
 263 class OldGCAllocRegion : public G1GCAllocRegion {
 264 public:
 265   OldGCAllocRegion(G1EvacStats* stats)
 266   : G1GCAllocRegion("Old GC Alloc Region", true /* bot_updates */, stats, InCSetState::Old) { }
 267 
 268   // This specialization of release() makes sure that the last card that has
 269   // been allocated into has been completely filled by a dummy object.  This
 270   // avoids races when remembered set scanning wants to update the BOT of the
 271   // last card in the retained old gc alloc region, and allocation threads
 272   // allocating into that card at the same time.
 273   virtual HeapRegion* release();







 274 };
 275 
 276 #endif // SHARE_VM_GC_G1_G1ALLOCREGION_HPP
< prev index next >