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 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; | 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 size_t total_capacity_bytes() { 114 return _length * HeapRegion::GrainBytes; 115 } 116 117 // It updates the fields of the set to reflect hr being added to 118 // the set and tags the region appropriately. 119 inline void add(HeapRegion* hr); 120 121 // It updates the fields of the set to reflect hr being removed 122 // from the set and tags the region appropriately. 123 inline void remove(HeapRegion* hr); 124 125 virtual void verify(); 126 void verify_start(); 127 void verify_next_region(HeapRegion* hr); 128 void verify_end(); 129 130 #if HEAP_REGION_SET_FORCE_VERIFY 131 void verify_optional() { 132 verify(); 133 } 134 #else // HEAP_REGION_SET_FORCE_VERIFY 140 141 #define hrs_assert_sets_match(_set1_, _set2_) \ 142 do { \ 143 assert(((_set1_)->regions_humongous() == (_set2_)->regions_humongous()) && \ 144 ((_set1_)->regions_free() == (_set2_)->regions_free()), \ 145 "the contents of set %s and set %s should match", \ 146 (_set1_)->name(), \ 147 (_set2_)->name()); \ 148 } while (0) 149 150 // This class represents heap region sets whose members are not 151 // explicitly tracked. It's helpful to group regions using such sets 152 // so that we can reason about all the region groups in the heap using 153 // the same interface (namely, the HeapRegionSetBase API). 154 155 class HeapRegionSet : public HeapRegionSetBase { 156 public: 157 HeapRegionSet(const char* name, bool humongous, HRSMtSafeChecker* mt_safety_checker): 158 HeapRegionSetBase(name, humongous, false /* free */, mt_safety_checker) { } 159 160 void bulk_remove(const uint removed) { 161 _length -= removed; 162 } 163 }; 164 165 // A set that links all the regions added to it in a doubly-linked 166 // sorted list. We should try to avoid doing operations that iterate over 167 // such lists in performance critical paths. Typically we should 168 // add / remove one region at a time or concatenate two lists. 169 170 class FreeRegionListIterator; 171 172 class FreeRegionList : public HeapRegionSetBase { 173 friend class FreeRegionListIterator; 174 175 private: 176 HeapRegion* _head; 177 HeapRegion* _tail; 178 179 // _last is used to keep track of where we added an element the last 180 // time. It helps to improve performance when adding several ordered items in a row. 181 HeapRegion* _last; |