hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp
author sgehwolf
Wed, 17 Feb 2016 17:03:31 -0500
changeset 36181 3a16e8ce0abf
parent 35201 996db89f378e
child 37430 fd743dadef12
permissions -rw-r--r--
8143245: Zero build requires disabled warnings Reviewed-by: dholmes, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     1
/*
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
     2
 * Copyright (c) 2003, 2016, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    26
// no precompiled headers
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    27
#include "assembler_zero.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    28
#include "classfile/classLoader.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    29
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    30
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    31
#include "code/icBuffer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    32
#include "code/vtableStubs.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    33
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    34
#include "jvm_linux.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    35
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    36
#include "mutex_linux.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    37
#include "nativeInst_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    38
#include "os_share_linux.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    39
#include "prims/jniFastGetField.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    40
#include "prims/jvm.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    41
#include "prims/jvm_misc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    42
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    43
#include "runtime/extendedPC.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    44
#include "runtime/frame.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    45
#include "runtime/interfaceSupport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    46
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    47
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    48
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    49
#include "runtime/osThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    50
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    51
#include "runtime/stubRoutines.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 13963
diff changeset
    52
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    53
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    54
#include "utilities/events.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7395
diff changeset
    55
#include "utilities/vmError.hpp"
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    56
30129
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
    57
// See stubGenerator_zero.cpp
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
    58
#include <setjmp.h>
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
    59
extern sigjmp_buf* get_jmp_buf_for_continuation();
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
    60
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    61
address os::current_stack_pointer() {
31128
024d19662029 8087120: [GCC5] java.lang.StackOverflowError on Zero JVM initialization on non x86 platforms.
sgehwolf
parents: 30129
diff changeset
    62
  // return the address of the current function
024d19662029 8087120: [GCC5] java.lang.StackOverflowError on Zero JVM initialization on non x86 platforms.
sgehwolf
parents: 30129
diff changeset
    63
  return (address)__builtin_frame_address(0);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    64
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    65
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    66
frame os::get_sender_for_C_frame(frame* fr) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    67
  ShouldNotCallThis();
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
    68
  return frame(NULL, NULL); // silence compile warning.
4013
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
frame os::current_frame() {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    72
  // The only thing that calls this is the stack printing code in
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    73
  // VMError::report:
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    74
  //   - Step 110 (printing stack bounds) uses the sp in the frame
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    75
  //     to determine the amount of free space on the stack.  We
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    76
  //     set the sp to a close approximation of the real value in
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    77
  //     order to allow this step to complete.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    78
  //   - Step 120 (printing native stack) tries to walk the stack.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    79
  //     The frame we create has a NULL pc, which is ignored as an
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    80
  //     invalid frame.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    81
  frame dummy = frame();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    82
  dummy.set_sp((intptr_t *) current_stack_pointer());
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    83
  return dummy;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    84
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    85
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    86
char* os::non_memory_address_word() {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    87
  // Must never look like an address returned by reserve_memory,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    88
  // even in its subfields (as defined by the CPU immediate fields,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    89
  // if the CPU splits constants across multiple instructions).
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    90
#ifdef SPARC
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    91
  // On SPARC, 0 != %hi(any real address), because there is no
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    92
  // allocation in the first 1Kb of the virtual address space.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    93
  return (char *) 0;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    94
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    95
  // This is the value for x86; works pretty well for PPC too.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    96
  return (char *) -1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    97
#endif // SPARC
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    98
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    99
13859
7fe4578493fc 7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents: 11961
diff changeset
   100
void os::initialize_thread(Thread * thr){
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   101
  // Nothing to do.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   102
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   103
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   104
address os::Linux::ucontext_get_pc(const ucontext_t* uc) {
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   105
  ShouldNotCallThis();
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   106
  return NULL; // silence compile warnings
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   107
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   108
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   109
void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   110
  ShouldNotCallThis();
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   111
}
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   112
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   113
ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   114
                                        intptr_t** ret_sp,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   115
                                        intptr_t** ret_fp) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   116
  ShouldNotCallThis();
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   117
  return NULL; // silence compile warnings
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   118
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   119
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   120
frame os::fetch_frame_from_context(const void* ucVoid) {
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   121
  ShouldNotCallThis();
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   122
  return frame(NULL, NULL); // silence compile warnings
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   123
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   124
8106
19106a0203fb 6588413: Use -fvisibility=hidden for gcc compiles
coleenp
parents: 7405
diff changeset
   125
extern "C" JNIEXPORT int
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   126
JVM_handle_linux_signal(int sig,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   127
                        siginfo_t* info,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   128
                        void* ucVoid,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   129
                        int abort_if_unrecognized) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   130
  ucontext_t* uc = (ucontext_t*) ucVoid;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   131
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 33105
diff changeset
   132
  Thread* t = Thread::current_or_null_safe();
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   133
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   134
  SignalHandlerMark shm(t);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   135
30129
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   136
  // handle SafeFetch faults
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   137
  if (sig == SIGSEGV || sig == SIGBUS) {
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   138
    sigjmp_buf* const pjb = get_jmp_buf_for_continuation();
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   139
    if (pjb) {
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   140
      siglongjmp(*pjb, 1);
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   141
    }
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   142
  }
351788433103 8076185: Provide SafeFetchX implementation for zero
dholmes
parents: 29573
diff changeset
   143
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   144
  // Note: it's not uncommon that JNI code uses signal/sigset to
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   145
  // install then restore certain signal handler (e.g. to temporarily
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   146
  // block SIGPIPE, or have a SIGILL handler when detecting CPU
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   147
  // type). When that happens, JVM_handle_linux_signal() might be
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   148
  // invoked with junk info/ucVoid. To avoid unnecessary crash when
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   149
  // libjsig is not preloaded, try handle signals that do not require
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   150
  // siginfo/ucontext first.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   151
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   152
  if (sig == SIGPIPE || sig == SIGXFSZ) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   153
    // allow chained handler to go first
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   154
    if (os::Linux::chained_handler(sig, info, ucVoid)) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   155
      return true;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   156
    } else {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   157
      if (PrintMiscellaneous && (WizardMode || Verbose)) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   158
        char buf[64];
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   159
        warning("Ignoring %s - see bugs 4229104 or 646499219",
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   160
                os::exception_name(sig, buf, sizeof(buf)));
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   161
      }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   162
      return true;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   163
    }
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
  JavaThread* thread = NULL;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   167
  VMThread* vmthread = NULL;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   168
  if (os::Linux::signal_handlers_are_installed) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   169
    if (t != NULL ){
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   170
      if(t->is_Java_thread()) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   171
        thread = (JavaThread*)t;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   172
      }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   173
      else if(t->is_VM_thread()){
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   174
        vmthread = (VMThread *)t;
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
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   178
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   179
  if (info != NULL && thread != NULL) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   180
    // Handle ALL stack overflow variations here
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   181
    if (sig == SIGSEGV) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   182
      address addr = (address) info->si_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
      // check if fault address is within thread stack
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   185
      if (thread->on_local_stack(addr)) {
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   186
        // stack overflow
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   187
        if (thread->in_stack_yellow_reserved_zone(addr)) {
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   188
          thread->disable_stack_yellow_reserved_zone();
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   189
          ShouldNotCallThis();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   190
        }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   191
        else if (thread->in_stack_red_zone(addr)) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   192
          thread->disable_stack_red_zone();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   193
          ShouldNotCallThis();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   194
        }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   195
        else {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   196
          // Accessing stack address below sp may cause SEGV if
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   197
          // current thread has MAP_GROWSDOWN stack. This should
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   198
          // only happen when current thread was created by user
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   199
          // code with MAP_GROWSDOWN flag and then attached to VM.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   200
          // See notes in os_linux.cpp.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   201
          if (thread->osthread()->expanding_stack() == 0) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   202
            thread->osthread()->set_expanding_stack();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   203
            if (os::Linux::manually_expand_stack(thread, addr)) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   204
              thread->osthread()->clear_expanding_stack();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   205
              return true;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   206
            }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   207
            thread->osthread()->clear_expanding_stack();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   208
          }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   209
          else {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   210
            fatal("recursive segv. expanding stack.");
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   211
          }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   212
        }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   213
      }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   214
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   215
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   216
    /*if (thread->thread_state() == _thread_in_Java) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   217
      ShouldNotCallThis();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   218
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   219
    else*/ if (thread->thread_state() == _thread_in_vm &&
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   220
               sig == SIGBUS && thread->doing_unsafe_access()) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   221
      ShouldNotCallThis();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   222
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   223
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   224
    // 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
   225
    // kicks in and the heap gets shrunk before the field access.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   226
    /*if (sig == SIGSEGV || sig == SIGBUS) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   227
      address addr = JNI_FastGetField::find_slowcase_pc(pc);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   228
      if (addr != (address)-1) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   229
        stub = addr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   230
      }
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
    // Check to see if we caught the safepoint code in the process
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   234
    // of write protecting the memory serialization page.  It write
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   235
    // enables the page immediately after protecting it so we can
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   236
    // just return to retry the write.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   237
    if (sig == SIGSEGV &&
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   238
        os::is_memory_serialize_page(thread, (address) info->si_addr)) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   239
      // Block current thread until permission is restored.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   240
      os::block_on_serialize_page_trap();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   241
      return true;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   242
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   243
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   244
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   245
  // signal-chaining
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   246
  if (os::Linux::chained_handler(sig, info, ucVoid)) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   247
     return true;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   248
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   249
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   250
  if (!abort_if_unrecognized) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   251
    // caller wants another chance, so give it to him
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   252
    return false;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   253
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   254
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   255
#ifndef PRODUCT
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   256
  if (sig == SIGSEGV) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   257
    fatal("\n#"
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   258
          "\n#    /--------------------\\"
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   259
          "\n#    | segmentation fault |"
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   260
          "\n#    \\---\\ /--------------/"
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   261
          "\n#        /"
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   262
          "\n#    [-]        |\\_/|    "
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   263
          "\n#    (+)=C      |o o|__  "
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   264
          "\n#    | |        =-*-=__\\ "
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   265
          "\n#    OOO        c_c_(___)");
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   266
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   267
#endif // !PRODUCT
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   268
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   269
  char buf[64];
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   270
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   271
  sprintf(buf, "caught unhandled signal %d", sig);
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   272
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   273
// Silence -Wformat-security warning for fatal()
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   274
PRAGMA_DIAG_PUSH
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   275
PRAGMA_FORMAT_NONLITERAL_IGNORED
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   276
  fatal(buf);
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   277
PRAGMA_DIAG_POP
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   278
  return true; // silence compiler warnings
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   279
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   280
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   281
void os::Linux::init_thread_fpu_state(void) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   282
  // Nothing to do
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   283
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   284
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   285
int os::Linux::get_fpu_control_word() {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   286
  ShouldNotCallThis();
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   287
  return -1; // silence compile warnings
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   288
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   289
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   290
void os::Linux::set_fpu_control_word(int fpu) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   291
  ShouldNotCallThis();
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
bool os::is_allocatable(size_t bytes) {
4647
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   295
#ifdef _LP64
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   296
  return true;
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   297
#else
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   298
  if (bytes < 2 * G) {
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   299
    return true;
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   300
  }
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   301
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   302
  char* addr = reserve_memory(bytes, NULL);
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   303
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   304
  if (addr != NULL) {
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   305
    release_memory(addr, bytes);
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   306
  }
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   307
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   308
  return addr != NULL;
51451c7e9103 6917698: os::is_allocatable Zero fix for 32-bit platforms
twisti
parents: 4013
diff changeset
   309
#endif // _LP64
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   310
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   311
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   312
///////////////////////////////////////////////////////////////////////////////
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   313
// thread stack
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   314
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   315
size_t os::Linux::min_stack_allowed = 64 * K;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   316
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   317
size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   318
#ifdef _LP64
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   319
  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   320
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   321
  size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   322
#endif // _LP64
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   323
  return s;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   324
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   325
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   326
size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   327
  // Only enable glibc guard pages for non-Java threads
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   328
  // (Java threads have HotSpot guard pages)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   329
  return (thr_type == java_thread ? 0 : page_size());
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   330
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   331
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   332
static void current_stack_region(address *bottom, size_t *size) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   333
  pthread_attr_t attr;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   334
  int res = pthread_getattr_np(pthread_self(), &attr);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   335
  if (res != 0) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   336
    if (res == ENOMEM) {
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 14583
diff changeset
   337
      vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   338
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   339
    else {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32080
diff changeset
   340
      fatal("pthread_getattr_np failed with errno = %d", res);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   341
    }
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
  address stack_bottom;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   345
  size_t stack_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   346
  res = pthread_attr_getstack(&attr, (void **) &stack_bottom, &stack_bytes);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   347
  if (res != 0) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32080
diff changeset
   348
    fatal("pthread_attr_getstack failed with errno = %d", res);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   349
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   350
  address stack_top = stack_bottom + stack_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   351
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   352
  // The block of memory returned by pthread_attr_getstack() includes
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   353
  // guard pages where present.  We need to trim these off.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   354
  size_t page_bytes = os::Linux::page_size();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   355
  assert(((intptr_t) stack_bottom & (page_bytes - 1)) == 0, "unaligned stack");
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   356
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   357
  size_t guard_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   358
  res = pthread_attr_getguardsize(&attr, &guard_bytes);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   359
  if (res != 0) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32080
diff changeset
   360
    fatal("pthread_attr_getguardsize failed with errno = %d", res);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   361
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   362
  int guard_pages = align_size_up(guard_bytes, page_bytes) / page_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   363
  assert(guard_bytes == guard_pages * page_bytes, "unaligned guard");
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   364
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   365
#ifdef IA64
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   366
  // IA64 has two stacks sharing the same area of memory, a normal
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   367
  // stack growing downwards and a register stack growing upwards.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   368
  // Guard pages, if present, are in the centre.  This code splits
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   369
  // the stack in two even without guard pages, though in theory
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   370
  // there's nothing to stop us allocating more to the normal stack
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   371
  // or more to the register stack if one or the other were found
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   372
  // to grow faster.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   373
  int total_pages = align_size_down(stack_bytes, page_bytes) / page_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   374
  stack_bottom += (total_pages - guard_pages) / 2 * page_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   375
#endif // IA64
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   376
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   377
  stack_bottom += guard_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   378
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   379
  pthread_attr_destroy(&attr);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   380
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   381
  // The initial thread has a growable stack, and the size reported
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   382
  // by pthread_attr_getstack is the maximum size it could possibly
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   383
  // be given what currently mapped.  This can be huge, so we cap it.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   384
  if (os::Linux::is_initial_thread()) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   385
    stack_bytes = stack_top - stack_bottom;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   386
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   387
    if (stack_bytes > JavaThread::stack_size_at_create())
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   388
      stack_bytes = JavaThread::stack_size_at_create();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   389
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   390
    stack_bottom = stack_top - stack_bytes;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   391
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   392
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   393
  assert(os::current_stack_pointer() >= stack_bottom, "should do");
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   394
  assert(os::current_stack_pointer() < stack_top, "should do");
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   395
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   396
  *bottom = stack_bottom;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   397
  *size = stack_top - stack_bottom;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   398
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   399
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   400
address os::current_stack_base() {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   401
  address bottom;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   402
  size_t size;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   403
  current_stack_region(&bottom, &size);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   404
  return bottom + size;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   405
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   406
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   407
size_t os::current_stack_size() {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   408
  // stack size includes normal stack and HotSpot guard pages
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   409
  address bottom;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   410
  size_t size;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   411
  current_stack_region(&bottom, &size);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   412
  return size;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   413
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   414
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   415
/////////////////////////////////////////////////////////////////////////////
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   416
// helper functions for fatal error handler
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   417
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   418
void os::print_context(outputStream* st, const void* context) {
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   419
  ShouldNotCallThis();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   420
}
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   421
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   422
void os::print_register_info(outputStream *st, const void *context) {
7395
08bfc4ce3045 7002129: Zero and Shark fixes, 3rd
twisti
parents: 6271
diff changeset
   423
  ShouldNotCallThis();
08bfc4ce3045 7002129: Zero and Shark fixes, 3rd
twisti
parents: 6271
diff changeset
   424
}
08bfc4ce3045 7002129: Zero and Shark fixes, 3rd
twisti
parents: 6271
diff changeset
   425
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   426
/////////////////////////////////////////////////////////////////////////////
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   427
// Stubs for things that would be in linux_zero.s if it existed.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   428
// You probably want to disassemble these monkeys to check they're ok.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   429
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   430
extern "C" {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   431
  int SpinPause() {
36181
3a16e8ce0abf 8143245: Zero build requires disabled warnings
sgehwolf
parents: 35201
diff changeset
   432
      return -1; // silence compile warnings
4013
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
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   436
  void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   437
    if (from > to) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   438
      jshort *end = from + count;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   439
      while (from < end)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   440
        *(to++) = *(from++);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   441
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   442
    else if (from < to) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   443
      jshort *end = from;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   444
      from += count - 1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   445
      to   += count - 1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   446
      while (from >= end)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   447
        *(to--) = *(from--);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   448
    }
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_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   451
    if (from > to) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   452
      jint *end = from + count;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   453
      while (from < end)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   454
        *(to++) = *(from++);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   455
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   456
    else if (from < to) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   457
      jint *end = from;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   458
      from += count - 1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   459
      to   += count - 1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   460
      while (from >= end)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   461
        *(to--) = *(from--);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   462
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   463
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   464
  void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   465
    if (from > to) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   466
      jlong *end = from + count;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   467
      while (from < end)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   468
        os::atomic_copy64(from++, to++);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   469
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   470
    else if (from < to) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   471
      jlong *end = from;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   472
      from += count - 1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   473
      to   += count - 1;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   474
      while (from >= end)
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   475
        os::atomic_copy64(from--, to--);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   476
    }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   477
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   478
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   479
  void _Copy_arrayof_conjoint_bytes(HeapWord* from,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   480
                                    HeapWord* to,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   481
                                    size_t    count) {
6271
271ac8e393e4 6977640: Zero and Shark fixes
twisti
parents: 5547
diff changeset
   482
    memmove(to, from, count);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   483
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   484
  void _Copy_arrayof_conjoint_jshorts(HeapWord* from,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   485
                                      HeapWord* to,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   486
                                      size_t    count) {
6271
271ac8e393e4 6977640: Zero and Shark fixes
twisti
parents: 5547
diff changeset
   487
    memmove(to, from, count * 2);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   488
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   489
  void _Copy_arrayof_conjoint_jints(HeapWord* from,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   490
                                    HeapWord* to,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   491
                                    size_t    count) {
6271
271ac8e393e4 6977640: Zero and Shark fixes
twisti
parents: 5547
diff changeset
   492
    memmove(to, from, count * 4);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   493
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   494
  void _Copy_arrayof_conjoint_jlongs(HeapWord* from,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   495
                                     HeapWord* to,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   496
                                     size_t    count) {
6271
271ac8e393e4 6977640: Zero and Shark fixes
twisti
parents: 5547
diff changeset
   497
    memmove(to, from, count * 8);
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   498
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   499
};
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   500
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   501
/////////////////////////////////////////////////////////////////////////////
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   502
// Implementations of atomic operations not supported by processors.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   503
//  -- http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Atomic-Builtins.html
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   504
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   505
#ifndef _LP64
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   506
extern "C" {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   507
  long long unsigned int __sync_val_compare_and_swap_8(
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   508
    volatile void *ptr,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   509
    long long unsigned int oldval,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   510
    long long unsigned int newval) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   511
    ShouldNotCallThis();
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   512
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   513
};
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   514
#endif // !_LP64
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 8921
diff changeset
   515
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 8921
diff changeset
   516
#ifndef PRODUCT
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 8921
diff changeset
   517
void os::verify_stack_alignment() {
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 8921
diff changeset
   518
}
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 8921
diff changeset
   519
#endif
26576
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   520
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   521
int os::extra_bang_size_in_bytes() {
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   522
  // Zero does not require an additional stack banging.
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   523
  return 0;
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   524
}