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 }
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 }
371 file, line);
372 }
373 }
374
375 void ShenandoahAsserts::print_rp_failure(const char *label, BoolObjectClosure* actual,
376 const char *file, int line) {
377 ShenandoahMessageBuffer msg("%s\n", label);
378 msg.append(" Actual: " PTR_FORMAT "\n", p2i(actual));
379 report_vm_error(file, line, msg.buffer());
380 }
381
382 void ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(Mutex* lock, const char* file, int line) {
383 if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
384 return;
385 }
386
387 if (lock->owned_by_self()) {
388 return;
389 }
390
391 ShenandoahMessageBuffer msg("Must be at a Shenandoah safepoint or held %s lock", lock->name());
392 report_vm_error(file, line, msg.buffer());
393 }
394
395 void ShenandoahAsserts::assert_heaplocked(const char* file, int line) {
396 ShenandoahHeap* heap = ShenandoahHeap::heap();
397
398 if (heap->lock()->owned_by_self()) {
399 return;
400 }
401
402 ShenandoahMessageBuffer msg("Heap lock must be owned by current thread");
403 report_vm_error(file, line, msg.buffer());
404 }
405
406 void ShenandoahAsserts::assert_not_heaplocked(const char* file, int line) {
407 ShenandoahHeap* heap = ShenandoahHeap::heap();
408
409 if (!heap->lock()->owned_by_self()) {
410 return;
411 }
412
413 ShenandoahMessageBuffer msg("Heap lock must not be owned by current thread");
414 report_vm_error(file, line, msg.buffer());
415 }
416
417 void ShenandoahAsserts::assert_heaplocked_or_safepoint(const char* file, int line) {
418 ShenandoahHeap* heap = ShenandoahHeap::heap();
419
420 if (heap->lock()->owned_by_self()) {
421 return;
422 }
423
424 if (ShenandoahSafepoint::is_at_shenandoah_safepoint() && Thread::current()->is_VM_thread()) {
425 return;
426 }
427
428 ShenandoahMessageBuffer msg("Heap lock must be owned by current thread, or be at safepoint");
429 report_vm_error(file, line, msg.buffer());
430 }
431
432 // Unlike assert_heaplocked_or_safepoint(), this does not require current thread in safepoint to be a VM thread
433 // TODO: This should be more aptly named. Nothing in this method checks we are actually in Full GC.
434 void ShenandoahAsserts::assert_heaplocked_or_fullgc_safepoint(const char* file, int line) {
435 ShenandoahHeap* heap = ShenandoahHeap::heap();
436
437 if (heap->lock()->owned_by_self()) {
438 return;
439 }
440
441 if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
442 return;
443 }
444
445 ShenandoahMessageBuffer msg("Heap lock must be owned by current thread, or be at safepoint");
446 report_vm_error(file, line, msg.buffer());
447 }
|