Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/heapRegionSet.hpp @ 4625:73f935f28920
in esa mode, check that values in stateAfter are all ready after LIRGen of a ValudeNode
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 17 Feb 2012 11:37:44 +0100 |
parents | 8aae2050e83e |
children | 0b3d1ec6eaee |
rev | line source |
---|---|
2152 | 1 /* |
3765
ae5b2f1dcf12
7045662: G1: OopsInHeapRegionClosure::set_region() should not be virtual
tonyp
parents:
2432
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
2152 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
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_IMPLEMENTATION_G1_HEAPREGIONSET_HPP | |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP | |
27 | |
28 #include "gc_implementation/g1/heapRegion.hpp" | |
29 | |
30 // Large buffer for some cases where the output might be larger than normal. | |
2361 | 31 #define HRS_ERR_MSG_BUFSZ 512 |
32 typedef FormatBuffer<HRS_ERR_MSG_BUFSZ> hrs_err_msg; | |
2152 | 33 |
34 // Set verification will be forced either if someone defines | |
35 // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which | |
36 // asserts are compiled in. | |
37 #ifndef HEAP_REGION_SET_FORCE_VERIFY | |
38 #define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT) | |
39 #endif // HEAP_REGION_SET_FORCE_VERIFY | |
40 | |
41 //////////////////// HeapRegionSetBase //////////////////// | |
42 | |
43 // Base class for all the classes that represent heap region sets. It | |
44 // contains the basic attributes that each set needs to maintain | |
45 // (e.g., length, region num, used bytes sum) plus any shared | |
46 // functionality (e.g., verification). | |
47 | |
2361 | 48 class hrs_ext_msg; |
2152 | 49 |
4072 | 50 typedef enum { |
51 HRSPhaseNone, | |
52 HRSPhaseEvacuation, | |
53 HRSPhaseCleanup, | |
54 HRSPhaseFullGC | |
55 } HRSPhase; | |
56 | |
57 class HRSPhaseSetter; | |
58 | |
2152 | 59 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC { |
2361 | 60 friend class hrs_ext_msg; |
4072 | 61 friend class HRSPhaseSetter; |
2152 | 62 |
63 protected: | |
64 static size_t calculate_region_num(HeapRegion* hr); | |
65 | |
66 static size_t _unrealistically_long_length; | |
67 | |
68 // The number of regions added to the set. If the set contains | |
69 // only humongous regions, this reflects only 'starts humongous' | |
70 // regions and does not include 'continues humongous' ones. | |
71 size_t _length; | |
72 | |
73 // The total number of regions represented by the set. If the set | |
74 // does not contain humongous regions, this should be the same as | |
75 // _length. If the set contains only humongous regions, this will | |
76 // include the 'continues humongous' regions. | |
77 size_t _region_num; | |
78 | |
79 // We don't keep track of the total capacity explicitly, we instead | |
80 // recalculate it based on _region_num and the heap region size. | |
81 | |
82 // The sum of used bytes in the all the regions in the set. | |
83 size_t _total_used_bytes; | |
84 | |
85 const char* _name; | |
86 | |
87 bool _verify_in_progress; | |
88 size_t _calc_length; | |
89 size_t _calc_region_num; | |
90 size_t _calc_total_capacity_bytes; | |
91 size_t _calc_total_used_bytes; | |
92 | |
4072 | 93 // This is here so that it can be used in the subclasses to assert |
94 // something different depending on which phase the GC is in. This | |
95 // can be particularly helpful in the check_mt_safety() methods. | |
96 static HRSPhase _phase; | |
97 | |
98 // Only used by HRSPhaseSetter. | |
99 static void clear_phase(); | |
100 static void set_phase(HRSPhase phase); | |
101 | |
2152 | 102 // verify_region() is used to ensure that the contents of a region |
103 // added to / removed from a set are consistent. Different sets | |
104 // make different assumptions about the regions added to them. So | |
105 // each set can override verify_region_extra(), which is called | |
106 // from verify_region(), and do any extra verification it needs to | |
107 // perform in that. | |
108 virtual const char* verify_region_extra(HeapRegion* hr) { return NULL; } | |
109 bool verify_region(HeapRegion* hr, | |
110 HeapRegionSetBase* expected_containing_set); | |
111 | |
112 // Indicates whether all regions in the set should be humongous or | |
113 // not. Only used during verification. | |
114 virtual bool regions_humongous() = 0; | |
115 | |
116 // Indicates whether all regions in the set should be empty or | |
117 // not. Only used during verification. | |
118 virtual bool regions_empty() = 0; | |
119 | |
120 // Subclasses can optionally override this to do MT safety protocol | |
121 // checks. It is called in an assert from all methods that perform | |
122 // updates on the set (and subclasses should also call it too). | |
123 virtual bool check_mt_safety() { return true; } | |
124 | |
125 // fill_in_ext_msg() writes the the values of the set's attributes | |
2361 | 126 // in the custom err_msg (hrs_ext_msg). fill_in_ext_msg_extra() |
2152 | 127 // allows subclasses to append further information. |
2361 | 128 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg) { } |
129 void fill_in_ext_msg(hrs_ext_msg* msg, const char* message); | |
2152 | 130 |
131 // It updates the fields of the set to reflect hr being added to | |
132 // the set. | |
133 inline void update_for_addition(HeapRegion* hr); | |
134 | |
135 // It updates the fields of the set to reflect hr being added to | |
136 // the set and tags the region appropriately. | |
137 inline void add_internal(HeapRegion* hr); | |
138 | |
139 // It updates the fields of the set to reflect hr being removed | |
140 // from the set. | |
141 inline void update_for_removal(HeapRegion* hr); | |
142 | |
143 // It updates the fields of the set to reflect hr being removed | |
144 // from the set and tags the region appropriately. | |
145 inline void remove_internal(HeapRegion* hr); | |
146 | |
147 // It clears all the fields of the sets. Note: it will not iterate | |
148 // over the set and remove regions from it. It assumes that the | |
149 // caller has already done so. It will literally just clear the fields. | |
150 virtual void clear(); | |
151 | |
152 HeapRegionSetBase(const char* name); | |
153 | |
154 public: | |
155 static void set_unrealistically_long_length(size_t len); | |
156 | |
157 const char* name() { return _name; } | |
158 | |
159 size_t length() { return _length; } | |
160 | |
161 bool is_empty() { return _length == 0; } | |
162 | |
163 size_t region_num() { return _region_num; } | |
164 | |
165 size_t total_capacity_bytes() { | |
166 return region_num() << HeapRegion::LogOfHRGrainBytes; | |
167 } | |
168 | |
169 size_t total_used_bytes() { return _total_used_bytes; } | |
170 | |
171 virtual void verify(); | |
172 void verify_start(); | |
173 void verify_next_region(HeapRegion* hr); | |
174 void verify_end(); | |
175 | |
176 #if HEAP_REGION_SET_FORCE_VERIFY | |
177 void verify_optional() { | |
178 verify(); | |
179 } | |
180 #else // HEAP_REGION_SET_FORCE_VERIFY | |
181 void verify_optional() { } | |
182 #endif // HEAP_REGION_SET_FORCE_VERIFY | |
183 | |
184 virtual void print_on(outputStream* out, bool print_contents = false); | |
185 }; | |
186 | |
187 // Customized err_msg for heap region sets. Apart from a | |
188 // assert/guarantee-specific message it also prints out the values of | |
189 // the fields of the associated set. This can be very helpful in | |
190 // diagnosing failures. | |
191 | |
2361 | 192 class hrs_ext_msg : public hrs_err_msg { |
2152 | 193 public: |
2361 | 194 hrs_ext_msg(HeapRegionSetBase* set, const char* message) : hrs_err_msg("") { |
2152 | 195 set->fill_in_ext_msg(this, message); |
196 } | |
197 }; | |
198 | |
4072 | 199 class HRSPhaseSetter { |
200 public: | |
201 HRSPhaseSetter(HRSPhase phase) { | |
202 HeapRegionSetBase::set_phase(phase); | |
203 } | |
204 ~HRSPhaseSetter() { | |
205 HeapRegionSetBase::clear_phase(); | |
206 } | |
207 }; | |
208 | |
2152 | 209 // These two macros are provided for convenience, to keep the uses of |
210 // these two asserts a bit more concise. | |
211 | |
2361 | 212 #define hrs_assert_mt_safety_ok(_set_) \ |
2152 | 213 do { \ |
2361 | 214 assert((_set_)->check_mt_safety(), hrs_ext_msg((_set_), "MT safety")); \ |
2152 | 215 } while (0) |
216 | |
2361 | 217 #define hrs_assert_region_ok(_set_, _hr_, _expected_) \ |
2152 | 218 do { \ |
219 assert((_set_)->verify_region((_hr_), (_expected_)), \ | |
2361 | 220 hrs_ext_msg((_set_), "region verification")); \ |
2152 | 221 } while (0) |
222 | |
223 //////////////////// HeapRegionSet //////////////////// | |
224 | |
2361 | 225 #define hrs_assert_sets_match(_set1_, _set2_) \ |
2152 | 226 do { \ |
227 assert(((_set1_)->regions_humongous() == \ | |
228 (_set2_)->regions_humongous()) && \ | |
229 ((_set1_)->regions_empty() == (_set2_)->regions_empty()), \ | |
2361 | 230 hrs_err_msg("the contents of set %s and set %s should match", \ |
2152 | 231 (_set1_)->name(), (_set2_)->name())); \ |
232 } while (0) | |
233 | |
234 // This class represents heap region sets whose members are not | |
235 // explicitly tracked. It's helpful to group regions using such sets | |
236 // so that we can reason about all the region groups in the heap using | |
237 // the same interface (namely, the HeapRegionSetBase API). | |
238 | |
239 class HeapRegionSet : public HeapRegionSetBase { | |
240 protected: | |
241 virtual const char* verify_region_extra(HeapRegion* hr) { | |
242 if (hr->next() != NULL) { | |
243 return "next() should always be NULL as we do not link the regions"; | |
244 } | |
245 | |
246 return HeapRegionSetBase::verify_region_extra(hr); | |
247 } | |
248 | |
249 HeapRegionSet(const char* name) : HeapRegionSetBase(name) { | |
250 clear(); | |
251 } | |
252 | |
253 public: | |
254 // It adds hr to the set. The region should not be a member of | |
255 // another set. | |
256 inline void add(HeapRegion* hr); | |
257 | |
258 // It removes hr from the set. The region should be a member of | |
259 // this set. | |
260 inline void remove(HeapRegion* hr); | |
261 | |
262 // It removes a region from the set. Instead of updating the fields | |
263 // of the set to reflect this removal, it accumulates the updates | |
264 // in proxy_set. The idea is that proxy_set is thread-local to | |
265 // avoid multiple threads updating the fields of the set | |
266 // concurrently and having to synchronize. The method | |
267 // update_from_proxy() will update the fields of the set from the | |
268 // proxy_set. | |
269 inline void remove_with_proxy(HeapRegion* hr, HeapRegionSet* proxy_set); | |
270 | |
271 // After multiple calls to remove_with_proxy() the updates to the | |
272 // fields of the set are accumulated in proxy_set. This call | |
273 // updates the fields of the set from proxy_set. | |
274 void update_from_proxy(HeapRegionSet* proxy_set); | |
275 }; | |
276 | |
277 //////////////////// HeapRegionLinkedList //////////////////// | |
278 | |
279 // A set that links all the regions added to it in a singly-linked | |
280 // list. We should try to avoid doing operations that iterate over | |
281 // such lists in performance critical paths. Typically we should | |
282 // add / remove one region at a time or concatenate two lists. All | |
283 // those operations are done in constant time. | |
284 | |
285 class HeapRegionLinkedListIterator; | |
286 | |
287 class HeapRegionLinkedList : public HeapRegionSetBase { | |
288 friend class HeapRegionLinkedListIterator; | |
289 | |
290 private: | |
291 HeapRegion* _head; | |
292 HeapRegion* _tail; | |
293 | |
294 // These are provided for use by the friend classes. | |
295 HeapRegion* head() { return _head; } | |
296 HeapRegion* tail() { return _tail; } | |
297 | |
298 protected: | |
2361 | 299 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg); |
2152 | 300 |
301 // See the comment for HeapRegionSetBase::clear() | |
302 virtual void clear(); | |
303 | |
304 HeapRegionLinkedList(const char* name) : HeapRegionSetBase(name) { | |
305 clear(); | |
306 } | |
307 | |
308 public: | |
2432
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
309 // It adds hr to the list as the new head. The region should not be |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
310 // a member of another set. |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
311 inline void add_as_head(HeapRegion* hr); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
312 |
2152 | 313 // It adds hr to the list as the new tail. The region should not be |
314 // a member of another set. | |
315 inline void add_as_tail(HeapRegion* hr); | |
316 | |
317 // It removes and returns the head of the list. It assumes that the | |
318 // list is not empty so it will return a non-NULL value. | |
319 inline HeapRegion* remove_head(); | |
320 | |
321 // Convenience method. | |
322 inline HeapRegion* remove_head_or_null(); | |
323 | |
324 // It moves the regions from from_list to this list and empties | |
325 // from_list. The new regions will appear in the same order as they | |
2432
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
326 // were in from_list and be linked in the beginning of this list. |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
327 void add_as_head(HeapRegionLinkedList* from_list); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
328 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
329 // It moves the regions from from_list to this list and empties |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
330 // from_list. The new regions will appear in the same order as they |
2152 | 331 // were in from_list and be linked in the end of this list. |
332 void add_as_tail(HeapRegionLinkedList* from_list); | |
333 | |
334 // It empties the list by removing all regions from it. | |
335 void remove_all(); | |
336 | |
337 // It removes all regions in the list that are pending for removal | |
338 // (i.e., they have been tagged with "pending_removal"). The list | |
339 // must not be empty, target_count should reflect the exact number | |
340 // of regions that are pending for removal in the list, and | |
341 // target_count should be > 1 (currently, we never need to remove a | |
342 // single region using this). | |
343 void remove_all_pending(size_t target_count); | |
344 | |
345 virtual void verify(); | |
346 | |
347 virtual void print_on(outputStream* out, bool print_contents = false); | |
348 }; | |
349 | |
2361 | 350 //////////////////// HeapRegionLinkedListIterator //////////////////// |
2152 | 351 |
2361 | 352 // Iterator class that provides a convenient way to iterate over the |
353 // regions of a HeapRegionLinkedList instance. | |
2152 | 354 |
355 class HeapRegionLinkedListIterator : public StackObj { | |
356 private: | |
357 HeapRegionLinkedList* _list; | |
358 HeapRegion* _curr; | |
359 | |
360 public: | |
361 bool more_available() { | |
362 return _curr != NULL; | |
363 } | |
364 | |
365 HeapRegion* get_next() { | |
366 assert(more_available(), | |
367 "get_next() should be called when more regions are available"); | |
368 | |
369 // If we are going to introduce a count in the iterator we should | |
370 // do the "cycle" check. | |
371 | |
372 HeapRegion* hr = _curr; | |
373 assert(_list->verify_region(hr, _list), "region verification"); | |
374 _curr = hr->next(); | |
375 return hr; | |
376 } | |
377 | |
378 HeapRegionLinkedListIterator(HeapRegionLinkedList* list) | |
379 : _curr(NULL), _list(list) { | |
380 _curr = list->head(); | |
381 } | |
382 }; | |
383 | |
384 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP |