26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP |
27 |
27 |
28 #include "gc_implementation/g1/heapRegion.hpp" |
28 #include "gc_implementation/g1/heapRegion.hpp" |
29 |
29 |
30 // Large buffer for some cases where the output might be larger than normal. |
30 // Large buffer for some cases where the output might be larger than normal. |
31 #define HRL_ERR_MSG_BUFSZ 512 |
31 #define HRS_ERR_MSG_BUFSZ 512 |
32 typedef FormatBuffer<HRL_ERR_MSG_BUFSZ> hrl_err_msg; |
32 typedef FormatBuffer<HRS_ERR_MSG_BUFSZ> hrs_err_msg; |
33 |
33 |
34 // Set verification will be forced either if someone defines |
34 // Set verification will be forced either if someone defines |
35 // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which |
35 // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which |
36 // asserts are compiled in. |
36 // asserts are compiled in. |
37 #ifndef HEAP_REGION_SET_FORCE_VERIFY |
37 #ifndef HEAP_REGION_SET_FORCE_VERIFY |
43 // Base class for all the classes that represent heap region sets. It |
43 // Base class for all the classes that represent heap region sets. It |
44 // contains the basic attributes that each set needs to maintain |
44 // contains the basic attributes that each set needs to maintain |
45 // (e.g., length, region num, used bytes sum) plus any shared |
45 // (e.g., length, region num, used bytes sum) plus any shared |
46 // functionality (e.g., verification). |
46 // functionality (e.g., verification). |
47 |
47 |
48 class hrl_ext_msg; |
48 class hrs_ext_msg; |
49 |
49 |
50 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC { |
50 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC { |
51 friend class hrl_ext_msg; |
51 friend class hrs_ext_msg; |
52 |
52 |
53 protected: |
53 protected: |
54 static size_t calculate_region_num(HeapRegion* hr); |
54 static size_t calculate_region_num(HeapRegion* hr); |
55 |
55 |
56 static size_t _unrealistically_long_length; |
56 static size_t _unrealistically_long_length; |
102 // checks. It is called in an assert from all methods that perform |
102 // checks. It is called in an assert from all methods that perform |
103 // updates on the set (and subclasses should also call it too). |
103 // updates on the set (and subclasses should also call it too). |
104 virtual bool check_mt_safety() { return true; } |
104 virtual bool check_mt_safety() { return true; } |
105 |
105 |
106 // fill_in_ext_msg() writes the the values of the set's attributes |
106 // fill_in_ext_msg() writes the the values of the set's attributes |
107 // in the custom err_msg (hrl_ext_msg). fill_in_ext_msg_extra() |
107 // in the custom err_msg (hrs_ext_msg). fill_in_ext_msg_extra() |
108 // allows subclasses to append further information. |
108 // allows subclasses to append further information. |
109 virtual void fill_in_ext_msg_extra(hrl_ext_msg* msg) { } |
109 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg) { } |
110 void fill_in_ext_msg(hrl_ext_msg* msg, const char* message); |
110 void fill_in_ext_msg(hrs_ext_msg* msg, const char* message); |
111 |
111 |
112 // It updates the fields of the set to reflect hr being added to |
112 // It updates the fields of the set to reflect hr being added to |
113 // the set. |
113 // the set. |
114 inline void update_for_addition(HeapRegion* hr); |
114 inline void update_for_addition(HeapRegion* hr); |
115 |
115 |
168 // Customized err_msg for heap region sets. Apart from a |
168 // Customized err_msg for heap region sets. Apart from a |
169 // assert/guarantee-specific message it also prints out the values of |
169 // assert/guarantee-specific message it also prints out the values of |
170 // the fields of the associated set. This can be very helpful in |
170 // the fields of the associated set. This can be very helpful in |
171 // diagnosing failures. |
171 // diagnosing failures. |
172 |
172 |
173 class hrl_ext_msg : public hrl_err_msg { |
173 class hrs_ext_msg : public hrs_err_msg { |
174 public: |
174 public: |
175 hrl_ext_msg(HeapRegionSetBase* set, const char* message) : hrl_err_msg("") { |
175 hrs_ext_msg(HeapRegionSetBase* set, const char* message) : hrs_err_msg("") { |
176 set->fill_in_ext_msg(this, message); |
176 set->fill_in_ext_msg(this, message); |
177 } |
177 } |
178 }; |
178 }; |
179 |
179 |
180 // These two macros are provided for convenience, to keep the uses of |
180 // These two macros are provided for convenience, to keep the uses of |
181 // these two asserts a bit more concise. |
181 // these two asserts a bit more concise. |
182 |
182 |
183 #define hrl_assert_mt_safety_ok(_set_) \ |
183 #define hrs_assert_mt_safety_ok(_set_) \ |
184 do { \ |
184 do { \ |
185 assert((_set_)->check_mt_safety(), hrl_ext_msg((_set_), "MT safety")); \ |
185 assert((_set_)->check_mt_safety(), hrs_ext_msg((_set_), "MT safety")); \ |
186 } while (0) |
186 } while (0) |
187 |
187 |
188 #define hrl_assert_region_ok(_set_, _hr_, _expected_) \ |
188 #define hrs_assert_region_ok(_set_, _hr_, _expected_) \ |
189 do { \ |
189 do { \ |
190 assert((_set_)->verify_region((_hr_), (_expected_)), \ |
190 assert((_set_)->verify_region((_hr_), (_expected_)), \ |
191 hrl_ext_msg((_set_), "region verification")); \ |
191 hrs_ext_msg((_set_), "region verification")); \ |
192 } while (0) |
192 } while (0) |
193 |
193 |
194 //////////////////// HeapRegionSet //////////////////// |
194 //////////////////// HeapRegionSet //////////////////// |
195 |
195 |
196 #define hrl_assert_sets_match(_set1_, _set2_) \ |
196 #define hrs_assert_sets_match(_set1_, _set2_) \ |
197 do { \ |
197 do { \ |
198 assert(((_set1_)->regions_humongous() == \ |
198 assert(((_set1_)->regions_humongous() == \ |
199 (_set2_)->regions_humongous()) && \ |
199 (_set2_)->regions_humongous()) && \ |
200 ((_set1_)->regions_empty() == (_set2_)->regions_empty()), \ |
200 ((_set1_)->regions_empty() == (_set2_)->regions_empty()), \ |
201 hrl_err_msg("the contents of set %s and set %s should match", \ |
201 hrs_err_msg("the contents of set %s and set %s should match", \ |
202 (_set1_)->name(), (_set2_)->name())); \ |
202 (_set1_)->name(), (_set2_)->name())); \ |
203 } while (0) |
203 } while (0) |
204 |
204 |
205 // This class represents heap region sets whose members are not |
205 // This class represents heap region sets whose members are not |
206 // explicitly tracked. It's helpful to group regions using such sets |
206 // explicitly tracked. It's helpful to group regions using such sets |
265 // These are provided for use by the friend classes. |
265 // These are provided for use by the friend classes. |
266 HeapRegion* head() { return _head; } |
266 HeapRegion* head() { return _head; } |
267 HeapRegion* tail() { return _tail; } |
267 HeapRegion* tail() { return _tail; } |
268 |
268 |
269 protected: |
269 protected: |
270 virtual void fill_in_ext_msg_extra(hrl_ext_msg* msg); |
270 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg); |
271 |
271 |
272 // See the comment for HeapRegionSetBase::clear() |
272 // See the comment for HeapRegionSetBase::clear() |
273 virtual void clear(); |
273 virtual void clear(); |
274 |
274 |
275 HeapRegionLinkedList(const char* name) : HeapRegionSetBase(name) { |
275 HeapRegionLinkedList(const char* name) : HeapRegionSetBase(name) { |
307 virtual void verify(); |
307 virtual void verify(); |
308 |
308 |
309 virtual void print_on(outputStream* out, bool print_contents = false); |
309 virtual void print_on(outputStream* out, bool print_contents = false); |
310 }; |
310 }; |
311 |
311 |
312 //////////////////// HeapRegionLinkedList //////////////////// |
312 //////////////////// HeapRegionLinkedListIterator //////////////////// |
313 |
313 |
314 // Iterator class that provides a convenient way to iterator over the |
314 // Iterator class that provides a convenient way to iterate over the |
315 // regions in a HeapRegionLinkedList instance. |
315 // regions of a HeapRegionLinkedList instance. |
316 |
316 |
317 class HeapRegionLinkedListIterator : public StackObj { |
317 class HeapRegionLinkedListIterator : public StackObj { |
318 private: |
318 private: |
319 HeapRegionLinkedList* _list; |
319 HeapRegionLinkedList* _list; |
320 HeapRegion* _curr; |
320 HeapRegion* _curr; |