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