static void print_bug_submit_message(outputStream *out, Thread *thread) { if (out == NULL) return; out->print_raw_cr("# If you would like to submit a bug report, please visit:"); out->print_raw ("# "); out->print_raw_cr(Arguments::java_vendor_url_bug()); // If the crash is in native code, encourage user to submit a bug to the // provider of that code. if (thread && thread->is_Java_thread() && !thread->is_hidden_from_external_view()) { JavaThread* jt = (JavaThread*)thread; if (jt->thread_state() == _thread_in_native) { out->print_cr("# The crash happened outside the Java Virtual Machine in native code.\n# See problematic frame for where to report the bug."); } } out->print_raw_cr("#"); }
void ZeroStack::handle_overflow(TRAPS) { JavaThread *thread = (JavaThread *) THREAD; // Set up the frame anchor if it isn't already bool has_last_Java_frame = thread->has_last_Java_frame(); if (!has_last_Java_frame) { intptr_t *sp = thread->zero_stack()->sp(); ZeroFrame *frame = thread->top_zero_frame(); while (frame) { if (frame->is_shark_frame()) break; if (frame->is_interpreter_frame()) { interpreterState istate = frame->as_interpreter_frame()->interpreter_state(); if (istate->self_link() == istate) break; } sp = ((intptr_t *) frame) + 1; frame = frame->next(); } if (frame == NULL) fatal("unrecoverable stack overflow"); thread->set_last_Java_frame(frame, sp); } // Throw the exception switch (thread->thread_state()) { case _thread_in_Java: InterpreterRuntime::throw_StackOverflowError(thread); break; case _thread_in_vm: Exceptions::throw_stack_overflow_exception(thread, __FILE__, __LINE__); break; default: ShouldNotReachHere(); } // Reset the frame anchor if necessary if (!has_last_Java_frame) thread->reset_last_Java_frame(); }
int VM_Exit::set_vm_exited() { Thread * thr_cur = ThreadLocalStorage::get_thread_slow(); assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); int num_active = 0; _shutdown_thread = thr_cur; _vm_exited = true; // global flag for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { ++num_active; thr->set_terminated(JavaThread::_vm_exited); // per-thread flag } return num_active; }
int VM_Exit::set_vm_exited() { CodeCacheExtensions::complete_step(CodeCacheExtensionsSteps::LastStep); Thread * thr_cur = Thread::current(); assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); int num_active = 0; _shutdown_thread = thr_cur; _vm_exited = true; // global flag for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { ++num_active; thr->set_terminated(JavaThread::_vm_exited); // per-thread flag } return num_active; }
extern "C" JNIEXPORT int JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { // in fact this isn't ucontext_t* at all, but struct sigcontext* // but Linux porting layer uses ucontext_t, so to minimize code change // we cast as needed ucontext_t* ucFake = (ucontext_t*) ucVoid; sigcontext* uc = (sigcontext*)ucVoid; Thread* t = ThreadLocalStorage::get_thread_slow(); SignalHandlerMark shm(t); // Note: it's not uncommon that JNI code uses signal/sigset to install // then restore certain signal handler (e.g. to temporarily block SIGPIPE, // or have a SIGILL handler when detecting CPU type). When that happens, // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To // avoid unnecessary crash when libjsig is not preloaded, try handle signals // that do not require siginfo/ucontext first. if (sig == SIGPIPE || sig == SIGXFSZ) { // allow chained handler to go first if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } else { if (PrintMiscellaneous && (WizardMode || Verbose)) { char buf[64]; warning("Ignoring %s - see bugs 4229104 or 646499219", os::exception_name(sig, buf, sizeof(buf))); } return true; } } JavaThread* thread = NULL; VMThread* vmthread = NULL; if (os::Linux::signal_handlers_are_installed) { if (t != NULL ){ if(t->is_Java_thread()) { thread = (JavaThread*)t; } else if(t->is_VM_thread()){ vmthread = (VMThread *)t; } } } // decide if this trap can be handled by a stub address stub = NULL; address pc = NULL; address npc = NULL; //%note os_trap_1 if (info != NULL && uc != NULL && thread != NULL) { pc = address(SIG_PC(uc)); npc = address(SIG_NPC(uc)); // Check to see if we caught the safepoint code in the // process of write protecting the memory serialization page. // It write enables the page immediately after protecting it // so we can just return to retry the write. if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { // Block current thread until the memory serialize page permission restored. os::block_on_serialize_page_trap(); return 1; } if (checkPrefetch(uc, pc)) { return 1; } // Handle ALL stack overflow variations here if (sig == SIGSEGV) { if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { return 1; } } if (sig == SIGBUS && thread->thread_state() == _thread_in_vm && thread->doing_unsafe_access()) { stub = StubRoutines::handler_for_unsafe_access(); } if (thread->thread_state() == _thread_in_Java) { do { // Java thread running in Java code => find exception handler if any // a fault inside compiled code, the interpreter, or a stub if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { break; } if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { break; } if ((sig == SIGSEGV || sig == SIGBUS) && checkVerifyOops(pc, (address)info->si_addr, &stub)) { break; } if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { break; } if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { break; } if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { break; } if ((sig == SIGSEGV) && checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { break; } } while (0); // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in // and the heap gets shrunk before the field access. if ((sig == SIGSEGV) || (sig == SIGBUS)) { checkFastJNIAccess(pc, &stub); } } if (stub != NULL) { // save all thread context in case we need to restore it thread->set_saved_exception_pc(pc); thread->set_saved_exception_npc(npc); set_cont_address(uc, stub); return true; } } // signal-chaining if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } if (!abort_if_unrecognized) { // caller wants another chance, so give it to him return false; } if (pc == NULL && uc != NULL) { pc = os::Linux::ucontext_get_pc((ucontext_t*)uc); } // unmask current signal sigset_t newset; sigemptyset(&newset); sigaddset(&newset, sig); sigprocmask(SIG_UNBLOCK, &newset, NULL); VMError err(t, sig, pc, info, ucVoid); err.report_and_die(); ShouldNotReachHere(); }
inline bool vframeStreamCommon::fill_from_frame() { // Interpreted frame if (_frame.is_interpreted_frame()) { fill_from_interpreter_frame(); return true; } // Compiled frame if (cb() != NULL && cb()->is_nmethod()) { if (nm()->is_native_method()) { // Do not rely on scopeDesc since the pc might be unprecise due to the _last_native_pc trick. fill_from_compiled_native_frame(); } else { PcDesc* pc_desc = nm()->pc_desc_at(_frame.pc()); int decode_offset; if (pc_desc == NULL) { // Should not happen, but let fill_from_compiled_frame handle it. // If we are trying to walk the stack of a thread that is not // at a safepoint (like AsyncGetCallTrace would do) then this is an // acceptable result. [ This is assuming that safe_for_sender // is so bullet proof that we can trust the frames it produced. ] // // So if we see that the thread is not safepoint safe // then simply produce the method and a bci of zero // and skip the possibility of decoding any inlining that // may be present. That is far better than simply stopping (or // asserting. If however the thread is safepoint safe this // is the sign of a compiler bug and we'll let // fill_from_compiled_frame handle it. JavaThreadState state = _thread->thread_state(); // in_Java should be good enough to test safepoint safety // if state were say in_Java_trans then we'd expect that // the pc would have already been slightly adjusted to // one that would produce a pcDesc since the trans state // would be one that might in fact anticipate a safepoint if (state == _thread_in_Java ) { // This will get a method a zero bci and no inlining. // Might be nice to have a unique bci to signify this // particular case but for now zero will do. fill_from_compiled_native_frame(); // There is something to be said for setting the mode to // at_end_mode to prevent trying to walk further up the // stack. There is evidence that if we walk any further // that we could produce a bad stack chain. However until // we see evidence that allowing this causes us to find // frames bad enough to cause segv's or assertion failures // we don't do it as while we may get a bad call chain the // probability is much higher (several magnitudes) that we // get good data. return true; } decode_offset = DebugInformationRecorder::serialized_null; } else { decode_offset = pc_desc->scope_decode_offset(); } fill_from_compiled_frame(decode_offset); } return true; } // End of stack? if (_frame.is_first_frame() || (_stop_at_java_call_stub && _frame.is_entry_frame())) { _mode = at_end_mode; return true; } return false; }
// For Forte Analyzer AsyncGetCallTrace profiling support - thread is // currently interrupted by SIGPROF bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr, void* ucontext, bool isInJava) { assert(Thread::current() == this, "caller must be current thread"); assert(this->is_Java_thread(), "must be JavaThread"); JavaThread* jt = (JavaThread *)this; if (!isInJava) { // make_walkable flushes register windows and grabs last_Java_pc // which can not be done if the ucontext sp matches last_Java_sp // stack walking utilities assume last_Java_pc set if marked flushed jt->frame_anchor()->make_walkable(jt); } // If we have a walkable last_Java_frame, then we should use it // even if isInJava == true. It should be more reliable than // ucontext info. if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) { *fr_addr = jt->pd_last_frame(); return true; } ucontext_t* uc = (ucontext_t*) ucontext; // At this point, we don't have a walkable last_Java_frame, so // we try to glean some information out of the ucontext. intptr_t* ret_sp; ExtendedPC addr = os::fetch_frame_from_context(uc, &ret_sp, NULL /* ret_fp only used on X86 */); if (addr.pc() == NULL || ret_sp == NULL) { // ucontext wasn't useful return false; } #if INCLUDE_CDS if (UseSharedSpaces && MetaspaceShared::is_in_shared_region(addr.pc(), MetaspaceShared::md)) { // In the middle of a trampoline call. Bail out for safety. // This happens rarely so shouldn't affect profiling. return false; } #endif // we were running Java code when SIGPROF came in if (isInJava) { // If we have a last_Java_sp, then the SIGPROF signal caught us // right when we were transitioning from _thread_in_Java to a new // JavaThreadState. We use last_Java_sp instead of the sp from // the ucontext since it should be more reliable. if (jt->has_last_Java_frame()) { ret_sp = jt->last_Java_sp(); } // Implied else: we don't have a last_Java_sp so we use what we // got from the ucontext. frame ret_frame(ret_sp, frame::unpatchable, addr.pc()); if (!ret_frame.safe_for_sender(jt)) { // nothing else to try if the frame isn't good return false; } *fr_addr = ret_frame; return true; } // At this point, we know we weren't running Java code. We might // have a last_Java_sp, but we don't have a walkable frame. // However, we might still be able to construct something useful // if the thread was running native code. if (jt->has_last_Java_frame()) { assert(!jt->frame_anchor()->walkable(), "case covered above"); if (jt->thread_state() == _thread_in_native) { frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc()); if (!ret_frame.safe_for_sender(jt)) { // nothing else to try if the frame isn't good return false; } *fr_addr = ret_frame; return true; } } // nothing else to try return false; }
extern "C" JNIEXPORT int JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { ucontext_t* uc = (ucontext_t*) ucVoid; Thread* t = ThreadLocalStorage::get_thread_slow(); SignalHandlerMark shm(t); // Note: it's not uncommon that JNI code uses signal/sigset to // install then restore certain signal handler (e.g. to temporarily // block SIGPIPE, or have a SIGILL handler when detecting CPU // type). When that happens, JVM_handle_linux_signal() might be // invoked with junk info/ucVoid. To avoid unnecessary crash when // libjsig is not preloaded, try handle signals that do not require // siginfo/ucontext first. if (sig == SIGPIPE || sig == SIGXFSZ) { // allow chained handler to go first if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } else { if (PrintMiscellaneous && (WizardMode || Verbose)) { char buf[64]; warning("Ignoring %s - see bugs 4229104 or 646499219", os::exception_name(sig, buf, sizeof(buf))); } return true; } } JavaThread* thread = NULL; VMThread* vmthread = NULL; if (os::Linux::signal_handlers_are_installed) { if (t != NULL ){ if(t->is_Java_thread()) { thread = (JavaThread*)t; } else if(t->is_VM_thread()){ vmthread = (VMThread *)t; } } } if (info != NULL && thread != NULL) { // Handle ALL stack overflow variations here if (sig == SIGSEGV) { address addr = (address) info->si_addr; // check if fault address is within thread stack if (addr < thread->stack_base() && addr >= thread->stack_base() - thread->stack_size()) { // stack overflow if (thread->in_stack_yellow_zone(addr)) { thread->disable_stack_yellow_zone(); ShouldNotCallThis(); } else if (thread->in_stack_red_zone(addr)) { thread->disable_stack_red_zone(); ShouldNotCallThis(); } else { // Accessing stack address below sp may cause SEGV if // current thread has MAP_GROWSDOWN stack. This should // only happen when current thread was created by user // code with MAP_GROWSDOWN flag and then attached to VM. // See notes in os_linux.cpp. if (thread->osthread()->expanding_stack() == 0) { thread->osthread()->set_expanding_stack(); if (os::Linux::manually_expand_stack(thread, addr)) { thread->osthread()->clear_expanding_stack(); return true; } thread->osthread()->clear_expanding_stack(); } else { fatal("recursive segv. expanding stack."); } } } } /*if (thread->thread_state() == _thread_in_Java) { ShouldNotCallThis(); } else*/ if (thread->thread_state() == _thread_in_vm && sig == SIGBUS && thread->doing_unsafe_access()) { ShouldNotCallThis(); } // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC // kicks in and the heap gets shrunk before the field access. /*if (sig == SIGSEGV || sig == SIGBUS) { address addr = JNI_FastGetField::find_slowcase_pc(pc); if (addr != (address)-1) { stub = addr; } }*/ // Check to see if we caught the safepoint code in the process // of write protecting the memory serialization page. It write // enables the page immediately after protecting it so we can // just return to retry the write. if (sig == SIGSEGV && os::is_memory_serialize_page(thread, (address) info->si_addr)) { // Block current thread until permission is restored. os::block_on_serialize_page_trap(); return true; } } // signal-chaining if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } if (!abort_if_unrecognized) { // caller wants another chance, so give it to him return false; } #ifndef PRODUCT if (sig == SIGSEGV) { fatal("\n#" "\n# /--------------------\\" "\n# | segmentation fault |" "\n# \\---\\ /--------------/" "\n# /" "\n# [-] |\\_/| " "\n# (+)=C |o o|__ " "\n# | | =-*-=__\\ " "\n# OOO c_c_(___)"); } #endif // !PRODUCT const char *fmt = "caught unhandled signal %d"; char buf[64]; sprintf(buf, fmt, sig); fatal(buf); }
void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) { // This is if'd out because we no longer use thread suspension. // However if someone wanted to backport this to a 5.0 jvm then this // code would be important. #if 0 if (SafepointSynchronize::is_synchronizing()) { // The safepoint mechanism is trying to synchronize all the threads. // Since this can involve thread suspension, it is not safe for us // to be here. We can reduce the deadlock risk window by quickly // returning to the SIGPROF handler. However, it is still possible // for VMThread to catch us here or in the SIGPROF handler. If we // are suspended while holding a resource and another thread blocks // on that resource in the SIGPROF handler, then we will have a // three-thread deadlock (VMThread, this thread, the other thread). trace->num_frames = ticks_safepoint; // -10 return; } #endif JavaThread* thread; if (trace->env_id == NULL || (thread = JavaThread::thread_from_jni_environment(trace->env_id)) == NULL || thread->is_exiting()) { // bad env_id, thread has exited or thread is exiting trace->num_frames = ticks_thread_exit; // -8 return; } if (thread->in_deopt_handler()) { // thread is in the deoptimization handler so return no frames trace->num_frames = ticks_deopt; // -9 return; } assert(JavaThread::current() == thread, "AsyncGetCallTrace must be called by the current interrupted thread"); if (!JvmtiExport::should_post_class_load()) { trace->num_frames = ticks_no_class_load; // -1 return; } if (Universe::heap()->is_gc_active()) { trace->num_frames = ticks_GC_active; // -2 return; } switch (thread->thread_state()) { case _thread_new: case _thread_uninitialized: case _thread_new_trans: // We found the thread on the threads list above, but it is too // young to be useful so return that there are no Java frames. trace->num_frames = 0; break; case _thread_in_native: case _thread_in_native_trans: case _thread_blocked: case _thread_blocked_trans: case _thread_in_vm: case _thread_in_vm_trans: { frame fr; // param isInJava == false - indicate we aren't in Java code if (!thread->pd_get_top_frame_for_signal_handler(&fr, ucontext, false)) { trace->num_frames = ticks_unknown_not_Java; // -3 unknown frame } else { if (!thread->has_last_Java_frame()) { trace->num_frames = 0; // No Java frames } else { trace->num_frames = ticks_not_walkable_not_Java; // -4 non walkable frame by default forte_fill_call_trace_given_top(thread, trace, depth, fr); // This assert would seem to be valid but it is not. // It would be valid if we weren't possibly racing a gc // thread. A gc thread can make a valid interpreted frame // look invalid. It's a small window but it does happen. // The assert is left here commented out as a reminder. // assert(trace->num_frames != ticks_not_walkable_not_Java, "should always be walkable"); } } } break; case _thread_in_Java: case _thread_in_Java_trans: { frame fr; // param isInJava == true - indicate we are in Java code if (!thread->pd_get_top_frame_for_signal_handler(&fr, ucontext, true)) { trace->num_frames = ticks_unknown_Java; // -5 unknown frame } else { trace->num_frames = ticks_not_walkable_Java; // -6, non walkable frame by default forte_fill_call_trace_given_top(thread, trace, depth, fr); } } break; default: // Unknown thread state trace->num_frames = ticks_unknown_state; // -7 break; } }
JNIEXPORT void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) { JavaThread* thread; if (trace->env_id == NULL || (thread = JavaThread::thread_from_jni_environment(trace->env_id)) == NULL || thread->is_exiting()) { // bad env_id, thread has exited or thread is exiting trace->num_frames = ticks_thread_exit; // -8 return; } if (thread->in_deopt_handler()) { // thread is in the deoptimization handler so return no frames trace->num_frames = ticks_deopt; // -9 return; } assert(JavaThread::current() == thread, "AsyncGetCallTrace must be called by the current interrupted thread"); if (!JvmtiExport::should_post_class_load()) { trace->num_frames = ticks_no_class_load; // -1 return; } if (Universe::heap()->is_gc_active()) { trace->num_frames = ticks_GC_active; // -2 return; } switch (thread->thread_state()) { case _thread_new: case _thread_uninitialized: case _thread_new_trans: // We found the thread on the threads list above, but it is too // young to be useful so return that there are no Java frames. trace->num_frames = 0; break; case _thread_in_native: case _thread_in_native_trans: case _thread_blocked: case _thread_blocked_trans: case _thread_in_vm: case _thread_in_vm_trans: { frame fr; // param isInJava == false - indicate we aren't in Java code if (!thread->pd_get_top_frame_for_signal_handler(&fr, ucontext, false)) { trace->num_frames = ticks_unknown_not_Java; // -3 unknown frame } else { if (!thread->has_last_Java_frame()) { trace->num_frames = 0; // No Java frames } else { trace->num_frames = ticks_not_walkable_not_Java; // -4 non walkable frame by default forte_fill_call_trace_given_top(thread, trace, depth, fr); // This assert would seem to be valid but it is not. // It would be valid if we weren't possibly racing a gc // thread. A gc thread can make a valid interpreted frame // look invalid. It's a small window but it does happen. // The assert is left here commented out as a reminder. // assert(trace->num_frames != ticks_not_walkable_not_Java, "should always be walkable"); } } } break; case _thread_in_Java: case _thread_in_Java_trans: { frame fr; // param isInJava == true - indicate we are in Java code if (!thread->pd_get_top_frame_for_signal_handler(&fr, ucontext, true)) { trace->num_frames = ticks_unknown_Java; // -5 unknown frame } else { trace->num_frames = ticks_not_walkable_Java; // -6, non walkable frame by default forte_fill_call_trace_given_top(thread, trace, depth, fr); } } break; default: // Unknown thread state trace->num_frames = ticks_unknown_state; // -7 break; } }
extern "C" JNIEXPORT int JVM_handle_linux_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { ucontext_t* uc = (ucontext_t*) ucVoid; Thread* t = ThreadLocalStorage::get_thread_slow(); // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away // (no destructors can be run) os::WatcherThreadCrashProtection::check_crash_protection(sig, t); SignalHandlerMark shm(t); // Note: it's not uncommon that JNI code uses signal/sigset to install // then restore certain signal handler (e.g. to temporarily block SIGPIPE, // or have a SIGILL handler when detecting CPU type). When that happens, // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To // avoid unnecessary crash when libjsig is not preloaded, try handle signals // that do not require siginfo/ucontext first. if (sig == SIGPIPE || sig == SIGXFSZ) { // allow chained handler to go first if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } else { if (PrintMiscellaneous && (WizardMode || Verbose)) { char buf[64]; warning("Ignoring %s - see bugs 4229104 or 646499219", os::exception_name(sig, buf, sizeof(buf))); } return true; } } JavaThread* thread = NULL; VMThread* vmthread = NULL; if (os::Linux::signal_handlers_are_installed) { if (t != NULL ){ if(t->is_Java_thread()) { thread = (JavaThread*)t; } else if(t->is_VM_thread()){ vmthread = (VMThread *)t; } } } /* NOTE: does not seem to work on linux. if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { // can't decode this kind of signal info = NULL; } else { assert(sig == info->si_signo, "bad siginfo"); } */ // decide if this trap can be handled by a stub address stub = NULL; address pc = NULL; //%note os_trap_1 if (info != NULL && uc != NULL && thread != NULL) { pc = (address) os::Linux::ucontext_get_pc(uc); #ifdef BUILTIN_SIM if (pc == (address) Fetch32PFI) { uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ; return 1 ; } if (pc == (address) FetchNPFI) { uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ; return 1 ; } #else if (StubRoutines::is_safefetch_fault(pc)) { uc->uc_mcontext.pc = intptr_t(StubRoutines::continuation_for_safefetch_fault(pc)); return 1; } #endif #ifndef AMD64 // Halt if SI_KERNEL before more crashes get misdiagnosed as Java bugs // This can happen in any running code (currently more frequently in // interpreter code but has been seen in compiled code) if (sig == SIGSEGV && info->si_addr == 0 && info->si_code == SI_KERNEL) { fatal("An irrecoverable SI_KERNEL SIGSEGV has occurred due " "to unstable signal handling in this distribution."); } #endif // AMD64 // Handle ALL stack overflow variations here if (sig == SIGSEGV) { address addr = (address) info->si_addr; // check if fault address is within thread stack if (addr < thread->stack_base() && addr >= thread->stack_base() - thread->stack_size()) { // stack overflow if (thread->in_stack_yellow_zone(addr)) { thread->disable_stack_yellow_zone(); if (thread->thread_state() == _thread_in_Java) { // Throw a stack overflow exception. Guard pages will be reenabled // while unwinding the stack. stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); } else { // Thread was in the vm or native code. Return and try to finish. return 1; } } else if (thread->in_stack_red_zone(addr)) { // Fatal red zone violation. Disable the guard pages and fall through // to handle_unexpected_exception way down below. thread->disable_stack_red_zone(); tty->print_raw_cr("An irrecoverable stack overflow has occurred."); // This is a likely cause, but hard to verify. Let's just print // it as a hint. tty->print_raw_cr("Please check if any of your loaded .so files has " "enabled executable stack (see man page execstack(8))"); } else { // Accessing stack address below sp may cause SEGV if current // thread has MAP_GROWSDOWN stack. This should only happen when // current thread was created by user code with MAP_GROWSDOWN flag // and then attached to VM. See notes in os_linux.cpp. if (thread->osthread()->expanding_stack() == 0) { thread->osthread()->set_expanding_stack(); if (os::Linux::manually_expand_stack(thread, addr)) { thread->osthread()->clear_expanding_stack(); return 1; } thread->osthread()->clear_expanding_stack(); } else { fatal("recursive segv. expanding stack."); } } } } if (thread->thread_state() == _thread_in_Java) { // Java thread running in Java code => find exception handler if any // a fault inside compiled code, the interpreter, or a stub // Handle signal from NativeJump::patch_verified_entry(). if ((sig == SIGILL || sig == SIGTRAP) && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) { if (TraceTraps) { tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL"); } stub = SharedRuntime::get_handle_wrong_method_stub(); } else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) { stub = SharedRuntime::get_poll_stub(pc); } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) { // BugId 4454115: A read from a MappedByteBuffer can fault // here if the underlying file has been truncated. // Do not crash the VM in such a case. CodeBlob* cb = CodeCache::find_blob_unsafe(pc); nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL; if (nm != NULL && nm->has_unsafe_access()) { stub = handle_unsafe_access(thread, pc); } } else if (sig == SIGFPE && (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) { stub = SharedRuntime:: continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO); } else if (sig == SIGSEGV && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { // Determination of interpreter/vtable stub/compiled code null exception stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); } } else if (thread->thread_state() == _thread_in_vm && sig == SIGBUS && /* info->si_code == BUS_OBJERR && */ thread->doing_unsafe_access()) { stub = handle_unsafe_access(thread, pc); } // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in // and the heap gets shrunk before the field access. if ((sig == SIGSEGV) || (sig == SIGBUS)) { address addr = JNI_FastGetField::find_slowcase_pc(pc); if (addr != (address)-1) { stub = addr; } } // Check to see if we caught the safepoint code in the // process of write protecting the memory serialization page. // It write enables the page immediately after protecting it // so we can just return to retry the write. if ((sig == SIGSEGV) && os::is_memory_serialize_page(thread, (address) info->si_addr)) { // Block current thread until the memory serialize page permission restored. os::block_on_serialize_page_trap(); return true; } } if (stub != NULL) { // save all thread context in case we need to restore it if (thread != NULL) thread->set_saved_exception_pc(pc); #ifdef BUILTIN_SIM uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub; #else uc->uc_mcontext.pc = (__u64)stub; #endif return true; } // signal-chaining if (os::Linux::chained_handler(sig, info, ucVoid)) { return true; } if (!abort_if_unrecognized) { // caller wants another chance, so give it to him return false; } if (pc == NULL && uc != NULL) { pc = os::Linux::ucontext_get_pc(uc); } // unmask current signal sigset_t newset; sigemptyset(&newset); sigaddset(&newset, sig); sigprocmask(SIG_UNBLOCK, &newset, NULL); VMError err(t, sig, pc, info, ucVoid); err.report_and_die(); ShouldNotReachHere(); }