< prev index next >

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

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  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_HEAPREGIONSET_HPP
  26 #define SHARE_VM_GC_G1_HEAPREGIONSET_HPP
  27 
  28 #include "gc/g1/heapRegion.hpp"
  29 
  30 #define assert_heap_region_set(p, message)                        \
  31   do {                                                            \
  32     assert((p), "[%s] %s ln: %u cy: " SIZE_FORMAT,                \
  33            name(), message, length(), total_capacity_bytes());    \
  34   } while (0)
  35 
  36 #define guarantee_heap_region_set(p, message)                     \
  37   do {                                                            \
  38     guarantee((p), "[%s] %s ln: %u cy: " SIZE_FORMAT,             \
  39               name(), message, length(), total_capacity_bytes()); \
  40   } while (0)
  41 
  42 #define assert_free_region_list(p, message)                                              \
  43   do {                                                                                   \
  44     assert((p), "[%s] %s ln: %u cy: " SIZE_FORMAT " hd: " PTR_FORMAT " tl: " PTR_FORMAT, \
  45            name(), message, length(), total_capacity_bytes(), p2i(_head), p2i(_tail));   \
  46   } while (0)
  47 
  48 
  49 // Set verification will be forced either if someone defines
  50 // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which
  51 // asserts are compiled in.
  52 #ifndef HEAP_REGION_SET_FORCE_VERIFY
  53 #define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
  54 #endif // HEAP_REGION_SET_FORCE_VERIFY
  55 
  56 class HRSMtSafeChecker : public CHeapObj<mtGC> {
  57 public:
  58   virtual void check() = 0;
  59 };
  60 
  61 class MasterFreeRegionListMtSafeChecker    : public HRSMtSafeChecker { public: void check(); };
  62 class SecondaryFreeRegionListMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
  63 class HumongousRegionSetMtSafeChecker      : public HRSMtSafeChecker { public: void check(); };
  64 class OldRegionSetMtSafeChecker            : public HRSMtSafeChecker { public: void check(); };
  65 
  66 class HeapRegionSetCount VALUE_OBJ_CLASS_SPEC {
  67   friend class VMStructs;
  68   uint   _length;
  69   size_t _capacity;
  70 
  71 public:
  72   HeapRegionSetCount() : _length(0), _capacity(0) { }
  73 
  74   const uint   length()   const { return _length;   }
  75   const size_t capacity() const { return _capacity; }
  76 
  77   void increment(uint length_to_add, size_t capacity_to_add) {
  78     _length += length_to_add;
  79     _capacity += capacity_to_add;
  80   }
  81 
  82   void decrement(const uint length_to_remove, const size_t capacity_to_remove) {
  83     _length -= length_to_remove;
  84     _capacity -= capacity_to_remove;
  85   }
  86 };
  87 
  88 // Base class for all the classes that represent heap region sets. It
  89 // contains the basic attributes that each set needs to maintain
  90 // (e.g., length, region num, used bytes sum) plus any shared
  91 // functionality (e.g., verification).
  92 
  93 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
  94   friend class VMStructs;
  95 private:
  96   bool _is_humongous;
  97   bool _is_free;
  98   HRSMtSafeChecker* _mt_safety_checker;
  99 
 100 protected:
 101   // The number of regions added to the set. If the set contains
 102   // only humongous regions, this reflects only 'starts humongous'
 103   // regions and does not include 'continues humongous' ones.
 104   HeapRegionSetCount _count;
 105 
 106   const char* _name;
 107 
 108   bool _verify_in_progress;
 109 
 110   // verify_region() is used to ensure that the contents of a region
 111   // added to / removed from a set are consistent.
 112   void verify_region(HeapRegion* hr) PRODUCT_RETURN;
 113 
 114   // Indicates whether all regions in the set should be humongous or
 115   // not. Only used during verification.
 116   bool regions_humongous() { return _is_humongous; }
 117 
 118   // Indicates whether all regions in the set should be free or
 119   // not. Only used during verification.
 120   bool regions_free() { return _is_free; }
 121 
 122   void check_mt_safety() {
 123     if (_mt_safety_checker != NULL) {
 124       _mt_safety_checker->check();
 125     }
 126   }
 127 
 128   HeapRegionSetBase(const char* name, bool humongous, bool free, HRSMtSafeChecker* mt_safety_checker);
 129 
 130 public:
 131   const char* name() { return _name; }
 132 
 133   uint length() const { return _count.length(); }
 134 
 135   bool is_empty() { return _count.length() == 0; }
 136 
 137   size_t total_capacity_bytes() {
 138     return _count.capacity();
 139   }
 140 
 141   // It updates the fields of the set to reflect hr being added to
 142   // the set and tags the region appropriately.
 143   inline void add(HeapRegion* hr);
 144 
 145   // It updates the fields of the set to reflect hr being removed
 146   // from the set and tags the region appropriately.
 147   inline void remove(HeapRegion* hr);
 148 
 149   virtual void verify();
 150   void verify_start();
 151   void verify_next_region(HeapRegion* hr);
 152   void verify_end();
 153 
 154 #if HEAP_REGION_SET_FORCE_VERIFY
 155   void verify_optional() {
 156     verify();
 157   }
 158 #else // HEAP_REGION_SET_FORCE_VERIFY
 159   void verify_optional() { }


 164 
 165 #define hrs_assert_sets_match(_set1_, _set2_)                                  \
 166   do {                                                                         \
 167     assert(((_set1_)->regions_humongous() == (_set2_)->regions_humongous()) && \
 168            ((_set1_)->regions_free() == (_set2_)->regions_free()),             \
 169            "the contents of set %s and set %s should match",                   \
 170            (_set1_)->name(),                                                   \
 171            (_set2_)->name());                                                  \
 172   } while (0)
 173 
 174 // This class represents heap region sets whose members are not
 175 // explicitly tracked. It's helpful to group regions using such sets
 176 // so that we can reason about all the region groups in the heap using
 177 // the same interface (namely, the HeapRegionSetBase API).
 178 
 179 class HeapRegionSet : public HeapRegionSetBase {
 180 public:
 181   HeapRegionSet(const char* name, bool humongous, HRSMtSafeChecker* mt_safety_checker):
 182     HeapRegionSetBase(name, humongous, false /* free */, mt_safety_checker) { }
 183 
 184   void bulk_remove(const HeapRegionSetCount& removed) {
 185     _count.decrement(removed.length(), removed.capacity());
 186   }
 187 };
 188 
 189 // A set that links all the regions added to it in a doubly-linked
 190 // sorted list. We should try to avoid doing operations that iterate over
 191 // such lists in performance critical paths. Typically we should
 192 // add / remove one region at a time or concatenate two lists.
 193 
 194 class FreeRegionListIterator;
 195 
 196 class FreeRegionList : public HeapRegionSetBase {
 197   friend class FreeRegionListIterator;
 198 
 199 private:
 200   HeapRegion* _head;
 201   HeapRegion* _tail;
 202 
 203   // _last is used to keep track of where we added an element the last
 204   // time. It helps to improve performance when adding several ordered items in a row.
 205   HeapRegion* _last;




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  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_HEAPREGIONSET_HPP
  26 #define SHARE_VM_GC_G1_HEAPREGIONSET_HPP
  27 
  28 #include "gc/g1/heapRegion.hpp"
  29 
  30 #define assert_heap_region_set(p, message) \
  31   do {                                     \
  32     assert((p), "[%s] %s ln: %u",          \
  33            name(), message, length());     \
  34   } while (0)
  35 
  36 #define guarantee_heap_region_set(p, message) \
  37   do {                                        \
  38     guarantee((p), "[%s] %s ln: %u",          \
  39               name(), message, length());     \
  40   } while (0)
  41 
  42 #define assert_free_region_list(p, message)                          \
  43   do {                                                               \
  44     assert((p), "[%s] %s ln: %u hd: " PTR_FORMAT " tl: " PTR_FORMAT, \
  45            name(), message, length(), p2i(_head), p2i(_tail));       \
  46   } while (0)
  47 
  48 
  49 // Set verification will be forced either if someone defines
  50 // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which
  51 // asserts are compiled in.
  52 #ifndef HEAP_REGION_SET_FORCE_VERIFY
  53 #define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
  54 #endif // HEAP_REGION_SET_FORCE_VERIFY
  55 
  56 class HRSMtSafeChecker : public CHeapObj<mtGC> {
  57 public:
  58   virtual void check() = 0;
  59 };
  60 
  61 class MasterFreeRegionListMtSafeChecker    : public HRSMtSafeChecker { public: void check(); };
  62 class SecondaryFreeRegionListMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
  63 class HumongousRegionSetMtSafeChecker      : public HRSMtSafeChecker { public: void check(); };
  64 class OldRegionSetMtSafeChecker            : public HRSMtSafeChecker { public: void check(); };
  65 






















  66 // Base class for all the classes that represent heap region sets. It
  67 // contains the basic attributes that each set needs to maintain
  68 // (e.g., length, region num, used bytes sum) plus any shared
  69 // functionality (e.g., verification).
  70 
  71 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
  72   friend class VMStructs;
  73 private:
  74   bool _is_humongous;
  75   bool _is_free;
  76   HRSMtSafeChecker* _mt_safety_checker;
  77 
  78 protected:
  79   // The number of regions in to the set.
  80   uint _length;


  81 
  82   const char* _name;
  83 
  84   bool _verify_in_progress;
  85 
  86   // verify_region() is used to ensure that the contents of a region
  87   // added to / removed from a set are consistent.
  88   void verify_region(HeapRegion* hr) PRODUCT_RETURN;
  89 
  90   // Indicates whether all regions in the set should be humongous or
  91   // not. Only used during verification.
  92   bool regions_humongous() { return _is_humongous; }
  93 
  94   // Indicates whether all regions in the set should be free or
  95   // not. Only used during verification.
  96   bool regions_free() { return _is_free; }
  97 
  98   void check_mt_safety() {
  99     if (_mt_safety_checker != NULL) {
 100       _mt_safety_checker->check();
 101     }
 102   }
 103 
 104   HeapRegionSetBase(const char* name, bool humongous, bool free, HRSMtSafeChecker* mt_safety_checker);
 105 
 106 public:
 107   const char* name() { return _name; }
 108 
 109   uint length() const { return _length; }


 110 
 111   bool is_empty() { return _length == 0; }


 112 
 113   // It updates the fields of the set to reflect hr being added to
 114   // the set and tags the region appropriately.
 115   inline void add(HeapRegion* hr);
 116 
 117   // It updates the fields of the set to reflect hr being removed
 118   // from the set and tags the region appropriately.
 119   inline void remove(HeapRegion* hr);
 120 
 121   virtual void verify();
 122   void verify_start();
 123   void verify_next_region(HeapRegion* hr);
 124   void verify_end();
 125 
 126 #if HEAP_REGION_SET_FORCE_VERIFY
 127   void verify_optional() {
 128     verify();
 129   }
 130 #else // HEAP_REGION_SET_FORCE_VERIFY
 131   void verify_optional() { }


 136 
 137 #define hrs_assert_sets_match(_set1_, _set2_)                                  \
 138   do {                                                                         \
 139     assert(((_set1_)->regions_humongous() == (_set2_)->regions_humongous()) && \
 140            ((_set1_)->regions_free() == (_set2_)->regions_free()),             \
 141            "the contents of set %s and set %s should match",                   \
 142            (_set1_)->name(),                                                   \
 143            (_set2_)->name());                                                  \
 144   } while (0)
 145 
 146 // This class represents heap region sets whose members are not
 147 // explicitly tracked. It's helpful to group regions using such sets
 148 // so that we can reason about all the region groups in the heap using
 149 // the same interface (namely, the HeapRegionSetBase API).
 150 
 151 class HeapRegionSet : public HeapRegionSetBase {
 152 public:
 153   HeapRegionSet(const char* name, bool humongous, HRSMtSafeChecker* mt_safety_checker):
 154     HeapRegionSetBase(name, humongous, false /* free */, mt_safety_checker) { }
 155 
 156   void bulk_remove(const uint removed) {
 157     _length -= removed;
 158   }
 159 };
 160 
 161 // A set that links all the regions added to it in a doubly-linked
 162 // sorted list. We should try to avoid doing operations that iterate over
 163 // such lists in performance critical paths. Typically we should
 164 // add / remove one region at a time or concatenate two lists.
 165 
 166 class FreeRegionListIterator;
 167 
 168 class FreeRegionList : public HeapRegionSetBase {
 169   friend class FreeRegionListIterator;
 170 
 171 private:
 172   HeapRegion* _head;
 173   HeapRegion* _tail;
 174 
 175   // _last is used to keep track of where we added an element the last
 176   // time. It helps to improve performance when adding several ordered items in a row.
 177   HeapRegion* _last;


< prev index next >