217 // Note we can't verify the contra-positive of the 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 public: 238 VerifyArchiveOopClosure(HeapRegion *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 guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj), 245 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT, 246 p2i(p), p2i(obj)); 247 } 248 }; 249 250 class VerifyArchiveRegionClosure: public ObjectClosure { 251 public: 252 VerifyArchiveRegionClosure(HeapRegion *hr) { } 253 // Verify that all object pointers are to archive regions. 254 void do_object(oop o) { 255 VerifyArchiveOopClosure checkOop(NULL); 256 assert(o != NULL, "Should not be here for NULL oops"); 257 o->oop_iterate_no_header(&checkOop); 258 } 259 }; 260 261 class VerifyRegionClosure: public HeapRegionClosure { 262 private: 263 bool _par; 264 VerifyOption _vo; 265 bool _failures; 266 public: 267 // _vo == UsePrevMarking -> use "prev" marking information, 268 // _vo == UseNextMarking -> use "next" marking information, 269 // _vo == UseMarkWord -> use mark word from object header. 270 VerifyRegionClosure(bool par, VerifyOption vo) 271 : _par(par), 272 _vo(vo), 273 _failures(false) {} 274 275 bool failures() { 276 return _failures; 277 } 278 279 bool doHeapRegion(HeapRegion* r) { 280 // For archive regions, verify there are no heap pointers to 281 // non-pinned regions. For all others, verify liveness info. 282 if (r->is_archive()) { 283 VerifyArchiveRegionClosure verify_oop_pointers(r); 284 r->object_iterate(&verify_oop_pointers); 285 return true; 286 } 287 if (!r->is_continues_humongous()) { 288 bool failures = false; 289 r->verify(_vo, &failures); 290 if (failures) { 291 _failures = true; 292 } else if (!r->is_starts_humongous()) { 293 VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo); 294 r->object_iterate(¬_dead_yet_cl); 295 if (_vo != VerifyOption_G1UseNextMarking) { 296 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) { 297 log_error(gc, verify)("[" PTR_FORMAT "," PTR_FORMAT "] max_live_bytes " SIZE_FORMAT " < calculated " SIZE_FORMAT, 298 p2i(r->bottom()), p2i(r->end()), r->max_live_bytes(), not_dead_yet_cl.live_bytes()); 299 _failures = true; 300 } 301 } else { 302 // When vo == UseNextMarking we cannot currently do a sanity 303 // check on the live bytes as the calculation has not been 304 // finalized yet. 305 } 306 } 307 } | 217 // Note we can't verify the contra-positive of the 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 288 void G1HeapVerifier::verify_archive_regions() { 289 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 290 VerifyArchivePointerRegionClosure cl(NULL); 291 g1h->heap_region_iterate(&cl); 292 } 293 294 class VerifyRegionClosure: public HeapRegionClosure { 295 private: 296 bool _par; 297 VerifyOption _vo; 298 bool _failures; 299 public: 300 // _vo == UsePrevMarking -> use "prev" marking information, 301 // _vo == UseNextMarking -> use "next" marking information, 302 // _vo == UseMarkWord -> use mark word from object header. 303 VerifyRegionClosure(bool par, VerifyOption vo) 304 : _par(par), 305 _vo(vo), 306 _failures(false) {} 307 308 bool failures() { 309 return _failures; 310 } 311 312 bool doHeapRegion(HeapRegion* r) { 313 // For archive regions, verify there are no heap pointers to 314 // non-pinned regions. For all others, verify liveness info. 315 if (r->is_closed_archive()) { 316 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false); 317 r->object_iterate(&verify_oop_pointers); 318 return true; 319 } else if (r->is_open_archive()) { 320 VerifyObjsInRegionClosure verify_open_archive_oop(r, _vo); 321 r->object_iterate(&verify_open_archive_oop); 322 return true; 323 } else if (!r->is_continues_humongous()) { 324 bool failures = false; 325 r->verify(_vo, &failures); 326 if (failures) { 327 _failures = true; 328 } else if (!r->is_starts_humongous()) { 329 VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo); 330 r->object_iterate(¬_dead_yet_cl); 331 if (_vo != VerifyOption_G1UseNextMarking) { 332 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) { 333 log_error(gc, verify)("[" PTR_FORMAT "," PTR_FORMAT "] max_live_bytes " SIZE_FORMAT " < calculated " SIZE_FORMAT, 334 p2i(r->bottom()), p2i(r->end()), r->max_live_bytes(), not_dead_yet_cl.live_bytes()); 335 _failures = true; 336 } 337 } else { 338 // When vo == UseNextMarking we cannot currently do a sanity 339 // check on the live bytes as the calculation has not been 340 // finalized yet. 341 } 342 } 343 } |