< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp

Print this page

 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 
 27 #include "gc/shenandoah/shenandoahAsserts.hpp"
 28 #include "gc/shenandoah/shenandoahForwarding.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 30 #include "gc/shenandoah/shenandoahHeapRegionSet.inline.hpp"
 31 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
 32 #include "gc/shenandoah/shenandoahUtils.hpp"
 33 #include "memory/resourceArea.hpp"
 34 
 35 void print_raw_memory(ShenandoahMessageBuffer &msg, void* loc) {
 36   // Be extra safe. Only access data that is guaranteed to be safe:
 37   // should be in heap, in known committed region, within that region.
 38 
 39   ShenandoahHeap* heap = ShenandoahHeap::heap();
 40   if (!heap->is_in(loc)) return;
 41 
 42   ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
 43   if (r != nullptr && r->is_committed()) {
 44     address start = MAX2((address) r->bottom(), (address) loc - 32);
 45     address end   = MIN2((address) r->end(),    (address) loc + 128);
 46     if (start >= end) return;
 47 
 48     stringStream ss;
 49     os::print_hex_dump(&ss, start, end, 4);
 50     msg.append("\n");
 51     msg.append("Raw heap memory:\n%s", ss.freeze());
 52   }
 53 }
 54 
 55 void ShenandoahAsserts::print_obj(ShenandoahMessageBuffer& msg, oop obj) {
 56   ShenandoahHeap* heap = ShenandoahHeap::heap();
 57   ShenandoahHeapRegion *r = heap->heap_region_containing(obj);
 58 
 59   ResourceMark rm;
 60   stringStream ss;
 61   r->print_on(&ss);
 62 
 63   stringStream mw_ss;
 64   obj->mark().print_on(&mw_ss);
 65 
 66   ShenandoahMarkingContext* const ctx = heap->marking_context();
 67 
 68   msg.append("  " PTR_FORMAT " - klass " PTR_FORMAT " %s\n", p2i(obj), p2i(obj->klass()), obj->klass()->external_name());
 69   msg.append("    %3s allocated after mark start\n", ctx->allocated_after_mark_start(obj) ? "" : "not");
 70   msg.append("    %3s after update watermark\n",     cast_from_oop<HeapWord*>(obj) >= r->get_update_watermark() ? "" : "not");
 71   msg.append("    %3s marked strong\n",              ctx->is_marked_strong(obj) ? "" : "not");
 72   msg.append("    %3s marked weak\n",                ctx->is_marked_weak(obj) ? "" : "not");
 73   msg.append("    %3s in collection set\n",          heap->in_collection_set(obj) ? "" : "not");



 74   msg.append("  mark:%s\n", mw_ss.freeze());
 75   msg.append("  region: %s", ss.freeze());
 76 }
 77 
 78 void ShenandoahAsserts::print_non_obj(ShenandoahMessageBuffer& msg, void* loc) {
 79   ShenandoahHeap* heap = ShenandoahHeap::heap();
 80   if (heap->is_in(loc)) {
 81     msg.append("  inside Java heap\n");
 82     ShenandoahHeapRegion *r = heap->heap_region_containing(loc);
 83     stringStream ss;
 84     r->print_on(&ss);
 85 
 86     msg.append("    %3s in collection set\n",    heap->in_collection_set_loc(loc) ? "" : "not");
 87     msg.append("  region: %s", ss.freeze());
 88   } else {
 89     msg.append("  outside of Java heap\n");
 90     stringStream ss;
 91     os::print_location(&ss, (intptr_t) loc, false);
 92     msg.append("  %s", ss.freeze());
 93   }
 94 }
 95 
 96 void ShenandoahAsserts::print_obj_safe(ShenandoahMessageBuffer& msg, void* loc) {
 97   ShenandoahHeap* heap = ShenandoahHeap::heap();
 98   msg.append("  " PTR_FORMAT " - safe print, no details\n", p2i(loc));
 99   if (heap->is_in(loc)) {
100     ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
101     if (r != nullptr) {
102       stringStream ss;
103       r->print_on(&ss);
104       msg.append("  region: %s", ss.freeze());
105       print_raw_memory(msg, loc);
106     }
107   }
108 }
109 
110 void ShenandoahAsserts::print_failure(SafeLevel level, oop obj, void* interior_loc, oop loc,
111                                        const char* phase, const char* label,
112                                        const char* file, int line) {
113   ShenandoahHeap* heap = ShenandoahHeap::heap();
114   ResourceMark rm;
115 
116   bool loc_in_heap = (loc != nullptr && heap->is_in(loc));
117 
118   ShenandoahMessageBuffer msg("%s; %s\n\n", phase, label);
119 
120   msg.append("Referenced from:\n");
121   if (interior_loc != nullptr) {
122     msg.append("  interior location: " PTR_FORMAT "\n", p2i(interior_loc));
123     if (loc_in_heap) {
124       print_obj(msg, loc);
125     } else {
126       print_non_obj(msg, interior_loc);
127     }
128   } else {
129     msg.append("  no interior location recorded (probably a plain heap scan, or detached oop)\n");
130   }
131   msg.append("\n");
132 
133   msg.append("Object:\n");
134   if (level >= _safe_oop) {
135     print_obj(msg, obj);
136   } else {

149       }
150     } else {
151       msg.append("  (the object itself)");
152     }
153     msg.append("\n");
154   }
155 
156   if (level >= _safe_oop_fwd) {
157     oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
158     oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
159     if (fwd != fwd2) {
160       msg.append("Second forwardee:\n");
161       print_obj_safe(msg, fwd2);
162       msg.append("\n");
163     }
164   }
165 
166   report_vm_error(file, line, msg.buffer());
167 }
168 
169 void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *file, int line) {
170   ShenandoahHeap* heap = ShenandoahHeap::heap();
171 
172   if (!heap->is_in(obj)) {
173     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_heap failed",
174                   "oop must point to a heap address",
175                   file, line);
176   }
177 }
178 
179 void ShenandoahAsserts::assert_in_heap_or_null(void* interior_loc, oop obj, const char *file, int line) {
180   ShenandoahHeap* heap = ShenandoahHeap::heap();
181 
182   if (obj != nullptr && !heap->is_in(obj)) {
183     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_heap_or_null failed",
184                   "oop must point to a heap address",
185                   file, line);
186   }
187 }
188 
189 void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
190   ShenandoahHeap* heap = ShenandoahHeap::heap();
191 
192   // Step 1. Check that obj is correct.
193   // After this step, it is safe to call heap_region_containing().
194   if (!heap->is_in(obj)) {
195     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
196                   "oop must point to a heap address",
197                   file, line);
198   }
199 
200   Klass* obj_klass = obj->klass_or_null();
201   if (obj_klass == nullptr) {
202     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
203                   "Object klass pointer should not be null",
204                   file,line);
205   }
206 
207   if (!Metaspace::contains(obj_klass)) {
208     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
209                   "Object klass pointer must go to metaspace",
210                   file,line);
211   }
212 






