8293402: hs-err file printer should reattempt stack trace printing if it fails

Reviewed-by: chagedorn, dsamersoff
This commit is contained in:
Thomas Stuefe 2022-09-14 16:49:06 +00:00
parent 211fab8d36
commit 95c7c556a3
3 changed files with 21 additions and 7 deletions
src/hotspot/share/utilities

@ -720,7 +720,7 @@ extern "C" JNIEXPORT void pns(void* sp, void* fp, void* pc) { // print native st
Thread* t = Thread::current_or_null();
// Call generic frame constructor (certain arguments may be ignored)
frame fr(sp, fp, pc);
VMError::print_native_stack(tty, fr, t, buf, sizeof(buf));
VMError::print_native_stack(tty, fr, t, false, buf, sizeof(buf));
}
//
@ -740,7 +740,7 @@ extern "C" JNIEXPORT void pns2() { // print native stack
} else {
Thread* t = Thread::current_or_null();
frame fr = os::current_frame();
VMError::print_native_stack(tty, fr, t, buf, sizeof(buf));
VMError::print_native_stack(tty, fr, t, false, buf, sizeof(buf));
}
}
#endif

@ -347,7 +347,7 @@ static frame next_frame(frame fr, Thread* t) {
}
}
void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size) {
void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, bool print_source_info, char* buf, int buf_size) {
// see if it's a valid frame
if (fr.pc()) {
@ -362,7 +362,8 @@ void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, char* bu
if (count == 1 && _lineno != 0) {
// We have source information of the first frame for internal errors. There is no need to parse it from the symbols.
st->print(" (%s:%d)", get_filename_only(), _lineno);
} else if (Decoder::get_source_info(fr.pc(), filename, sizeof(filename), &line_no, count != 1)) {
} else if (print_source_info &&
Decoder::get_source_info(fr.pc(), filename, sizeof(filename), &line_no, count != 1)) {
st->print(" (%s:%d)", filename, line_no);
}
}
@ -535,6 +536,8 @@ void VMError::report(outputStream* st, bool _verbose) {
// don't allocate large buffer on stack
static char buf[O_BUFLEN];
static bool print_native_stack_succeeded = false;
BEGIN
STEP("printing fatal error message")
@ -832,7 +835,7 @@ void VMError::report(outputStream* st, bool _verbose) {
st->cr();
}
STEP("printing native stack")
STEP("printing native stack (with source info)")
if (_verbose) {
if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) {
@ -842,9 +845,20 @@ void VMError::report(outputStream* st, bool _verbose) {
frame fr = _context ? os::fetch_frame_from_context(_context)
: os::current_frame();
print_native_stack(st, fr, _thread, buf, sizeof(buf));
print_native_stack(st, fr, _thread, true, buf, sizeof(buf));
_print_native_stack_used = true;
}
print_native_stack_succeeded = true;
}
STEP("retry printing native stack (no source info)")
if (_verbose && !print_native_stack_succeeded) {
st->cr();
st->print_cr("Retrying call stack printing without source information...");
frame fr = _context ? os::fetch_frame_from_context(_context) : os::current_frame();
print_native_stack(st, fr, _thread, false, buf, sizeof(buf));
_print_native_stack_used = true;
}
STEP("printing Java stack")

@ -105,7 +105,7 @@ class VMError : public AllStatic {
// public for use by the internal non-product debugger.
NOT_PRODUCT(public:)
static void print_native_stack(outputStream* st, frame fr, Thread* t,
static void print_native_stack(outputStream* st, frame fr, Thread* t, bool print_source_info,
char* buf, int buf_size);
NOT_PRODUCT(private:)