hotspot/src/os_cpu/bsd_zero/vm/os_bsd_zero.cpp
author lana
Mon, 16 Jul 2012 14:49:27 -0700
changeset 13239 7bea6829e8d6
parent 11961 0abd4cd26e5a
child 13859 7fe4578493fc
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    26
#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
#include <pthread.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
# include <pthread_np.h> /* For pthread_attr_get_np */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
// no precompiled headers
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
#include "assembler_zero.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
#include "classfile/classLoader.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
#include "classfile/systemDictionary.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
#include "classfile/vmSymbols.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
#include "code/icBuffer.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
#include "code/vtableStubs.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
#include "interpreter/interpreter.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
#include "jvm_bsd.h"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
#include "memory/allocation.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
#include "mutex_bsd.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
#include "nativeInst_zero.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
#include "os_share_bsd.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
#include "prims/jniFastGetField.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
#include "prims/jvm.h"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
#include "prims/jvm_misc.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
#include "runtime/arguments.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
#include "runtime/extendedPC.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
#include "runtime/frame.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
#include "runtime/interfaceSupport.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
#include "runtime/java.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
#include "runtime/javaCalls.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
#include "runtime/mutexLocker.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
#include "runtime/osThread.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
#include "runtime/sharedRuntime.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
#include "runtime/stubRoutines.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
#include "runtime/timer.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
#include "thread_bsd.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
#include "utilities/events.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
#include "utilities/vmError.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
#ifdef COMPILER1
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
#include "c1/c1_Runtime1.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
#ifdef COMPILER2
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
#include "opto/runtime.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
address os::current_stack_pointer() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
  address dummy = (address) &dummy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
  return dummy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
frame os::get_sender_for_C_frame(frame* fr) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
frame os::current_frame() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
  // The only thing that calls this is the stack printing code in
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
  // VMError::report:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
  //   - Step 110 (printing stack bounds) uses the sp in the frame
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
  //     to determine the amount of free space on the stack.  We
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
  //     set the sp to a close approximation of the real value in
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
  //     order to allow this step to complete.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
  //   - Step 120 (printing native stack) tries to walk the stack.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
  //     The frame we create has a NULL pc, which is ignored as an
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
  //     invalid frame.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    87
  frame dummy = frame();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    88
  dummy.set_sp((intptr_t *) current_stack_pointer());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
  return dummy;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    90
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
char* os::non_memory_address_word() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
  // Must never look like an address returned by reserve_memory,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
  // even in its subfields (as defined by the CPU immediate fields,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
  // if the CPU splits constants across multiple instructions).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
#ifdef SPARC
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
  // On SPARC, 0 != %hi(any real address), because there is no
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
  // allocation in the first 1Kb of the virtual address space.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
  return (char *) 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
  // This is the value for x86; works pretty well for PPC too.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
  return (char *) -1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
#endif // SPARC
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
void os::initialize_thread() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
  // Nothing to do.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
address os::Bsd::ucontext_get_pc(ucontext_t* uc) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
ExtendedPC os::fetch_frame_from_context(void* ucVoid,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
                                        intptr_t** ret_sp,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
                                        intptr_t** ret_fp) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
