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/g1CollectedHeap.inline.hpp"
27 #include "gc_implementation/g1/heapRegionRemSet.hpp"
28 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
29
30 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
31
32 uint FreeRegionList::_unrealistically_long_length = 0;
33
34 void HeapRegionSetBase::fill_in_ext_msg(hrs_ext_msg* msg, const char* message) {
35 msg->append("[%s] %s ln: %u cy: "SIZE_FORMAT,
36 name(), message, length(), total_capacity_bytes());
37 fill_in_ext_msg_extra(msg);
38 }
39
40 #ifndef PRODUCT
41 void HeapRegionSetBase::verify_region(HeapRegion* hr) {
42 assert(hr->containing_set() == this, err_msg("Inconsistent containing set for %u", hr->hrm_index()));
43 assert(!hr->is_young(), err_msg("Adding young region %u", hr->hrm_index())); // currently we don't use these sets for young regions
44 assert(hr->isHumongous() == regions_humongous(), err_msg("Wrong humongous state for region %u and set %s", hr->hrm_index(), name()));
45 assert(hr->is_free() == regions_free(), err_msg("Wrong free state for region %u and set %s", hr->hrm_index(), name()));
46 assert(!hr->is_free() || hr->is_empty(), err_msg("Free region %u is not empty for set %s", hr->hrm_index(), name()));
47 assert(!hr->is_empty() || hr->is_free(), err_msg("Empty region %u is not free for set %s", hr->hrm_index(), name()));
48 assert(hr->rem_set()->verify_ready_for_par_iteration(), err_msg("Wrong iteration state %u", hr->hrm_index()));
49 }
50 #endif
51
52 void HeapRegionSetBase::verify() {
53 // It's important that we also observe the MT safety protocol even
54 // for the verification calls. If we do verification without the
55 // appropriate locks and the set changes underneath our feet
67 assert(!_verify_in_progress,
68 hrs_ext_msg(this, "verification should not be in progress"));
69
70 // Do the basic verification first before we do the checks over the regions.
71 HeapRegionSetBase::verify();
72
73 _verify_in_progress = true;
74 }
75
76 void HeapRegionSetBase::verify_end() {
77 // See comment in verify() about MT safety and verification.
78 check_mt_safety();
79 assert(_verify_in_progress,
80 hrs_ext_msg(this, "verification should be in progress"));
81
82 _verify_in_progress = false;
83 }
84
85 void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) {
86 out->cr();
87 out->print_cr("Set: %s ("PTR_FORMAT")", name(), this);
88 out->print_cr(" Region Assumptions");
89 out->print_cr(" humongous : %s", BOOL_TO_STR(regions_humongous()));
90 out->print_cr(" free : %s", BOOL_TO_STR(regions_free()));
91 out->print_cr(" Attributes");
92 out->print_cr(" length : %14u", length());
93 out->print_cr(" total capacity : "SIZE_FORMAT_W(14)" bytes",
94 total_capacity_bytes());
95 }
96
97 HeapRegionSetBase::HeapRegionSetBase(const char* name, bool humongous, bool free, HRSMtSafeChecker* mt_safety_checker)
98 : _name(name), _verify_in_progress(false),
99 _is_humongous(humongous), _is_free(free), _mt_safety_checker(mt_safety_checker),
100 _count()
101 { }
102
103 void FreeRegionList::set_unrealistically_long_length(uint len) {
104 guarantee(_unrealistically_long_length == 0, "should only be set once");
105 _unrealistically_long_length = len;
106 }
107
108 void FreeRegionList::fill_in_ext_msg_extra(hrs_ext_msg* msg) {
109 msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, _head, _tail);
110 }
111
112 void FreeRegionList::remove_all() {
113 check_mt_safety();
114 verify_optional();
115
116 HeapRegion* curr = _head;
117 while (curr != NULL) {
118 verify_region(curr);
119
120 HeapRegion* next = curr->next();
121 curr->set_next(NULL);
122 curr->set_prev(NULL);
123 curr->set_containing_set(NULL);
124 curr = next;
125 }
126 clear();
127
128 verify_optional();
129 }
260 check_mt_safety();
261
262 // This will also do the basic verification too.
263 verify_start();
264
265 verify_list();
266
267 verify_end();
268 }
269
270 void FreeRegionList::clear() {
271 _count = HeapRegionSetCount();
272 _head = NULL;
273 _tail = NULL;
274 _last = NULL;
275 }
276
277 void FreeRegionList::print_on(outputStream* out, bool print_contents) {
278 HeapRegionSetBase::print_on(out, print_contents);
279 out->print_cr(" Linking");
280 out->print_cr(" head : "PTR_FORMAT, _head);
281 out->print_cr(" tail : "PTR_FORMAT, _tail);
282
283 if (print_contents) {
284 out->print_cr(" Contents");
285 FreeRegionListIterator iter(this);
286 while (iter.more_available()) {
287 HeapRegion* hr = iter.get_next();
288 hr->print_on(out);
289 }
290 }
291
292 out->cr();
293 }
294
295 void FreeRegionList::verify_list() {
296 HeapRegion* curr = _head;
297 HeapRegion* prev1 = NULL;
298 HeapRegion* prev0 = NULL;
299 uint count = 0;
300 size_t capacity = 0;
301 uint last_index = 0;
302
303 guarantee(_head == NULL || _head->prev() == NULL, "_head should not have a prev");
304 while (curr != NULL) {
305 verify_region(curr);
306
307 count++;
308 guarantee(count < _unrealistically_long_length,
309 hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " "prev1: "PTR_FORMAT" length: %u", name(), count, curr, prev0, prev1, length()));
310
311 if (curr->next() != NULL) {
312 guarantee(curr->next()->prev() == curr, "Next or prev pointers messed up");
313 }
314 guarantee(curr->hrm_index() == 0 || curr->hrm_index() > last_index, "List should be sorted");
315 last_index = curr->hrm_index();
316
317 capacity += curr->capacity();
318
319 prev1 = prev0;
320 prev0 = curr;
321 curr = curr->next();
322 }
323
324 guarantee(_tail == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), _tail->hrm_index(), prev0->hrm_index()));
325 guarantee(_tail == NULL || _tail->next() == NULL, "_tail should not have a next");
326 guarantee(length() == count, err_msg("%s count mismatch. Expected %u, actual %u.", name(), length(), count));
327 guarantee(total_capacity_bytes() == capacity, err_msg("%s capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
328 name(), total_capacity_bytes(), capacity));
329 }
|
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/g1CollectedHeap.inline.hpp"
27 #include "gc_implementation/g1/heapRegionRemSet.hpp"
28 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
29
30 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
31
32 uint FreeRegionList::_unrealistically_long_length = 0;
33
34 void HeapRegionSetBase::fill_in_ext_msg(hrs_ext_msg* msg, const char* message) {
35 msg->append("[%s] %s ln: %u cy: " SIZE_FORMAT,
36 name(), message, length(), total_capacity_bytes());
37 fill_in_ext_msg_extra(msg);
38 }
39
40 #ifndef PRODUCT
41 void HeapRegionSetBase::verify_region(HeapRegion* hr) {
42 assert(hr->containing_set() == this, err_msg("Inconsistent containing set for %u", hr->hrm_index()));
43 assert(!hr->is_young(), err_msg("Adding young region %u", hr->hrm_index())); // currently we don't use these sets for young regions
44 assert(hr->isHumongous() == regions_humongous(), err_msg("Wrong humongous state for region %u and set %s", hr->hrm_index(), name()));
45 assert(hr->is_free() == regions_free(), err_msg("Wrong free state for region %u and set %s", hr->hrm_index(), name()));
46 assert(!hr->is_free() || hr->is_empty(), err_msg("Free region %u is not empty for set %s", hr->hrm_index(), name()));
47 assert(!hr->is_empty() || hr->is_free(), err_msg("Empty region %u is not free for set %s", hr->hrm_index(), name()));
48 assert(hr->rem_set()->verify_ready_for_par_iteration(), err_msg("Wrong iteration state %u", hr->hrm_index()));
49 }
50 #endif
51
52 void HeapRegionSetBase::verify() {
53 // It's important that we also observe the MT safety protocol even
54 // for the verification calls. If we do verification without the
55 // appropriate locks and the set changes underneath our feet
67 assert(!_verify_in_progress,
68 hrs_ext_msg(this, "verification should not be in progress"));
69
70 // Do the basic verification first before we do the checks over the regions.
71 HeapRegionSetBase::verify();
72
73 _verify_in_progress = true;
74 }
75
76 void HeapRegionSetBase::verify_end() {
77 // See comment in verify() about MT safety and verification.
78 check_mt_safety();
79 assert(_verify_in_progress,
80 hrs_ext_msg(this, "verification should be in progress"));
81
82 _verify_in_progress = false;
83 }
84
85 void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) {
86 out->cr();
87 out->print_cr("Set: %s (" PTR_FORMAT ")", name(), this);
88 out->print_cr(" Region Assumptions");
89 out->print_cr(" humongous : %s", BOOL_TO_STR(regions_humongous()));
90 out->print_cr(" free : %s", BOOL_TO_STR(regions_free()));
91 out->print_cr(" Attributes");
92 out->print_cr(" length : %14u", length());
93 out->print_cr(" total capacity : " SIZE_FORMAT_W(14) " bytes",
94 total_capacity_bytes());
95 }
96
97 HeapRegionSetBase::HeapRegionSetBase(const char* name, bool humongous, bool free, HRSMtSafeChecker* mt_safety_checker)
98 : _name(name), _verify_in_progress(false),
99 _is_humongous(humongous), _is_free(free), _mt_safety_checker(mt_safety_checker),
100 _count()
101 { }
102
103 void FreeRegionList::set_unrealistically_long_length(uint len) {
104 guarantee(_unrealistically_long_length == 0, "should only be set once");
105 _unrealistically_long_length = len;
106 }
107
108 void FreeRegionList::fill_in_ext_msg_extra(hrs_ext_msg* msg) {
109 msg->append(" hd: " PTR_FORMAT " tl: " PTR_FORMAT, _head, _tail);
110 }
111
112 void FreeRegionList::remove_all() {
113 check_mt_safety();
114 verify_optional();
115
116 HeapRegion* curr = _head;
117 while (curr != NULL) {
118 verify_region(curr);
119
120 HeapRegion* next = curr->next();
121 curr->set_next(NULL);
122 curr->set_prev(NULL);
123 curr->set_containing_set(NULL);
124 curr = next;
125 }
126 clear();
127
128 verify_optional();
129 }
260 check_mt_safety();
261
262 // This will also do the basic verification too.
263 verify_start();
264
265 verify_list();
266
267 verify_end();
268 }
269
270 void FreeRegionList::clear() {
271 _count = HeapRegionSetCount();
272 _head = NULL;
273 _tail = NULL;
274 _last = NULL;
275 }
276
277 void FreeRegionList::print_on(outputStream* out, bool print_contents) {
278 HeapRegionSetBase::print_on(out, print_contents);
279 out->print_cr(" Linking");
280 out->print_cr(" head : " PTR_FORMAT, _head);
281 out->print_cr(" tail : " PTR_FORMAT, _tail);
282
283 if (print_contents) {
284 out->print_cr(" Contents");
285 FreeRegionListIterator iter(this);
286 while (iter.more_available()) {
287 HeapRegion* hr = iter.get_next();
288 hr->print_on(out);
289 }
290 }
291
292 out->cr();
293 }
294
295 void FreeRegionList::verify_list() {
296 HeapRegion* curr = _head;
297 HeapRegion* prev1 = NULL;
298 HeapRegion* prev0 = NULL;
299 uint count = 0;
300 size_t capacity = 0;
301 uint last_index = 0;
302
303 guarantee(_head == NULL || _head->prev() == NULL, "_head should not have a prev");
304 while (curr != NULL) {
305 verify_region(curr);
306
307 count++;
308 guarantee(count < _unrealistically_long_length,
309 hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: " PTR_FORMAT " prev0: " PTR_FORMAT " " "prev1: " PTR_FORMAT " length: %u", name(), count, curr, prev0, prev1, length()));
310
311 if (curr->next() != NULL) {
312 guarantee(curr->next()->prev() == curr, "Next or prev pointers messed up");
313 }
314 guarantee(curr->hrm_index() == 0 || curr->hrm_index() > last_index, "List should be sorted");
315 last_index = curr->hrm_index();
316
317 capacity += curr->capacity();
318
319 prev1 = prev0;
320 prev0 = curr;
321 curr = curr->next();
322 }
323
324 guarantee(_tail == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), _tail->hrm_index(), prev0->hrm_index()));
325 guarantee(_tail == NULL || _tail->next() == NULL, "_tail should not have a next");
326 guarantee(length() == count, err_msg("%s count mismatch. Expected %u, actual %u.", name(), length(), count));
327 guarantee(total_capacity_bytes() == capacity, err_msg("%s capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
328 name(), total_capacity_bytes(), capacity));
329 }
|