0N/A/*
2273N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A// no precompiled headers
1879N/A#include "assembler_sparc.inline.hpp"
1879N/A#include "classfile/classLoader.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "code/icBuffer.hpp"
1879N/A#include "code/vtableStubs.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "jvm_solaris.h"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "mutex_solaris.inline.hpp"
1879N/A#include "nativeInst_sparc.hpp"
1879N/A#include "os_share_solaris.hpp"
1879N/A#include "prims/jniFastGetField.hpp"
1879N/A#include "prims/jvm.h"
1879N/A#include "prims/jvm_misc.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/extendedPC.hpp"
1879N/A#include "runtime/frame.inline.hpp"
1879N/A#include "runtime/interfaceSupport.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/javaCalls.hpp"
1879N/A#include "runtime/mutexLocker.hpp"
1879N/A#include "runtime/osThread.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "runtime/timer.hpp"
1879N/A#include "thread_solaris.inline.hpp"
1879N/A#include "utilities/events.hpp"
1879N/A#include "utilities/vmError.hpp"
0N/A
0N/A# include <signal.h> // needed first to avoid name collision for "std" with SC 5.0
0N/A
0N/A// put OS-includes here
0N/A# include <sys/types.h>
0N/A# include <sys/mman.h>
0N/A# include <pthread.h>
0N/A# include <errno.h>
0N/A# include <dlfcn.h>
0N/A# include <stdio.h>
0N/A# include <unistd.h>
0N/A# include <sys/resource.h>
0N/A# include <thread.h>
0N/A# include <sys/stat.h>
0N/A# include <sys/time.h>
0N/A# include <sys/filio.h>
0N/A# include <sys/utsname.h>
0N/A# include <sys/systeminfo.h>
0N/A# include <sys/socket.h>
0N/A# include <sys/lwp.h>
0N/A# include <pwd.h>
0N/A# include <poll.h>
0N/A# include <sys/lwp.h>
0N/A
0N/A# define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later
0N/A# include <sys/procfs.h> // see comment in <sys/procfs.h>
0N/A
0N/A#define MAX_PATH (2 * K)
0N/A
0N/A// Minimum stack size for the VM. It's easier to document a constant
0N/A// but it's different for x86 and sparc because the page sizes are different.
0N/A#ifdef _LP64
0N/Asize_t os::Solaris::min_stack_allowed = 128*K;
0N/A#else
0N/Asize_t os::Solaris::min_stack_allowed = 96*K;
0N/A#endif
0N/A
0N/Aint os::Solaris::max_register_window_saves_before_flushing() {
0N/A // We should detect this at run time. For now, filling
0N/A // in with a constant.
0N/A return 8;
0N/A}
0N/A
0N/Astatic void handle_unflushed_register_windows(gwindows_t *win) {
0N/A int restore_count = win->wbcnt;
0N/A int i;
0N/A
0N/A for(i=0; i<restore_count; i++) {
0N/A address sp = ((address)win->spbuf[i]) + STACK_BIAS;
0N/A address reg_win = (address)&win->wbuf[i];
0N/A memcpy(sp,reg_win,sizeof(struct rwindow));
0N/A }
0N/A}
0N/A
0N/Achar* os::non_memory_address_word() {
0N/A // Must never look like an address returned by reserve_memory,
0N/A // even in its subfields (as defined by the CPU immediate fields,
0N/A // if the CPU splits constants across multiple instructions).
0N/A // On SPARC, 0 != %hi(any real address), because there is no
0N/A // allocation in the first 1Kb of the virtual address space.
0N/A return (char*) 0;
0N/A}
0N/A
0N/A// Validate a ucontext retrieved from walking a uc_link of a ucontext.
0N/A// There are issues with libthread giving out uc_links for different threads
0N/A// on the same uc_link chain and bad or circular links.
0N/A//
0N/Abool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) {
0N/A if (valid >= suspect ||
0N/A valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags ||
0N/A valid->uc_stack.ss_sp != suspect->uc_stack.ss_sp ||
0N/A valid->uc_stack.ss_size != suspect->uc_stack.ss_size) {
0N/A DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");)
0N/A return false;
0N/A }
0N/A
0N/A if (thread->is_Java_thread()) {
0N/A if (!valid_stack_address(thread, (address)suspect)) {
0N/A DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");)
0N/A return false;
0N/A }
0N/A address _sp = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS);
0N/A if (!valid_stack_address(thread, _sp) ||
0N/A !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) {
0N/A DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");)
0N/A return false;
0N/A }
0N/A }
0N/A return true;
0N/A}
0N/A
0N/A// We will only follow one level of uc_link since there are libthread
0N/A// issues with ucontext linking and it is better to be safe and just
0N/A// let caller retry later.
0N/Aucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread,
0N/A ucontext_t *uc) {
0N/A
0N/A ucontext_t *retuc = NULL;
0N/A
0N/A // Sometimes the topmost register windows are not properly flushed.
0N/A // i.e., if the kernel would have needed to take a page fault
0N/A if (uc != NULL && uc->uc_mcontext.gwins != NULL) {
0N/A ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
0N/A }
0N/A
0N/A if (uc != NULL) {
0N/A if (uc->uc_link == NULL) {
0N/A // cannot validate without uc_link so accept current ucontext
0N/A retuc = uc;
0N/A } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
0N/A // first ucontext is valid so try the next one
0N/A uc = uc->uc_link;
0N/A if (uc->uc_link == NULL) {
0N/A // cannot validate without uc_link so accept current ucontext
0N/A retuc = uc;
0N/A } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
0N/A // the ucontext one level down is also valid so return it
0N/A retuc = uc;
0N/A }
0N/A }
0N/A }
0N/A return retuc;
0N/A}
0N/A
0N/A// Assumes ucontext is valid
0N/AExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) {
0N/A address pc = (address)uc->uc_mcontext.gregs[REG_PC];
0N/A // set npc to zero to avoid using it for safepoint, good for profiling only
0N/A return ExtendedPC(pc);
0N/A}
0N/A
0N/A// Assumes ucontext is valid
0N/Aintptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) {
0N/A return (intptr_t*)((intptr_t)uc->uc_mcontext.gregs[REG_SP] + STACK_BIAS);
0N/A}
0N/A
0N/A// Solaris X86 only
0N/Aintptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) {
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
4141N/Aaddress os::Solaris::ucontext_get_pc(ucontext_t *uc) {
4141N/A return (address) uc->uc_mcontext.gregs[REG_PC];
4141N/A}
4141N/A
4141N/A
0N/A// For Forte Analyzer AsyncGetCallTrace profiling support - thread
0N/A// is currently interrupted by SIGPROF.
0N/A//
0N/A// ret_fp parameter is only used by Solaris X86.
0N/A//
0N/A// The difference between this and os::fetch_frame_from_context() is that
0N/A// here we try to skip nested signal frames.
0N/AExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread,
0N/A ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
0N/A
0N/A assert(thread != NULL, "just checking");
0N/A assert(ret_sp != NULL, "just checking");
0N/A assert(ret_fp == NULL, "just checking");
0N/A
0N/A ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc);
0N/A
0N/A return os::fetch_frame_from_context(luc, ret_sp, ret_fp);
0N/A}
0N/A
0N/A
0N/A// ret_fp parameter is only used by Solaris X86.
0N/AExtendedPC os::fetch_frame_from_context(void* ucVoid,
0N/A intptr_t** ret_sp, intptr_t** ret_fp) {
0N/A
0N/A ExtendedPC epc;
0N/A ucontext_t *uc = (ucontext_t*)ucVoid;
0N/A
0N/A if (uc != NULL) {
0N/A epc = os::Solaris::ucontext_get_ExtendedPC(uc);
0N/A if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc);
0N/A } else {
0N/A // construct empty ExtendedPC for return value checking
0N/A epc = ExtendedPC(NULL);
0N/A if (ret_sp) *ret_sp = (intptr_t *)NULL;
0N/A }
0N/A
0N/A return epc;
0N/A}
0N/A
0N/Aframe os::fetch_frame_from_context(void* ucVoid) {
0N/A intptr_t* sp;
0N/A intptr_t* fp;
0N/A ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
0N/A return frame(sp, frame::unpatchable, epc.pc());
0N/A}
0N/A
0N/Aframe os::get_sender_for_C_frame(frame* fr) {
0N/A return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc());
0N/A}
0N/A
3574N/A// Returns an estimate of the current stack pointer. Result must be guaranteed to
3574N/A// point into the calling threads stack, and be no lower than the current stack
3574N/A// pointer.
3574N/Aaddress os::current_stack_pointer() {
3574N/A volatile int dummy;
3574N/A address sp = (address)&dummy + 8; // %%%% need to confirm if this is right
3574N/A return sp;
3574N/A}
3574N/A
0N/Aframe os::current_frame() {
0N/A intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
0N/A frame myframe(sp, frame::unpatchable,
0N/A CAST_FROM_FN_PTR(address, os::current_frame));
0N/A if (os::is_first_C_frame(&myframe)) {
0N/A // stack is not walkable
0N/A return frame(NULL, NULL, NULL);
0N/A } else {
0N/A return os::get_sender_for_C_frame(&myframe);
0N/A }
0N/A}
0N/A
0N/Astatic int threadgetstate(thread_t tid, int *flags, lwpid_t *lwp, stack_t *ss, gregset_t rs, lwpstatus_t *lwpstatus) {
0N/A char lwpstatusfile[PROCFILE_LENGTH];
0N/A int lwpfd, err;
0N/A
0N/A if (err = os::Solaris::thr_getstate(tid, flags, lwp, ss, rs))
0N/A return (err);
0N/A if (*flags == TRS_LWPID) {
0N/A sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(),
0N/A *lwp);
1887N/A if ((lwpfd = ::open(lwpstatusfile, O_RDONLY)) < 0) {
0N/A perror("thr_mutator_status: open lwpstatus");
0N/A return (EINVAL);
0N/A }
0N/A if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) !=
0N/A sizeof (lwpstatus_t)) {
0N/A perror("thr_mutator_status: read lwpstatus");
1887N/A (void) ::close(lwpfd);
0N/A return (EINVAL);
0N/A }
1887N/A (void) ::close(lwpfd);
0N/A }
0N/A return (0);
0N/A}
0N/A
0N/A
0N/Abool os::is_allocatable(size_t bytes) {
0N/A#ifdef _LP64
0N/A return true;
0N/A#else
0N/A return (bytes <= (size_t)3835*M);
0N/A#endif
0N/A}
0N/A
0N/Aextern "C" void Fetch32PFI () ;
0N/Aextern "C" void Fetch32Resume () ;
0N/Aextern "C" void FetchNPFI () ;
0N/Aextern "C" void FetchNResume () ;
0N/A
2072N/Aextern "C" JNIEXPORT int
2072N/AJVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
2072N/A int abort_if_unrecognized) {
0N/A ucontext_t* uc = (ucontext_t*) ucVoid;
0N/A
0N/A Thread* t = ThreadLocalStorage::get_thread_slow();
0N/A
0N/A SignalHandlerMark shm(t);
0N/A
0N/A if(sig == SIGPIPE || sig == SIGXFSZ) {
0N/A if (os::Solaris::chained_handler(sig, info, ucVoid)) {
0N/A return true;
0N/A } else {
0N/A if (PrintMiscellaneous && (WizardMode || Verbose)) {
0N/A char buf[64];
0N/A warning("Ignoring %s - see 4229104 or 6499219",
0N/A os::exception_name(sig, buf, sizeof(buf)));
0N/A
0N/A }
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A JavaThread* thread = NULL;
0N/A VMThread* vmthread = NULL;
0N/A if (os::Solaris::signal_handlers_are_installed) {
0N/A if (t != NULL ){
0N/A if(t->is_Java_thread()) {
0N/A thread = (JavaThread*)t;
0N/A }
0N/A else if(t->is_VM_thread()){
0N/A vmthread = (VMThread *)t;
0N/A }
0N/A }
0N/A }
0N/A
0N/A guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs");
0N/A
0N/A if (sig == os::Solaris::SIGasync()) {
4141N/A if (thread || vmthread) {
4141N/A OSThread::SR_handler(t, uc);
0N/A return true;
0N/A } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
0N/A return true;
0N/A } else {
0N/A // If os::Solaris::SIGasync not chained, and this is a non-vm and
0N/A // non-java thread
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
0N/A // can't decode this kind of signal
0N/A info = NULL;
0N/A } else {
0N/A assert(sig == info->si_signo, "bad siginfo");
0N/A }
0N/A
0N/A // decide if this trap can be handled by a stub
0N/A address stub = NULL;
0N/A
0N/A address pc = NULL;
0N/A address npc = NULL;
0N/A
0N/A //%note os_trap_1
0N/A if (info != NULL && uc != NULL && thread != NULL) {
0N/A // factor me: getPCfromContext
0N/A pc = (address) uc->uc_mcontext.gregs[REG_PC];
0N/A npc = (address) uc->uc_mcontext.gregs[REG_nPC];
0N/A
0N/A // SafeFetch() support
0N/A // Implemented with either a fixed set of addresses such
0N/A // as Fetch32*, or with Thread._OnTrap.
0N/A if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(Fetch32PFI)) {
0N/A uc->uc_mcontext.gregs [REG_PC] = intptr_t(Fetch32Resume) ;
0N/A uc->uc_mcontext.gregs [REG_nPC] = intptr_t(Fetch32Resume) + 4 ;
0N/A return true ;
0N/A }
0N/A if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(FetchNPFI)) {
0N/A uc->uc_mcontext.gregs [REG_PC] = intptr_t(FetchNResume) ;
0N/A uc->uc_mcontext.gregs [REG_nPC] = intptr_t(FetchNResume) + 4 ;
0N/A return true ;
0N/A }
0N/A
0N/A // Handle ALL stack overflow variations here
0N/A if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
0N/A address addr = (address) info->si_addr;
0N/A if (thread->in_stack_yellow_zone(addr)) {
0N/A thread->disable_stack_yellow_zone();
0N/A // Sometimes the register windows are not properly flushed.
0N/A if(uc->uc_mcontext.gwins != NULL) {
0N/A ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
0N/A }
0N/A if (thread->thread_state() == _thread_in_Java) {
0N/A // Throw a stack overflow exception. Guard pages will be reenabled
0N/A // while unwinding the stack.
0N/A stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
0N/A } else {
0N/A // Thread was in the vm or native code. Return and try to finish.
0N/A return true;
0N/A }
0N/A } else if (thread->in_stack_red_zone(addr)) {
0N/A // Fatal red zone violation. Disable the guard pages and fall through
0N/A // to handle_unexpected_exception way down below.
0N/A thread->disable_stack_red_zone();
0N/A tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
0N/A // Sometimes the register windows are not properly flushed.
0N/A if(uc->uc_mcontext.gwins != NULL) {
0N/A ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A if (thread->thread_state() == _thread_in_vm) {
0N/A if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) {
0N/A stub = StubRoutines::handler_for_unsafe_access();
0N/A }
0N/A }
0N/A
0N/A else if (thread->thread_state() == _thread_in_Java) {
0N/A // Java thread running in Java code => find exception handler if any
0N/A // a fault inside compiled code, the interpreter, or a stub
0N/A
0N/A // Support Safepoint Polling
0N/A if ( sig == SIGSEGV && (address)info->si_addr == os::get_polling_page() ) {
0N/A stub = SharedRuntime::get_poll_stub(pc);
0N/A }
0N/A
0N/A // Not needed on x86 solaris because verify_oops doesn't generate
0N/A // SEGV/BUS like sparc does.
0N/A if ( (sig == SIGSEGV || sig == SIGBUS)
0N/A && pc >= MacroAssembler::_verify_oop_implicit_branch[0]
0N/A && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) {
0N/A stub = MacroAssembler::_verify_oop_implicit_branch[2];
0N/A warning("fixed up memory fault in +VerifyOops at address " INTPTR_FORMAT, info->si_addr);
0N/A }
0N/A
0N/A // This is not factored because on x86 solaris the patching for
0N/A // zombies does not generate a SEGV.
0N/A else if (sig == SIGSEGV && nativeInstruction_at(pc)->is_zombie()) {
0N/A // zombie method (ld [%g0],%o7 instruction)
0N/A stub = SharedRuntime::get_handle_wrong_method_stub();
0N/A
0N/A // At the stub it needs to look like a call from the caller of this
0N/A // method (not a call from the segv site).
0N/A pc = (address)uc->uc_mcontext.gregs[REG_O7];
0N/A }
0N/A else if (sig == SIGBUS && info->si_code == BUS_OBJERR) {
0N/A // BugId 4454115: A read from a MappedByteBuffer can fault
0N/A // here if the underlying file has been truncated.
0N/A // Do not crash the VM in such a case.
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
0N/A nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
0N/A if (nm != NULL && nm->has_unsafe_access()) {
0N/A stub = StubRoutines::handler_for_unsafe_access();
0N/A }
0N/A }
0N/A
0N/A else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
0N/A // integer divide by zero
0N/A stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
0N/A }
0N/A else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) {
0N/A // floating-point divide by zero
0N/A stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
0N/A }
0N/A#ifdef COMPILER2
0N/A else if (sig == SIGILL && nativeInstruction_at(pc)->is_ic_miss_trap()) {
0N/A#ifdef ASSERT
0N/A #ifdef TIERED
0N/A CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
0N/A assert(cb->is_compiled_by_c2(), "Wrong compiler");
0N/A #endif // TIERED
0N/A#endif // ASSERT
0N/A // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken.
0N/A stub = SharedRuntime::get_ic_miss_stub();
0N/A // At the stub it needs to look like a call from the caller of this
0N/A // method (not a call from the segv site).
0N/A pc = (address)uc->uc_mcontext.gregs[REG_O7];
0N/A }
0N/A#endif // COMPILER2
0N/A
0N/A else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
0N/A // Determination of interpreter/vtable stub/compiled code null exception
0N/A stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
0N/A }
0N/A }
0N/A
0N/A // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
0N/A // and the heap gets shrunk before the field access.
0N/A if ((sig == SIGSEGV) || (sig == SIGBUS)) {
0N/A address addr = JNI_FastGetField::find_slowcase_pc(pc);
0N/A if (addr != (address)-1) {
0N/A stub = addr;
0N/A }
0N/A }
0N/A
0N/A // Check to see if we caught the safepoint code in the
0N/A // process of write protecting the memory serialization page.
0N/A // It write enables the page immediately after protecting it
0N/A // so just return.
0N/A if ((sig == SIGSEGV) &&
0N/A os::is_memory_serialize_page(thread, (address)info->si_addr)) {
0N/A // Block current thread until the memory serialize page permission restored.
0N/A os::block_on_serialize_page_trap();
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A if (stub != NULL) {
0N/A // save all thread context in case we need to restore it
0N/A
0N/A thread->set_saved_exception_pc(pc);
0N/A thread->set_saved_exception_npc(npc);
0N/A
0N/A // simulate a branch to the stub (a "call" in the safepoint stub case)
0N/A // factor me: setPC
0N/A uc->uc_mcontext.gregs[REG_PC ] = (greg_t)stub;
0N/A uc->uc_mcontext.gregs[REG_nPC] = (greg_t)(stub + 4);
0N/A
0N/A#ifndef PRODUCT
0N/A if (TraceJumps) thread->record_jump(stub, NULL, __FILE__, __LINE__);
0N/A#endif /* PRODUCT */
0N/A
0N/A return true;
0N/A }
0N/A
0N/A // signal-chaining
0N/A if (os::Solaris::chained_handler(sig, info, ucVoid)) {
0N/A return true;
0N/A }
0N/A
0N/A if (!abort_if_unrecognized) {
0N/A // caller wants another chance, so give it to him
0N/A return false;
0N/A }
0N/A
0N/A if (!os::Solaris::libjsig_is_loaded) {
0N/A struct sigaction oldAct;
0N/A sigaction(sig, (struct sigaction *)0, &oldAct);
0N/A if (oldAct.sa_sigaction != signalHandler) {
0N/A void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
0N/A : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
605N/A warning("Unexpected Signal %d occurred under user-defined signal handler " INTPTR_FORMAT, sig, (intptr_t)sighand);
0N/A }
0N/A }
0N/A
0N/A if (pc == NULL && uc != NULL) {
0N/A pc = (address) uc->uc_mcontext.gregs[REG_PC];
0N/A }
0N/A
1827N/A // Sometimes the register windows are not properly flushed.
1827N/A if(uc->uc_mcontext.gwins != NULL) {
1827N/A ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
1827N/A }
1827N/A
0N/A // unmask current signal
0N/A sigset_t newset;
0N/A sigemptyset(&newset);
0N/A sigaddset(&newset, sig);
0N/A sigprocmask(SIG_UNBLOCK, &newset, NULL);
0N/A
1983N/A // Determine which sort of error to throw. Out of swap may signal
1983N/A // on the thread stack, which could get a mapping error when touched.
1983N/A address addr = (address) info->si_addr;
1983N/A if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) {
1983N/A vm_exit_out_of_memory(0, "Out of swap space to map in thread stack.");
1983N/A }
1983N/A
0N/A VMError err(t, sig, pc, info, ucVoid);
0N/A err.report_and_die();
0N/A
0N/A ShouldNotReachHere();
0N/A}
0N/A
0N/Avoid os::print_context(outputStream *st, void *context) {
0N/A if (context == NULL) return;
0N/A
0N/A ucontext_t *uc = (ucontext_t*)context;
0N/A st->print_cr("Registers:");
0N/A
1827N/A st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT
1827N/A " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT,
1827N/A uc->uc_mcontext.gregs[REG_G1],
1827N/A uc->uc_mcontext.gregs[REG_G2],
1827N/A uc->uc_mcontext.gregs[REG_G3],
1827N/A uc->uc_mcontext.gregs[REG_G4]);
1827N/A st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT
1827N/A " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT,
1827N/A uc->uc_mcontext.gregs[REG_G5],
1827N/A uc->uc_mcontext.gregs[REG_G6],
1827N/A uc->uc_mcontext.gregs[REG_G7],
1827N/A uc->uc_mcontext.gregs[REG_Y]);
0N/A st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT
0N/A " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT,
0N/A uc->uc_mcontext.gregs[REG_O0],
0N/A uc->uc_mcontext.gregs[REG_O1],
0N/A uc->uc_mcontext.gregs[REG_O2],
0N/A uc->uc_mcontext.gregs[REG_O3]);
0N/A st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT
0N/A " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT,
0N/A uc->uc_mcontext.gregs[REG_O4],
0N/A uc->uc_mcontext.gregs[REG_O5],
0N/A uc->uc_mcontext.gregs[REG_O6],
0N/A uc->uc_mcontext.gregs[REG_O7]);
0N/A
1827N/A
1827N/A intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
1827N/A st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT
1827N/A " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT,
1827N/A sp[L0->sp_offset_in_saved_window()],
1827N/A sp[L1->sp_offset_in_saved_window()],
1827N/A sp[L2->sp_offset_in_saved_window()],
1827N/A sp[L3->sp_offset_in_saved_window()]);
1827N/A st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT
1827N/A " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT,
1827N/A sp[L4->sp_offset_in_saved_window()],
1827N/A sp[L5->sp_offset_in_saved_window()],
1827N/A sp[L6->sp_offset_in_saved_window()],
1827N/A sp[L7->sp_offset_in_saved_window()]);
1827N/A st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT
1827N/A " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT,
1827N/A sp[I0->sp_offset_in_saved_window()],
1827N/A sp[I1->sp_offset_in_saved_window()],
1827N/A sp[I2->sp_offset_in_saved_window()],
1827N/A sp[I3->sp_offset_in_saved_window()]);
1827N/A st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT
1827N/A " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT,
1827N/A sp[I4->sp_offset_in_saved_window()],
1827N/A sp[I5->sp_offset_in_saved_window()],
1827N/A sp[I6->sp_offset_in_saved_window()],
1827N/A sp[I7->sp_offset_in_saved_window()]);
0N/A
0N/A st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT,
0N/A uc->uc_mcontext.gregs[REG_PC],
0N/A uc->uc_mcontext.gregs[REG_nPC]);
1601N/A st->cr();
1601N/A st->cr();
1601N/A
0N/A st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
0N/A print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
0N/A st->cr();
0N/A
0N/A // Note: it may be unsafe to inspect memory near pc. For example, pc may
0N/A // point to garbage if entry point in an nmethod is corrupted. Leave
0N/A // this at the end, and hope for the best.
0N/A ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc);
0N/A address pc = epc.pc();
0N/A st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
1827N/A print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
1827N/A}
1827N/A
1827N/Avoid os::print_register_info(outputStream *st, void *context) {
1827N/A if (context == NULL) return;
1827N/A
1827N/A ucontext_t *uc = (ucontext_t*)context;
1827N/A intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
1827N/A
1827N/A st->print_cr("Register to memory mapping:");
1827N/A st->cr();
1827N/A
1827N/A // this is only for the "general purpose" registers
1827N/A st->print("G1="); print_location(st, uc->uc_mcontext.gregs[REG_G1]);
1827N/A st->print("G2="); print_location(st, uc->uc_mcontext.gregs[REG_G2]);
1827N/A st->print("G3="); print_location(st, uc->uc_mcontext.gregs[REG_G3]);
1827N/A st->print("G4="); print_location(st, uc->uc_mcontext.gregs[REG_G4]);
1827N/A st->print("G5="); print_location(st, uc->uc_mcontext.gregs[REG_G5]);
1827N/A st->print("G6="); print_location(st, uc->uc_mcontext.gregs[REG_G6]);
1827N/A st->print("G7="); print_location(st, uc->uc_mcontext.gregs[REG_G7]);
1827N/A st->cr();
1827N/A
1827N/A st->print("O0="); print_location(st, uc->uc_mcontext.gregs[REG_O0]);
1827N/A st->print("O1="); print_location(st, uc->uc_mcontext.gregs[REG_O1]);
1827N/A st->print("O2="); print_location(st, uc->uc_mcontext.gregs[REG_O2]);
1827N/A st->print("O3="); print_location(st, uc->uc_mcontext.gregs[REG_O3]);
1827N/A st->print("O4="); print_location(st, uc->uc_mcontext.gregs[REG_O4]);
1827N/A st->print("O5="); print_location(st, uc->uc_mcontext.gregs[REG_O5]);
1827N/A st->print("O6="); print_location(st, uc->uc_mcontext.gregs[REG_O6]);
1827N/A st->print("O7="); print_location(st, uc->uc_mcontext.gregs[REG_O7]);
1827N/A st->cr();
1827N/A
1827N/A st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]);
1827N/A st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]);
1827N/A st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]);
1827N/A st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]);
1827N/A st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]);
1827N/A st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]);
1827N/A st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]);
1827N/A st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]);
1827N/A st->cr();
1827N/A
1827N/A st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]);
1827N/A st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]);
1827N/A st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]);
1827N/A st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]);
1827N/A st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]);
1827N/A st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]);
1827N/A st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]);
1827N/A st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]);
1827N/A st->cr();
0N/A}
0N/A
0N/Avoid os::Solaris::init_thread_fpu_state(void) {
0N/A // Nothing needed on Sparc.
0N/A}
0N/A
0N/A#if !defined(COMPILER2) && !defined(_LP64)
0N/A
0N/A// These routines are the initial value of atomic_xchg_entry(),
0N/A// atomic_cmpxchg_entry(), atomic_add_entry() and fence_entry()
0N/A// until initialization is complete.
0N/A// TODO - remove when the VM drops support for V8.
0N/A
0N/Atypedef jint xchg_func_t (jint, volatile jint*);
0N/Atypedef jint cmpxchg_func_t (jint, volatile jint*, jint);
0N/Atypedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong);
0N/Atypedef jint add_func_t (jint, volatile jint*);
0N/A
0N/Ajint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) {
0N/A // try to use the stub:
0N/A xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
0N/A
0N/A if (func != NULL) {
0N/A os::atomic_xchg_func = func;
0N/A return (*func)(exchange_value, dest);
0N/A }
0N/A assert(Threads::number_of_threads() == 0, "for bootstrap only");
0N/A
0N/A jint old_value = *dest;
0N/A *dest = exchange_value;
0N/A return old_value;
0N/A}
0N/A
0N/Ajint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) {
0N/A // try to use the stub:
0N/A cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
0N/A
0N/A if (func != NULL) {
0N/A os::atomic_cmpxchg_func = func;
0N/A return (*func)(exchange_value, dest, compare_value);
0N/A }
0N/A assert(Threads::number_of_threads() == 0, "for bootstrap only");
0N/A
0N/A jint old_value = *dest;
0N/A if (old_value == compare_value)
0N/A *dest = exchange_value;
0N/A return old_value;
0N/A}
0N/A
0N/Ajlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) {
0N/A // try to use the stub:
0N/A cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry());
0N/A
0N/A if (func != NULL) {
0N/A os::atomic_cmpxchg_long_func = func;
0N/A return (*func)(exchange_value, dest, compare_value);
0N/A }
0N/A assert(Threads::number_of_threads() == 0, "for bootstrap only");
0N/A
0N/A jlong old_value = *dest;
0N/A if (old_value == compare_value)
0N/A *dest = exchange_value;
0N/A return old_value;
0N/A}
0N/A
0N/Ajint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) {
0N/A // try to use the stub:
0N/A add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
0N/A
0N/A if (func != NULL) {
0N/A os::atomic_add_func = func;
0N/A return (*func)(add_value, dest);
0N/A }
0N/A assert(Threads::number_of_threads() == 0, "for bootstrap only");
0N/A
0N/A return (*dest) += add_value;
0N/A}
0N/A
0N/Axchg_func_t* os::atomic_xchg_func = os::atomic_xchg_bootstrap;
0N/Acmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap;
0N/Acmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
0N/Aadd_func_t* os::atomic_add_func = os::atomic_add_bootstrap;
0N/A
0N/A#endif // !_LP64 && !COMPILER2
0N/A
0N/A#if defined(__sparc) && defined(COMPILER2) && defined(_GNU_SOURCE)
0N/A // See file build/solaris/makefiles/$compiler.make
0N/A // For compiler1 the architecture is v8 and frps isn't present in v8
0N/A extern "C" void _mark_fpu_nosave() {
0N/A __asm__ __volatile__ ("wr %%g0, 0, %%fprs \n\t" : : :);
0N/A }
0N/A#endif //defined(__sparc) && defined(COMPILER2)
3574N/A
3574N/A#ifndef PRODUCT
3574N/Avoid os::verify_stack_alignment() {
3574N/A}
3574N/A#endif