From f0b251d76078e8d5b47e967b0449c4cbdcb5a005 Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Thu, 7 Nov 2024 12:10:50 +0000 Subject: [PATCH] 8343531: Improve print_location for invalid heap pointers Reviewed-by: shade, tschatzl, ayang --- src/hotspot/share/gc/shared/locationPrinter.inline.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/gc/shared/locationPrinter.inline.hpp b/src/hotspot/share/gc/shared/locationPrinter.inline.hpp index d368aa1c6c6..ae873d52cb5 100644 --- a/src/hotspot/share/gc/shared/locationPrinter.inline.hpp +++ b/src/hotspot/share/gc/shared/locationPrinter.inline.hpp @@ -37,7 +37,7 @@ oop BlockLocationPrinter::base_oop_or_null(void* addr) { return cast_to_oop(addr); } - // Try to find addr using block_start. + // Try to find addr using block_start (not implemented for all GCs/generations). HeapWord* p = CollectedHeapT::heap()->block_start(addr); if (p != nullptr && CollectedHeapT::heap()->block_is_obj(p)) { if (!is_valid_obj(p)) { @@ -52,7 +52,9 @@ oop BlockLocationPrinter::base_oop_or_null(void* addr) { template bool BlockLocationPrinter::print_location(outputStream* st, void* addr) { // Check if addr points into Java heap. - if (CollectedHeapT::heap()->is_in(addr)) { + bool in_heap = CollectedHeapT::heap()->is_in(addr); + if (in_heap) { + // base_oop_or_null() might be unimplemented and return NULL for some GCs/generations oop o = base_oop_or_null(addr); if (o != nullptr) { if ((void*)o == addr) { @@ -83,6 +85,10 @@ bool BlockLocationPrinter::print_location(outputStream* st, void } #endif + if (in_heap) { + st->print_cr(PTR_FORMAT " is an unknown heap location", p2i(addr)); + return true; + } return false; }