Skip to content

Commit c1bd8d9

Browse files
committed
8343343: Misc crash dump improvements on more platforms after JDK-8294160
8343149: Cleanup os::print_tos_pc on AIX Reviewed-by: mbaesken Backport-of: e33dc13567a4f0d9a6c1ae63fa0424ca27d52584
1 parent 37df1cb commit c1bd8d9

File tree

14 files changed

+68
-219
lines changed

14 files changed

+68
-219
lines changed

src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
124124
intptr_t* sp;
125125
intptr_t* fp;
126126
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
127-
// Avoid crash during crash if pc broken.
128-
if (epc) {
129-
frame fr(sp, epc);
130-
return fr;
127+
if (epc == nullptr || !is_readable_pointer(epc)) {
128+
// Try to recover from calling into bad memory
129+
// Assume new frame has not been set up, the same as
130+
// compiled frame stack bang
131+
return fetch_compiled_frame_from_context(ucVoid);
131132
}
132-
frame fr(sp);
133-
return fr;
133+
return frame(sp, epc);
134134
}
135135

136136
frame os::fetch_compiled_frame_from_context(const void* ucVoid) {
@@ -450,29 +450,6 @@ void os::print_context(outputStream *st, const void *context) {
450450
st->cr();
451451
}
452452

453-
void os::print_tos_pc(outputStream *st, const void *context) {
454-
if (context == nullptr) return;
455-
456-
const ucontext_t* uc = (const ucontext_t*)context;
457-
458-
address sp = (address)os::Aix::ucontext_get_sp(uc);
459-
print_tos(st, sp);
460-
st->cr();
461-
462-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
463-
// point to garbage if entry point in an nmethod is corrupted. Leave
464-
// this at the end, and hope for the best.
465-
address pc = os::Posix::ucontext_get_pc(uc);
466-
print_instructions(st, pc);
467-
st->cr();
468-
469-
// Try to decode the instructions.
470-
st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", pc);
471-
st->print("<TODO: PPC port - print_context>");
472-
// TODO: PPC port Disassembler::decode(pc, 16, 16, st);
473-
st->cr();
474-
}
475-
476453
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
477454
const int register_count = 32 /* r0-r32 */ + 3 /* pc, lr, sp */;
478455
int n = continuation;

src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
160160
intptr_t* sp;
161161
intptr_t* fp;
162162
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
163+
if (!is_readable_pointer(epc)) {
164+
// Try to recover from calling into bad memory
165+
// Assume new frame has not been set up, the same as
166+
// compiled frame stack bang
167+
return fetch_compiled_frame_from_context(ucVoid);
168+
}
163169
return frame(sp, fp, epc);
164170
}
165171

@@ -464,23 +470,6 @@ void os::print_context(outputStream *st, const void *context) {
464470
st->cr();
465471
}
466472

467-
void os::print_tos_pc(outputStream *st, const void *context) {
468-
if (context == nullptr) return;
469-
470-
const ucontext_t* uc = (const ucontext_t*)context;
471-
472-
address sp = (address)os::Bsd::ucontext_get_sp(uc);
473-
print_tos(st, sp);
474-
st->cr();
475-
476-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
477-
// point to garbage if entry point in an nmethod is corrupted. Leave
478-
// this at the end, and hope for the best.
479-
address pc = os::Posix::ucontext_get_pc(uc);
480-
print_instructions(st, pc);
481-
st->cr();
482-
}
483-
484473
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
485474
const int register_count = 29 /* x0-x28 */ + 3 /* fp, lr, sp */;
486475
int n = continuation;

src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
334334
intptr_t* sp;
335335
intptr_t* fp;
336336
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
337+
if (!is_readable_pointer(epc)) {
338+
// Try to recover from calling into bad memory
339+
// Assume new frame has not been set up, the same as
340+
// compiled frame stack bang
341+
return fetch_compiled_frame_from_context(ucVoid);
342+
}
337343
return frame(sp, fp, epc);
338344
}
339345

@@ -841,23 +847,6 @@ void os::print_context(outputStream *st, const void *context) {
841847
st->cr();
842848
}
843849

