43 class VerifyRootsClosure: public OopClosure {
44 private:
45 G1CollectedHeap* _g1h;
46 VerifyOption _vo;
47 bool _failures;
48 public:
49 // _vo == UsePrevMarking -> use "prev" marking information,
50 // _vo == UseNextMarking -> use "next" marking information,
51 // _vo == UseMarkWord -> use mark word from object header.
52 VerifyRootsClosure(VerifyOption vo) :
53 _g1h(G1CollectedHeap::heap()),
54 _vo(vo),
55 _failures(false) { }
56
57 bool failures() { return _failures; }
58
59 template <class T> void do_oop_nv(T* p) {
60 T heap_oop = oopDesc::load_heap_oop(p);
61 if (!oopDesc::is_null(heap_oop)) {
62 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
63 if (_g1h->is_obj_dead_cond(obj, _vo)) {
64 Log(gc, verify) log;
65 log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
66 if (_vo == VerifyOption_G1UseMarkWord) {
67 log.error(" Mark word: " PTR_FORMAT, p2i(obj->mark()));
68 }
69 ResourceMark rm;
70 LogStream ls(log.error());
71 obj->print_on(&ls);
72 _failures = true;
73 }
74 }
75 }
76
77 void do_oop(oop* p) { do_oop_nv(p); }
78 void do_oop(narrowOop* p) { do_oop_nv(p); }
79 };
80
81 class G1VerifyCodeRootOopClosure: public OopClosure {
82 G1CollectedHeap* _g1h;
83 OopClosure* _root_cl;
217 // Note we can't verify the contra-positive of the
218 // above: if the object is dead (according to the mark
219 // word), it may not be marked, or may have been marked
220 // but has since became dead, or may have been allocated
221 // since the last marking.
222 if (_vo == VerifyOption_G1UseMarkWord) {
223 guarantee(!_g1h->is_obj_dead(o), "mark word and concurrent mark mismatch");
224 }
225
226 o->oop_iterate_no_header(&isLive);
227 if (!_hr->obj_allocated_since_prev_marking(o)) {
228 size_t obj_size = o->size(); // Make sure we don't overflow
229 _live_bytes += (obj_size * HeapWordSize);
230 }
231 }
232 }
233 size_t live_bytes() { return _live_bytes; }
234 };
235
236 class VerifyArchiveOopClosure: public OopClosure {
237 public:
238 VerifyArchiveOopClosure(HeapRegion *hr) { }
239 void do_oop(narrowOop *p) { do_oop_work(p); }
240 void do_oop( oop *p) { do_oop_work(p); }
241
242 template <class T> void do_oop_work(T *p) {
243 oop obj = oopDesc::load_decode_heap_oop(p);
244 guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
245 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
246 p2i(p), p2i(obj));
247 }
248 };
249
250 class VerifyArchiveRegionClosure: public ObjectClosure {
251 public:
252 VerifyArchiveRegionClosure(HeapRegion *hr) { }
253 // Verify that all object pointers are to archive regions.
254 void do_object(oop o) {
255 VerifyArchiveOopClosure checkOop(NULL);
256 assert(o != NULL, "Should not be here for NULL oops");
257 o->oop_iterate_no_header(&checkOop);
258 }
259 };
260
261 class VerifyRegionClosure: public HeapRegionClosure {
262 private:
263 bool _par;
264 VerifyOption _vo;
265 bool _failures;
266 public:
267 // _vo == UsePrevMarking -> use "prev" marking information,
268 // _vo == UseNextMarking -> use "next" marking information,
269 // _vo == UseMarkWord -> use mark word from object header.
270 VerifyRegionClosure(bool par, VerifyOption vo)
271 : _par(par),
272 _vo(vo),
273 _failures(false) {}
274
275 bool failures() {
276 return _failures;
277 }
278
279 bool doHeapRegion(HeapRegion* r) {
280 // For archive regions, verify there are no heap pointers to
281 // non-pinned regions. For all others, verify liveness info.
282 if (r->is_archive()) {
283 VerifyArchiveRegionClosure verify_oop_pointers(r);
284 r->object_iterate(&verify_oop_pointers);
285 return true;
286 }
287 if (!r->is_continues_humongous()) {
288 bool failures = false;
289 r->verify(_vo, &failures);
290 if (failures) {
291 _failures = true;
292 } else if (!r->is_starts_humongous()) {
293 VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo);
294 r->object_iterate(¬_dead_yet_cl);
295 if (_vo != VerifyOption_G1UseNextMarking) {
296 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) {
297 log_error(gc, verify)("[" PTR_FORMAT "," PTR_FORMAT "] max_live_bytes " SIZE_FORMAT " < calculated " SIZE_FORMAT,
298 p2i(r->bottom()), p2i(r->end()), r->max_live_bytes(), not_dead_yet_cl.live_bytes());
299 _failures = true;
300 }
301 } else {
302 // When vo == UseNextMarking we cannot currently do a sanity
303 // check on the live bytes as the calculation has not been
304 // finalized yet.
305 }
306 }
307 }
|
43 class VerifyRootsClosure: public OopClosure {
44 private:
45 G1CollectedHeap* _g1h;
46 VerifyOption _vo;
47 bool _failures;
48 public:
49 // _vo == UsePrevMarking -> use "prev" marking information,
50 // _vo == UseNextMarking -> use "next" marking information,
51 // _vo == UseMarkWord -> use mark word from object header.
52 VerifyRootsClosure(VerifyOption vo) :
53 _g1h(G1CollectedHeap::heap()),
54 _vo(vo),
55 _failures(false) { }
56
57 bool failures() { return _failures; }
58
59 template <class T> void do_oop_nv(T* p) {
60 T heap_oop = oopDesc::load_heap_oop(p);
61 if (!oopDesc::is_null(heap_oop)) {
62 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
63 HeapRegion* hr = _g1h->heap_region_containing(obj);
64 if (_g1h->is_obj_dead_cond(obj, _vo) && !hr->is_archive()) {
65 Log(gc, verify) log;
66 log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
67 if (_vo == VerifyOption_G1UseMarkWord) {
68 log.error(" Mark word: " PTR_FORMAT, p2i(obj->mark()));
69 }
70 ResourceMark rm;
71 LogStream ls(log.error());
72 obj->print_on(&ls);
73 _failures = true;
74 }
75 }
76 }
77
78 void do_oop(oop* p) { do_oop_nv(p); }
79 void do_oop(narrowOop* p) { do_oop_nv(p); }
80 };
81
82 class G1VerifyCodeRootOopClosure: public OopClosure {
83 G1CollectedHeap* _g1h;
84 OopClosure* _root_cl;
218 // Note we can't verify the contra-positive of the
219 // above: if the object is dead (according to the mark
220 // word), it may not be marked, or may have been marked
221 // but has since became dead, or may have been allocated
222 // since the last marking.
223 if (_vo == VerifyOption_G1UseMarkWord) {
224 guarantee(!_g1h->is_obj_dead(o), "mark word and concurrent mark mismatch");
225 }
226
227 o->oop_iterate_no_header(&isLive);
228 if (!_hr->obj_allocated_since_prev_marking(o)) {
229 size_t obj_size = o->size(); // Make sure we don't overflow
230 _live_bytes += (obj_size * HeapWordSize);
231 }
232 }
233 }
234 size_t live_bytes() { return _live_bytes; }
235 };
236
237 class VerifyArchiveOopClosure: public OopClosure {
238 HeapRegion* _hr;
239 bool _verbose;
240 public:
241 VerifyArchiveOopClosure(HeapRegion *hr, bool verbose)
242 : _hr(hr), _verbose(verbose) { }
243 void do_oop(narrowOop *p) { do_oop_work(p); }
244 void do_oop( oop *p) { do_oop_work(p); }
245
246 template <class T> void do_oop_work(T *p) {
247 oop obj = oopDesc::load_decode_heap_oop(p);
248 if (_verbose) {
249 if (obj != NULL) {
250 obj->print();
251 }
252 }
253
254 if (_hr->is_open_archive()) {
255 guarantee(obj == NULL || G1ArchiveAllocator::is_archive_object(obj),
256 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
257 p2i(p), p2i(obj));
258 } else {
259 assert(_hr->is_closed_archive(), "should be archive region");
260 guarantee(obj == NULL || G1ArchiveAllocator::is_closed_archive_object(obj),
261 "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
262 p2i(p), p2i(obj));
263 }
264 }
265 };
266
267 class VerifyObjectInArchiveRegionClosure: public ObjectClosure {
268 HeapRegion* _hr;
269 bool _verbose;
270 public:
271 VerifyObjectInArchiveRegionClosure(HeapRegion *hr, bool verbose)
272 : _hr(hr), _verbose(verbose) { }
273 // Verify that all object pointers are to archive regions.
274 void do_object(oop o) {
275 if (_verbose) {
276 o->print();
277 }
278
279 VerifyArchiveOopClosure checkOop(_hr, _verbose);
280 assert(o != NULL, "Should not be here for NULL oops");
281 o->oop_iterate_no_header(&checkOop);
282 }
283 };
284
285 // Should be only used at CDS dump time
286 class VerifyArchivePointerRegionClosure: public HeapRegionClosure {
287 private:
288 G1CollectedHeap* _g1h;
289 public:
290 VerifyArchivePointerRegionClosure(G1CollectedHeap* g1h) { }
291 virtual bool doHeapRegion(HeapRegion* r) {
292 if (r->is_archive()) {
293 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
294 r->object_iterate(&verify_oop_pointers);
295 }
296 return false;
297 }
298 };
299
300 void G1HeapVerifier::verify_archive_regions() {
301 G1CollectedHeap* g1h = G1CollectedHeap::heap();
302 VerifyArchivePointerRegionClosure cl(NULL);
303 g1h->heap_region_iterate(&cl);
304 }
305
306 class VerifyRegionClosure: public HeapRegionClosure {
307 private:
308 bool _par;
309 VerifyOption _vo;
310 bool _failures;
311 public:
312 // _vo == UsePrevMarking -> use "prev" marking information,
313 // _vo == UseNextMarking -> use "next" marking information,
314 // _vo == UseMarkWord -> use mark word from object header.
315 VerifyRegionClosure(bool par, VerifyOption vo)
316 : _par(par),
317 _vo(vo),
318 _failures(false) {}
319
320 bool failures() {
321 return _failures;
322 }
323
324 bool doHeapRegion(HeapRegion* r) {
325 // For archive regions, verify there are no heap pointers to
326 // non-pinned regions. For all others, verify liveness info.
327 if (r->is_closed_archive()) {
328 VerifyObjectInArchiveRegionClosure verify_oop_pointers(r, false);
329 r->object_iterate(&verify_oop_pointers);
330 return true;
331 } else if (r->is_open_archive()) {
332 VerifyObjsInRegionClosure verify_open_archive_oop(r, _vo);
333 r->object_iterate(&verify_open_archive_oop);
334 return true;
335 } else if (!r->is_continues_humongous()) {
336 bool failures = false;
337 r->verify(_vo, &failures);
338 if (failures) {
339 _failures = true;
340 } else if (!r->is_starts_humongous()) {
341 VerifyObjsInRegionClosure not_dead_yet_cl(r, _vo);
342 r->object_iterate(¬_dead_yet_cl);
343 if (_vo != VerifyOption_G1UseNextMarking) {
344 if (r->max_live_bytes() < not_dead_yet_cl.live_bytes()) {
345 log_error(gc, verify)("[" PTR_FORMAT "," PTR_FORMAT "] max_live_bytes " SIZE_FORMAT " < calculated " SIZE_FORMAT,
346 p2i(r->bottom()), p2i(r->end()), r->max_live_bytes(), not_dead_yet_cl.live_bytes());
347 _failures = true;
348 }
349 } else {
350 // When vo == UseNextMarking we cannot currently do a sanity
351 // check on the live bytes as the calculation has not been
352 // finalized yet.
353 }
354 }
355 }
|