src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 // no precompiled headers
aoqi@0 26 #include "asm/macroAssembler.hpp"
aoqi@0 27 #include "classfile/classLoader.hpp"
aoqi@0 28 #include "classfile/systemDictionary.hpp"
aoqi@0 29 #include "classfile/vmSymbols.hpp"
aoqi@0 30 #include "code/icBuffer.hpp"
aoqi@0 31 #include "code/vtableStubs.hpp"
aoqi@0 32 #include "interpreter/interpreter.hpp"
aoqi@0 33 #include "jvm_solaris.h"
aoqi@0 34 #include "memory/allocation.inline.hpp"
aoqi@0 35 #include "mutex_solaris.inline.hpp"
aoqi@0 36 #include "os_share_solaris.hpp"
aoqi@0 37 #include "prims/jniFastGetField.hpp"
aoqi@0 38 #include "prims/jvm.h"
aoqi@0 39 #include "prims/jvm_misc.hpp"
aoqi@0 40 #include "runtime/arguments.hpp"
aoqi@0 41 #include "runtime/extendedPC.hpp"
aoqi@0 42 #include "runtime/frame.inline.hpp"
aoqi@0 43 #include "runtime/interfaceSupport.hpp"
aoqi@0 44 #include "runtime/java.hpp"
aoqi@0 45 #include "runtime/javaCalls.hpp"
aoqi@0 46 #include "runtime/mutexLocker.hpp"
aoqi@0 47 #include "runtime/osThread.hpp"
aoqi@0 48 #include "runtime/sharedRuntime.hpp"
aoqi@0 49 #include "runtime/stubRoutines.hpp"
aoqi@0 50 #include "runtime/thread.inline.hpp"
aoqi@0 51 #include "runtime/timer.hpp"
aoqi@0 52 #include "utilities/events.hpp"
aoqi@0 53 #include "utilities/vmError.hpp"
aoqi@0 54
aoqi@0 55 // put OS-includes here
aoqi@0 56 # include <sys/types.h>
aoqi@0 57 # include <sys/mman.h>
aoqi@0 58 # include <pthread.h>
aoqi@0 59 # include <signal.h>
aoqi@0 60 # include <setjmp.h>
aoqi@0 61 # include <errno.h>
aoqi@0 62 # include <dlfcn.h>
aoqi@0 63 # include <stdio.h>
aoqi@0 64 # include <unistd.h>
aoqi@0 65 # include <sys/resource.h>
aoqi@0 66 # include <thread.h>
aoqi@0 67 # include <sys/stat.h>
aoqi@0 68 # include <sys/time.h>
aoqi@0 69 # include <sys/filio.h>
aoqi@0 70 # include <sys/utsname.h>
aoqi@0 71 # include <sys/systeminfo.h>
aoqi@0 72 # include <sys/socket.h>
aoqi@0 73 # include <sys/trap.h>
aoqi@0 74 # include <sys/lwp.h>
aoqi@0 75 # include <pwd.h>
aoqi@0 76 # include <poll.h>
aoqi@0 77 # include <sys/lwp.h>
aoqi@0 78 # include <procfs.h> // see comment in <sys/procfs.h>
aoqi@0 79
aoqi@0 80 #ifndef AMD64
aoqi@0 81 // QQQ seems useless at this point
aoqi@0 82 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later
aoqi@0 83 #endif // AMD64
aoqi@0 84 # include <sys/procfs.h> // see comment in <sys/procfs.h>
aoqi@0 85
aoqi@0 86
aoqi@0 87 #define MAX_PATH (2 * K)
aoqi@0 88
aoqi@0 89 // Minimum stack size for the VM. It's easier to document a constant value
aoqi@0 90 // but it's different for x86 and sparc because the page sizes are different.
aoqi@0 91 #ifdef AMD64
aoqi@0 92 size_t os::Solaris::min_stack_allowed = 224*K;
aoqi@0 93 #define REG_SP REG_RSP
aoqi@0 94 #define REG_PC REG_RIP
aoqi@0 95 #define REG_FP REG_RBP
aoqi@0 96 #else
aoqi@0 97 size_t os::Solaris::min_stack_allowed = 64*K;
aoqi@0 98 #define REG_SP UESP
aoqi@0 99 #define REG_PC EIP
aoqi@0 100 #define REG_FP EBP
aoqi@0 101 // 4900493 counter to prevent runaway LDTR refresh attempt
aoqi@0 102
aoqi@0 103 static volatile int ldtr_refresh = 0;
aoqi@0 104 // the libthread instruction that faults because of the stale LDTR
aoqi@0 105
aoqi@0 106 static const unsigned char movlfs[] = { 0x8e, 0xe0 // movl %eax,%fs
aoqi@0 107 };
aoqi@0 108 #endif // AMD64
aoqi@0 109
aoqi@0 110 char* os::non_memory_address_word() {
aoqi@0 111 // Must never look like an address returned by reserve_memory,
aoqi@0 112 // even in its subfields (as defined by the CPU immediate fields,
aoqi@0 113 // if the CPU splits constants across multiple instructions).
aoqi@0 114 return (char*) -1;
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 //
aoqi@0 118 // Validate a ucontext retrieved from walking a uc_link of a ucontext.
aoqi@0 119 // There are issues with libthread giving out uc_links for different threads
aoqi@0 120 // on the same uc_link chain and bad or circular links.
aoqi@0 121 //
aoqi@0 122 bool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) {
aoqi@0 123 if (valid >= suspect ||
aoqi@0 124 valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags ||
aoqi@0 125 valid->uc_stack.ss_sp != suspect->uc_stack.ss_sp ||
aoqi@0 126 valid->uc_stack.ss_size != suspect->uc_stack.ss_size) {
aoqi@0 127 DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");)
aoqi@0 128 return false;
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 if (thread->is_Java_thread()) {
aoqi@0 132 if (!valid_stack_address(thread, (address)suspect)) {
aoqi@0 133 DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");)
aoqi@0 134 return false;
aoqi@0 135 }
aoqi@0 136 if (!valid_stack_address(thread, (address) suspect->uc_mcontext.gregs[REG_SP])) {
aoqi@0 137 DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");)
aoqi@0 138 return false;
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 return true;
aoqi@0 142 }
aoqi@0 143
aoqi@0 144 // We will only follow one level of uc_link since there are libthread
aoqi@0 145 // issues with ucontext linking and it is better to be safe and just
aoqi@0 146 // let caller retry later.
aoqi@0 147 ucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread,
aoqi@0 148 ucontext_t *uc) {
aoqi@0 149
aoqi@0 150 ucontext_t *retuc = NULL;
aoqi@0 151
aoqi@0 152 if (uc != NULL) {
aoqi@0 153 if (uc->uc_link == NULL) {
aoqi@0 154 // cannot validate without uc_link so accept current ucontext
aoqi@0 155 retuc = uc;
aoqi@0 156 } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
aoqi@0 157 // first ucontext is valid so try the next one
aoqi@0 158 uc = uc->uc_link;
aoqi@0 159 if (uc->uc_link == NULL) {
aoqi@0 160 // cannot validate without uc_link so accept current ucontext
aoqi@0 161 retuc = uc;
aoqi@0 162 } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
aoqi@0 163 // the ucontext one level down is also valid so return it
aoqi@0 164 retuc = uc;
aoqi@0 165 }
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168 return retuc;
aoqi@0 169 }
aoqi@0 170
aoqi@0 171 // Assumes ucontext is valid
aoqi@0 172 ExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) {
aoqi@0 173 return ExtendedPC((address)uc->uc_mcontext.gregs[REG_PC]);
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 // Assumes ucontext is valid
aoqi@0 177 intptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) {
aoqi@0 178 return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 // Assumes ucontext is valid
aoqi@0 182 intptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) {
aoqi@0 183 return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
aoqi@0 184 }
aoqi@0 185
aoqi@0 186 address os::Solaris::ucontext_get_pc(ucontext_t *uc) {
aoqi@0 187 return (address) uc->uc_mcontext.gregs[REG_PC];
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
aoqi@0 191 // is currently interrupted by SIGPROF.
aoqi@0 192 //
aoqi@0 193 // The difference between this and os::fetch_frame_from_context() is that
aoqi@0 194 // here we try to skip nested signal frames.
aoqi@0 195 ExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread,
aoqi@0 196 ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
aoqi@0 197
aoqi@0 198 assert(thread != NULL, "just checking");
aoqi@0 199 assert(ret_sp != NULL, "just checking");
aoqi@0 200 assert(ret_fp != NULL, "just checking");
aoqi@0 201
aoqi@0 202 ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc);
aoqi@0 203 return os::fetch_frame_from_context(luc, ret_sp, ret_fp);
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
aoqi@0 207 intptr_t** ret_sp, intptr_t** ret_fp) {
aoqi@0 208
aoqi@0 209 ExtendedPC epc;
aoqi@0 210 ucontext_t *uc = (ucontext_t*)ucVoid;
aoqi@0 211
aoqi@0 212 if (uc != NULL) {
aoqi@0 213 epc = os::Solaris::ucontext_get_ExtendedPC(uc);
aoqi@0 214 if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc);
aoqi@0 215 if (ret_fp) *ret_fp = os::Solaris::ucontext_get_fp(uc);
aoqi@0 216 } else {
aoqi@0 217 // construct empty ExtendedPC for return value checking
aoqi@0 218 epc = ExtendedPC(NULL);
aoqi@0 219 if (ret_sp) *ret_sp = (intptr_t *)NULL;
aoqi@0 220 if (ret_fp) *ret_fp = (intptr_t *)NULL;
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 return epc;
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 frame os::fetch_frame_from_context(void* ucVoid) {
aoqi@0 227 intptr_t* sp;
aoqi@0 228 intptr_t* fp;
aoqi@0 229 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
aoqi@0 230 return frame(sp, fp, epc.pc());
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 frame os::get_sender_for_C_frame(frame* fr) {
aoqi@0 234 return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 extern "C" intptr_t *_get_current_sp(); // in .il file
aoqi@0 238
aoqi@0 239 address os::current_stack_pointer() {
aoqi@0 240 return (address)_get_current_sp();
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 extern "C" intptr_t *_get_current_fp(); // in .il file
aoqi@0 244
aoqi@0 245 frame os::current_frame() {
aoqi@0 246 intptr_t* fp = _get_current_fp(); // it's inlined so want current fp
aoqi@0 247 frame myframe((intptr_t*)os::current_stack_pointer(),
aoqi@0 248 (intptr_t*)fp,
aoqi@0 249 CAST_FROM_FN_PTR(address, os::current_frame));
aoqi@0 250 if (os::is_first_C_frame(&myframe)) {
aoqi@0 251 // stack is not walkable
aoqi@0 252 frame ret; // This will be a null useless frame
aoqi@0 253 return ret;
aoqi@0 254 } else {
aoqi@0 255 return os::get_sender_for_C_frame(&myframe);
aoqi@0 256 }
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 static int threadgetstate(thread_t tid, int *flags, lwpid_t *lwp, stack_t *ss, gregset_t rs, lwpstatus_t *lwpstatus) {
aoqi@0 260 char lwpstatusfile[PROCFILE_LENGTH];
aoqi@0 261 int lwpfd, err;
aoqi@0 262
aoqi@0 263 if (err = os::Solaris::thr_getstate(tid, flags, lwp, ss, rs))
aoqi@0 264 return (err);
aoqi@0 265 if (*flags == TRS_LWPID) {
aoqi@0 266 sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(),
aoqi@0 267 *lwp);
aoqi@0 268 if ((lwpfd = open(lwpstatusfile, O_RDONLY)) < 0) {
aoqi@0 269 perror("thr_mutator_status: open lwpstatus");
aoqi@0 270 return (EINVAL);
aoqi@0 271 }
aoqi@0 272 if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) !=
aoqi@0 273 sizeof (lwpstatus_t)) {
aoqi@0 274 perror("thr_mutator_status: read lwpstatus");
aoqi@0 275 (void) close(lwpfd);
aoqi@0 276 return (EINVAL);
aoqi@0 277 }
aoqi@0 278 (void) close(lwpfd);
aoqi@0 279 }
aoqi@0 280 return (0);
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 #ifndef AMD64
aoqi@0 284
aoqi@0 285 // Detecting SSE support by OS
aoqi@0 286 // From solaris_i486.s
aoqi@0 287 extern "C" bool sse_check();
aoqi@0 288 extern "C" bool sse_unavailable();
aoqi@0 289
aoqi@0 290 enum { SSE_UNKNOWN, SSE_NOT_SUPPORTED, SSE_SUPPORTED};
aoqi@0 291 static int sse_status = SSE_UNKNOWN;
aoqi@0 292
aoqi@0 293
aoqi@0 294 static void check_for_sse_support() {
aoqi@0 295 if (!VM_Version::supports_sse()) {
aoqi@0 296 sse_status = SSE_NOT_SUPPORTED;
aoqi@0 297 return;
aoqi@0 298 }
aoqi@0 299 // looking for _sse_hw in libc.so, if it does not exist or
aoqi@0 300 // the value (int) is 0, OS has no support for SSE
aoqi@0 301 int *sse_hwp;
aoqi@0 302 void *h;
aoqi@0 303
aoqi@0 304 if ((h=dlopen("/usr/lib/libc.so", RTLD_LAZY)) == NULL) {
aoqi@0 305 //open failed, presume no support for SSE
aoqi@0 306 sse_status = SSE_NOT_SUPPORTED;
aoqi@0 307 return;
aoqi@0 308 }
aoqi@0 309 if ((sse_hwp = (int *)dlsym(h, "_sse_hw")) == NULL) {
aoqi@0 310 sse_status = SSE_NOT_SUPPORTED;
aoqi@0 311 } else if (*sse_hwp == 0) {
aoqi@0 312 sse_status = SSE_NOT_SUPPORTED;
aoqi@0 313 }
aoqi@0 314 dlclose(h);
aoqi@0 315
aoqi@0 316 if (sse_status == SSE_UNKNOWN) {
aoqi@0 317 bool (*try_sse)() = (bool (*)())sse_check;
aoqi@0 318 sse_status = (*try_sse)() ? SSE_SUPPORTED : SSE_NOT_SUPPORTED;
aoqi@0 319 }
aoqi@0 320
aoqi@0 321 }
aoqi@0 322
aoqi@0 323 #endif // AMD64
aoqi@0 324
aoqi@0 325 bool os::supports_sse() {
aoqi@0 326 #ifdef AMD64
aoqi@0 327 return true;
aoqi@0 328 #else
aoqi@0 329 if (sse_status == SSE_UNKNOWN)
aoqi@0 330 check_for_sse_support();
aoqi@0 331 return sse_status == SSE_SUPPORTED;
aoqi@0 332 #endif // AMD64
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 bool os::is_allocatable(size_t bytes) {
aoqi@0 336 #ifdef AMD64
aoqi@0 337 return true;
aoqi@0 338 #else
aoqi@0 339
aoqi@0 340 if (bytes < 2 * G) {
aoqi@0 341 return true;
aoqi@0 342 }
aoqi@0 343
aoqi@0 344 char* addr = reserve_memory(bytes, NULL);
aoqi@0 345
aoqi@0 346 if (addr != NULL) {
aoqi@0 347 release_memory(addr, bytes);
aoqi@0 348 }
aoqi@0 349
aoqi@0 350 return addr != NULL;
aoqi@0 351 #endif // AMD64
aoqi@0 352
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 extern "C" JNIEXPORT int
aoqi@0 356 JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
aoqi@0 357 int abort_if_unrecognized) {
aoqi@0 358 ucontext_t* uc = (ucontext_t*) ucVoid;
aoqi@0 359
aoqi@0 360 #ifndef AMD64
aoqi@0 361 if (sig == SIGILL && info->si_addr == (caddr_t)sse_check) {
aoqi@0 362 // the SSE instruction faulted. supports_sse() need return false.
aoqi@0 363 uc->uc_mcontext.gregs[EIP] = (greg_t)sse_unavailable;
aoqi@0 364 return true;
aoqi@0 365 }
aoqi@0 366 #endif // !AMD64
aoqi@0 367
aoqi@0 368 Thread* t = ThreadLocalStorage::get_thread_slow(); // slow & steady
aoqi@0 369
aoqi@0 370 // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
aoqi@0 371 // (no destructors can be run)
aoqi@0 372 os::WatcherThreadCrashProtection::check_crash_protection(sig, t);
aoqi@0 373
aoqi@0 374 SignalHandlerMark shm(t);
aoqi@0 375
aoqi@0 376 if(sig == SIGPIPE || sig == SIGXFSZ) {
aoqi@0 377 if (os::Solaris::chained_handler(sig, info, ucVoid)) {
aoqi@0 378 return true;
aoqi@0 379 } else {
aoqi@0 380 if (PrintMiscellaneous && (WizardMode || Verbose)) {
aoqi@0 381 char buf[64];
aoqi@0 382 warning("Ignoring %s - see 4229104 or 6499219",
aoqi@0 383 os::exception_name(sig, buf, sizeof(buf)));
aoqi@0 384
aoqi@0 385 }
aoqi@0 386 return true;
aoqi@0 387 }
aoqi@0 388 }
aoqi@0 389
aoqi@0 390 JavaThread* thread = NULL;
aoqi@0 391 VMThread* vmthread = NULL;
aoqi@0 392
aoqi@0 393 if (os::Solaris::signal_handlers_are_installed) {
aoqi@0 394 if (t != NULL ){
aoqi@0 395 if(t->is_Java_thread()) {
aoqi@0 396 thread = (JavaThread*)t;
aoqi@0 397 }
aoqi@0 398 else if(t->is_VM_thread()){
aoqi@0 399 vmthread = (VMThread *)t;
aoqi@0 400 }
aoqi@0 401 }
aoqi@0 402 }
aoqi@0 403
aoqi@0 404 guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs");
aoqi@0 405
aoqi@0 406 if (sig == os::Solaris::SIGasync()) {
aoqi@0 407 if(thread || vmthread){
aoqi@0 408 OSThread::SR_handler(t, uc);
aoqi@0 409 return true;
aoqi@0 410 } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
aoqi@0 411 return true;
aoqi@0 412 } else {
aoqi@0 413 // If os::Solaris::SIGasync not chained, and this is a non-vm and
aoqi@0 414 // non-java thread
aoqi@0 415 return true;
aoqi@0 416 }
aoqi@0 417 }
aoqi@0 418
aoqi@0 419 if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
aoqi@0 420 // can't decode this kind of signal
aoqi@0 421 info = NULL;
aoqi@0 422 } else {
aoqi@0 423 assert(sig == info->si_signo, "bad siginfo");
aoqi@0 424 }
aoqi@0 425
aoqi@0 426 // decide if this trap can be handled by a stub
aoqi@0 427 address stub = NULL;
aoqi@0 428
aoqi@0 429 address pc = NULL;
aoqi@0 430
aoqi@0 431 //%note os_trap_1
aoqi@0 432 if (info != NULL && uc != NULL && thread != NULL) {
aoqi@0 433 // factor me: getPCfromContext
aoqi@0 434 pc = (address) uc->uc_mcontext.gregs[REG_PC];
aoqi@0 435
aoqi@0 436 if (StubRoutines::is_safefetch_fault(pc)) {
aoqi@0 437 uc->uc_mcontext.gregs[REG_PC] = intptr_t(StubRoutines::continuation_for_safefetch_fault(pc));
aoqi@0 438 return true;
aoqi@0 439 }
aoqi@0 440
aoqi@0 441 // Handle ALL stack overflow variations here
aoqi@0 442 if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
aoqi@0 443 address addr = (address) info->si_addr;
aoqi@0 444 if (thread->in_stack_yellow_zone(addr)) {
aoqi@0 445 thread->disable_stack_yellow_zone();
aoqi@0 446 if (thread->thread_state() == _thread_in_Java) {
aoqi@0 447 // Throw a stack overflow exception. Guard pages will be reenabled
aoqi@0 448 // while unwinding the stack.
aoqi@0 449 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
aoqi@0 450 } else {
aoqi@0 451 // Thread was in the vm or native code. Return and try to finish.
aoqi@0 452 return true;
aoqi@0 453 }
aoqi@0 454 } else if (thread->in_stack_red_zone(addr)) {
aoqi@0 455 // Fatal red zone violation. Disable the guard pages and fall through
aoqi@0 456 // to handle_unexpected_exception way down below.
aoqi@0 457 thread->disable_stack_red_zone();
aoqi@0 458 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
aoqi@0 459 }
aoqi@0 460 }
aoqi@0 461
aoqi@0 462 if ((sig == SIGSEGV) && VM_Version::is_cpuinfo_segv_addr(pc)) {
aoqi@0 463 // Verify that OS save/restore AVX registers.
aoqi@0 464 stub = VM_Version::cpuinfo_cont_addr();
aoqi@0 465 }
aoqi@0 466
aoqi@0 467 if (thread->thread_state() == _thread_in_vm) {
aoqi@0 468 if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) {
aoqi@0 469 stub = StubRoutines::handler_for_unsafe_access();
aoqi@0 470 }
aoqi@0 471 }
aoqi@0 472
aoqi@0 473 if (thread->thread_state() == _thread_in_Java) {
aoqi@0 474 // Support Safepoint Polling
aoqi@0 475 if ( sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
aoqi@0 476 stub = SharedRuntime::get_poll_stub(pc);
aoqi@0 477 }
aoqi@0 478 else if (sig == SIGBUS && info->si_code == BUS_OBJERR) {
aoqi@0 479 // BugId 4454115: A read from a MappedByteBuffer can fault
aoqi@0 480 // here if the underlying file has been truncated.
aoqi@0 481 // Do not crash the VM in such a case.
aoqi@0 482 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
aoqi@0 483 if (cb != NULL) {
aoqi@0 484 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
aoqi@0 485 if (nm != NULL && nm->has_unsafe_access()) {
aoqi@0 486 stub = StubRoutines::handler_for_unsafe_access();
aoqi@0 487 }
aoqi@0 488 }
aoqi@0 489 }
aoqi@0 490 else
aoqi@0 491 if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
aoqi@0 492 // integer divide by zero
aoqi@0 493 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
aoqi@0 494 }
aoqi@0 495 #ifndef AMD64
aoqi@0 496 else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) {
aoqi@0 497 // floating-point divide by zero
aoqi@0 498 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
aoqi@0 499 }
aoqi@0 500 else if (sig == SIGFPE && info->si_code == FPE_FLTINV) {
aoqi@0 501 // The encoding of D2I in i486.ad can cause an exception prior
aoqi@0 502 // to the fist instruction if there was an invalid operation
aoqi@0 503 // pending. We want to dismiss that exception. From the win_32
aoqi@0 504 // side it also seems that if it really was the fist causing
aoqi@0 505 // the exception that we do the d2i by hand with different
aoqi@0 506 // rounding. Seems kind of weird. QQQ TODO
aoqi@0 507 // Note that we take the exception at the NEXT floating point instruction.
aoqi@0 508 if (pc[0] == 0xDB) {
aoqi@0 509 assert(pc[0] == 0xDB, "not a FIST opcode");
aoqi@0 510 assert(pc[1] == 0x14, "not a FIST opcode");
aoqi@0 511 assert(pc[2] == 0x24, "not a FIST opcode");
aoqi@0 512 return true;
aoqi@0 513 } else {
aoqi@0 514 assert(pc[-3] == 0xDB, "not an flt invalid opcode");
aoqi@0 515 assert(pc[-2] == 0x14, "not an flt invalid opcode");
aoqi@0 516 assert(pc[-1] == 0x24, "not an flt invalid opcode");
aoqi@0 517 }
aoqi@0 518 }
aoqi@0 519 else if (sig == SIGFPE ) {
aoqi@0 520 tty->print_cr("caught SIGFPE, info 0x%x.", info->si_code);
aoqi@0 521 }
aoqi@0 522 #endif // !AMD64
aoqi@0 523
aoqi@0 524 // QQQ It doesn't seem that we need to do this on x86 because we should be able
aoqi@0 525 // to return properly from the handler without this extra stuff on the back side.
aoqi@0 526
aoqi@0 527 else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
aoqi@0 528 // Determination of interpreter/vtable stub/compiled code null exception
aoqi@0 529 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
aoqi@0 530 }
aoqi@0 531 }
aoqi@0 532
aoqi@0 533 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
aoqi@0 534 // and the heap gets shrunk before the field access.
aoqi@0 535 if ((sig == SIGSEGV) || (sig == SIGBUS)) {
aoqi@0 536 address addr = JNI_FastGetField::find_slowcase_pc(pc);
aoqi@0 537 if (addr != (address)-1) {
aoqi@0 538 stub = addr;
aoqi@0 539 }
aoqi@0 540 }
aoqi@0 541
aoqi@0 542 // Check to see if we caught the safepoint code in the
aoqi@0 543 // process of write protecting the memory serialization page.
aoqi@0 544 // It write enables the page immediately after protecting it
aoqi@0 545 // so we can just return to retry the write.
aoqi@0 546 if ((sig == SIGSEGV) &&
aoqi@0 547 os::is_memory_serialize_page(thread, (address)info->si_addr)) {
aoqi@0 548 // Block current thread until the memory serialize page permission restored.
aoqi@0 549 os::block_on_serialize_page_trap();
aoqi@0 550 return true;
aoqi@0 551 }
aoqi@0 552 }
aoqi@0 553
aoqi@0 554 // Execution protection violation
aoqi@0 555 //
aoqi@0 556 // Preventative code for future versions of Solaris which may
aoqi@0 557 // enable execution protection when running the 32-bit VM on AMD64.
aoqi@0 558 //
aoqi@0 559 // This should be kept as the last step in the triage. We don't
aoqi@0 560 // have a dedicated trap number for a no-execute fault, so be
aoqi@0 561 // conservative and allow other handlers the first shot.
aoqi@0 562 //
aoqi@0 563 // Note: We don't test that info->si_code == SEGV_ACCERR here.
aoqi@0 564 // this si_code is so generic that it is almost meaningless; and
aoqi@0 565 // the si_code for this condition may change in the future.
aoqi@0 566 // Furthermore, a false-positive should be harmless.
aoqi@0 567 if (UnguardOnExecutionViolation > 0 &&
aoqi@0 568 (sig == SIGSEGV || sig == SIGBUS) &&
aoqi@0 569 uc->uc_mcontext.gregs[TRAPNO] == T_PGFLT) { // page fault
aoqi@0 570 int page_size = os::vm_page_size();
aoqi@0 571 address addr = (address) info->si_addr;
aoqi@0 572 address pc = (address) uc->uc_mcontext.gregs[REG_PC];
aoqi@0 573 // Make sure the pc and the faulting address are sane.
aoqi@0 574 //
aoqi@0 575 // If an instruction spans a page boundary, and the page containing
aoqi@0 576 // the beginning of the instruction is executable but the following
aoqi@0 577 // page is not, the pc and the faulting address might be slightly
aoqi@0 578 // different - we still want to unguard the 2nd page in this case.
aoqi@0 579 //
aoqi@0 580 // 15 bytes seems to be a (very) safe value for max instruction size.
aoqi@0 581 bool pc_is_near_addr =
aoqi@0 582 (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
aoqi@0 583 bool instr_spans_page_boundary =
aoqi@0 584 (align_size_down((intptr_t) pc ^ (intptr_t) addr,
aoqi@0 585 (intptr_t) page_size) > 0);
aoqi@0 586
aoqi@0 587 if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
aoqi@0 588 static volatile address last_addr =
aoqi@0 589 (address) os::non_memory_address_word();
aoqi@0 590
aoqi@0 591 // In conservative mode, don't unguard unless the address is in the VM
aoqi@0 592 if (addr != last_addr &&
aoqi@0 593 (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
aoqi@0 594
aoqi@0 595 // Make memory rwx and retry
aoqi@0 596 address page_start =
aoqi@0 597 (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
aoqi@0 598 bool res = os::protect_memory((char*) page_start, page_size,
aoqi@0 599 os::MEM_PROT_RWX);
aoqi@0 600
aoqi@0 601 if (PrintMiscellaneous && Verbose) {
aoqi@0 602 char buf[256];
aoqi@0 603 jio_snprintf(buf, sizeof(buf), "Execution protection violation "
aoqi@0 604 "at " INTPTR_FORMAT
aoqi@0 605 ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr,
aoqi@0 606 page_start, (res ? "success" : "failed"), errno);
aoqi@0 607 tty->print_raw_cr(buf);
aoqi@0 608 }
aoqi@0 609 stub = pc;
aoqi@0 610
aoqi@0 611 // Set last_addr so if we fault again at the same address, we don't end
aoqi@0 612 // up in an endless loop.
aoqi@0 613 //
aoqi@0 614 // There are two potential complications here. Two threads trapping at
aoqi@0 615 // the same address at the same time could cause one of the threads to
aoqi@0 616 // think it already unguarded, and abort the VM. Likely very rare.
aoqi@0 617 //
aoqi@0 618 // The other race involves two threads alternately trapping at
aoqi@0 619 // different addresses and failing to unguard the page, resulting in
aoqi@0 620 // an endless loop. This condition is probably even more unlikely than
aoqi@0 621 // the first.
aoqi@0 622 //
aoqi@0 623 // Although both cases could be avoided by using locks or thread local
aoqi@0 624 // last_addr, these solutions are unnecessary complication: this
aoqi@0 625 // handler is a best-effort safety net, not a complete solution. It is
aoqi@0 626 // disabled by default and should only be used as a workaround in case
aoqi@0 627 // we missed any no-execute-unsafe VM code.
aoqi@0 628
aoqi@0 629 last_addr = addr;
aoqi@0 630 }
aoqi@0 631 }
aoqi@0 632 }
aoqi@0 633
aoqi@0 634 if (stub != NULL) {
aoqi@0 635 // save all thread context in case we need to restore it
aoqi@0 636
aoqi@0 637 if (thread != NULL) thread->set_saved_exception_pc(pc);
aoqi@0 638 // 12/02/99: On Sparc it appears that the full context is also saved
aoqi@0 639 // but as yet, no one looks at or restores that saved context
aoqi@0 640 // factor me: setPC
aoqi@0 641 uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub;
aoqi@0 642 return true;
aoqi@0 643 }
aoqi@0 644
aoqi@0 645 // signal-chaining
aoqi@0 646 if (os::Solaris::chained_handler(sig, info, ucVoid)) {
aoqi@0 647 return true;
aoqi@0 648 }
aoqi@0 649
aoqi@0 650 #ifndef AMD64
aoqi@0 651 // Workaround (bug 4900493) for Solaris kernel bug 4966651.
aoqi@0 652 // Handle an undefined selector caused by an attempt to assign
aoqi@0 653 // fs in libthread getipriptr(). With the current libthread design every 512
aoqi@0 654 // thread creations the LDT for a private thread data structure is extended
aoqi@0 655 // and thre is a hazard that and another thread attempting a thread creation
aoqi@0 656 // will use a stale LDTR that doesn't reflect the structure's growth,
aoqi@0 657 // causing a GP fault.
aoqi@0 658 // Enforce the probable limit of passes through here to guard against an
aoqi@0 659 // infinite loop if some other move to fs caused the GP fault. Note that
aoqi@0 660 // this loop counter is ultimately a heuristic as it is possible for
aoqi@0 661 // more than one thread to generate this fault at a time in an MP system.
aoqi@0 662 // In the case of the loop count being exceeded or if the poll fails
aoqi@0 663 // just fall through to a fatal error.
aoqi@0 664 // If there is some other source of T_GPFLT traps and the text at EIP is
aoqi@0 665 // unreadable this code will loop infinitely until the stack is exausted.
aoqi@0 666 // The key to diagnosis in this case is to look for the bottom signal handler
aoqi@0 667 // frame.
aoqi@0 668
aoqi@0 669 if(! IgnoreLibthreadGPFault) {
aoqi@0 670 if (sig == SIGSEGV && uc->uc_mcontext.gregs[TRAPNO] == T_GPFLT) {
aoqi@0 671 const unsigned char *p =
aoqi@0 672 (unsigned const char *) uc->uc_mcontext.gregs[EIP];
aoqi@0 673
aoqi@0 674 // Expected instruction?
aoqi@0 675
aoqi@0 676 if(p[0] == movlfs[0] && p[1] == movlfs[1]) {
aoqi@0 677
aoqi@0 678 Atomic::inc(&ldtr_refresh);
aoqi@0 679
aoqi@0 680 // Infinite loop?
aoqi@0 681
aoqi@0 682 if(ldtr_refresh < ((2 << 16) / PAGESIZE)) {
aoqi@0 683
aoqi@0 684 // No, force scheduling to get a fresh view of the LDTR
aoqi@0 685
aoqi@0 686 if(poll(NULL, 0, 10) == 0) {
aoqi@0 687
aoqi@0 688 // Retry the move
aoqi@0 689
aoqi@0 690 return false;
aoqi@0 691 }
aoqi@0 692 }
aoqi@0 693 }
aoqi@0 694 }
aoqi@0 695 }
aoqi@0 696 #endif // !AMD64
aoqi@0 697
aoqi@0 698 if (!abort_if_unrecognized) {
aoqi@0 699 // caller wants another chance, so give it to him
aoqi@0 700 return false;
aoqi@0 701 }
aoqi@0 702
aoqi@0 703 if (!os::Solaris::libjsig_is_loaded) {
aoqi@0 704 struct sigaction oldAct;
aoqi@0 705 sigaction(sig, (struct sigaction *)0, &oldAct);
aoqi@0 706 if (oldAct.sa_sigaction != signalHandler) {
aoqi@0 707 void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
aoqi@0 708 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
aoqi@0 709 warning("Unexpected Signal %d occurred under user-defined signal handler %#lx", sig, (long)sighand);
aoqi@0 710 }
aoqi@0 711 }
aoqi@0 712
aoqi@0 713 if (pc == NULL && uc != NULL) {
aoqi@0 714 pc = (address) uc->uc_mcontext.gregs[REG_PC];
aoqi@0 715 }
aoqi@0 716
aoqi@0 717 // unmask current signal
aoqi@0 718 sigset_t newset;
aoqi@0 719 sigemptyset(&newset);
aoqi@0 720 sigaddset(&newset, sig);
aoqi@0 721 sigprocmask(SIG_UNBLOCK, &newset, NULL);
aoqi@0 722
aoqi@0 723 // Determine which sort of error to throw. Out of swap may signal
aoqi@0 724 // on the thread stack, which could get a mapping error when touched.
aoqi@0 725 address addr = (address) info->si_addr;
aoqi@0 726 if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) {
aoqi@0 727 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "Out of swap space to map in thread stack.");
aoqi@0 728 }
aoqi@0 729
aoqi@0 730 VMError err(t, sig, pc, info, ucVoid);
aoqi@0 731 err.report_and_die();
aoqi@0 732
aoqi@0 733 ShouldNotReachHere();
aoqi@0 734 return false;
aoqi@0 735 }
aoqi@0 736
aoqi@0 737 void os::print_context(outputStream *st, void *context) {
aoqi@0 738 if (context == NULL) return;
aoqi@0 739
aoqi@0 740 ucontext_t *uc = (ucontext_t*)context;
aoqi@0 741 st->print_cr("Registers:");
aoqi@0 742 #ifdef AMD64
aoqi@0 743 st->print( "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
aoqi@0 744 st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
aoqi@0 745 st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]);
aoqi@0 746 st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]);
aoqi@0 747 st->cr();
aoqi@0 748 st->print( "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]);
aoqi@0 749 st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]);
aoqi@0 750 st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]);
aoqi@0 751 st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]);
aoqi@0 752 st->cr();
aoqi@0 753 st->print( "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]);
aoqi@0 754 st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]);
aoqi@0 755 st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]);
aoqi@0 756 st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]);
aoqi@0 757 st->cr();
aoqi@0 758 st->print( "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]);
aoqi@0 759 st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]);
aoqi@0 760 st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]);
aoqi@0 761 st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]);
aoqi@0 762 st->cr();
aoqi@0 763 st->print( "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]);
aoqi@0 764 st->print(", RFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RFL]);
aoqi@0 765 #else
aoqi@0 766 st->print( "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EAX]);
aoqi@0 767 st->print(", EBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EBX]);
aoqi@0 768 st->print(", ECX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[ECX]);
aoqi@0 769 st->print(", EDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EDX]);
aoqi@0 770 st->cr();
aoqi@0 771 st->print( "ESP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[UESP]);
aoqi@0 772 st->print(", EBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EBP]);
aoqi@0 773 st->print(", ESI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[ESI]);
aoqi@0 774 st->print(", EDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EDI]);
aoqi@0 775 st->cr();
aoqi@0 776 st->print( "EIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EIP]);
aoqi@0 777 st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EFL]);
aoqi@0 778 #endif // AMD64
aoqi@0 779 st->cr();
aoqi@0 780 st->cr();
aoqi@0 781
aoqi@0 782 intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
aoqi@0 783 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
aoqi@0 784 print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
aoqi@0 785 st->cr();
aoqi@0 786
aoqi@0 787 // Note: it may be unsafe to inspect memory near pc. For example, pc may
aoqi@0 788 // point to garbage if entry point in an nmethod is corrupted. Leave
aoqi@0 789 // this at the end, and hope for the best.
aoqi@0 790 ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc);
aoqi@0 791 address pc = epc.pc();
aoqi@0 792 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
aoqi@0 793 print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
aoqi@0 794 }
aoqi@0 795
aoqi@0 796 void os::print_register_info(outputStream *st, void *context) {
aoqi@0 797 if (context == NULL) return;
aoqi@0 798
aoqi@0 799 ucontext_t *uc = (ucontext_t*)context;
aoqi@0 800
aoqi@0 801 st->print_cr("Register to memory mapping:");
aoqi@0 802 st->cr();
aoqi@0 803
aoqi@0 804 // this is horrendously verbose but the layout of the registers in the
aoqi@0 805 // context does not match how we defined our abstract Register set, so
aoqi@0 806 // we can't just iterate through the gregs area
aoqi@0 807
aoqi@0 808 // this is only for the "general purpose" registers
aoqi@0 809
aoqi@0 810 #ifdef AMD64
aoqi@0 811 st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]);
aoqi@0 812 st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]);
aoqi@0 813 st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]);
aoqi@0 814 st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]);
aoqi@0 815 st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]);
aoqi@0 816 st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]);
aoqi@0 817 st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]);
aoqi@0 818 st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]);
aoqi@0 819 st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]);
aoqi@0 820 st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]);
aoqi@0 821 st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]);
aoqi@0 822 st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]);
aoqi@0 823 st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]);
aoqi@0 824 st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]);
aoqi@0 825 st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]);
aoqi@0 826 st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]);
aoqi@0 827 #else
aoqi@0 828 st->print("EAX="); print_location(st, uc->uc_mcontext.gregs[EAX]);
aoqi@0 829 st->print("EBX="); print_location(st, uc->uc_mcontext.gregs[EBX]);
aoqi@0 830 st->print("ECX="); print_location(st, uc->uc_mcontext.gregs[ECX]);
aoqi@0 831 st->print("EDX="); print_location(st, uc->uc_mcontext.gregs[EDX]);
aoqi@0 832 st->print("ESP="); print_location(st, uc->uc_mcontext.gregs[UESP]);
aoqi@0 833 st->print("EBP="); print_location(st, uc->uc_mcontext.gregs[EBP]);
aoqi@0 834 st->print("ESI="); print_location(st, uc->uc_mcontext.gregs[ESI]);
aoqi@0 835 st->print("EDI="); print_location(st, uc->uc_mcontext.gregs[EDI]);
aoqi@0 836 #endif
aoqi@0 837
aoqi@0 838 st->cr();
aoqi@0 839 }
aoqi@0 840
aoqi@0 841
aoqi@0 842 #ifdef AMD64
aoqi@0 843 void os::Solaris::init_thread_fpu_state(void) {
aoqi@0 844 // Nothing to do
aoqi@0 845 }
aoqi@0 846 #else
aoqi@0 847 // From solaris_i486.s
aoqi@0 848 extern "C" void fixcw();
aoqi@0 849
aoqi@0 850 void os::Solaris::init_thread_fpu_state(void) {
aoqi@0 851 // Set fpu to 53 bit precision. This happens too early to use a stub.
aoqi@0 852 fixcw();
aoqi@0 853 }
aoqi@0 854
aoqi@0 855 // These routines are the initial value of atomic_xchg_entry(),
aoqi@0 856 // atomic_cmpxchg_entry(), atomic_inc_entry() and fence_entry()
aoqi@0 857 // until initialization is complete.
aoqi@0 858 // TODO - replace with .il implementation when compiler supports it.
aoqi@0 859
aoqi@0 860 typedef jint xchg_func_t (jint, volatile jint*);
aoqi@0 861 typedef jint cmpxchg_func_t (jint, volatile jint*, jint);
aoqi@0 862 typedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong);
aoqi@0 863 typedef jint add_func_t (jint, volatile jint*);
aoqi@0 864
aoqi@0 865 jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) {
aoqi@0 866 // try to use the stub:
aoqi@0 867 xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
aoqi@0 868
aoqi@0 869 if (func != NULL) {
aoqi@0 870 os::atomic_xchg_func = func;
aoqi@0 871 return (*func)(exchange_value, dest);
aoqi@0 872 }
aoqi@0 873 assert(Threads::number_of_threads() == 0, "for bootstrap only");
aoqi@0 874
aoqi@0 875 jint old_value = *dest;
aoqi@0 876 *dest = exchange_value;
aoqi@0 877 return old_value;
aoqi@0 878 }
aoqi@0 879
aoqi@0 880 jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) {
aoqi@0 881 // try to use the stub:
aoqi@0 882 cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
aoqi@0 883
aoqi@0 884 if (func != NULL) {
aoqi@0 885 os::atomic_cmpxchg_func = func;
aoqi@0 886 return (*func)(exchange_value, dest, compare_value);
aoqi@0 887 }
aoqi@0 888 assert(Threads::number_of_threads() == 0, "for bootstrap only");
aoqi@0 889
aoqi@0 890 jint old_value = *dest;
aoqi@0 891 if (old_value == compare_value)
aoqi@0 892 *dest = exchange_value;
aoqi@0 893 return old_value;
aoqi@0 894 }
aoqi@0 895
aoqi@0 896 jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) {
aoqi@0 897 // try to use the stub:
aoqi@0 898 cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry());
aoqi@0 899
aoqi@0 900 if (func != NULL) {
aoqi@0 901 os::atomic_cmpxchg_long_func = func;
aoqi@0 902 return (*func)(exchange_value, dest, compare_value);
aoqi@0 903 }
aoqi@0 904 assert(Threads::number_of_threads() == 0, "for bootstrap only");
aoqi@0 905
aoqi@0 906 jlong old_value = *dest;
aoqi@0 907 if (old_value == compare_value)
aoqi@0 908 *dest = exchange_value;
aoqi@0 909 return old_value;
aoqi@0 910 }
aoqi@0 911
aoqi@0 912 jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) {
aoqi@0 913 // try to use the stub:
aoqi@0 914 add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
aoqi@0 915
aoqi@0 916 if (func != NULL) {
aoqi@0 917 os::atomic_add_func = func;
aoqi@0 918 return (*func)(add_value, dest);
aoqi@0 919 }
aoqi@0 920 assert(Threads::number_of_threads() == 0, "for bootstrap only");
aoqi@0 921
aoqi@0 922 return (*dest) += add_value;
aoqi@0 923 }
aoqi@0 924
aoqi@0 925 xchg_func_t* os::atomic_xchg_func = os::atomic_xchg_bootstrap;
aoqi@0 926 cmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap;
aoqi@0 927 cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
aoqi@0 928 add_func_t* os::atomic_add_func = os::atomic_add_bootstrap;
aoqi@0 929
aoqi@0 930 extern "C" void _solaris_raw_setup_fpu(address ptr);
aoqi@0 931 void os::setup_fpu() {
aoqi@0 932 address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std();
aoqi@0 933 _solaris_raw_setup_fpu(fpu_cntrl);
aoqi@0 934 }
aoqi@0 935 #endif // AMD64
aoqi@0 936
aoqi@0 937 #ifndef PRODUCT
aoqi@0 938 void os::verify_stack_alignment() {
aoqi@0 939 #ifdef AMD64
aoqi@0 940 assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
aoqi@0 941 #endif
aoqi@0 942 }
aoqi@0 943 #endif

mercurial