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