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/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 "memory/iterator.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "runtime/atomic.hpp"
43 #include "runtime/orderAccess.inline.hpp"
44
45 int HeapRegion::LogOfHRGrainBytes = 0;
46 int HeapRegion::LogOfHRGrainWords = 0;
47 size_t HeapRegion::GrainBytes = 0;
48 size_t HeapRegion::GrainWords = 0;
49 size_t HeapRegion::CardsPerRegion = 0;
50
51 size_t HeapRegion::max_region_size() {
52 return HeapRegionBounds::max_size();
53 }
54
55 size_t HeapRegion::min_region_size_in_words() {
56 return HeapRegionBounds::min_size() >> LogHeapWordSize;
57 }
58
510
511 template <class T>
512 void verify_liveness(T* p) {
513 T heap_oop = oopDesc::load_heap_oop(p);
514 Log(gc, verify) log;
515 if (!oopDesc::is_null(heap_oop)) {
516 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
517 bool failed = false;
518 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
519 MutexLockerEx x(ParGCRareEvent_lock,
520 Mutex::_no_safepoint_check_flag);
521
522 if (!_failures) {
523 log.error("----------");
524 }
525 ResourceMark rm;
526 if (!_g1h->is_in_closed_subset(obj)) {
527 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
528 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
529 p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
530 print_object(log.error_stream(), _containing_obj);
531 log.error("points to obj " PTR_FORMAT " not in the heap", p2i(obj));
532 } else {
533 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
534 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
535 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
536 p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
537 print_object(log.error_stream(), _containing_obj);
538 log.error("points to dead obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
539 p2i(obj), p2i(to->bottom()), p2i(to->end()));
540 print_object(log.error_stream(), obj);
541 }
542 log.error("----------");
543 _failures = true;
544 failed = true;
545 _n_failures++;
546 }
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),
576 jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
577 jbyte cv_field = *_bs->byte_for_const(p);
578 const jbyte dirty = CardTableModRefBS::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("----------");
591 }
592 log.error("Missing rem set entry:");
593 log.error("Field " PTR_FORMAT " of obj " PTR_FORMAT ", in region " HR_FORMAT,
594 p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from));
595 ResourceMark rm;
596 _containing_obj->print_on(log.error_stream());
597 log.error("points to obj " PTR_FORMAT " in region " HR_FORMAT, p2i(obj), HR_FORMAT_PARAMS(to));
598 if (obj->is_oop()) {
599 obj->print_on(log.error_stream());
600 }
601 log.error("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
602 log.error("----------");
603 _failures = true;
604 _n_failures++;
605 }
606 }
607 }
608 }
609 };
610
611 // Closure that applies the given two closures in sequence.
612 class G1Mux2Closure : public OopClosure {
613 OopClosure* _c1;
614 OopClosure* _c2;
615 public:
616 G1Mux2Closure(OopClosure *c1, OopClosure *c2) { _c1 = c1; _c2 = c2; }
617 template <class T> inline void do_oop_work(T* p) {
618 // Apply first closure; then apply the second.
619 _c1->do_oop(p);
|
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/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
46 int HeapRegion::LogOfHRGrainBytes = 0;
47 int HeapRegion::LogOfHRGrainWords = 0;
48 size_t HeapRegion::GrainBytes = 0;
49 size_t HeapRegion::GrainWords = 0;
50 size_t HeapRegion::CardsPerRegion = 0;
51
52 size_t HeapRegion::max_region_size() {
53 return HeapRegionBounds::max_size();
54 }
55
56 size_t HeapRegion::min_region_size_in_words() {
57 return HeapRegionBounds::min_size() >> LogHeapWordSize;
58 }
59
511
512 template <class T>
513 void verify_liveness(T* p) {
514 T heap_oop = oopDesc::load_heap_oop(p);
515 Log(gc, verify) log;
516 if (!oopDesc::is_null(heap_oop)) {
517 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
518 bool failed = false;
519 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
520 MutexLockerEx x(ParGCRareEvent_lock,
521 Mutex::_no_safepoint_check_flag);
522
523 if (!_failures) {
524 log.error("----------");
525 }
526 ResourceMark rm;
527 if (!_g1h->is_in_closed_subset(obj)) {
528 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
529 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
530 p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
531 // Unconditional write?
532 LogStream ls(log.error());
533 print_object(&ls, _containing_obj);
534 log.error("points to obj " PTR_FORMAT " not in the heap", p2i(obj));
535 } else {
536 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
537 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
538 log.error("Field " PTR_FORMAT " of live obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
539 p2i(p), p2i(_containing_obj), p2i(from->bottom()), p2i(from->end()));
540 // Unconditional write?
541 LogStream ls(log.error());
542 print_object(&ls, _containing_obj);
543 log.error("points to dead obj " PTR_FORMAT " in region [" PTR_FORMAT ", " PTR_FORMAT ")",
544 p2i(obj), p2i(to->bottom()), p2i(to->end()));
545 print_object(&ls, obj);
546 }
547 log.error("----------");
548 _failures = true;
549 failed = true;
550 _n_failures++;
551 }
552 }
553 }
554 };
555
556 class VerifyRemSetClosure : public G1VerificationClosure {
557 public:
558 VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {}
559 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
560 virtual void do_oop(oop* p) { do_oop_work(p); }
561
562 template <class T>
563 void do_oop_work(T* p) {
564 assert(_containing_obj != NULL, "Precondition");
565 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
581 jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
582 jbyte cv_field = *_bs->byte_for_const(p);
583 const jbyte dirty = CardTableModRefBS::dirty_card_val();
584
585 bool is_bad = !(from->is_young()
586 || to->rem_set()->contains_reference(p)
587 || (_containing_obj->is_objArray() ?
588 cv_field == dirty :
589 cv_obj == dirty || cv_field == dirty));
590 if (is_bad) {
591 MutexLockerEx x(ParGCRareEvent_lock,
592 Mutex::_no_safepoint_check_flag);
593
594 if (!_failures) {
595 log.error("----------");
596 }
597 log.error("Missing rem set entry:");
598 log.error("Field " PTR_FORMAT " of obj " PTR_FORMAT ", in region " HR_FORMAT,
599 p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from));
600 ResourceMark rm;
601 // Unconditional write?
602 LogStream ls(log.error());
603 _containing_obj->print_on(&ls);
604 log.error("points to obj " PTR_FORMAT " in region " HR_FORMAT, p2i(obj), HR_FORMAT_PARAMS(to));
605 if (obj->is_oop()) {
606 obj->print_on(&ls);
607 }
608 log.error("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
609 log.error("----------");
610 _failures = true;
611 _n_failures++;
612 }
613 }
614 }
615 }
616 };
617
618 // Closure that applies the given two closures in sequence.
619 class G1Mux2Closure : public OopClosure {
620 OopClosure* _c1;
621 OopClosure* _c2;
622 public:
623 G1Mux2Closure(OopClosure *c1, OopClosure *c2) { _c1 = c1; _c2 = c2; }
624 template <class T> inline void do_oop_work(T* p) {
625 // Apply first closure; then apply the second.
626 _c1->do_oop(p);
|