phh@568: /* mikael@6198: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. phh@568: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. phh@568: * phh@568: * This code is free software; you can redistribute it and/or modify it phh@568: * under the terms of the GNU General Public License version 2 only, as phh@568: * published by the Free Software Foundation. phh@568: * phh@568: * This code is distributed in the hope that it will be useful, but WITHOUT phh@568: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or phh@568: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License phh@568: * version 2 for more details (a copy is included in the LICENSE file that phh@568: * accompanied this code). phh@568: * phh@568: * You should have received a copy of the GNU General Public License version phh@568: * 2 along with this work; if not, write to the Free Software Foundation, phh@568: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. phh@568: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. phh@568: * phh@568: */ phh@568: stefank@2314: // no precompiled headers twisti@4323: #include "asm/macroAssembler.hpp" stefank@2314: #include "classfile/classLoader.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "code/icBuffer.hpp" stefank@2314: #include "code/vtableStubs.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "jvm_linux.h" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "mutex_linux.inline.hpp" stefank@2314: #include "nativeInst_sparc.hpp" stefank@2314: #include "os_share_linux.hpp" stefank@2314: #include "prims/jniFastGetField.hpp" stefank@2314: #include "prims/jvm.h" stefank@2314: #include "prims/jvm_misc.hpp" stefank@2314: #include "runtime/arguments.hpp" stefank@2314: #include "runtime/extendedPC.hpp" stefank@2314: #include "runtime/frame.inline.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/java.hpp" stefank@2314: #include "runtime/javaCalls.hpp" stefank@2314: #include "runtime/mutexLocker.hpp" stefank@2314: #include "runtime/osThread.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@4299: #include "runtime/thread.inline.hpp" stefank@2314: #include "runtime/timer.hpp" stefank@2314: #include "utilities/events.hpp" stefank@2314: #include "utilities/vmError.hpp" phh@568: phh@568: // Linux/Sparc has rather obscure naming of registers in sigcontext phh@568: // different between 32 and 64 bits phh@568: #ifdef _LP64 phh@568: #define SIG_PC(x) ((x)->sigc_regs.tpc) phh@568: #define SIG_NPC(x) ((x)->sigc_regs.tnpc) phh@568: #define SIG_REGS(x) ((x)->sigc_regs) phh@568: #else phh@568: #define SIG_PC(x) ((x)->si_regs.pc) phh@568: #define SIG_NPC(x) ((x)->si_regs.npc) phh@568: #define SIG_REGS(x) ((x)->si_regs) phh@568: #endif phh@568: phh@568: // those are to reference registers in sigcontext phh@568: enum { phh@568: CON_G0 = 0, phh@568: CON_G1, phh@568: CON_G2, phh@568: CON_G3, phh@568: CON_G4, phh@568: CON_G5, phh@568: CON_G6, phh@568: CON_G7, phh@568: CON_O0, phh@568: CON_O1, phh@568: CON_O2, phh@568: CON_O3, phh@568: CON_O4, phh@568: CON_O5, phh@568: CON_O6, phh@568: CON_O7, phh@568: }; phh@568: phh@568: static inline void set_cont_address(sigcontext* ctx, address addr) { phh@568: SIG_PC(ctx) = (intptr_t)addr; phh@568: SIG_NPC(ctx) = (intptr_t)(addr+4); phh@568: } phh@568: phh@568: // For Forte Analyzer AsyncGetCallTrace profiling support - thread is phh@568: // currently interrupted by SIGPROF. phh@568: // os::Solaris::fetch_frame_from_ucontext() tries to skip nested phh@568: // signal frames. Currently we don't do that on Linux, so it's the phh@568: // same as os::fetch_frame_from_context(). phh@568: ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, phh@568: ucontext_t* uc, phh@568: intptr_t** ret_sp, phh@568: intptr_t** ret_fp) { phh@568: assert(thread != NULL, "just checking"); phh@568: assert(ret_sp != NULL, "just checking"); phh@568: assert(ret_fp != NULL, "just checking"); phh@568: phh@568: return os::fetch_frame_from_context(uc, ret_sp, ret_fp); phh@568: } phh@568: phh@568: ExtendedPC os::fetch_frame_from_context(void* ucVoid, phh@568: intptr_t** ret_sp, phh@568: intptr_t** ret_fp) { phh@568: ucontext_t* uc = (ucontext_t*) ucVoid; phh@568: ExtendedPC epc; phh@568: phh@568: if (uc != NULL) { phh@568: epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); phh@568: if (ret_sp) { phh@568: *ret_sp = os::Linux::ucontext_get_sp(uc); phh@568: } phh@568: if (ret_fp) { zgu@6921: *ret_fp = (intptr_t*)NULL; phh@568: } phh@568: } else { phh@568: // construct empty ExtendedPC for return value checking phh@568: epc = ExtendedPC(NULL); phh@568: if (ret_sp) { phh@568: *ret_sp = (intptr_t*) NULL; phh@568: } phh@568: if (ret_fp) { phh@568: *ret_fp = (intptr_t*) NULL; phh@568: } phh@568: } phh@568: phh@568: return epc; phh@568: } phh@568: phh@568: frame os::fetch_frame_from_context(void* ucVoid) { phh@568: intptr_t* sp; zgu@6921: ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, NULL); zgu@6921: return frame(sp, frame::unpatchable, epc.pc()); phh@568: } phh@568: phh@568: frame os::get_sender_for_C_frame(frame* fr) { zgu@6920: return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); phh@568: } phh@568: phh@568: frame os::current_frame() { phh@568: intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); phh@568: frame myframe(sp, frame::unpatchable, phh@568: CAST_FROM_FN_PTR(address, os::current_frame)); phh@568: if (os::is_first_C_frame(&myframe)) { phh@568: // stack is not walkable phh@568: return frame(NULL, frame::unpatchable, NULL); phh@568: } else { phh@568: return os::get_sender_for_C_frame(&myframe); phh@568: } phh@568: } phh@568: phh@568: address os::current_stack_pointer() { phh@568: register void *sp __asm__ ("sp"); phh@568: return (address)sp; phh@568: } phh@568: phh@568: static void current_stack_region(address* bottom, size_t* size) { phh@568: if (os::Linux::is_initial_thread()) { phh@568: // initial thread needs special handling because pthread_getattr_np() phh@568: // may return bogus value. phh@568: *bottom = os::Linux::initial_thread_stack_bottom(); phh@568: *size = os::Linux::initial_thread_stack_size(); phh@568: } else { phh@568: pthread_attr_t attr; phh@568: phh@568: int rslt = pthread_getattr_np(pthread_self(), &attr); phh@568: phh@568: // JVM needs to know exact stack location, abort if it fails phh@568: if (rslt != 0) { phh@568: if (rslt == ENOMEM) { ccheung@4993: vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); phh@568: } else { jcoomes@1845: fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); phh@568: } phh@568: } phh@568: phh@568: if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) { phh@568: fatal("Can not locate current stack attributes!"); phh@568: } phh@568: phh@568: pthread_attr_destroy(&attr); phh@568: } phh@568: assert(os::current_stack_pointer() >= *bottom && phh@568: os::current_stack_pointer() < *bottom + *size, "just checking"); phh@568: } phh@568: phh@568: address os::current_stack_base() { phh@568: address bottom; phh@568: size_t size; phh@568: current_stack_region(&bottom, &size); phh@568: return bottom + size; phh@568: } phh@568: phh@568: size_t os::current_stack_size() { phh@568: // stack size includes normal stack and HotSpot guard pages phh@568: address bottom; phh@568: size_t size; phh@568: current_stack_region(&bottom, &size); phh@568: return size; phh@568: } phh@568: phh@568: char* os::non_memory_address_word() { phh@568: // Must never look like an address returned by reserve_memory, phh@568: // even in its subfields (as defined by the CPU immediate fields, phh@568: // if the CPU splits constants across multiple instructions). phh@568: // On SPARC, 0 != %hi(any real address), because there is no phh@568: // allocation in the first 1Kb of the virtual address space. phh@568: return (char*) 0; phh@568: } phh@568: zgu@4079: void os::initialize_thread(Thread* thr) {} phh@568: phh@568: void os::print_context(outputStream *st, void *context) { phh@568: if (context == NULL) return; phh@568: phh@568: ucontext_t* uc = (ucontext_t*)context; phh@568: sigcontext* sc = (sigcontext*)context; phh@568: st->print_cr("Registers:"); phh@568: never@2262: st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT never@2262: " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, never@2262: SIG_REGS(sc).u_regs[CON_G1], never@2262: SIG_REGS(sc).u_regs[CON_G2], never@2262: SIG_REGS(sc).u_regs[CON_G3], never@2262: SIG_REGS(sc).u_regs[CON_G4]); never@2262: st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT never@2262: " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, never@2262: SIG_REGS(sc).u_regs[CON_G5], never@2262: SIG_REGS(sc).u_regs[CON_G6], never@2262: SIG_REGS(sc).u_regs[CON_G7], never@2262: SIG_REGS(sc).y); phh@568: st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT phh@568: " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, phh@568: SIG_REGS(sc).u_regs[CON_O0], phh@568: SIG_REGS(sc).u_regs[CON_O1], phh@568: SIG_REGS(sc).u_regs[CON_O2], phh@568: SIG_REGS(sc).u_regs[CON_O3]); phh@568: st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT phh@568: " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, phh@568: SIG_REGS(sc).u_regs[CON_O4], phh@568: SIG_REGS(sc).u_regs[CON_O5], phh@568: SIG_REGS(sc).u_regs[CON_O6], phh@568: SIG_REGS(sc).u_regs[CON_O7]); phh@568: never@2262: never@2262: intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); never@2262: st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT never@2262: " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, never@2262: sp[L0->sp_offset_in_saved_window()], never@2262: sp[L1->sp_offset_in_saved_window()], never@2262: sp[L2->sp_offset_in_saved_window()], never@2262: sp[L3->sp_offset_in_saved_window()]); never@2262: st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT never@2262: " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, never@2262: sp[L4->sp_offset_in_saved_window()], never@2262: sp[L5->sp_offset_in_saved_window()], never@2262: sp[L6->sp_offset_in_saved_window()], never@2262: sp[L7->sp_offset_in_saved_window()]); never@2262: st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT never@2262: " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, never@2262: sp[I0->sp_offset_in_saved_window()], never@2262: sp[I1->sp_offset_in_saved_window()], never@2262: sp[I2->sp_offset_in_saved_window()], never@2262: sp[I3->sp_offset_in_saved_window()]); never@2262: st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT never@2262: " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, never@2262: sp[I4->sp_offset_in_saved_window()], never@2262: sp[I5->sp_offset_in_saved_window()], never@2262: sp[I6->sp_offset_in_saved_window()], never@2262: sp[I7->sp_offset_in_saved_window()]); phh@568: phh@568: st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, phh@568: SIG_PC(sc), phh@568: SIG_NPC(sc)); phh@568: st->cr(); phh@568: st->cr(); phh@568: phh@568: st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); phh@568: print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); phh@568: st->cr(); phh@568: phh@568: // Note: it may be unsafe to inspect memory near pc. For example, pc may phh@568: // point to garbage if entry point in an nmethod is corrupted. Leave phh@568: // this at the end, and hope for the best. phh@568: address pc = os::Linux::ucontext_get_pc(uc); phh@568: st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); never@2262: print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); never@2262: } never@2262: never@2262: never@2262: void os::print_register_info(outputStream *st, void *context) { never@2262: if (context == NULL) return; never@2262: never@2262: ucontext_t *uc = (ucontext_t*)context; mikael@6683: sigcontext* sc = (sigcontext*)context; never@2262: intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); never@2262: never@2262: st->print_cr("Register to memory mapping:"); never@2262: st->cr(); never@2262: never@2262: // this is only for the "general purpose" registers mikael@6683: st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]); mikael@6683: st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]); mikael@6683: st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]); mikael@6683: st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]); mikael@6683: st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]); mikael@6683: st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]); mikael@6683: st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]); never@2262: st->cr(); never@2262: mikael@6683: st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]); mikael@6683: st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]); mikael@6683: st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]); mikael@6683: st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]); mikael@6683: st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]); mikael@6683: st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]); mikael@6683: st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]); mikael@6683: st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]); never@2262: st->cr(); never@2262: never@2262: st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); never@2262: st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); never@2262: st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); never@2262: st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); never@2262: st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); never@2262: st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); never@2262: st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); never@2262: st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); never@2262: st->cr(); never@2262: never@2262: st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); never@2262: st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); never@2262: st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); never@2262: st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); never@2262: st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); never@2262: st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); never@2262: st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); never@2262: st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); never@2262: st->cr(); phh@568: } phh@568: phh@568: phh@568: address os::Linux::ucontext_get_pc(ucontext_t* uc) { phh@568: return (address) SIG_PC((sigcontext*)uc); phh@568: } phh@568: phh@568: intptr_t* os::Linux::ucontext_get_sp(ucontext_t *uc) { phh@568: return (intptr_t*) phh@568: ((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); phh@568: } phh@568: phh@568: // not used on Sparc phh@568: intptr_t* os::Linux::ucontext_get_fp(ucontext_t *uc) { phh@568: ShouldNotReachHere(); phh@568: return NULL; phh@568: } phh@568: phh@568: // Utility functions phh@568: phh@568: inline static bool checkPrefetch(sigcontext* uc, address pc) { goetz@5400: if (StubRoutines::is_safefetch_fault(pc)) { goetz@5400: set_cont_address(uc, address(StubRoutines::continuation_for_safefetch_fault(pc))); phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkOverflow(sigcontext* uc, phh@568: address pc, phh@568: address addr, phh@568: JavaThread* thread, phh@568: address* stub) { phh@568: // check if fault address is within thread stack phh@568: if (addr < thread->stack_base() && phh@568: addr >= thread->stack_base() - thread->stack_size()) { phh@568: // stack overflow phh@568: if (thread->in_stack_yellow_zone(addr)) { phh@568: thread->disable_stack_yellow_zone(); phh@568: if (thread->thread_state() == _thread_in_Java) { phh@568: // Throw a stack overflow exception. Guard pages will be reenabled phh@568: // while unwinding the stack. phh@568: *stub = phh@568: SharedRuntime::continuation_for_implicit_exception(thread, phh@568: pc, phh@568: SharedRuntime::STACK_OVERFLOW); phh@568: } else { phh@568: // Thread was in the vm or native code. Return and try to finish. phh@568: return true; phh@568: } phh@568: } else if (thread->in_stack_red_zone(addr)) { phh@568: // Fatal red zone violation. Disable the guard pages and fall through phh@568: // to handle_unexpected_exception way down below. phh@568: thread->disable_stack_red_zone(); phh@568: tty->print_raw_cr("An irrecoverable stack overflow has occurred."); iklam@4710: iklam@4710: // This is a likely cause, but hard to verify. Let's just print iklam@4710: // it as a hint. iklam@4710: tty->print_raw_cr("Please check if any of your loaded .so files has " iklam@4710: "enabled executable stack (see man page execstack(8))"); phh@568: } else { phh@568: // Accessing stack address below sp may cause SEGV if current phh@568: // thread has MAP_GROWSDOWN stack. This should only happen when phh@568: // current thread was created by user code with MAP_GROWSDOWN flag phh@568: // and then attached to VM. See notes in os_linux.cpp. phh@568: if (thread->osthread()->expanding_stack() == 0) { phh@568: thread->osthread()->set_expanding_stack(); phh@568: if (os::Linux::manually_expand_stack(thread, addr)) { phh@568: thread->osthread()->clear_expanding_stack(); phh@568: return true; phh@568: } phh@568: thread->osthread()->clear_expanding_stack(); phh@568: } else { phh@568: fatal("recursive segv. expanding stack."); phh@568: } phh@568: } phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkPollingPage(address pc, address fault, address* stub) { phh@568: if (fault == os::get_polling_page()) { phh@568: *stub = SharedRuntime::get_poll_stub(pc); phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkByteBuffer(address pc, address* stub) { phh@568: // BugId 4454115: A read from a MappedByteBuffer can fault phh@568: // here if the underlying file has been truncated. phh@568: // Do not crash the VM in such a case. phh@568: CodeBlob* cb = CodeCache::find_blob_unsafe(pc); phh@568: nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; phh@568: if (nm != NULL && nm->has_unsafe_access()) { phh@568: *stub = StubRoutines::handler_for_unsafe_access(); phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkVerifyOops(address pc, address fault, address* stub) { phh@568: if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] phh@568: && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { phh@568: *stub = MacroAssembler::_verify_oop_implicit_branch[2]; phh@568: warning("fixed up memory fault in +VerifyOops at address " phh@568: INTPTR_FORMAT, fault); phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkFPFault(address pc, int code, phh@568: JavaThread* thread, address* stub) { phh@568: if (code == FPE_INTDIV || code == FPE_FLTDIV) { phh@568: *stub = phh@568: SharedRuntime:: phh@568: continuation_for_implicit_exception(thread, phh@568: pc, phh@568: SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkNullPointer(address pc, intptr_t fault, phh@568: JavaThread* thread, address* stub) { phh@568: if (!MacroAssembler::needs_explicit_null_check(fault)) { phh@568: // Determination of interpreter/vtable stub/compiled code null phh@568: // exception phh@568: *stub = phh@568: SharedRuntime:: phh@568: continuation_for_implicit_exception(thread, pc, phh@568: SharedRuntime::IMPLICIT_NULL); phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkFastJNIAccess(address pc, address* stub) { phh@568: address addr = JNI_FastGetField::find_slowcase_pc(pc); phh@568: if (addr != (address)-1) { phh@568: *stub = addr; phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkSerializePage(JavaThread* thread, address addr) { phh@568: return os::is_memory_serialize_page(thread, addr); phh@568: } phh@568: phh@568: inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { phh@568: if (nativeInstruction_at(*pc)->is_zombie()) { phh@568: // zombie method (ld [%g0],%o7 instruction) phh@568: *stub = SharedRuntime::get_handle_wrong_method_stub(); phh@568: phh@568: // At the stub it needs to look like a call from the caller of this phh@568: // method (not a call from the segv site). phh@568: *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; phh@568: return true; phh@568: } phh@568: return false; phh@568: } phh@568: phh@568: inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { phh@568: #ifdef COMPILER2 phh@568: if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { phh@568: #ifdef ASSERT phh@568: #ifdef TIERED mikael@6683: CodeBlob* cb = CodeCache::find_blob_unsafe(*pc); phh@568: assert(cb->is_compiled_by_c2(), "Wrong compiler"); phh@568: #endif // TIERED phh@568: #endif // ASSERT phh@568: // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. phh@568: *stub = SharedRuntime::get_ic_miss_stub(); phh@568: // At the stub it needs to look like a call from the caller of this phh@568: // method (not a call from the segv site). phh@568: *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; phh@568: return true; phh@568: } phh@568: #endif // COMPILER2 phh@568: return false; phh@568: } phh@568: coleenp@2507: extern "C" JNIEXPORT int phh@568: JVM_handle_linux_signal(int sig, phh@568: siginfo_t* info, phh@568: void* ucVoid, phh@568: int abort_if_unrecognized) { phh@568: // in fact this isn't ucontext_t* at all, but struct sigcontext* phh@568: // but Linux porting layer uses ucontext_t, so to minimize code change phh@568: // we cast as needed phh@568: ucontext_t* ucFake = (ucontext_t*) ucVoid; phh@568: sigcontext* uc = (sigcontext*)ucVoid; phh@568: phh@568: Thread* t = ThreadLocalStorage::get_thread_slow(); phh@568: rbackman@5424: // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away rbackman@5424: // (no destructors can be run) rbackman@5424: os::WatcherThreadCrashProtection::check_crash_protection(sig, t); rbackman@5424: phh@568: SignalHandlerMark shm(t); phh@568: phh@568: // Note: it's not uncommon that JNI code uses signal/sigset to install phh@568: // then restore certain signal handler (e.g. to temporarily block SIGPIPE, phh@568: // or have a SIGILL handler when detecting CPU type). When that happens, phh@568: // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To phh@568: // avoid unnecessary crash when libjsig is not preloaded, try handle signals phh@568: // that do not require siginfo/ucontext first. phh@568: phh@568: if (sig == SIGPIPE || sig == SIGXFSZ) { phh@568: // allow chained handler to go first phh@568: if (os::Linux::chained_handler(sig, info, ucVoid)) { phh@568: return true; phh@568: } else { phh@568: if (PrintMiscellaneous && (WizardMode || Verbose)) { phh@568: char buf[64]; phh@568: warning("Ignoring %s - see bugs 4229104 or 646499219", phh@568: os::exception_name(sig, buf, sizeof(buf))); phh@568: } phh@568: return true; phh@568: } phh@568: } phh@568: phh@568: JavaThread* thread = NULL; phh@568: VMThread* vmthread = NULL; phh@568: if (os::Linux::signal_handlers_are_installed) { phh@568: if (t != NULL ){ phh@568: if(t->is_Java_thread()) { phh@568: thread = (JavaThread*)t; phh@568: } phh@568: else if(t->is_VM_thread()){ phh@568: vmthread = (VMThread *)t; phh@568: } phh@568: } phh@568: } phh@568: phh@568: // decide if this trap can be handled by a stub phh@568: address stub = NULL; phh@568: address pc = NULL; phh@568: address npc = NULL; phh@568: phh@568: //%note os_trap_1 phh@568: if (info != NULL && uc != NULL && thread != NULL) { phh@568: pc = address(SIG_PC(uc)); phh@568: npc = address(SIG_NPC(uc)); phh@568: phh@568: // Check to see if we caught the safepoint code in the phh@568: // process of write protecting the memory serialization page. phh@568: // It write enables the page immediately after protecting it phh@568: // so we can just return to retry the write. phh@568: if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { phh@568: // Block current thread until the memory serialize page permission restored. phh@568: os::block_on_serialize_page_trap(); phh@568: return 1; phh@568: } phh@568: phh@568: if (checkPrefetch(uc, pc)) { phh@568: return 1; phh@568: } phh@568: phh@568: // Handle ALL stack overflow variations here phh@568: if (sig == SIGSEGV) { phh@568: if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { phh@568: return 1; phh@568: } phh@568: } phh@568: phh@568: if (sig == SIGBUS && phh@568: thread->thread_state() == _thread_in_vm && phh@568: thread->doing_unsafe_access()) { phh@568: stub = StubRoutines::handler_for_unsafe_access(); phh@568: } phh@568: phh@568: if (thread->thread_state() == _thread_in_Java) { phh@568: do { phh@568: // Java thread running in Java code => find exception handler if any phh@568: // a fault inside compiled code, the interpreter, or a stub phh@568: phh@568: if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { phh@568: break; phh@568: } phh@568: phh@568: if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { phh@568: break; phh@568: } phh@568: phh@568: if ((sig == SIGSEGV || sig == SIGBUS) && phh@568: checkVerifyOops(pc, (address)info->si_addr, &stub)) { phh@568: break; phh@568: } phh@568: phh@568: if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { phh@568: break; phh@568: } phh@568: phh@568: if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { phh@568: break; phh@568: } phh@568: phh@568: if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { phh@568: break; phh@568: } phh@568: phh@568: if ((sig == SIGSEGV) && phh@568: checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { phh@568: break; phh@568: } phh@568: } while (0); phh@568: phh@568: // jni_fast_GetField can trap at certain pc's if a GC kicks in phh@568: // and the heap gets shrunk before the field access. phh@568: if ((sig == SIGSEGV) || (sig == SIGBUS)) { phh@568: checkFastJNIAccess(pc, &stub); phh@568: } phh@568: } phh@568: phh@568: if (stub != NULL) { phh@568: // save all thread context in case we need to restore it phh@568: thread->set_saved_exception_pc(pc); phh@568: thread->set_saved_exception_npc(npc); phh@568: set_cont_address(uc, stub); phh@568: return true; phh@568: } phh@568: } phh@568: phh@568: // signal-chaining phh@568: if (os::Linux::chained_handler(sig, info, ucVoid)) { phh@568: return true; phh@568: } phh@568: phh@568: if (!abort_if_unrecognized) { phh@568: // caller wants another chance, so give it to him phh@568: return false; phh@568: } phh@568: phh@568: if (pc == NULL && uc != NULL) { phh@568: pc = os::Linux::ucontext_get_pc((ucontext_t*)uc); phh@568: } phh@568: phh@568: // unmask current signal phh@568: sigset_t newset; phh@568: sigemptyset(&newset); phh@568: sigaddset(&newset, sig); phh@568: sigprocmask(SIG_UNBLOCK, &newset, NULL); phh@568: phh@568: VMError err(t, sig, pc, info, ucVoid); phh@568: err.report_and_die(); phh@568: phh@568: ShouldNotReachHere(); phh@568: } phh@568: phh@568: void os::Linux::init_thread_fpu_state(void) { phh@568: // Nothing to do phh@568: } phh@568: phh@568: int os::Linux::get_fpu_control_word() { phh@568: return 0; phh@568: } phh@568: phh@568: void os::Linux::set_fpu_control_word(int fpu) { phh@568: // nothing phh@568: } phh@568: phh@568: bool os::is_allocatable(size_t bytes) { phh@568: #ifdef _LP64 phh@568: return true; phh@568: #else phh@568: if (bytes < 2 * G) { phh@568: return true; phh@568: } phh@568: phh@568: char* addr = reserve_memory(bytes, NULL); phh@568: phh@568: if (addr != NULL) { phh@568: release_memory(addr, bytes); phh@568: } phh@568: phh@568: return addr != NULL; phh@568: #endif // _LP64 phh@568: } phh@568: phh@568: /////////////////////////////////////////////////////////////////////////////// phh@568: // thread stack phh@568: phh@568: size_t os::Linux::min_stack_allowed = 128 * K; phh@568: phh@568: // pthread on Ubuntu is always in floating stack mode phh@568: bool os::Linux::supports_variable_stack_size() { return true; } phh@568: phh@568: // return default stack size for thr_type phh@568: size_t os::Linux::default_stack_size(os::ThreadType thr_type) { phh@568: // default stack size (compiler thread needs larger stack) phh@568: size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); phh@568: return s; phh@568: } phh@568: phh@568: size_t os::Linux::default_guard_size(os::ThreadType thr_type) { phh@568: // Creating guard page is very expensive. Java thread has HotSpot phh@568: // guard page, only enable glibc guard page for non-Java threads. phh@568: return (thr_type == java_thread ? 0 : page_size()); phh@568: } roland@3606: roland@3606: #ifndef PRODUCT roland@3606: void os::verify_stack_alignment() { roland@3606: } roland@3606: #endif