提交 5abb9f95 编写于 作者: P poonam

8145442: Add the facility to verify remembered sets for G1

Summary: Implement remembered sets verification for G1 with option VerifyRememberedSets
Reviewed-by: jmasa, mgerdin
上级 1b31c94c
...@@ -3839,6 +3839,16 @@ G1CollectedHeap::cleanup_surviving_young_words() { ...@@ -3839,6 +3839,16 @@ G1CollectedHeap::cleanup_surviving_young_words() {
_surviving_young_words = NULL; _surviving_young_words = NULL;
} }
class VerifyRegionRemSetClosure : public HeapRegionClosure {
public:
bool doHeapRegion(HeapRegion* hr) {
if (!hr->continuesHumongous()) {
hr->verify_rem_set();
}
return false;
}
};
#ifdef ASSERT #ifdef ASSERT
class VerifyCSetClosure: public HeapRegionClosure { class VerifyCSetClosure: public HeapRegionClosure {
public: public:
...@@ -4015,6 +4025,14 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) { ...@@ -4015,6 +4025,14 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) {
increment_total_collections(false /* full gc */); increment_total_collections(false /* full gc */);
increment_gc_time_stamp(); increment_gc_time_stamp();
if (VerifyRememberedSets) {
if (!VerifySilently) {
gclog_or_tty->print_cr("[Verifying RemSets before GC]");
}
VerifyRegionRemSetClosure v_cl;
heap_region_iterate(&v_cl);
}
verify_before_gc(); verify_before_gc();
check_bitmaps("GC Start"); check_bitmaps("GC Start");
...@@ -4246,6 +4264,14 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) { ...@@ -4246,6 +4264,14 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) {
// scanning cards (see CR 7039627). // scanning cards (see CR 7039627).
increment_gc_time_stamp(); increment_gc_time_stamp();
if (VerifyRememberedSets) {
if (!VerifySilently) {
gclog_or_tty->print_cr("[Verifying RemSets after GC]");
}
VerifyRegionRemSetClosure v_cl;
heap_region_iterate(&v_cl);
}
verify_after_gc(); verify_after_gc();
check_bitmaps("GC End"); check_bitmaps("GC End");
......
...@@ -639,8 +639,8 @@ void HeapRegion::print_on(outputStream* st) const { ...@@ -639,8 +639,8 @@ void HeapRegion::print_on(outputStream* st) const {
G1OffsetTableContigSpace::print_on(st); G1OffsetTableContigSpace::print_on(st);
} }
class VerifyLiveClosure: public OopClosure { class G1VerificationClosure : public OopClosure {
private: protected:
G1CollectedHeap* _g1h; G1CollectedHeap* _g1h;
CardTableModRefBS* _bs; CardTableModRefBS* _bs;
oop _containing_obj; oop _containing_obj;
...@@ -651,7 +651,7 @@ public: ...@@ -651,7 +651,7 @@ public:
// _vo == UsePrevMarking -> use "prev" marking information, // _vo == UsePrevMarking -> use "prev" marking information,
// _vo == UseNextMarking -> use "next" marking information, // _vo == UseNextMarking -> use "next" marking information,
// _vo == UseMarkWord -> use mark word from object header. // _vo == UseMarkWord -> use mark word from object header.
VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(G1CollectedHeap* g1h, VerifyOption vo) :
_g1h(g1h), _bs(NULL), _containing_obj(NULL), _g1h(g1h), _bs(NULL), _containing_obj(NULL),
_failures(false), _n_failures(0), _vo(vo) _failures(false), _n_failures(0), _vo(vo)
{ {
...@@ -667,9 +667,6 @@ public: ...@@ -667,9 +667,6 @@ public:
bool failures() { return _failures; } bool failures() { return _failures; }
int n_failures() { return _n_failures; } int n_failures() { return _n_failures; }
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
virtual void do_oop( oop* p) { do_oop_work(p); }
void print_object(outputStream* out, oop obj) { void print_object(outputStream* out, oop obj) {
#ifdef PRODUCT #ifdef PRODUCT
Klass* k = obj->klass(); Klass* k = obj->klass();
...@@ -679,19 +676,31 @@ public: ...@@ -679,19 +676,31 @@ public:
obj->print_on(out); obj->print_on(out);
#endif // PRODUCT #endif // PRODUCT
} }
};
class VerifyLiveClosure : public G1VerificationClosure {
public:
VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {}
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
virtual void do_oop(oop* p) { do_oop_work(p); }
template <class T> template <class T>
void do_oop_work(T* p) { void do_oop_work(T* p) {
assert(_containing_obj != NULL, "Precondition"); assert(_containing_obj != NULL, "Precondition");
assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
"Precondition"); "Precondition");
verify_liveness(p);
}
template <class T>
void verify_liveness(T* p) {
T heap_oop = oopDesc::load_heap_oop(p); T heap_oop = oopDesc::load_heap_oop(p);
if (!oopDesc::is_null(heap_oop)) { if (!oopDesc::is_null(heap_oop)) {
oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
bool failed = false; bool failed = false;
if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) { if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
MutexLockerEx x(ParGCRareEvent_lock, MutexLockerEx x(ParGCRareEvent_lock,
Mutex::_no_safepoint_check_flag); Mutex::_no_safepoint_check_flag);
if (!_failures) { if (!_failures) {
gclog_or_tty->cr(); gclog_or_tty->cr();
...@@ -727,50 +736,71 @@ public: ...@@ -727,50 +736,71 @@ public:
failed = true; failed = true;
_n_failures++; _n_failures++;
} }
}
}
};
if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) { class VerifyRemSetClosure : public G1VerificationClosure {
HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); public:
HeapRegion* to = _g1h->heap_region_containing(obj); VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {}
if (from != NULL && to != NULL && virtual void do_oop(narrowOop* p) { do_oop_work(p); }
from != to && virtual void do_oop(oop* p) { do_oop_work(p); }
!to->isHumongous()) {
jbyte cv_obj = *_bs->byte_for_const(_containing_obj); template <class T>
jbyte cv_field = *_bs->byte_for_const(p); void do_oop_work(T* p) {
const jbyte dirty = CardTableModRefBS::dirty_card_val(); assert(_containing_obj != NULL, "Precondition");
assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
bool is_bad = !(from->is_young() "Precondition");
|| to->rem_set()->contains_reference(p) verify_remembered_set(p);
|| !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed }
(_containing_obj->is_objArray() ?
cv_field == dirty template <class T>
: cv_obj == dirty || cv_field == dirty)); void verify_remembered_set(T* p) {
if (is_bad) { T heap_oop = oopDesc::load_heap_oop(p);
MutexLockerEx x(ParGCRareEvent_lock, if (!oopDesc::is_null(heap_oop)) {
Mutex::_no_safepoint_check_flag); oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
bool failed = false;
if (!_failures) { HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
gclog_or_tty->cr(); HeapRegion* to = _g1h->heap_region_containing(obj);
gclog_or_tty->print_cr("----------"); if (from != NULL && to != NULL &&
} from != to &&
gclog_or_tty->print_cr("Missing rem set entry:"); !to->isHumongous()) {
gclog_or_tty->print_cr("Field "PTR_FORMAT" " jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
"of obj "PTR_FORMAT", " jbyte cv_field = *_bs->byte_for_const(p);
"in region "HR_FORMAT, const jbyte dirty = CardTableModRefBS::dirty_card_val();
p, (void*) _containing_obj,
HR_FORMAT_PARAMS(from)); bool is_bad = !(from->is_young()
_containing_obj->print_on(gclog_or_tty); || to->rem_set()->contains_reference(p)
gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
"in region "HR_FORMAT, (_containing_obj->is_objArray() ?
(void*) obj, cv_field == dirty
HR_FORMAT_PARAMS(to)); : cv_obj == dirty || cv_field == dirty));
obj->print_on(gclog_or_tty); if (is_bad) {
gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", MutexLockerEx x(ParGCRareEvent_lock,
cv_obj, cv_field); Mutex::_no_safepoint_check_flag);
if (!_failures) {
gclog_or_tty->cr();
gclog_or_tty->print_cr("----------"); gclog_or_tty->print_cr("----------");
gclog_or_tty->flush();
_failures = true;
if (!failed) _n_failures++;
} }
gclog_or_tty->print_cr("Missing rem set entry:");
gclog_or_tty->print_cr("Field "PTR_FORMAT" "
"of obj "PTR_FORMAT", "
"in region "HR_FORMAT,
p, (void*) _containing_obj,
HR_FORMAT_PARAMS(from));
_containing_obj->print_on(gclog_or_tty);
gclog_or_tty->print_cr("points to obj "PTR_FORMAT" "
"in region "HR_FORMAT,
(void*) obj,
HR_FORMAT_PARAMS(to));
obj->print_on(gclog_or_tty);
gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.",
cv_obj, cv_field);
gclog_or_tty->print_cr("----------");
gclog_or_tty->flush();
_failures = true;
if (!failed) _n_failures++;
} }
} }
} }
...@@ -787,6 +817,7 @@ void HeapRegion::verify(VerifyOption vo, ...@@ -787,6 +817,7 @@ void HeapRegion::verify(VerifyOption vo,
HeapWord* p = bottom(); HeapWord* p = bottom();
HeapWord* prev_p = NULL; HeapWord* prev_p = NULL;
VerifyLiveClosure vl_cl(g1, vo); VerifyLiveClosure vl_cl(g1, vo);
VerifyRemSetClosure vr_cl(g1, vo);
bool is_humongous = isHumongous(); bool is_humongous = isHumongous();
bool do_bot_verify = !is_young(); bool do_bot_verify = !is_young();
size_t object_num = 0; size_t object_num = 0;
...@@ -832,7 +863,23 @@ void HeapRegion::verify(VerifyOption vo, ...@@ -832,7 +863,23 @@ void HeapRegion::verify(VerifyOption vo,
return; return;
} else { } else {
vl_cl.set_containing_obj(obj); vl_cl.set_containing_obj(obj);
obj->oop_iterate_no_header(&vl_cl); if (!g1->full_collection() || G1VerifyRSetsDuringFullGC) {
// verify liveness and rem_set
vr_cl.set_containing_obj(obj);
G1Mux2Closure mux(&vl_cl, &vr_cl);
obj->oop_iterate_no_header(&mux);
if (vr_cl.failures()) {
*failures = true;
}
if (G1MaxVerifyFailures >= 0 &&
vr_cl.n_failures() >= G1MaxVerifyFailures) {
return;
}
} else {
// verify only liveness
obj->oop_iterate_no_header(&vl_cl);
}
if (vl_cl.failures()) { if (vl_cl.failures()) {
*failures = true; *failures = true;
} }
...@@ -842,7 +889,7 @@ void HeapRegion::verify(VerifyOption vo, ...@@ -842,7 +889,7 @@ void HeapRegion::verify(VerifyOption vo,
} }
} }
} else { } else {
gclog_or_tty->print_cr(PTR_FORMAT" no an oop", (void *)obj); gclog_or_tty->print_cr(PTR_FORMAT" not an oop", (void *)obj);
*failures = true; *failures = true;
return; return;
} }
...@@ -930,6 +977,46 @@ void HeapRegion::verify() const { ...@@ -930,6 +977,46 @@ void HeapRegion::verify() const {
verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy); verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
} }
void HeapRegion::verify_rem_set(VerifyOption vo, bool* failures) const {
G1CollectedHeap* g1 = G1CollectedHeap::heap();
*failures = false;
HeapWord* p = bottom();
HeapWord* prev_p = NULL;
VerifyRemSetClosure vr_cl(g1, vo);
while (p < top()) {
oop obj = oop(p);
size_t obj_size = block_size(p);
if (!g1->is_obj_dead_cond(obj, this, vo)) {
if (obj->is_oop()) {
vr_cl.set_containing_obj(obj);
obj->oop_iterate_no_header(&vr_cl);
if (vr_cl.failures()) {
*failures = true;
}
if (G1MaxVerifyFailures >= 0 &&
vr_cl.n_failures() >= G1MaxVerifyFailures) {
return;
}
} else {
gclog_or_tty->print_cr(PTR_FORMAT " not an oop", p2i(obj));
*failures = true;
return;
}
}
prev_p = p;
p += obj_size;
}
}
void HeapRegion::verify_rem_set() const {
bool failures = false;
verify_rem_set(VerifyOption_G1UsePrevMarking, &failures);
guarantee(!failures, "HeapRegion RemSet verification failed");
}
// G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
// away eventually. // away eventually.
......
...@@ -779,6 +779,9 @@ class HeapRegion: public G1OffsetTableContigSpace { ...@@ -779,6 +779,9 @@ class HeapRegion: public G1OffsetTableContigSpace {
// Override; it uses the "prev" marking information // Override; it uses the "prev" marking information
virtual void verify() const; virtual void verify() const;
void verify_rem_set(VerifyOption vo, bool *failures) const;
void verify_rem_set() const;
}; };
// HeapRegionClosure is used for iterating over regions. // HeapRegionClosure is used for iterating over regions.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册