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 }
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 }
|
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(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 }
236 print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
237 "Forwardee klass disagrees with object class",
238 file, line);
239 }
240
241 // Step 3. Check that forwardee points to correct region
242 if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
243 print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
244 "Non-trivial forwardee should in another region",
245 file, line);
246 }
247
248 // Step 4. Check for multiple forwardings
249 oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
250 if (fwd != fwd2) {
251 print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
252 "Multiple forwardings",
253 file, line);
254 }
255 }
256
257 // Do additional checks for special objects: their fields can hold metadata as well.
258 // We want to check class loading/unloading did not corrupt them.
259
260 if (obj_klass == vmClasses::Class_klass()) {
261 Metadata* klass = obj->metadata_field(java_lang_Class::klass_offset());
262 if (klass != nullptr && !Metaspace::contains(klass)) {
263 print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
264 "Instance class mirror should point to Metaspace",
265 file, line);
266 }
267
268 Metadata* array_klass = obj->metadata_field(java_lang_Class::array_klass_offset());
269 if (array_klass != nullptr && !Metaspace::contains(array_klass)) {
270 print_failure(_safe_all, obj, interior_loc, nullptr, "Shenandoah assert_correct failed",
271 "Array class mirror should point to Metaspace",
272 file, line);
273 }
274 }
275 }
276
277 void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
278 assert_correct(interior_loc, obj, file, line);
279
280 ShenandoahHeap* heap = ShenandoahHeap::heap();
281 ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
282 if (!r->is_active()) {
283 print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
284 "Object must reside in active region",
285 file, line);
286 }
287
288 size_t alloc_size = obj->size();
289 if (ShenandoahHeapRegion::requires_humongous(alloc_size)) {
290 size_t idx = r->index();
291 size_t num_regions = ShenandoahHeapRegion::required_regions(alloc_size * HeapWordSize);
292 for (size_t i = idx; i < idx + num_regions; i++) {
293 ShenandoahHeapRegion* chain_reg = heap->get_region(i);
294 if (i == idx && !chain_reg->is_humongous_start()) {
295 print_failure(_safe_unknown, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
296 "Object must reside in humongous start",
297 file, line);
298 }
299 if (i != idx && !chain_reg->is_humongous_continuation()) {
300 print_failure(_safe_oop, obj, interior_loc, nullptr, "Shenandoah assert_in_correct_region failed",
301 "Humongous continuation should be of proper size",
302 file, line);
303 }
304 }
305 }
306 }
307
308 void ShenandoahAsserts::assert_forwarded(void* interior_loc, oop obj, const char* file, int line) {
309 assert_correct(interior_loc, obj, file, line);
390 file, line);
391 }
392 }
393
394 void ShenandoahAsserts::print_rp_failure(const char *label, BoolObjectClosure* actual,
395 const char *file, int line) {
396 ShenandoahMessageBuffer msg("%s\n", label);
397 msg.append(" Actual: " PTR_FORMAT "\n", p2i(actual));
398 report_vm_error(file, line, msg.buffer());
399 }
400
401 void ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(Mutex* lock, const char* file, int line) {
402 if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
403 return;
404 }
405
406 if (lock->owned_by_self()) {
407 return;
408 }
409
410 ShenandoahMessageBuffer msg("Must be at a Shenandoah safepoint or held %s lock", lock->name());
411 report_vm_error(file, line, msg.buffer());
412 }
413
414 void ShenandoahAsserts::assert_heaplocked(const char* file, int line) {
415 ShenandoahHeap* heap = ShenandoahHeap::heap();
416
417 if (heap->lock()->owned_by_self()) {
418 return;
419 }
420
421 ShenandoahMessageBuffer msg("Heap lock must be owned by current thread");
422 report_vm_error(file, line, msg.buffer());
423 }
424
425 void ShenandoahAsserts::assert_not_heaplocked(const char* file, int line) {
426 ShenandoahHeap* heap = ShenandoahHeap::heap();
427
428 if (!heap->lock()->owned_by_self()) {
429 return;
430 }
431
432 ShenandoahMessageBuffer msg("Heap lock must not be owned by current thread");
433 report_vm_error(file, line, msg.buffer());
434 }
435
436 void ShenandoahAsserts::assert_heaplocked_or_safepoint(const char* file, int line) {
437 ShenandoahHeap* heap = ShenandoahHeap::heap();
438
439 if (heap->lock()->owned_by_self()) {
440 return;
441 }
442
443 if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
444 return;
445 }
446
447 ShenandoahMessageBuffer msg("Heap lock must be owned by current thread, or be at safepoint");
448 report_vm_error(file, line, msg.buffer());
449 }
450
451 void ShenandoahAsserts::assert_generational(const char* file, int line) {
452 if (ShenandoahHeap::heap()->mode()->is_generational()) {
453 return;
454 }
455
456 ShenandoahMessageBuffer msg("Must be in generational mode");
457 report_vm_error(file, line, msg.buffer());
458 }
459
460 void ShenandoahAsserts::assert_control_or_vm_thread_at_safepoint(bool at_safepoint, const char* file, int line) {
461 Thread* thr = Thread::current();
462 if (thr == ShenandoahHeap::heap()->control_thread()) {
463 return;
464 }
465 if (thr->is_VM_thread()) {
466 if (!at_safepoint) {
467 return;
468 } else if (SafepointSynchronize::is_at_safepoint()) {
469 return;
470 }
471 }
472
473 ShenandoahMessageBuffer msg("Must be either control thread, or vm thread");
474 if (at_safepoint) {
475 msg.append(" at a safepoint");
476 }
477 report_vm_error(file, line, msg.buffer());
478 }
479
480 void ShenandoahAsserts::assert_generations_reconciled(const char* file, int line) {
481 if (!SafepointSynchronize::is_at_safepoint()) {
482 return;
483 }
484
485 ShenandoahHeap* heap = ShenandoahHeap::heap();
486 ShenandoahGeneration* ggen = heap->gc_generation();
487 ShenandoahGeneration* agen = heap->active_generation();
488 if (agen == ggen) {
489 return;
490 }
491
492 ShenandoahMessageBuffer msg("Active(%d) & GC(%d) Generations aren't reconciled", agen->type(), ggen->type());
493 report_vm_error(file, line, msg.buffer());
494 }
|