213   oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
214 
215   if (obj != fwd) {
216     // When Full GC moves the objects, we cannot trust fwdptrs. If we got here, it means something
217     // tries fwdptr manipulation when Full GC is running. The only exception is using the fwdptr
218     // that still points to the object itself.
219     if (heap->is_full_gc_move_in_progress()) {
220       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
221                     "Non-trivial forwarding pointer during Full GC moves, probable bug.",
222                     file, line);
223     }
224 
225     // Step 2. Check that forwardee is correct
226     if (!heap->is_in(fwd)) {
227       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
228                     "Forwardee must point to a heap address",
229                     file, line);
230     }
231 
232     if (obj_klass != fwd->klass()) {
233       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
234                     "Forwardee klass disagrees with object class",
235                     file, line);
236     }
237 
238     // Step 3. Check that forwardee points to correct region






239     if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
240       print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
241                     "Non-trivial forwardee should in another region",
242                     file, line);
243     }
244 
245     // Step 4. Check for multiple forwardings
246     oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
247     if (fwd != fwd2) {
248       print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
249                     "Multiple forwardings",
250                     file, line);
251     }
252   }



















253 }
254 
255 void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
256   assert_correct(interior_loc, obj, file, line);
257 
258   ShenandoahHeap* heap = ShenandoahHeap::heap();
259   ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
260   if (!r->is_active()) {
261     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
262                   "Object must reside in active region",
263                   file, line);
264   }
265 
266   size_t alloc_size = obj->size();
267   if (alloc_size > ShenandoahHeapRegion::humongous_threshold_words()) {
268     size_t idx = r->index();
269     size_t num_regions = ShenandoahHeapRegion::required_regions(alloc_size * HeapWordSize);
270     for (size_t i = idx; i < idx + num_regions; i++) {
271       ShenandoahHeapRegion* chain_reg = heap->get_region(i);
272       if (i == idx && !chain_reg->is_humongous_start()) {
273         print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
274                       "Object must reside in humongous start",
275                       file, line);
276       }
277       if (i != idx && !chain_reg->is_humongous_continuation()) {
278         print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
279                       "Humongous continuation should be of proper size",
280                       file, line);
281       }
282     }
283   }
284 }
285 
286 void ShenandoahAsserts::assert_forwarded(void* interior_loc, oop obj, const char* file, int line) {
287   assert_correct(interior_loc, obj, file, line);

368                   file, line);
369   }
370 }
371 
372 void ShenandoahAsserts::print_rp_failure(const char *label, BoolObjectClosure* actual,
373                                          const char *file, int line) {
374   ShenandoahMessageBuffer msg("%s\n", label);
375   msg.append(" Actual:                  " PTR_FORMAT "\n", p2i(actual));
376   report_vm_error(file, line, msg.buffer());
377 }
378 
379 void ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(Mutex* lock, const char* file, int line) {
380   if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
381     return;
382   }
383 
384   if (lock->owned_by_self()) {
385     return;
386   }
387 
388   ShenandoahMessageBuffer msg("Must ba at a Shenandoah safepoint or held %s lock", lock->name());
389   report_vm_error(file, line, msg.buffer());
390 }
391 
392 void ShenandoahAsserts::assert_heaplocked(const char* file, int line) {
393   ShenandoahHeap* heap = ShenandoahHeap::heap();
394 
395   if (heap->lock()->owned_by_self()) {
396     return;
397   }
398 
399   ShenandoahMessageBuffer msg("Heap lock must be owned by current thread");
400   report_vm_error(file, line, msg.buffer());
401 }
402 
403 void ShenandoahAsserts::assert_not_heaplocked(const char* file, int line) {
404   ShenandoahHeap* heap = ShenandoahHeap::heap();
405 
406   if (!heap->lock()->owned_by_self()) {
407     return;
408   }
409 
410   ShenandoahMessageBuffer msg("Heap lock must not be owned by current thread");
411   report_vm_error(file, line, msg.buffer());
412 }
413 
414 void ShenandoahAsserts::assert_heaplocked_or_safepoint(const char* file, int line) {
415   ShenandoahHeap* heap = ShenandoahHeap::heap();
416 
417   if (heap->lock()->owned_by_self()) {
418     return;
419   }
420 
421   if (ShenandoahSafepoint::is_at_shenandoah_safepoint() && Thread::current()->is_VM_thread()) {
422     return;
423   }
424 
425   ShenandoahMessageBuffer msg("Heap lock must be owned by current thread, or be at safepoint");
426   report_vm_error(file, line, msg.buffer());
427 }














































 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 
 27 #include "gc/shenandoah/shenandoahAsserts.hpp"
 28 #include "gc/shenandoah/shenandoahForwarding.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 30 #include "gc/shenandoah/shenandoahHeapRegionSet.inline.hpp"
 31 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
 32 #include "gc/shenandoah/shenandoahUtils.hpp"
 33 #include "memory/resourceArea.hpp"
 34 
 35 void print_raw_memory(ShenandoahMessageBuffer &msg, void* loc) {
 36   // Be extra safe. Only access data that is guaranteed to be safe:
 37   // should be in heap, in known committed region, within that region.
 38 
 39   ShenandoahHeap* heap = ShenandoahHeap::heap();
 40   if (!heap->is_in_reserved(loc)) return;
 41 
 42   ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
 43   if (r != nullptr && r->is_committed()) {
 44     address start = MAX2((address) r->bottom(), (address) loc - 32);
 45     address end   = MIN2((address) r->end(),    (address) loc + 128);
 46     if (start >= end) return;
 47 
 48     stringStream ss;
 49     os::print_hex_dump(&ss, start, end, 4);
 50     msg.append("\n");
 51     msg.append("Raw heap memory:\n%s", ss.freeze());
 52   }
 53 }
 54 
 55 void ShenandoahAsserts::print_obj(ShenandoahMessageBuffer& msg, oop obj) {
 56   ShenandoahHeap* heap = ShenandoahHeap::heap();
 57   ShenandoahHeapRegion *r = heap->heap_region_containing(obj);
 58 
 59   ResourceMark rm;
 60   stringStream ss;
 61   r->print_on(&ss);
 62 
 63   stringStream mw_ss;
 64   obj->mark().print_on(&mw_ss);
 65 
 66   ShenandoahMarkingContext* const ctx = heap->marking_context();
 67 
 68   msg.append("  " PTR_FORMAT " - klass " PTR_FORMAT " %s\n", p2i(obj), p2i(obj->klass()), obj->klass()->external_name());
 69   msg.append("    %3s allocated after mark start\n", ctx->allocated_after_mark_start(obj) ? "" : "not");
 70   msg.append("    %3s after update watermark\n",     cast_from_oop<HeapWord*>(obj) >= r->get_update_watermark() ? "" : "not");
 71   msg.append("    %3s marked strong\n",              ctx->is_marked_strong(obj) ? "" : "not");
 72   msg.append("    %3s marked weak\n",                ctx->is_marked_weak(obj) ? "" : "not");
 73   msg.append("    %3s in collection set\n",          heap->in_collection_set(obj) ? "" : "not");
 74   if (heap->mode()->is_generational() && !obj->is_forwarded()) {
 75     msg.append("  age: %d\n", obj->age());
 76   }
 77   msg.append("  mark:%s\n", mw_ss.freeze());
 78   msg.append("  region: %s", ss.freeze());
 79 }
 80 
 81 void ShenandoahAsserts::print_non_obj(ShenandoahMessageBuffer& msg, void* loc) {
 82   ShenandoahHeap* heap = ShenandoahHeap::heap();
 83   if (heap->is_in_reserved(loc)) {
 84     msg.append("  inside Java heap\n");
 85     ShenandoahHeapRegion *r = heap->heap_region_containing(loc);
 86     stringStream ss;
 87     r->print_on(&ss);
 88 
 89     msg.append("    %3s in collection set\n",    heap->in_collection_set_loc(loc) ? "" : "not");
 90     msg.append("  region: %s", ss.freeze());
 91   } else {
 92     msg.append("  outside of Java heap\n");
 93     stringStream ss;
 94     os::print_location(&ss, (intptr_t) loc, false);
 95     msg.append("  %s", ss.freeze());
 96   }
 97 }
 98 
 99 void ShenandoahAsserts::print_obj_safe(ShenandoahMessageBuffer& msg, void* loc) {
100   ShenandoahHeap* heap = ShenandoahHeap::heap();
101   msg.append("  " PTR_FORMAT " - safe print, no details\n", p2i(loc));
102   if (heap->is_in_reserved(loc)) {
103     ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
104     if (r != nullptr) {
105       stringStream ss;
106       r->print_on(&ss);
107       msg.append("  region: %s", ss.freeze());
108       print_raw_memory(msg, loc);
109     }
110   }
111 }
112 
113 void ShenandoahAsserts::print_failure(SafeLevel level, oop obj, void* interior_loc, oop loc,
114                                        const char* phase, const char* label,
115                                        const char* file, int line) {
116   ShenandoahHeap* heap = ShenandoahHeap::heap();
117   ResourceMark rm;
118 
119   bool loc_in_heap = (loc != nullptr && heap->is_in_reserved(loc));
120 
121   ShenandoahMessageBuffer msg("%s; %s\n\n", phase, label);
122 
123   msg.append("Referenced from:\n");
124   if (interior_loc != nullptr) {
125     msg.append("  interior location: " PTR_FORMAT "\n", p2i(interior_loc));
126     if (loc_in_heap) {
127       print_obj(msg, loc);
128     } else {
129       print_non_obj(msg, interior_loc);
130     }
131   } else {
132     msg.append("  no interior location recorded (probably a plain heap scan, or detached oop)\n");
133   }
134   msg.append("\n");
135 
136   msg.append("Object:\n");
137   if (level >= _safe_oop) {
138     print_obj(msg, obj);
139   } else {

152       }
153     } else {
154       msg.append("  (the object itself)");
155     }
156     msg.append("\n");
157   }
158 
159   if (level >= _safe_oop_fwd) {
160     oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
161     oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
162     if (fwd != fwd2) {
163       msg.append("Second forwardee:\n");
164       print_obj_safe(msg, fwd2);
165       msg.append("\n");
166     }
167   }
168 
169   report_vm_error(file, line, msg.buffer());
170 }
171 
172 void ShenandoahAsserts::assert_in_heap_bounds(void* interior_loc, oop obj, const char *file, int line) {
173   ShenandoahHeap* heap = ShenandoahHeap::heap();
174 
175   if (!heap->is_in_reserved(obj)) {
176     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_heap_bounds failed",
177                   "oop must be in heap bounds",
178                   file, line);
179   }
180 }
181 
182 void ShenandoahAsserts::assert_in_heap_bounds_or_null(void* interior_loc, oop obj, const char *file, int line) {
183   ShenandoahHeap* heap = ShenandoahHeap::heap();
184 
185   if (obj != nullptr && !heap->is_in_reserved(obj)) {
186     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_heap_bounds_or_null failed",
187                   "oop must be in heap bounds",
188                   file, line);
189   }
190 }
191 
192 void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
193   ShenandoahHeap* heap = ShenandoahHeap::heap();
194 
195   // Step 1. Check that obj is correct.
196   // After this step, it is safe to call heap_region_containing().
197   if (!heap->is_in_reserved(obj)) {
198     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
199                   "oop must be in heap bounds",
200                   file, line);
201   }
202 
203   Klass* obj_klass = obj->klass_or_null();
204   if (obj_klass == nullptr) {
205     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
206                   "Object klass pointer should not be null",
207                   file,line);
208   }
209 
210   if (!Metaspace::contains(obj_klass)) {
211     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
212                   "Object klass pointer must go to metaspace",
213                   file,line);
214   }
215 
216   if (!heap->is_in(obj)) {
217     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
218                   "Object should be in active region area",
219                   file, line);
220   }
221 
222   oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
223 
224   if (obj != fwd) {
225     // When Full GC moves the objects, we cannot trust fwdptrs. If we got here, it means something
226     // tries fwdptr manipulation when Full GC is running. The only exception is using the fwdptr
227     // that still points to the object itself.
228     if (heap->is_full_gc_move_in_progress()) {
229       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
230                     "Non-trivial forwarding pointer during Full GC moves, probable bug.",
231                     file, line);
232     }
233 
234     // Step 2. Check that forwardee is correct
235     if (!heap->is_in_reserved(fwd)) {
236       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
237                     "Forwardee must be in heap bounds",
238                     file, line);
239     }
240 
241     if (obj_klass != fwd->klass()) {
242       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
243                     "Forwardee klass disagrees with object class",
244                     file, line);
245     }
246 
247     // Step 3. Check that forwardee points to correct region
248     if (!heap->is_in(fwd)) {
249       print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
250                     "Forwardee should be in active region area",
251                     file, line);
252     }
253 
254     if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
255       print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
256                     "Non-trivial forwardee should be in another region",
257                     file, line);
258     }
259 
260     // Step 4. Check for multiple forwardings
261     oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
262     if (fwd != fwd2) {
263       print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
264                     "Multiple forwardings",
265                     file, line);
266     }
267   }
268 
269   // Do additional checks for special objects: their fields can hold metadata as well.
270   // We want to check class loading/unloading did not corrupt them.
271 
272   if (obj_klass == vmClasses::Class_klass()) {
273     Metadata* klass = obj->metadata_field(java_lang_Class::klass_offset());
274     if (klass != nullptr && !Metaspace::contains(klass)) {
275       print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
276                     "Instance class mirror should point to Metaspace",
277                     file, line);
278     }
279 
280     Metadata* array_klass = obj->metadata_field(java_lang_Class::array_klass_offset());
281     if (array_klass != nullptr && !Metaspace::contains(array_klass)) {
282       print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
283                     "Array class mirror should point to Metaspace",
284                     file, line);
285     }
286   }
287 }
288 
289 void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
290   assert_correct(interior_loc, obj, file, line);
291 
292   ShenandoahHeap* heap = ShenandoahHeap::heap();
293   ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
294   if (!r->is_active()) {
295     print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
296                   "Object must reside in active region",
297                   file, line);
298   }
299 
300   size_t alloc_size = obj->size();
301   if (ShenandoahHeapRegion::requires_humongous(alloc_size)) {
302     size_t idx = r->index();
303     size_t num_regions = ShenandoahHeapRegion::required_regions(alloc_size * HeapWordSize);
304     for (size_t i = idx; i < idx + num_regions; i++) {
305       ShenandoahHeapRegion* chain_reg = heap->get_region(i);
306       if (i == idx && !chain_reg->is_humongous_start()) {
307         print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
308                       "Object must reside in humongous start",
309                       file, line);
310       }
311       if (i != idx && !chain_reg->is_humongous_continuation()) {
312         print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
313                       "Humongous continuation should be of proper size",
314                       file, line);
315       }
316     }
317   }
318 }
319 
320 void ShenandoahAsserts::assert_forwarded(void* interior_loc, oop obj, const char* file, int line) {
321   assert_correct(interior_loc, obj, file, line);

402                   file, line);
403   }
404 }
405 
406 void ShenandoahAsserts::print_rp_failure(const char *label, BoolObjectClosure* actual,
407                                          const char *file, int line) {
408   ShenandoahMessageBuffer msg("%s\n", label);
409   msg.append(" Actual:                  " PTR_FORMAT "\n", p2i(actual));
410   report_vm_error(file, line, msg.buffer());
411 }
412 
413 void ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(Mutex* lock, const char* file, int line) {
414   if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
415     return;
416   }
417 
418   if (lock->owned_by_self()) {
419     return;
420   }
421 
422   ShenandoahMessageBuffer msg("Must be at a Shenandoah safepoint or held %s lock", lock->name());
423   report_vm_error(file, line, msg.buffer());
424 }
425 
426 void ShenandoahAsserts::assert_heaplocked(const char* file, int line) {
427   ShenandoahHeap* heap = ShenandoahHeap::heap();
428 
429   if (heap->lock()->owned_by_self()) {
430     return;
431   }
432 
433   ShenandoahMessageBuffer msg("Heap lock must be owned by current thread");
434   report_vm_error(file, line, msg.buffer());
435 }
436 
437 void ShenandoahAsserts::assert_not_heaplocked(const char* file, int line) {
438   ShenandoahHeap* heap = ShenandoahHeap::heap();
439 
440   if (!heap->lock()->owned_by_self()) {
441     return;
442   }
443 
444   ShenandoahMessageBuffer msg("Heap lock must not be owned by current thread");
445   report_vm_error(file, line, msg.buffer());
446 }
447 
448 void ShenandoahAsserts::assert_heaplocked_or_safepoint(const char* file, int line) {
449   ShenandoahHeap* heap = ShenandoahHeap::heap();
450 
451   if (heap->lock()->owned_by_self()) {
452     return;
453   }
454 
455   if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
456     return;
457   }
458 
459   ShenandoahMessageBuffer msg("Heap lock must be owned by current thread, or be at safepoint");
460   report_vm_error(file, line, msg.buffer());
461 }
462 
463 void ShenandoahAsserts::assert_generational(const char* file, int line) {
464   if (ShenandoahHeap::heap()->mode()->is_generational()) {
465     return;
466   }
467 
468   ShenandoahMessageBuffer msg("Must be in generational mode");
469   report_vm_error(file, line, msg.buffer());
470 }
471 
472 void ShenandoahAsserts::assert_control_or_vm_thread_at_safepoint(bool at_safepoint, const char* file, int line) {
473   Thread* thr = Thread::current();
474   if (thr == ShenandoahHeap::heap()->control_thread()) {
475     return;
476   }
477   if (thr->is_VM_thread()) {
478     if (!at_safepoint) {
479       return;
480     } else if (SafepointSynchronize::is_at_safepoint()) {
481       return;
482     }
483   }
484 
485   ShenandoahMessageBuffer msg("Must be either control thread, or vm thread");
486   if (at_safepoint) {
487     msg.append(" at a safepoint");
488   }
489   report_vm_error(file, line, msg.buffer());
490 }
491 
492 void ShenandoahAsserts::assert_generations_reconciled(const char* file, int line) {
493   if (!SafepointSynchronize::is_at_safepoint()) {
494     return;
495   }
496 
497   ShenandoahHeap* heap = ShenandoahHeap::heap();
498   ShenandoahGeneration* ggen = heap->gc_generation();
499   ShenandoahGeneration* agen = heap->active_generation();
500   if (agen == ggen) {
501     return;
502   }
503 
504   ShenandoahMessageBuffer msg("Active(%d) & GC(%d) Generations aren't reconciled", agen->type(), ggen->type());
505   report_vm_error(file, line, msg.buffer());
506 }
< prev index next >