annotate src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp @ 4298:5c6a5b30734b

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