frame os::fetch_frame_from_context(void* ucVoid) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   121
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   122
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   123
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
extern "C" JNIEXPORT int
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
JVM_handle_bsd_signal(int sig,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
                        siginfo_t* info,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
                        void* ucVoid,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
                        int abort_if_unrecognized) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
  ucontext_t* uc = (ucontext_t*) ucVoid;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
  Thread* t = ThreadLocalStorage::get_thread_slow();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
  SignalHandlerMark shm(t);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
  // Note: it's not uncommon that JNI code uses signal/sigset to
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
  // install then restore certain signal handler (e.g. to temporarily
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
  // block SIGPIPE, or have a SIGILL handler when detecting CPU
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   138
  // type). When that happens, JVM_handle_bsd_signal() might be
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
  // invoked with junk info/ucVoid. To avoid unnecessary crash when
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   140
  // libjsig is not preloaded, try handle signals that do not require
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
  // siginfo/ucontext first.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
  if (sig == SIGPIPE || sig == SIGXFSZ) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
    // allow chained handler to go first
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
    if (os::Bsd::chained_handler(sig, info, ucVoid)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
      return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
    } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
      if (PrintMiscellaneous && (WizardMode || Verbose)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
        char buf[64];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
        warning("Ignoring %s - see bugs 4229104 or 646499219",
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   151
                os::exception_name(sig, buf, sizeof(buf)));
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   153
      return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   154
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   155
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   156
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   157
  JavaThread* thread = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   158
  VMThread* vmthread = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   159
  if (os::Bsd::signal_handlers_are_installed) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   160
    if (t != NULL ){
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   161
      if(t->is_Java_thread()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   162
        thread = (JavaThread*)t;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   163
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   164
      else if(t->is_VM_thread()){
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   165
        vmthread = (VMThread *)t;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   166
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   167
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   168
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   169
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   170
  if (info != NULL && thread != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   171
    // Handle ALL stack overflow variations here
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   172
    if (sig == SIGSEGV || sig == SIGBUS) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   173
      address addr = (address) info->si_addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   174
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   175
      // check if fault address is within thread stack
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   176
      if (addr < thread->stack_base() &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   177
          addr >= thread->stack_base() - thread->stack_size()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   178
        // stack overflow
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   179
        if (thread->in_stack_yellow_zone(addr)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   180
          thread->disable_stack_yellow_zone();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   181
          ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   182
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   183
        else if (thread->in_stack_red_zone(addr)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   184
          thread->disable_stack_red_zone();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   185
          ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   186
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   187
#ifndef _ALLBSD_SOURCE
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   188
        else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   189
          // Accessing stack address below sp may cause SEGV if
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   190
          // current thread has MAP_GROWSDOWN stack. This should
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   191
          // only happen when current thread was created by user
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   192
          // code with MAP_GROWSDOWN flag and then attached to VM.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   193
          // See notes in os_bsd.cpp.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   194
          if (thread->osthread()->expanding_stack() == 0) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   195
            thread->osthread()->set_expanding_stack();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   196
            if (os::Bsd::manually_expand_stack(thread, addr)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   197
              thread->osthread()->clear_expanding_stack();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   198
              return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   199
            }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   200
            thread->osthread()->clear_expanding_stack();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   201
          }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   202
          else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   203
            fatal("recursive segv. expanding stack.");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   204
          }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   205
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   206
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   207
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   208
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   209
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   210
    /*if (thread->thread_state() == _thread_in_Java) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   211
      ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   212
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   213
    else*/ if (thread->thread_state() == _thread_in_vm &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   214
               sig == SIGBUS && thread->doing_unsafe_access()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   215
      ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   216
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   217
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   218
    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   219
    // kicks in and the heap gets shrunk before the field access.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   220
    /*if (sig == SIGSEGV || sig == SIGBUS) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   221
      address addr = JNI_FastGetField::find_slowcase_pc(pc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   222
      if (addr != (address)-1) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   223
        stub = addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   224
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   225
    }*/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   226
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   227
    // Check to see if we caught the safepoint code in the process
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   228
    // of write protecting the memory serialization page.  It write
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   229
    // enables the page immediately after protecting it so we can
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   230
    // just return to retry the write.
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   231
    if ((sig == SIGSEGV || sig == SIGBUS) &&
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   232
        os::is_memory_serialize_page(thread, (address) info->si_addr)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   233
      // Block current thread until permission is restored.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   234
      os::block_on_serialize_page_trap();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   235
      return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   236
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   237
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   238
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   239
  // signal-chaining
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   240
  if (os::Bsd::chained_handler(sig, info, ucVoid)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   241
     return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   242
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   243
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   244
  if (!abort_if_unrecognized) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   245
    // caller wants another chance, so give it to him
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   246
    return false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   247
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   248
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   249
#ifndef PRODUCT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   250
  if (sig == SIGSEGV) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   251
    fatal("\n#"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   252
          "\n#    /--------------------\\"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   253
          "\n#    | segmentation fault |"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   254
          "\n#    \\---\\ /--------------/"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   255
          "\n#        /"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   256
          "\n#    [-]        |\\_/|    "
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   257
          "\n#    (+)=C      |o o|__  "
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   258
          "\n#    | |        =-*-=__\\ "
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   259
          "\n#    OOO        c_c_(___)");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   260
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   261
#endif // !PRODUCT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   262
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   263
  const char *fmt =
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   264
      "caught unhandled signal " INT32_FORMAT " at address " PTR_FORMAT;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   265
  char buf[128];
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   266
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   267
  sprintf(buf, fmt, sig, info->si_addr);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   268
  fatal(buf);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   269
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   270
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   271
void os::Bsd::init_thread_fpu_state(void) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   272
  // Nothing to do
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   273
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   274
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   275
#ifndef _ALLBSD_SOURCE
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   276
int os::Bsd::get_fpu_control_word() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   277
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   278
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   279
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   280
void os::Bsd::set_fpu_control_word(int fpu) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   281
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   282
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   283
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   284
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   285
bool os::is_allocatable(size_t bytes) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   286
#ifdef _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   287
  return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   288
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   289
  if (bytes < 2 * G) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   290
    return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   291
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   292
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   293
  char* addr = reserve_memory(bytes, NULL);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   294
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   295
  if (addr != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   296
    release_memory(addr, bytes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   297
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   298
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   299
  return addr != NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   300
#endif // _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   301
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   302
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   303
///////////////////////////////////////////////////////////////////////////////
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   304
// thread stack
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   305
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   306
size_t os::Bsd::min_stack_allowed = 64 * K;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   307
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   308
bool os::Bsd::supports_variable_stack_size() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   309
  return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   310
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   311
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   312
size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   313
#ifdef _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   314
  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   315
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   316
  size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   317
#endif // _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   318
  return s;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   319
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   320
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   321
size_t os::Bsd::default_guard_size(os::ThreadType thr_type) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   322
  // Only enable glibc guard pages for non-Java threads
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   323
  // (Java threads have HotSpot guard pages)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   324
  return (thr_type == java_thread ? 0 : page_size());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   325
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   326
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   327
static void current_stack_region(address *bottom, size_t *size) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   328
  address stack_bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   329
  address stack_top;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   330
  size_t stack_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   331
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   332
#ifdef __APPLE__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   333
  pthread_t self = pthread_self();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   334
  stack_top = (address) pthread_get_stackaddr_np(self);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   335
  stack_bytes = pthread_get_stacksize_np(self);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   336
  stack_bottom = stack_top - stack_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   337
#elif defined(__OpenBSD__)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   338
  stack_t ss;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   339
  int rslt = pthread_stackseg_np(pthread_self(), &ss);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   340
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   341
  if (rslt != 0)
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   342
    fatal(err_msg("pthread_stackseg_np failed with err = " INT32_FORMAT,
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   343
          rslt));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   344
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   345
  stack_top = (address) ss.ss_sp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   346
  stack_bytes  = ss.ss_size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   347
  stack_bottom = stack_top - stack_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   348
#elif defined(_ALLBSD_SOURCE)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   349
  pthread_attr_t attr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   350
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   351
  int rslt = pthread_attr_init(&attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   352
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   353
  // JVM needs to know exact stack location, abort if it fails
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   354
  if (rslt != 0)
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   355
    fatal(err_msg("pthread_attr_init failed with err = " INT32_FORMAT, rslt));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   356
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   357
  rslt = pthread_attr_get_np(pthread_self(), &attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   358
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   359
  if (rslt != 0)
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   360
    fatal(err_msg("pthread_attr_get_np failed with err = " INT32_FORMAT,
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   361
          rslt));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   362
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   363
  if (pthread_attr_getstackaddr(&attr, (void **) &stack_bottom) != 0 ||
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   364
      pthread_attr_getstacksize(&attr, &stack_bytes) != 0) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   365
    fatal("Can not locate current stack attributes!");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   366
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   367
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   368
  pthread_attr_destroy(&attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   369
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   370
  stack_top = stack_bottom + stack_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   371
#else /* Linux */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   372
  pthread_attr_t attr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   373
  int res = pthread_getattr_np(pthread_self(), &attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   374
  if (res != 0) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   375
    if (res == ENOMEM) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   376
      vm_exit_out_of_memory(0, "pthread_getattr_np");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   377
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   378
    else {
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   379
      fatal(err_msg("pthread_getattr_np failed with errno = " INT32_FORMAT,
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   380
            res));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   381
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   382
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   383
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   384
  res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   385
  if (res != 0) {
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   386
    fatal(err_msg("pthread_attr_getstack failed with errno = " INT32_FORMAT,
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   387
          res));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   388
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   389
  stack_top = stack_bottom + stack_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   390
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   391
  // The block of memory returned by pthread_attr_getstack() includes
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   392
  // guard pages where present.  We need to trim these off.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   393
  size_t page_bytes = os::Bsd::page_size();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   394
  assert(((intptr_t) stack_bottom & (page_bytes - 1)) == 0, "unaligned stack");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   395
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   396
  size_t guard_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   397
  res = pthread_attr_getguardsize(&attr, &guard_bytes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   398
  if (res != 0) {
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   399
    fatal(err_msg(
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   400
        "pthread_attr_getguardsize failed with errno = " INT32_FORMAT, res));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   401
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   402
  int guard_pages = align_size_up(guard_bytes, page_bytes) / page_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   403
  assert(guard_bytes == guard_pages * page_bytes, "unaligned guard");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   404
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   405
#ifdef IA64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   406
  // IA64 has two stacks sharing the same area of memory, a normal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   407
  // stack growing downwards and a register stack growing upwards.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   408
  // Guard pages, if present, are in the centre.  This code splits
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   409
  // the stack in two even without guard pages, though in theory
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   410
  // there's nothing to stop us allocating more to the normal stack
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   411
  // or more to the register stack if one or the other were found
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   412
  // to grow faster.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   413
  int total_pages = align_size_down(stack_bytes, page_bytes) / page_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   414
  stack_bottom += (total_pages - guard_pages) / 2 * page_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   415
#endif // IA64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   416
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   417
  stack_bottom += guard_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   418
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   419
  pthread_attr_destroy(&attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   420
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   421
  // The initial thread has a growable stack, and the size reported
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   422
  // by pthread_attr_getstack is the maximum size it could possibly
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   423
  // be given what currently mapped.  This can be huge, so we cap it.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   424
  if (os::Bsd::is_initial_thread()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   425
    stack_bytes = stack_top - stack_bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   426
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   427
    if (stack_bytes > JavaThread::stack_size_at_create())
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   428
      stack_bytes = JavaThread::stack_size_at_create();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   429
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   430
    stack_bottom = stack_top - stack_bytes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   431
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   432
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   433
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   434
  assert(os::current_stack_pointer() >= stack_bottom, "should do");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   435
  assert(os::current_stack_pointer() < stack_top, "should do");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   436
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   437
  *bottom = stack_bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   438
  *size = stack_top - stack_bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   439
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   440
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   441
address os::current_stack_base() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   442
  address bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   443
  size_t size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   444
  current_stack_region(&bottom, &size);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   445
  return bottom + size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   446
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   447
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   448
size_t os::current_stack_size() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   449
  // stack size includes normal stack and HotSpot guard pages
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   450
  address bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   451
  size_t size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   452
  current_stack_region(&bottom, &size);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   453
  return size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   454
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   455
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   456
/////////////////////////////////////////////////////////////////////////////
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   457
// helper functions for fatal error handler
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   458
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   459
void os::print_context(outputStream* st, void* context) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   460
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   461
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   462
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   463
void os::print_register_info(outputStream *st, void *context) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   464
  ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   465
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   466
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   467
/////////////////////////////////////////////////////////////////////////////
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   468
// Stubs for things that would be in bsd_zero.s if it existed.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   469
// You probably want to disassemble these monkeys to check they're ok.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   470
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   471
extern "C" {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   472
  int SpinPause() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   473
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   474
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   475
  int SafeFetch32(int *adr, int errValue) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   476
    int value = errValue;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   477
    value = *adr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   478
    return value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   479
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   480
  intptr_t SafeFetchN(intptr_t *adr, intptr_t errValue) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   481
    intptr_t value = errValue;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   482
    value = *adr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   483
    return value;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   484
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   485
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   486
  void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   487
    if (from > to) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   488
      jshort *end = from + count;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   489
      while (from < end)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   490
        *(to++) = *(from++);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   491
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   492
    else if (from < to) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   493
      jshort *end = from;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   494
      from += count - 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   495
      to   += count - 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   496
      while (from >= end)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   497
        *(to--) = *(from--);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   498
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   499
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   500
  void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   501
    if (from > to) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   502
      jint *end = from + count;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   503
      while (from < end)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   504
        *(to++) = *(from++);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   505
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   506
    else if (from < to) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   507
      jint *end = from;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   508
      from += count - 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   509
      to   += count - 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   510
      while (from >= end)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   511
        *(to--) = *(from--);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   512
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   513
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   514
  void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   515
    if (from > to) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   516
      jlong *end = from + count;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   517
      while (from < end)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   518
        os::atomic_copy64(from++, to++);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   519
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   520
    else if (from < to) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   521
      jlong *end = from;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   522
      from += count - 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   523
      to   += count - 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   524
      while (from >= end)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   525
        os::atomic_copy64(from--, to--);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   526
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   527
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   528
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   529
  void _Copy_arrayof_conjoint_bytes(HeapWord* from,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   530
                                    HeapWord* to,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   531
                                    size_t    count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   532
    memmove(to, from, count);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   533
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   534
  void _Copy_arrayof_conjoint_jshorts(HeapWord* from,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   535
                                      HeapWord* to,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   536
                                      size_t    count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   537
    memmove(to, from, count * 2);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   538
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   539
  void _Copy_arrayof_conjoint_jints(HeapWord* from,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   540
                                    HeapWord* to,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   541
                                    size_t    count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   542
    memmove(to, from, count * 4);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   543
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   544
  void _Copy_arrayof_conjoint_jlongs(HeapWord* from,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   545
                                     HeapWord* to,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   546
                                     size_t    count) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   547
    memmove(to, from, count * 8);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   548
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   549
};
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   550
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   551
/////////////////////////////////////////////////////////////////////////////
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   552
// Implementations of atomic operations not supported by processors.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   553
//  -- http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Atomic-Builtins.html
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   554
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   555
#ifndef _LP64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   556
extern "C" {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   557
  long long unsigned int __sync_val_compare_and_swap_8(
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   558
    volatile void *ptr,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   559
    long long unsigned int oldval,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   560
    long long unsigned int newval) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   561
    ShouldNotCallThis();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   562
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   563
};
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   564
#endif // !_LP64
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10739
diff changeset
   565
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10739
diff changeset
   566
#ifndef PRODUCT
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10739
diff changeset
   567
void os::verify_stack_alignment() {
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10739
diff changeset
   568
}
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10739
diff changeset
   569
#endif