306
307 if (during_initial_mark) {
308 // During initial-mark, we'll also explicitly mark all objects
309 // we find to be self-forwarded on the next bitmap. So all
310 // objects need to be below NTAMS.
311 _next_top_at_mark_start = top();
312 _next_marked_bytes = 0;
313 } else if (during_conc_mark) {
314 // During concurrent mark, all objects in the CSet (including
315 // the ones we find to be self-forwarded) are implicitly live.
316 // So all objects need to be above NTAMS.
317 _next_top_at_mark_start = bottom();
318 _next_marked_bytes = 0;
319 }
320 }
321
322 void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark,
323 bool during_conc_mark,
324 size_t marked_bytes) {
325 assert(marked_bytes <= used(),
326 err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT, marked_bytes, used()));
327 _prev_top_at_mark_start = top();
328 _prev_marked_bytes = marked_bytes;
329 }
330
331 HeapWord*
332 HeapRegion::object_iterate_mem_careful(MemRegion mr,
333 ObjectClosure* cl) {
334 G1CollectedHeap* g1h = G1CollectedHeap::heap();
335 // We used to use "block_start_careful" here. But we're actually happy
336 // to update the BOT while we do this...
337 HeapWord* cur = block_start(mr.start());
338 mr = mr.intersection(used_region());
339 if (mr.is_empty()) return NULL;
340 // Otherwise, find the obj that extends onto mr.start().
341
342 assert(cur <= mr.start()
343 && (oop(cur)->klass_or_null() == NULL ||
344 cur + oop(cur)->size() > mr.start()),
345 "postcondition of block_start");
346 oop obj;
483 hrrs->strong_code_roots_do(blk);
484 }
485
486 class VerifyStrongCodeRootOopClosure: public OopClosure {
487 const HeapRegion* _hr;
488 nmethod* _nm;
489 bool _failures;
490 bool _has_oops_in_region;
491
492 template <class T> void do_oop_work(T* p) {
493 T heap_oop = oopDesc::load_heap_oop(p);
494 if (!oopDesc::is_null(heap_oop)) {
495 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
496
497 // Note: not all the oops embedded in the nmethod are in the
498 // current region. We only look at those which are.
499 if (_hr->is_in(obj)) {
500 // Object is in the region. Check that its less than top
501 if (_hr->top() <= (HeapWord*)obj) {
502 // Object is above top
503 gclog_or_tty->print_cr("Object "PTR_FORMAT" in region "
504 "["PTR_FORMAT", "PTR_FORMAT") is above "
505 "top "PTR_FORMAT,
506 p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top()));
507 _failures = true;
508 return;
509 }
510 // Nmethod has at least one oop in the current region
511 _has_oops_in_region = true;
512 }
513 }
514 }
515
516 public:
517 VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
518 _hr(hr), _failures(false), _has_oops_in_region(false) {}
519
520 void do_oop(narrowOop* p) { do_oop_work(p); }
521 void do_oop(oop* p) { do_oop_work(p); }
522
523 bool failures() { return _failures; }
524 bool has_oops_in_region() { return _has_oops_in_region; }
525 };
526
527 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
528 const HeapRegion* _hr;
529 bool _failures;
530 public:
531 VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
532 _hr(hr), _failures(false) {}
533
534 void do_code_blob(CodeBlob* cb) {
535 nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
536 if (nm != NULL) {
537 // Verify that the nemthod is live
538 if (!nm->is_alive()) {
539 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has dead nmethod "
540 PTR_FORMAT" in its strong code roots",
541 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
542 _failures = true;
543 } else {
544 VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
545 nm->oops_do(&oop_cl);
546 if (!oop_cl.has_oops_in_region()) {
547 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has nmethod "
548 PTR_FORMAT" in its strong code roots "
549 "with no pointers into region",
550 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
551 _failures = true;
552 } else if (oop_cl.failures()) {
553 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has other "
554 "failures for nmethod "PTR_FORMAT,
555 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
556 _failures = true;
557 }
558 }
559 }
560 }
561
562 bool failures() { return _failures; }
563 };
564
565 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
566 if (!G1VerifyHeapRegionCodeRoots) {
567 // We're not verifying code roots.
568 return;
569 }
570 if (vo == VerifyOption_G1UseMarkWord) {
571 // Marking verification during a full GC is performed after class
572 // unloading, code cache unloading, etc so the strong code roots
573 // attached to each heap region are in an inconsistent state. They won't
574 // be consistent until the strong code roots are rebuilt after the
575 // actual GC. Skip verifying the strong code roots in this particular
576 // time.
577 assert(VerifyDuringGC, "only way to get here");
578 return;
579 }
580
581 HeapRegionRemSet* hrrs = rem_set();
582 size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
583
584 // if this region is empty then there should be no entries
585 // on its strong code root list
586 if (is_empty()) {
587 if (strong_code_roots_length > 0) {
588 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty "
589 "but has "SIZE_FORMAT" code root entries",
590 p2i(bottom()), p2i(end()), strong_code_roots_length);
591 *failures = true;
592 }
593 return;
594 }
595
596 if (is_continues_humongous()) {
597 if (strong_code_roots_length > 0) {
598 gclog_or_tty->print_cr("region "HR_FORMAT" is a continuation of a humongous "
599 "region but has "SIZE_FORMAT" code root entries",
600 HR_FORMAT_PARAMS(this), strong_code_roots_length);
601 *failures = true;
602 }
603 return;
604 }
605
606 VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
607 strong_code_roots_do(&cb_cl);
608
609 if (cb_cl.failures()) {
610 *failures = true;
611 }
612 }
613
614 void HeapRegion::print() const { print_on(gclog_or_tty); }
615 void HeapRegion::print_on(outputStream* st) const {
616 st->print("AC%4u", allocation_context());
617
618 st->print(" %2s", get_short_type_str());
619 if (in_collection_set())
620 st->print(" CS");
621 else
622 st->print(" ");
623 st->print(" TS %5d", _gc_time_stamp);
624 st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT,
625 p2i(prev_top_at_mark_start()), p2i(next_top_at_mark_start()));
626 G1OffsetTableContigSpace::print_on(st);
627 }
628
629 class VerifyLiveClosure: public OopClosure {
630 private:
631 G1CollectedHeap* _g1h;
632 CardTableModRefBS* _bs;
633 oop _containing_obj;
634 bool _failures;
635 int _n_failures;
636 VerifyOption _vo;
637 public:
638 // _vo == UsePrevMarking -> use "prev" marking information,
639 // _vo == UseNextMarking -> use "next" marking information,
640 // _vo == UseMarkWord -> use mark word from object header.
641 VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :
642 _g1h(g1h), _bs(barrier_set_cast<CardTableModRefBS>(g1h->barrier_set())),
643 _containing_obj(NULL), _failures(false), _n_failures(0), _vo(vo)
644 { }
665
666 template <class T>
667 void do_oop_work(T* p) {
668 assert(_containing_obj != NULL, "Precondition");
669 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
670 "Precondition");
671 T heap_oop = oopDesc::load_heap_oop(p);
672 if (!oopDesc::is_null(heap_oop)) {
673 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
674 bool failed = false;
675 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
676 MutexLockerEx x(ParGCRareEvent_lock,
677 Mutex::_no_safepoint_check_flag);
678
679 if (!_failures) {
680 gclog_or_tty->cr();
681 gclog_or_tty->print_cr("----------");
682 }
683 if (!_g1h->is_in_closed_subset(obj)) {
684 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
685 gclog_or_tty->print_cr("Field "PTR_FORMAT
686 " of live obj "PTR_FORMAT" in region "
687 "["PTR_FORMAT", "PTR_FORMAT")",
688 p2i(p), p2i(_containing_obj),
689 p2i(from->bottom()), p2i(from->end()));
690 print_object(gclog_or_tty, _containing_obj);
691 gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap",
692 p2i(obj));
693 } else {
694 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
695 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
696 gclog_or_tty->print_cr("Field "PTR_FORMAT
697 " of live obj "PTR_FORMAT" in region "
698 "["PTR_FORMAT", "PTR_FORMAT")",
699 p2i(p), p2i(_containing_obj),
700 p2i(from->bottom()), p2i(from->end()));
701 print_object(gclog_or_tty, _containing_obj);
702 gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region "
703 "["PTR_FORMAT", "PTR_FORMAT")",
704 p2i(obj), p2i(to->bottom()), p2i(to->end()));
705 print_object(gclog_or_tty, obj);
706 }
707 gclog_or_tty->print_cr("----------");
708 gclog_or_tty->flush();
709 _failures = true;
710 failed = true;
711 _n_failures++;
712 }
713
714 if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) {
715 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
716 HeapRegion* to = _g1h->heap_region_containing(obj);
717 if (from != NULL && to != NULL &&
718 from != to &&
719 !to->is_humongous()) {
720 jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
721 jbyte cv_field = *_bs->byte_for_const(p);
722 const jbyte dirty = CardTableModRefBS::dirty_card_val();
723
724 bool is_bad = !(from->is_young()
725 || to->rem_set()->contains_reference(p)
726 || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
727 (_containing_obj->is_objArray() ?
728 cv_field == dirty
729 : cv_obj == dirty || cv_field == dirty));
730 if (is_bad) {
731 MutexLockerEx x(ParGCRareEvent_lock,
732 Mutex::_no_safepoint_check_flag);
733
734 if (!_failures) {
735 gclog_or_tty->cr();
736 gclog_or_tty->print_cr("----------");
737 }
738 gclog_or_tty->print_cr("Missing rem set entry:");
739 gclog_or_tty->print_cr("Field "PTR_FORMAT" "
740 "of obj "PTR_FORMAT", "
741 "in region "HR_FORMAT,
742 p2i(p), p2i(_containing_obj),
743 HR_FORMAT_PARAMS(from));
744 _containing_obj->print_on(gclog_or_tty);
745 gclog_or_tty->print_cr("points to obj "PTR_FORMAT" "
746 "in region "HR_FORMAT,
747 p2i(obj),
748 HR_FORMAT_PARAMS(to));
749 obj->print_on(gclog_or_tty);
750 gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.",
751 cv_obj, cv_field);
752 gclog_or_tty->print_cr("----------");
753 gclog_or_tty->flush();
754 _failures = true;
755 if (!failed) _n_failures++;
756 }
757 }
758 }
759 }
760 }
761 };
762
763 // This really ought to be commoned up into OffsetTableContigSpace somehow.
764 // We would need a mechanism to make that code skip dead objects.
765
766 void HeapRegion::verify(VerifyOption vo,
767 bool* failures) const {
768 G1CollectedHeap* g1 = G1CollectedHeap::heap();
769 *failures = false;
770 HeapWord* p = bottom();
771 HeapWord* prev_p = NULL;
772 VerifyLiveClosure vl_cl(g1, vo);
773 bool is_region_humongous = is_humongous();
774 size_t object_num = 0;
775 while (p < top()) {
776 oop obj = oop(p);
777 size_t obj_size = block_size(p);
778 object_num += 1;
779
780 if (is_region_humongous != g1->is_humongous(obj_size) &&
781 !g1->is_obj_dead(obj, this)) { // Dead objects may have bigger block_size since they span several objects.
782 gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size ("
783 SIZE_FORMAT" words) in a %shumongous region",
784 p2i(p), g1->is_humongous(obj_size) ? "" : "non-",
785 obj_size, is_region_humongous ? "" : "non-");
786 *failures = true;
787 return;
788 }
789
790 if (!g1->is_obj_dead_cond(obj, this, vo)) {
791 if (obj->is_oop()) {
792 Klass* klass = obj->klass();
793 bool is_metaspace_object = Metaspace::contains(klass) ||
794 (vo == VerifyOption_G1UsePrevMarking &&
795 ClassLoaderDataGraph::unload_list_contains(klass));
796 if (!is_metaspace_object) {
797 gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" "
798 "not metadata", p2i(klass), p2i(obj));
799 *failures = true;
800 return;
801 } else if (!klass->is_klass()) {
802 gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" "
803 "not a klass", p2i(klass), p2i(obj));
804 *failures = true;
805 return;
806 } else {
807 vl_cl.set_containing_obj(obj);
808 obj->oop_iterate_no_header(&vl_cl);
809 if (vl_cl.failures()) {
810 *failures = true;
811 }
812 if (G1MaxVerifyFailures >= 0 &&
813 vl_cl.n_failures() >= G1MaxVerifyFailures) {
814 return;
815 }
816 }
817 } else {
818 gclog_or_tty->print_cr(PTR_FORMAT" no an oop", p2i(obj));
819 *failures = true;
820 return;
821 }
822 }
823 prev_p = p;
824 p += obj_size;
825 }
826
827 if (!is_young() && !is_empty()) {
828 _offsets.verify();
829 }
830
831 if (p != top()) {
832 gclog_or_tty->print_cr("end of last object "PTR_FORMAT" "
833 "does not match top "PTR_FORMAT, p2i(p), p2i(top()));
834 *failures = true;
835 return;
836 }
837
838 HeapWord* the_end = end();
839 assert(p == top(), "it should still hold");
840 // Do some extra BOT consistency checking for addresses in the
841 // range [top, end). BOT look-ups in this range should yield
842 // top. No point in doing that if top == end (there's nothing there).
843 if (p < the_end) {
844 // Look up top
845 HeapWord* addr_1 = p;
846 HeapWord* b_start_1 = _offsets.block_start_const(addr_1);
847 if (b_start_1 != p) {
848 gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" "
849 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
850 p2i(addr_1), p2i(b_start_1), p2i(p));
851 *failures = true;
852 return;
853 }
854
855 // Look up top + 1
856 HeapWord* addr_2 = p + 1;
857 if (addr_2 < the_end) {
858 HeapWord* b_start_2 = _offsets.block_start_const(addr_2);
859 if (b_start_2 != p) {
860 gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" "
861 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
862 p2i(addr_2), p2i(b_start_2), p2i(p));
863 *failures = true;
864 return;
865 }
866 }
867
868 // Look up an address between top and end
869 size_t diff = pointer_delta(the_end, p) / 2;
870 HeapWord* addr_3 = p + diff;
871 if (addr_3 < the_end) {
872 HeapWord* b_start_3 = _offsets.block_start_const(addr_3);
873 if (b_start_3 != p) {
874 gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" "
875 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
876 p2i(addr_3), p2i(b_start_3), p2i(p));
877 *failures = true;
878 return;
879 }
880 }
881
882 // Look up end - 1
883 HeapWord* addr_4 = the_end - 1;
884 HeapWord* b_start_4 = _offsets.block_start_const(addr_4);
885 if (b_start_4 != p) {
886 gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" "
887 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
888 p2i(addr_4), p2i(b_start_4), p2i(p));
889 *failures = true;
890 return;
891 }
892 }
893
894 if (is_region_humongous && object_num > 1) {
895 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous "
896 "but has "SIZE_FORMAT", objects",
897 p2i(bottom()), p2i(end()), object_num);
898 *failures = true;
899 return;
900 }
901
902 verify_strong_code_roots(vo, failures);
903 }
904
905 void HeapRegion::verify() const {
906 bool dummy = false;
907 verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
908 }
909
910 void HeapRegion::prepare_for_compaction(CompactPoint* cp) {
911 scan_and_forward(this, cp);
912 }
913
914 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
915 // away eventually.
916
|
306
307 if (during_initial_mark) {
308 // During initial-mark, we'll also explicitly mark all objects
309 // we find to be self-forwarded on the next bitmap. So all
310 // objects need to be below NTAMS.
311 _next_top_at_mark_start = top();
312 _next_marked_bytes = 0;
313 } else if (during_conc_mark) {
314 // During concurrent mark, all objects in the CSet (including
315 // the ones we find to be self-forwarded) are implicitly live.
316 // So all objects need to be above NTAMS.
317 _next_top_at_mark_start = bottom();
318 _next_marked_bytes = 0;
319 }
320 }
321
322 void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark,
323 bool during_conc_mark,
324 size_t marked_bytes) {
325 assert(marked_bytes <= used(),
326 err_msg("marked: " SIZE_FORMAT " used: " SIZE_FORMAT, marked_bytes, used()));
327 _prev_top_at_mark_start = top();
328 _prev_marked_bytes = marked_bytes;
329 }
330
331 HeapWord*
332 HeapRegion::object_iterate_mem_careful(MemRegion mr,
333 ObjectClosure* cl) {
334 G1CollectedHeap* g1h = G1CollectedHeap::heap();
335 // We used to use "block_start_careful" here. But we're actually happy
336 // to update the BOT while we do this...
337 HeapWord* cur = block_start(mr.start());
338 mr = mr.intersection(used_region());
339 if (mr.is_empty()) return NULL;
340 // Otherwise, find the obj that extends onto mr.start().
341
342 assert(cur <= mr.start()
343 && (oop(cur)->klass_or_null() == NULL ||
344 cur + oop(cur)->size() > mr.start()),
345 "postcondition of block_start");
346 oop obj;
483 hrrs->strong_code_roots_do(blk);
484 }
485
486 class VerifyStrongCodeRootOopClosure: public OopClosure {
487 const HeapRegion* _hr;
488 nmethod* _nm;
489 bool _failures;
490 bool _has_oops_in_region;
491
492 template <class T> void do_oop_work(T* p) {
493 T heap_oop = oopDesc::load_heap_oop(p);
494 if (!oopDesc::is_null(heap_oop)) {
495 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
496
497 // Note: not all the oops embedded in the nmethod are in the
498 // current region. We only look at those which are.
499 if (_hr->is_in(obj)) {
500 // Object is in the region. Check that its less than top
501 if (_hr->top() <= (HeapWord*)obj) {
502 // Object is above top
503 gclog_or_tty->print_cr("Object " PTR_FORMAT " in region "
504 "[" PTR_FORMAT ", " PTR_FORMAT ") is above "
505 "top " PTR_FORMAT,
506 p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top()));
507 _failures = true;
508 return;
509 }
510 // Nmethod has at least one oop in the current region
511 _has_oops_in_region = true;
512 }
513 }
514 }
515
516 public:
517 VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
518 _hr(hr), _failures(false), _has_oops_in_region(false) {}
519
520 void do_oop(narrowOop* p) { do_oop_work(p); }
521 void do_oop(oop* p) { do_oop_work(p); }
522
523 bool failures() { return _failures; }
524 bool has_oops_in_region() { return _has_oops_in_region; }
525 };
526
527 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
528 const HeapRegion* _hr;
529 bool _failures;
530 public:
531 VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
532 _hr(hr), _failures(false) {}
533
534 void do_code_blob(CodeBlob* cb) {
535 nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
536 if (nm != NULL) {
537 // Verify that the nemthod is live
538 if (!nm->is_alive()) {
539 gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] has dead nmethod "
540 PTR_FORMAT " in its strong code roots",
541 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
542 _failures = true;
543 } else {
544 VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
545 nm->oops_do(&oop_cl);
546 if (!oop_cl.has_oops_in_region()) {
547 gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod "
548 PTR_FORMAT " in its strong code roots "
549 "with no pointers into region",
550 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
551 _failures = true;
552 } else if (oop_cl.failures()) {
553 gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] has other "
554 "failures for nmethod " PTR_FORMAT,
555 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
556 _failures = true;
557 }
558 }
559 }
560 }
561
562 bool failures() { return _failures; }
563 };
564
565 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
566 if (!G1VerifyHeapRegionCodeRoots) {
567 // We're not verifying code roots.
568 return;
569 }
570 if (vo == VerifyOption_G1UseMarkWord) {
571 // Marking verification during a full GC is performed after class
572 // unloading, code cache unloading, etc so the strong code roots
573 // attached to each heap region are in an inconsistent state. They won't
574 // be consistent until the strong code roots are rebuilt after the
575 // actual GC. Skip verifying the strong code roots in this particular
576 // time.
577 assert(VerifyDuringGC, "only way to get here");
578 return;
579 }
580
581 HeapRegionRemSet* hrrs = rem_set();
582 size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
583
584 // if this region is empty then there should be no entries
585 // on its strong code root list
586 if (is_empty()) {
587 if (strong_code_roots_length > 0) {
588 gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] is empty "
589 "but has " SIZE_FORMAT " code root entries",
590 p2i(bottom()), p2i(end()), strong_code_roots_length);
591 *failures = true;
592 }
593 return;
594 }
595
596 if (is_continues_humongous()) {
597 if (strong_code_roots_length > 0) {
598 gclog_or_tty->print_cr("region " HR_FORMAT " is a continuation of a humongous "
599 "region but has " SIZE_FORMAT " code root entries",
600 HR_FORMAT_PARAMS(this), strong_code_roots_length);
601 *failures = true;
602 }
603 return;
604 }
605
606 VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
607 strong_code_roots_do(&cb_cl);
608
609 if (cb_cl.failures()) {
610 *failures = true;
611 }
612 }
613
614 void HeapRegion::print() const { print_on(gclog_or_tty); }
615 void HeapRegion::print_on(outputStream* st) const {
616 st->print("AC%4u", allocation_context());
617
618 st->print(" %2s", get_short_type_str());
619 if (in_collection_set())
620 st->print(" CS");
621 else
622 st->print(" ");
623 st->print(" TS %5d", _gc_time_stamp);
624 st->print(" PTAMS " PTR_FORMAT " NTAMS " PTR_FORMAT,
625 p2i(prev_top_at_mark_start()), p2i(next_top_at_mark_start()));
626 G1OffsetTableContigSpace::print_on(st);
627 }
628
629 class VerifyLiveClosure: public OopClosure {
630 private:
631 G1CollectedHeap* _g1h;
632 CardTableModRefBS* _bs;
633 oop _containing_obj;
634 bool _failures;
635 int _n_failures;
636 VerifyOption _vo;
637 public:
638 // _vo == UsePrevMarking -> use "prev" marking information,
639 // _vo == UseNextMarking -> use "next" marking information,
640 // _vo == UseMarkWord -> use mark word from object header.
641 VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :
642 _g1h(g1h), _bs(barrier_set_cast<CardTableModRefBS>(g1h->barrier_set())),
643 _containing_obj(NULL), _failures(false), _n_failures(0), _vo(vo)
644 { }
665
666 template <class T>
667 void do_oop_work(T* p) {
668 assert(_containing_obj != NULL, "Precondition");
669 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
670 "Precondition");
671 T heap_oop = oopDesc::load_heap_oop(p);
672 if (!oopDesc::is_null(heap_oop)) {
673 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
674 bool failed = false;
675 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
676 MutexLockerEx x(ParGCRareEvent_lock,
677 Mutex::_no_safepoint_check_flag);
678
679 if (!_failures) {
680 gclog_or_tty->cr();
681 gclog_or_tty->print_cr("----------");
682 }
683 if (!_g1h->is_in_closed_subset(obj)) {
684 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
685 gclog_or_tty->print_cr("Field " PTR_FORMAT
686 " of live obj " PTR_FORMAT " in region "
687 "[" PTR_FORMAT ", " PTR_FORMAT ")",
688 p2i(p), p2i(_containing_obj),
689 p2i(from->bottom()), p2i(from->end()));
690 print_object(gclog_or_tty, _containing_obj);
691 gclog_or_tty->print_cr("points to obj " PTR_FORMAT " not in the heap",
692 p2i(obj));
693 } else {
694 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
695 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
696 gclog_or_tty->print_cr("Field " PTR_FORMAT
697 " of live obj " PTR_FORMAT " in region "
698 "[" PTR_FORMAT ", " PTR_FORMAT ")",
699 p2i(p), p2i(_containing_obj),
700 p2i(from->bottom()), p2i(from->end()));
701 print_object(gclog_or_tty, _containing_obj);
702 gclog_or_tty->print_cr("points to dead obj " PTR_FORMAT " in region "
703 "[" PTR_FORMAT ", " PTR_FORMAT ")",
704 p2i(obj), p2i(to->bottom()), p2i(to->end()));
705 print_object(gclog_or_tty, obj);
706 }
707 gclog_or_tty->print_cr("----------");
708 gclog_or_tty->flush();
709 _failures = true;
710 failed = true;
711 _n_failures++;
712 }
713
714 if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) {
715 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
716 HeapRegion* to = _g1h->heap_region_containing(obj);
717 if (from != NULL && to != NULL &&
718 from != to &&
719 !to->is_humongous()) {
720 jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
721 jbyte cv_field = *_bs->byte_for_const(p);
722 const jbyte dirty = CardTableModRefBS::dirty_card_val();
723
724 bool is_bad = !(from->is_young()
725 || to->rem_set()->contains_reference(p)
726 || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
727 (_containing_obj->is_objArray() ?
728 cv_field == dirty
729 : cv_obj == dirty || cv_field == dirty));
730 if (is_bad) {
731 MutexLockerEx x(ParGCRareEvent_lock,
732 Mutex::_no_safepoint_check_flag);
733
734 if (!_failures) {
735 gclog_or_tty->cr();
736 gclog_or_tty->print_cr("----------");
737 }
738 gclog_or_tty->print_cr("Missing rem set entry:");
739 gclog_or_tty->print_cr("Field " PTR_FORMAT " "
740 "of obj " PTR_FORMAT ", "
741 "in region " HR_FORMAT,
742 p2i(p), p2i(_containing_obj),
743 HR_FORMAT_PARAMS(from));
744 _containing_obj->print_on(gclog_or_tty);
745 gclog_or_tty->print_cr("points to obj " PTR_FORMAT " "
746 "in region " HR_FORMAT,
747 p2i(obj),
748 HR_FORMAT_PARAMS(to));
749 obj->print_on(gclog_or_tty);
750 gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.",
751 cv_obj, cv_field);
752 gclog_or_tty->print_cr("----------");
753 gclog_or_tty->flush();
754 _failures = true;
755 if (!failed) _n_failures++;
756 }
757 }
758 }
759 }
760 }
761 };
762
763 // This really ought to be commoned up into OffsetTableContigSpace somehow.
764 // We would need a mechanism to make that code skip dead objects.
765
766 void HeapRegion::verify(VerifyOption vo,
767 bool* failures) const {
768 G1CollectedHeap* g1 = G1CollectedHeap::heap();
769 *failures = false;
770 HeapWord* p = bottom();
771 HeapWord* prev_p = NULL;
772 VerifyLiveClosure vl_cl(g1, vo);
773 bool is_region_humongous = is_humongous();
774 size_t object_num = 0;
775 while (p < top()) {
776 oop obj = oop(p);
777 size_t obj_size = block_size(p);
778 object_num += 1;
779
780 if (is_region_humongous != g1->is_humongous(obj_size) &&
781 !g1->is_obj_dead(obj, this)) { // Dead objects may have bigger block_size since they span several objects.
782 gclog_or_tty->print_cr("obj " PTR_FORMAT " is of %shumongous size ("
783 SIZE_FORMAT " words) in a %shumongous region",
784 p2i(p), g1->is_humongous(obj_size) ? "" : "non-",
785 obj_size, is_region_humongous ? "" : "non-");
786 *failures = true;
787 return;
788 }
789
790 if (!g1->is_obj_dead_cond(obj, this, vo)) {
791 if (obj->is_oop()) {
792 Klass* klass = obj->klass();
793 bool is_metaspace_object = Metaspace::contains(klass) ||
794 (vo == VerifyOption_G1UsePrevMarking &&
795 ClassLoaderDataGraph::unload_list_contains(klass));
796 if (!is_metaspace_object) {
797 gclog_or_tty->print_cr("klass " PTR_FORMAT " of object " PTR_FORMAT " "
798 "not metadata", p2i(klass), p2i(obj));
799 *failures = true;
800 return;
801 } else if (!klass->is_klass()) {
802 gclog_or_tty->print_cr("klass " PTR_FORMAT " of object " PTR_FORMAT " "
803 "not a klass", p2i(klass), p2i(obj));
804 *failures = true;
805 return;
806 } else {
807 vl_cl.set_containing_obj(obj);
808 obj->oop_iterate_no_header(&vl_cl);
809 if (vl_cl.failures()) {
810 *failures = true;
811 }
812 if (G1MaxVerifyFailures >= 0 &&
813 vl_cl.n_failures() >= G1MaxVerifyFailures) {
814 return;
815 }
816 }
817 } else {
818 gclog_or_tty->print_cr(PTR_FORMAT " no an oop", p2i(obj));
819 *failures = true;
820 return;
821 }
822 }
823 prev_p = p;
824 p += obj_size;
825 }
826
827 if (!is_young() && !is_empty()) {
828 _offsets.verify();
829 }
830
831 if (p != top()) {
832 gclog_or_tty->print_cr("end of last object " PTR_FORMAT " "
833 "does not match top " PTR_FORMAT, p2i(p), p2i(top()));
834 *failures = true;
835 return;
836 }
837
838 HeapWord* the_end = end();
839 assert(p == top(), "it should still hold");
840 // Do some extra BOT consistency checking for addresses in the
841 // range [top, end). BOT look-ups in this range should yield
842 // top. No point in doing that if top == end (there's nothing there).
843 if (p < the_end) {
844 // Look up top
845 HeapWord* addr_1 = p;
846 HeapWord* b_start_1 = _offsets.block_start_const(addr_1);
847 if (b_start_1 != p) {
848 gclog_or_tty->print_cr("BOT look up for top: " PTR_FORMAT " "
849 " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
850 p2i(addr_1), p2i(b_start_1), p2i(p));
851 *failures = true;
852 return;
853 }
854
855 // Look up top + 1
856 HeapWord* addr_2 = p + 1;
857 if (addr_2 < the_end) {
858 HeapWord* b_start_2 = _offsets.block_start_const(addr_2);
859 if (b_start_2 != p) {
860 gclog_or_tty->print_cr("BOT look up for top + 1: " PTR_FORMAT " "
861 " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
862 p2i(addr_2), p2i(b_start_2), p2i(p));
863 *failures = true;
864 return;
865 }
866 }
867
868 // Look up an address between top and end
869 size_t diff = pointer_delta(the_end, p) / 2;
870 HeapWord* addr_3 = p + diff;
871 if (addr_3 < the_end) {
872 HeapWord* b_start_3 = _offsets.block_start_const(addr_3);
873 if (b_start_3 != p) {
874 gclog_or_tty->print_cr("BOT look up for top + diff: " PTR_FORMAT " "
875 " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
876 p2i(addr_3), p2i(b_start_3), p2i(p));
877 *failures = true;
878 return;
879 }
880 }
881
882 // Look up end - 1
883 HeapWord* addr_4 = the_end - 1;
884 HeapWord* b_start_4 = _offsets.block_start_const(addr_4);
885 if (b_start_4 != p) {
886 gclog_or_tty->print_cr("BOT look up for end - 1: " PTR_FORMAT " "
887 " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
888 p2i(addr_4), p2i(b_start_4), p2i(p));
889 *failures = true;
890 return;
891 }
892 }
893
894 if (is_region_humongous && object_num > 1) {
895 gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] is humongous "
896 "but has " SIZE_FORMAT ", objects",
897 p2i(bottom()), p2i(end()), object_num);
898 *failures = true;
899 return;
900 }
901
902 verify_strong_code_roots(vo, failures);
903 }
904
905 void HeapRegion::verify() const {
906 bool dummy = false;
907 verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
908 }
909
910 void HeapRegion::prepare_for_compaction(CompactPoint* cp) {
911 scan_and_forward(this, cp);
912 }
913
914 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
915 // away eventually.
916
|