1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2013 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file hat
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
290 goto report_and_die;
291 }
292
293 // Handle signal from NativeJump::patch_verified_entry().
294 if (( TrapBasedNotEntrantChecks && sig == SIGTRAP && nativeInstruction_at(pc)->is_sigtrap_zombie_not_entrant()) ||
295 (!TrapBasedNotEntrantChecks && sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant())) {
296 if (TraceTraps) {
297 tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL");
298 }
299 stub = SharedRuntime::get_handle_wrong_method_stub();
300 }
301
302 else if (sig == SIGSEGV &&
303 // A linux-ppc64 kernel before 2.6.6 doesn't set si_addr on some segfaults
304 // in 64bit mode (cf. http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.6),
305 // especially when we try to read from the safepoint polling page. So the check
306 // (address)info->si_addr == os::get_standard_polling_page()
307 // doesn't work for us. We use:
308 ((NativeInstruction*)pc)->is_safepoint_poll()) {
309 if (TraceTraps) {
310 tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", pc);
311 }
312 stub = SharedRuntime::get_poll_stub(pc);
313 }
314
315 // SIGTRAP-based ic miss check in compiled code.
316 else if (sig == SIGTRAP && TrapBasedICMissChecks &&
317 nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {
318 if (TraceTraps) {
319 tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
320 }
321 stub = SharedRuntime::get_ic_miss_stub();
322 }
323
324 // SIGTRAP-based implicit null check in compiled code.
325 else if (sig == SIGTRAP && TrapBasedNullChecks &&
326 nativeInstruction_at(pc)->is_sigtrap_null_check()) {
327 if (TraceTraps) {
328 tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
329 }
330 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
331 }
332
333 // SIGSEGV-based implicit null check in compiled code.
334 else if (sig == SIGSEGV && ImplicitNullChecks &&
335 CodeCache::contains((void*) pc) &&
336 !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
337 if (TraceTraps) {
338 tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc);
339 }
340 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
341 }
342
343 #ifdef COMPILER2
344 // SIGTRAP-based implicit range check in compiled code.
345 else if (sig == SIGTRAP && TrapBasedRangeChecks &&
346 nativeInstruction_at(pc)->is_sigtrap_range_check()) {
347 if (TraceTraps) {
348 tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
349 }
350 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
351 }
352 #endif
353 else if (sig == SIGBUS) {
354 // BugId 4454115: A read from a MappedByteBuffer can fault here if the
355 // underlying file has been truncated. Do not crash the VM in such a case.
356 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
357 nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL;
358 if (nm != NULL && nm->has_unsafe_access()) {
359 // We don't really need a stub here! Just set the pending exeption and
360 // continue at the next instruction after the faulting read. Returning
361 // garbage from this read is ok.
362 thread->set_pending_unsafe_access_error();
363 uc->uc_mcontext.regs->nip = ((unsigned long)pc) + 4;
364 return true;
365 }
366 }
367 }
368
555 // helper functions for fatal error handler
556
557 void os::print_context(outputStream *st, void *context) {
558 if (context == NULL) return;
559
560 ucontext_t* uc = (ucontext_t*)context;
561
562 st->print_cr("Registers:");
563 st->print("pc =" INTPTR_FORMAT " ", uc->uc_mcontext.regs->nip);
564 st->print("lr =" INTPTR_FORMAT " ", uc->uc_mcontext.regs->link);
565 st->print("ctr=" INTPTR_FORMAT " ", uc->uc_mcontext.regs->ctr);
566 st->cr();
567 for (int i = 0; i < 32; i++) {
568 st->print("r%-2d=" INTPTR_FORMAT " ", i, uc->uc_mcontext.regs->gpr[i]);
569 if (i % 3 == 2) st->cr();
570 }
571 st->cr();
572 st->cr();
573
574 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
575 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
576 print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
577 st->cr();
578
579 // Note: it may be unsafe to inspect memory near pc. For example, pc may
580 // point to garbage if entry point in an nmethod is corrupted. Leave
581 // this at the end, and hope for the best.
582 address pc = os::Linux::ucontext_get_pc(uc);
583 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
584 print_hex_dump(st, pc - 64, pc + 64, /*instrsize=*/4);
585 st->cr();
586 }
587
588 void os::print_register_info(outputStream *st, void *context) {
589 if (context == NULL) return;
590
591 ucontext_t *uc = (ucontext_t*)context;
592
593 st->print_cr("Register to memory mapping:");
594 st->cr();
595
596 // this is only for the "general purpose" registers
597 for (int i = 0; i < 32; i++) {
598 st->print("r%-2d=", i);
599 print_location(st, uc->uc_mcontext.regs->gpr[i]);
600 }
601 st->cr();
602 }
603
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2014 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file hat
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
290 goto report_and_die;
291 }
292
293 // Handle signal from NativeJump::patch_verified_entry().
294 if (( TrapBasedNotEntrantChecks && sig == SIGTRAP && nativeInstruction_at(pc)->is_sigtrap_zombie_not_entrant()) ||
295 (!TrapBasedNotEntrantChecks && sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant())) {
296 if (TraceTraps) {
297 tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL");
298 }
299 stub = SharedRuntime::get_handle_wrong_method_stub();
300 }
301
302 else if (sig == SIGSEGV &&
303 // A linux-ppc64 kernel before 2.6.6 doesn't set si_addr on some segfaults
304 // in 64bit mode (cf. http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.6),
305 // especially when we try to read from the safepoint polling page. So the check
306 // (address)info->si_addr == os::get_standard_polling_page()
307 // doesn't work for us. We use:
308 ((NativeInstruction*)pc)->is_safepoint_poll()) {
309 if (TraceTraps) {
310 tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
311 }
312 stub = SharedRuntime::get_poll_stub(pc);
313 }
314
315 // SIGTRAP-based ic miss check in compiled code.
316 else if (sig == SIGTRAP && TrapBasedICMissChecks &&
317 nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {
318 if (TraceTraps) {
319 tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
320 }
321 stub = SharedRuntime::get_ic_miss_stub();
322 }
323
324 // SIGTRAP-based implicit null check in compiled code.
325 else if (sig == SIGTRAP && TrapBasedNullChecks &&
326 nativeInstruction_at(pc)->is_sigtrap_null_check()) {
327 if (TraceTraps) {
328 tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
329 }
330 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
331 }
332
333 // SIGSEGV-based implicit null check in compiled code.
334 else if (sig == SIGSEGV && ImplicitNullChecks &&
335 CodeCache::contains((void*) pc) &&
336 !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
337 if (TraceTraps) {
338 tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
339 }
340 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
341 }
342
343 #ifdef COMPILER2
344 // SIGTRAP-based implicit range check in compiled code.
345 else if (sig == SIGTRAP && TrapBasedRangeChecks &&
346 nativeInstruction_at(pc)->is_sigtrap_range_check()) {
347 if (TraceTraps) {
348 tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
349 }
350 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
351 }
352 #endif
353 else if (sig == SIGBUS) {
354 // BugId 4454115: A read from a MappedByteBuffer can fault here if the
355 // underlying file has been truncated. Do not crash the VM in such a case.
356 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
357 nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL;
358 if (nm != NULL && nm->has_unsafe_access()) {
359 // We don't really need a stub here! Just set the pending exeption and
360 // continue at the next instruction after the faulting read. Returning
361 // garbage from this read is ok.
362 thread->set_pending_unsafe_access_error();
363 uc->uc_mcontext.regs->nip = ((unsigned long)pc) + 4;
364 return true;
365 }
366 }
367 }
368
555 // helper functions for fatal error handler
556
557 void os::print_context(outputStream *st, void *context) {
558 if (context == NULL) return;
559
560 ucontext_t* uc = (ucontext_t*)context;
561
562 st->print_cr("Registers:");
563 st->print("pc =" INTPTR_FORMAT " ", uc->uc_mcontext.regs->nip);
564 st->print("lr =" INTPTR_FORMAT " ", uc->uc_mcontext.regs->link);
565 st->print("ctr=" INTPTR_FORMAT " ", uc->uc_mcontext.regs->ctr);
566 st->cr();
567 for (int i = 0; i < 32; i++) {
568 st->print("r%-2d=" INTPTR_FORMAT " ", i, uc->uc_mcontext.regs->gpr[i]);
569 if (i % 3 == 2) st->cr();
570 }
571 st->cr();
572 st->cr();
573
574 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
575 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
576 print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
577 st->cr();
578
579 // Note: it may be unsafe to inspect memory near pc. For example, pc may
580 // point to garbage if entry point in an nmethod is corrupted. Leave
581 // this at the end, and hope for the best.
582 address pc = os::Linux::ucontext_get_pc(uc);
583 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
584 print_hex_dump(st, pc - 64, pc + 64, /*instrsize=*/4);
585 st->cr();
586 }
587
588 void os::print_register_info(outputStream *st, void *context) {
589 if (context == NULL) return;
590
591 ucontext_t *uc = (ucontext_t*)context;
592
593 st->print_cr("Register to memory mapping:");
594 st->cr();
595
596 // this is only for the "general purpose" registers
597 for (int i = 0; i < 32; i++) {
598 st->print("r%-2d=", i);
599 print_location(st, uc->uc_mcontext.regs->gpr[i]);
600 }
601 st->cr();
602 }
603
|