844-
void os::print_tos_pc(outputStream *st, const void *context) {
845-
if (context == nullptr) return;
846-
847-
const ucontext_t* uc = (const ucontext_t*)context;
848-
849-
address sp = (address)os::Bsd::ucontext_get_sp(uc);
850-
print_tos(st, sp);
851-
st->cr();
852-
853-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
854-
// point to garbage if entry point in an nmethod is corrupted. Leave
855-
// this at the end, and hope for the best.
856-
address pc = os::Posix::ucontext_get_pc(uc);
857-
print_instructions(st, pc);
858-
st->cr();
859-
}
860-
861850
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
862851
const int register_count = AMD64_ONLY(16) NOT_AMD64(8);
863852
int n = continuation;

src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ void os::print_context(outputStream* st, const void* context) {
249249
ShouldNotCallThis();
250250
}
251251

252-
void os::print_tos_pc(outputStream *st, const void *context) {
253-
ShouldNotCallThis();
254-
}
255-
256252
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
257253
ShouldNotCallThis();
258254
}

src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,6 @@ void os::print_context(outputStream *st, const void *context) {
357357
st->cr();
358358
}
359359

360-
void os::print_tos_pc(outputStream *st, const void *context) {
361-
if (context == nullptr) return;
362-
363-
const ucontext_t* uc = (const ucontext_t*)context;
364-
365-
address sp = (address)os::Linux::ucontext_get_sp(uc);
366-
print_tos(st, sp);
367-
st->cr();
368-
369-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
370-
// point to garbage if entry point in an nmethod is corrupted. Leave
371-
// this at the end, and hope for the best.
372-
address pc = os::fetch_frame_from_context(uc).pc();
373-
print_instructions(st, pc);
374-
st->cr();
375-
}
376-
377360
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
378361
const int register_count = 32 /* r0-r31 */;
379362
int n = continuation;

src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,27 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
189189
intptr_t* sp;
190190
intptr_t* fp;
191191
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
192+
if (!is_readable_pointer(epc)) {
193+
// Try to recover from calling into bad memory
194+
// Assume new frame has not been set up, the same as
195+
// compiled frame stack bang
196+
return fetch_compiled_frame_from_context(ucVoid);
197+
}
192198
return frame(sp, fp, epc);
193199
}
194200

201+
frame os::fetch_compiled_frame_from_context(const void* ucVoid) {
202+
const ucontext_t* uc = (const ucontext_t*)ucVoid;
203+
// In compiled code, the stack banging is performed before LR
204+
// has been saved in the frame. LR is live, and SP and FP
205+
// belong to the caller.
206+
intptr_t* fp = os::Linux::ucontext_get_fp(uc);
207+
intptr_t* sp = os::Linux::ucontext_get_sp(uc);
208+
address pc = (address)(uc->uc_mcontext.arm_lr
209+
- NativeInstruction::instruction_size);
210+
return frame(sp, fp, pc);
211+
}
212+
195213
frame os::get_sender_for_C_frame(frame* fr) {
196214
#ifdef __thumb__
197215
// We can't reliably get anything from a thumb C frame.
@@ -470,23 +488,6 @@ void os::print_context(outputStream *st, const void *context) {
470488
st->cr();
471489
}
472490

473-
void os::print_tos_pc(outputStream *st, const void *context) {
474-
if (context == nullptr) return;
475-
476-
const ucontext_t* uc = (const ucontext_t*)context;
477-
478-
address sp = (address)os::Linux::ucontext_get_sp(uc);
479-
print_tos(st, sp);
480-
st->cr();
481-
482-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
483-
// point to garbage if entry point in an nmethod is corrupted. Leave
484-
// this at the end, and hope for the best.
485-
address pc = os::Posix::ucontext_get_pc(uc);
486-
print_instructions(st, pc);
487-
st->cr();
488-
}
489-
490491
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
491492
const int register_count = ARM_REGS_IN_CONTEXT;
492493
int n = continuation;

src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
156156
intptr_t* sp;
157157
intptr_t* fp;
158158
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
159+
if (!is_readable_pointer(epc)) {
160+
// Try to recover from calling into bad memory
161+
// Assume new frame has not been set up, the same as
162+
// compiled frame stack bang
163+
return fetch_compiled_frame_from_context(ucVoid);
164+
}
159165
return frame(sp, epc);
160166
}
161167

