src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp

Tue, 01 Feb 2011 11:23:19 -0500

author
coleenp
date
Tue, 01 Feb 2011 11:23:19 -0500
changeset 2507
d70fe6ab4436
parent 2418
36c186bcc085
child 2708
1d1603768966
permissions
-rw-r--r--

6588413: Use -fvisibility=hidden for gcc compiles
Summary: Add option for gcc 4 and above, define JNIEXPORT and JNIIMPORT to visibility=default, add for jio_snprintf and others since -fvisibility=hidden overrides --version-script definitions.
Reviewed-by: kamg, never

duke@435 1 /*
never@2262 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 // no precompiled headers
stefank@2314 26 #include "assembler_sparc.inline.hpp"
stefank@2314 27 #include "classfile/classLoader.hpp"
stefank@2314 28 #include "classfile/systemDictionary.hpp"
stefank@2314 29 #include "classfile/vmSymbols.hpp"
stefank@2314 30 #include "code/icBuffer.hpp"
stefank@2314 31 #include "code/vtableStubs.hpp"
stefank@2314 32 #include "interpreter/interpreter.hpp"
stefank@2314 33 #include "jvm_solaris.h"
stefank@2314 34 #include "memory/allocation.inline.hpp"
stefank@2314 35 #include "mutex_solaris.inline.hpp"
stefank@2314 36 #include "nativeInst_sparc.hpp"
stefank@2314 37 #include "os_share_solaris.hpp"
stefank@2314 38 #include "prims/jniFastGetField.hpp"
stefank@2314 39 #include "prims/jvm.h"
stefank@2314 40 #include "prims/jvm_misc.hpp"
stefank@2314 41 #include "runtime/arguments.hpp"
stefank@2314 42 #include "runtime/extendedPC.hpp"
stefank@2314 43 #include "runtime/frame.inline.hpp"
stefank@2314 44 #include "runtime/interfaceSupport.hpp"
stefank@2314 45 #include "runtime/java.hpp"
stefank@2314 46 #include "runtime/javaCalls.hpp"
stefank@2314 47 #include "runtime/mutexLocker.hpp"
stefank@2314 48 #include "runtime/osThread.hpp"
stefank@2314 49 #include "runtime/sharedRuntime.hpp"
stefank@2314 50 #include "runtime/stubRoutines.hpp"
stefank@2314 51 #include "runtime/timer.hpp"
stefank@2314 52 #include "thread_solaris.inline.hpp"
stefank@2314 53 #include "utilities/events.hpp"
stefank@2314 54 #include "utilities/vmError.hpp"
stefank@2314 55 #ifdef COMPILER1
stefank@2314 56 #include "c1/c1_Runtime1.hpp"
stefank@2314 57 #endif
stefank@2314 58 #ifdef COMPILER2
stefank@2314 59 #include "opto/runtime.hpp"
stefank@2314 60 #endif
stefank@2314 61
duke@435 62
duke@435 63 # include <signal.h> // needed first to avoid name collision for "std" with SC 5.0
duke@435 64
duke@435 65 // put OS-includes here
duke@435 66 # include <sys/types.h>
duke@435 67 # include <sys/mman.h>
duke@435 68 # include <pthread.h>
duke@435 69 # include <errno.h>
duke@435 70 # include <dlfcn.h>
duke@435 71 # include <stdio.h>
duke@435 72 # include <unistd.h>
duke@435 73 # include <sys/resource.h>
duke@435 74 # include <thread.h>
duke@435 75 # include <sys/stat.h>
duke@435 76 # include <sys/time.h>
duke@435 77 # include <sys/filio.h>
duke@435 78 # include <sys/utsname.h>
duke@435 79 # include <sys/systeminfo.h>
duke@435 80 # include <sys/socket.h>
duke@435 81 # include <sys/lwp.h>
duke@435 82 # include <pwd.h>
duke@435 83 # include <poll.h>
duke@435 84 # include <sys/lwp.h>
duke@435 85
duke@435 86 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later
duke@435 87 # include <sys/procfs.h> // see comment in <sys/procfs.h>
duke@435 88
duke@435 89 #define MAX_PATH (2 * K)
duke@435 90
duke@435 91 // Minimum stack size for the VM. It's easier to document a constant
duke@435 92 // but it's different for x86 and sparc because the page sizes are different.
duke@435 93 #ifdef _LP64
duke@435 94 size_t os::Solaris::min_stack_allowed = 128*K;
duke@435 95 #else
duke@435 96 size_t os::Solaris::min_stack_allowed = 96*K;
duke@435 97 #endif
duke@435 98
duke@435 99 int os::Solaris::max_register_window_saves_before_flushing() {
duke@435 100 // We should detect this at run time. For now, filling
duke@435 101 // in with a constant.
duke@435 102 return 8;
duke@435 103 }
duke@435 104
duke@435 105 static void handle_unflushed_register_windows(gwindows_t *win) {
duke@435 106 int restore_count = win->wbcnt;
duke@435 107 int i;
duke@435 108
duke@435 109 for(i=0; i<restore_count; i++) {
duke@435 110 address sp = ((address)win->spbuf[i]) + STACK_BIAS;
duke@435 111 address reg_win = (address)&win->wbuf[i];
duke@435 112 memcpy(sp,reg_win,sizeof(struct rwindow));
duke@435 113 }
duke@435 114 }
duke@435 115
duke@435 116 char* os::non_memory_address_word() {
duke@435 117 // Must never look like an address returned by reserve_memory,
duke@435 118 // even in its subfields (as defined by the CPU immediate fields,
duke@435 119 // if the CPU splits constants across multiple instructions).
duke@435 120 // On SPARC, 0 != %hi(any real address), because there is no
duke@435 121 // allocation in the first 1Kb of the virtual address space.
duke@435 122 return (char*) 0;
duke@435 123 }
duke@435 124
duke@435 125 // Validate a ucontext retrieved from walking a uc_link of a ucontext.
duke@435 126 // There are issues with libthread giving out uc_links for different threads
duke@435 127 // on the same uc_link chain and bad or circular links.
duke@435 128 //
duke@435 129 bool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) {
duke@435 130 if (valid >= suspect ||
duke@435 131 valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags ||
duke@435 132 valid->uc_stack.ss_sp != suspect->uc_stack.ss_sp ||
duke@435 133 valid->uc_stack.ss_size != suspect->uc_stack.ss_size) {
duke@435 134 DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");)
duke@435 135 return false;
duke@435 136 }
duke@435 137
duke@435 138 if (thread->is_Java_thread()) {
duke@435 139 if (!valid_stack_address(thread, (address)suspect)) {
duke@435 140 DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");)
duke@435 141 return false;
duke@435 142 }
duke@435 143 address _sp = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS);
duke@435 144 if (!valid_stack_address(thread, _sp) ||
duke@435 145 !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) {
duke@435 146 DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");)
duke@435 147 return false;
duke@435 148 }
duke@435 149 }
duke@435 150 return true;
duke@435 151 }
duke@435 152
duke@435 153 // We will only follow one level of uc_link since there are libthread
duke@435 154 // issues with ucontext linking and it is better to be safe and just
duke@435 155 // let caller retry later.
duke@435 156 ucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread,
duke@435 157 ucontext_t *uc) {
duke@435 158
duke@435 159 ucontext_t *retuc = NULL;
duke@435 160
duke@435 161 // Sometimes the topmost register windows are not properly flushed.
duke@435 162 // i.e., if the kernel would have needed to take a page fault
duke@435 163 if (uc != NULL && uc->uc_mcontext.gwins != NULL) {
duke@435 164 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
duke@435 165 }
duke@435 166
duke@435 167 if (uc != NULL) {
duke@435 168 if (uc->uc_link == NULL) {
duke@435 169 // cannot validate without uc_link so accept current ucontext
duke@435 170 retuc = uc;
duke@435 171 } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
duke@435 172 // first ucontext is valid so try the next one
duke@435 173 uc = uc->uc_link;
duke@435 174 if (uc->uc_link == NULL) {
duke@435 175 // cannot validate without uc_link so accept current ucontext
duke@435 176 retuc = uc;
duke@435 177 } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
duke@435 178 // the ucontext one level down is also valid so return it
duke@435 179 retuc = uc;
duke@435 180 }
duke@435 181 }
duke@435 182 }
duke@435 183 return retuc;
duke@435 184 }
duke@435 185
duke@435 186 // Assumes ucontext is valid
duke@435 187 ExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) {
duke@435 188 address pc = (address)uc->uc_mcontext.gregs[REG_PC];
duke@435 189 // set npc to zero to avoid using it for safepoint, good for profiling only
duke@435 190 return ExtendedPC(pc);
duke@435 191 }
duke@435 192
duke@435 193 // Assumes ucontext is valid
duke@435 194 intptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) {
duke@435 195 return (intptr_t*)((intptr_t)uc->uc_mcontext.gregs[REG_SP] + STACK_BIAS);
duke@435 196 }
duke@435 197
duke@435 198 // Solaris X86 only
duke@435 199 intptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) {
duke@435 200 ShouldNotReachHere();
duke@435 201 return NULL;
duke@435 202 }
duke@435 203
duke@435 204 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
duke@435 205 // is currently interrupted by SIGPROF.
duke@435 206 //
duke@435 207 // ret_fp parameter is only used by Solaris X86.
duke@435 208 //
duke@435 209 // The difference between this and os::fetch_frame_from_context() is that
duke@435 210 // here we try to skip nested signal frames.
duke@435 211 ExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread,
duke@435 212 ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
duke@435 213
duke@435 214 assert(thread != NULL, "just checking");
duke@435 215 assert(ret_sp != NULL, "just checking");
duke@435 216 assert(ret_fp == NULL, "just checking");
duke@435 217
duke@435 218 ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc);
duke@435 219
duke@435 220 return os::fetch_frame_from_context(luc, ret_sp, ret_fp);
duke@435 221 }
duke@435 222
duke@435 223
duke@435 224 // ret_fp parameter is only used by Solaris X86.
duke@435 225 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
duke@435 226 intptr_t** ret_sp, intptr_t** ret_fp) {
duke@435 227
duke@435 228 ExtendedPC epc;
duke@435 229 ucontext_t *uc = (ucontext_t*)ucVoid;
duke@435 230
duke@435 231 if (uc != NULL) {
duke@435 232 epc = os::Solaris::ucontext_get_ExtendedPC(uc);
duke@435 233 if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc);
duke@435 234 } else {
duke@435 235 // construct empty ExtendedPC for return value checking
duke@435 236 epc = ExtendedPC(NULL);
duke@435 237 if (ret_sp) *ret_sp = (intptr_t *)NULL;
duke@435 238 }
duke@435 239
duke@435 240 return epc;
duke@435 241 }
duke@435 242
duke@435 243 frame os::fetch_frame_from_context(void* ucVoid) {
duke@435 244 intptr_t* sp;
duke@435 245 intptr_t* fp;
duke@435 246 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
duke@435 247 return frame(sp, frame::unpatchable, epc.pc());
duke@435 248 }
duke@435 249
duke@435 250 frame os::get_sender_for_C_frame(frame* fr) {
duke@435 251 return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc());
duke@435 252 }
duke@435 253
duke@435 254 frame os::current_frame() {
duke@435 255 intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
duke@435 256 frame myframe(sp, frame::unpatchable,
duke@435 257 CAST_FROM_FN_PTR(address, os::current_frame));
duke@435 258 if (os::is_first_C_frame(&myframe)) {
duke@435 259 // stack is not walkable
duke@435 260 return frame(NULL, NULL, NULL);
duke@435 261 } else {
duke@435 262 return os::get_sender_for_C_frame(&myframe);
duke@435 263 }
duke@435 264 }
duke@435 265
duke@435 266
duke@435 267 void GetThreadPC_Callback::execute(OSThread::InterruptArguments *args) {
duke@435 268 Thread* thread = args->thread();
duke@435 269 ucontext_t* uc = args->ucontext();
duke@435 270 intptr_t* sp;
duke@435 271
duke@435 272 assert(ProfileVM && thread->is_VM_thread(), "just checking");
duke@435 273
duke@435 274 // Skip the mcontext corruption verification. If if occasionally
duke@435 275 // things get corrupt, it is ok for profiling - we will just get an unresolved
duke@435 276 // function name
duke@435 277 ExtendedPC new_addr((address)uc->uc_mcontext.gregs[REG_PC]);
duke@435 278 _addr = new_addr;
duke@435 279 }
duke@435 280
duke@435 281
duke@435 282 static int threadgetstate(thread_t tid, int *flags, lwpid_t *lwp, stack_t *ss, gregset_t rs, lwpstatus_t *lwpstatus) {
duke@435 283 char lwpstatusfile[PROCFILE_LENGTH];
duke@435 284 int lwpfd, err;
duke@435 285
duke@435 286 if (err = os::Solaris::thr_getstate(tid, flags, lwp, ss, rs))
duke@435 287 return (err);
duke@435 288 if (*flags == TRS_LWPID) {
duke@435 289 sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(),
duke@435 290 *lwp);
ikrylov@2322 291 if ((lwpfd = ::open(lwpstatusfile, O_RDONLY)) < 0) {
duke@435 292 perror("thr_mutator_status: open lwpstatus");
duke@435 293 return (EINVAL);
duke@435 294 }
duke@435 295 if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) !=
duke@435 296 sizeof (lwpstatus_t)) {
duke@435 297 perror("thr_mutator_status: read lwpstatus");
ikrylov@2322 298 (void) ::close(lwpfd);
duke@435 299 return (EINVAL);
duke@435 300 }
ikrylov@2322 301 (void) ::close(lwpfd);
duke@435 302 }
duke@435 303 return (0);
duke@435 304 }
duke@435 305
duke@435 306
duke@435 307 bool os::is_allocatable(size_t bytes) {
duke@435 308 #ifdef _LP64
duke@435 309 return true;
duke@435 310 #else
duke@435 311 return (bytes <= (size_t)3835*M);
duke@435 312 #endif
duke@435 313 }
duke@435 314
duke@435 315 extern "C" void Fetch32PFI () ;
duke@435 316 extern "C" void Fetch32Resume () ;
duke@435 317 extern "C" void FetchNPFI () ;
duke@435 318 extern "C" void FetchNResume () ;
duke@435 319
coleenp@2507 320 extern "C" JNIEXPORT int
coleenp@2507 321 JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
coleenp@2507 322 int abort_if_unrecognized) {
duke@435 323 ucontext_t* uc = (ucontext_t*) ucVoid;
duke@435 324
duke@435 325 Thread* t = ThreadLocalStorage::get_thread_slow();
duke@435 326
duke@435 327 SignalHandlerMark shm(t);
duke@435 328
duke@435 329 if(sig == SIGPIPE || sig == SIGXFSZ) {
duke@435 330 if (os::Solaris::chained_handler(sig, info, ucVoid)) {
duke@435 331 return true;
duke@435 332 } else {
duke@435 333 if (PrintMiscellaneous && (WizardMode || Verbose)) {
duke@435 334 char buf[64];
duke@435 335 warning("Ignoring %s - see 4229104 or 6499219",
duke@435 336 os::exception_name(sig, buf, sizeof(buf)));
duke@435 337
duke@435 338 }
duke@435 339 return true;
duke@435 340 }
duke@435 341 }
duke@435 342
duke@435 343 JavaThread* thread = NULL;
duke@435 344 VMThread* vmthread = NULL;
duke@435 345 if (os::Solaris::signal_handlers_are_installed) {
duke@435 346 if (t != NULL ){
duke@435 347 if(t->is_Java_thread()) {
duke@435 348 thread = (JavaThread*)t;
duke@435 349 }
duke@435 350 else if(t->is_VM_thread()){
duke@435 351 vmthread = (VMThread *)t;
duke@435 352 }
duke@435 353 }
duke@435 354 }
duke@435 355
duke@435 356 guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs");
duke@435 357
duke@435 358 if (sig == os::Solaris::SIGasync()) {
duke@435 359 if (thread) {
duke@435 360 OSThread::InterruptArguments args(thread, uc);
duke@435 361 thread->osthread()->do_interrupt_callbacks_at_interrupt(&args);
duke@435 362 return true;
duke@435 363 } else if (vmthread) {
duke@435 364 OSThread::InterruptArguments args(vmthread, uc);
duke@435 365 vmthread->osthread()->do_interrupt_callbacks_at_interrupt(&args);
duke@435 366 return true;
duke@435 367 } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
duke@435 368 return true;
duke@435 369 } else {
duke@435 370 // If os::Solaris::SIGasync not chained, and this is a non-vm and
duke@435 371 // non-java thread
duke@435 372 return true;
duke@435 373 }
duke@435 374 }
duke@435 375
duke@435 376 if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
duke@435 377 // can't decode this kind of signal
duke@435 378 info = NULL;
duke@435 379 } else {
duke@435 380 assert(sig == info->si_signo, "bad siginfo");
duke@435 381 }
duke@435 382
duke@435 383 // decide if this trap can be handled by a stub
duke@435 384 address stub = NULL;
duke@435 385
duke@435 386 address pc = NULL;
duke@435 387 address npc = NULL;
duke@435 388
duke@435 389 //%note os_trap_1
duke@435 390 if (info != NULL && uc != NULL && thread != NULL) {
duke@435 391 // factor me: getPCfromContext
duke@435 392 pc = (address) uc->uc_mcontext.gregs[REG_PC];
duke@435 393 npc = (address) uc->uc_mcontext.gregs[REG_nPC];
duke@435 394
duke@435 395 // SafeFetch() support
duke@435 396 // Implemented with either a fixed set of addresses such
duke@435 397 // as Fetch32*, or with Thread._OnTrap.
duke@435 398 if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(Fetch32PFI)) {
duke@435 399 uc->uc_mcontext.gregs [REG_PC] = intptr_t(Fetch32Resume) ;
duke@435 400 uc->uc_mcontext.gregs [REG_nPC] = intptr_t(Fetch32Resume) + 4 ;
duke@435 401 return true ;
duke@435 402 }
duke@435 403 if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(FetchNPFI)) {
duke@435 404 uc->uc_mcontext.gregs [REG_PC] = intptr_t(FetchNResume) ;
duke@435 405 uc->uc_mcontext.gregs [REG_nPC] = intptr_t(FetchNResume) + 4 ;
duke@435 406 return true ;
duke@435 407 }
duke@435 408
duke@435 409 // Handle ALL stack overflow variations here
duke@435 410 if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
duke@435 411 address addr = (address) info->si_addr;
duke@435 412 if (thread->in_stack_yellow_zone(addr)) {
duke@435 413 thread->disable_stack_yellow_zone();
duke@435 414 // Sometimes the register windows are not properly flushed.
duke@435 415 if(uc->uc_mcontext.gwins != NULL) {
duke@435 416 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
duke@435 417 }
duke@435 418 if (thread->thread_state() == _thread_in_Java) {
duke@435 419 // Throw a stack overflow exception. Guard pages will be reenabled
duke@435 420 // while unwinding the stack.
duke@435 421 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
duke@435 422 } else {
duke@435 423 // Thread was in the vm or native code. Return and try to finish.
duke@435 424 return true;
duke@435 425 }
duke@435 426 } else if (thread->in_stack_red_zone(addr)) {
duke@435 427 // Fatal red zone violation. Disable the guard pages and fall through
duke@435 428 // to handle_unexpected_exception way down below.
duke@435 429 thread->disable_stack_red_zone();
duke@435 430 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
duke@435 431 // Sometimes the register windows are not properly flushed.
duke@435 432 if(uc->uc_mcontext.gwins != NULL) {
duke@435 433 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
duke@435 434 }
duke@435 435 }
duke@435 436 }
duke@435 437
duke@435 438
duke@435 439 if (thread->thread_state() == _thread_in_vm) {
duke@435 440 if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) {
duke@435 441 stub = StubRoutines::handler_for_unsafe_access();
duke@435 442 }
duke@435 443 }
duke@435 444
duke@435 445 else if (thread->thread_state() == _thread_in_Java) {
duke@435 446 // Java thread running in Java code => find exception handler if any
duke@435 447 // a fault inside compiled code, the interpreter, or a stub
duke@435 448
duke@435 449 // Support Safepoint Polling
duke@435 450 if ( sig == SIGSEGV && (address)info->si_addr == os::get_polling_page() ) {
duke@435 451 stub = SharedRuntime::get_poll_stub(pc);
duke@435 452 }
duke@435 453
duke@435 454 // Not needed on x86 solaris because verify_oops doesn't generate
duke@435 455 // SEGV/BUS like sparc does.
duke@435 456 if ( (sig == SIGSEGV || sig == SIGBUS)
duke@435 457 && pc >= MacroAssembler::_verify_oop_implicit_branch[0]
duke@435 458 && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) {
duke@435 459 stub = MacroAssembler::_verify_oop_implicit_branch[2];
duke@435 460 warning("fixed up memory fault in +VerifyOops at address " INTPTR_FORMAT, info->si_addr);
duke@435 461 }
duke@435 462
duke@435 463 // This is not factored because on x86 solaris the patching for
duke@435 464 // zombies does not generate a SEGV.
duke@435 465 else if (sig == SIGSEGV && nativeInstruction_at(pc)->is_zombie()) {
duke@435 466 // zombie method (ld [%g0],%o7 instruction)
duke@435 467 stub = SharedRuntime::get_handle_wrong_method_stub();
duke@435 468
duke@435 469 // At the stub it needs to look like a call from the caller of this
duke@435 470 // method (not a call from the segv site).
duke@435 471 pc = (address)uc->uc_mcontext.gregs[REG_O7];
duke@435 472 }
duke@435 473 else if (sig == SIGBUS && info->si_code == BUS_OBJERR) {
duke@435 474 // BugId 4454115: A read from a MappedByteBuffer can fault
duke@435 475 // here if the underlying file has been truncated.
duke@435 476 // Do not crash the VM in such a case.
duke@435 477 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
duke@435 478 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
duke@435 479 if (nm != NULL && nm->has_unsafe_access()) {
duke@435 480 stub = StubRoutines::handler_for_unsafe_access();
duke@435 481 }
duke@435 482 }
duke@435 483
duke@435 484 else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
duke@435 485 // integer divide by zero
duke@435 486 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
duke@435 487 }
duke@435 488 else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) {
duke@435 489 // floating-point divide by zero
duke@435 490 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
duke@435 491 }
duke@435 492 #ifdef COMPILER2
duke@435 493 else if (sig == SIGILL && nativeInstruction_at(pc)->is_ic_miss_trap()) {
duke@435 494 #ifdef ASSERT
duke@435 495 #ifdef TIERED
duke@435 496 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
duke@435 497 assert(cb->is_compiled_by_c2(), "Wrong compiler");
duke@435 498 #endif // TIERED
duke@435 499 #endif // ASSERT
duke@435 500 // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken.
duke@435 501 stub = SharedRuntime::get_ic_miss_stub();
duke@435 502 // At the stub it needs to look like a call from the caller of this
duke@435 503 // method (not a call from the segv site).
duke@435 504 pc = (address)uc->uc_mcontext.gregs[REG_O7];
duke@435 505 }
duke@435 506 #endif // COMPILER2
duke@435 507
duke@435 508 else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
duke@435 509 // Determination of interpreter/vtable stub/compiled code null exception
duke@435 510 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
duke@435 511 }
duke@435 512 }
duke@435 513
duke@435 514 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
duke@435 515 // and the heap gets shrunk before the field access.
duke@435 516 if ((sig == SIGSEGV) || (sig == SIGBUS)) {
duke@435 517 address addr = JNI_FastGetField::find_slowcase_pc(pc);
duke@435 518 if (addr != (address)-1) {
duke@435 519 stub = addr;
duke@435 520 }
duke@435 521 }
duke@435 522
duke@435 523 // Check to see if we caught the safepoint code in the
duke@435 524 // process of write protecting the memory serialization page.
duke@435 525 // It write enables the page immediately after protecting it
duke@435 526 // so just return.
duke@435 527 if ((sig == SIGSEGV) &&
duke@435 528 os::is_memory_serialize_page(thread, (address)info->si_addr)) {
duke@435 529 // Block current thread until the memory serialize page permission restored.
duke@435 530 os::block_on_serialize_page_trap();
duke@435 531 return true;
duke@435 532 }
duke@435 533 }
duke@435 534
duke@435 535 if (stub != NULL) {
duke@435 536 // save all thread context in case we need to restore it
duke@435 537
duke@435 538 thread->set_saved_exception_pc(pc);
duke@435 539 thread->set_saved_exception_npc(npc);
duke@435 540
duke@435 541 // simulate a branch to the stub (a "call" in the safepoint stub case)
duke@435 542 // factor me: setPC
duke@435 543 uc->uc_mcontext.gregs[REG_PC ] = (greg_t)stub;
duke@435 544 uc->uc_mcontext.gregs[REG_nPC] = (greg_t)(stub + 4);
duke@435 545
duke@435 546 #ifndef PRODUCT
duke@435 547 if (TraceJumps) thread->record_jump(stub, NULL, __FILE__, __LINE__);
duke@435 548 #endif /* PRODUCT */
duke@435 549
duke@435 550 return true;
duke@435 551 }
duke@435 552
duke@435 553 // signal-chaining
duke@435 554 if (os::Solaris::chained_handler(sig, info, ucVoid)) {
duke@435 555 return true;
duke@435 556 }
duke@435 557
duke@435 558 if (!abort_if_unrecognized) {
duke@435 559 // caller wants another chance, so give it to him
duke@435 560 return false;
duke@435 561 }
duke@435 562
duke@435 563 if (!os::Solaris::libjsig_is_loaded) {
duke@435 564 struct sigaction oldAct;
duke@435 565 sigaction(sig, (struct sigaction *)0, &oldAct);
duke@435 566 if (oldAct.sa_sigaction != signalHandler) {
duke@435 567 void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
duke@435 568 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
twisti@1040 569 warning("Unexpected Signal %d occurred under user-defined signal handler " INTPTR_FORMAT, sig, (intptr_t)sighand);
duke@435 570 }
duke@435 571 }
duke@435 572
duke@435 573 if (pc == NULL && uc != NULL) {
duke@435 574 pc = (address) uc->uc_mcontext.gregs[REG_PC];
duke@435 575 }
duke@435 576
never@2262 577 // Sometimes the register windows are not properly flushed.
never@2262 578 if(uc->uc_mcontext.gwins != NULL) {
never@2262 579 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
never@2262 580 }
never@2262 581
duke@435 582 // unmask current signal
duke@435 583 sigset_t newset;
duke@435 584 sigemptyset(&newset);
duke@435 585 sigaddset(&newset, sig);
duke@435 586 sigprocmask(SIG_UNBLOCK, &newset, NULL);
duke@435 587
coleenp@2418 588 // Determine which sort of error to throw. Out of swap may signal
coleenp@2418 589 // on the thread stack, which could get a mapping error when touched.
coleenp@2418 590 address addr = (address) info->si_addr;
coleenp@2418 591 if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) {
coleenp@2418 592 vm_exit_out_of_memory(0, "Out of swap space to map in thread stack.");
coleenp@2418 593 }
coleenp@2418 594
duke@435 595 VMError err(t, sig, pc, info, ucVoid);
duke@435 596 err.report_and_die();
duke@435 597
duke@435 598 ShouldNotReachHere();
duke@435 599 }
duke@435 600
duke@435 601 void os::print_context(outputStream *st, void *context) {
duke@435 602 if (context == NULL) return;
duke@435 603
duke@435 604 ucontext_t *uc = (ucontext_t*)context;
duke@435 605 st->print_cr("Registers:");
duke@435 606
never@2262 607 st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT
never@2262 608 " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT,
never@2262 609 uc->uc_mcontext.gregs[REG_G1],
never@2262 610 uc->uc_mcontext.gregs[REG_G2],
never@2262 611 uc->uc_mcontext.gregs[REG_G3],
never@2262 612 uc->uc_mcontext.gregs[REG_G4]);
never@2262 613 st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT
never@2262 614 " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT,
never@2262 615 uc->uc_mcontext.gregs[REG_G5],
never@2262 616 uc->uc_mcontext.gregs[REG_G6],
never@2262 617 uc->uc_mcontext.gregs[REG_G7],
never@2262 618 uc->uc_mcontext.gregs[REG_Y]);
duke@435 619 st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT
duke@435 620 " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT,
duke@435 621 uc->uc_mcontext.gregs[REG_O0],
duke@435 622 uc->uc_mcontext.gregs[REG_O1],
duke@435 623 uc->uc_mcontext.gregs[REG_O2],
duke@435 624 uc->uc_mcontext.gregs[REG_O3]);
duke@435 625 st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT
duke@435 626 " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT,
duke@435 627 uc->uc_mcontext.gregs[REG_O4],
duke@435 628 uc->uc_mcontext.gregs[REG_O5],
duke@435 629 uc->uc_mcontext.gregs[REG_O6],
duke@435 630 uc->uc_mcontext.gregs[REG_O7]);
duke@435 631
never@2262 632
never@2262 633 intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
never@2262 634 st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT
never@2262 635 " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT,
never@2262 636 sp[L0->sp_offset_in_saved_window()],
never@2262 637 sp[L1->sp_offset_in_saved_window()],
never@2262 638 sp[L2->sp_offset_in_saved_window()],
never@2262 639 sp[L3->sp_offset_in_saved_window()]);
never@2262 640 st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT
never@2262 641 " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT,
never@2262 642 sp[L4->sp_offset_in_saved_window()],
never@2262 643 sp[L5->sp_offset_in_saved_window()],
never@2262 644 sp[L6->sp_offset_in_saved_window()],
never@2262 645 sp[L7->sp_offset_in_saved_window()]);
never@2262 646 st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT
never@2262 647 " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT,
never@2262 648 sp[I0->sp_offset_in_saved_window()],
never@2262 649 sp[I1->sp_offset_in_saved_window()],
never@2262 650 sp[I2->sp_offset_in_saved_window()],
never@2262 651 sp[I3->sp_offset_in_saved_window()]);
never@2262 652 st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT
never@2262 653 " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT,
never@2262 654 sp[I4->sp_offset_in_saved_window()],
never@2262 655 sp[I5->sp_offset_in_saved_window()],
never@2262 656 sp[I6->sp_offset_in_saved_window()],
never@2262 657 sp[I7->sp_offset_in_saved_window()]);
duke@435 658
duke@435 659 st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT,
duke@435 660 uc->uc_mcontext.gregs[REG_PC],
duke@435 661 uc->uc_mcontext.gregs[REG_nPC]);
bobv@2036 662 st->cr();
bobv@2036 663 st->cr();
bobv@2036 664
duke@435 665 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
duke@435 666 print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
duke@435 667 st->cr();
duke@435 668
duke@435 669 // Note: it may be unsafe to inspect memory near pc. For example, pc may
duke@435 670 // point to garbage if entry point in an nmethod is corrupted. Leave
duke@435 671 // this at the end, and hope for the best.
duke@435 672 ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc);
duke@435 673 address pc = epc.pc();
duke@435 674 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
never@2262 675 print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
never@2262 676 }
never@2262 677
never@2262 678 void os::print_register_info(outputStream *st, void *context) {
never@2262 679 if (context == NULL) return;
never@2262 680
never@2262 681 ucontext_t *uc = (ucontext_t*)context;
never@2262 682 intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
never@2262 683
never@2262 684 st->print_cr("Register to memory mapping:");
never@2262 685 st->cr();
never@2262 686
never@2262 687 // this is only for the "general purpose" registers
never@2262 688 st->print("G1="); print_location(st, uc->uc_mcontext.gregs[REG_G1]);
never@2262 689 st->print("G2="); print_location(st, uc->uc_mcontext.gregs[REG_G2]);
never@2262 690 st->print("G3="); print_location(st, uc->uc_mcontext.gregs[REG_G3]);
never@2262 691 st->print("G4="); print_location(st, uc->uc_mcontext.gregs[REG_G4]);
never@2262 692 st->print("G5="); print_location(st, uc->uc_mcontext.gregs[REG_G5]);
never@2262 693 st->print("G6="); print_location(st, uc->uc_mcontext.gregs[REG_G6]);
never@2262 694 st->print("G7="); print_location(st, uc->uc_mcontext.gregs[REG_G7]);
never@2262 695 st->cr();
never@2262 696
never@2262 697 st->print("O0="); print_location(st, uc->uc_mcontext.gregs[REG_O0]);
never@2262 698 st->print("O1="); print_location(st, uc->uc_mcontext.gregs[REG_O1]);
never@2262 699 st->print("O2="); print_location(st, uc->uc_mcontext.gregs[REG_O2]);
never@2262 700 st->print("O3="); print_location(st, uc->uc_mcontext.gregs[REG_O3]);
never@2262 701 st->print("O4="); print_location(st, uc->uc_mcontext.gregs[REG_O4]);
never@2262 702 st->print("O5="); print_location(st, uc->uc_mcontext.gregs[REG_O5]);
never@2262 703 st->print("O6="); print_location(st, uc->uc_mcontext.gregs[REG_O6]);
never@2262 704 st->print("O7="); print_location(st, uc->uc_mcontext.gregs[REG_O7]);
never@2262 705 st->cr();
never@2262 706
never@2262 707 st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]);
never@2262 708 st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]);
never@2262 709 st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]);
never@2262 710 st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]);
never@2262 711 st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]);
never@2262 712 st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]);
never@2262 713 st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]);
never@2262 714 st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]);
never@2262 715 st->cr();
never@2262 716
never@2262 717 st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]);
never@2262 718 st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]);
never@2262 719 st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]);
never@2262 720 st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]);
never@2262 721 st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]);
never@2262 722 st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]);
never@2262 723 st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]);
never@2262 724 st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]);
never@2262 725 st->cr();
duke@435 726 }
duke@435 727
duke@435 728 void os::Solaris::init_thread_fpu_state(void) {
duke@435 729 // Nothing needed on Sparc.
duke@435 730 }
duke@435 731
duke@435 732 #if !defined(COMPILER2) && !defined(_LP64)
duke@435 733
duke@435 734 // These routines are the initial value of atomic_xchg_entry(),
duke@435 735 // atomic_cmpxchg_entry(), atomic_add_entry() and fence_entry()
duke@435 736 // until initialization is complete.
duke@435 737 // TODO - remove when the VM drops support for V8.
duke@435 738
duke@435 739 typedef jint xchg_func_t (jint, volatile jint*);
duke@435 740 typedef jint cmpxchg_func_t (jint, volatile jint*, jint);
duke@435 741 typedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong);
duke@435 742 typedef jint add_func_t (jint, volatile jint*);
duke@435 743
duke@435 744 jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) {
duke@435 745 // try to use the stub:
duke@435 746 xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
duke@435 747
duke@435 748 if (func != NULL) {
duke@435 749 os::atomic_xchg_func = func;
duke@435 750 return (*func)(exchange_value, dest);
duke@435 751 }
duke@435 752 assert(Threads::number_of_threads() == 0, "for bootstrap only");
duke@435 753
duke@435 754 jint old_value = *dest;
duke@435 755 *dest = exchange_value;
duke@435 756 return old_value;
duke@435 757 }
duke@435 758
duke@435 759 jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) {
duke@435 760 // try to use the stub:
duke@435 761 cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
duke@435 762
duke@435 763 if (func != NULL) {
duke@435 764 os::atomic_cmpxchg_func = func;
duke@435 765 return (*func)(exchange_value, dest, compare_value);
duke@435 766 }
duke@435 767 assert(Threads::number_of_threads() == 0, "for bootstrap only");
duke@435 768
duke@435 769 jint old_value = *dest;
duke@435 770 if (old_value == compare_value)
duke@435 771 *dest = exchange_value;
duke@435 772 return old_value;
duke@435 773 }
duke@435 774
duke@435 775 jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) {
duke@435 776 // try to use the stub:
duke@435 777 cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry());
duke@435 778
duke@435 779 if (func != NULL) {
duke@435 780 os::atomic_cmpxchg_long_func = func;
duke@435 781 return (*func)(exchange_value, dest, compare_value);
duke@435 782 }
duke@435 783 assert(Threads::number_of_threads() == 0, "for bootstrap only");
duke@435 784
duke@435 785 jlong old_value = *dest;
duke@435 786 if (old_value == compare_value)
duke@435 787 *dest = exchange_value;
duke@435 788 return old_value;
duke@435 789 }
duke@435 790
duke@435 791 jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) {
duke@435 792 // try to use the stub:
duke@435 793 add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
duke@435 794
duke@435 795 if (func != NULL) {
duke@435 796 os::atomic_add_func = func;
duke@435 797 return (*func)(add_value, dest);
duke@435 798 }
duke@435 799 assert(Threads::number_of_threads() == 0, "for bootstrap only");
duke@435 800
duke@435 801 return (*dest) += add_value;
duke@435 802 }
duke@435 803
duke@435 804 xchg_func_t* os::atomic_xchg_func = os::atomic_xchg_bootstrap;
duke@435 805 cmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap;
duke@435 806 cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
duke@435 807 add_func_t* os::atomic_add_func = os::atomic_add_bootstrap;
duke@435 808
duke@435 809 #endif // !_LP64 && !COMPILER2
duke@435 810
duke@435 811 #if defined(__sparc) && defined(COMPILER2) && defined(_GNU_SOURCE)
duke@435 812 // See file build/solaris/makefiles/$compiler.make
duke@435 813 // For compiler1 the architecture is v8 and frps isn't present in v8
duke@435 814 extern "C" void _mark_fpu_nosave() {
duke@435 815 __asm__ __volatile__ ("wr %%g0, 0, %%fprs \n\t" : : :);
duke@435 816 }
duke@435 817 #endif //defined(__sparc) && defined(COMPILER2)

mercurial