Skip to content

Commit 95c7c55

Browse files
committed
8293402: hs-err file printer should reattempt stack trace printing if it fails
Reviewed-by: chagedorn, dsamersoff
1 parent 211fab8 commit 95c7c55

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/hotspot/share/utilities/debug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ extern "C" JNIEXPORT void pns(void* sp, void* fp, void* pc) { // print native st
720720
Thread* t = Thread::current_or_null();
721721
// Call generic frame constructor (certain arguments may be ignored)
722722
frame fr(sp, fp, pc);
723-
VMError::print_native_stack(tty, fr, t, buf, sizeof(buf));
723+
VMError::print_native_stack(tty, fr, t, false, buf, sizeof(buf));
724724
}
725725

726726
//
@@ -740,7 +740,7 @@ extern "C" JNIEXPORT void pns2() { // print native stack
740740
} else {
741741
Thread* t = Thread::current_or_null();
742742
frame fr = os::current_frame();
743-
VMError::print_native_stack(tty, fr, t, buf, sizeof(buf));
743+
VMError::print_native_stack(tty, fr, t, false, buf, sizeof(buf));
744744
}
745745
}
746746
#endif

src/hotspot/share/utilities/vmError.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static frame next_frame(frame fr, Thread* t) {
347347
}
348348
}
349349

350-
void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, char* buf, int buf_size) {
350+
void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, bool print_source_info, char* buf, int buf_size) {
351351

352352
// see if it's a valid frame
353353
if (fr.pc()) {
@@ -362,7 +362,8 @@ void VMError::print_native_stack(outputStream* st, frame fr, Thread* t, char* bu
362362
if (count == 1 && _lineno != 0) {
363363
// We have source information of the first frame for internal errors. There is no need to parse it from the symbols.
364364
st->print(" (%s:%d)", get_filename_only(), _lineno);
365-
} else if (Decoder::get_source_info(fr.pc(), filename, sizeof(filename), &line_no, count != 1)) {
365+
} else if (print_source_info &&
366+
Decoder::get_source_info(fr.pc(), filename, sizeof(filename), &line_no, count != 1)) {
366367
st->print(" (%s:%d)", filename, line_no);
367368
}
368369
}
@@ -535,6 +536,8 @@ void VMError::report(outputStream* st, bool _verbose) {
535536
// don't allocate large buffer on stack
536537
static char buf[O_BUFLEN];
537538

539+
static bool print_native_stack_succeeded = false;
540+
538541
BEGIN
539542

540543
STEP("printing fatal error message")
@@ -832,7 +835,7 @@ void VMError::report(outputStream* st, bool _verbose) {
832835
st->cr();
833836
}
834837

835-
STEP("printing native stack")
838+
STEP("printing native stack (with source info)")
836839

837840
if (_verbose) {
838841
if (os::platform_print_native_stack(st, _context, buf, sizeof(buf))) {
@@ -842,9 +845,20 @@ void VMError::report(outputStream* st, bool _verbose) {
842845
frame fr = _context ? os::fetch_frame_from_context(_context)
843846
: os::current_frame();
844847

845-
print_native_stack(st, fr, _thread, buf, sizeof(buf));
848+
print_native_stack(st, fr, _thread, true, buf, sizeof(buf));
846849
_print_native_stack_used = true;
847850
}
851+
print_native_stack_succeeded = true;
852+
}
853+
854+
STEP("retry printing native stack (no source info)")
855+
856+
if (_verbose && !print_native_stack_succeeded) {
857+
st->cr();
858+
st->print_cr("Retrying call stack printing without source information...");
859+
frame fr = _context ? os::fetch_frame_from_context(_context) : os::current_frame();
860+
print_native_stack(st, fr, _thread, false, buf, sizeof(buf));
861+
_print_native_stack_used = true;
848862
}
849863

850864
STEP("printing Java stack")

src/hotspot/share/utilities/vmError.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class VMError : public AllStatic {
105105

106106
// public for use by the internal non-product debugger.
107107
NOT_PRODUCT(public:)
108-
static void print_native_stack(outputStream* st, frame fr, Thread* t,
108+
static void print_native_stack(outputStream* st, frame fr, Thread* t, bool print_source_info,
109109
char* buf, int buf_size);
110110
NOT_PRODUCT(private:)
111111

0 commit comments

Comments
 (0)