@@ -464,23 +470,6 @@ void os::print_context(outputStream *st, const void *context) {
464470
st->cr();
465471
}
466472

467-
void os::print_tos_pc(outputStream *st, const void *context) {
468-
if (context == nullptr) return;
469-
470-
const ucontext_t* uc = (const ucontext_t*)context;
471-
472-
address sp = (address)os::Linux::ucontext_get_sp(uc);
473-
print_tos(st, sp);
474-
st->cr();
475-
476-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
477-
// point to garbage if entry point in an nmethod is corrupted. Leave
478-
// this at the end, and hope for the best.
479-
address pc = os::Posix::ucontext_get_pc(uc);
480-
print_instructions(st, pc);
481-
st->cr();
482-
}
483-
484473
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
485474
const int register_count = 32 /* r0-r32 */ + 3 /* pc, lr, ctr */;
486475
int n = continuation;

src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,23 +354,6 @@ void os::print_context(outputStream *st, const void *context) {
354354
st->cr();
355355
}
356356

357-
void os::print_tos_pc(outputStream *st, const void *context) {
358-
if (context == nullptr) return;
359-
360-
const ucontext_t* uc = (const ucontext_t*)context;
361-
362-
address sp = (address)os::Linux::ucontext_get_sp(uc);
363-
print_tos(st, sp);
364-
st->cr();
365-
366-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
367-
// point to garbage if entry point in an nmethod is corrupted. Leave
368-
// this at the end, and hope for the best.
369-
address pc = os::fetch_frame_from_context(uc).pc();
370-
print_instructions(st, pc);
371-
st->cr();
372-
}
373-
374357
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
375358
const int register_count = 32;
376359
int n = continuation;

src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
141141
intptr_t* sp;
142142
intptr_t* fp;
143143
address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
144+
if (!is_readable_pointer(epc)) {
145+
// Try to recover from calling into bad memory
146+
// Assume new frame has not been set up, the same as
147+
// compiled frame stack bang
148+
return fetch_compiled_frame_from_context(ucVoid);
149+
}
144150
return frame(sp, epc);
145151
}
146152

@@ -443,23 +449,6 @@ void os::print_context(outputStream *st, const void *context) {
443449
st->cr();
444450
}
445451

446-
void os::print_tos_pc(outputStream *st, const void *context) {
447-
if (context == nullptr) return;
448-
449-
const ucontext_t* uc = (const ucontext_t*)context;
450-
451-
address sp = (address)os::Linux::ucontext_get_sp(uc);
452-
print_tos(st, sp);
453-
st->cr();
454-
455-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
456-
// point to garbage if entry point in an nmethod is corrupted. Leave
457-
// this at the end, and hope for the best.
458-
address pc = os::Posix::ucontext_get_pc(uc);
459-
print_instructions(st, pc);
460-
st->cr();
461-
}
462-
463452
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
464453
const int register_count = 16 /* r0-r15 */ + 1 /* pc */;
465454
int n = continuation;

src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -573,23 +573,6 @@ void os::print_context(outputStream *st, const void *context) {
573573
st->cr();
574574
}
575575

576-
void os::print_tos_pc(outputStream *st, const void *context) {
577-
if (context == nullptr) return;
578-
579-
const ucontext_t* uc = (const ucontext_t*)context;
580-
581-
address sp = (address)os::Linux::ucontext_get_sp(uc);
582-
print_tos(st, sp);
583-
st->cr();
584-
585-
// Note: it may be unsafe to inspect memory near pc. For example, pc may
586-
// point to garbage if entry point in an nmethod is corrupted. Leave
587-
// this at the end, and hope for the best.
588-
address pc = os::fetch_frame_from_context(uc).pc();
589-
print_instructions(st, pc);
590-
st->cr();
591-
}
592-
593576
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
594577
const int register_count = AMD64_ONLY(16) NOT_AMD64(8);
595578
int n = continuation;

0 commit comments

Comments
 (0)