51 G1CollectedHeap* _g1h;
52 VerifyOption _vo;
53 bool _failures;
54 public:
55 // _vo == UsePrevMarking -> use "prev" marking information,
56 // _vo == UseNextMarking -> use "next" marking information,
57 // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
58 VerifyRootsClosure(VerifyOption vo) :
59 _g1h(G1CollectedHeap::heap()),
60 _vo(vo),
61 _failures(false) { }
62
63 bool failures() { return _failures; }
64
65 template <class T> void do_oop_work(T* p) {
66 T heap_oop = RawAccess<>::oop_load(p);
67 if (!CompressedOops::is_null(heap_oop)) {
68 oop obj = CompressedOops::decode_not_null(heap_oop);
69 if (_g1h->is_obj_dead_cond(obj, _vo)) {
70 Log(gc, verify) log;
71 log.error("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
72 ResourceMark rm;
73 LogStream ls(log.error());
74 obj->print_on(&ls);
75 _failures = true;
76 }
77 }
78 }
79
80 void do_oop(oop* p) { do_oop_work(p); }
81 void do_oop(narrowOop* p) { do_oop_work(p); }
82 };
83
84 class G1VerifyCodeRootOopClosure: public OopClosure {
85 G1CollectedHeap* _g1h;
86 OopClosure* _root_cl;
87 nmethod* _nm;
88 VerifyOption _vo;
89 bool _failures;
90
91 template <class T> void do_oop_work(T* p) {
166
167 class VerifyCLDClosure: public CLDClosure {
168 YoungRefCounterClosure _young_ref_counter_closure;
169 OopClosure *_oop_closure;
170 public:
171 VerifyCLDClosure(G1CollectedHeap* g1h, OopClosure* cl) : _young_ref_counter_closure(g1h), _oop_closure(cl) {}
172 void do_cld(ClassLoaderData* cld) {
173 cld->oops_do(_oop_closure, ClassLoaderData::_claim_none);
174
175 _young_ref_counter_closure.reset_count();
176 cld->oops_do(&_young_ref_counter_closure, ClassLoaderData::_claim_none);
177 if (_young_ref_counter_closure.count() > 0) {
178 guarantee(cld->has_modified_oops(), "CLD " PTR_FORMAT ", has young %d refs but is not dirty.", p2i(cld), _young_ref_counter_closure.count());
179 }
180 }
181 };
182
183 class VerifyLivenessOopClosure: public BasicOopIterateClosure {
184 G1CollectedHeap* _g1h;
185 VerifyOption _vo;
186 public:
187 VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
188 _g1h(g1h), _vo(vo)
189 { }
190 void do_oop(narrowOop *p) { do_oop_work(p); }
191 void do_oop( oop *p) { do_oop_work(p); }
192
193 template <class T> void do_oop_work(T *p) {
194 oop obj = RawAccess<>::oop_load(p);
195 guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
196 "Dead object referenced by a not dead object");
197 }
198 };
199
200 class VerifyObjsInRegionClosure: public ObjectClosure {
201 private:
202 G1CollectedHeap* _g1h;
203 size_t _live_bytes;
204 HeapRegion *_hr;
205 VerifyOption _vo;
206 public:
207 // _vo == UsePrevMarking -> use "prev" marking information,
208 // _vo == UseNextMarking -> use "next" marking information,
209 // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS.
210 VerifyObjsInRegionClosure(HeapRegion *hr, VerifyOption vo)
211 : _live_bytes(0), _hr(hr), _vo(vo) {
212 _g1h = G1CollectedHeap::heap();
213 }
214 void do_object(oop o) {
215 VerifyLivenessOopClosure isLive(_g1h, _vo);
216 assert(o != NULL, "Huh?");
217 if (!_g1h->is_obj_dead_cond(o, _vo)) {
218 // If the object is alive according to the full gc mark,
219 // then verify that the marking information agrees.
220 // Note we can't verify the contra-positive of the
221 // above: if the object is dead (according to the mark
222 // word), it may not be marked, or may have been marked
223 // but has since became dead, or may have been allocated
224 // since the last marking.
225 if (_vo == VerifyOption_G1UseFullMarking) {
226 guarantee(!_g1h->is_obj_dead(o), "Full GC marking and concurrent mark mismatch");
227 }
228
229 o->oop_iterate(&isLive);
230 if (!_hr->obj_allocated_since_prev_marking(o)) {
231 size_t obj_size = o->size(); // Make sure we don't overflow
232 _live_bytes += (obj_size * HeapWordSize);
233 }
234 }
235 }
|
51 G1CollectedHeap* _g1h;
52 VerifyOption _vo;
53 bool _failures;
54 public:
55 // _vo == UsePrevMarking -> use "prev" marking information,
56 // _vo == UseNextMarking -> use "next" marking information,
57 // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS
58 VerifyRootsClosure(VerifyOption vo) :
59 _g1h(G1CollectedHeap::heap()),
60 _vo(vo),
61 _failures(false) { }
62
63 bool failures() { return _failures; }
64
65 template <class T> void do_oop_work(T* p) {
66 T heap_oop = RawAccess<>::oop_load(p);
67 if (!CompressedOops::is_null(heap_oop)) {
68 oop obj = CompressedOops::decode_not_null(heap_oop);
69 if (_g1h->is_obj_dead_cond(obj, _vo)) {
70 Log(gc, verify) log;
71 log.error("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT " vo %d", p2i(p), p2i(obj), _vo);
72 ResourceMark rm;
73 LogStream ls(log.error());
74 obj->print_on(&ls);
75 _failures = true;
76 }
77 }
78 }
79
80 void do_oop(oop* p) { do_oop_work(p); }
81 void do_oop(narrowOop* p) { do_oop_work(p); }
82 };
83
84 class G1VerifyCodeRootOopClosure: public OopClosure {
85 G1CollectedHeap* _g1h;
86 OopClosure* _root_cl;
87 nmethod* _nm;
88 VerifyOption _vo;
89 bool _failures;
90
91 template <class T> void do_oop_work(T* p) {
166
167 class VerifyCLDClosure: public CLDClosure {
168 YoungRefCounterClosure _young_ref_counter_closure;
169 OopClosure *_oop_closure;
170 public:
171 VerifyCLDClosure(G1CollectedHeap* g1h, OopClosure* cl) : _young_ref_counter_closure(g1h), _oop_closure(cl) {}
172 void do_cld(ClassLoaderData* cld) {
173 cld->oops_do(_oop_closure, ClassLoaderData::_claim_none);
174
175 _young_ref_counter_closure.reset_count();
176 cld->oops_do(&_young_ref_counter_closure, ClassLoaderData::_claim_none);
177 if (_young_ref_counter_closure.count() > 0) {
178 guarantee(cld->has_modified_oops(), "CLD " PTR_FORMAT ", has young %d refs but is not dirty.", p2i(cld), _young_ref_counter_closure.count());
179 }
180 }
181 };
182
183 class VerifyLivenessOopClosure: public BasicOopIterateClosure {
184 G1CollectedHeap* _g1h;
185 VerifyOption _vo;
186 oop _o;
187 public:
188 VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo, oop o):
189 _g1h(g1h), _vo(vo), _o(o)
190 { }
191 void do_oop(narrowOop *p) { do_oop_work(p); }
192 void do_oop( oop *p) { do_oop_work(p); }
193
194 template <class T> void do_oop_work(T *p) {
195 oop obj = RawAccess<>::oop_load(p);
196 guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
197 "vo %d Dead object " PTR_FORMAT " (%s) referenced by a not dead object " PTR_FORMAT " (%s) _g1h->is_obj_dead_cond(obj, _vo) %d marked %d since prev mark %d since next mark %d",
198 _vo,
199 p2i(obj), _g1h->heap_region_containing(obj)->get_short_type_str(),
200 p2i(_o), _g1h->heap_region_containing(_o)->get_short_type_str(),
201 _g1h->is_obj_dead_cond(obj, _vo),
202 _g1h->concurrent_mark()->prev_mark_bitmap()->is_marked(_o),
203 _g1h->heap_region_containing(_o)->obj_allocated_since_prev_marking(_o),
204 _g1h->heap_region_containing(_o)->obj_allocated_since_next_marking(_o)
205 );
206 }
207 };
208
209 class VerifyObjsInRegionClosure: public ObjectClosure {
210 private:
211 G1CollectedHeap* _g1h;
212 size_t _live_bytes;
213 HeapRegion *_hr;
214 VerifyOption _vo;
215 public:
216 // _vo == UsePrevMarking -> use "prev" marking information,
217 // _vo == UseNextMarking -> use "next" marking information,
218 // _vo == UseFullMarking -> use "next" marking bitmap but no TAMS.
219 VerifyObjsInRegionClosure(HeapRegion *hr, VerifyOption vo)
220 : _live_bytes(0), _hr(hr), _vo(vo) {
221 _g1h = G1CollectedHeap::heap();
222 }
223 void do_object(oop o) {
224 VerifyLivenessOopClosure isLive(_g1h, _vo, o);
225 assert(o != NULL, "Huh?");
226 if (!_g1h->is_obj_dead_cond(o, _vo)) {
227 // If the object is alive according to the full gc mark,
228 // then verify that the marking information agrees.
229 // Note we can't verify the contra-positive of the
230 // above: if the object is dead (according to the mark
231 // word), it may not be marked, or may have been marked
232 // but has since became dead, or may have been allocated
233 // since the last marking.
234 if (_vo == VerifyOption_G1UseFullMarking) {
235 guarantee(!_g1h->is_obj_dead(o), "Full GC marking and concurrent mark mismatch");
236 }
237
238 o->oop_iterate(&isLive);
239 if (!_hr->obj_allocated_since_prev_marking(o)) {
240 size_t obj_size = o->size(); // Make sure we don't overflow
241 _live_bytes += (obj_size * HeapWordSize);
242 }
243 }
244 }
|