From 20ff603108a52468dd41020cbf6c0bf669e23861 Mon Sep 17 00:00:00 2001 From: Martin Doerr Date: Tue, 26 Sep 2023 13:33:33 +0000 Subject: [PATCH] 8316735: Print LockStack in hs_err files Reviewed-by: dholmes, mbaesken --- src/hotspot/share/runtime/lockStack.cpp | 12 ++++++++++++ src/hotspot/share/runtime/lockStack.hpp | 5 ++++- src/hotspot/share/utilities/vmError.cpp | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/runtime/lockStack.cpp b/src/hotspot/share/runtime/lockStack.cpp index 5fd5297fd5c..b4a3bf1e8e6 100644 --- a/src/hotspot/share/runtime/lockStack.cpp +++ b/src/hotspot/share/runtime/lockStack.cpp @@ -77,3 +77,15 @@ void LockStack::verify(const char* msg) const { } } #endif + +void LockStack::print_on(outputStream* st) { + for (int i = to_index(_top); (--i) >= 0;) { + st->print("LockStack[%d]: ", i); + oop o = _base[i]; + if (oopDesc::is_oop(o)) { + o->print_on(st); + } else { + st->print_cr("not an oop: " PTR_FORMAT, p2i(o)); + } + } +} diff --git a/src/hotspot/share/runtime/lockStack.hpp b/src/hotspot/share/runtime/lockStack.hpp index ce6a96bcfe6..25ab7a8de05 100644 --- a/src/hotspot/share/runtime/lockStack.hpp +++ b/src/hotspot/share/runtime/lockStack.hpp @@ -30,8 +30,9 @@ #include "utilities/globalDefinitions.hpp" #include "utilities/sizes.hpp" -class Thread; +class JavaThread; class OopClosure; +class outputStream; class LockStack { friend class VMStructs; @@ -91,6 +92,8 @@ public: // GC support inline void oops_do(OopClosure* cl); + // Printing + void print_on(outputStream* st); }; #endif // SHARE_RUNTIME_LOCKSTACK_HPP diff --git a/src/hotspot/share/utilities/vmError.cpp b/src/hotspot/share/utilities/vmError.cpp index e9b4fcb2434..355483b4efe 100644 --- a/src/hotspot/share/utilities/vmError.cpp +++ b/src/hotspot/share/utilities/vmError.cpp @@ -1100,6 +1100,11 @@ void VMError::report(outputStream* st, bool _verbose) { print_stack_location(st, _context, continuation); st->cr(); + STEP_IF("printing lock stack", _verbose && _thread != nullptr && _thread->is_Java_thread() && LockingMode == LM_LIGHTWEIGHT); + st->print_cr("Lock stack of current Java thread (top to bottom):"); + JavaThread::cast(_thread)->lock_stack().print_on(st); + st->cr(); + STEP_IF("printing code blobs if possible", _verbose) const int printed_capacity = max_error_log_print_code; address printed[printed_capacity];