8343531: Improve print_location for invalid heap pointers

Reviewed-by: shade, tschatzl, ayang
This commit is contained in:
Volker Simonis 2024-11-07 12:10:50 +00:00
parent 4244682309
commit f0b251d760

View File

@ -37,7 +37,7 @@ oop BlockLocationPrinter<CollectedHeapT>::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<CollectedHeapT>::base_oop_or_null(void* addr) {
template <typename CollectedHeapT>
bool BlockLocationPrinter<CollectedHeapT>::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<CollectedHeapT>::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;
}