256
257 class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
258 HeapRegion* _hr;
259 public:
260 VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
261 : _hr(hr) { }
262 // Verify that all object pointers are to archive regions.
263 void do_object(oop o) {
264 VerifyArchiveOopClosure checkOop(_hr);
265 assert(o != NULL, "Should not be here for NULL oops");
266 o->oop_iterate_no_header(&checkOop);
267 }
268 };
269
270 // Should be only used at CDS dump time
271 class VerifyArchivePointerRegionClosure: public HeapRegionClosure {
272 private:
273 G1CollectedHeap* _g1h;
274 public:
275 VerifyArchivePointerRegionClosure(G1CollectedHeap* g1h) { }
276 virtual bool doHeapRegion(HeapRegion* r) {
277 if (r->is_archive()) {
278 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
279 r->object_iterate(&verify_oop_pointers);
280 }
281 return false;
282 }
283 };
284
285 void G1HeapVerifier::verify_archive_regions() {
286 G1CollectedHeap* g1h = G1CollectedHeap::heap();
287 VerifyArchivePointerRegionClosure cl(NULL);
288 g1h->heap_region_iterate(&cl);
289 }
290
291 class VerifyRegionClosure: public HeapRegionClosure {
292 private:
293 bool _par;
294 VerifyOption _vo;
295 bool _failures;
296 public:
297 // _vo == UsePrevMarking -> use "prev" marking information,
298 // _vo == UseNextMarking -> use "next" marking information,
299 // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
300 VerifyRegionClosure(bool par, VerifyOption vo)
301 : _par(par),
302 _vo(vo),
303 _failures(false) {}
304
305 bool failures() {
306 return _failures;
307 }
308
309 bool doHeapRegion(HeapRegion* r) {
310 // For archive regions, verify there are no heap pointers to
311 // non-pinned regions. For all others, verify liveness info.
312 if (r->is_closed_archive()) {
313 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
314 r->object_iterate(&verify_oop_pointers);
315 return true;
316 } else if (r->is_open_archive()) {
317 VerifyObjsInRegionClosure verify_open_archive_oop(r, _vo);
318 r->object_iterate(&verify_open_archive_oop);
319 return true;
320 } else if (!r->is_continues_humongous()) {
321 bool failures = false;
322 r->verify(_vo, &failures);
323 if (failures) {
324 _failures = true;
325 } else if (!r->is_starts_humongous()) {
326 VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo);
327 r->object_iterate(¬_dead_yet_cl);
328 if (_vo != VerifyOption_G1UseNextMarking) {
329 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) {
481
482 // Heap region set verification
483
484 class VerifyRegionListsClosure : public HeapRegionClosure {
485 private:
486 HeapRegionSet* _old_set;
487 HeapRegionSet* _humongous_set;
488 HeapRegionManager* _hrm;
489
490 public:
491 uint _old_count;
492 uint _humongous_count;
493 uint _free_count;
494
495 VerifyRegionListsClosure(HeapRegionSet* old_set,
496 HeapRegionSet* humongous_set,
497 HeapRegionManager* hrm) :
498 _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
499 _old_count(), _humongous_count(), _free_count(){ }
500
501 bool doHeapRegion(HeapRegion* hr) {
502 if (hr->is_young()) {
503 // TODO
504 } else if (hr->is_humongous()) {
505 assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
506 _humongous_count++;
507 } else if (hr->is_empty()) {
508 assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
509 _free_count++;
510 } else if (hr->is_old()) {
511 assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
512 _old_count++;
513 } else {
514 // There are no other valid region types. Check for one invalid
515 // one we can identify: pinned without old or humongous set.
516 assert(!hr->is_pinned(), "Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index());
517 ShouldNotReachHere();
518 }
519 return false;
520 }
521
591 double verify_time_ms = verify(type, VerifyOption_G1UsePrevMarking, "Before GC");
592 _g1h->g1_policy()->phase_times()->record_verify_before_time_ms(verify_time_ms);
593 }
594 }
595
596 void G1HeapVerifier::verify_after_gc(G1VerifyType type) {
597 if (VerifyAfterGC) {
598 double verify_time_ms = verify(type, VerifyOption_G1UsePrevMarking, "After GC");
599 _g1h->g1_policy()->phase_times()->record_verify_after_time_ms(verify_time_ms);
600 }
601 }
602
603
604 #ifndef PRODUCT
605 class G1VerifyCardTableCleanup: public HeapRegionClosure {
606 G1HeapVerifier* _verifier;
607 G1SATBCardTableModRefBS* _ct_bs;
608 public:
609 G1VerifyCardTableCleanup(G1HeapVerifier* verifier, G1SATBCardTableModRefBS* ct_bs)
610 : _verifier(verifier), _ct_bs(ct_bs) { }
611 virtual bool doHeapRegion(HeapRegion* r) {
612 if (r->is_survivor()) {
613 _verifier->verify_dirty_region(r);
614 } else {
615 _verifier->verify_not_dirty_region(r);
616 }
617 return false;
618 }
619 };
620
621 void G1HeapVerifier::verify_card_table_cleanup() {
622 if (G1VerifyCTCleanup || VerifyAfterGC) {
623 G1VerifyCardTableCleanup cleanup_verifier(this, _g1h->g1_barrier_set());
624 _g1h->heap_region_iterate(&cleanup_verifier);
625 }
626 }
627
628 void G1HeapVerifier::verify_not_dirty_region(HeapRegion* hr) {
629 // All of the region should be clean.
630 G1SATBCardTableModRefBS* ct_bs = _g1h->g1_barrier_set();
631 MemRegion mr(hr->bottom(), hr->end());
637 // dirty allocated blocks as they allocate them. The thread that
638 // retires each region and replaces it with a new one will do a
639 // maximal allocation to fill in [pre_dummy_top(),end()] but will
640 // not dirty that area (one less thing to have to do while holding
641 // a lock). So we can only verify that [bottom(),pre_dummy_top()]
642 // is dirty.
643 G1SATBCardTableModRefBS* ct_bs = _g1h->g1_barrier_set();
644 MemRegion mr(hr->bottom(), hr->pre_dummy_top());
645 if (hr->is_young()) {
646 ct_bs->verify_g1_young_region(mr);
647 } else {
648 ct_bs->verify_dirty_region(mr);
649 }
650 }
651
652 class G1VerifyDirtyYoungListClosure : public HeapRegionClosure {
653 private:
654 G1HeapVerifier* _verifier;
655 public:
656 G1VerifyDirtyYoungListClosure(G1HeapVerifier* verifier) : HeapRegionClosure(), _verifier(verifier) { }
657 virtual bool doHeapRegion(HeapRegion* r) {
658 _verifier->verify_dirty_region(r);
659 return false;
660 }
661 };
662
663 void G1HeapVerifier::verify_dirty_young_regions() {
664 G1VerifyDirtyYoungListClosure cl(this);
665 _g1h->collection_set()->iterate(&cl);
666 }
667
668 bool G1HeapVerifier::verify_no_bits_over_tams(const char* bitmap_name, const G1CMBitMap* const bitmap,
669 HeapWord* tams, HeapWord* end) {
670 guarantee(tams <= end,
671 "tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end));
672 HeapWord* result = bitmap->get_next_marked_addr(tams, end);
673 if (result < end) {
674 log_error(gc, verify)("## wrong marked address on %s bitmap: " PTR_FORMAT, bitmap_name, p2i(result));
675 log_error(gc, verify)("## %s tams: " PTR_FORMAT " end: " PTR_FORMAT, bitmap_name, p2i(tams), p2i(end));
676 return false;
677 }
704 }
705
706 void G1HeapVerifier::check_bitmaps(const char* caller, HeapRegion* hr) {
707 if (!G1VerifyBitmaps) return;
708
709 guarantee(verify_bitmaps(caller, hr), "bitmap verification");
710 }
711
712 class G1VerifyBitmapClosure : public HeapRegionClosure {
713 private:
714 const char* _caller;
715 G1HeapVerifier* _verifier;
716 bool _failures;
717
718 public:
719 G1VerifyBitmapClosure(const char* caller, G1HeapVerifier* verifier) :
720 _caller(caller), _verifier(verifier), _failures(false) { }
721
722 bool failures() { return _failures; }
723
724 virtual bool doHeapRegion(HeapRegion* hr) {
725 bool result = _verifier->verify_bitmaps(_caller, hr);
726 if (!result) {
727 _failures = true;
728 }
729 return false;
730 }
731 };
732
733 void G1HeapVerifier::check_bitmaps(const char* caller) {
734 if (!G1VerifyBitmaps) return;
735
736 G1VerifyBitmapClosure cl(caller, this);
737 _g1h->heap_region_iterate(&cl);
738 guarantee(!cl.failures(), "bitmap verification");
739 }
740
741 class G1CheckCSetFastTableClosure : public HeapRegionClosure {
742 private:
743 bool _failures;
744 public:
745 G1CheckCSetFastTableClosure() : HeapRegionClosure(), _failures(false) { }
746
747 virtual bool doHeapRegion(HeapRegion* hr) {
748 uint i = hr->hrm_index();
749 InCSetState cset_state = (InCSetState) G1CollectedHeap::heap()->_in_cset_fast_test.get_by_index(i);
750 if (hr->is_humongous()) {
751 if (hr->in_collection_set()) {
752 log_error(gc, verify)("## humongous region %u in CSet", i);
753 _failures = true;
754 return true;
755 }
756 if (cset_state.is_in_cset()) {
757 log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for humongous region %u", cset_state.value(), i);
758 _failures = true;
759 return true;
760 }
761 if (hr->is_continues_humongous() && cset_state.is_humongous()) {
762 log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for continues humongous region %u", cset_state.value(), i);
763 _failures = true;
764 return true;
765 }
766 } else {
767 if (cset_state.is_humongous()) {
|
256
257 class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
258 HeapRegion* _hr;
259 public:
260 VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
261 : _hr(hr) { }
262 // Verify that all object pointers are to archive regions.
263 void do_object(oop o) {
264 VerifyArchiveOopClosure checkOop(_hr);
265 assert(o != NULL, "Should not be here for NULL oops");
266 o->oop_iterate_no_header(&checkOop);
267 }
268 };
269
270 // Should be only used at CDS dump time
271 class VerifyArchivePointerRegionClosure: public HeapRegionClosure {
272 private:
273 G1CollectedHeap* _g1h;
274 public:
275 VerifyArchivePointerRegionClosure(G1CollectedHeap* g1h) { }
276 virtual bool do_heap_region(HeapRegion* r) {
277 if (r->is_archive()) {
278 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
279 r->object_iterate(&verify_oop_pointers);
280 }
281 return false;
282 }
283 };
284
285 void G1HeapVerifier::verify_archive_regions() {
286 G1CollectedHeap* g1h = G1CollectedHeap::heap();
287 VerifyArchivePointerRegionClosure cl(NULL);
288 g1h->heap_region_iterate(&cl);
289 }
290
291 class VerifyRegionClosure: public HeapRegionClosure {
292 private:
293 bool _par;
294 VerifyOption _vo;
295 bool _failures;
296 public:
297 // _vo == UsePrevMarking -> use "prev" marking information,
298 // _vo == UseNextMarking -> use "next" marking information,
299 // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
300 VerifyRegionClosure(bool par, VerifyOption vo)
301 : _par(par),
302 _vo(vo),
303 _failures(false) {}
304
305 bool failures() {
306 return _failures;
307 }
308
309 bool do_heap_region(HeapRegion* r) {
310 // For archive regions, verify there are no heap pointers to
311 // non-pinned regions. For all others, verify liveness info.
312 if (r->is_closed_archive()) {
313 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
314 r->object_iterate(&verify_oop_pointers);
315 return true;
316 } else if (r->is_open_archive()) {
317 VerifyObjsInRegionClosure verify_open_archive_oop(r, _vo);
318 r->object_iterate(&verify_open_archive_oop);
319 return true;
320 } else if (!r->is_continues_humongous()) {
321 bool failures = false;
322 r->verify(_vo, &failures);
323 if (failures) {
324 _failures = true;
325 } else if (!r->is_starts_humongous()) {
326 VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo);
327 r->object_iterate(¬_dead_yet_cl);
328 if (_vo != VerifyOption_G1UseNextMarking) {
329 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) {
481
482 // Heap region set verification
483
484 class VerifyRegionListsClosure : public HeapRegionClosure {
485 private:
486 HeapRegionSet* _old_set;
487 HeapRegionSet* _humongous_set;
488 HeapRegionManager* _hrm;
489
490 public:
491 uint _old_count;
492 uint _humongous_count;
493 uint _free_count;
494
495 VerifyRegionListsClosure(HeapRegionSet* old_set,
496 HeapRegionSet* humongous_set,
497 HeapRegionManager* hrm) :
498 _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
499 _old_count(), _humongous_count(), _free_count(){ }
500
501 bool do_heap_region(HeapRegion* hr) {
502 if (hr->is_young()) {
503 // TODO
504 } else if (hr->is_humongous()) {
505 assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
506 _humongous_count++;
507 } else if (hr->is_empty()) {
508 assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
509 _free_count++;
510 } else if (hr->is_old()) {
511 assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
512 _old_count++;
513 } else {
514 // There are no other valid region types. Check for one invalid
515 // one we can identify: pinned without old or humongous set.
516 assert(!hr->is_pinned(), "Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index());
517 ShouldNotReachHere();
518 }
519 return false;
520 }
521
591 double verify_time_ms = verify(type, VerifyOption_G1UsePrevMarking, "Before GC");
592 _g1h->g1_policy()->phase_times()->record_verify_before_time_ms(verify_time_ms);
593 }
594 }
595
596 void G1HeapVerifier::verify_after_gc(G1VerifyType type) {
597 if (VerifyAfterGC) {
598 double verify_time_ms = verify(type, VerifyOption_G1UsePrevMarking, "After GC");
599 _g1h->g1_policy()->phase_times()->record_verify_after_time_ms(verify_time_ms);
600 }
601 }
602
603
604 #ifndef PRODUCT
605 class G1VerifyCardTableCleanup: public HeapRegionClosure {
606 G1HeapVerifier* _verifier;
607 G1SATBCardTableModRefBS* _ct_bs;
608 public:
609 G1VerifyCardTableCleanup(G1HeapVerifier* verifier, G1SATBCardTableModRefBS* ct_bs)
610 : _verifier(verifier), _ct_bs(ct_bs) { }
611 virtual bool do_heap_region(HeapRegion* r) {
612 if (r->is_survivor()) {
613 _verifier->verify_dirty_region(r);
614 } else {
615 _verifier->verify_not_dirty_region(r);
616 }
617 return false;
618 }
619 };
620
621 void G1HeapVerifier::verify_card_table_cleanup() {
622 if (G1VerifyCTCleanup || VerifyAfterGC) {
623 G1VerifyCardTableCleanup cleanup_verifier(this, _g1h->g1_barrier_set());
624 _g1h->heap_region_iterate(&cleanup_verifier);
625 }
626 }
627
628 void G1HeapVerifier::verify_not_dirty_region(HeapRegion* hr) {
629 // All of the region should be clean.
630 G1SATBCardTableModRefBS* ct_bs = _g1h->g1_barrier_set();
631 MemRegion mr(hr->bottom(), hr->end());
637 // dirty allocated blocks as they allocate them. The thread that
638 // retires each region and replaces it with a new one will do a
639 // maximal allocation to fill in [pre_dummy_top(),end()] but will
640 // not dirty that area (one less thing to have to do while holding
641 // a lock). So we can only verify that [bottom(),pre_dummy_top()]
642 // is dirty.
643 G1SATBCardTableModRefBS* ct_bs = _g1h->g1_barrier_set();
644 MemRegion mr(hr->bottom(), hr->pre_dummy_top());
645 if (hr->is_young()) {
646 ct_bs->verify_g1_young_region(mr);
647 } else {
648 ct_bs->verify_dirty_region(mr);
649 }
650 }
651
652 class G1VerifyDirtyYoungListClosure : public HeapRegionClosure {
653 private:
654 G1HeapVerifier* _verifier;
655 public:
656 G1VerifyDirtyYoungListClosure(G1HeapVerifier* verifier) : HeapRegionClosure(), _verifier(verifier) { }
657 virtual bool do_heap_region(HeapRegion* r) {
658 _verifier->verify_dirty_region(r);
659 return false;
660 }
661 };
662
663 void G1HeapVerifier::verify_dirty_young_regions() {
664 G1VerifyDirtyYoungListClosure cl(this);
665 _g1h->collection_set()->iterate(&cl);
666 }
667
668 bool G1HeapVerifier::verify_no_bits_over_tams(const char* bitmap_name, const G1CMBitMap* const bitmap,
669 HeapWord* tams, HeapWord* end) {
670 guarantee(tams <= end,
671 "tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end));
672 HeapWord* result = bitmap->get_next_marked_addr(tams, end);
673 if (result < end) {
674 log_error(gc, verify)("## wrong marked address on %s bitmap: " PTR_FORMAT, bitmap_name, p2i(result));
675 log_error(gc, verify)("## %s tams: " PTR_FORMAT " end: " PTR_FORMAT, bitmap_name, p2i(tams), p2i(end));
676 return false;
677 }
704 }
705
706 void G1HeapVerifier::check_bitmaps(const char* caller, HeapRegion* hr) {
707 if (!G1VerifyBitmaps) return;
708
709 guarantee(verify_bitmaps(caller, hr), "bitmap verification");
710 }
711
712 class G1VerifyBitmapClosure : public HeapRegionClosure {
713 private:
714 const char* _caller;
715 G1HeapVerifier* _verifier;
716 bool _failures;
717
718 public:
719 G1VerifyBitmapClosure(const char* caller, G1HeapVerifier* verifier) :
720 _caller(caller), _verifier(verifier), _failures(false) { }
721
722 bool failures() { return _failures; }
723
724 virtual bool do_heap_region(HeapRegion* hr) {
725 bool result = _verifier->verify_bitmaps(_caller, hr);
726 if (!result) {
727 _failures = true;
728 }
729 return false;
730 }
731 };
732
733 void G1HeapVerifier::check_bitmaps(const char* caller) {
734 if (!G1VerifyBitmaps) return;
735
736 G1VerifyBitmapClosure cl(caller, this);
737 _g1h->heap_region_iterate(&cl);
738 guarantee(!cl.failures(), "bitmap verification");
739 }
740
741 class G1CheckCSetFastTableClosure : public HeapRegionClosure {
742 private:
743 bool _failures;
744 public:
745 G1CheckCSetFastTableClosure() : HeapRegionClosure(), _failures(false) { }
746
747 virtual bool do_heap_region(HeapRegion* hr) {
748 uint i = hr->hrm_index();
749 InCSetState cset_state = (InCSetState) G1CollectedHeap::heap()->_in_cset_fast_test.get_by_index(i);
750 if (hr->is_humongous()) {
751 if (hr->in_collection_set()) {
752 log_error(gc, verify)("## humongous region %u in CSet", i);
753 _failures = true;
754 return true;
755 }
756 if (cset_state.is_in_cset()) {
757 log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for humongous region %u", cset_state.value(), i);
758 _failures = true;
759 return true;
760 }
761 if (hr->is_continues_humongous() && cset_state.is_humongous()) {
762 log_error(gc, verify)("## inconsistent cset state " CSETSTATE_FORMAT " for continues humongous region %u", cset_state.value(), i);
763 _failures = true;
764 return true;
765 }
766 } else {
767 if (cset_state.is_humongous()) {
|