< prev index next >

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

Print this page




  43 class VerifyRootsClosure: public OopClosure {
  44 private:
  45   G1CollectedHeap* _g1h;
  46   VerifyOption     _vo;
  47   bool             _failures;
  48 public:
  49   // _vo == UsePrevMarking -> use "prev" marking information,
  50   // _vo == UseNextMarking -> use "next" marking information,
  51   // _vo == UseMarkWord    -> use mark word from object header.
  52   VerifyRootsClosure(VerifyOption vo) :
  53     _g1h(G1CollectedHeap::heap()),
  54     _vo(vo),
  55     _failures(false) { }
  56 
  57   bool failures() { return _failures; }
  58 
  59   template <class T> void do_oop_nv(T* p) {
  60     T heap_oop = oopDesc::load_heap_oop(p);
  61     if (!oopDesc::is_null(heap_oop)) {
  62       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  63       HeapRegion* hr = _g1h->heap_region_containing(obj);
  64       if (_g1h->is_obj_dead_cond(obj, _vo) && !hr->is_archive()) {
  65         Log(gc, verify) log;
  66         log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
  67         if (_vo == VerifyOption_G1UseMarkWord) {
  68           log.error("  Mark word: " PTR_FORMAT, p2i(obj->mark()));
  69         }
  70         ResourceMark rm;
  71         LogStream ls(log.error());
  72         obj->print_on(&ls);
  73         _failures = true;
  74       }
  75     }
  76   }
  77 
  78   void do_oop(oop* p)       { do_oop_nv(p); }
  79   void do_oop(narrowOop* p) { do_oop_nv(p); }
  80 };
  81 
  82 class G1VerifyCodeRootOopClosure: public OopClosure {
  83   G1CollectedHeap* _g1h;
  84   OopClosure* _root_cl;


 219       // above: if the object is dead (according to the mark
 220       // word), it may not be marked, or may have been marked
 221       // but has since became dead, or may have been allocated
 222       // since the last marking.
 223       if (_vo == VerifyOption_G1UseMarkWord) {
 224         guarantee(!_g1h->is_obj_dead(o), "mark word and concurrent mark mismatch");
 225       }
 226 
 227       o->oop_iterate_no_header(&isLive);
 228       if (!_hr->obj_allocated_since_prev_marking(o)) {
 229         size_t obj_size = o->size();    // Make sure we don't overflow
 230         _live_bytes += (obj_size * HeapWordSize);
 231       }
 232     }
 233   }
 234   size_t live_bytes() { return _live_bytes; }
 235 };
 236 
 237 class VerifyArchiveOopClosure: public OopClosure {
 238   HeapRegion* _hr;
 239   bool _verbose;
 240 public:
 241   VerifyArchiveOopClosure(HeapRegion *hr, bool verbose)
 242     : _hr(hr), _verbose(verbose) { }
 243   void do_oop(narrowOop *p) { do_oop_work(p); }
 244   void do_oop(      oop *p) { do_oop_work(p); }
 245 
 246   template <class T> void do_oop_work(T *p) {
 247     oop obj = oopDesc::load_decode_heap_oop(p);
 248     if (_verbose) {
 249       if (obj != NULL) {
 250         obj->print();
 251       }
 252     }
 253 
 254     if (_hr->is_open_archive()) {
 255       guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
 256                 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
 257                 p2i(p), p2i(obj));
 258     } else {
 259       assert(_hr->is_closed_archive(), "should be archive region");
 260       guarantee(obj == NULL || G1ArchiveAllocator::is_closed_archive_object(obj),
 261                 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
 262                 p2i(p), p2i(obj));
 263     }
 264   }
 265 };
 266 
 267 class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
 268   HeapRegion* _hr;
 269   bool _verbose;
 270 public:
 271   VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
 272     : _hr(hr), _verbose(verbose) { }
 273   // Verify that all object pointers are to archive regions.
 274   void do_object(oop o) {
 275     if (_verbose) {
 276       o->print();
 277     }
 278 
 279     VerifyArchiveOopClosure checkOop(_hr, _verbose);
 280     assert(o != NULL, "Should not be here for NULL oops");
 281     o->oop_iterate_no_header(&checkOop);
 282   }
 283 };
 284 
 285 // Should be only used at CDS dump time
 286 class VerifyArchivePointerRegionClosure: public HeapRegionClosure {
 287 private:
 288   G1CollectedHeap* _g1h;
 289 public:
 290   VerifyArchivePointerRegionClosure(G1CollectedHeap* g1h) { }
 291   virtual bool doHeapRegion(HeapRegion* r) {
 292    if (r->is_archive()) {
 293       VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
 294       r->object_iterate(&verify_oop_pointers);
 295     }
 296     return false;
 297   }
 298 };
 299 




  43 class VerifyRootsClosure: public OopClosure {
  44 private:
  45   G1CollectedHeap* _g1h;
  46   VerifyOption     _vo;
  47   bool             _failures;
  48 public:
  49   // _vo == UsePrevMarking -> use "prev" marking information,
  50   // _vo == UseNextMarking -> use "next" marking information,
  51   // _vo == UseMarkWord    -> use mark word from object header.
  52   VerifyRootsClosure(VerifyOption vo) :
  53     _g1h(G1CollectedHeap::heap()),
  54     _vo(vo),
  55     _failures(false) { }
  56 
  57   bool failures() { return _failures; }
  58 
  59   template <class T> void do_oop_nv(T* p) {
  60     T heap_oop = oopDesc::load_heap_oop(p);
  61     if (!oopDesc::is_null(heap_oop)) {
  62       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  63       if (_g1h->is_obj_dead_cond(obj, _vo)) {

  64         Log(gc, verify) log;
  65         log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
  66         if (_vo == VerifyOption_G1UseMarkWord) {
  67           log.error("  Mark word: " PTR_FORMAT, p2i(obj->mark()));
  68         }
  69         ResourceMark rm;
  70         LogStream ls(log.error());
  71         obj->print_on(&ls);
  72         _failures = true;
  73       }
  74     }
  75   }
  76 
  77   void do_oop(oop* p)       { do_oop_nv(p); }
  78   void do_oop(narrowOop* p) { do_oop_nv(p); }
  79 };
  80 
  81 class G1VerifyCodeRootOopClosure: public OopClosure {
  82   G1CollectedHeap* _g1h;
  83   OopClosure* _root_cl;


 218       // above: if the object is dead (according to the mark
 219       // word), it may not be marked, or may have been marked
 220       // but has since became dead, or may have been allocated
 221       // since the last marking.
 222       if (_vo == VerifyOption_G1UseMarkWord) {
 223         guarantee(!_g1h->is_obj_dead(o), "mark word and concurrent mark mismatch");
 224       }
 225 
 226       o->oop_iterate_no_header(&isLive);
 227       if (!_hr->obj_allocated_since_prev_marking(o)) {
 228         size_t obj_size = o->size();    // Make sure we don't overflow
 229         _live_bytes += (obj_size * HeapWordSize);
 230       }
 231     }
 232   }
 233   size_t live_bytes() { return _live_bytes; }
 234 };
 235 
 236 class VerifyArchiveOopClosure: public OopClosure {
 237   HeapRegion* _hr;

 238 public:
 239   VerifyArchiveOopClosure(HeapRegion *hr)
 240     : _hr(hr) { }
 241   void do_oop(narrowOop *p) { do_oop_work(p); }
 242   void do_oop(      oop *p) { do_oop_work(p); }
 243 
 244   template <class T> void do_oop_work(T *p) {
 245     oop obj = oopDesc::load_decode_heap_oop(p);





 246 
 247     if (_hr->is_open_archive()) {
 248       guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
 249                 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
 250                 p2i(p), p2i(obj));
 251     } else {
 252       assert(_hr->is_closed_archive(), "should be archive region");
 253       guarantee(obj == NULL || G1ArchiveAllocator::is_closed_archive_object(obj),
 254                 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
 255                 p2i(p), p2i(obj));
 256     }
 257   }
 258 };
 259 
 260 class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
 261   HeapRegion* _hr;

 262 public:
 263   VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
 264     : _hr(hr) { }
 265   // Verify that all object pointers are to archive regions.
 266   void do_object(oop o) {
 267     VerifyArchiveOopClosure checkOop(_hr);




 268     assert(o != NULL, "Should not be here for NULL oops");
 269     o->oop_iterate_no_header(&checkOop);
 270   }
 271 };
 272 
 273 // Should be only used at CDS dump time
 274 class VerifyArchivePointerRegionClosure: public HeapRegionClosure {
 275 private:
 276   G1CollectedHeap* _g1h;
 277 public:
 278   VerifyArchivePointerRegionClosure(G1CollectedHeap* g1h) { }
 279   virtual bool doHeapRegion(HeapRegion* r) {
 280    if (r->is_archive()) {
 281       VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
 282       r->object_iterate(&verify_oop_pointers);
 283     }
 284     return false;
 285   }
 286 };
 287 


< prev index next >