< prev index next >

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

Print this page




  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 "code/nmethod.hpp"
  27 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
  28 #include "gc/g1/g1CollectedHeap.inline.hpp"
  29 #include "gc/g1/g1OopClosures.inline.hpp"
  30 #include "gc/g1/heapRegion.inline.hpp"
  31 #include "gc/g1/heapRegionBounds.inline.hpp"
  32 #include "gc/g1/heapRegionManager.inline.hpp"
  33 #include "gc/g1/heapRegionRemSet.hpp"
  34 #include "gc/shared/genOopClosures.inline.hpp"
  35 #include "gc/shared/liveRange.hpp"
  36 #include "gc/shared/space.inline.hpp"

  37 #include "memory/iterator.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/atomic.inline.hpp"
  40 #include "runtime/orderAccess.inline.hpp"
  41 
  42 int    HeapRegion::LogOfHRGrainBytes = 0;
  43 int    HeapRegion::LogOfHRGrainWords = 0;
  44 size_t HeapRegion::GrainBytes        = 0;
  45 size_t HeapRegion::GrainWords        = 0;
  46 size_t HeapRegion::CardsPerRegion    = 0;
  47 
  48 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
  49                                  HeapRegion* hr,
  50                                  G1ParPushHeapRSClosure* cl,
  51                                  CardTableModRefBS::PrecisionStyle precision) :
  52   DirtyCardToOopClosure(hr, cl, precision, NULL),
  53   _hr(hr), _rs_scan(cl), _g1(g1) { }
  54 
  55 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  56                                                    OopClosure* oc) :


 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           gclog_or_tty->print_cr("Object " PTR_FORMAT " in region "
 483                                  "[" PTR_FORMAT ", " PTR_FORMAT ") is above "
 484                                  "top " PTR_FORMAT,
 485                                  p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top()));
 486           _failures = true;
 487           return;
 488         }
 489         // Nmethod has at least one oop in the current region
 490         _has_oops_in_region = true;
 491       }
 492     }
 493   }
 494 
 495 public:
 496   VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
 497     _hr(hr), _failures(false), _has_oops_in_region(false) {}
 498 
 499   void do_oop(narrowOop* p) { do_oop_work(p); }
 500   void do_oop(oop* p)       { do_oop_work(p); }
 501 
 502   bool failures()           { return _failures; }
 503   bool has_oops_in_region() { return _has_oops_in_region; }
 504 };
 505 
 506 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
 507   const HeapRegion* _hr;
 508   bool _failures;
 509 public:
 510   VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
 511     _hr(hr), _failures(false) {}
 512 
 513   void do_code_blob(CodeBlob* cb) {
 514     nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
 515     if (nm != NULL) {
 516       // Verify that the nemthod is live
 517       if (!nm->is_alive()) {
 518         gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] has dead nmethod "
 519                                PTR_FORMAT " in its strong code roots",
 520                                p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 521         _failures = true;
 522       } else {
 523         VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
 524         nm->oops_do(&oop_cl);
 525         if (!oop_cl.has_oops_in_region()) {
 526           gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod "
 527                                  PTR_FORMAT " in its strong code roots "
 528                                  "with no pointers into region",
 529                                  p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 530           _failures = true;
 531         } else if (oop_cl.failures()) {
 532           gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] has other "
 533                                  "failures for nmethod " PTR_FORMAT,
 534                                  p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 535           _failures = true;
 536         }
 537       }
 538     }
 539   }
 540 
 541   bool failures()       { return _failures; }
 542 };
 543 
 544 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
 545   if (!G1VerifyHeapRegionCodeRoots) {
 546     // We're not verifying code roots.
 547     return;
 548   }
 549   if (vo == VerifyOption_G1UseMarkWord) {
 550     // Marking verification during a full GC is performed after class
 551     // unloading, code cache unloading, etc so the strong code roots
 552     // attached to each heap region are in an inconsistent state. They won't
 553     // be consistent until the strong code roots are rebuilt after the
 554     // actual GC. Skip verifying the strong code roots in this particular
 555     // time.
 556     assert(VerifyDuringGC, "only way to get here");
 557     return;
 558   }
 559 
 560   HeapRegionRemSet* hrrs = rem_set();
 561   size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
 562 
 563   // if this region is empty then there should be no entries
 564   // on its strong code root list
 565   if (is_empty()) {
 566     if (strong_code_roots_length > 0) {
 567       gclog_or_tty->print_cr("region [" PTR_FORMAT "," PTR_FORMAT "] is empty "
 568                              "but has " SIZE_FORMAT " code root entries",
 569                              p2i(bottom()), p2i(end()), strong_code_roots_length);
 570       *failures = true;
 571     }
 572     return;
 573   }
 574 
 575   if (is_continues_humongous()) {
 576     if (strong_code_roots_length > 0) {
 577       gclog_or_tty->print_cr("region " HR_FORMAT " is a continuation of a humongous "
 578                              "region but has " SIZE_FORMAT " code root entries",
 579                              HR_FORMAT_PARAMS(this), strong_code_roots_length);
 580       *failures = true;
 581     }
 582     return;
 583   }
 584 
 585   VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
 586   strong_code_roots_do(&cb_cl);
 587 
 588   if (cb_cl.failures()) {
 589     *failures = true;
 590   }
 591 }
 592 
 593 void HeapRegion::print() const { print_on(gclog_or_tty); }
 594 void HeapRegion::print_on(outputStream* st) const {
 595   st->print("|%4u", this->_hrm_index);
 596   st->print("|" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT,
 597             p2i(bottom()), p2i(top()), p2i(end()));
 598   st->print("|%3d%%", (int) ((double) used() * 100 / capacity()));
 599   st->print("|%2s", get_short_type_str());
 600   if (in_collection_set()) {
 601     st->print("|CS");
 602   } else {
 603     st->print("|  ");
 604   }
 605   st->print("|TS%3u", _gc_time_stamp);
 606   st->print("|AC%3u", allocation_context());
 607   st->print_cr("|TAMS " PTR_FORMAT ", " PTR_FORMAT "|",
 608                p2i(prev_top_at_mark_start()), p2i(next_top_at_mark_start()));
 609 }
 610 
 611 class VerifyLiveClosure: public OopClosure {
 612 private:
 613   G1CollectedHeap* _g1h;


 634 
 635   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 636   virtual void do_oop(      oop* p) { do_oop_work(p); }
 637 
 638   void print_object(outputStream* out, oop obj) {
 639 #ifdef PRODUCT
 640     Klass* k = obj->klass();
 641     const char* class_name = k->external_name();
 642     out->print_cr("class name %s", class_name);
 643 #else // PRODUCT
 644     obj->print_on(out);
 645 #endif // PRODUCT
 646   }
 647 
 648   template <class T>
 649   void do_oop_work(T* p) {
 650     assert(_containing_obj != NULL, "Precondition");
 651     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 652            "Precondition");
 653     T heap_oop = oopDesc::load_heap_oop(p);

 654     if (!oopDesc::is_null(heap_oop)) {
 655       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 656       bool failed = false;
 657       if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
 658         MutexLockerEx x(ParGCRareEvent_lock,
 659                         Mutex::_no_safepoint_check_flag);
 660 
 661         if (!_failures) {
 662           gclog_or_tty->cr();
 663           gclog_or_tty->print_cr("----------");
 664         }

 665         if (!_g1h->is_in_closed_subset(obj)) {
 666           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 667           gclog_or_tty->print_cr("Field " PTR_FORMAT
 668                                  " of live obj " PTR_FORMAT " in region "
 669                                  "[" PTR_FORMAT ", " PTR_FORMAT ")",
 670                                  p2i(p), p2i(_containing_obj),
 671                                  p2i(from->bottom()), p2i(from->end()));
 672           print_object(gclog_or_tty, _containing_obj);
 673           gclog_or_tty->print_cr("points to obj " PTR_FORMAT " not in the heap",
 674                                  p2i(obj));
 675         } else {
 676           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 677           HeapRegion* to   = _g1h->heap_region_containing((HeapWord*)obj);
 678           gclog_or_tty->print_cr("Field " PTR_FORMAT
 679                                  " of live obj " PTR_FORMAT " in region "
 680                                  "[" PTR_FORMAT ", " PTR_FORMAT ")",
 681                                  p2i(p), p2i(_containing_obj),
 682                                  p2i(from->bottom()), p2i(from->end()));
 683           print_object(gclog_or_tty, _containing_obj);
 684           gclog_or_tty->print_cr("points to dead obj " PTR_FORMAT " in region "
 685                                  "[" PTR_FORMAT ", " PTR_FORMAT ")",
 686                                  p2i(obj), p2i(to->bottom()), p2i(to->end()));
 687           print_object(gclog_or_tty, obj);
 688         }
 689         gclog_or_tty->print_cr("----------");
 690         gclog_or_tty->flush();
 691         _failures = true;
 692         failed = true;
 693         _n_failures++;
 694       }
 695 
 696       if (!_g1h->collector_state()->full_collection() || G1VerifyRSetsDuringFullGC) {
 697         HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 698         HeapRegion* to   = _g1h->heap_region_containing(obj);
 699         if (from != NULL && to != NULL &&
 700             from != to &&
 701             !to->is_pinned()) {
 702           jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
 703           jbyte cv_field = *_bs->byte_for_const(p);
 704           const jbyte dirty = CardTableModRefBS::dirty_card_val();
 705 
 706           bool is_bad = !(from->is_young()
 707                           || to->rem_set()->contains_reference(p)
 708                           || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
 709                               (_containing_obj->is_objArray() ?
 710                                   cv_field == dirty
 711                                : cv_obj == dirty || cv_field == dirty));
 712           if (is_bad) {
 713             MutexLockerEx x(ParGCRareEvent_lock,
 714                             Mutex::_no_safepoint_check_flag);
 715 
 716             if (!_failures) {
 717               gclog_or_tty->cr();
 718               gclog_or_tty->print_cr("----------");
 719             }
 720             gclog_or_tty->print_cr("Missing rem set entry:");
 721             gclog_or_tty->print_cr("Field " PTR_FORMAT " "
 722                                    "of obj " PTR_FORMAT ", "
 723                                    "in region " HR_FORMAT,
 724                                    p2i(p), p2i(_containing_obj),
 725                                    HR_FORMAT_PARAMS(from));
 726             _containing_obj->print_on(gclog_or_tty);
 727             gclog_or_tty->print_cr("points to obj " PTR_FORMAT " "
 728                                    "in region " HR_FORMAT,
 729                                    p2i(obj),
 730                                    HR_FORMAT_PARAMS(to));
 731             obj->print_on(gclog_or_tty);
 732             gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.",
 733                           cv_obj, cv_field);
 734             gclog_or_tty->print_cr("----------");
 735             gclog_or_tty->flush();
 736             _failures = true;
 737             if (!failed) _n_failures++;
 738           }
 739         }
 740       }
 741     }
 742   }
 743 };
 744 
 745 // This really ought to be commoned up into OffsetTableContigSpace somehow.
 746 // We would need a mechanism to make that code skip dead objects.
 747 
 748 void HeapRegion::verify(VerifyOption vo,
 749                         bool* failures) const {
 750   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 751   *failures = false;
 752   HeapWord* p = bottom();
 753   HeapWord* prev_p = NULL;
 754   VerifyLiveClosure vl_cl(g1, vo);
 755   bool is_region_humongous = is_humongous();
 756   size_t object_num = 0;
 757   while (p < top()) {
 758     oop obj = oop(p);
 759     size_t obj_size = block_size(p);
 760     object_num += 1;
 761 
 762     if (!g1->is_obj_dead_cond(obj, this, vo)) {
 763       if (obj->is_oop()) {
 764         Klass* klass = obj->klass();
 765         bool is_metaspace_object = Metaspace::contains(klass) ||
 766                                    (vo == VerifyOption_G1UsePrevMarking &&
 767                                    ClassLoaderDataGraph::unload_list_contains(klass));
 768         if (!is_metaspace_object) {
 769           gclog_or_tty->print_cr("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 770                                  "not metadata", p2i(klass), p2i(obj));
 771           *failures = true;
 772           return;
 773         } else if (!klass->is_klass()) {
 774           gclog_or_tty->print_cr("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 775                                  "not a klass", p2i(klass), p2i(obj));
 776           *failures = true;
 777           return;
 778         } else {
 779           vl_cl.set_containing_obj(obj);
 780           obj->oop_iterate_no_header(&vl_cl);
 781           if (vl_cl.failures()) {
 782             *failures = true;
 783           }
 784           if (G1MaxVerifyFailures >= 0 &&
 785               vl_cl.n_failures() >= G1MaxVerifyFailures) {
 786             return;
 787           }
 788         }
 789       } else {
 790         gclog_or_tty->print_cr(PTR_FORMAT " no an oop", p2i(obj));
 791         *failures = true;
 792         return;
 793       }
 794     }
 795     prev_p = p;
 796     p += obj_size;
 797   }
 798 
 799   if (!is_young() && !is_empty()) {
 800     _offsets.verify();
 801   }
 802 
 803   if (is_region_humongous) {
 804     oop obj = oop(this->humongous_start_region()->bottom());
 805     if ((HeapWord*)obj > bottom() || (HeapWord*)obj + obj->size() < bottom()) {
 806       gclog_or_tty->print_cr("this humongous region is not part of its' humongous object " PTR_FORMAT, p2i(obj));
 807     }
 808   }
 809 
 810   if (!is_region_humongous && p != top()) {
 811     gclog_or_tty->print_cr("end of last object " PTR_FORMAT " "
 812                            "does not match top " PTR_FORMAT, p2i(p), p2i(top()));
 813     *failures = true;
 814     return;
 815   }
 816 
 817   HeapWord* the_end = end();
 818   // Do some extra BOT consistency checking for addresses in the
 819   // range [top, end). BOT look-ups in this range should yield
 820   // top. No point in doing that if top == end (there's nothing there).
 821   if (p < the_end) {
 822     // Look up top
 823     HeapWord* addr_1 = p;
 824     HeapWord* b_start_1 = _offsets.block_start_const(addr_1);
 825     if (b_start_1 != p) {
 826       gclog_or_tty->print_cr("BOT look up for top: " PTR_FORMAT " "
 827                              " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 828                              p2i(addr_1), p2i(b_start_1), p2i(p));
 829       *failures = true;
 830       return;
 831     }
 832 
 833     // Look up top + 1
 834     HeapWord* addr_2 = p + 1;
 835     if (addr_2 < the_end) {
 836       HeapWord* b_start_2 = _offsets.block_start_const(addr_2);
 837       if (b_start_2 != p) {
 838         gclog_or_tty->print_cr("BOT look up for top + 1: " PTR_FORMAT " "
 839                                " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 840                                p2i(addr_2), p2i(b_start_2), p2i(p));
 841         *failures = true;
 842         return;
 843       }
 844     }
 845 
 846     // Look up an address between top and end
 847     size_t diff = pointer_delta(the_end, p) / 2;
 848     HeapWord* addr_3 = p + diff;
 849     if (addr_3 < the_end) {
 850       HeapWord* b_start_3 = _offsets.block_start_const(addr_3);
 851       if (b_start_3 != p) {
 852         gclog_or_tty->print_cr("BOT look up for top + diff: " PTR_FORMAT " "
 853                                " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 854                                p2i(addr_3), p2i(b_start_3), p2i(p));
 855         *failures = true;
 856         return;
 857       }
 858     }
 859 
 860     // Look up end - 1
 861     HeapWord* addr_4 = the_end - 1;
 862     HeapWord* b_start_4 = _offsets.block_start_const(addr_4);
 863     if (b_start_4 != p) {
 864       gclog_or_tty->print_cr("BOT look up for end - 1: " PTR_FORMAT " "
 865                              " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 866                              p2i(addr_4), p2i(b_start_4), p2i(p));
 867       *failures = true;
 868       return;
 869     }
 870   }
 871 
 872   verify_strong_code_roots(vo, failures);
 873 }
 874 
 875 void HeapRegion::verify() const {
 876   bool dummy = false;
 877   verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
 878 }
 879 
 880 void HeapRegion::prepare_for_compaction(CompactPoint* cp) {
 881   scan_and_forward(this, cp);
 882 }
 883 
 884 // G1OffsetTableContigSpace code; copied from space.cpp.  Hope this can go


 897 }
 898 
 899 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) {
 900   assert(new_end == _bottom + HeapRegion::GrainWords, "set_end should only ever be set to _bottom + HeapRegion::GrainWords");
 901   Space::set_end(new_end);
 902   _offsets.resize(new_end - bottom());
 903 }
 904 
 905 #ifndef PRODUCT
 906 void G1OffsetTableContigSpace::mangle_unused_area() {
 907   mangle_unused_area_complete();
 908 }
 909 
 910 void G1OffsetTableContigSpace::mangle_unused_area_complete() {
 911   SpaceMangler::mangle_region(MemRegion(top(), end()));
 912 }
 913 #endif
 914 
 915 void G1OffsetTableContigSpace::print() const {
 916   print_short();
 917   gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
 918                 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
 919                 p2i(bottom()), p2i(top()), p2i(_offsets.threshold()), p2i(end()));
 920 }
 921 
 922 HeapWord* G1OffsetTableContigSpace::initialize_threshold() {
 923   return _offsets.initialize_threshold();
 924 }
 925 
 926 HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start,
 927                                                     HeapWord* end) {
 928   _offsets.alloc_block(start, end);
 929   return _offsets.threshold();
 930 }
 931 
 932 HeapWord* G1OffsetTableContigSpace::scan_top() const {
 933   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 934   HeapWord* local_top = top();
 935   OrderAccess::loadload();
 936   const unsigned local_time_stamp = _gc_time_stamp;
 937   assert(local_time_stamp <= g1h->get_gc_time_stamp(), "invariant");




  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 "code/nmethod.hpp"
  27 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
  28 #include "gc/g1/g1CollectedHeap.inline.hpp"
  29 #include "gc/g1/g1OopClosures.inline.hpp"
  30 #include "gc/g1/heapRegion.inline.hpp"
  31 #include "gc/g1/heapRegionBounds.inline.hpp"
  32 #include "gc/g1/heapRegionManager.inline.hpp"
  33 #include "gc/g1/heapRegionRemSet.hpp"
  34 #include "gc/shared/genOopClosures.inline.hpp"
  35 #include "gc/shared/liveRange.hpp"
  36 #include "gc/shared/space.inline.hpp"
  37 #include "logging/log.hpp"
  38 #include "memory/iterator.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "runtime/atomic.inline.hpp"
  41 #include "runtime/orderAccess.inline.hpp"
  42 
  43 int    HeapRegion::LogOfHRGrainBytes = 0;
  44 int    HeapRegion::LogOfHRGrainWords = 0;
  45 size_t HeapRegion::GrainBytes        = 0;
  46 size_t HeapRegion::GrainWords        = 0;
  47 size_t HeapRegion::CardsPerRegion    = 0;
  48 
  49 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
  50                                  HeapRegion* hr,
  51                                  G1ParPushHeapRSClosure* cl,
  52                                  CardTableModRefBS::PrecisionStyle precision) :
  53   DirtyCardToOopClosure(hr, cl, precision, NULL),
  54   _hr(hr), _rs_scan(cl), _g1(g1) { }
  55 
  56 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
  57                                                    OopClosure* oc) :


 463   hrrs->strong_code_roots_do(blk);
 464 }
 465 
 466 class VerifyStrongCodeRootOopClosure: public OopClosure {
 467   const HeapRegion* _hr;
 468   nmethod* _nm;
 469   bool _failures;
 470   bool _has_oops_in_region;
 471 
 472   template <class T> void do_oop_work(T* p) {
 473     T heap_oop = oopDesc::load_heap_oop(p);
 474     if (!oopDesc::is_null(heap_oop)) {
 475       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 476 
 477       // Note: not all the oops embedded in the nmethod are in the
 478       // current region. We only look at those which are.
 479       if (_hr->is_in(obj)) {
 480         // Object is in the region. Check that its less than top
 481         if (_hr->top() <= (HeapWord*)obj) {
 482           // Object is above top
 483           log_info(gc, verify)("Object " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ") is above top " PTR_FORMAT,


 484                                p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top()));
 485           _failures = true;
 486           return;
 487         }
 488         // Nmethod has at least one oop in the current region
 489         _has_oops_in_region = true;
 490       }
 491     }
 492   }
 493 
 494 public:
 495   VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
 496     _hr(hr), _failures(false), _has_oops_in_region(false) {}
 497 
 498   void do_oop(narrowOop* p) { do_oop_work(p); }
 499   void do_oop(oop* p)       { do_oop_work(p); }
 500 
 501   bool failures()           { return _failures; }
 502   bool has_oops_in_region() { return _has_oops_in_region; }
 503 };
 504 
 505 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
 506   const HeapRegion* _hr;
 507   bool _failures;
 508 public:
 509   VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
 510     _hr(hr), _failures(false) {}
 511 
 512   void do_code_blob(CodeBlob* cb) {
 513     nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
 514     if (nm != NULL) {
 515       // Verify that the nemthod is live
 516       if (!nm->is_alive()) {
 517         log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has dead nmethod " PTR_FORMAT " in its strong code roots",

 518                              p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 519         _failures = true;
 520       } else {
 521         VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
 522         nm->oops_do(&oop_cl);
 523         if (!oop_cl.has_oops_in_region()) {
 524           log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its strong code roots with no pointers into region",


 525                                p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 526           _failures = true;
 527         } else if (oop_cl.failures()) {
 528           log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has other failures for nmethod " PTR_FORMAT,

 529                                p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
 530           _failures = true;
 531         }
 532       }
 533     }
 534   }
 535 
 536   bool failures()       { return _failures; }
 537 };
 538 
 539 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
 540   if (!G1VerifyHeapRegionCodeRoots) {
 541     // We're not verifying code roots.
 542     return;
 543   }
 544   if (vo == VerifyOption_G1UseMarkWord) {
 545     // Marking verification during a full GC is performed after class
 546     // unloading, code cache unloading, etc so the strong code roots
 547     // attached to each heap region are in an inconsistent state. They won't
 548     // be consistent until the strong code roots are rebuilt after the
 549     // actual GC. Skip verifying the strong code roots in this particular
 550     // time.
 551     assert(VerifyDuringGC, "only way to get here");
 552     return;
 553   }
 554 
 555   HeapRegionRemSet* hrrs = rem_set();
 556   size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
 557 
 558   // if this region is empty then there should be no entries
 559   // on its strong code root list
 560   if (is_empty()) {
 561     if (strong_code_roots_length > 0) {
 562       log_info(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] is empty but has " SIZE_FORMAT " code root entries",

 563                            p2i(bottom()), p2i(end()), strong_code_roots_length);
 564       *failures = true;
 565     }
 566     return;
 567   }
 568 
 569   if (is_continues_humongous()) {
 570     if (strong_code_roots_length > 0) {
 571       log_info(gc, verify)("region " HR_FORMAT " is a continuation of a humongous region but has " SIZE_FORMAT " code root entries",

 572                            HR_FORMAT_PARAMS(this), strong_code_roots_length);
 573       *failures = true;
 574     }
 575     return;
 576   }
 577 
 578   VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
 579   strong_code_roots_do(&cb_cl);
 580 
 581   if (cb_cl.failures()) {
 582     *failures = true;
 583   }
 584 }
 585 
 586 void HeapRegion::print() const { print_on(tty); }
 587 void HeapRegion::print_on(outputStream* st) const {
 588   st->print("|%4u", this->_hrm_index);
 589   st->print("|" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT,
 590             p2i(bottom()), p2i(top()), p2i(end()));
 591   st->print("|%3d%%", (int) ((double) used() * 100 / capacity()));
 592   st->print("|%2s", get_short_type_str());
 593   if (in_collection_set()) {
 594     st->print("|CS");
 595   } else {
 596     st->print("|  ");
 597   }
 598   st->print("|TS%3u", _gc_time_stamp);
 599   st->print("|AC%3u", allocation_context());
 600   st->print_cr("|TAMS " PTR_FORMAT ", " PTR_FORMAT "|",
 601                p2i(prev_top_at_mark_start()), p2i(next_top_at_mark_start()));
 602 }
 603 
 604 class VerifyLiveClosure: public OopClosure {
 605 private:
 606   G1CollectedHeap* _g1h;


 627 
 628   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 629   virtual void do_oop(      oop* p) { do_oop_work(p); }
 630 
 631   void print_object(outputStream* out, oop obj) {
 632 #ifdef PRODUCT
 633     Klass* k = obj->klass();
 634     const char* class_name = k->external_name();
 635     out->print_cr("class name %s", class_name);
 636 #else // PRODUCT
 637     obj->print_on(out);
 638 #endif // PRODUCT
 639   }
 640 
 641   template <class T>
 642   void do_oop_work(T* p) {
 643     assert(_containing_obj != NULL, "Precondition");
 644     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 645            "Precondition");
 646     T heap_oop = oopDesc::load_heap_oop(p);
 647     LogHandle(gc, verify) log;
 648     if (!oopDesc::is_null(heap_oop)) {
 649       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 650       bool failed = false;
 651       if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
 652         MutexLockerEx x(ParGCRareEvent_lock,
 653                         Mutex::_no_safepoint_check_flag);
 654 
 655         if (!_failures) {
 656           log.info("----------");

 657         }
 658         ResourceMark rm;
 659         if (!_g1h->is_in_closed_subset(obj)) {
 660           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 661           log.info("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 662                    p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
 663           print_object(log.info_stream(), _containing_obj);
 664           log.info("points to obj " PTR_FORMAT " not in the heap", p2i(obj));




 665         } else {
 666           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 667           HeapRegion* to   = _g1h->heap_region_containing((HeapWord*)obj);
 668           log.info("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
 669                    p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
 670           print_object(log.info_stream(), _containing_obj);
 671           log.info("points to dead obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",




 672                    p2i(obj), p2i(to->bottom()), p2i(to->end()));
 673           print_object(log.info_stream(), obj);
 674         }
 675         log.info("----------");

 676         _failures = true;
 677         failed = true;
 678         _n_failures++;
 679       }
 680 
 681       if (!_g1h->collector_state()->full_collection() || G1VerifyRSetsDuringFullGC) {
 682         HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 683         HeapRegion* to   = _g1h->heap_region_containing(obj);
 684         if (from != NULL && to != NULL &&
 685             from != to &&
 686             !to->is_pinned()) {
 687           jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
 688           jbyte cv_field = *_bs->byte_for_const(p);
 689           const jbyte dirty = CardTableModRefBS::dirty_card_val();
 690 
 691           bool is_bad = !(from->is_young()
 692                           || to->rem_set()->contains_reference(p)
 693                           || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
 694                               (_containing_obj->is_objArray() ?
 695                                   cv_field == dirty
 696                                : cv_obj == dirty || cv_field == dirty));
 697           if (is_bad) {
 698             MutexLockerEx x(ParGCRareEvent_lock,
 699                             Mutex::_no_safepoint_check_flag);
 700 
 701             if (!_failures) {
 702               log.info("----------");

 703             }
 704             log.info("Missing rem set entry:");
 705             log.info("Field " PTR_FORMAT " of obj " PTR_FORMAT ", in region " HR_FORMAT,
 706                      p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from));
 707             ResourceMark rm;
 708             _containing_obj->print_on(log.info_stream());
 709             log.info("points to obj " PTR_FORMAT " in region " HR_FORMAT, p2i(obj), HR_FORMAT_PARAMS(to));
 710             obj->print_on(log.info_stream());
 711             log.info("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
 712             log.info("----------");







 713             _failures = true;
 714             if (!failed) _n_failures++;
 715           }
 716         }
 717       }
 718     }
 719   }
 720 };
 721 
 722 // This really ought to be commoned up into OffsetTableContigSpace somehow.
 723 // We would need a mechanism to make that code skip dead objects.
 724 
 725 void HeapRegion::verify(VerifyOption vo,
 726                         bool* failures) const {
 727   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 728   *failures = false;
 729   HeapWord* p = bottom();
 730   HeapWord* prev_p = NULL;
 731   VerifyLiveClosure vl_cl(g1, vo);
 732   bool is_region_humongous = is_humongous();
 733   size_t object_num = 0;
 734   while (p < top()) {
 735     oop obj = oop(p);
 736     size_t obj_size = block_size(p);
 737     object_num += 1;
 738 
 739     if (!g1->is_obj_dead_cond(obj, this, vo)) {
 740       if (obj->is_oop()) {
 741         Klass* klass = obj->klass();
 742         bool is_metaspace_object = Metaspace::contains(klass) ||
 743                                    (vo == VerifyOption_G1UsePrevMarking &&
 744                                    ClassLoaderDataGraph::unload_list_contains(klass));
 745         if (!is_metaspace_object) {
 746           log_info(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 747                                "not metadata", p2i(klass), p2i(obj));
 748           *failures = true;
 749           return;
 750         } else if (!klass->is_klass()) {
 751           log_info(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " "
 752                                "not a klass", p2i(klass), p2i(obj));
 753           *failures = true;
 754           return;
 755         } else {
 756           vl_cl.set_containing_obj(obj);
 757           obj->oop_iterate_no_header(&vl_cl);
 758           if (vl_cl.failures()) {
 759             *failures = true;
 760           }
 761           if (G1MaxVerifyFailures >= 0 &&
 762               vl_cl.n_failures() >= G1MaxVerifyFailures) {
 763             return;
 764           }
 765         }
 766       } else {
 767         log_info(gc, verify)(PTR_FORMAT " no an oop", p2i(obj));
 768         *failures = true;
 769         return;
 770       }
 771     }
 772     prev_p = p;
 773     p += obj_size;
 774   }
 775 
 776   if (!is_young() && !is_empty()) {
 777     _offsets.verify();
 778   }
 779 
 780   if (is_region_humongous) {
 781     oop obj = oop(this->humongous_start_region()->bottom());
 782     if ((HeapWord*)obj > bottom() || (HeapWord*)obj + obj->size() < bottom()) {
 783       log_info(gc, verify)("this humongous region is not part of its' humongous object " PTR_FORMAT, p2i(obj));
 784     }
 785   }
 786 
 787   if (!is_region_humongous && p != top()) {
 788     log_info(gc, verify)("end of last object " PTR_FORMAT " "
 789                          "does not match top " PTR_FORMAT, p2i(p), p2i(top()));
 790     *failures = true;
 791     return;
 792   }
 793 
 794   HeapWord* the_end = end();
 795   // Do some extra BOT consistency checking for addresses in the
 796   // range [top, end). BOT look-ups in this range should yield
 797   // top. No point in doing that if top == end (there's nothing there).
 798   if (p < the_end) {
 799     // Look up top
 800     HeapWord* addr_1 = p;
 801     HeapWord* b_start_1 = _offsets.block_start_const(addr_1);
 802     if (b_start_1 != p) {
 803       log_info(gc, verify)("BOT look up for top: " PTR_FORMAT " "
 804                            " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 805                            p2i(addr_1), p2i(b_start_1), p2i(p));
 806       *failures = true;
 807       return;
 808     }
 809 
 810     // Look up top + 1
 811     HeapWord* addr_2 = p + 1;
 812     if (addr_2 < the_end) {
 813       HeapWord* b_start_2 = _offsets.block_start_const(addr_2);
 814       if (b_start_2 != p) {
 815         log_info(gc, verify)("BOT look up for top + 1: " PTR_FORMAT " "
 816                              " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 817                              p2i(addr_2), p2i(b_start_2), p2i(p));
 818         *failures = true;
 819         return;
 820       }
 821     }
 822 
 823     // Look up an address between top and end
 824     size_t diff = pointer_delta(the_end, p) / 2;
 825     HeapWord* addr_3 = p + diff;
 826     if (addr_3 < the_end) {
 827       HeapWord* b_start_3 = _offsets.block_start_const(addr_3);
 828       if (b_start_3 != p) {
 829         log_info(gc, verify)("BOT look up for top + diff: " PTR_FORMAT " "
 830                              " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 831                              p2i(addr_3), p2i(b_start_3), p2i(p));
 832         *failures = true;
 833         return;
 834       }
 835     }
 836 
 837     // Look up end - 1
 838     HeapWord* addr_4 = the_end - 1;
 839     HeapWord* b_start_4 = _offsets.block_start_const(addr_4);
 840     if (b_start_4 != p) {
 841       log_info(gc, verify)("BOT look up for end - 1: " PTR_FORMAT " "
 842                            " yielded " PTR_FORMAT ", expecting " PTR_FORMAT,
 843                            p2i(addr_4), p2i(b_start_4), p2i(p));
 844       *failures = true;
 845       return;
 846     }
 847   }
 848 
 849   verify_strong_code_roots(vo, failures);
 850 }
 851 
 852 void HeapRegion::verify() const {
 853   bool dummy = false;
 854   verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
 855 }
 856 
 857 void HeapRegion::prepare_for_compaction(CompactPoint* cp) {
 858   scan_and_forward(this, cp);
 859 }
 860 
 861 // G1OffsetTableContigSpace code; copied from space.cpp.  Hope this can go


 874 }
 875 
 876 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) {
 877   assert(new_end == _bottom + HeapRegion::GrainWords, "set_end should only ever be set to _bottom + HeapRegion::GrainWords");
 878   Space::set_end(new_end);
 879   _offsets.resize(new_end - bottom());
 880 }
 881 
 882 #ifndef PRODUCT
 883 void G1OffsetTableContigSpace::mangle_unused_area() {
 884   mangle_unused_area_complete();
 885 }
 886 
 887 void G1OffsetTableContigSpace::mangle_unused_area_complete() {
 888   SpaceMangler::mangle_region(MemRegion(top(), end()));
 889 }
 890 #endif
 891 
 892 void G1OffsetTableContigSpace::print() const {
 893   print_short();
 894   tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
 895                 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
 896                 p2i(bottom()), p2i(top()), p2i(_offsets.threshold()), p2i(end()));
 897 }
 898 
 899 HeapWord* G1OffsetTableContigSpace::initialize_threshold() {
 900   return _offsets.initialize_threshold();
 901 }
 902 
 903 HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start,
 904                                                     HeapWord* end) {
 905   _offsets.alloc_block(start, end);
 906   return _offsets.threshold();
 907 }
 908 
 909 HeapWord* G1OffsetTableContigSpace::scan_top() const {
 910   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 911   HeapWord* local_top = top();
 912   OrderAccess::loadload();
 913   const unsigned local_time_stamp = _gc_time_stamp;
 914   assert(local_time_stamp <= g1h->get_gc_time_stamp(), "invariant");


< prev index next >