80 _interior_loc(NULL),
81 _loc(NULL) {
82 if (options._verify_marked == ShenandoahVerifier::_verify_marked_complete_except_references ||
83 options._verify_marked == ShenandoahVerifier::_verify_marked_disable) {
84 set_ref_discoverer_internal(new ShenandoahIgnoreReferenceDiscoverer());
85 }
86 }
87
88 private:
89 void check(ShenandoahAsserts::SafeLevel level, oop obj, bool test, const char* label) {
90 if (!test) {
91 ShenandoahAsserts::print_failure(level, obj, _interior_loc, _loc, _phase, label, __FILE__, __LINE__);
92 }
93 }
94
95 template <class T>
96 void do_oop_work(T* p) {
97 T o = RawAccess<>::oop_load(p);
98 if (!CompressedOops::is_null(o)) {
99 oop obj = CompressedOops::decode_not_null(o);
100 if (is_instance_ref_klass(obj->klass())) {
101 obj = ShenandoahForwarding::get_forwardee(obj);
102 }
103 // Single threaded verification can use faster non-atomic stack and bitmap
104 // methods.
105 //
106 // For performance reasons, only fully verify non-marked field values.
107 // We are here when the host object for *p is already marked.
108
109 if (_map->par_mark(obj)) {
110 verify_oop_at(p, obj);
111 _stack->push(ShenandoahVerifierTask(obj));
112 }
113 }
114 }
115
116 void verify_oop(oop obj) {
117 // Perform consistency checks with gradually decreasing safety level. This guarantees
118 // that failure report would not try to touch something that was not yet verified to be
119 // safe to process.
120
121 check(ShenandoahAsserts::_safe_unknown, obj, _heap->is_in(obj),
122 "oop must be in heap");
123 check(ShenandoahAsserts::_safe_unknown, obj, is_object_aligned(obj),
124 "oop must be aligned");
125
126 ShenandoahHeapRegion *obj_reg = _heap->heap_region_containing(obj);
127 Klass* obj_klass = obj->klass_or_null();
128
129 // Verify that obj is not in dead space:
130 {
131 // Do this before touching obj->size()
132 check(ShenandoahAsserts::_safe_unknown, obj, obj_klass != NULL,
133 "Object klass pointer should not be NULL");
134 check(ShenandoahAsserts::_safe_unknown, obj, Metaspace::contains(obj_klass),
135 "Object klass pointer must go to metaspace");
136
137 HeapWord *obj_addr = cast_from_oop<HeapWord*>(obj);
138 check(ShenandoahAsserts::_safe_unknown, obj, obj_addr < obj_reg->top(),
139 "Object start should be within the region");
140
141 if (!obj_reg->is_humongous()) {
142 check(ShenandoahAsserts::_safe_unknown, obj, (obj_addr + obj->size()) <= obj_reg->top(),
143 "Object end should be within the region");
144 } else {
145 size_t humongous_start = obj_reg->index();
146 size_t humongous_end = humongous_start + (obj->size() >> ShenandoahHeapRegion::region_size_words_shift());
147 for (size_t idx = humongous_start + 1; idx < humongous_end; idx++) {
148 check(ShenandoahAsserts::_safe_unknown, obj, _heap->get_region(idx)->is_humongous_continuation(),
149 "Humongous object is in continuation that fits it");
150 }
151 }
152
153 // ------------ obj is safe at this point --------------
154
155 check(ShenandoahAsserts::_safe_oop, obj, obj_reg->is_active(),
156 "Object should be in active region");
157
158 switch (_options._verify_liveness) {
159 case ShenandoahVerifier::_verify_liveness_disable:
160 // skip
161 break;
162 case ShenandoahVerifier::_verify_liveness_complete:
163 Atomic::add(&_ld[obj_reg->index()], (uint) obj->size(), memory_order_relaxed);
164 // fallthrough for fast failure for un-live regions:
165 case ShenandoahVerifier::_verify_liveness_conservative:
166 check(ShenandoahAsserts::_safe_oop, obj, obj_reg->has_live(),
167 "Object must belong to region with live data");
168 break;
169 default:
170 assert(false, "Unhandled liveness verification");
171 }
172 }
173
174 oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
175
176 ShenandoahHeapRegion* fwd_reg = NULL;
177
178 if (obj != fwd) {
179 check(ShenandoahAsserts::_safe_oop, obj, _heap->is_in(fwd),
180 "Forwardee must be in heap");
181 check(ShenandoahAsserts::_safe_oop, obj, !CompressedOops::is_null(fwd),
182 "Forwardee is set");
183 check(ShenandoahAsserts::_safe_oop, obj, is_object_aligned(fwd),
184 "Forwardee must be aligned");
185
186 // Do this before touching fwd->size()
187 Klass* fwd_klass = fwd->klass_or_null();
188 check(ShenandoahAsserts::_safe_oop, obj, fwd_klass != NULL,
189 "Forwardee klass pointer should not be NULL");
190 check(ShenandoahAsserts::_safe_oop, obj, Metaspace::contains(fwd_klass),
191 "Forwardee klass pointer must go to metaspace");
192 check(ShenandoahAsserts::_safe_oop, obj, obj_klass == fwd_klass,
193 "Forwardee klass pointer must go to metaspace");
194
195 fwd_reg = _heap->heap_region_containing(fwd);
196
197 // Verify that forwardee is not in the dead space:
198 check(ShenandoahAsserts::_safe_oop, obj, !fwd_reg->is_humongous(),
199 "Should have no humongous forwardees");
200
201 HeapWord *fwd_addr = cast_from_oop<HeapWord *>(fwd);
202 check(ShenandoahAsserts::_safe_oop, obj, fwd_addr < fwd_reg->top(),
203 "Forwardee start should be within the region");
204 check(ShenandoahAsserts::_safe_oop, obj, (fwd_addr + fwd->size()) <= fwd_reg->top(),
205 "Forwardee end should be within the region");
206
207 oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
208 check(ShenandoahAsserts::_safe_oop, obj, (fwd == fwd2),
209 "Double forwarding");
210 } else {
211 fwd_reg = obj_reg;
212 }
213
214 // ------------ obj and fwd are safe at this point --------------
215
216 switch (_options._verify_marked) {
217 case ShenandoahVerifier::_verify_marked_disable:
218 // skip
219 break;
220 case ShenandoahVerifier::_verify_marked_incomplete:
221 check(ShenandoahAsserts::_safe_all, obj, _heap->marking_context()->is_marked(obj),
222 "Must be marked in incomplete bitmap");
223 break;
224 case ShenandoahVerifier::_verify_marked_complete:
287 }
288
289 /**
290 * Verify object without known interior reference.
291 * Useful when picking up the object at known offset in heap,
292 * but without knowing what objects reference it.
293 * @param obj verified object
294 */
295 void verify_oop_standalone(oop obj) {
296 _interior_loc = NULL;
297 verify_oop(obj);
298 _interior_loc = NULL;
299 }
300
301 /**
302 * Verify oop fields from this object.
303 * @param obj host object for verified fields
304 */
305 void verify_oops_from(oop obj) {
306 _loc = obj;
307 obj->oop_iterate(this);
308 _loc = NULL;
309 }
310
311 virtual void do_oop(oop* p) { do_oop_work(p); }
312 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
313 };
314
315 class ShenandoahCalculateRegionStatsClosure : public ShenandoahHeapRegionClosure {
316 private:
317 size_t _used, _committed, _garbage;
318 public:
319 ShenandoahCalculateRegionStatsClosure() : _used(0), _committed(0), _garbage(0) {};
320
321 void heap_region_do(ShenandoahHeapRegion* r) {
322 _used += r->used();
323 _garbage += r->garbage();
324 _committed += r->is_committed() ? ShenandoahHeapRegion::region_size_bytes() : 0;
325 }
326
327 size_t used() { return _used; }
567 HeapWord* addr = tams;
568
569 while (addr < limit) {
570 verify_and_follow(addr, stack, cl, &processed);
571 addr += cast_to_oop(addr)->size();
572 }
573 }
574
575 Atomic::add(&_processed, processed, memory_order_relaxed);
576 }
577
578 void verify_and_follow(HeapWord *addr, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl, size_t *processed) {
579 if (!_bitmap->par_mark(addr)) return;
580
581 // Verify the object itself:
582 oop obj = cast_to_oop(addr);
583 cl.verify_oop_standalone(obj);
584
585 // Verify everything reachable from that object too, hopefully realizing
586 // everything was already marked, and never touching further:
587 if (!is_instance_ref_klass(obj->klass())) {
588 cl.verify_oops_from(obj);
589 (*processed)++;
590 }
591 while (!stack.is_empty()) {
592 ShenandoahVerifierTask task = stack.pop();
593 cl.verify_oops_from(task.obj());
594 (*processed)++;
595 }
596 }
597 };
598
599 class VerifyThreadGCState : public ThreadClosure {
600 private:
601 const char* const _label;
602 char const _expected;
603
604 public:
605 VerifyThreadGCState(const char* label, char expected) : _label(label), _expected(expected) {}
606 void do_thread(Thread* t) {
607 char actual = ShenandoahThreadLocalData::gc_state(t);
|
80 _interior_loc(NULL),
81 _loc(NULL) {
82 if (options._verify_marked == ShenandoahVerifier::_verify_marked_complete_except_references ||
83 options._verify_marked == ShenandoahVerifier::_verify_marked_disable) {
84 set_ref_discoverer_internal(new ShenandoahIgnoreReferenceDiscoverer());
85 }
86 }
87
88 private:
89 void check(ShenandoahAsserts::SafeLevel level, oop obj, bool test, const char* label) {
90 if (!test) {
91 ShenandoahAsserts::print_failure(level, obj, _interior_loc, _loc, _phase, label, __FILE__, __LINE__);
92 }
93 }
94
95 template <class T>
96 void do_oop_work(T* p) {
97 T o = RawAccess<>::oop_load(p);
98 if (!CompressedOops::is_null(o)) {
99 oop obj = CompressedOops::decode_not_null(o);
100 if (is_instance_ref_klass(obj->forward_safe_klass())) {
101 obj = ShenandoahForwarding::get_forwardee(obj);
102 }
103 // Single threaded verification can use faster non-atomic stack and bitmap
104 // methods.
105 //
106 // For performance reasons, only fully verify non-marked field values.
107 // We are here when the host object for *p is already marked.
108
109 if (_map->par_mark(obj)) {
110 verify_oop_at(p, obj);
111 _stack->push(ShenandoahVerifierTask(obj));
112 }
113 }
114 }
115
116 void verify_oop(oop obj) {
117 // Perform consistency checks with gradually decreasing safety level. This guarantees
118 // that failure report would not try to touch something that was not yet verified to be
119 // safe to process.
120
121 check(ShenandoahAsserts::_safe_unknown, obj, _heap->is_in(obj),
122 "oop must be in heap");
123 check(ShenandoahAsserts::_safe_unknown, obj, is_object_aligned(obj),
124 "oop must be aligned");
125
126 ShenandoahHeapRegion *obj_reg = _heap->heap_region_containing(obj);
127 Klass* obj_klass = obj->forward_safe_klass();
128
129 // Verify that obj is not in dead space:
130 {
131 // Do this before touching obj->size()
132 check(ShenandoahAsserts::_safe_unknown, obj, obj_klass != NULL,
133 "Object klass pointer should not be NULL");
134 check(ShenandoahAsserts::_safe_unknown, obj, Metaspace::contains(obj_klass),
135 "Object klass pointer must go to metaspace");
136
137 HeapWord *obj_addr = cast_from_oop<HeapWord*>(obj);
138 check(ShenandoahAsserts::_safe_unknown, obj, obj_addr < obj_reg->top(),
139 "Object start should be within the region");
140
141 if (!obj_reg->is_humongous()) {
142 check(ShenandoahAsserts::_safe_unknown, obj, (obj_addr + obj->forward_safe_size()) <= obj_reg->top(),
143 "Object end should be within the region");
144 } else {
145 size_t humongous_start = obj_reg->index();
146 size_t humongous_end = humongous_start + (obj->forward_safe_size() >> ShenandoahHeapRegion::region_size_words_shift());
147 for (size_t idx = humongous_start + 1; idx < humongous_end; idx++) {
148 check(ShenandoahAsserts::_safe_unknown, obj, _heap->get_region(idx)->is_humongous_continuation(),
149 "Humongous object is in continuation that fits it");
150 }
151 }
152
153 // ------------ obj is safe at this point --------------
154
155 check(ShenandoahAsserts::_safe_oop, obj, obj_reg->is_active(),
156 "Object should be in active region");
157
158 switch (_options._verify_liveness) {
159 case ShenandoahVerifier::_verify_liveness_disable:
160 // skip
161 break;
162 case ShenandoahVerifier::_verify_liveness_complete:
163 Atomic::add(&_ld[obj_reg->index()], (uint) obj->forward_safe_size(), memory_order_relaxed);
164 // fallthrough for fast failure for un-live regions:
165 case ShenandoahVerifier::_verify_liveness_conservative:
166 check(ShenandoahAsserts::_safe_oop, obj, obj_reg->has_live(),
167 "Object must belong to region with live data");
168 break;
169 default:
170 assert(false, "Unhandled liveness verification");
171 }
172 }
173
174 oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
175
176 ShenandoahHeapRegion* fwd_reg = NULL;
177
178 if (obj != fwd) {
179 check(ShenandoahAsserts::_safe_oop, obj, _heap->is_in(fwd),
180 "Forwardee must be in heap");
181 check(ShenandoahAsserts::_safe_oop, obj, !CompressedOops::is_null(fwd),
182 "Forwardee is set");
183 check(ShenandoahAsserts::_safe_oop, obj, is_object_aligned(fwd),
184 "Forwardee must be aligned");
185
186 // Do this before touching fwd->size()
187 Klass* fwd_klass = fwd->klass_or_null();
188 check(ShenandoahAsserts::_safe_oop, obj, fwd_klass != NULL,
189 "Forwardee klass pointer should not be NULL");
190 check(ShenandoahAsserts::_safe_oop, obj, Metaspace::contains(fwd_klass),
191 "Forwardee klass pointer must go to metaspace");
192 check(ShenandoahAsserts::_safe_oop, obj, obj_klass == fwd_klass,
193 "Forwardee klass pointer must go to metaspace");
194
195 fwd_reg = _heap->heap_region_containing(fwd);
196
197 // Verify that forwardee is not in the dead space:
198 check(ShenandoahAsserts::_safe_oop, obj, !fwd_reg->is_humongous(),
199 "Should have no humongous forwardees");
200
201 HeapWord *fwd_addr = cast_from_oop<HeapWord *>(fwd);
202 check(ShenandoahAsserts::_safe_oop, obj, fwd_addr < fwd_reg->top(),
203 "Forwardee start should be within the region");
204 check(ShenandoahAsserts::_safe_oop, obj, (fwd_addr + fwd->forward_safe_size()) <= fwd_reg->top(),
205 "Forwardee end should be within the region");
206
207 oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
208 check(ShenandoahAsserts::_safe_oop, obj, (fwd == fwd2),
209 "Double forwarding");
210 } else {
211 fwd_reg = obj_reg;
212 }
213
214 // ------------ obj and fwd are safe at this point --------------
215
216 switch (_options._verify_marked) {
217 case ShenandoahVerifier::_verify_marked_disable:
218 // skip
219 break;
220 case ShenandoahVerifier::_verify_marked_incomplete:
221 check(ShenandoahAsserts::_safe_all, obj, _heap->marking_context()->is_marked(obj),
222 "Must be marked in incomplete bitmap");
223 break;
224 case ShenandoahVerifier::_verify_marked_complete:
287 }
288
289 /**
290 * Verify object without known interior reference.
291 * Useful when picking up the object at known offset in heap,
292 * but without knowing what objects reference it.
293 * @param obj verified object
294 */
295 void verify_oop_standalone(oop obj) {
296 _interior_loc = NULL;
297 verify_oop(obj);
298 _interior_loc = NULL;
299 }
300
301 /**
302 * Verify oop fields from this object.
303 * @param obj host object for verified fields
304 */
305 void verify_oops_from(oop obj) {
306 _loc = obj;
307 Klass* klass = obj->forward_safe_klass();
308 obj->oop_iterate_backwards(this, klass);
309 _loc = NULL;
310 }
311
312 virtual void do_oop(oop* p) { do_oop_work(p); }
313 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
314 };
315
316 class ShenandoahCalculateRegionStatsClosure : public ShenandoahHeapRegionClosure {
317 private:
318 size_t _used, _committed, _garbage;
319 public:
320 ShenandoahCalculateRegionStatsClosure() : _used(0), _committed(0), _garbage(0) {};
321
322 void heap_region_do(ShenandoahHeapRegion* r) {
323 _used += r->used();
324 _garbage += r->garbage();
325 _committed += r->is_committed() ? ShenandoahHeapRegion::region_size_bytes() : 0;
326 }
327
328 size_t used() { return _used; }
568 HeapWord* addr = tams;
569
570 while (addr < limit) {
571 verify_and_follow(addr, stack, cl, &processed);
572 addr += cast_to_oop(addr)->size();
573 }
574 }
575
576 Atomic::add(&_processed, processed, memory_order_relaxed);
577 }
578
579 void verify_and_follow(HeapWord *addr, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl, size_t *processed) {
580 if (!_bitmap->par_mark(addr)) return;
581
582 // Verify the object itself:
583 oop obj = cast_to_oop(addr);
584 cl.verify_oop_standalone(obj);
585
586 // Verify everything reachable from that object too, hopefully realizing
587 // everything was already marked, and never touching further:
588 if (!is_instance_ref_klass(obj->forward_safe_klass())) {
589 cl.verify_oops_from(obj);
590 (*processed)++;
591 }
592 while (!stack.is_empty()) {
593 ShenandoahVerifierTask task = stack.pop();
594 cl.verify_oops_from(task.obj());
595 (*processed)++;
596 }
597 }
598 };
599
600 class VerifyThreadGCState : public ThreadClosure {
601 private:
602 const char* const _label;
603 char const _expected;
604
605 public:
606 VerifyThreadGCState(const char* label, char expected) : _label(label), _expected(expected) {}
607 void do_thread(Thread* t) {
608 char actual = ShenandoahThreadLocalData::gc_state(t);
|