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/g1HeapRegionTraceType.hpp" 30 #include "gc/g1/g1OopClosures.inline.hpp" 31 #include "gc/g1/heapRegion.inline.hpp" 32 #include "gc/g1/heapRegionBounds.inline.hpp" 33 #include "gc/g1/heapRegionManager.inline.hpp" 34 #include "gc/g1/heapRegionRemSet.hpp" 35 #include "gc/g1/heapRegionTracer.hpp" 36 #include "gc/shared/genOopClosures.inline.hpp" 37 #include "gc/shared/space.inline.hpp" 38 #include "logging/log.hpp" 39 #include "logging/logStream.hpp" 40 #include "memory/iterator.hpp" 41 #include "memory/resourceArea.hpp" 42 #include "oops/oop.inline.hpp" 43 #include "runtime/atomic.hpp" 44 #include "runtime/orderAccess.inline.hpp" 45 #include "utilities/growableArray.hpp" 46 47 int HeapRegion::LogOfHRGrainBytes = 0; 48 int HeapRegion::LogOfHRGrainWords = 0; 49 size_t HeapRegion::GrainBytes = 0; 50 size_t HeapRegion::GrainWords = 0; 51 size_t HeapRegion::CardsPerRegion = 0; 52 53 size_t HeapRegion::max_region_size() { 54 return HeapRegionBounds::max_size(); 55 } 56 57 size_t HeapRegion::min_region_size_in_words() { 58 return HeapRegionBounds::min_size() >> LogHeapWordSize; 59 } 60 61 void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { 308 HeapRegionRemSet* hrrs = rem_set(); 309 hrrs->add_strong_code_root_locked(nm); 310 } 311 312 void HeapRegion::remove_strong_code_root(nmethod* nm) { 313 HeapRegionRemSet* hrrs = rem_set(); 314 hrrs->remove_strong_code_root(nm); 315 } 316 317 void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const { 318 HeapRegionRemSet* hrrs = rem_set(); 319 hrrs->strong_code_roots_do(blk); 320 } 321 322 class VerifyStrongCodeRootOopClosure: public OopClosure { 323 const HeapRegion* _hr; 324 bool _failures; 325 bool _has_oops_in_region; 326 327 template <class T> void do_oop_work(T* p) { 328 T heap_oop = oopDesc::load_heap_oop(p); 329 if (!oopDesc::is_null(heap_oop)) { 330 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); 331 332 // Note: not all the oops embedded in the nmethod are in the 333 // current region. We only look at those which are. 334 if (_hr->is_in(obj)) { 335 // Object is in the region. Check that its less than top 336 if (_hr->top() <= (HeapWord*)obj) { 337 // Object is above top 338 log_error(gc, verify)("Object " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ") is above top " PTR_FORMAT, 339 p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top())); 340 _failures = true; 341 return; 342 } 343 // Nmethod has at least one oop in the current region 344 _has_oops_in_region = true; 345 } 346 } 347 } 348 349 public: 350 VerifyStrongCodeRootOopClosure(const HeapRegion* hr): 489 #endif // PRODUCT 490 } 491 }; 492 493 class VerifyLiveClosure : public G1VerificationClosure { 494 public: 495 VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {} 496 virtual void do_oop(narrowOop* p) { do_oop_work(p); } 497 virtual void do_oop(oop* p) { do_oop_work(p); } 498 499 template <class T> 500 void do_oop_work(T* p) { 501 assert(_containing_obj != NULL, "Precondition"); 502 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), 503 "Precondition"); 504 verify_liveness(p); 505 } 506 507 template <class T> 508 void verify_liveness(T* p) { 509 T heap_oop = oopDesc::load_heap_oop(p); 510 Log(gc, verify) log; 511 if (!oopDesc::is_null(heap_oop)) { 512 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); 513 bool failed = false; 514 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) { 515 MutexLockerEx x(ParGCRareEvent_lock, 516 Mutex::_no_safepoint_check_flag); 517 518 if (!_failures) { 519 log.error("----------"); 520 } 521 ResourceMark rm; 522 if (!_g1h->is_in_closed_subset(obj)) { 523 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 524 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")", 525 p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end())); 526 LogStream ls(log.error()); 527 print_object(&ls, _containing_obj); 528 log.error("points to obj " PTR_FORMAT " not in the heap", p2i(obj)); 529 } else { 530 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 531 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); 532 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")", 545 } 546 } 547 }; 548 549 class VerifyRemSetClosure : public G1VerificationClosure { 550 public: 551 VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {} 552 virtual void do_oop(narrowOop* p) { do_oop_work(p); } 553 virtual void do_oop(oop* p) { do_oop_work(p); } 554 555 template <class T> 556 void do_oop_work(T* p) { 557 assert(_containing_obj != NULL, "Precondition"); 558 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), 559 "Precondition"); 560 verify_remembered_set(p); 561 } 562 563 template <class T> 564 void verify_remembered_set(T* p) { 565 T heap_oop = oopDesc::load_heap_oop(p); 566 Log(gc, verify) log; 567 if (!oopDesc::is_null(heap_oop)) { 568 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); 569 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 570 HeapRegion* to = _g1h->heap_region_containing(obj); 571 if (from != NULL && to != NULL && 572 from != to && 573 !to->is_pinned()) { 574 jbyte cv_obj = *_ct->byte_for_const(_containing_obj); 575 jbyte cv_field = *_ct->byte_for_const(p); 576 const jbyte dirty = G1CardTable::dirty_card_val(); 577 578 bool is_bad = !(from->is_young() 579 || to->rem_set()->contains_reference(p) 580 || (_containing_obj->is_objArray() ? 581 cv_field == dirty : 582 cv_obj == dirty || cv_field == dirty)); 583 if (is_bad) { 584 MutexLockerEx x(ParGCRareEvent_lock, 585 Mutex::_no_safepoint_check_flag); 586 587 if (!_failures) { 588 log.error("----------"); | 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/g1HeapRegionTraceType.hpp" 30 #include "gc/g1/g1OopClosures.inline.hpp" 31 #include "gc/g1/heapRegion.inline.hpp" 32 #include "gc/g1/heapRegionBounds.inline.hpp" 33 #include "gc/g1/heapRegionManager.inline.hpp" 34 #include "gc/g1/heapRegionRemSet.hpp" 35 #include "gc/g1/heapRegionTracer.hpp" 36 #include "gc/shared/genOopClosures.inline.hpp" 37 #include "gc/shared/space.inline.hpp" 38 #include "logging/log.hpp" 39 #include "logging/logStream.hpp" 40 #include "memory/iterator.hpp" 41 #include "memory/resourceArea.hpp" 42 #include "oops/access.inline.hpp" 43 #include "oops/compressedOops.inline.hpp" 44 #include "oops/oop.inline.hpp" 45 #include "runtime/atomic.hpp" 46 #include "runtime/orderAccess.inline.hpp" 47 #include "utilities/growableArray.hpp" 48 49 int HeapRegion::LogOfHRGrainBytes = 0; 50 int HeapRegion::LogOfHRGrainWords = 0; 51 size_t HeapRegion::GrainBytes = 0; 52 size_t HeapRegion::GrainWords = 0; 53 size_t HeapRegion::CardsPerRegion = 0; 54 55 size_t HeapRegion::max_region_size() { 56 return HeapRegionBounds::max_size(); 57 } 58 59 size_t HeapRegion::min_region_size_in_words() { 60 return HeapRegionBounds::min_size() >> LogHeapWordSize; 61 } 62 63 void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { 310 HeapRegionRemSet* hrrs = rem_set(); 311 hrrs->add_strong_code_root_locked(nm); 312 } 313 314 void HeapRegion::remove_strong_code_root(nmethod* nm) { 315 HeapRegionRemSet* hrrs = rem_set(); 316 hrrs->remove_strong_code_root(nm); 317 } 318 319 void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const { 320 HeapRegionRemSet* hrrs = rem_set(); 321 hrrs->strong_code_roots_do(blk); 322 } 323 324 class VerifyStrongCodeRootOopClosure: public OopClosure { 325 const HeapRegion* _hr; 326 bool _failures; 327 bool _has_oops_in_region; 328 329 template <class T> void do_oop_work(T* p) { 330 T heap_oop = RawAccess<>::oop_load(p); 331 if (!CompressedOops::is_null(heap_oop)) { 332 oop obj = CompressedOops::decode_not_null(heap_oop); 333 334 // Note: not all the oops embedded in the nmethod are in the 335 // current region. We only look at those which are. 336 if (_hr->is_in(obj)) { 337 // Object is in the region. Check that its less than top 338 if (_hr->top() <= (HeapWord*)obj) { 339 // Object is above top 340 log_error(gc, verify)("Object " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ") is above top " PTR_FORMAT, 341 p2i(obj), p2i(_hr->bottom()), p2i(_hr->end()), p2i(_hr->top())); 342 _failures = true; 343 return; 344 } 345 // Nmethod has at least one oop in the current region 346 _has_oops_in_region = true; 347 } 348 } 349 } 350 351 public: 352 VerifyStrongCodeRootOopClosure(const HeapRegion* hr): 491 #endif // PRODUCT 492 } 493 }; 494 495 class VerifyLiveClosure : public G1VerificationClosure { 496 public: 497 VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {} 498 virtual void do_oop(narrowOop* p) { do_oop_work(p); } 499 virtual void do_oop(oop* p) { do_oop_work(p); } 500 501 template <class T> 502 void do_oop_work(T* p) { 503 assert(_containing_obj != NULL, "Precondition"); 504 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), 505 "Precondition"); 506 verify_liveness(p); 507 } 508 509 template <class T> 510 void verify_liveness(T* p) { 511 T heap_oop = RawAccess<>::oop_load(p); 512 Log(gc, verify) log; 513 if (!CompressedOops::is_null(heap_oop)) { 514 oop obj = CompressedOops::decode_not_null(heap_oop); 515 bool failed = false; 516 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) { 517 MutexLockerEx x(ParGCRareEvent_lock, 518 Mutex::_no_safepoint_check_flag); 519 520 if (!_failures) { 521 log.error("----------"); 522 } 523 ResourceMark rm; 524 if (!_g1h->is_in_closed_subset(obj)) { 525 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 526 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")", 527 p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end())); 528 LogStream ls(log.error()); 529 print_object(&ls, _containing_obj); 530 log.error("points to obj " PTR_FORMAT " not in the heap", p2i(obj)); 531 } else { 532 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 533 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); 534 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")", 547 } 548 } 549 }; 550 551 class VerifyRemSetClosure : public G1VerificationClosure { 552 public: 553 VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {} 554 virtual void do_oop(narrowOop* p) { do_oop_work(p); } 555 virtual void do_oop(oop* p) { do_oop_work(p); } 556 557 template <class T> 558 void do_oop_work(T* p) { 559 assert(_containing_obj != NULL, "Precondition"); 560 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), 561 "Precondition"); 562 verify_remembered_set(p); 563 } 564 565 template <class T> 566 void verify_remembered_set(T* p) { 567 T heap_oop = RawAccess<>::oop_load(p); 568 Log(gc, verify) log; 569 if (!CompressedOops::is_null(heap_oop)) { 570 oop obj = CompressedOops::decode_not_null(heap_oop); 571 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 572 HeapRegion* to = _g1h->heap_region_containing(obj); 573 if (from != NULL && to != NULL && 574 from != to && 575 !to->is_pinned()) { 576 jbyte cv_obj = *_ct->byte_for_const(_containing_obj); 577 jbyte cv_field = *_ct->byte_for_const(p); 578 const jbyte dirty = G1CardTable::dirty_card_val(); 579 580 bool is_bad = !(from->is_young() 581 || to->rem_set()->contains_reference(p) 582 || (_containing_obj->is_objArray() ? 583 cv_field == dirty : 584 cv_obj == dirty || cv_field == dirty)); 585 if (is_bad) { 586 MutexLockerEx x(ParGCRareEvent_lock, 587 Mutex::_no_safepoint_check_flag); 588 589 if (!_failures) { 590 log.error("----------"); |