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