< prev index next >

src/share/vm/gc/g1/heapRegion.cpp

Print this page




 462   hrrs->strong_code_roots_do(blk);
 463 }
 464 
 465 class VerifyStrongCodeRootOopClosure: public OopClosure {
 466   const HeapRegion* _hr;
 467   nmethod* _nm;
 468   bool _failures;
 469   bool _has_oops_in_region;
 470 
 471   template <class T> void do_oop_work(T* p) {
 472     T heap_oop = oopDesc::load_heap_oop(p);
 473     if (!oopDesc::is_null(heap_oop)) {
 474       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 475 
 476       // Note: not all the oops embedded in the nmethod are in the
 477       // current region. We only look at those which are.
 478       if (_hr->is_in(obj)) {
 479         // Object is in the region. Check that its less than top
 480         if (_hr->top() <= (HeapWord*)obj) {
 481           // Object is above top
 482           log_info(gc, verify)("Object " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ") is above top " PTR_FORMAT,
 483                                p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top()));
 484           _failures = true;
 485           return;
 486         }
 487         // Nmethod has at least one oop in the current region
 488         _has_oops_in_region = true;
 489       }
 490     }
 491   }
 492 
 493 public:
 494   VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
 495     _hr(hr), _failures(false), _has_oops_in_region(false) {}
 496 
 497   void do_oop(narrowOop* p) { do_oop_work(p); }
 498   void do_oop(oop* p)       { do_oop_work(p); }
 499 
 500   bool failures()           { return _failures; }
 501   bool has_oops_in_region() { return _has_oops_in_region; }
 502 };
 503 
 504 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
 505   const HeapRegion* _hr;
 506   bool _failures;
 507 public:
 508   VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
 509     _hr(hr), _failures(false) {}
 510 
 511   void do_code_blob(CodeBlob* cb) {
 512     nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
 513     if (nm != NULL) {
 514       // Verify that the nemthod is live
 515       if (!nm->is_alive()) {
 516         log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has dead nmethod " PTR_FORMAT " in its strong code roots",
 517                              p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 518         _failures = true;
 519       } else {
 520         VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
 521         nm->oops_do(&oop_cl);
 522         if (!oop_cl.has_oops_in_region()) {
 523           log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its strong code roots with no pointers into region",
 524                                p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 525           _failures = true;
 526         } else if (oop_cl.failures()) {
 527           log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has other failures for nmethod " PTR_FORMAT,
 528                                p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 529           _failures = true;
 530         }
 531       }
 532     }
 533   }
 534 
 535   bool failures()       { return _failures; }
 536 };
 537 
 538 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
 539   if (!G1VerifyHeapRegionCodeRoots) {
 540     // We're not verifying code roots.
 541     return;
 542   }
 543   if (vo == VerifyOption_G1UseMarkWord) {
 544     // Marking verification during a full GC is performed after class
 545     // unloading, code cache unloading, etc so the strong code roots
 546     // attached to each heap region are in an inconsistent state. They won't
 547     // be consistent until the strong code roots are rebuilt after the
 548     // actual GC. Skip verifying the strong code roots in this particular
 549     // time.
 550     assert(VerifyDuringGC, "only way to get here");
 551     return;
 552   }
 553 
 554   HeapRegionRemSet* hrrs = rem_set();
 555   size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
 556 
 557   // if this region is empty then there should be no entries
 558   // on its strong code root list
 559   if (is_empty()) {
 560     if (strong_code_roots_length > 0) {
 561       log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] is empty but has " SIZE_FORMAT " code root entries",
 562                            p2i(bottom()), p2i(end()), strong_code_roots_length);
 563       *failures = true;
 564     }
 565     return;
 566   }
 567 
 568   if (is_continues_humongous()) {
 569     if (strong_code_roots_length > 0) {
 570       log_info(gc, verify)("region " HR_FORMAT " is a continuation of a humongous region but has " SIZE_FORMAT " code root entries",
 571                            HR_FORMAT_PARAMS(this), strong_code_roots_length);
 572       *failures = true;
 573     }
 574     return;
 575   }
 576 
 577   VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
 578   strong_code_roots_do(&cb_cl);
 579 
 580   if (cb_cl.failures()) {
 581     *failures = true;
 582   }
 583 }
 584 
 585 void HeapRegion::print() const { print_on(tty); }
 586 void HeapRegion::print_on(outputStream* st) const {
 587   st->print("|%4u", this->_hrm_index);
 588   st->print("|" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT,
 589             p2i(bottom()), p2i(top()), p2i(end()));
 590   st->print("|%3d%%", (int) ((double) used() * 100 / capacity()));


 644   template <class T>
 645   void do_oop_work(T* p) {
 646     assert(_containing_obj != NULL, "Precondition");
 647     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 648       "Precondition");
 649     verify_liveness(p);
 650   }
 651 
 652   template <class T>
 653   void verify_liveness(T* p) {
 654     T heap_oop = oopDesc::load_heap_oop(p);
 655     LogHandle(gc, verify) log;
 656     if (!oopDesc::is_null(heap_oop)) {
 657       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 658       bool failed = false;
 659       if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
 660         MutexLockerEx x(ParGCRareEvent_lock,
 661           Mutex::_no_safepoint_check_flag);
 662 
 663         if (!_failures) {
 664           log.info("----------");
 665         }
 666         ResourceMark rm;
 667         if (!_g1h->is_in_closed_subset(obj)) {
 668           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 669           log.info("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 670             p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
 671           print_object(log.info_stream(), _containing_obj);
 672           log.info("points to obj " PTR_FORMAT " not in the heap", p2i(obj));
 673         } else {
 674           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 675           HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
 676           log.info("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 677             p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
 678           print_object(log.info_stream(), _containing_obj);
 679           log.info("points to dead obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 680             p2i(obj), p2i(to->bottom()), p2i(to->end()));
 681           print_object(log.info_stream(), obj);
 682         }
 683         log.info("----------");
 684         _failures = true;
 685         failed = true;
 686         _n_failures++;
 687       }
 688     }
 689   }
 690 };
 691 
 692 class VerifyRemSetClosure : public G1VerificationClosure {
 693 public:
 694   VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {}
 695   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 696   virtual void do_oop(oop* p) { do_oop_work(p); }
 697 
 698   template <class T>
 699   void do_oop_work(T* p) {
 700     assert(_containing_obj != NULL, "Precondition");
 701     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 702       "Precondition");
 703     verify_remembered_set(p);


 713       HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 714       HeapRegion* to = _g1h->heap_region_containing(obj);
 715       if (from != NULL && to != NULL &&
 716         from != to &&
 717         !to->is_pinned()) {
 718         jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
 719         jbyte cv_field = *_bs->byte_for_const(p);
 720         const jbyte dirty = CardTableModRefBS::dirty_card_val();
 721 
 722         bool is_bad = !(from->is_young()
 723           || to->rem_set()->contains_reference(p)
 724           || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
 725           (_containing_obj->is_objArray() ?
 726           cv_field == dirty
 727           : cv_obj == dirty || cv_field == dirty));
 728         if (is_bad) {
 729           MutexLockerEx x(ParGCRareEvent_lock,
 730             Mutex::_no_safepoint_check_flag);
 731 
 732           if (!_failures) {
 733             log.info("----------");
 734           }
 735           log.info("Missing rem set entry:");
 736           log.info("Field " PTR_FORMAT " of obj " PTR_FORMAT ", in region " HR_FORMAT,
 737             p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from));
 738           ResourceMark rm;
 739           _containing_obj->print_on(log.info_stream());
 740           log.info("points to obj " PTR_FORMAT " in region " HR_FORMAT, p2i(obj), HR_FORMAT_PARAMS(to));
 741           obj->print_on(log.info_stream());
 742           log.info("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
 743           log.info("----------");
 744           _failures = true;
 745           if (!failed) _n_failures++;
 746         }
 747       }
 748     }
 749   }
 750 };
 751 
 752 // This really ought to be commoned up into OffsetTableContigSpace somehow.
 753 // We would need a mechanism to make that code skip dead objects.
 754 
 755 void HeapRegion::verify(VerifyOption vo,
 756                         bool* failures) const {
 757   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 758   *failures = false;
 759   HeapWord* p = bottom();
 760   HeapWord* prev_p = NULL;
 761   VerifyLiveClosure vl_cl(g1, vo);
 762   VerifyRemSetClosure vr_cl(g1, vo);
 763   bool is_region_humongous = is_humongous();
 764   size_t object_num = 0;
 765   while (p < top()) {
 766     oop obj = oop(p);
 767     size_t obj_size = block_size(p);
 768     object_num += 1;
 769 
 770     if (!g1->is_obj_dead_cond(obj, this, vo)) {
 771       if (obj->is_oop()) {
 772         Klass* klass = obj->klass();
 773         bool is_metaspace_object = Metaspace::contains(klass) ||
 774                                    (vo == VerifyOption_G1UsePrevMarking &&
 775                                    ClassLoaderDataGraph::unload_list_contains(klass));
 776         if (!is_metaspace_object) {
 777           log_info(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 778                                "not metadata", p2i(klass), p2i(obj));
 779           *failures = true;
 780           return;
 781         } else if (!klass->is_klass()) {
 782           log_info(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 783                                "not a klass", p2i(klass), p2i(obj));
 784           *failures = true;
 785           return;
 786         } else {
 787           vl_cl.set_containing_obj(obj);
 788           if (!g1->collector_state()->full_collection() || G1VerifyRSetsDuringFullGC) {
 789             // verify liveness and rem_set
 790             vr_cl.set_containing_obj(obj);
 791             G1Mux2Closure mux(&vl_cl, &vr_cl);
 792             obj->oop_iterate_no_header(&mux);
 793 
 794             if (vr_cl.failures()) {
 795               *failures = true;
 796             }
 797             if (G1MaxVerifyFailures >= 0 &&
 798               vr_cl.n_failures() >= G1MaxVerifyFailures) {
 799               return;
 800             }
 801           } else {
 802             // verify only liveness
 803             obj->oop_iterate_no_header(&vl_cl);
 804           }
 805           if (vl_cl.failures()) {
 806             *failures = true;
 807           }
 808           if (G1MaxVerifyFailures >= 0 &&
 809               vl_cl.n_failures() >= G1MaxVerifyFailures) {
 810             return;
 811           }
 812         }
 813       } else {
 814         log_info(gc, verify)(PTR_FORMAT " not an oop", p2i(obj));
 815         *failures = true;
 816         return;
 817       }
 818     }
 819     prev_p = p;
 820     p += obj_size;
 821   }
 822 
 823   if (!is_young() && !is_empty()) {
 824     _bot_part.verify();
 825   }
 826 
 827   if (is_region_humongous) {
 828     oop obj = oop(this->humongous_start_region()->bottom());
 829     if ((HeapWord*)obj > bottom() || (HeapWord*)obj + obj->size() < bottom()) {
 830       log_info(gc, verify)("this humongous region is not part of its' humongous object " PTR_FORMAT, p2i(obj));
 831     }
 832   }
 833 
 834   if (!is_region_humongous && p != top()) {
 835     log_info(gc, verify)("end of last object " PTR_FORMAT " "
 836                          "does not match top " PTR_FORMAT, p2i(p), p2i(top()));
 837     *failures = true;
 838     return;
 839   }
 840 
 841   HeapWord* the_end = end();
 842   // Do some extra BOT consistency checking for addresses in the
 843   // range [top, end). BOT look-ups in this range should yield
 844   // top. No point in doing that if top == end (there's nothing there).
 845   if (p < the_end) {
 846     // Look up top
 847     HeapWord* addr_1 = p;
 848     HeapWord* b_start_1 = _bot_part.block_start_const(addr_1);
 849     if (b_start_1 != p) {
 850       log_info(gc, verify)("BOT look up for top: " PTR_FORMAT " "
 851                            " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 852                            p2i(addr_1), p2i(b_start_1), p2i(p));
 853       *failures = true;
 854       return;
 855     }
 856 
 857     // Look up top + 1
 858     HeapWord* addr_2 = p + 1;
 859     if (addr_2 < the_end) {
 860       HeapWord* b_start_2 = _bot_part.block_start_const(addr_2);
 861       if (b_start_2 != p) {
 862         log_info(gc, verify)("BOT look up for top + 1: " PTR_FORMAT " "
 863                              " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 864                              p2i(addr_2), p2i(b_start_2), p2i(p));
 865         *failures = true;
 866         return;
 867       }
 868     }
 869 
 870     // Look up an address between top and end
 871     size_t diff = pointer_delta(the_end, p) / 2;
 872     HeapWord* addr_3 = p + diff;
 873     if (addr_3 < the_end) {
 874       HeapWord* b_start_3 = _bot_part.block_start_const(addr_3);
 875       if (b_start_3 != p) {
 876         log_info(gc, verify)("BOT look up for top + diff: " PTR_FORMAT " "
 877                              " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 878                              p2i(addr_3), p2i(b_start_3), p2i(p));
 879         *failures = true;
 880         return;
 881       }
 882     }
 883 
 884     // Look up end - 1
 885     HeapWord* addr_4 = the_end - 1;
 886     HeapWord* b_start_4 = _bot_part.block_start_const(addr_4);
 887     if (b_start_4 != p) {
 888       log_info(gc, verify)("BOT look up for end - 1: " PTR_FORMAT " "
 889                            " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 890                            p2i(addr_4), p2i(b_start_4), p2i(p));
 891       *failures = true;
 892       return;
 893     }
 894   }
 895 
 896   verify_strong_code_roots(vo, failures);
 897 }
 898 
 899 void HeapRegion::verify() const {
 900   bool dummy = false;
 901   verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
 902 }
 903 
 904 void HeapRegion::verify_rem_set(VerifyOption vo, bool* failures) const {
 905   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 906   *failures = false;
 907   HeapWord* p = bottom();
 908   HeapWord* prev_p = NULL;
 909   VerifyRemSetClosure vr_cl(g1, vo);
 910   while (p < top()) {
 911     oop obj = oop(p);
 912     size_t obj_size = block_size(p);
 913 
 914     if (!g1->is_obj_dead_cond(obj, this, vo)) {
 915       if (obj->is_oop()) {
 916         vr_cl.set_containing_obj(obj);
 917         obj->oop_iterate_no_header(&vr_cl);
 918 
 919         if (vr_cl.failures()) {
 920           *failures = true;
 921         }
 922         if (G1MaxVerifyFailures >= 0 &&
 923           vr_cl.n_failures() >= G1MaxVerifyFailures) {
 924           return;
 925         }
 926       } else {
 927         log_info(gc, verify)(PTR_FORMAT " not an oop", p2i(obj));
 928         *failures = true;
 929         return;
 930       }
 931     }
 932 
 933     prev_p = p;
 934     p += obj_size;
 935   }
 936 }
 937 
 938 void HeapRegion::verify_rem_set() const {
 939   bool failures = false;
 940   verify_rem_set(VerifyOption_G1UsePrevMarking, &failures);
 941   guarantee(!failures, "HeapRegion RemSet verification failed");
 942 }
 943 
 944 void HeapRegion::prepare_for_compaction(CompactPoint* cp) {
 945   scan_and_forward(this, cp);
 946 }
 947 




 462   hrrs->strong_code_roots_do(blk);
 463 }
 464 
 465 class VerifyStrongCodeRootOopClosure: public OopClosure {
 466   const HeapRegion* _hr;
 467   nmethod* _nm;
 468   bool _failures;
 469   bool _has_oops_in_region;
 470 
 471   template <class T> void do_oop_work(T* p) {
 472     T heap_oop = oopDesc::load_heap_oop(p);
 473     if (!oopDesc::is_null(heap_oop)) {
 474       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 475 
 476       // Note: not all the oops embedded in the nmethod are in the
 477       // current region. We only look at those which are.
 478       if (_hr->is_in(obj)) {
 479         // Object is in the region. Check that its less than top
 480         if (_hr->top() <= (HeapWord*)obj) {
 481           // Object is above top
 482           log_error(gc, verify)("Object " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ") is above top " PTR_FORMAT,
 483                                p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top()));
 484           _failures = true;
 485           return;
 486         }
 487         // Nmethod has at least one oop in the current region
 488         _has_oops_in_region = true;
 489       }
 490     }
 491   }
 492 
 493 public:
 494   VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
 495     _hr(hr), _failures(false), _has_oops_in_region(false) {}
 496 
 497   void do_oop(narrowOop* p) { do_oop_work(p); }
 498   void do_oop(oop* p)       { do_oop_work(p); }
 499 
 500   bool failures()           { return _failures; }
 501   bool has_oops_in_region() { return _has_oops_in_region; }
 502 };
 503 
 504 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
 505   const HeapRegion* _hr;
 506   bool _failures;
 507 public:
 508   VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
 509     _hr(hr), _failures(false) {}
 510 
 511   void do_code_blob(CodeBlob* cb) {
 512     nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
 513     if (nm != NULL) {
 514       // Verify that the nemthod is live
 515       if (!nm->is_alive()) {
 516         log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has dead nmethod " PTR_FORMAT " in its strong code roots",
 517                               p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 518         _failures = true;
 519       } else {
 520         VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
 521         nm->oops_do(&oop_cl);
 522         if (!oop_cl.has_oops_in_region()) {
 523           log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its strong code roots with no pointers into region",
 524                                 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 525           _failures = true;
 526         } else if (oop_cl.failures()) {
 527           log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has other failures for nmethod " PTR_FORMAT,
 528                                 p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 529           _failures = true;
 530         }
 531       }
 532     }
 533   }
 534 
 535   bool failures()       { return _failures; }
 536 };
 537 
 538 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
 539   if (!G1VerifyHeapRegionCodeRoots) {
 540     // We're not verifying code roots.
 541     return;
 542   }
 543   if (vo == VerifyOption_G1UseMarkWord) {
 544     // Marking verification during a full GC is performed after class
 545     // unloading, code cache unloading, etc so the strong code roots
 546     // attached to each heap region are in an inconsistent state. They won't
 547     // be consistent until the strong code roots are rebuilt after the
 548     // actual GC. Skip verifying the strong code roots in this particular
 549     // time.
 550     assert(VerifyDuringGC, "only way to get here");
 551     return;
 552   }
 553 
 554   HeapRegionRemSet* hrrs = rem_set();
 555   size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
 556 
 557   // if this region is empty then there should be no entries
 558   // on its strong code root list
 559   if (is_empty()) {
 560     if (strong_code_roots_length > 0) {
 561       log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] is empty but has " SIZE_FORMAT " code root entries",
 562                             p2i(bottom()), p2i(end()), strong_code_roots_length);
 563       *failures = true;
 564     }
 565     return;
 566   }
 567 
 568   if (is_continues_humongous()) {
 569     if (strong_code_roots_length > 0) {
 570       log_error(gc, verify)("region " HR_FORMAT " is a continuation of a humongous region but has " SIZE_FORMAT " code root entries",
 571                             HR_FORMAT_PARAMS(this), strong_code_roots_length);
 572       *failures = true;
 573     }
 574     return;
 575   }
 576 
 577   VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
 578   strong_code_roots_do(&cb_cl);
 579 
 580   if (cb_cl.failures()) {
 581     *failures = true;
 582   }
 583 }
 584 
 585 void HeapRegion::print() const { print_on(tty); }
 586 void HeapRegion::print_on(outputStream* st) const {
 587   st->print("|%4u", this->_hrm_index);
 588   st->print("|" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT,
 589             p2i(bottom()), p2i(top()), p2i(end()));
 590   st->print("|%3d%%", (int) ((double) used() * 100 / capacity()));


 644   template <class T>
 645   void do_oop_work(T* p) {
 646     assert(_containing_obj != NULL, "Precondition");
 647     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 648       "Precondition");
 649     verify_liveness(p);
 650   }
 651 
 652   template <class T>
 653   void verify_liveness(T* p) {
 654     T heap_oop = oopDesc::load_heap_oop(p);
 655     LogHandle(gc, verify) log;
 656     if (!oopDesc::is_null(heap_oop)) {
 657       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 658       bool failed = false;
 659       if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
 660         MutexLockerEx x(ParGCRareEvent_lock,
 661           Mutex::_no_safepoint_check_flag);
 662 
 663         if (!_failures) {
 664           log.error("----------");
 665         }
 666         ResourceMark rm;
 667         if (!_g1h->is_in_closed_subset(obj)) {
 668           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 669           log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 670             p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
 671           print_object(log.error_stream(), _containing_obj);
 672           log.error("points to obj " PTR_FORMAT " not in the heap", p2i(obj));
 673         } else {
 674           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 675           HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
 676           log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 677             p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
 678           print_object(log.error_stream(), _containing_obj);
 679           log.error("points to dead obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 680             p2i(obj), p2i(to->bottom()), p2i(to->end()));
 681           print_object(log.error_stream(), obj);
 682         }
 683         log.error("----------");
 684         _failures = true;
 685         failed = true;
 686         _n_failures++;
 687       }
 688     }
 689   }
 690 };
 691 
 692 class VerifyRemSetClosure : public G1VerificationClosure {
 693 public:
 694   VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {}
 695   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 696   virtual void do_oop(oop* p) { do_oop_work(p); }
 697 
 698   template <class T>
 699   void do_oop_work(T* p) {
 700     assert(_containing_obj != NULL, "Precondition");
 701     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 702       "Precondition");
 703     verify_remembered_set(p);


 713       HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 714       HeapRegion* to = _g1h->heap_region_containing(obj);
 715       if (from != NULL && to != NULL &&
 716         from != to &&
 717         !to->is_pinned()) {
 718         jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
 719         jbyte cv_field = *_bs->byte_for_const(p);
 720         const jbyte dirty = CardTableModRefBS::dirty_card_val();
 721 
 722         bool is_bad = !(from->is_young()
 723           || to->rem_set()->contains_reference(p)
 724           || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
 725           (_containing_obj->is_objArray() ?
 726           cv_field == dirty
 727           : cv_obj == dirty || cv_field == dirty));
 728         if (is_bad) {
 729           MutexLockerEx x(ParGCRareEvent_lock,
 730             Mutex::_no_safepoint_check_flag);
 731 
 732           if (!_failures) {
 733             log.error("----------");
 734           }
 735           log.error("Missing rem set entry:");
 736           log.error("Field " PTR_FORMAT " of obj " PTR_FORMAT ", in region " HR_FORMAT,
 737             p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from));
 738           ResourceMark rm;
 739           _containing_obj->print_on(log.error_stream());
 740           log.error("points to obj " PTR_FORMAT " in region " HR_FORMAT, p2i(obj), HR_FORMAT_PARAMS(to));
 741           obj->print_on(log.error_stream());
 742           log.error("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
 743           log.error("----------");
 744           _failures = true;
 745           if (!failed) _n_failures++;
 746         }
 747       }
 748     }
 749   }
 750 };
 751 
 752 // This really ought to be commoned up into OffsetTableContigSpace somehow.
 753 // We would need a mechanism to make that code skip dead objects.
 754 
 755 void HeapRegion::verify(VerifyOption vo,
 756                         bool* failures) const {
 757   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 758   *failures = false;
 759   HeapWord* p = bottom();
 760   HeapWord* prev_p = NULL;
 761   VerifyLiveClosure vl_cl(g1, vo);
 762   VerifyRemSetClosure vr_cl(g1, vo);
 763   bool is_region_humongous = is_humongous();
 764   size_t object_num = 0;
 765   while (p < top()) {
 766     oop obj = oop(p);
 767     size_t obj_size = block_size(p);
 768     object_num += 1;
 769 
 770     if (!g1->is_obj_dead_cond(obj, this, vo)) {
 771       if (obj->is_oop()) {
 772         Klass* klass = obj->klass();
 773         bool is_metaspace_object = Metaspace::contains(klass) ||
 774                                    (vo == VerifyOption_G1UsePrevMarking &&
 775                                    ClassLoaderDataGraph::unload_list_contains(klass));
 776         if (!is_metaspace_object) {
 777           log_error(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 778                                 "not metadata", p2i(klass), p2i(obj));
 779           *failures = true;
 780           return;
 781         } else if (!klass->is_klass()) {
 782           log_error(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 783                                 "not a klass", p2i(klass), p2i(obj));
 784           *failures = true;
 785           return;
 786         } else {
 787           vl_cl.set_containing_obj(obj);
 788           if (!g1->collector_state()->full_collection() || G1VerifyRSetsDuringFullGC) {
 789             // verify liveness and rem_set
 790             vr_cl.set_containing_obj(obj);
 791             G1Mux2Closure mux(&vl_cl, &vr_cl);
 792             obj->oop_iterate_no_header(&mux);
 793 
 794             if (vr_cl.failures()) {
 795               *failures = true;
 796             }
 797             if (G1MaxVerifyFailures >= 0 &&
 798               vr_cl.n_failures() >= G1MaxVerifyFailures) {
 799               return;
 800             }
 801           } else {
 802             // verify only liveness
 803             obj->oop_iterate_no_header(&vl_cl);
 804           }
 805           if (vl_cl.failures()) {
 806             *failures = true;
 807           }
 808           if (G1MaxVerifyFailures >= 0 &&
 809               vl_cl.n_failures() >= G1MaxVerifyFailures) {
 810             return;
 811           }
 812         }
 813       } else {
 814         log_error(gc, verify)(PTR_FORMAT " not an oop", p2i(obj));
 815         *failures = true;
 816         return;
 817       }
 818     }
 819     prev_p = p;
 820     p += obj_size;
 821   }
 822 
 823   if (!is_young() && !is_empty()) {
 824     _bot_part.verify();
 825   }
 826 
 827   if (is_region_humongous) {
 828     oop obj = oop(this->humongous_start_region()->bottom());
 829     if ((HeapWord*)obj > bottom() || (HeapWord*)obj + obj->size() < bottom()) {
 830       log_error(gc, verify)("this humongous region is not part of its' humongous object " PTR_FORMAT, p2i(obj));
 831     }
 832   }
 833 
 834   if (!is_region_humongous && p != top()) {
 835     log_error(gc, verify)("end of last object " PTR_FORMAT " "
 836                           "does not match top " PTR_FORMAT, p2i(p), p2i(top()));
 837     *failures = true;
 838     return;
 839   }
 840 
 841   HeapWord* the_end = end();
 842   // Do some extra BOT consistency checking for addresses in the
 843   // range [top, end). BOT look-ups in this range should yield
 844   // top. No point in doing that if top == end (there's nothing there).
 845   if (p < the_end) {
 846     // Look up top
 847     HeapWord* addr_1 = p;
 848     HeapWord* b_start_1 = _bot_part.block_start_const(addr_1);
 849     if (b_start_1 != p) {
 850       log_error(gc, verify)("BOT look up for top: " PTR_FORMAT " "
 851                             " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 852                             p2i(addr_1), p2i(b_start_1), p2i(p));
 853       *failures = true;
 854       return;
 855     }
 856 
 857     // Look up top + 1
 858     HeapWord* addr_2 = p + 1;
 859     if (addr_2 < the_end) {
 860       HeapWord* b_start_2 = _bot_part.block_start_const(addr_2);
 861       if (b_start_2 != p) {
 862         log_error(gc, verify)("BOT look up for top + 1: " PTR_FORMAT " "
 863                               " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 864                               p2i(addr_2), p2i(b_start_2), p2i(p));
 865         *failures = true;
 866         return;
 867       }
 868     }
 869 
 870     // Look up an address between top and end
 871     size_t diff = pointer_delta(the_end, p) / 2;
 872     HeapWord* addr_3 = p + diff;
 873     if (addr_3 < the_end) {
 874       HeapWord* b_start_3 = _bot_part.block_start_const(addr_3);
 875       if (b_start_3 != p) {
 876         log_error(gc, verify)("BOT look up for top + diff: " PTR_FORMAT " "
 877                               " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 878                               p2i(addr_3), p2i(b_start_3), p2i(p));
 879         *failures = true;
 880         return;
 881       }
 882     }
 883 
 884     // Look up end - 1
 885     HeapWord* addr_4 = the_end - 1;
 886     HeapWord* b_start_4 = _bot_part.block_start_const(addr_4);
 887     if (b_start_4 != p) {
 888       log_error(gc, verify)("BOT look up for end - 1: " PTR_FORMAT " "
 889                             " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 890                             p2i(addr_4), p2i(b_start_4), p2i(p));
 891       *failures = true;
 892       return;
 893     }
 894   }
 895 
 896   verify_strong_code_roots(vo, failures);
 897 }
 898 
 899 void HeapRegion::verify() const {
 900   bool dummy = false;
 901   verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
 902 }
 903 
 904 void HeapRegion::verify_rem_set(VerifyOption vo, bool* failures) const {
 905   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 906   *failures = false;
 907   HeapWord* p = bottom();
 908   HeapWord* prev_p = NULL;
 909   VerifyRemSetClosure vr_cl(g1, vo);
 910   while (p < top()) {
 911     oop obj = oop(p);
 912     size_t obj_size = block_size(p);
 913 
 914     if (!g1->is_obj_dead_cond(obj, this, vo)) {
 915       if (obj->is_oop()) {
 916         vr_cl.set_containing_obj(obj);
 917         obj->oop_iterate_no_header(&vr_cl);
 918 
 919         if (vr_cl.failures()) {
 920           *failures = true;
 921         }
 922         if (G1MaxVerifyFailures >= 0 &&
 923           vr_cl.n_failures() >= G1MaxVerifyFailures) {
 924           return;
 925         }
 926       } else {
 927         log_error(gc, verify)(PTR_FORMAT " not an oop", p2i(obj));
 928         *failures = true;
 929         return;
 930       }
 931     }
 932 
 933     prev_p = p;
 934     p += obj_size;
 935   }
 936 }
 937 
 938 void HeapRegion::verify_rem_set() const {
 939   bool failures = false;
 940   verify_rem_set(VerifyOption_G1UsePrevMarking, &failures);
 941   guarantee(!failures, "HeapRegion RemSet verification failed");
 942 }
 943 
 944 void HeapRegion::prepare_for_compaction(CompactPoint* cp) {
 945   scan_and_forward(this, cp);
 946 }
 947 


< prev index next >