src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,943 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// no precompiled headers
    1.29 +#include "asm/macroAssembler.hpp"
    1.30 +#include "classfile/classLoader.hpp"
    1.31 +#include "classfile/systemDictionary.hpp"
    1.32 +#include "classfile/vmSymbols.hpp"
    1.33 +#include "code/icBuffer.hpp"
    1.34 +#include "code/vtableStubs.hpp"
    1.35 +#include "interpreter/interpreter.hpp"
    1.36 +#include "jvm_solaris.h"
    1.37 +#include "memory/allocation.inline.hpp"
    1.38 +#include "mutex_solaris.inline.hpp"
    1.39 +#include "os_share_solaris.hpp"
    1.40 +#include "prims/jniFastGetField.hpp"
    1.41 +#include "prims/jvm.h"
    1.42 +#include "prims/jvm_misc.hpp"
    1.43 +#include "runtime/arguments.hpp"
    1.44 +#include "runtime/extendedPC.hpp"
    1.45 +#include "runtime/frame.inline.hpp"
    1.46 +#include "runtime/interfaceSupport.hpp"
    1.47 +#include "runtime/java.hpp"
    1.48 +#include "runtime/javaCalls.hpp"
    1.49 +#include "runtime/mutexLocker.hpp"
    1.50 +#include "runtime/osThread.hpp"
    1.51 +#include "runtime/sharedRuntime.hpp"
    1.52 +#include "runtime/stubRoutines.hpp"
    1.53 +#include "runtime/thread.inline.hpp"
    1.54 +#include "runtime/timer.hpp"
    1.55 +#include "utilities/events.hpp"
    1.56 +#include "utilities/vmError.hpp"
    1.57 +
    1.58 +// put OS-includes here
    1.59 +# include <sys/types.h>
    1.60 +# include <sys/mman.h>
    1.61 +# include <pthread.h>
    1.62 +# include <signal.h>
    1.63 +# include <setjmp.h>
    1.64 +# include <errno.h>
    1.65 +# include <dlfcn.h>
    1.66 +# include <stdio.h>
    1.67 +# include <unistd.h>
    1.68 +# include <sys/resource.h>
    1.69 +# include <thread.h>
    1.70 +# include <sys/stat.h>
    1.71 +# include <sys/time.h>
    1.72 +# include <sys/filio.h>
    1.73 +# include <sys/utsname.h>
    1.74 +# include <sys/systeminfo.h>
    1.75 +# include <sys/socket.h>
    1.76 +# include <sys/trap.h>
    1.77 +# include <sys/lwp.h>
    1.78 +# include <pwd.h>
    1.79 +# include <poll.h>
    1.80 +# include <sys/lwp.h>
    1.81 +# include <procfs.h>     //  see comment in <sys/procfs.h>
    1.82 +
    1.83 +#ifndef AMD64
    1.84 +// QQQ seems useless at this point
    1.85 +# define _STRUCTURED_PROC 1  //  this gets us the new structured proc interfaces of 5.6 & later
    1.86 +#endif // AMD64
    1.87 +# include <sys/procfs.h>     //  see comment in <sys/procfs.h>
    1.88 +
    1.89 +
    1.90 +#define MAX_PATH (2 * K)
    1.91 +
    1.92 +// Minimum stack size for the VM.  It's easier to document a constant value
    1.93 +// but it's different for x86 and sparc because the page sizes are different.
    1.94 +#ifdef AMD64
    1.95 +size_t os::Solaris::min_stack_allowed = 224*K;
    1.96 +#define REG_SP REG_RSP
    1.97 +#define REG_PC REG_RIP
    1.98 +#define REG_FP REG_RBP
    1.99 +#else
   1.100 +size_t os::Solaris::min_stack_allowed = 64*K;
   1.101 +#define REG_SP UESP
   1.102 +#define REG_PC EIP
   1.103 +#define REG_FP EBP
   1.104 +// 4900493 counter to prevent runaway LDTR refresh attempt
   1.105 +
   1.106 +static volatile int ldtr_refresh = 0;
   1.107 +// the libthread instruction that faults because of the stale LDTR
   1.108 +
   1.109 +static const unsigned char movlfs[] = { 0x8e, 0xe0    // movl %eax,%fs
   1.110 +                       };
   1.111 +#endif // AMD64
   1.112 +
   1.113 +char* os::non_memory_address_word() {
   1.114 +  // Must never look like an address returned by reserve_memory,
   1.115 +  // even in its subfields (as defined by the CPU immediate fields,
   1.116 +  // if the CPU splits constants across multiple instructions).
   1.117 +  return (char*) -1;
   1.118 +}
   1.119 +
   1.120 +//
   1.121 +// Validate a ucontext retrieved from walking a uc_link of a ucontext.
   1.122 +// There are issues with libthread giving out uc_links for different threads
   1.123 +// on the same uc_link chain and bad or circular links.
   1.124 +//
   1.125 +bool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) {
   1.126 +  if (valid >= suspect ||
   1.127 +      valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags ||
   1.128 +      valid->uc_stack.ss_sp    != suspect->uc_stack.ss_sp    ||
   1.129 +      valid->uc_stack.ss_size  != suspect->uc_stack.ss_size) {
   1.130 +    DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");)
   1.131 +    return false;
   1.132 +  }
   1.133 +
   1.134 +  if (thread->is_Java_thread()) {
   1.135 +    if (!valid_stack_address(thread, (address)suspect)) {
   1.136 +      DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");)
   1.137 +      return false;
   1.138 +    }
   1.139 +    if (!valid_stack_address(thread,  (address) suspect->uc_mcontext.gregs[REG_SP])) {
   1.140 +      DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");)
   1.141 +      return false;
   1.142 +    }
   1.143 +  }
   1.144 +  return true;
   1.145 +}
   1.146 +
   1.147 +// We will only follow one level of uc_link since there are libthread
   1.148 +// issues with ucontext linking and it is better to be safe and just
   1.149 +// let caller retry later.
   1.150 +ucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread,
   1.151 +  ucontext_t *uc) {
   1.152 +
   1.153 +  ucontext_t *retuc = NULL;
   1.154 +
   1.155 +  if (uc != NULL) {
   1.156 +    if (uc->uc_link == NULL) {
   1.157 +      // cannot validate without uc_link so accept current ucontext
   1.158 +      retuc = uc;
   1.159 +    } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
   1.160 +      // first ucontext is valid so try the next one
   1.161 +      uc = uc->uc_link;
   1.162 +      if (uc->uc_link == NULL) {
   1.163 +        // cannot validate without uc_link so accept current ucontext
   1.164 +        retuc = uc;
   1.165 +      } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
   1.166 +        // the ucontext one level down is also valid so return it
   1.167 +        retuc = uc;
   1.168 +      }
   1.169 +    }
   1.170 +  }
   1.171 +  return retuc;
   1.172 +}
   1.173 +
   1.174 +// Assumes ucontext is valid
   1.175 +ExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) {
   1.176 +  return ExtendedPC((address)uc->uc_mcontext.gregs[REG_PC]);
   1.177 +}
   1.178 +
   1.179 +// Assumes ucontext is valid
   1.180 +intptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) {
   1.181 +  return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
   1.182 +}
   1.183 +
   1.184 +// Assumes ucontext is valid
   1.185 +intptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) {
   1.186 +  return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
   1.187 +}
   1.188 +
   1.189 +address os::Solaris::ucontext_get_pc(ucontext_t *uc) {
   1.190 +  return (address) uc->uc_mcontext.gregs[REG_PC];
   1.191 +}
   1.192 +
   1.193 +// For Forte Analyzer AsyncGetCallTrace profiling support - thread
   1.194 +// is currently interrupted by SIGPROF.
   1.195 +//
   1.196 +// The difference between this and os::fetch_frame_from_context() is that
   1.197 +// here we try to skip nested signal frames.
   1.198 +ExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread,
   1.199 +  ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
   1.200 +
   1.201 +  assert(thread != NULL, "just checking");
   1.202 +  assert(ret_sp != NULL, "just checking");
   1.203 +  assert(ret_fp != NULL, "just checking");
   1.204 +
   1.205 +  ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc);
   1.206 +  return os::fetch_frame_from_context(luc, ret_sp, ret_fp);
   1.207 +}
   1.208 +
   1.209 +ExtendedPC os::fetch_frame_from_context(void* ucVoid,
   1.210 +                    intptr_t** ret_sp, intptr_t** ret_fp) {
   1.211 +
   1.212 +  ExtendedPC  epc;
   1.213 +  ucontext_t *uc = (ucontext_t*)ucVoid;
   1.214 +
   1.215 +  if (uc != NULL) {
   1.216 +    epc = os::Solaris::ucontext_get_ExtendedPC(uc);
   1.217 +    if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc);
   1.218 +    if (ret_fp) *ret_fp = os::Solaris::ucontext_get_fp(uc);
   1.219 +  } else {
   1.220 +    // construct empty ExtendedPC for return value checking
   1.221 +    epc = ExtendedPC(NULL);
   1.222 +    if (ret_sp) *ret_sp = (intptr_t *)NULL;
   1.223 +    if (ret_fp) *ret_fp = (intptr_t *)NULL;
   1.224 +  }
   1.225 +
   1.226 +  return epc;
   1.227 +}
   1.228 +
   1.229 +frame os::fetch_frame_from_context(void* ucVoid) {
   1.230 +  intptr_t* sp;
   1.231 +  intptr_t* fp;
   1.232 +  ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
   1.233 +  return frame(sp, fp, epc.pc());
   1.234 +}
   1.235 +
   1.236 +frame os::get_sender_for_C_frame(frame* fr) {
   1.237 +  return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
   1.238 +}
   1.239 +
   1.240 +extern "C" intptr_t *_get_current_sp();  // in .il file
   1.241 +
   1.242 +address os::current_stack_pointer() {
   1.243 +  return (address)_get_current_sp();
   1.244 +}
   1.245 +
   1.246 +extern "C" intptr_t *_get_current_fp();  // in .il file
   1.247 +
   1.248 +frame os::current_frame() {
   1.249 +  intptr_t* fp = _get_current_fp();  // it's inlined so want current fp
   1.250 +  frame myframe((intptr_t*)os::current_stack_pointer(),
   1.251 +                (intptr_t*)fp,
   1.252 +                CAST_FROM_FN_PTR(address, os::current_frame));
   1.253 +  if (os::is_first_C_frame(&myframe)) {
   1.254 +    // stack is not walkable
   1.255 +    frame ret; // This will be a null useless frame
   1.256 +    return ret;
   1.257 +  } else {
   1.258 +    return os::get_sender_for_C_frame(&myframe);
   1.259 +  }
   1.260 +}
   1.261 +
   1.262 +static int threadgetstate(thread_t tid, int *flags, lwpid_t *lwp, stack_t *ss, gregset_t rs, lwpstatus_t *lwpstatus) {
   1.263 +  char lwpstatusfile[PROCFILE_LENGTH];
   1.264 +  int lwpfd, err;
   1.265 +
   1.266 +  if (err = os::Solaris::thr_getstate(tid, flags, lwp, ss, rs))
   1.267 +    return (err);
   1.268 +  if (*flags == TRS_LWPID) {
   1.269 +    sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(),
   1.270 +            *lwp);
   1.271 +    if ((lwpfd = open(lwpstatusfile, O_RDONLY)) < 0) {
   1.272 +      perror("thr_mutator_status: open lwpstatus");
   1.273 +      return (EINVAL);
   1.274 +    }
   1.275 +    if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) !=
   1.276 +        sizeof (lwpstatus_t)) {
   1.277 +      perror("thr_mutator_status: read lwpstatus");
   1.278 +      (void) close(lwpfd);
   1.279 +      return (EINVAL);
   1.280 +    }
   1.281 +    (void) close(lwpfd);
   1.282 +  }
   1.283 +  return (0);
   1.284 +}
   1.285 +
   1.286 +#ifndef AMD64
   1.287 +
   1.288 +// Detecting SSE support by OS
   1.289 +// From solaris_i486.s
   1.290 +extern "C" bool sse_check();
   1.291 +extern "C" bool sse_unavailable();
   1.292 +
   1.293 +enum { SSE_UNKNOWN, SSE_NOT_SUPPORTED, SSE_SUPPORTED};
   1.294 +static int sse_status = SSE_UNKNOWN;
   1.295 +
   1.296 +
   1.297 +static void  check_for_sse_support() {
   1.298 +  if (!VM_Version::supports_sse()) {
   1.299 +    sse_status = SSE_NOT_SUPPORTED;
   1.300 +    return;
   1.301 +  }
   1.302 +  // looking for _sse_hw in libc.so, if it does not exist or
   1.303 +  // the value (int) is 0, OS has no support for SSE
   1.304 +  int *sse_hwp;
   1.305 +  void *h;
   1.306 +
   1.307 +  if ((h=dlopen("/usr/lib/libc.so", RTLD_LAZY)) == NULL) {
   1.308 +    //open failed, presume no support for SSE
   1.309 +    sse_status = SSE_NOT_SUPPORTED;
   1.310 +    return;
   1.311 +  }
   1.312 +  if ((sse_hwp = (int *)dlsym(h, "_sse_hw")) == NULL) {
   1.313 +    sse_status = SSE_NOT_SUPPORTED;
   1.314 +  } else if (*sse_hwp == 0) {
   1.315 +    sse_status = SSE_NOT_SUPPORTED;
   1.316 +  }
   1.317 +  dlclose(h);
   1.318 +
   1.319 +  if (sse_status == SSE_UNKNOWN) {
   1.320 +    bool (*try_sse)() = (bool (*)())sse_check;
   1.321 +    sse_status = (*try_sse)() ? SSE_SUPPORTED : SSE_NOT_SUPPORTED;
   1.322 +  }
   1.323 +
   1.324 +}
   1.325 +
   1.326 +#endif // AMD64
   1.327 +
   1.328 +bool os::supports_sse() {
   1.329 +#ifdef AMD64
   1.330 +  return true;
   1.331 +#else
   1.332 +  if (sse_status == SSE_UNKNOWN)
   1.333 +    check_for_sse_support();
   1.334 +  return sse_status == SSE_SUPPORTED;
   1.335 +#endif // AMD64
   1.336 +}
   1.337 +
   1.338 +bool os::is_allocatable(size_t bytes) {
   1.339 +#ifdef AMD64
   1.340 +  return true;
   1.341 +#else
   1.342 +
   1.343 +  if (bytes < 2 * G) {
   1.344 +    return true;
   1.345 +  }
   1.346 +
   1.347 +  char* addr = reserve_memory(bytes, NULL);
   1.348 +
   1.349 +  if (addr != NULL) {
   1.350 +    release_memory(addr, bytes);
   1.351 +  }
   1.352 +
   1.353 +  return addr != NULL;
   1.354 +#endif // AMD64
   1.355 +
   1.356 +}
   1.357 +
   1.358 +extern "C" JNIEXPORT int
   1.359 +JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
   1.360 +                          int abort_if_unrecognized) {
   1.361 +  ucontext_t* uc = (ucontext_t*) ucVoid;
   1.362 +
   1.363 +#ifndef AMD64
   1.364 +  if (sig == SIGILL && info->si_addr == (caddr_t)sse_check) {
   1.365 +    // the SSE instruction faulted. supports_sse() need return false.
   1.366 +    uc->uc_mcontext.gregs[EIP] = (greg_t)sse_unavailable;
   1.367 +    return true;
   1.368 +  }
   1.369 +#endif // !AMD64
   1.370 +
   1.371 +  Thread* t = ThreadLocalStorage::get_thread_slow();  // slow & steady
   1.372 +
   1.373 +  // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
   1.374 +  // (no destructors can be run)
   1.375 +  os::WatcherThreadCrashProtection::check_crash_protection(sig, t);
   1.376 +
   1.377 +  SignalHandlerMark shm(t);
   1.378 +
   1.379 +  if(sig == SIGPIPE || sig == SIGXFSZ) {
   1.380 +    if (os::Solaris::chained_handler(sig, info, ucVoid)) {
   1.381 +      return true;
   1.382 +    } else {
   1.383 +      if (PrintMiscellaneous && (WizardMode || Verbose)) {
   1.384 +        char buf[64];
   1.385 +        warning("Ignoring %s - see 4229104 or 6499219",
   1.386 +                os::exception_name(sig, buf, sizeof(buf)));
   1.387 +
   1.388 +      }
   1.389 +      return true;
   1.390 +    }
   1.391 +  }
   1.392 +
   1.393 +  JavaThread* thread = NULL;
   1.394 +  VMThread* vmthread = NULL;
   1.395 +
   1.396 +  if (os::Solaris::signal_handlers_are_installed) {
   1.397 +    if (t != NULL ){
   1.398 +      if(t->is_Java_thread()) {
   1.399 +        thread = (JavaThread*)t;
   1.400 +      }
   1.401 +      else if(t->is_VM_thread()){
   1.402 +        vmthread = (VMThread *)t;
   1.403 +      }
   1.404 +    }
   1.405 +  }
   1.406 +
   1.407 +  guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs");
   1.408 +
   1.409 +  if (sig == os::Solaris::SIGasync()) {
   1.410 +    if(thread || vmthread){
   1.411 +      OSThread::SR_handler(t, uc);
   1.412 +      return true;
   1.413 +    } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
   1.414 +      return true;
   1.415 +    } else {
   1.416 +      // If os::Solaris::SIGasync not chained, and this is a non-vm and
   1.417 +      // non-java thread
   1.418 +      return true;
   1.419 +    }
   1.420 +  }
   1.421 +
   1.422 +  if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
   1.423 +    // can't decode this kind of signal
   1.424 +    info = NULL;
   1.425 +  } else {
   1.426 +    assert(sig == info->si_signo, "bad siginfo");
   1.427 +  }
   1.428 +
   1.429 +  // decide if this trap can be handled by a stub
   1.430 +  address stub = NULL;
   1.431 +
   1.432 +  address pc          = NULL;
   1.433 +
   1.434 +  //%note os_trap_1
   1.435 +  if (info != NULL && uc != NULL && thread != NULL) {
   1.436 +    // factor me: getPCfromContext
   1.437 +    pc = (address) uc->uc_mcontext.gregs[REG_PC];
   1.438 +
   1.439 +    if (StubRoutines::is_safefetch_fault(pc)) {
   1.440 +      uc->uc_mcontext.gregs[REG_PC] = intptr_t(StubRoutines::continuation_for_safefetch_fault(pc));
   1.441 +      return true;
   1.442 +    }
   1.443 +
   1.444 +    // Handle ALL stack overflow variations here
   1.445 +    if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
   1.446 +      address addr = (address) info->si_addr;
   1.447 +      if (thread->in_stack_yellow_zone(addr)) {
   1.448 +        thread->disable_stack_yellow_zone();
   1.449 +        if (thread->thread_state() == _thread_in_Java) {
   1.450 +          // Throw a stack overflow exception.  Guard pages will be reenabled
   1.451 +          // while unwinding the stack.
   1.452 +          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
   1.453 +        } else {
   1.454 +          // Thread was in the vm or native code.  Return and try to finish.
   1.455 +          return true;
   1.456 +        }
   1.457 +      } else if (thread->in_stack_red_zone(addr)) {
   1.458 +        // Fatal red zone violation.  Disable the guard pages and fall through
   1.459 +        // to handle_unexpected_exception way down below.
   1.460 +        thread->disable_stack_red_zone();
   1.461 +        tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
   1.462 +      }
   1.463 +    }
   1.464 +
   1.465 +    if ((sig == SIGSEGV) && VM_Version::is_cpuinfo_segv_addr(pc)) {
   1.466 +      // Verify that OS save/restore AVX registers.
   1.467 +      stub = VM_Version::cpuinfo_cont_addr();
   1.468 +    }
   1.469 +
   1.470 +    if (thread->thread_state() == _thread_in_vm) {
   1.471 +      if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) {
   1.472 +        stub = StubRoutines::handler_for_unsafe_access();
   1.473 +      }
   1.474 +    }
   1.475 +
   1.476 +    if (thread->thread_state() == _thread_in_Java) {
   1.477 +      // Support Safepoint Polling
   1.478 +      if ( sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
   1.479 +        stub = SharedRuntime::get_poll_stub(pc);
   1.480 +      }
   1.481 +      else if (sig == SIGBUS && info->si_code == BUS_OBJERR) {
   1.482 +        // BugId 4454115: A read from a MappedByteBuffer can fault
   1.483 +        // here if the underlying file has been truncated.
   1.484 +        // Do not crash the VM in such a case.
   1.485 +        CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
   1.486 +        if (cb != NULL) {
   1.487 +          nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
   1.488 +          if (nm != NULL && nm->has_unsafe_access()) {
   1.489 +            stub = StubRoutines::handler_for_unsafe_access();
   1.490 +          }
   1.491 +        }
   1.492 +      }
   1.493 +      else
   1.494 +      if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
   1.495 +        // integer divide by zero
   1.496 +        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
   1.497 +      }
   1.498 +#ifndef AMD64
   1.499 +      else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) {
   1.500 +        // floating-point divide by zero
   1.501 +        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
   1.502 +      }
   1.503 +      else if (sig == SIGFPE && info->si_code == FPE_FLTINV) {
   1.504 +        // The encoding of D2I in i486.ad can cause an exception prior
   1.505 +        // to the fist instruction if there was an invalid operation
   1.506 +        // pending. We want to dismiss that exception. From the win_32
   1.507 +        // side it also seems that if it really was the fist causing
   1.508 +        // the exception that we do the d2i by hand with different
   1.509 +        // rounding. Seems kind of weird. QQQ TODO
   1.510 +        // Note that we take the exception at the NEXT floating point instruction.
   1.511 +        if (pc[0] == 0xDB) {
   1.512 +            assert(pc[0] == 0xDB, "not a FIST opcode");
   1.513 +            assert(pc[1] == 0x14, "not a FIST opcode");
   1.514 +            assert(pc[2] == 0x24, "not a FIST opcode");
   1.515 +            return true;
   1.516 +        } else {
   1.517 +            assert(pc[-3] == 0xDB, "not an flt invalid opcode");
   1.518 +            assert(pc[-2] == 0x14, "not an flt invalid opcode");
   1.519 +            assert(pc[-1] == 0x24, "not an flt invalid opcode");
   1.520 +        }
   1.521 +      }
   1.522 +      else if (sig == SIGFPE ) {
   1.523 +        tty->print_cr("caught SIGFPE, info 0x%x.", info->si_code);
   1.524 +      }
   1.525 +#endif // !AMD64
   1.526 +
   1.527 +        // QQQ It doesn't seem that we need to do this on x86 because we should be able
   1.528 +        // to return properly from the handler without this extra stuff on the back side.
   1.529 +
   1.530 +      else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
   1.531 +        // Determination of interpreter/vtable stub/compiled code null exception
   1.532 +        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
   1.533 +      }
   1.534 +    }
   1.535 +
   1.536 +    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
   1.537 +    // and the heap gets shrunk before the field access.
   1.538 +    if ((sig == SIGSEGV) || (sig == SIGBUS)) {
   1.539 +      address addr = JNI_FastGetField::find_slowcase_pc(pc);
   1.540 +      if (addr != (address)-1) {
   1.541 +        stub = addr;
   1.542 +      }
   1.543 +    }
   1.544 +
   1.545 +    // Check to see if we caught the safepoint code in the
   1.546 +    // process of write protecting the memory serialization page.
   1.547 +    // It write enables the page immediately after protecting it
   1.548 +    // so we can just return to retry the write.
   1.549 +    if ((sig == SIGSEGV) &&
   1.550 +        os::is_memory_serialize_page(thread, (address)info->si_addr)) {
   1.551 +      // Block current thread until the memory serialize page permission restored.
   1.552 +      os::block_on_serialize_page_trap();
   1.553 +      return true;
   1.554 +    }
   1.555 +  }
   1.556 +
   1.557 +  // Execution protection violation
   1.558 +  //
   1.559 +  // Preventative code for future versions of Solaris which may
   1.560 +  // enable execution protection when running the 32-bit VM on AMD64.
   1.561 +  //
   1.562 +  // This should be kept as the last step in the triage.  We don't
   1.563 +  // have a dedicated trap number for a no-execute fault, so be
   1.564 +  // conservative and allow other handlers the first shot.
   1.565 +  //
   1.566 +  // Note: We don't test that info->si_code == SEGV_ACCERR here.
   1.567 +  // this si_code is so generic that it is almost meaningless; and
   1.568 +  // the si_code for this condition may change in the future.
   1.569 +  // Furthermore, a false-positive should be harmless.
   1.570 +  if (UnguardOnExecutionViolation > 0 &&
   1.571 +      (sig == SIGSEGV || sig == SIGBUS) &&
   1.572 +      uc->uc_mcontext.gregs[TRAPNO] == T_PGFLT) {  // page fault
   1.573 +    int page_size = os::vm_page_size();
   1.574 +    address addr = (address) info->si_addr;
   1.575 +    address pc = (address) uc->uc_mcontext.gregs[REG_PC];
   1.576 +    // Make sure the pc and the faulting address are sane.
   1.577 +    //
   1.578 +    // If an instruction spans a page boundary, and the page containing
   1.579 +    // the beginning of the instruction is executable but the following
   1.580 +    // page is not, the pc and the faulting address might be slightly
   1.581 +    // different - we still want to unguard the 2nd page in this case.
   1.582 +    //
   1.583 +    // 15 bytes seems to be a (very) safe value for max instruction size.
   1.584 +    bool pc_is_near_addr =
   1.585 +      (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
   1.586 +    bool instr_spans_page_boundary =
   1.587 +      (align_size_down((intptr_t) pc ^ (intptr_t) addr,
   1.588 +                       (intptr_t) page_size) > 0);
   1.589 +
   1.590 +    if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
   1.591 +      static volatile address last_addr =
   1.592 +        (address) os::non_memory_address_word();
   1.593 +
   1.594 +      // In conservative mode, don't unguard unless the address is in the VM
   1.595 +      if (addr != last_addr &&
   1.596 +          (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
   1.597 +
   1.598 +        // Make memory rwx and retry
   1.599 +        address page_start =
   1.600 +          (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
   1.601 +        bool res = os::protect_memory((char*) page_start, page_size,
   1.602 +                                      os::MEM_PROT_RWX);
   1.603 +
   1.604 +        if (PrintMiscellaneous && Verbose) {
   1.605 +          char buf[256];
   1.606 +          jio_snprintf(buf, sizeof(buf), "Execution protection violation "
   1.607 +                       "at " INTPTR_FORMAT
   1.608 +                       ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr,
   1.609 +                       page_start, (res ? "success" : "failed"), errno);
   1.610 +          tty->print_raw_cr(buf);
   1.611 +        }
   1.612 +        stub = pc;
   1.613 +
   1.614 +        // Set last_addr so if we fault again at the same address, we don't end
   1.615 +        // up in an endless loop.
   1.616 +        //
   1.617 +        // There are two potential complications here.  Two threads trapping at
   1.618 +        // the same address at the same time could cause one of the threads to
   1.619 +        // think it already unguarded, and abort the VM.  Likely very rare.
   1.620 +        //
   1.621 +        // The other race involves two threads alternately trapping at
   1.622 +        // different addresses and failing to unguard the page, resulting in
   1.623 +        // an endless loop.  This condition is probably even more unlikely than
   1.624 +        // the first.
   1.625 +        //
   1.626 +        // Although both cases could be avoided by using locks or thread local
   1.627 +        // last_addr, these solutions are unnecessary complication: this
   1.628 +        // handler is a best-effort safety net, not a complete solution.  It is
   1.629 +        // disabled by default and should only be used as a workaround in case
   1.630 +        // we missed any no-execute-unsafe VM code.
   1.631 +
   1.632 +        last_addr = addr;
   1.633 +      }
   1.634 +    }
   1.635 +  }
   1.636 +
   1.637 +  if (stub != NULL) {
   1.638 +    // save all thread context in case we need to restore it
   1.639 +
   1.640 +    if (thread != NULL) thread->set_saved_exception_pc(pc);
   1.641 +    // 12/02/99: On Sparc it appears that the full context is also saved
   1.642 +    // but as yet, no one looks at or restores that saved context
   1.643 +    // factor me: setPC
   1.644 +    uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub;
   1.645 +    return true;
   1.646 +  }
   1.647 +
   1.648 +  // signal-chaining
   1.649 +  if (os::Solaris::chained_handler(sig, info, ucVoid)) {
   1.650 +    return true;
   1.651 +  }
   1.652 +
   1.653 +#ifndef AMD64
   1.654 +  // Workaround (bug 4900493) for Solaris kernel bug 4966651.
   1.655 +  // Handle an undefined selector caused by an attempt to assign
   1.656 +  // fs in libthread getipriptr(). With the current libthread design every 512
   1.657 +  // thread creations the LDT for a private thread data structure is extended
   1.658 +  // and thre is a hazard that and another thread attempting a thread creation
   1.659 +  // will use a stale LDTR that doesn't reflect the structure's growth,
   1.660 +  // causing a GP fault.
   1.661 +  // Enforce the probable limit of passes through here to guard against an
   1.662 +  // infinite loop if some other move to fs caused the GP fault. Note that
   1.663 +  // this loop counter is ultimately a heuristic as it is possible for
   1.664 +  // more than one thread to generate this fault at a time in an MP system.
   1.665 +  // In the case of the loop count being exceeded or if the poll fails
   1.666 +  // just fall through to a fatal error.
   1.667 +  // If there is some other source of T_GPFLT traps and the text at EIP is
   1.668 +  // unreadable this code will loop infinitely until the stack is exausted.
   1.669 +  // The key to diagnosis in this case is to look for the bottom signal handler
   1.670 +  // frame.
   1.671 +
   1.672 +  if(! IgnoreLibthreadGPFault) {
   1.673 +    if (sig == SIGSEGV && uc->uc_mcontext.gregs[TRAPNO] == T_GPFLT) {
   1.674 +      const unsigned char *p =
   1.675 +                        (unsigned const char *) uc->uc_mcontext.gregs[EIP];
   1.676 +
   1.677 +      // Expected instruction?
   1.678 +
   1.679 +      if(p[0] == movlfs[0] && p[1] == movlfs[1]) {
   1.680 +
   1.681 +        Atomic::inc(&ldtr_refresh);
   1.682 +
   1.683 +        // Infinite loop?
   1.684 +
   1.685 +        if(ldtr_refresh < ((2 << 16) / PAGESIZE)) {
   1.686 +
   1.687 +          // No, force scheduling to get a fresh view of the LDTR
   1.688 +
   1.689 +          if(poll(NULL, 0, 10) == 0) {
   1.690 +
   1.691 +            // Retry the move
   1.692 +
   1.693 +            return false;
   1.694 +          }
   1.695 +        }
   1.696 +      }
   1.697 +    }
   1.698 +  }
   1.699 +#endif // !AMD64
   1.700 +
   1.701 +  if (!abort_if_unrecognized) {
   1.702 +    // caller wants another chance, so give it to him
   1.703 +    return false;
   1.704 +  }
   1.705 +
   1.706 +  if (!os::Solaris::libjsig_is_loaded) {
   1.707 +    struct sigaction oldAct;
   1.708 +    sigaction(sig, (struct sigaction *)0, &oldAct);
   1.709 +    if (oldAct.sa_sigaction != signalHandler) {
   1.710 +      void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oldAct.sa_sigaction)
   1.711 +                                          : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
   1.712 +      warning("Unexpected Signal %d occurred under user-defined signal handler %#lx", sig, (long)sighand);
   1.713 +    }
   1.714 +  }
   1.715 +
   1.716 +  if (pc == NULL && uc != NULL) {
   1.717 +    pc = (address) uc->uc_mcontext.gregs[REG_PC];
   1.718 +  }
   1.719 +
   1.720 +  // unmask current signal
   1.721 +  sigset_t newset;
   1.722 +  sigemptyset(&newset);
   1.723 +  sigaddset(&newset, sig);
   1.724 +  sigprocmask(SIG_UNBLOCK, &newset, NULL);
   1.725 +
   1.726 +  // Determine which sort of error to throw.  Out of swap may signal
   1.727 +  // on the thread stack, which could get a mapping error when touched.
   1.728 +  address addr = (address) info->si_addr;
   1.729 +  if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) {
   1.730 +    vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "Out of swap space to map in thread stack.");
   1.731 +  }
   1.732 +
   1.733 +  VMError err(t, sig, pc, info, ucVoid);
   1.734 +  err.report_and_die();
   1.735 +
   1.736 +  ShouldNotReachHere();
   1.737 +  return false;
   1.738 +}
   1.739 +
   1.740 +void os::print_context(outputStream *st, void *context) {
   1.741 +  if (context == NULL) return;
   1.742 +
   1.743 +  ucontext_t *uc = (ucontext_t*)context;
   1.744 +  st->print_cr("Registers:");
   1.745 +#ifdef AMD64
   1.746 +  st->print(  "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
   1.747 +  st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
   1.748 +  st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]);
   1.749 +  st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]);
   1.750 +  st->cr();
   1.751 +  st->print(  "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]);
   1.752 +  st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]);
   1.753 +  st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]);
   1.754 +  st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]);
   1.755 +  st->cr();
   1.756 +  st->print(  "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]);
   1.757 +  st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]);
   1.758 +  st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]);
   1.759 +  st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]);
   1.760 +  st->cr();
   1.761 +  st->print(  "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]);
   1.762 +  st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]);
   1.763 +  st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]);
   1.764 +  st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]);
   1.765 +  st->cr();
   1.766 +  st->print(  "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]);
   1.767 +  st->print(", RFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RFL]);
   1.768 +#else
   1.769 +  st->print(  "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EAX]);
   1.770 +  st->print(", EBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EBX]);
   1.771 +  st->print(", ECX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[ECX]);
   1.772 +  st->print(", EDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EDX]);
   1.773 +  st->cr();
   1.774 +  st->print(  "ESP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[UESP]);
   1.775 +  st->print(", EBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EBP]);
   1.776 +  st->print(", ESI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[ESI]);
   1.777 +  st->print(", EDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EDI]);
   1.778 +  st->cr();
   1.779 +  st->print(  "EIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EIP]);
   1.780 +  st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[EFL]);
   1.781 +#endif // AMD64
   1.782 +  st->cr();
   1.783 +  st->cr();
   1.784 +
   1.785 +  intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
   1.786 +  st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
   1.787 +  print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
   1.788 +  st->cr();
   1.789 +
   1.790 +  // Note: it may be unsafe to inspect memory near pc. For example, pc may
   1.791 +  // point to garbage if entry point in an nmethod is corrupted. Leave
   1.792 +  // this at the end, and hope for the best.
   1.793 +  ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc);
   1.794 +  address pc = epc.pc();
   1.795 +  st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
   1.796 +  print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
   1.797 +}
   1.798 +
   1.799 +void os::print_register_info(outputStream *st, void *context) {
   1.800 +  if (context == NULL) return;
   1.801 +
   1.802 +  ucontext_t *uc = (ucontext_t*)context;
   1.803 +
   1.804 +  st->print_cr("Register to memory mapping:");
   1.805 +  st->cr();
   1.806 +
   1.807 +  // this is horrendously verbose but the layout of the registers in the
   1.808 +  // context does not match how we defined our abstract Register set, so
   1.809 +  // we can't just iterate through the gregs area
   1.810 +
   1.811 +  // this is only for the "general purpose" registers
   1.812 +
   1.813 +#ifdef AMD64
   1.814 +  st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]);
   1.815 +  st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]);
   1.816 +  st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]);
   1.817 +  st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]);
   1.818 +  st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]);
   1.819 +  st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]);
   1.820 +  st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]);
   1.821 +  st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]);
   1.822 +  st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]);
   1.823 +  st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]);
   1.824 +  st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]);
   1.825 +  st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]);
   1.826 +  st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]);
   1.827 +  st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]);
   1.828 +  st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]);
   1.829 +  st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]);
   1.830 +#else
   1.831 +  st->print("EAX="); print_location(st, uc->uc_mcontext.gregs[EAX]);
   1.832 +  st->print("EBX="); print_location(st, uc->uc_mcontext.gregs[EBX]);
   1.833 +  st->print("ECX="); print_location(st, uc->uc_mcontext.gregs[ECX]);
   1.834 +  st->print("EDX="); print_location(st, uc->uc_mcontext.gregs[EDX]);
   1.835 +  st->print("ESP="); print_location(st, uc->uc_mcontext.gregs[UESP]);
   1.836 +  st->print("EBP="); print_location(st, uc->uc_mcontext.gregs[EBP]);
   1.837 +  st->print("ESI="); print_location(st, uc->uc_mcontext.gregs[ESI]);
   1.838 +  st->print("EDI="); print_location(st, uc->uc_mcontext.gregs[EDI]);
   1.839 +#endif
   1.840 +
   1.841 +  st->cr();
   1.842 +}
   1.843 +
   1.844 +
   1.845 +#ifdef AMD64
   1.846 +void os::Solaris::init_thread_fpu_state(void) {
   1.847 +  // Nothing to do
   1.848 +}
   1.849 +#else
   1.850 +// From solaris_i486.s
   1.851 +extern "C" void fixcw();
   1.852 +
   1.853 +void os::Solaris::init_thread_fpu_state(void) {
   1.854 +  // Set fpu to 53 bit precision. This happens too early to use a stub.
   1.855 +  fixcw();
   1.856 +}
   1.857 +
   1.858 +// These routines are the initial value of atomic_xchg_entry(),
   1.859 +// atomic_cmpxchg_entry(), atomic_inc_entry() and fence_entry()
   1.860 +// until initialization is complete.
   1.861 +// TODO - replace with .il implementation when compiler supports it.
   1.862 +
   1.863 +typedef jint  xchg_func_t        (jint,  volatile jint*);
   1.864 +typedef jint  cmpxchg_func_t     (jint,  volatile jint*,  jint);
   1.865 +typedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong);
   1.866 +typedef jint  add_func_t         (jint,  volatile jint*);
   1.867 +
   1.868 +jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) {
   1.869 +  // try to use the stub:
   1.870 +  xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
   1.871 +
   1.872 +  if (func != NULL) {
   1.873 +    os::atomic_xchg_func = func;
   1.874 +    return (*func)(exchange_value, dest);
   1.875 +  }
   1.876 +  assert(Threads::number_of_threads() == 0, "for bootstrap only");
   1.877 +
   1.878 +  jint old_value = *dest;
   1.879 +  *dest = exchange_value;
   1.880 +  return old_value;
   1.881 +}
   1.882 +
   1.883 +jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) {
   1.884 +  // try to use the stub:
   1.885 +  cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
   1.886 +
   1.887 +  if (func != NULL) {
   1.888 +    os::atomic_cmpxchg_func = func;
   1.889 +    return (*func)(exchange_value, dest, compare_value);
   1.890 +  }
   1.891 +  assert(Threads::number_of_threads() == 0, "for bootstrap only");
   1.892 +
   1.893 +  jint old_value = *dest;
   1.894 +  if (old_value == compare_value)
   1.895 +    *dest = exchange_value;
   1.896 +  return old_value;
   1.897 +}
   1.898 +
   1.899 +jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) {
   1.900 +  // try to use the stub:
   1.901 +  cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry());
   1.902 +
   1.903 +  if (func != NULL) {
   1.904 +    os::atomic_cmpxchg_long_func = func;
   1.905 +    return (*func)(exchange_value, dest, compare_value);
   1.906 +  }
   1.907 +  assert(Threads::number_of_threads() == 0, "for bootstrap only");
   1.908 +
   1.909 +  jlong old_value = *dest;
   1.910 +  if (old_value == compare_value)
   1.911 +    *dest = exchange_value;
   1.912 +  return old_value;
   1.913 +}
   1.914 +
   1.915 +jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) {
   1.916 +  // try to use the stub:
   1.917 +  add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
   1.918 +
   1.919 +  if (func != NULL) {
   1.920 +    os::atomic_add_func = func;
   1.921 +    return (*func)(add_value, dest);
   1.922 +  }
   1.923 +  assert(Threads::number_of_threads() == 0, "for bootstrap only");
   1.924 +
   1.925 +  return (*dest) += add_value;
   1.926 +}
   1.927 +
   1.928 +xchg_func_t*         os::atomic_xchg_func         = os::atomic_xchg_bootstrap;
   1.929 +cmpxchg_func_t*      os::atomic_cmpxchg_func      = os::atomic_cmpxchg_bootstrap;
   1.930 +cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
   1.931 +add_func_t*          os::atomic_add_func          = os::atomic_add_bootstrap;
   1.932 +
   1.933 +extern "C" void _solaris_raw_setup_fpu(address ptr);
   1.934 +void os::setup_fpu() {
   1.935 +  address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std();
   1.936 +  _solaris_raw_setup_fpu(fpu_cntrl);
   1.937 +}
   1.938 +#endif // AMD64
   1.939 +
   1.940 +#ifndef PRODUCT
   1.941 +void os::verify_stack_alignment() {
   1.942 +#ifdef AMD64
   1.943 +  assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
   1.944 +#endif
   1.945 +}
   1.946 +#endif

mercurial