144 nmethod* nm = cb->as_nmethod_or_null();
145 if (nm != NULL) {
146 _oop_cl->set_nmethod(nm);
147 nm->oops_do(_oop_cl);
148 }
149 }
150 };
151
152 class YoungRefCounterClosure : public OopClosure {
153 G1CollectedHeap* _g1h;
154 int _count;
155 public:
156 YoungRefCounterClosure(G1CollectedHeap* g1h) : _g1h(g1h), _count(0) {}
157 void do_oop(oop* p) { if (_g1h->is_in_young(*p)) { _count++; } }
158 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
159
160 int count() { return _count; }
161 void reset_count() { _count = 0; };
162 };
163
164 class VerifyKlassClosure: public KlassClosure {
165 YoungRefCounterClosure _young_ref_counter_closure;
166 OopClosure *_oop_closure;
167 public:
168 VerifyKlassClosure(G1CollectedHeap* g1h, OopClosure* cl) : _young_ref_counter_closure(g1h), _oop_closure(cl) {}
169 void do_klass(Klass* k) {
170 k->oops_do(_oop_closure);
171
172 _young_ref_counter_closure.reset_count();
173 k->oops_do(&_young_ref_counter_closure);
174 if (_young_ref_counter_closure.count() > 0) {
175 guarantee(k->has_modified_oops(), "Klass " PTR_FORMAT ", has young refs but is not dirty.", p2i(k));
176 }
177 }
178 };
179
180 class VerifyLivenessOopClosure: public OopClosure {
181 G1CollectedHeap* _g1h;
182 VerifyOption _vo;
183 public:
184 VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
185 _g1h(g1h), _vo(vo)
186 { }
187 void do_oop(narrowOop *p) { do_oop_work(p); }
188 void do_oop( oop *p) { do_oop_work(p); }
189
190 template <class T> void do_oop_work(T *p) {
191 oop obj = oopDesc::load_decode_heap_oop(p);
192 guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
193 "Dead object referenced by a not dead object");
194 }
195 };
373 HandleMark hm;
374 VerifyRegionClosure blk(true, _vo);
375 _g1h->heap_region_par_iterate(&blk, worker_id, &_hrclaimer);
376 if (blk.failures()) {
377 _failures = true;
378 }
379 }
380 };
381
382
383 void G1HeapVerifier::verify(VerifyOption vo) {
384 if (!SafepointSynchronize::is_at_safepoint()) {
385 log_info(gc, verify)("Skipping verification. Not at safepoint.");
386 }
387
388 assert(Thread::current()->is_VM_thread(),
389 "Expected to be executed serially by the VM thread at this point");
390
391 log_debug(gc, verify)("Roots");
392 VerifyRootsClosure rootsCl(vo);
393 VerifyKlassClosure klassCl(_g1h, &rootsCl);
394 CLDToKlassAndOopClosure cldCl(&klassCl, &rootsCl, false);
395
396 // We apply the relevant closures to all the oops in the
397 // system dictionary, class loader data graph, the string table
398 // and the nmethods in the code cache.
399 G1VerifyCodeRootOopClosure codeRootsCl(_g1h, &rootsCl, vo);
400 G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl);
401
402 {
403 G1RootProcessor root_processor(_g1h, 1);
404 root_processor.process_all_roots(&rootsCl,
405 &cldCl,
406 &blobsCl);
407 }
408
409 bool failures = rootsCl.failures() || codeRootsCl.failures();
410
411 if (vo != VerifyOption_G1UseMarkWord) {
412 // If we're verifying during a full GC then the region sets
413 // will have been torn down at the start of the GC. Therefore
414 // verifying the region sets will fail. So we only verify
|
144 nmethod* nm = cb->as_nmethod_or_null();
145 if (nm != NULL) {
146 _oop_cl->set_nmethod(nm);
147 nm->oops_do(_oop_cl);
148 }
149 }
150 };
151
152 class YoungRefCounterClosure : public OopClosure {
153 G1CollectedHeap* _g1h;
154 int _count;
155 public:
156 YoungRefCounterClosure(G1CollectedHeap* g1h) : _g1h(g1h), _count(0) {}
157 void do_oop(oop* p) { if (_g1h->is_in_young(*p)) { _count++; } }
158 void do_oop(narrowOop* p) { ShouldNotReachHere(); }
159
160 int count() { return _count; }
161 void reset_count() { _count = 0; };
162 };
163
164 class VerifyCLDClosure: public CLDClosure {
165 YoungRefCounterClosure _young_ref_counter_closure;
166 OopClosure *_oop_closure;
167 G1CollectedHeap* _g1h;
168 public:
169 VerifyCLDClosure(G1CollectedHeap* g1h, OopClosure* cl) : _g1h(g1h), _young_ref_counter_closure(g1h), _oop_closure(cl) {}
170 void do_cld(ClassLoaderData* cld) {
171 cld->oops_do(_oop_closure, false);
172
173 _young_ref_counter_closure.reset_count();
174 cld->oops_do(&_young_ref_counter_closure, false);
175 if (_young_ref_counter_closure.count() > 0) {
176 guarantee(cld->has_modified_oops(), "CLD " PTR_FORMAT ", has young %d refs but is not dirty.", p2i(cld), _young_ref_counter_closure.count());
177 }
178 }
179 };
180
181 class VerifyLivenessOopClosure: public OopClosure {
182 G1CollectedHeap* _g1h;
183 VerifyOption _vo;
184 public:
185 VerifyLivenessOopClosure(G1CollectedHeap* g1h, VerifyOption vo):
186 _g1h(g1h), _vo(vo)
187 { }
188 void do_oop(narrowOop *p) { do_oop_work(p); }
189 void do_oop( oop *p) { do_oop_work(p); }
190
191 template <class T> void do_oop_work(T *p) {
192 oop obj = oopDesc::load_decode_heap_oop(p);
193 guarantee(obj == NULL || !_g1h->is_obj_dead_cond(obj, _vo),
194 "Dead object referenced by a not dead object");
195 }
196 };
374 HandleMark hm;
375 VerifyRegionClosure blk(true, _vo);
376 _g1h->heap_region_par_iterate(&blk, worker_id, &_hrclaimer);
377 if (blk.failures()) {
378 _failures = true;
379 }
380 }
381 };
382
383
384 void G1HeapVerifier::verify(VerifyOption vo) {
385 if (!SafepointSynchronize::is_at_safepoint()) {
386 log_info(gc, verify)("Skipping verification. Not at safepoint.");
387 }
388
389 assert(Thread::current()->is_VM_thread(),
390 "Expected to be executed serially by the VM thread at this point");
391
392 log_debug(gc, verify)("Roots");
393 VerifyRootsClosure rootsCl(vo);
394 VerifyCLDClosure cldCl(_g1h, &rootsCl);
395
396 // We apply the relevant closures to all the oops in the
397 // system dictionary, class loader data graph, the string table
398 // and the nmethods in the code cache.
399 G1VerifyCodeRootOopClosure codeRootsCl(_g1h, &rootsCl, vo);
400 G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl);
401
402 {
403 G1RootProcessor root_processor(_g1h, 1);
404 root_processor.process_all_roots(&rootsCl,
405 &cldCl,
406 &blobsCl);
407 }
408
409 bool failures = rootsCl.failures() || codeRootsCl.failures();
410
411 if (vo != VerifyOption_G1UseMarkWord) {
412 // If we're verifying during a full GC then the region sets
413 // will have been torn down at the start of the GC. Therefore
414 // verifying the region sets will fail. So we only verify
|