Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/heapRegionSet.cpp @ 8500:992f62c457b0
-More bug fixes
author | Christos Kotselidis <christos.kotselidis@oracle.com> |
---|---|
date | Tue, 05 Mar 2013 18:53:26 +0100 |
parents | a2f7274eb6ef |
children | 86b4965f0c9a |
rev | line source |
---|---|
2152 | 1 /* |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
2 * Copyright (c) 2011, 2012, 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 #include "precompiled.hpp" | |
26 #include "gc_implementation/g1/heapRegionSet.inline.hpp" | |
27 | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
28 uint HeapRegionSetBase::_unrealistically_long_length = 0; |
4072 | 29 HRSPhase HeapRegionSetBase::_phase = HRSPhaseNone; |
2152 | 30 |
31 //////////////////// HeapRegionSetBase //////////////////// | |
32 | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
33 void HeapRegionSetBase::set_unrealistically_long_length(uint len) { |
2152 | 34 guarantee(_unrealistically_long_length == 0, "should only be set once"); |
35 _unrealistically_long_length = len; | |
36 } | |
37 | |
2361 | 38 void HeapRegionSetBase::fill_in_ext_msg(hrs_ext_msg* msg, const char* message) { |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
39 msg->append("[%s] %s ln: %u rn: %u cy: "SIZE_FORMAT" ud: "SIZE_FORMAT, |
2152 | 40 name(), message, length(), region_num(), |
41 total_capacity_bytes(), total_used_bytes()); | |
42 fill_in_ext_msg_extra(msg); | |
43 } | |
44 | |
45 bool HeapRegionSetBase::verify_region(HeapRegion* hr, | |
46 HeapRegionSetBase* expected_containing_set) { | |
47 const char* error_message = NULL; | |
48 | |
49 if (!regions_humongous()) { | |
50 if (hr->isHumongous()) { | |
51 error_message = "the region should not be humongous"; | |
52 } | |
53 } else { | |
54 if (!hr->isHumongous() || !hr->startsHumongous()) { | |
55 error_message = "the region should be 'starts humongous'"; | |
56 } | |
57 } | |
58 | |
59 if (!regions_empty()) { | |
60 if (hr->is_empty()) { | |
61 error_message = "the region should not be empty"; | |
62 } | |
63 } else { | |
64 if (!hr->is_empty()) { | |
65 error_message = "the region should be empty"; | |
66 } | |
67 } | |
68 | |
69 #ifdef ASSERT | |
70 // The _containing_set field is only available when ASSERT is defined. | |
71 if (hr->containing_set() != expected_containing_set) { | |
72 error_message = "inconsistent containing set found"; | |
73 } | |
74 #endif // ASSERT | |
75 | |
76 const char* extra_error_message = verify_region_extra(hr); | |
77 if (extra_error_message != NULL) { | |
78 error_message = extra_error_message; | |
79 } | |
80 | |
81 if (error_message != NULL) { | |
82 outputStream* out = tty; | |
83 out->cr(); | |
84 out->print_cr("## [%s] %s", name(), error_message); | |
85 out->print_cr("## Offending Region: "PTR_FORMAT, hr); | |
86 out->print_cr(" "HR_FORMAT, HR_FORMAT_PARAMS(hr)); | |
87 #ifdef ASSERT | |
88 out->print_cr(" containing set: "PTR_FORMAT, hr->containing_set()); | |
89 #endif // ASSERT | |
90 out->print_cr("## Offending Region Set: "PTR_FORMAT, this); | |
91 print_on(out); | |
92 return false; | |
93 } else { | |
94 return true; | |
95 } | |
96 } | |
97 | |
98 void HeapRegionSetBase::verify() { | |
99 // It's important that we also observe the MT safety protocol even | |
100 // for the verification calls. If we do verification without the | |
101 // appropriate locks and the set changes underneath our feet | |
102 // verification might fail and send us on a wild goose chase. | |
2361 | 103 hrs_assert_mt_safety_ok(this); |
2152 | 104 |
105 guarantee(( is_empty() && length() == 0 && region_num() == 0 && | |
106 total_used_bytes() == 0 && total_capacity_bytes() == 0) || | |
107 (!is_empty() && length() >= 0 && region_num() >= 0 && | |
108 total_used_bytes() >= 0 && total_capacity_bytes() >= 0), | |
2361 | 109 hrs_ext_msg(this, "invariant")); |
2152 | 110 |
111 guarantee((!regions_humongous() && region_num() == length()) || | |
112 ( regions_humongous() && region_num() >= length()), | |
2361 | 113 hrs_ext_msg(this, "invariant")); |
2152 | 114 |
8500
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
115 printf("region name %s\n", this->name()); |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
116 printf("regions empty? %d\n", regions_empty()); |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
117 printf("total used bytes %lu\n", total_used_bytes()); |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
118 |
2152 | 119 guarantee(!regions_empty() || total_used_bytes() == 0, |
2361 | 120 hrs_ext_msg(this, "invariant")); |
2152 | 121 |
122 guarantee(total_used_bytes() <= total_capacity_bytes(), | |
2361 | 123 hrs_ext_msg(this, "invariant")); |
2152 | 124 } |
125 | |
126 void HeapRegionSetBase::verify_start() { | |
127 // See comment in verify() about MT safety and verification. | |
2361 | 128 hrs_assert_mt_safety_ok(this); |
2152 | 129 assert(!_verify_in_progress, |
2361 | 130 hrs_ext_msg(this, "verification should not be in progress")); |
2152 | 131 |
132 // Do the basic verification first before we do the checks over the regions. | |
8500
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
133 //HeapRegionSetBase::verify(); |
2152 | 134 |
135 _calc_length = 0; | |
136 _calc_region_num = 0; | |
137 _calc_total_capacity_bytes = 0; | |
138 _calc_total_used_bytes = 0; | |
139 _verify_in_progress = true; | |
140 } | |
141 | |
142 void HeapRegionSetBase::verify_next_region(HeapRegion* hr) { | |
143 // See comment in verify() about MT safety and verification. | |
2361 | 144 hrs_assert_mt_safety_ok(this); |
2152 | 145 assert(_verify_in_progress, |
2361 | 146 hrs_ext_msg(this, "verification should be in progress")); |
2152 | 147 |
2361 | 148 guarantee(verify_region(hr, this), hrs_ext_msg(this, "region verification")); |
2152 | 149 |
150 _calc_length += 1; | |
6254
a2f7274eb6ef
7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents:
6252
diff
changeset
|
151 _calc_region_num += hr->region_num(); |
2152 | 152 _calc_total_capacity_bytes += hr->capacity(); |
153 _calc_total_used_bytes += hr->used(); | |
154 } | |
155 | |
156 void HeapRegionSetBase::verify_end() { | |
157 // See comment in verify() about MT safety and verification. | |
2361 | 158 hrs_assert_mt_safety_ok(this); |
2152 | 159 assert(_verify_in_progress, |
2361 | 160 hrs_ext_msg(this, "verification should be in progress")); |
2152 | 161 |
162 guarantee(length() == _calc_length, | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
163 hrs_err_msg("[%s] length: %u should be == calc length: %u", |
2152 | 164 name(), length(), _calc_length)); |
165 | |
166 guarantee(region_num() == _calc_region_num, | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
167 hrs_err_msg("[%s] region num: %u should be == calc region num: %u", |
2152 | 168 name(), region_num(), _calc_region_num)); |
169 | |
170 guarantee(total_capacity_bytes() == _calc_total_capacity_bytes, | |
2361 | 171 hrs_err_msg("[%s] capacity bytes: "SIZE_FORMAT" should be == " |
2152 | 172 "calc capacity bytes: "SIZE_FORMAT, |
173 name(), | |
174 total_capacity_bytes(), _calc_total_capacity_bytes)); | |
175 | |
176 guarantee(total_used_bytes() == _calc_total_used_bytes, | |
2361 | 177 hrs_err_msg("[%s] used bytes: "SIZE_FORMAT" should be == " |
2152 | 178 "calc used bytes: "SIZE_FORMAT, |
179 name(), total_used_bytes(), _calc_total_used_bytes)); | |
180 | |
181 _verify_in_progress = false; | |
182 } | |
183 | |
4072 | 184 void HeapRegionSetBase::clear_phase() { |
185 assert(_phase != HRSPhaseNone, "pre-condition"); | |
186 _phase = HRSPhaseNone; | |
187 } | |
188 | |
189 void HeapRegionSetBase::set_phase(HRSPhase phase) { | |
190 assert(_phase == HRSPhaseNone, "pre-condition"); | |
191 assert(phase != HRSPhaseNone, "pre-condition"); | |
192 _phase = phase; | |
193 } | |
194 | |
2152 | 195 void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) { |
196 out->cr(); | |
197 out->print_cr("Set: %s ("PTR_FORMAT")", name(), this); | |
198 out->print_cr(" Region Assumptions"); | |
199 out->print_cr(" humongous : %s", BOOL_TO_STR(regions_humongous())); | |
200 out->print_cr(" empty : %s", BOOL_TO_STR(regions_empty())); | |
201 out->print_cr(" Attributes"); | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
202 out->print_cr(" length : %14u", length()); |
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
203 out->print_cr(" region num : %14u", region_num()); |
2152 | 204 out->print_cr(" total capacity : "SIZE_FORMAT_W(14)" bytes", |
205 total_capacity_bytes()); | |
206 out->print_cr(" total used : "SIZE_FORMAT_W(14)" bytes", | |
207 total_used_bytes()); | |
208 } | |
209 | |
210 void HeapRegionSetBase::clear() { | |
211 _length = 0; | |
212 _region_num = 0; | |
213 _total_used_bytes = 0; | |
214 } | |
215 | |
216 HeapRegionSetBase::HeapRegionSetBase(const char* name) | |
217 : _name(name), _verify_in_progress(false), | |
218 _calc_length(0), _calc_region_num(0), | |
219 _calc_total_capacity_bytes(0), _calc_total_used_bytes(0) { } | |
220 | |
221 //////////////////// HeapRegionSet //////////////////// | |
222 | |
223 void HeapRegionSet::update_from_proxy(HeapRegionSet* proxy_set) { | |
2361 | 224 hrs_assert_mt_safety_ok(this); |
225 hrs_assert_mt_safety_ok(proxy_set); | |
226 hrs_assert_sets_match(this, proxy_set); | |
2152 | 227 |
228 verify_optional(); | |
229 proxy_set->verify_optional(); | |
230 | |
231 if (proxy_set->is_empty()) return; | |
232 | |
233 assert(proxy_set->length() <= _length, | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
234 hrs_err_msg("[%s] proxy set length: %u should be <= length: %u", |
2152 | 235 name(), proxy_set->length(), _length)); |
236 _length -= proxy_set->length(); | |
237 | |
238 assert(proxy_set->region_num() <= _region_num, | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
239 hrs_err_msg("[%s] proxy set region num: %u should be <= region num: %u", |
2152 | 240 name(), proxy_set->region_num(), _region_num)); |
241 _region_num -= proxy_set->region_num(); | |
242 | |
243 assert(proxy_set->total_used_bytes() <= _total_used_bytes, | |
2361 | 244 hrs_err_msg("[%s] proxy set used bytes: "SIZE_FORMAT" " |
2152 | 245 "should be <= used bytes: "SIZE_FORMAT, |
246 name(), proxy_set->total_used_bytes(), | |
247 _total_used_bytes)); | |
248 _total_used_bytes -= proxy_set->total_used_bytes(); | |
249 | |
250 proxy_set->clear(); | |
251 | |
252 verify_optional(); | |
253 proxy_set->verify_optional(); | |
254 } | |
255 | |
256 //////////////////// HeapRegionLinkedList //////////////////// | |
257 | |
2361 | 258 void HeapRegionLinkedList::fill_in_ext_msg_extra(hrs_ext_msg* msg) { |
2152 | 259 msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, head(), tail()); |
260 } | |
261 | |
2432
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
262 void HeapRegionLinkedList::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
|
263 hrs_assert_mt_safety_ok(this); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
264 hrs_assert_mt_safety_ok(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
|
265 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
266 verify_optional(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
267 from_list->verify_optional(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
268 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
269 if (from_list->is_empty()) return; |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
270 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
271 #ifdef ASSERT |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
272 HeapRegionLinkedListIterator iter(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
|
273 while (iter.more_available()) { |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
274 HeapRegion* hr = iter.get_next(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
275 // In set_containing_set() we check that we either set the value |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
276 // from NULL to non-NULL or vice versa to catch bugs. So, we have |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
277 // to NULL it first before setting it to the value. |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
278 hr->set_containing_set(NULL); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
279 hr->set_containing_set(this); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
280 } |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
281 #endif // ASSERT |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
282 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
283 if (_head != NULL) { |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
284 assert(length() > 0 && _tail != NULL, hrs_ext_msg(this, "invariant")); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
285 from_list->_tail->set_next(_head); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
286 } else { |
6252
d42fe3c3001d
7184772: G1: Incorrect assert in HeapRegionLinkedList::add_as_head()
johnc
parents:
6010
diff
changeset
|
287 assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant")); |
2432
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
288 _tail = from_list->_tail; |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
289 } |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
290 _head = from_list->_head; |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
291 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
292 _length += from_list->length(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
293 _region_num += from_list->region_num(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
294 _total_used_bytes += from_list->total_used_bytes(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
295 from_list->clear(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
296 |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
297 verify_optional(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
298 from_list->verify_optional(); |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
299 } |
455328d90876
7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents:
2361
diff
changeset
|
300 |
2152 | 301 void HeapRegionLinkedList::add_as_tail(HeapRegionLinkedList* from_list) { |
2361 | 302 hrs_assert_mt_safety_ok(this); |
303 hrs_assert_mt_safety_ok(from_list); | |
2152 | 304 |
305 verify_optional(); | |
306 from_list->verify_optional(); | |
307 | |
308 if (from_list->is_empty()) return; | |
309 | |
310 #ifdef ASSERT | |
311 HeapRegionLinkedListIterator iter(from_list); | |
312 while (iter.more_available()) { | |
313 HeapRegion* hr = iter.get_next(); | |
314 // In set_containing_set() we check that we either set the value | |
315 // from NULL to non-NULL or vice versa to catch bugs. So, we have | |
316 // to NULL it first before setting it to the value. | |
317 hr->set_containing_set(NULL); | |
318 hr->set_containing_set(this); | |
319 } | |
320 #endif // ASSERT | |
321 | |
322 if (_tail != NULL) { | |
2361 | 323 assert(length() > 0 && _head != NULL, hrs_ext_msg(this, "invariant")); |
2152 | 324 _tail->set_next(from_list->_head); |
325 } else { | |
2361 | 326 assert(length() == 0 && _head == NULL, hrs_ext_msg(this, "invariant")); |
2152 | 327 _head = from_list->_head; |
328 } | |
329 _tail = from_list->_tail; | |
330 | |
331 _length += from_list->length(); | |
332 _region_num += from_list->region_num(); | |
333 _total_used_bytes += from_list->total_used_bytes(); | |
334 from_list->clear(); | |
335 | |
336 verify_optional(); | |
337 from_list->verify_optional(); | |
338 } | |
339 | |
340 void HeapRegionLinkedList::remove_all() { | |
2361 | 341 hrs_assert_mt_safety_ok(this); |
2152 | 342 verify_optional(); |
343 | |
344 HeapRegion* curr = _head; | |
345 while (curr != NULL) { | |
2361 | 346 hrs_assert_region_ok(this, curr, this); |
2152 | 347 |
348 HeapRegion* next = curr->next(); | |
349 curr->set_next(NULL); | |
350 curr->set_containing_set(NULL); | |
351 curr = next; | |
352 } | |
353 clear(); | |
354 | |
355 verify_optional(); | |
356 } | |
357 | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
358 void HeapRegionLinkedList::remove_all_pending(uint target_count) { |
2361 | 359 hrs_assert_mt_safety_ok(this); |
360 assert(target_count > 1, hrs_ext_msg(this, "pre-condition")); | |
361 assert(!is_empty(), hrs_ext_msg(this, "pre-condition")); | |
2152 | 362 |
363 verify_optional(); | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
364 DEBUG_ONLY(uint old_length = length();) |
2152 | 365 |
366 HeapRegion* curr = _head; | |
367 HeapRegion* prev = NULL; | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
368 uint count = 0; |
2152 | 369 while (curr != NULL) { |
2361 | 370 hrs_assert_region_ok(this, curr, this); |
2152 | 371 HeapRegion* next = curr->next(); |
372 | |
373 if (curr->pending_removal()) { | |
374 assert(count < target_count, | |
2361 | 375 hrs_err_msg("[%s] should not come across more regions " |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
376 "pending for removal than target_count: %u", |
2152 | 377 name(), target_count)); |
378 | |
379 if (prev == NULL) { | |
2361 | 380 assert(_head == curr, hrs_ext_msg(this, "invariant")); |
2152 | 381 _head = next; |
382 } else { | |
2361 | 383 assert(_head != curr, hrs_ext_msg(this, "invariant")); |
2152 | 384 prev->set_next(next); |
385 } | |
386 if (next == NULL) { | |
2361 | 387 assert(_tail == curr, hrs_ext_msg(this, "invariant")); |
2152 | 388 _tail = prev; |
389 } else { | |
2361 | 390 assert(_tail != curr, hrs_ext_msg(this, "invariant")); |
2152 | 391 } |
392 | |
393 curr->set_next(NULL); | |
394 remove_internal(curr); | |
395 curr->set_pending_removal(false); | |
396 | |
397 count += 1; | |
398 | |
399 // If we have come across the target number of regions we can | |
400 // just bail out. However, for debugging purposes, we can just | |
401 // carry on iterating to make sure there are not more regions | |
402 // tagged with pending removal. | |
403 DEBUG_ONLY(if (count == target_count) break;) | |
404 } else { | |
405 prev = curr; | |
406 } | |
407 curr = next; | |
408 } | |
409 | |
410 assert(count == target_count, | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
411 hrs_err_msg("[%s] count: %u should be == target_count: %u", |
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
412 name(), count, target_count)); |
2152 | 413 assert(length() + target_count == old_length, |
2361 | 414 hrs_err_msg("[%s] new length should be consistent " |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
415 "new length: %u old length: %u target_count: %u", |
2152 | 416 name(), length(), old_length, target_count)); |
417 | |
418 verify_optional(); | |
419 } | |
420 | |
421 void HeapRegionLinkedList::verify() { | |
422 // See comment in HeapRegionSetBase::verify() about MT safety and | |
423 // verification. | |
2361 | 424 hrs_assert_mt_safety_ok(this); |
2152 | 425 |
426 // This will also do the basic verification too. | |
427 verify_start(); | |
428 | |
429 HeapRegion* curr = _head; | |
430 HeapRegion* prev1 = NULL; | |
431 HeapRegion* prev0 = NULL; | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
432 uint count = 0; |
2152 | 433 while (curr != NULL) { |
434 verify_next_region(curr); | |
435 | |
436 count += 1; | |
437 guarantee(count < _unrealistically_long_length, | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
438 hrs_err_msg("[%s] the calculated length: %u " |
2152 | 439 "seems very long, is there maybe a cycle? " |
440 "curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " | |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
4072
diff
changeset
|
441 "prev1: "PTR_FORMAT" length: %u", |
2152 | 442 name(), count, curr, prev0, prev1, length())); |
443 | |
8500
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
444 //printf("[%s] the calculated length: %u " |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
445 // "just print " |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
446 // "curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
447 // "prev1: "PTR_FORMAT" length: %u used: %lu\n", |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
448 // name(), count, (unsigned long)curr, (unsigned long)prev0, (unsigned long)prev1, length(), curr->used()); |
992f62c457b0
-More bug fixes
Christos Kotselidis <christos.kotselidis@oracle.com>
parents:
6254
diff
changeset
|
449 curr->print(); |
2152 | 450 prev1 = prev0; |
451 prev0 = curr; | |
452 curr = curr->next(); | |
453 } | |
454 | |
2361 | 455 guarantee(_tail == prev0, hrs_ext_msg(this, "post-condition")); |
2152 | 456 |
457 verify_end(); | |
458 } | |
459 | |
460 void HeapRegionLinkedList::clear() { | |
461 HeapRegionSetBase::clear(); | |
462 _head = NULL; | |
463 _tail = NULL; | |
464 } | |
465 | |
466 void HeapRegionLinkedList::print_on(outputStream* out, bool print_contents) { | |
467 HeapRegionSetBase::print_on(out, print_contents); | |
468 out->print_cr(" Linking"); | |
469 out->print_cr(" head : "PTR_FORMAT, _head); | |
470 out->print_cr(" tail : "PTR_FORMAT, _tail); | |
471 | |
472 if (print_contents) { | |
473 out->print_cr(" Contents"); | |
474 HeapRegionLinkedListIterator iter(this); | |
475 while (iter.more_available()) { | |
476 HeapRegion* hr = iter.get_next(); | |
477 hr->print_on(out); | |
478 } | |
479 } | |
480 } |