src/hotspot/share/gc/g1/g1AllocRegion.hpp
changeset 59060 fce1fa1bdc91
parent 54843 25c329958c70
child 59061 df6f2350edfa
equal deleted inserted replaced
59059:27a266d5fb13 59060:fce1fa1bdc91
    26 #define SHARE_GC_G1_G1ALLOCREGION_HPP
    26 #define SHARE_GC_G1_G1ALLOCREGION_HPP
    27 
    27 
    28 #include "gc/g1/heapRegion.hpp"
    28 #include "gc/g1/heapRegion.hpp"
    29 #include "gc/g1/g1EvacStats.hpp"
    29 #include "gc/g1/g1EvacStats.hpp"
    30 #include "gc/g1/g1HeapRegionAttr.hpp"
    30 #include "gc/g1/g1HeapRegionAttr.hpp"
       
    31 #include "gc/g1/g1NUMA.hpp"
    31 
    32 
    32 class G1CollectedHeap;
    33 class G1CollectedHeap;
    33 
    34 
    34 // A class that holds a region that is active in satisfying allocation
    35 // A class that holds a region that is active in satisfying allocation
    35 // requests, potentially issued in parallel. When the active region is
    36 // requests, potentially issued in parallel. When the active region is
    36 // full it will be retired and replaced with a new one. The
    37 // full it will be retired and replaced with a new one. The
    37 // implementation assumes that fast-path allocations will be lock-free
    38 // 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 // and a lock will need to be taken when the active region needs to be
    39 // replaced.
    40 // replaced.
    40 
    41 
    41 class G1AllocRegion {
    42 class G1AllocRegion : public CHeapObj<mtGC> {
    42 
    43 
    43 private:
    44 private:
    44   // The active allocating region we are currently allocating out
    45   // The active allocating region we are currently allocating out
    45   // of. The invariant is that if this object is initialized (i.e.,
    46   // 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   // init() has been called and release() has not) then _alloc_region
    89   // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
    90   // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
    90   // to allocate a new region even if the max has been reached.
    91   // to allocate a new region even if the max has been reached.
    91   HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
    92   HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
    92 
    93 
    93 protected:
    94 protected:
       
    95   // The memory node index this allocation region belongs to.
       
    96   uint _node_index;
       
    97 
    94   // Reset the alloc region to point a the dummy region.
    98   // Reset the alloc region to point a the dummy region.
    95   void reset_alloc_region();
    99   void reset_alloc_region();
    96 
   100 
    97   // Perform a non-MT-safe allocation out of the given region.
   101   // Perform a non-MT-safe allocation out of the given region.
    98   inline HeapWord* allocate(HeapRegion* alloc_region,
   102   inline HeapWord* allocate(HeapRegion* alloc_region,
   129 
   133 
   130   virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
   134   virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
   131   virtual void retire_region(HeapRegion* alloc_region,
   135   virtual void retire_region(HeapRegion* alloc_region,
   132                              size_t allocated_bytes) = 0;
   136                              size_t allocated_bytes) = 0;
   133 
   137 
   134   G1AllocRegion(const char* name, bool bot_updates);
   138   G1AllocRegion(const char* name, bool bot_updates, uint node_index);
   135 
   139 
   136 public:
   140 public:
   137   static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
   141   static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
   138 
   142 
   139   HeapRegion* get() const {
   143   HeapRegion* get() const {
   218 protected:
   222 protected:
   219   virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
   223   virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
   220   virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
   224   virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
   221   virtual size_t retire(bool fill_up);
   225   virtual size_t retire(bool fill_up);
   222 public:
   226 public:
   223   MutatorAllocRegion()
   227   MutatorAllocRegion(uint node_index)
   224     : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */),
   228     : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */, node_index),
   225       _wasted_bytes(0),
   229       _wasted_bytes(0),
   226       _retained_alloc_region(NULL) { }
   230       _retained_alloc_region(NULL) { }
   227 
   231 
   228   // Returns the combined used memory in the current alloc region and
   232   // Returns the combined used memory in the current alloc region and
   229   // the retained alloc region.
   233   // the retained alloc region.
   243   // region is retired and set to NULL.
   247   // region is retired and set to NULL.
   244   virtual HeapRegion* release();
   248   virtual HeapRegion* release();
   245 
   249 
   246   virtual void init();
   250   virtual void init();
   247 };
   251 };
       
   252 
   248 // Common base class for allocation regions used during GC.
   253 // Common base class for allocation regions used during GC.
   249 class G1GCAllocRegion : public G1AllocRegion {
   254 class G1GCAllocRegion : public G1AllocRegion {
   250 protected:
   255 protected:
   251   G1EvacStats* _stats;
   256   G1EvacStats* _stats;
   252   G1HeapRegionAttr::region_type_t _purpose;
   257   G1HeapRegionAttr::region_type_t _purpose;
   254   virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
   259   virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
   255   virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
   260   virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
   256 
   261 
   257   virtual size_t retire(bool fill_up);
   262   virtual size_t retire(bool fill_up);
   258 
   263 
   259   G1GCAllocRegion(const char* name, bool bot_updates, G1EvacStats* stats, G1HeapRegionAttr::region_type_t purpose)
   264   G1GCAllocRegion(const char* name, bool bot_updates, G1EvacStats* stats,
   260   : G1AllocRegion(name, bot_updates), _stats(stats), _purpose(purpose) {
   265                   G1HeapRegionAttr::region_type_t purpose, uint node_index = G1NUMA::AnyNodeIndex)
       
   266   : G1AllocRegion(name, bot_updates, node_index), _stats(stats), _purpose(purpose) {
   261     assert(stats != NULL, "Must pass non-NULL PLAB statistics");
   267     assert(stats != NULL, "Must pass non-NULL PLAB statistics");
   262   }
   268   }
   263 };
   269 };
   264 
   270 
   265 class SurvivorGCAllocRegion : public G1GCAllocRegion {
   271 class SurvivorGCAllocRegion : public G1GCAllocRegion {