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