os_solaris_sparc.cpp revision 9056:dc9930a04ab0
12061Sjkh/* 235452Sandreas * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 32061Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 433611Sjb * 532427Sjb * This code is free software; you can redistribute it and/or modify it 632427Sjb * under the terms of the GNU General Public License version 2 only, as 733611Sjb * published by the Free Software Foundation. 833611Sjb * 932427Sjb * This code is distributed in the hope that it will be useful, but WITHOUT 1032427Sjb * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112061Sjkh * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1215603Smarkm * version 2 for more details (a copy is included in the LICENSE file that 1330169Sjkh * accompanied this code). 1420710Sasami * 1520710Sasami * You should have received a copy of the GNU General Public License version 163197Scsgr * 2 along with this work; if not, write to the Free Software Foundation, 172061Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1812483Speter * 1934509Sbde * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 202160Scsgr * or visit www.oracle.com if you need additional information or have any 212834Swollman * questions. 222061Sjkh * 232061Sjkh */ 242160Scsgr 2517308Speter// no precompiled headers 2619320Sadam#include "asm/macroAssembler.hpp" 2727788Sasami#include "classfile/classLoader.hpp" 2830169Sjkh#include "classfile/systemDictionary.hpp" 2925980Sasami#include "classfile/vmSymbols.hpp" 301594Srgrimes#include "code/codeCache.hpp" 3117308Speter#include "code/icBuffer.hpp" 3217308Speter#include "code/vtableStubs.hpp" 3327910Sasami#include "interpreter/interpreter.hpp" 3427910Sasami#include "jvm_solaris.h" 3527910Sasami#include "memory/allocation.inline.hpp" 3617308Speter#include "mutex_solaris.inline.hpp" 3717308Speter#include "nativeInst_sparc.hpp" 3817308Speter#include "os_share_solaris.hpp" 3919175Sbde#include "prims/jniFastGetField.hpp" 4019175Sbde#include "prims/jvm.h" 4119175Sbde#include "prims/jvm_misc.hpp" 4219175Sbde#include "runtime/arguments.hpp" 4317308Speter#include "runtime/extendedPC.hpp" 4427910Sasami#include "runtime/frame.inline.hpp" 4534509Sbde#include "runtime/interfaceSupport.hpp" 4627910Sasami#include "runtime/java.hpp" 4717308Speter#include "runtime/javaCalls.hpp" 482061Sjkh#include "runtime/mutexLocker.hpp" 492061Sjkh#include "runtime/osThread.hpp" 501594Srgrimes#include "runtime/sharedRuntime.hpp" 5130169Sjkh#include "runtime/stubRoutines.hpp" 5230169Sjkh#include "runtime/thread.inline.hpp" 5330169Sjkh#include "runtime/timer.hpp" 5430169Sjkh#include "utilities/events.hpp" 5530169Sjkh#include "utilities/vmError.hpp" 5630169Sjkh 5730169Sjkh# include <signal.h> // needed first to avoid name collision for "std" with SC 5.0 5830169Sjkh 597407Srgrimes// put OS-includes here 607108Sphk# include <sys/types.h> 617108Sphk# include <sys/mman.h> 627108Sphk# include <pthread.h> 637407Srgrimes# include <errno.h> 647407Srgrimes# include <dlfcn.h> 657407Srgrimes# include <stdio.h> 667108Sphk# include <unistd.h> 672061Sjkh# include <sys/resource.h> 682061Sjkh# include <thread.h> 692061Sjkh# include <sys/stat.h> 7017308Speter# include <sys/time.h> 712061Sjkh# include <sys/filio.h> 722061Sjkh# include <sys/utsname.h> 732061Sjkh# include <sys/systeminfo.h> 742061Sjkh# include <sys/socket.h> 752061Sjkh# include <sys/lwp.h> 7635427Sbde# include <pwd.h> 7735427Sbde# include <poll.h> 7830169Sjkh# include <sys/lwp.h> 792626Scsgr 802061Sjkh# define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later 812061Sjkh# include <sys/procfs.h> // see comment in <sys/procfs.h> 822061Sjkh 832061Sjkh#define MAX_PATH (2 * K) 842061Sjkh 852061Sjkh// Minimum stack size for the VM. It's easier to document a constant 8619320Sadam// but it's different for x86 and sparc because the page sizes are different. 872061Sjkh#ifdef _LP64 882061Sjkhsize_t os::Solaris::min_stack_allowed = 128*K; 892061Sjkh#else 902061Sjkhsize_t os::Solaris::min_stack_allowed = 96*K; 912061Sjkh#endif 922061Sjkh 932061Sjkhint os::Solaris::max_register_window_saves_before_flushing() { 942061Sjkh // We should detect this at run time. For now, filling 952061Sjkh // in with a constant. 962061Sjkh return 8; 972061Sjkh} 982834Swollman 992834Swollmanstatic void handle_unflushed_register_windows(gwindows_t *win) { 1002834Swollman int restore_count = win->wbcnt; 1012834Swollman int i; 1022834Swollman 1032834Swollman for(i=0; i<restore_count; i++) { 1041594Srgrimes address sp = ((address)win->spbuf[i]) + STACK_BIAS; 1054486Sphk address reg_win = (address)&win->wbuf[i]; 1064486Sphk memcpy(sp,reg_win,sizeof(struct rwindow)); 1074486Sphk } 1084486Sphk} 1094486Sphk 1102061Sjkhchar* os::non_memory_address_word() { 1112061Sjkh // Must never look like an address returned by reserve_memory, 11225979Sjkh // even in its subfields (as defined by the CPU immediate fields, 11325979Sjkh // if the CPU splits constants across multiple instructions). 11425979Sjkh // On SPARC, 0 != %hi(any real address), because there is no 11525979Sjkh // allocation in the first 1Kb of the virtual address space. 1162061Sjkh return (char*) 0; 11725979Sjkh} 1182061Sjkh 1192061Sjkh// Validate a ucontext retrieved from walking a uc_link of a ucontext. 12017308Speter// There are issues with libthread giving out uc_links for different threads 1212061Sjkh// on the same uc_link chain and bad or circular links. 1222061Sjkh// 1232061Sjkhbool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) { 1242061Sjkh if (valid >= suspect || 1252061Sjkh valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags || 12612483Speter valid->uc_stack.ss_sp != suspect->uc_stack.ss_sp || 12712483Speter valid->uc_stack.ss_size != suspect->uc_stack.ss_size) { 12812483Speter DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");) 12912483Speter return false; 1302061Sjkh } 1312061Sjkh 1328854Srgrimes if (thread->is_Java_thread()) { 1332061Sjkh if (!valid_stack_address(thread, (address)suspect)) { 1342061Sjkh DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");) 13512483Speter return false; 1362061Sjkh } 13727910Sasami address _sp = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS); 13827910Sasami if (!valid_stack_address(thread, _sp) || 13918714Sache !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) { 14017308Speter DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");) 14134541Sbde return false; 14234575Sbde } 14334575Sbde } 14434575Sbde return true; 14534592Sbde} 14617308Speter 14734575Sbde// We will only follow one level of uc_link since there are libthread 14835427Sbde// issues with ucontext linking and it is better to be safe and just 14934575Sbde// let caller retry later. 15035427Sbdeucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread, 15134575Sbde ucontext_t *uc) { 15215603Smarkm 15317308Speter ucontext_t *retuc = NULL; 15417308Speter 15517308Speter // Sometimes the topmost register windows are not properly flushed. 15617308Speter // i.e., if the kernel would have needed to take a page fault 15717308Speter if (uc != NULL && uc->uc_mcontext.gwins != NULL) { 15817308Speter ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); 15917308Speter } 16017308Speter 16117308Speter if (uc != NULL) { 16218362Sjkh if (uc->uc_link == NULL) { 16319966Sache // cannot validate without uc_link so accept current ucontext 16418362Sjkh retuc = uc; 16517308Speter } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) { 16627910Sasami // first ucontext is valid so try the next one 16717308Speter uc = uc->uc_link; 16817308Speter if (uc->uc_link == NULL) { 16917308Speter // cannot validate without uc_link so accept current ucontext 17028803Speter retuc = uc; 17127910Sasami } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) { 17228803Speter // the ucontext one level down is also valid so return it 17330113Sjkh retuc = uc; 17427910Sasami } 17517308Speter } 1762061Sjkh } 17727910Sasami return retuc; 1782061Sjkh} 17928803Speter 18027910Sasami// Assumes ucontext is valid 1812061SjkhExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) { 18217308Speter address pc = (address)uc->uc_mcontext.gregs[REG_PC]; 18327910Sasami // set npc to zero to avoid using it for safepoint, good for profiling only 18417308Speter return ExtendedPC(pc); 18527910Sasami} 18627910Sasami 18727910Sasamivoid os::Solaris::ucontext_set_pc(ucontext_t* uc, address pc) { 18817308Speter uc->uc_mcontext.gregs [REG_PC] = (greg_t) pc; 18927910Sasami uc->uc_mcontext.gregs [REG_nPC] = (greg_t) (pc + 4); 19017308Speter} 19127910Sasami 19227910Sasami// Assumes ucontext is valid 19327910Sasamiintptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) { 19427910Sasami return (intptr_t*)((intptr_t)uc->uc_mcontext.gregs[REG_SP] + STACK_BIAS); 19527910Sasami} 19627910Sasami 19727910Sasami// Solaris X86 only 19827910Sasamiintptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) { 19927910Sasami ShouldNotReachHere(); 20027910Sasami return NULL; 20127910Sasami} 20227910Sasami 20334509Sbdeaddress os::Solaris::ucontext_get_pc(ucontext_t *uc) { 20427910Sasami return (address) uc->uc_mcontext.gregs[REG_PC]; 20527910Sasami} 20627910Sasami 20727910Sasami 20827910Sasami// For Forte Analyzer AsyncGetCallTrace profiling support - thread 20927910Sasami// is currently interrupted by SIGPROF. 21027910Sasami// 21127910Sasami// ret_fp parameter is only used by Solaris X86. 21234688Sbde// 21334688Sbde// The difference between this and os::fetch_frame_from_context() is that 21427910Sasami// here we try to skip nested signal frames. 21535427SbdeExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread, 21627910Sasami ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { 21735427Sbde 21827910Sasami assert(thread != NULL, "just checking"); 21935427Sbde assert(ret_sp != NULL, "just checking"); 22027910Sasami assert(ret_fp == NULL, "just checking"); 22127910Sasami 22227910Sasami ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc); 22327910Sasami 22427910Sasami return os::fetch_frame_from_context(luc, ret_sp, ret_fp); 22527910Sasami} 22627910Sasami 22727910Sasami 22827910Sasami// ret_fp parameter is only used by Solaris X86. 22917308SpeterExtendedPC os::fetch_frame_from_context(void* ucVoid, 23017308Speter intptr_t** ret_sp, intptr_t** ret_fp) { 23127910Sasami 23217308Speter ExtendedPC epc; 23327910Sasami ucontext_t *uc = (ucontext_t*)ucVoid; 23427910Sasami 23527910Sasami if (uc != NULL) { 23627910Sasami epc = os::Solaris::ucontext_get_ExtendedPC(uc); 23733133Sadam if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc); 23817466Speter } else { 23917308Speter // construct empty ExtendedPC for return value checking 24027910Sasami epc = ExtendedPC(NULL); 24117308Speter if (ret_sp) *ret_sp = (intptr_t *)NULL; 24234688Sbde } 24334688Sbde 24427910Sasami return epc; 24534688Sbde} 24630113Sjkh 24730277Sasamiframe os::fetch_frame_from_context(void* ucVoid) { 24834688Sbde intptr_t* sp; 24934688Sbde intptr_t* fp; 25033133Sadam ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); 25117308Speter return frame(sp, frame::unpatchable, epc.pc()); 25217308Speter} 25327910Sasami 25417308Speterframe os::get_sender_for_C_frame(frame* fr) { 25527910Sasami return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); 25627910Sasami} 25717308Speter 25817308Speter// Returns an estimate of the current stack pointer. Result must be guaranteed to 25927910Sasami// point into the calling threads stack, and be no lower than the current stack 26017308Speter// pointer. 26130113Sjkhaddress os::current_stack_pointer() { 26227910Sasami volatile int dummy; 26327910Sasami address sp = (address)&dummy + 8; // %%%% need to confirm if this is right 26417308Speter return sp; 26517308Speter} 26627910Sasami 26717308Speterframe os::current_frame() { 26834509Sbde intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); 26927910Sasami frame myframe(sp, frame::unpatchable, 27033133Sadam CAST_FROM_FN_PTR(address, os::current_frame)); 27117308Speter if (os::is_first_C_frame(&myframe)) { 27217308Speter // stack is not walkable 27327910Sasami return frame(NULL, NULL, false); 27417308Speter } else { 27527910Sasami return os::get_sender_for_C_frame(&myframe); 27617308Speter } 27717308Speter} 27827910Sasami 27917308Speterbool os::is_allocatable(size_t bytes) { 28027910Sasami#ifdef _LP64 28133133Sadam return true; 28217308Speter#else 28317308Speter return (bytes <= (size_t)3835*M); 28434509Sbde#endif 28517308Speter} 28629503Sbde 28733133Sadamextern "C" JNIEXPORT int 28817962SpeterJVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, 28917962Speter int abort_if_unrecognized) { 29035427Sbde ucontext_t* uc = (ucontext_t*) ucVoid; 29117962Speter 29227910Sasami Thread* t = ThreadLocalStorage::get_thread_slow(); 29333133Sadam 29417962Speter // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away 29517962Speter // (no destructors can be run) 29635427Sbde os::WatcherThreadCrashProtection::check_crash_protection(sig, t); 29717962Speter 29835427Sbde SignalHandlerMark shm(t); 29933133Sadam 30017962Speter if(sig == SIGPIPE || sig == SIGXFSZ) { 30117962Speter if (os::Solaris::chained_handler(sig, info, ucVoid)) { 30227910Sasami return true; 30317962Speter } else { 30427910Sasami if (PrintMiscellaneous && (WizardMode || Verbose)) { 30533133Sadam char buf[64]; 30617308Speter warning("Ignoring %s - see 4229104 or 6499219", 30717308Speter os::exception_name(sig, buf, sizeof(buf))); 30827910Sasami 30917308Speter } 31030205Sbde return true; 31117308Speter } 31217308Speter } 31335427Sbde 31435427Sbde JavaThread* thread = NULL; 31535427Sbde VMThread* vmthread = NULL; 31635427Sbde if (os::Solaris::signal_handlers_are_installed) { 31735427Sbde if (t != NULL ){ 31827910Sasami if(t->is_Java_thread()) { 31917962Speter thread = (JavaThread*)t; 32027910Sasami } 3212061Sjkh else if(t->is_VM_thread()){ 32217308Speter vmthread = (VMThread *)t; 32327910Sasami } 32427910Sasami } 32527910Sasami } 32627910Sasami 32727910Sasami guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs"); 32827910Sasami 32927910Sasami if (sig == os::Solaris::SIGasync()) { 33027910Sasami if (thread || vmthread) { 33117308Speter OSThread::SR_handler(t, uc); 33217308Speter return true; 33317308Speter } else if (os::Solaris::chained_handler(sig, info, ucVoid)) { 33417308Speter return true; 33517308Speter } else { 33617308Speter // If os::Solaris::SIGasync not chained, and this is a non-vm and 33717308Speter // non-java thread 33812483Speter return true; 33917308Speter } 34012483Speter } 34117308Speter 34212483Speter if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { 3432061Sjkh // can't decode this kind of signal 34417962Speter info = NULL; 34517962Speter } else { 34617308Speter assert(sig == info->si_signo, "bad siginfo"); 34717962Speter } 34817962Speter 34933595Snate // decide if this trap can be handled by a stub 35033595Snate address stub = NULL; 35133595Snate 35233595Snate address pc = NULL; 35333595Snate address npc = NULL; 35417962Speter 35517962Speter //%note os_trap_1 35617308Speter if (info != NULL && uc != NULL && thread != NULL) { 3572061Sjkh // factor me: getPCfromContext 35817308Speter pc = (address) uc->uc_mcontext.gregs[REG_PC]; 35917308Speter npc = (address) uc->uc_mcontext.gregs[REG_nPC]; 36017308Speter 36117308Speter // SafeFetch() support 36217308Speter if (StubRoutines::is_safefetch_fault(pc)) { 36317308Speter os::Solaris::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); 3642302Spaul return 1; 3652302Spaul } 3662302Spaul 3672302Spaul // Handle ALL stack overflow variations here 3682302Spaul if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) { 36918714Sache address addr = (address) info->si_addr; 37010760Sache if (thread->in_stack_yellow_zone(addr)) { 37118714Sache thread->disable_stack_yellow_zone(); 3722302Spaul // Sometimes the register windows are not properly flushed. 37310760Sache if(uc->uc_mcontext.gwins != NULL) { 37418714Sache ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); 37510760Sache } 37610760Sache if (thread->thread_state() == _thread_in_Java) { 3772302Spaul // Throw a stack overflow exception. Guard pages will be reenabled 3782302Spaul // while unwinding the stack. 3792302Spaul stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); 3802302Spaul } else { 38130132Sfsmp // Thread was in the vm or native code. Return and try to finish. 3822302Spaul return true; 3832302Spaul } 38417308Speter } else if (thread->in_stack_red_zone(addr)) { 38517308Speter // Fatal red zone violation. Disable the guard pages and fall through 38617308Speter // to handle_unexpected_exception way down below. 38717308Speter thread->disable_stack_red_zone(); 38817308Speter tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 38917308Speter // Sometimes the register windows are not properly flushed. 3902061Sjkh if(uc->uc_mcontext.gwins != NULL) { 39117308Speter ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); 3922061Sjkh } 39330205Sbde } 39430205Sbde } 39530205Sbde 39630205Sbde 39730205Sbde if (thread->thread_state() == _thread_in_vm) { 39830205Sbde if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) { 39930205Sbde stub = StubRoutines::handler_for_unsafe_access(); 40030205Sbde } 40130169Sjkh } 40230205Sbde 40317308Speter else if (thread->thread_state() == _thread_in_Java) { 40417308Speter // Java thread running in Java code => find exception handler if any 40530205Sbde // a fault inside compiled code, the interpreter, or a stub 40617308Speter 4072061Sjkh // Support Safepoint Polling 40817308Speter if ( sig == SIGSEGV && (address)info->si_addr == os::get_polling_page() ) { 40917308Speter stub = SharedRuntime::get_poll_stub(pc); 41017308Speter } 41117308Speter 41217308Speter // Not needed on x86 solaris because verify_oops doesn't generate 41317308Speter // SEGV/BUS like sparc does. 4143626Swollman if ( (sig == SIGSEGV || sig == SIGBUS) 4153626Swollman && pc >= MacroAssembler::_verify_oop_implicit_branch[0] 4163626Swollman && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { 4173626Swollman stub = MacroAssembler::_verify_oop_implicit_branch[2]; 41830205Sbde warning("fixed up memory fault in +VerifyOops at address " INTPTR_FORMAT, info->si_addr); 41930205Sbde } 42030205Sbde 42130205Sbde // This is not factored because on x86 solaris the patching for 42230205Sbde // zombies does not generate a SEGV. 42330205Sbde else if (sig == SIGSEGV && nativeInstruction_at(pc)->is_zombie()) { 42430205Sbde // zombie method (ld [%g0],%o7 instruction) 42530205Sbde stub = SharedRuntime::get_handle_wrong_method_stub(); 42630169Sjkh 42730205Sbde // At the stub it needs to look like a call from the caller of this 4283626Swollman // method (not a call from the segv site). 4293626Swollman pc = (address)uc->uc_mcontext.gregs[REG_O7]; 43030205Sbde } 4313626Swollman else if (sig == SIGBUS && info->si_code == BUS_OBJERR) { 4323626Swollman // BugId 4454115: A read from a MappedByteBuffer can fault 43317308Speter // here if the underlying file has been truncated. 43417308Speter // Do not crash the VM in such a case. 43517308Speter CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 43617308Speter nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; 43717308Speter if (nm != NULL && nm->has_unsafe_access()) { 43817308Speter stub = StubRoutines::handler_for_unsafe_access(); 43917308Speter } 44017308Speter } 44117308Speter 44217308Speter else if (sig == SIGFPE && info->si_code == FPE_INTDIV) { 4433626Swollman // integer divide by zero 44417308Speter stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); 44517308Speter } 44617308Speter else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) { 44717308Speter // floating-point divide by zero 44817308Speter stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); 44917308Speter } 45017308Speter#ifdef COMPILER2 45117308Speter else if (sig == SIGILL && nativeInstruction_at(pc)->is_ic_miss_trap()) { 45217308Speter#ifdef ASSERT 45317308Speter #ifdef TIERED 45417308Speter CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 45517308Speter assert(cb->is_compiled_by_c2(), "Wrong compiler"); 45627910Sasami #endif // TIERED 45727910Sasami#endif // ASSERT 45827910Sasami // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. 45927910Sasami stub = SharedRuntime::get_ic_miss_stub(); 46034575Sbde // At the stub it needs to look like a call from the caller of this 46127910Sasami // method (not a call from the segv site). 46234509Sbde pc = (address)uc->uc_mcontext.gregs[REG_O7]; 46330113Sjkh } 46430113Sjkh#endif // COMPILER2 46534509Sbde 46630113Sjkh else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { 46730113Sjkh // Determination of interpreter/vtable stub/compiled code null exception 46834509Sbde stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); 46934509Sbde } 47030170Sjkh } 47130113Sjkh 47229938Smckay // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 47334509Sbde // and the heap gets shrunk before the field access. 47429938Smckay if ((sig == SIGSEGV) || (sig == SIGBUS)) { 47517308Speter address addr = JNI_FastGetField::find_slowcase_pc(pc); 47617308Speter if (addr != (address)-1) { 47717308Speter stub = addr; 47817308Speter } 47917308Speter } 48027910Sasami 48127910Sasami // Check to see if we caught the safepoint code in the 48227910Sasami // process of write protecting the memory serialization page. 48317308Speter // It write enables the page immediately after protecting it 48417308Speter // so just return. 48534520Sbde if ((sig == SIGSEGV) && 48634520Sbde os::is_memory_serialize_page(thread, (address)info->si_addr)) { 48734509Sbde // Block current thread until the memory serialize page permission restored. 48830113Sjkh os::block_on_serialize_page_trap(); 48930113Sjkh return true; 49034520Sbde } 49117308Speter } 49217308Speter 49317308Speter if (stub != NULL) { 49417308Speter // save all thread context in case we need to restore it 49514119Speter 4962061Sjkh thread->set_saved_exception_pc(pc); 4977130Srgrimes thread->set_saved_exception_npc(npc); 4987130Srgrimes 4997130Srgrimes // simulate a branch to the stub (a "call" in the safepoint stub case) 5002061Sjkh // factor me: setPC 50130113Sjkh os::Solaris::ucontext_set_pc(uc, stub); 50217308Speter 50330169Sjkh#ifndef PRODUCT 50430169Sjkh if (TraceJumps) thread->record_jump(stub, NULL, __FILE__, __LINE__); 5052685Srgrimes#endif /* PRODUCT */ 5066927Snate 50727790Sasami return true; 50827790Sasami } 50927790Sasami 51030169Sjkh // signal-chaining 51130169Sjkh if (os::Solaris::chained_handler(sig, info, ucVoid)) { 51230169Sjkh return true; 5133197Scsgr } 51430169Sjkh 51530169Sjkh if (!abort_if_unrecognized) { 51630169Sjkh // caller wants another chance, so give it to him 51730169Sjkh return false; 51830169Sjkh } 51930169Sjkh 52030169Sjkh if (!os::Solaris::libjsig_is_loaded) { 52130169Sjkh struct sigaction oldAct; 52230169Sjkh sigaction(sig, (struct sigaction *)0, &oldAct); 52330169Sjkh if (oldAct.sa_sigaction != signalHandler) { 52432427Sjb void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) 52532427Sjb : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); 52632427Sjb warning("Unexpected Signal %d occurred under user-defined signal handler " INTPTR_FORMAT, sig, (intptr_t)sighand); 52726152Speter } 5282061Sjkh } 52935452Sandreas 5302061Sjkh if (pc == NULL && uc != NULL) { 53130169Sjkh pc = (address) uc->uc_mcontext.gregs[REG_PC]; 5322061Sjkh } 53316786Snate 5342883Sphk // Sometimes the register windows are not properly flushed. 53527790Sasami if(uc->uc_mcontext.gwins != NULL) { 53617308Speter ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); 5377281Srgrimes } 5383242Spaul 5393242Spaul // unmask current signal 54030169Sjkh sigset_t newset; 5417171Sats sigemptyset(&newset); 5422061Sjkh sigaddset(&newset, sig); 5433213Spst sigprocmask(SIG_UNBLOCK, &newset, NULL); 54430169Sjkh 54530169Sjkh // Determine which sort of error to throw. Out of swap may signal 54630169Sjkh // on the thread stack, which could get a mapping error when touched. 54730169Sjkh address addr = (address) info->si_addr; 54817308Speter if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) { 5495749Swollman vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "Out of swap space to map in thread stack."); 55034520Sbde } 55117308Speter 55217308Speter VMError::report_and_die(t, sig, pc, info, ucVoid); 55330169Sjkh 55426504Sjhay ShouldNotReachHere(); 55530169Sjkh} 55630169Sjkh 5572061Sjkhvoid os::print_context(outputStream *st, void *context) { 55817308Speter if (context == NULL) return; 55917308Speter 56017308Speter ucontext_t *uc = (ucontext_t*)context; 56127910Sasami st->print_cr("Registers:"); 56227910Sasami 5635366Snate st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT 56427910Sasami " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, 56527910Sasami uc->uc_mcontext.gregs[REG_G1], 56627910Sasami uc->uc_mcontext.gregs[REG_G2], 56727910Sasami uc->uc_mcontext.gregs[REG_G3], 56827910Sasami uc->uc_mcontext.gregs[REG_G4]); 56927910Sasami st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT 57027910Sasami " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, 57127910Sasami uc->uc_mcontext.gregs[REG_G5], 57227910Sasami uc->uc_mcontext.gregs[REG_G6], 57327910Sasami uc->uc_mcontext.gregs[REG_G7], 57427910Sasami uc->uc_mcontext.gregs[REG_Y]); 57527910Sasami st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT 57627910Sasami " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, 57734509Sbde uc->uc_mcontext.gregs[REG_O0], 57830113Sjkh uc->uc_mcontext.gregs[REG_O1], 57934623Sbde uc->uc_mcontext.gregs[REG_O2], 58034575Sbde uc->uc_mcontext.gregs[REG_O3]); 58127910Sasami st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT 5825366Snate " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, 58317308Speter uc->uc_mcontext.gregs[REG_O4], 58435427Sbde uc->uc_mcontext.gregs[REG_O5], 58517308Speter uc->uc_mcontext.gregs[REG_O6], 58635427Sbde uc->uc_mcontext.gregs[REG_O7]); 58735427Sbde 58835427Sbde 58935427Sbde intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc); 59035427Sbde st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT 59135427Sbde " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, 59235427Sbde sp[L0->sp_offset_in_saved_window()], 59335427Sbde sp[L1->sp_offset_in_saved_window()], 59435427Sbde sp[L2->sp_offset_in_saved_window()], 59535427Sbde sp[L3->sp_offset_in_saved_window()]); 59635427Sbde st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT 59735427Sbde " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, 59835427Sbde sp[L4->sp_offset_in_saved_window()], 59935427Sbde sp[L5->sp_offset_in_saved_window()], 60035427Sbde sp[L6->sp_offset_in_saved_window()], 60134541Sbde sp[L7->sp_offset_in_saved_window()]); 60235427Sbde st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT 60324754Sjdp " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, 60434541Sbde sp[I0->sp_offset_in_saved_window()], 60535427Sbde sp[I1->sp_offset_in_saved_window()], 60635427Sbde sp[I2->sp_offset_in_saved_window()], 60735427Sbde sp[I3->sp_offset_in_saved_window()]); 60835427Sbde st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT 60935427Sbde " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, 61034541Sbde sp[I4->sp_offset_in_saved_window()], 61135427Sbde sp[I5->sp_offset_in_saved_window()], 61234541Sbde sp[I6->sp_offset_in_saved_window()], 61335427Sbde sp[I7->sp_offset_in_saved_window()]); 6148295Srgrimes 61534541Sbde st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, 61634541Sbde uc->uc_mcontext.gregs[REG_PC], 61735427Sbde uc->uc_mcontext.gregs[REG_nPC]); 61835427Sbde st->cr(); 61934541Sbde st->cr(); 62035427Sbde 62135427Sbde st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); 62235427Sbde print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); 62335427Sbde st->cr(); 62435427Sbde 62534541Sbde // Note: it may be unsafe to inspect memory near pc. For example, pc may 62635427Sbde // point to garbage if entry point in an nmethod is corrupted. Leave 62735427Sbde // this at the end, and hope for the best. 62835427Sbde ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc); 62935427Sbde address pc = epc.pc(); 63034541Sbde st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); 63135427Sbde print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); 63235427Sbde} 63335427Sbde 63435427Sbdevoid os::print_register_info(outputStream *st, void *context) { 63534541Sbde if (context == NULL) return; 63634541Sbde 63734541Sbde ucontext_t *uc = (ucontext_t*)context; 63830113Sjkh intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc); 63930113Sjkh 6408489Srgrimes st->print_cr("Register to memory mapping:"); 64134541Sbde st->cr(); 64235427Sbde 64335427Sbde // this is only for the "general purpose" registers 64435427Sbde st->print("G1="); print_location(st, uc->uc_mcontext.gregs[REG_G1]); 64535427Sbde st->print("G2="); print_location(st, uc->uc_mcontext.gregs[REG_G2]); 64635427Sbde st->print("G3="); print_location(st, uc->uc_mcontext.gregs[REG_G3]); 64735427Sbde st->print("G4="); print_location(st, uc->uc_mcontext.gregs[REG_G4]); 64835427Sbde st->print("G5="); print_location(st, uc->uc_mcontext.gregs[REG_G5]); 64935427Sbde st->print("G6="); print_location(st, uc->uc_mcontext.gregs[REG_G6]); 65035427Sbde st->print("G7="); print_location(st, uc->uc_mcontext.gregs[REG_G7]); 65135427Sbde st->cr(); 65235427Sbde 65335427Sbde st->print("O0="); print_location(st, uc->uc_mcontext.gregs[REG_O0]); 65435427Sbde st->print("O1="); print_location(st, uc->uc_mcontext.gregs[REG_O1]); 65535427Sbde st->print("O2="); print_location(st, uc->uc_mcontext.gregs[REG_O2]); 65635427Sbde st->print("O3="); print_location(st, uc->uc_mcontext.gregs[REG_O3]); 65735427Sbde st->print("O4="); print_location(st, uc->uc_mcontext.gregs[REG_O4]); 65834541Sbde st->print("O5="); print_location(st, uc->uc_mcontext.gregs[REG_O5]); 65935427Sbde st->print("O6="); print_location(st, uc->uc_mcontext.gregs[REG_O6]); 6602160Scsgr st->print("O7="); print_location(st, uc->uc_mcontext.gregs[REG_O7]); 66134541Sbde st->cr(); 66234541Sbde 66335427Sbde st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); 6642626Scsgr st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); 6652061Sjkh st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); 66617308Speter st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); 66717308Speter st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); 66817308Speter st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); 66927910Sasami st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); 67027910Sasami st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); 67127910Sasami st->cr(); 67227910Sasami 67327910Sasami st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); 67427910Sasami st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); 67517308Speter st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); 67611806Sphk st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); 67719175Sbde st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); 67827910Sasami st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); 67927910Sasami st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); 68027910Sasami st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); 68127910Sasami st->cr(); 68227910Sasami} 68327910Sasami 68427910Sasamivoid os::Solaris::init_thread_fpu_state(void) { 68527910Sasami // Nothing needed on Sparc. 68627910Sasami} 68727910Sasami 68827910Sasami#if !defined(COMPILER2) && !defined(_LP64) 68927910Sasami 69027910Sasami// These routines are the initial value of atomic_xchg_entry(), 69127910Sasami// atomic_cmpxchg_entry(), atomic_add_entry() and fence_entry() 69227910Sasami// until initialization is complete. 69327910Sasami// TODO - remove when the VM drops support for V8. 69427910Sasami 69527910Sasamitypedef jint xchg_func_t (jint, volatile jint*); 69627910Sasamitypedef jint cmpxchg_func_t (jint, volatile jint*, jint); 69727910Sasamitypedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong); 69827910Sasamitypedef jint add_func_t (jint, volatile jint*); 69927910Sasami 70034509Sbdejint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) { 70121673Sjkh // try to use the stub: 70227910Sasami xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry()); 70327910Sasami 70427910Sasami if (func != NULL) { 70527910Sasami os::atomic_xchg_func = func; 70627910Sasami return (*func)(exchange_value, dest); 70727910Sasami } 70827910Sasami assert(Threads::number_of_threads() == 0, "for bootstrap only"); 70927910Sasami 71027910Sasami jint old_value = *dest; 71127910Sasami *dest = exchange_value; 71227910Sasami return old_value; 71327910Sasami} 71427910Sasami 71527910Sasamijint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) { 71627910Sasami // try to use the stub: 71727910Sasami cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry()); 71827910Sasami 71927910Sasami if (func != NULL) { 72019175Sbde os::atomic_cmpxchg_func = func; 72127910Sasami return (*func)(exchange_value, dest, compare_value); 72227910Sasami } 72327910Sasami assert(Threads::number_of_threads() == 0, "for bootstrap only"); 72427910Sasami 72527910Sasami jint old_value = *dest; 72627910Sasami if (old_value == compare_value) 72727910Sasami *dest = exchange_value; 72827910Sasami return old_value; 72934688Sbde} 73027910Sasami 73127910Sasamijlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) { 73227910Sasami // try to use the stub: 73327910Sasami cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry()); 73434509Sbde 73530113Sjkh if (func != NULL) { 73630113Sjkh os::atomic_cmpxchg_long_func = func; 73719175Sbde return (*func)(exchange_value, dest, compare_value); 7382061Sjkh } 73930113Sjkh assert(Threads::number_of_threads() == 0, "for bootstrap only"); 74030113Sjkh 74130113Sjkh jlong old_value = *dest; 74235294Sdt if (old_value == compare_value) 74330113Sjkh *dest = exchange_value; 74430113Sjkh return old_value; 74530113Sjkh} 74630113Sjkh 74730113Sjkhjint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) { 74830113Sjkh // try to use the stub: 74930113Sjkh add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry()); 75030113Sjkh 75130113Sjkh if (func != NULL) { 75230113Sjkh os::atomic_add_func = func; 75330113Sjkh return (*func)(add_value, dest); 75430113Sjkh } 75530113Sjkh assert(Threads::number_of_threads() == 0, "for bootstrap only"); 75632427Sjb 75732427Sjb return (*dest) += add_value; 7581594Srgrimes} 759 760xchg_func_t* os::atomic_xchg_func = os::atomic_xchg_bootstrap; 761cmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap; 762cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap; 763add_func_t* os::atomic_add_func = os::atomic_add_bootstrap; 764 765#endif // !_LP64 && !COMPILER2 766 767#if defined(__sparc) && defined(COMPILER2) && defined(_GNU_SOURCE) 768 // See file build/solaris/makefiles/$compiler.make 769 // For compiler1 the architecture is v8 and frps isn't present in v8 770 extern "C" void _mark_fpu_nosave() { 771 __asm__ __volatile__ ("wr %%g0, 0, %%fprs \n\t" : : :); 772 } 773#endif //defined(__sparc) && defined(COMPILER2) 774 775#ifndef PRODUCT 776void os::verify_stack_alignment() { 777} 778#endif 779 780int os::extra_bang_size_in_bytes() { 781 // SPARC does not require an additional stack bang. 782 return 0; 783} 784