< prev index next >

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

Print this page




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/concurrentMarkThread.hpp"
  27 #include "gc/g1/g1Allocator.inline.hpp"
  28 #include "gc/g1/g1CollectedHeap.hpp"
  29 #include "gc/g1/g1CollectedHeap.inline.hpp"
  30 #include "gc/g1/g1HeapVerifier.hpp"
  31 #include "gc/g1/g1Policy.hpp"
  32 #include "gc/g1/g1RemSet.hpp"
  33 #include "gc/g1/g1RootProcessor.hpp"
  34 #include "gc/g1/heapRegion.hpp"
  35 #include "gc/g1/heapRegion.inline.hpp"
  36 #include "gc/g1/heapRegionRemSet.hpp"
  37 #include "gc/g1/g1StringDedup.hpp"
  38 #include "logging/log.hpp"
  39 #include "logging/logStream.hpp"
  40 #include "memory/resourceArea.hpp"


  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 
  44 class VerifyRootsClosure: public OopClosure {
  45 private:
  46   G1CollectedHeap* _g1h;
  47   VerifyOption     _vo;
  48   bool             _failures;
  49 public:
  50   // _vo == UsePrevMarking -> use "prev" marking information,
  51   // _vo == UseNextMarking -> use "next" marking information,
  52   // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
  53   VerifyRootsClosure(VerifyOption vo) :
  54     _g1h(G1CollectedHeap::heap()),
  55     _vo(vo),
  56     _failures(false) { }
  57 
  58   bool failures() { return _failures; }
  59 
  60   template <class T> void do_oop_nv(T* p) {
  61     T heap_oop = oopDesc::load_heap_oop(p);
  62     if (!oopDesc::is_null(heap_oop)) {
  63       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  64       if (_g1h->is_obj_dead_cond(obj, _vo)) {
  65         Log(gc, verify) log;
  66         log.error("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
  67         ResourceMark rm;
  68         LogStream ls(log.error());
  69         obj->print_on(&ls);
  70         _failures = true;
  71       }
  72     }
  73   }
  74 
  75   void do_oop(oop* p)       { do_oop_nv(p); }
  76   void do_oop(narrowOop* p) { do_oop_nv(p); }
  77 };
  78 
  79 class G1VerifyCodeRootOopClosure: public OopClosure {
  80   G1CollectedHeap* _g1h;
  81   OopClosure* _root_cl;
  82   nmethod* _nm;
  83   VerifyOption _vo;
  84   bool _failures;
  85 
  86   template <class T> void do_oop_work(T* p) {
  87     // First verify that this root is live
  88     _root_cl->do_oop(p);
  89 
  90     if (!G1VerifyHeapRegionCodeRoots) {
  91       // We're not verifying the code roots attached to heap region.
  92       return;
  93     }
  94 
  95     // Don't check the code roots during marking verification in a full GC
  96     if (_vo == VerifyOption_G1UseFullMarking) {
  97       return;
  98     }
  99 
 100     // Now verify that the current nmethod (which contains p) is
 101     // in the code root list of the heap region containing the
 102     // object referenced by p.
 103 
 104     T heap_oop = oopDesc::load_heap_oop(p);
 105     if (!oopDesc::is_null(heap_oop)) {
 106       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 107 
 108       // Now fetch the region containing the object
 109       HeapRegion* hr = _g1h->heap_region_containing(obj);
 110       HeapRegionRemSet* hrrs = hr->rem_set();
 111       // Verify that the strong code root list for this region
 112       // contains the nmethod
 113       if (!hrrs->strong_code_roots_list_contains(_nm)) {
 114         log_error(gc, verify)("Code root location " PTR_FORMAT " "
 115                               "from nmethod " PTR_FORMAT " not in strong "
 116                               "code roots for region [" PTR_FORMAT "," PTR_FORMAT ")",
 117                               p2i(p), p2i(_nm), p2i(hr->bottom()), p2i(hr->end()));
 118         _failures = true;
 119       }
 120     }
 121   }
 122 
 123 public:
 124   G1VerifyCodeRootOopClosure(G1CollectedHeap* g1h, OopClosure* root_cl, VerifyOption vo):
 125     _g1h(g1h), _root_cl(root_cl), _vo(vo), _nm(NULL), _failures(false) {}
 126 


 169 
 170     _young_ref_counter_closure.reset_count();
 171     cld->oops_do(&_young_ref_counter_closure, false);
 172     if (_young_ref_counter_closure.count() > 0) {
 173       guarantee(cld->has_modified_oops(), "CLD " PTR_FORMAT ", has young %d refs but is not dirty.", p2i(cld), _young_ref_counter_closure.count());
 174     }
 175   }
 176 };
 177 
 178 class VerifyLivenessOopClosure: public OopClosure {
 179   G1CollectedHeap* _g1h;
 180   VerifyOption _vo;
 181 public:
 182   VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
 183     _g1h(g1h), _vo(vo)
 184   { }
 185   void do_oop(narrowOop *p) { do_oop_work(p); }
 186   void do_oop(      oop *p) { do_oop_work(p); }
 187 
 188   template <class T> void do_oop_work(T *p) {
 189     oop obj = oopDesc::load_decode_heap_oop(p);
 190     guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
 191               "Dead object referenced by a not dead object");
 192   }
 193 };
 194 
 195 class VerifyObjsInRegionClosure: public ObjectClosure {
 196 private:
 197   G1CollectedHeap* _g1h;
 198   size_t _live_bytes;
 199   HeapRegion *_hr;
 200   VerifyOption _vo;
 201 public:
 202   // _vo == UsePrevMarking -> use "prev" marking information,
 203   // _vo == UseNextMarking -> use "next" marking information,
 204   // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS.
 205   VerifyObjsInRegionClosure(HeapRegion *hr, VerifyOption vo)
 206     : _live_bytes(0), _hr(hr), _vo(vo) {
 207     _g1h = G1CollectedHeap::heap();
 208   }
 209   void do_object(oop o) {


 223 
 224       o->oop_iterate_no_header(&isLive);
 225       if (!_hr->obj_allocated_since_prev_marking(o)) {
 226         size_t obj_size = o->size();    // Make sure we don't overflow
 227         _live_bytes += (obj_size * HeapWordSize);
 228       }
 229     }
 230   }
 231   size_t live_bytes() { return _live_bytes; }
 232 };
 233 
 234 class VerifyArchiveOopClosure: public OopClosure {
 235   HeapRegion* _hr;
 236 public:
 237   VerifyArchiveOopClosure(HeapRegion *hr)
 238     : _hr(hr) { }
 239   void do_oop(narrowOop *p) { do_oop_work(p); }
 240   void do_oop(      oop *p) { do_oop_work(p); }
 241 
 242   template <class T> void do_oop_work(T *p) {
 243     oop obj = oopDesc::load_decode_heap_oop(p);
 244 
 245     if (_hr->is_open_archive()) {
 246       guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
 247                 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
 248                 p2i(p), p2i(obj));
 249     } else {
 250       assert(_hr->is_closed_archive(), "should be closed archive region");
 251       guarantee(obj == NULL || G1ArchiveAllocator::is_closed_archive_object(obj),
 252                 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
 253                 p2i(p), p2i(obj));
 254     }
 255   }
 256 };
 257 
 258 class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
 259   HeapRegion* _hr;
 260 public:
 261   VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
 262     : _hr(hr) { }
 263   // Verify that all object pointers are to archive regions.




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/concurrentMarkThread.hpp"
  27 #include "gc/g1/g1Allocator.inline.hpp"
  28 #include "gc/g1/g1CollectedHeap.hpp"
  29 #include "gc/g1/g1CollectedHeap.inline.hpp"
  30 #include "gc/g1/g1HeapVerifier.hpp"
  31 #include "gc/g1/g1Policy.hpp"
  32 #include "gc/g1/g1RemSet.hpp"
  33 #include "gc/g1/g1RootProcessor.hpp"
  34 #include "gc/g1/heapRegion.hpp"
  35 #include "gc/g1/heapRegion.inline.hpp"
  36 #include "gc/g1/heapRegionRemSet.hpp"
  37 #include "gc/g1/g1StringDedup.hpp"
  38 #include "logging/log.hpp"
  39 #include "logging/logStream.hpp"
  40 #include "memory/resourceArea.hpp"
  41 #include "oops/access.inline.hpp"
  42 #include "oops/compressedOops.inline.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "runtime/handles.inline.hpp"
  45 
  46 class VerifyRootsClosure: public OopClosure {
  47 private:
  48   G1CollectedHeap* _g1h;
  49   VerifyOption     _vo;
  50   bool             _failures;
  51 public:
  52   // _vo == UsePrevMarking -> use "prev" marking information,
  53   // _vo == UseNextMarking -> use "next" marking information,
  54   // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
  55   VerifyRootsClosure(VerifyOption vo) :
  56     _g1h(G1CollectedHeap::heap()),
  57     _vo(vo),
  58     _failures(false) { }
  59 
  60   bool failures() { return _failures; }
  61 
  62   template <class T> void do_oop_nv(T* p) {
  63     T heap_oop = RawAccess<>::oop_load(p);
  64     if (!CompressedOops::is_null(heap_oop)) {
  65       oop obj = CompressedOops::decode_not_null(heap_oop);
  66       if (_g1h->is_obj_dead_cond(obj, _vo)) {
  67         Log(gc, verify) log;
  68         log.error("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
  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;
  84   nmethod* _nm;
  85   VerifyOption _vo;
  86   bool _failures;
  87 
  88   template <class T> void do_oop_work(T* p) {
  89     // First verify that this root is live
  90     _root_cl->do_oop(p);
  91 
  92     if (!G1VerifyHeapRegionCodeRoots) {
  93       // We're not verifying the code roots attached to heap region.
  94       return;
  95     }
  96 
  97     // Don't check the code roots during marking verification in a full GC
  98     if (_vo == VerifyOption_G1UseFullMarking) {
  99       return;
 100     }
 101 
 102     // Now verify that the current nmethod (which contains p) is
 103     // in the code root list of the heap region containing the
 104     // object referenced by p.
 105 
 106     T heap_oop = RawAccess<>::oop_load(p);
 107     if (!CompressedOops::is_null(heap_oop)) {
 108       oop obj = CompressedOops::decode_not_null(heap_oop);
 109 
 110       // Now fetch the region containing the object
 111       HeapRegion* hr = _g1h->heap_region_containing(obj);
 112       HeapRegionRemSet* hrrs = hr->rem_set();
 113       // Verify that the strong code root list for this region
 114       // contains the nmethod
 115       if (!hrrs->strong_code_roots_list_contains(_nm)) {
 116         log_error(gc, verify)("Code root location " PTR_FORMAT " "
 117                               "from nmethod " PTR_FORMAT " not in strong "
 118                               "code roots for region [" PTR_FORMAT "," PTR_FORMAT ")",
 119                               p2i(p), p2i(_nm), p2i(hr->bottom()), p2i(hr->end()));
 120         _failures = true;
 121       }
 122     }
 123   }
 124 
 125 public:
 126   G1VerifyCodeRootOopClosure(G1CollectedHeap* g1h, OopClosure* root_cl, VerifyOption vo):
 127     _g1h(g1h), _root_cl(root_cl), _vo(vo), _nm(NULL), _failures(false) {}
 128 


 171 
 172     _young_ref_counter_closure.reset_count();
 173     cld->oops_do(&_young_ref_counter_closure, false);
 174     if (_young_ref_counter_closure.count() > 0) {
 175       guarantee(cld->has_modified_oops(), "CLD " PTR_FORMAT ", has young %d refs but is not dirty.", p2i(cld), _young_ref_counter_closure.count());
 176     }
 177   }
 178 };
 179 
 180 class VerifyLivenessOopClosure: public OopClosure {
 181   G1CollectedHeap* _g1h;
 182   VerifyOption _vo;
 183 public:
 184   VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
 185     _g1h(g1h), _vo(vo)
 186   { }
 187   void do_oop(narrowOop *p) { do_oop_work(p); }
 188   void do_oop(      oop *p) { do_oop_work(p); }
 189 
 190   template <class T> void do_oop_work(T *p) {
 191     oop obj = RawAccess<>::oop_load(p);
 192     guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
 193               "Dead object referenced by a not dead object");
 194   }
 195 };
 196 
 197 class VerifyObjsInRegionClosure: public ObjectClosure {
 198 private:
 199   G1CollectedHeap* _g1h;
 200   size_t _live_bytes;
 201   HeapRegion *_hr;
 202   VerifyOption _vo;
 203 public:
 204   // _vo == UsePrevMarking -> use "prev" marking information,
 205   // _vo == UseNextMarking -> use "next" marking information,
 206   // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS.
 207   VerifyObjsInRegionClosure(HeapRegion *hr, VerifyOption vo)
 208     : _live_bytes(0), _hr(hr), _vo(vo) {
 209     _g1h = G1CollectedHeap::heap();
 210   }
 211   void do_object(oop o) {


 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 = RawAccess<>::oop_load(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 closed 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.


< prev index next >