Mon, 01 Feb 2016 13:19:14 -0800
8145442: Add the facility to verify remembered sets for G1
Summary: Implement remembered sets verification for G1 with option VerifyRememberedSets
Reviewed-by: jmasa, mgerdin
1.1 --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Thu Jan 28 09:41:33 2016 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Mon Feb 01 13:19:14 2016 -0800 1.3 @@ -3839,6 +3839,16 @@ 1.4 _surviving_young_words = NULL; 1.5 } 1.6 1.7 +class VerifyRegionRemSetClosure : public HeapRegionClosure { 1.8 + public: 1.9 + bool doHeapRegion(HeapRegion* hr) { 1.10 + if (!hr->continuesHumongous()) { 1.11 + hr->verify_rem_set(); 1.12 + } 1.13 + return false; 1.14 + } 1.15 +}; 1.16 + 1.17 #ifdef ASSERT 1.18 class VerifyCSetClosure: public HeapRegionClosure { 1.19 public: 1.20 @@ -4015,6 +4025,14 @@ 1.21 increment_total_collections(false /* full gc */); 1.22 increment_gc_time_stamp(); 1.23 1.24 + if (VerifyRememberedSets) { 1.25 + if (!VerifySilently) { 1.26 + gclog_or_tty->print_cr("[Verifying RemSets before GC]"); 1.27 + } 1.28 + VerifyRegionRemSetClosure v_cl; 1.29 + heap_region_iterate(&v_cl); 1.30 + } 1.31 + 1.32 verify_before_gc(); 1.33 check_bitmaps("GC Start"); 1.34 1.35 @@ -4246,6 +4264,14 @@ 1.36 // scanning cards (see CR 7039627). 1.37 increment_gc_time_stamp(); 1.38 1.39 + if (VerifyRememberedSets) { 1.40 + if (!VerifySilently) { 1.41 + gclog_or_tty->print_cr("[Verifying RemSets after GC]"); 1.42 + } 1.43 + VerifyRegionRemSetClosure v_cl; 1.44 + heap_region_iterate(&v_cl); 1.45 + } 1.46 + 1.47 verify_after_gc(); 1.48 check_bitmaps("GC End"); 1.49
2.1 --- a/src/share/vm/gc_implementation/g1/heapRegion.cpp Thu Jan 28 09:41:33 2016 +0000 2.2 +++ b/src/share/vm/gc_implementation/g1/heapRegion.cpp Mon Feb 01 13:19:14 2016 -0800 2.3 @@ -639,8 +639,8 @@ 2.4 G1OffsetTableContigSpace::print_on(st); 2.5 } 2.6 2.7 -class VerifyLiveClosure: public OopClosure { 2.8 -private: 2.9 +class G1VerificationClosure : public OopClosure { 2.10 +protected: 2.11 G1CollectedHeap* _g1h; 2.12 CardTableModRefBS* _bs; 2.13 oop _containing_obj; 2.14 @@ -651,7 +651,7 @@ 2.15 // _vo == UsePrevMarking -> use "prev" marking information, 2.16 // _vo == UseNextMarking -> use "next" marking information, 2.17 // _vo == UseMarkWord -> use mark word from object header. 2.18 - VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : 2.19 + G1VerificationClosure(G1CollectedHeap* g1h, VerifyOption vo) : 2.20 _g1h(g1h), _bs(NULL), _containing_obj(NULL), 2.21 _failures(false), _n_failures(0), _vo(vo) 2.22 { 2.23 @@ -667,9 +667,6 @@ 2.24 bool failures() { return _failures; } 2.25 int n_failures() { return _n_failures; } 2.26 2.27 - virtual void do_oop(narrowOop* p) { do_oop_work(p); } 2.28 - virtual void do_oop( oop* p) { do_oop_work(p); } 2.29 - 2.30 void print_object(outputStream* out, oop obj) { 2.31 #ifdef PRODUCT 2.32 Klass* k = obj->klass(); 2.33 @@ -679,19 +676,31 @@ 2.34 obj->print_on(out); 2.35 #endif // PRODUCT 2.36 } 2.37 +}; 2.38 + 2.39 +class VerifyLiveClosure : public G1VerificationClosure { 2.40 +public: 2.41 + VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {} 2.42 + virtual void do_oop(narrowOop* p) { do_oop_work(p); } 2.43 + virtual void do_oop(oop* p) { do_oop_work(p); } 2.44 2.45 template <class T> 2.46 void do_oop_work(T* p) { 2.47 assert(_containing_obj != NULL, "Precondition"); 2.48 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), 2.49 - "Precondition"); 2.50 + "Precondition"); 2.51 + verify_liveness(p); 2.52 + } 2.53 + 2.54 + template <class T> 2.55 + void verify_liveness(T* p) { 2.56 T heap_oop = oopDesc::load_heap_oop(p); 2.57 if (!oopDesc::is_null(heap_oop)) { 2.58 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); 2.59 bool failed = false; 2.60 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) { 2.61 MutexLockerEx x(ParGCRareEvent_lock, 2.62 - Mutex::_no_safepoint_check_flag); 2.63 + Mutex::_no_safepoint_check_flag); 2.64 2.65 if (!_failures) { 2.66 gclog_or_tty->cr(); 2.67 @@ -727,50 +736,71 @@ 2.68 failed = true; 2.69 _n_failures++; 2.70 } 2.71 + } 2.72 + } 2.73 +}; 2.74 2.75 - if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) { 2.76 - HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 2.77 - HeapRegion* to = _g1h->heap_region_containing(obj); 2.78 - if (from != NULL && to != NULL && 2.79 - from != to && 2.80 - !to->isHumongous()) { 2.81 - jbyte cv_obj = *_bs->byte_for_const(_containing_obj); 2.82 - jbyte cv_field = *_bs->byte_for_const(p); 2.83 - const jbyte dirty = CardTableModRefBS::dirty_card_val(); 2.84 +class VerifyRemSetClosure : public G1VerificationClosure { 2.85 +public: 2.86 + VerifyRemSetClosure(G1CollectedHeap* g1h, VerifyOption vo) : G1VerificationClosure(g1h, vo) {} 2.87 + virtual void do_oop(narrowOop* p) { do_oop_work(p); } 2.88 + virtual void do_oop(oop* p) { do_oop_work(p); } 2.89 2.90 - bool is_bad = !(from->is_young() 2.91 - || to->rem_set()->contains_reference(p) 2.92 - || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed 2.93 - (_containing_obj->is_objArray() ? 2.94 - cv_field == dirty 2.95 - : cv_obj == dirty || cv_field == dirty)); 2.96 - if (is_bad) { 2.97 - MutexLockerEx x(ParGCRareEvent_lock, 2.98 - Mutex::_no_safepoint_check_flag); 2.99 + template <class T> 2.100 + void do_oop_work(T* p) { 2.101 + assert(_containing_obj != NULL, "Precondition"); 2.102 + assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), 2.103 + "Precondition"); 2.104 + verify_remembered_set(p); 2.105 + } 2.106 2.107 - if (!_failures) { 2.108 - gclog_or_tty->cr(); 2.109 - gclog_or_tty->print_cr("----------"); 2.110 - } 2.111 - gclog_or_tty->print_cr("Missing rem set entry:"); 2.112 - gclog_or_tty->print_cr("Field "PTR_FORMAT" " 2.113 - "of obj "PTR_FORMAT", " 2.114 - "in region "HR_FORMAT, 2.115 - p, (void*) _containing_obj, 2.116 - HR_FORMAT_PARAMS(from)); 2.117 - _containing_obj->print_on(gclog_or_tty); 2.118 - gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " 2.119 - "in region "HR_FORMAT, 2.120 - (void*) obj, 2.121 - HR_FORMAT_PARAMS(to)); 2.122 - obj->print_on(gclog_or_tty); 2.123 - gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", 2.124 - cv_obj, cv_field); 2.125 + template <class T> 2.126 + void verify_remembered_set(T* p) { 2.127 + T heap_oop = oopDesc::load_heap_oop(p); 2.128 + if (!oopDesc::is_null(heap_oop)) { 2.129 + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); 2.130 + bool failed = false; 2.131 + HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 2.132 + HeapRegion* to = _g1h->heap_region_containing(obj); 2.133 + if (from != NULL && to != NULL && 2.134 + from != to && 2.135 + !to->isHumongous()) { 2.136 + jbyte cv_obj = *_bs->byte_for_const(_containing_obj); 2.137 + jbyte cv_field = *_bs->byte_for_const(p); 2.138 + const jbyte dirty = CardTableModRefBS::dirty_card_val(); 2.139 + 2.140 + bool is_bad = !(from->is_young() 2.141 + || to->rem_set()->contains_reference(p) 2.142 + || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed 2.143 + (_containing_obj->is_objArray() ? 2.144 + cv_field == dirty 2.145 + : cv_obj == dirty || cv_field == dirty)); 2.146 + if (is_bad) { 2.147 + MutexLockerEx x(ParGCRareEvent_lock, 2.148 + Mutex::_no_safepoint_check_flag); 2.149 + 2.150 + if (!_failures) { 2.151 + gclog_or_tty->cr(); 2.152 gclog_or_tty->print_cr("----------"); 2.153 - gclog_or_tty->flush(); 2.154 - _failures = true; 2.155 - if (!failed) _n_failures++; 2.156 } 2.157 + gclog_or_tty->print_cr("Missing rem set entry:"); 2.158 + gclog_or_tty->print_cr("Field "PTR_FORMAT" " 2.159 + "of obj "PTR_FORMAT", " 2.160 + "in region "HR_FORMAT, 2.161 + p, (void*) _containing_obj, 2.162 + HR_FORMAT_PARAMS(from)); 2.163 + _containing_obj->print_on(gclog_or_tty); 2.164 + gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " 2.165 + "in region "HR_FORMAT, 2.166 + (void*) obj, 2.167 + HR_FORMAT_PARAMS(to)); 2.168 + obj->print_on(gclog_or_tty); 2.169 + gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", 2.170 + cv_obj, cv_field); 2.171 + gclog_or_tty->print_cr("----------"); 2.172 + gclog_or_tty->flush(); 2.173 + _failures = true; 2.174 + if (!failed) _n_failures++; 2.175 } 2.176 } 2.177 } 2.178 @@ -787,6 +817,7 @@ 2.179 HeapWord* p = bottom(); 2.180 HeapWord* prev_p = NULL; 2.181 VerifyLiveClosure vl_cl(g1, vo); 2.182 + VerifyRemSetClosure vr_cl(g1, vo); 2.183 bool is_humongous = isHumongous(); 2.184 bool do_bot_verify = !is_young(); 2.185 size_t object_num = 0; 2.186 @@ -832,7 +863,23 @@ 2.187 return; 2.188 } else { 2.189 vl_cl.set_containing_obj(obj); 2.190 - obj->oop_iterate_no_header(&vl_cl); 2.191 + if (!g1->full_collection() || G1VerifyRSetsDuringFullGC) { 2.192 + // verify liveness and rem_set 2.193 + vr_cl.set_containing_obj(obj); 2.194 + G1Mux2Closure mux(&vl_cl, &vr_cl); 2.195 + obj->oop_iterate_no_header(&mux); 2.196 + 2.197 + if (vr_cl.failures()) { 2.198 + *failures = true; 2.199 + } 2.200 + if (G1MaxVerifyFailures >= 0 && 2.201 + vr_cl.n_failures() >= G1MaxVerifyFailures) { 2.202 + return; 2.203 + } 2.204 + } else { 2.205 + // verify only liveness 2.206 + obj->oop_iterate_no_header(&vl_cl); 2.207 + } 2.208 if (vl_cl.failures()) { 2.209 *failures = true; 2.210 } 2.211 @@ -842,7 +889,7 @@ 2.212 } 2.213 } 2.214 } else { 2.215 - gclog_or_tty->print_cr(PTR_FORMAT" no an oop", (void *)obj); 2.216 + gclog_or_tty->print_cr(PTR_FORMAT" not an oop", (void *)obj); 2.217 *failures = true; 2.218 return; 2.219 } 2.220 @@ -930,6 +977,46 @@ 2.221 verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy); 2.222 } 2.223 2.224 +void HeapRegion::verify_rem_set(VerifyOption vo, bool* failures) const { 2.225 + G1CollectedHeap* g1 = G1CollectedHeap::heap(); 2.226 + *failures = false; 2.227 + HeapWord* p = bottom(); 2.228 + HeapWord* prev_p = NULL; 2.229 + VerifyRemSetClosure vr_cl(g1, vo); 2.230 + while (p < top()) { 2.231 + oop obj = oop(p); 2.232 + size_t obj_size = block_size(p); 2.233 + 2.234 + if (!g1->is_obj_dead_cond(obj, this, vo)) { 2.235 + if (obj->is_oop()) { 2.236 + vr_cl.set_containing_obj(obj); 2.237 + obj->oop_iterate_no_header(&vr_cl); 2.238 + 2.239 + if (vr_cl.failures()) { 2.240 + *failures = true; 2.241 + } 2.242 + if (G1MaxVerifyFailures >= 0 && 2.243 + vr_cl.n_failures() >= G1MaxVerifyFailures) { 2.244 + return; 2.245 + } 2.246 + } else { 2.247 + gclog_or_tty->print_cr(PTR_FORMAT " not an oop", p2i(obj)); 2.248 + *failures = true; 2.249 + return; 2.250 + } 2.251 + } 2.252 + 2.253 + prev_p = p; 2.254 + p += obj_size; 2.255 + } 2.256 +} 2.257 + 2.258 +void HeapRegion::verify_rem_set() const { 2.259 + bool failures = false; 2.260 + verify_rem_set(VerifyOption_G1UsePrevMarking, &failures); 2.261 + guarantee(!failures, "HeapRegion RemSet verification failed"); 2.262 +} 2.263 + 2.264 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go 2.265 // away eventually. 2.266
3.1 --- a/src/share/vm/gc_implementation/g1/heapRegion.hpp Thu Jan 28 09:41:33 2016 +0000 3.2 +++ b/src/share/vm/gc_implementation/g1/heapRegion.hpp Mon Feb 01 13:19:14 2016 -0800 3.3 @@ -779,6 +779,9 @@ 3.4 3.5 // Override; it uses the "prev" marking information 3.6 virtual void verify() const; 3.7 + 3.8 + void verify_rem_set(VerifyOption vo, bool *failures) const; 3.9 + void verify_rem_set() const; 3.10 }; 3.11 3.12 // HeapRegionClosure is used for iterating over regions.