src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp
author pliden
Thu, 07 Nov 2019 15:48:43 +0100
changeset 58965 86c8b22945a1
parent 55490 3f3dc00a69a5
permissions -rw-r--r--
8233793: ZGC: Incorrect type used in ZBarrierSetC2 clone_type() Reviewed-by: eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
// no precompiled headers
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14286
diff changeset
    27
#include "asm/macroAssembler.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
#include "classfile/classLoader.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
#include "classfile/systemDictionary.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
#include "classfile/vmSymbols.hpp"
34667
6b077f0ef25d 8144881: Various fixes to linux/sparc
mikael
parents: 34633
diff changeset
    31
#include "code/codeCache.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
#include "code/icBuffer.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
#include "code/vtableStubs.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
#include "interpreter/interpreter.hpp"
49615
1b1de4b263c8 8200232: Build failures after JDK-8200106 (Move NoSafepointVerifier out from gcLocker.hpp)
shade
parents: 49449
diff changeset
    35
#include "logging/log.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
#include "memory/allocation.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
#include "os_share_bsd.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
#include "prims/jniFastGetField.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
#include "prims/jvm_misc.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
#include "runtime/arguments.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
#include "runtime/extendedPC.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
#include "runtime/frame.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 48824
diff changeset
    43
#include "runtime/interfaceSupport.inline.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
#include "runtime/java.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
#include "runtime/javaCalls.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
#include "runtime/mutexLocker.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
#include "runtime/osThread.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
#include "runtime/sharedRuntime.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
#include "runtime/stubRoutines.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 14286
diff changeset
    50
#include "runtime/thread.inline.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
#include "runtime/timer.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    52
#include "utilities/align.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
#include "utilities/events.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
#include "utilities/vmError.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
// put OS-includes here
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
# include <sys/types.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
# include <sys/mman.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
# include <pthread.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
# include <signal.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
# include <errno.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
# include <dlfcn.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
# include <stdlib.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
# include <stdio.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
# include <unistd.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
# include <sys/resource.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
# include <pthread.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
# include <sys/stat.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
# include <sys/time.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
# include <sys/utsname.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
# include <sys/socket.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
# include <sys/wait.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
# include <pwd.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
# include <poll.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
#ifndef __OpenBSD__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
# include <ucontext.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
14286
ec9e76cd402f 8001619: Remove usage of _ALLBSD_SOURCE in bsd files
sla
parents: 13932
diff changeset
    79
#if !defined(__APPLE__) && !defined(__NetBSD__)
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
# include <pthread_np.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
21184
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    83
// needed by current_stack_region() workaround for Mavericks
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    84
#if defined(__APPLE__)
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    85
# include <errno.h>
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    86
# include <sys/types.h>
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    87
# include <sys/sysctl.h>
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    88
# define DEFAULT_MAIN_THREAD_STACK_PAGES 2048
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    89
# define OS_X_10_9_0_KERNEL_MAJOR_VERSION 13
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    90
#endif
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
    91
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
#ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
#define SPELL_REG_SP "rsp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
#define SPELL_REG_FP "rbp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
#define SPELL_REG_SP "esp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
#define SPELL_REG_FP "ebp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
#ifdef __FreeBSD__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
# define context_trapno uc_mcontext.mc_trapno
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
# ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
#  define context_pc uc_mcontext.mc_rip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
#  define context_sp uc_mcontext.mc_rsp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
#  define context_fp uc_mcontext.mc_rbp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
#  define context_rip uc_mcontext.mc_rip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
#  define context_rsp uc_mcontext.mc_rsp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
#  define context_rbp uc_mcontext.mc_rbp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
#  define context_rax uc_mcontext.mc_rax
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
#  define context_rbx uc_mcontext.mc_rbx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
#  define context_rcx uc_mcontext.mc_rcx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
#  define context_rdx uc_mcontext.mc_rdx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
#  define context_rsi uc_mcontext.mc_rsi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
#  define context_rdi uc_mcontext.mc_rdi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
#  define context_r8  uc_mcontext.mc_r8
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
#  define context_r9  uc_mcontext.mc_r9
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
#  define context_r10 uc_mcontext.mc_r10
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
#  define context_r11 uc_mcontext.mc_r11
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
#  define context_r12 uc_mcontext.mc_r12
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
#  define context_r13 uc_mcontext.mc_r13
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   121
#  define context_r14 uc_mcontext.mc_r14
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   122
#  define context_r15 uc_mcontext.mc_r15
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   123
#  define context_flags uc_mcontext.mc_flags
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
#  define context_err uc_mcontext.mc_err
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
# else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
#  define context_pc uc_mcontext.mc_eip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
#  define context_sp uc_mcontext.mc_esp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
#  define context_fp uc_mcontext.mc_ebp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
#  define context_eip uc_mcontext.mc_eip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
#  define context_esp uc_mcontext.mc_esp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
#  define context_eax uc_mcontext.mc_eax
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
#  define context_ebx uc_mcontext.mc_ebx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
#  define context_ecx uc_mcontext.mc_ecx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
#  define context_edx uc_mcontext.mc_edx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
#  define context_ebp uc_mcontext.mc_ebp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
#  define context_esi uc_mcontext.mc_esi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
#  define context_edi uc_mcontext.mc_edi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   138
#  define context_eflags uc_mcontext.mc_eflags
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
#  define context_trapno uc_mcontext.mc_trapno
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   140
# endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
#ifdef __APPLE__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
# if __DARWIN_UNIX03 && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
  // 10.5 UNIX03 member name prefixes
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
  #define DU3_PREFIX(s, m) __ ## s.__ ## m
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
# else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
  #define DU3_PREFIX(s, m) s ## . ## m
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
# endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   151
# ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
#  define context_pc context_rip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   153
#  define context_sp context_rsp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   154
#  define context_fp context_rbp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   155
#  define context_rip uc_mcontext->DU3_PREFIX(ss,rip)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   156
#  define context_rsp uc_mcontext->DU3_PREFIX(ss,rsp)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   157
#  define context_rax uc_mcontext->DU3_PREFIX(ss,rax)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   158
#  define context_rbx uc_mcontext->DU3_PREFIX(ss,rbx)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   159
#  define context_rcx uc_mcontext->DU3_PREFIX(ss,rcx)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   160
#  define context_rdx uc_mcontext->DU3_PREFIX(ss,rdx)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   161
#  define context_rbp uc_mcontext->DU3_PREFIX(ss,rbp)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   162
#  define context_rsi uc_mcontext->DU3_PREFIX(ss,rsi)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   163
#  define context_rdi uc_mcontext->DU3_PREFIX(ss,rdi)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   164
#  define context_r8  uc_mcontext->DU3_PREFIX(ss,r8)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   165
#  define context_r9  uc_mcontext->DU3_PREFIX(ss,r9)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   166
#  define context_r10 uc_mcontext->DU3_PREFIX(ss,r10)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   167
#  define context_r11 uc_mcontext->DU3_PREFIX(ss,r11)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   168
#  define context_r12 uc_mcontext->DU3_PREFIX(ss,r12)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   169
#  define context_r13 uc_mcontext->DU3_PREFIX(ss,r13)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   170
#  define context_r14 uc_mcontext->DU3_PREFIX(ss,r14)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   171
#  define context_r15 uc_mcontext->DU3_PREFIX(ss,r15)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   172
#  define context_flags uc_mcontext->DU3_PREFIX(ss,rflags)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   173
#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   174
#  define context_err uc_mcontext->DU3_PREFIX(es,err)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   175
# else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   176
#  define context_pc context_eip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   177
#  define context_sp context_esp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   178
#  define context_fp context_ebp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   179
#  define context_eip uc_mcontext->DU3_PREFIX(ss,eip)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   180
#  define context_esp uc_mcontext->DU3_PREFIX(ss,esp)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   181
#  define context_eax uc_mcontext->DU3_PREFIX(ss,eax)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   182
#  define context_ebx uc_mcontext->DU3_PREFIX(ss,ebx)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   183
#  define context_ecx uc_mcontext->DU3_PREFIX(ss,ecx)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   184
#  define context_edx uc_mcontext->DU3_PREFIX(ss,edx)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   185
#  define context_ebp uc_mcontext->DU3_PREFIX(ss,ebp)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   186
#  define context_esi uc_mcontext->DU3_PREFIX(ss,esi)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   187
#  define context_edi uc_mcontext->DU3_PREFIX(ss,edi)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   188
#  define context_eflags uc_mcontext->DU3_PREFIX(ss,eflags)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   189
#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   190
# endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   191
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   192
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   193
#ifdef __OpenBSD__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   194
# define context_trapno sc_trapno
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   195
# ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   196
#  define context_pc sc_rip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   197
#  define context_sp sc_rsp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   198
#  define context_fp sc_rbp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   199
#  define context_rip sc_rip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   200
#  define context_rsp sc_rsp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   201
#  define context_rbp sc_rbp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   202
#  define context_rax sc_rax
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   203
#  define context_rbx sc_rbx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   204
#  define context_rcx sc_rcx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   205
#  define context_rdx sc_rdx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   206
#  define context_rsi sc_rsi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   207
#  define context_rdi sc_rdi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   208
#  define context_r8  sc_r8
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   209
#  define context_r9  sc_r9
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   210
#  define context_r10 sc_r10
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   211
#  define context_r11 sc_r11
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   212
#  define context_r12 sc_r12
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   213
#  define context_r13 sc_r13
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   214
#  define context_r14 sc_r14
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   215
#  define context_r15 sc_r15
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   216
#  define context_flags sc_rflags
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   217
#  define context_err sc_err
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   218
# else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   219
#  define context_pc sc_eip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   220
#  define context_sp sc_esp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   221
#  define context_fp sc_ebp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   222
#  define context_eip sc_eip
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   223
#  define context_esp sc_esp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   224
#  define context_eax sc_eax
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   225
#  define context_ebx sc_ebx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   226
#  define context_ecx sc_ecx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   227
#  define context_edx sc_edx
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   228
#  define context_ebp sc_ebp
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   229
#  define context_esi sc_esi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   230
#  define context_edi sc_edi
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   231
#  define context_eflags sc_eflags
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   232
#  define context_trapno sc_trapno
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   233
# endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   234
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   235
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   236
#ifdef __NetBSD__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   237
# define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   238
# ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   239
#  define __register_t __greg_t
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   240
#  define context_pc uc_mcontext.__gregs[_REG_RIP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   241
#  define context_sp uc_mcontext.__gregs[_REG_URSP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   242
#  define context_fp uc_mcontext.__gregs[_REG_RBP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   243
#  define context_rip uc_mcontext.__gregs[_REG_RIP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   244
#  define context_rsp uc_mcontext.__gregs[_REG_URSP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   245
#  define context_rax uc_mcontext.__gregs[_REG_RAX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   246
#  define context_rbx uc_mcontext.__gregs[_REG_RBX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   247
#  define context_rcx uc_mcontext.__gregs[_REG_RCX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   248
#  define context_rdx uc_mcontext.__gregs[_REG_RDX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   249
#  define context_rbp uc_mcontext.__gregs[_REG_RBP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   250
#  define context_rsi uc_mcontext.__gregs[_REG_RSI]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   251
#  define context_rdi uc_mcontext.__gregs[_REG_RDI]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   252
#  define context_r8  uc_mcontext.__gregs[_REG_R8]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   253
#  define context_r9  uc_mcontext.__gregs[_REG_R9]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   254
#  define context_r10 uc_mcontext.__gregs[_REG_R10]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   255
#  define context_r11 uc_mcontext.__gregs[_REG_R11]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   256
#  define context_r12 uc_mcontext.__gregs[_REG_R12]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   257
#  define context_r13 uc_mcontext.__gregs[_REG_R13]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   258
#  define context_r14 uc_mcontext.__gregs[_REG_R14]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   259
#  define context_r15 uc_mcontext.__gregs[_REG_R15]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   260
#  define context_flags uc_mcontext.__gregs[_REG_RFL]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   261
#  define context_err uc_mcontext.__gregs[_REG_ERR]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   262
# else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   263
#  define context_pc uc_mcontext.__gregs[_REG_EIP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   264
#  define context_sp uc_mcontext.__gregs[_REG_UESP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   265
#  define context_fp uc_mcontext.__gregs[_REG_EBP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   266
#  define context_eip uc_mcontext.__gregs[_REG_EIP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   267
#  define context_esp uc_mcontext.__gregs[_REG_UESP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   268
#  define context_eax uc_mcontext.__gregs[_REG_EAX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   269
#  define context_ebx uc_mcontext.__gregs[_REG_EBX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   270
#  define context_ecx uc_mcontext.__gregs[_REG_ECX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   271
#  define context_edx uc_mcontext.__gregs[_REG_EDX]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   272
#  define context_ebp uc_mcontext.__gregs[_REG_EBP]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   273
#  define context_esi uc_mcontext.__gregs[_REG_ESI]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   274
#  define context_edi uc_mcontext.__gregs[_REG_EDI]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   275
#  define context_eflags uc_mcontext.__gregs[_REG_EFL]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   276
#  define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   277
# endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   278
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   279
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   280
address os::current_stack_pointer() {
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   281
#if defined(__clang__) || defined(__llvm__)
51050
96ea37459ca7 8207011: Remove uses of the register storage class specifier
mikael
parents: 49615
diff changeset
   282
  void *esp;
48824
e48c4461a8bb 8181503: Can't compile hotspot with c++11
gziemski
parents: 47765
diff changeset
   283
  __asm__("mov %%" SPELL_REG_SP ", %0":"=r"(esp));
10739
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   284
  return (address) esp;
91935236600e 7098194: integrate macosx-port changes
dcubed
parents: 10565
diff changeset
   285
#elif defined(SPARC_WORKS)
51050
96ea37459ca7 8207011: Remove uses of the register storage class specifier
mikael
parents: 49615
diff changeset
   286
  void *esp;
48824
e48c4461a8bb 8181503: Can't compile hotspot with c++11
gziemski
parents: 47765
diff changeset
   287
  __asm__("mov %%" SPELL_REG_SP ", %0":"=r"(esp));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   288
  return (address) ((char*)esp + sizeof(long)*2);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   289
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   290
  register void *esp __asm__ (SPELL_REG_SP);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   291
  return (address) esp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   292
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   293
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   294
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   295
char* os::non_memory_address_word() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   296
  // Must never look like an address returned by reserve_memory,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   297
  // even in its subfields (as defined by the CPU immediate fields,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   298
  // if the CPU splits constants across multiple instructions).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   299
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   300
  return (char*) -1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   301
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   302
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   303
address os::Bsd::ucontext_get_pc(const ucontext_t * uc) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   304
  return (address)uc->context_pc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   305
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   306
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   307
void os::Bsd::ucontext_set_pc(ucontext_t * uc, address pc) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   308
  uc->context_pc = (intptr_t)pc ;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   309
}
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   310
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   311
intptr_t* os::Bsd::ucontext_get_sp(const ucontext_t * uc) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   312
  return (intptr_t*)uc->context_sp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   313
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   314
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   315
intptr_t* os::Bsd::ucontext_get_fp(const ucontext_t * uc) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   316
  return (intptr_t*)uc->context_fp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   317
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   318
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   319
// For Forte Analyzer AsyncGetCallTrace profiling support - thread
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   320
// is currently interrupted by SIGPROF.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   321
// os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   322
// frames. Currently we don't do that on Bsd, so it's the same as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   323
// os::fetch_frame_from_context().
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   324
// This method is also used for stack overflow signal handling.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   325
ExtendedPC os::Bsd::fetch_frame_from_ucontext(Thread* thread,
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   326
  const ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   327
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   328
  assert(thread != NULL, "just checking");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   329
  assert(ret_sp != NULL, "just checking");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   330
  assert(ret_fp != NULL, "just checking");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   331
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   332
  return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   333
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   334
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   335
ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   336
                    intptr_t** ret_sp, intptr_t** ret_fp) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   337
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   338
  ExtendedPC  epc;
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   339
  const ucontext_t* uc = (const ucontext_t*)ucVoid;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   340
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   341
  if (uc != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   342
    epc = ExtendedPC(os::Bsd::ucontext_get_pc(uc));
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   343
    if (ret_sp) *ret_sp = os::Bsd::ucontext_get_sp(uc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   344
    if (ret_fp) *ret_fp = os::Bsd::ucontext_get_fp(uc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   345
  } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   346
    // construct empty ExtendedPC for return value checking
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   347
    epc = ExtendedPC(NULL);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   348
    if (ret_sp) *ret_sp = (intptr_t *)NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   349
    if (ret_fp) *ret_fp = (intptr_t *)NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   350
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   351
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   352
  return epc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   353
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   354
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   355
frame os::fetch_frame_from_context(const void* ucVoid) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   356
  intptr_t* sp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   357
  intptr_t* fp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   358
  ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   359
  return frame(sp, fp, epc.pc());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   360
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   361
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   362
frame os::fetch_frame_from_ucontext(Thread* thread, void* ucVoid) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   363
  intptr_t* sp;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   364
  intptr_t* fp;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   365
  ExtendedPC epc = os::Bsd::fetch_frame_from_ucontext(thread, (ucontext_t*)ucVoid, &sp, &fp);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   366
  return frame(sp, fp, epc.pc());
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   367
}
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   368
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   369
bool os::Bsd::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   370
  address pc = (address) os::Bsd::ucontext_get_pc(uc);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   371
  if (Interpreter::contains(pc)) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   372
    // interpreter performs stack banging after the fixed frame header has
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   373
    // been generated while the compilers perform it before. To maintain
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   374
    // semantic consistency between interpreted and compiled frames, the
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   375
    // method returns the Java sender of the current frame.
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   376
    *fr = os::fetch_frame_from_ucontext(thread, uc);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   377
    if (!fr->is_first_java_frame()) {
41314
f815c3be1f2e 8146546: assert(fr->safe_for_sender(thread)) failed: Safety check
fparain
parents: 41070
diff changeset
   378
      // get_frame_at_stack_banging_point() is only called when we
f815c3be1f2e 8146546: assert(fr->safe_for_sender(thread)) failed: Safety check
fparain
parents: 41070
diff changeset
   379
      // have well defined stacks so java_sender() calls do not need
f815c3be1f2e 8146546: assert(fr->safe_for_sender(thread)) failed: Safety check
fparain
parents: 41070
diff changeset
   380
      // to assert safe_for_sender() first.
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   381
      *fr = fr->java_sender();
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   382
    }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   383
  } else {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   384
    // more complex code with compiled code
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   385
    assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   386
    CodeBlob* cb = CodeCache::find_blob(pc);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   387
    if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   388
      // Not sure where the pc points to, fallback to default
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   389
      // stack overflow handling
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   390
      return false;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   391
    } else {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   392
      *fr = os::fetch_frame_from_ucontext(thread, uc);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   393
      // in compiled code, the stack banging is performed just after the return pc
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   394
      // has been pushed on the stack
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   395
      *fr = frame(fr->sp() + 1, fr->fp(), (address)*(fr->sp()));
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   396
      if (!fr->is_java_frame()) {
41314
f815c3be1f2e 8146546: assert(fr->safe_for_sender(thread)) failed: Safety check
fparain
parents: 41070
diff changeset
   397
        // See java_sender() comment above.
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   398
        *fr = fr->java_sender();
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   399
      }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   400
    }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   401
  }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   402
  assert(fr->is_java_frame(), "Safety check");
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   403
  return true;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   404
}
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   405
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   406
// By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   407
// turned off by -fomit-frame-pointer,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   408
frame os::get_sender_for_C_frame(frame* fr) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   409
  return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   410
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   411
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   412
intptr_t* _get_previous_fp() {
11723
f3702d2e534c 7142167: MAC: _get_previous_fp broken on bsd with llvm-gcc
kvn
parents: 10739
diff changeset
   413
#if defined(SPARC_WORKS) || defined(__clang__) || defined(__llvm__)
51050
96ea37459ca7 8207011: Remove uses of the register storage class specifier
mikael
parents: 49615
diff changeset
   414
  intptr_t **ebp;
48824
e48c4461a8bb 8181503: Can't compile hotspot with c++11
gziemski
parents: 47765
diff changeset
   415
  __asm__("mov %%" SPELL_REG_FP ", %0":"=r"(ebp));
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   416
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   417
  register intptr_t **ebp __asm__ (SPELL_REG_FP);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   418
#endif
40384
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   419
  // ebp is for this frame (_get_previous_fp). We want the ebp for the
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   420
  // caller of os::current_frame*(), so go up two frames. However, for
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   421
  // optimized builds, _get_previous_fp() will be inlined, so only go
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   422
  // up 1 frame in that case.
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   423
#ifdef _NMT_NOINLINE_
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   424
  return **(intptr_t***)ebp;
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   425
#else
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   426
  return *ebp;
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   427
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   428
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   429
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   430
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   431
frame os::current_frame() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   432
  intptr_t* fp = _get_previous_fp();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   433
  frame myframe((intptr_t*)os::current_stack_pointer(),
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   434
                (intptr_t*)fp,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   435
                CAST_FROM_FN_PTR(address, os::current_frame));
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   436
  if (os::is_first_C_frame(&myframe)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   437
    // stack is not walkable
15468
4a274f843f41 8006508: Wrong frame constructor is called in os_linux_x86.cpp
dholmes
parents: 14633
diff changeset
   438
    return frame();
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   439
  } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   440
    return os::get_sender_for_C_frame(&myframe);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   441
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   442
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   443
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   444
// Utility functions
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   445
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   446
// From IA32 System Programming Guide
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   447
enum {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   448
  trap_page_fault = 0xE
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   449
};
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   450
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   451
extern "C" JNIEXPORT int
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   452
JVM_handle_bsd_signal(int sig,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   453
                        siginfo_t* info,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   454
                        void* ucVoid,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   455
                        int abort_if_unrecognized) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   456
  ucontext_t* uc = (ucontext_t*) ucVoid;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   457
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 33148
diff changeset
   458
  Thread* t = Thread::current_or_null_safe();
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   459
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 15947
diff changeset
   460
  // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 15947
diff changeset
   461
  // (no destructors can be run)
46644
a5813fb66270 8183925: Decouple crash protection from watcher thread
rehn
parents: 46630
diff changeset
   462
  os::ThreadCrashProtection::check_crash_protection(sig, t);
18943
7d0ef675e808 8020701: Avoid crashes in WatcherThread
rbackman
parents: 15947
diff changeset
   463
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   464
  SignalHandlerMark shm(t);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   465
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   466
  // Note: it's not uncommon that JNI code uses signal/sigset to install
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   467
  // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   468
  // or have a SIGILL handler when detecting CPU type). When that happens,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   469
  // JVM_handle_bsd_signal() might be invoked with junk info/ucVoid. To
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   470
  // avoid unnecessary crash when libjsig is not preloaded, try handle signals
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   471
  // that do not require siginfo/ucontext first.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   472
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   473
  if (sig == SIGPIPE || sig == SIGXFSZ) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   474
    // allow chained handler to go first
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   475
    if (os::Bsd::chained_handler(sig, info, ucVoid)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   476
      return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   477
    } else {
37430
fd743dadef12 8151939: VM_Version_init() print buffer is too small
coleenp
parents: 35201
diff changeset
   478
      // Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   479
      return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   480
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   481
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   482
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   483
  JavaThread* thread = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   484
  VMThread* vmthread = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   485
  if (os::Bsd::signal_handlers_are_installed) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   486
    if (t != NULL ){
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   487
      if(t->is_Java_thread()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   488
        thread = (JavaThread*)t;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   489
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   490
      else if(t->is_VM_thread()){
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   491
        vmthread = (VMThread *)t;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   492
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   493
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   494
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   495
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   496
  NOTE: does not seem to work on bsd.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   497
  if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   498
    // can't decode this kind of signal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   499
    info = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   500
  } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   501
    assert(sig == info->si_signo, "bad siginfo");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   502
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   503
*/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   504
  // decide if this trap can be handled by a stub
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   505
  address stub = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   506
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   507
  address pc          = NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   508
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   509
  //%note os_trap_1
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   510
  if (info != NULL && uc != NULL && thread != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   511
    pc = (address) os::Bsd::ucontext_get_pc(uc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   512
18740
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 15947
diff changeset
   513
    if (StubRoutines::is_safefetch_fault(pc)) {
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   514
      os::Bsd::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
18740
db44b1599483 8016697: Use stubs to implement safefetch
goetz
parents: 15947
diff changeset
   515
      return 1;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   516
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   517
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   518
    // Handle ALL stack overflow variations here
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   519
    if (sig == SIGSEGV || sig == SIGBUS) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   520
      address addr = (address) info->si_addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   521
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   522
      // check if fault address is within thread stack
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   523
      if (thread->on_local_stack(addr)) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   524
        // stack overflow
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   525
        if (thread->in_stack_yellow_reserved_zone(addr)) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   526
          if (thread->thread_state() == _thread_in_Java) {
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   527
            if (thread->in_stack_reserved_zone(addr)) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   528
              frame fr;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   529
              if (os::Bsd::get_frame_at_stack_banging_point(thread, uc, &fr)) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   530
                assert(fr.is_java_frame(), "Must be a Java frame");
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   531
                frame activation = SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   532
                if (activation.sp() != NULL) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   533
                  thread->disable_stack_reserved_zone();
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   534
                  if (activation.is_interpreted_frame()) {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   535
                    thread->set_reserved_stack_activation((address)(
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   536
                      activation.fp() + frame::interpreter_frame_initial_sp_offset));
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   537
                  } else {
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   538
                    thread->set_reserved_stack_activation((address)activation.unextended_sp());
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   539
                  }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   540
                  return 1;
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   541
                }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   542
              }
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34667
diff changeset
   543
            }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   544
            // Throw a stack overflow exception.  Guard pages will be reenabled
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   545
            // while unwinding the stack.
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   546
            thread->disable_stack_yellow_reserved_zone();
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   547
            stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   548
          } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   549
            // Thread was in the vm or native code.  Return and try to finish.
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35077
diff changeset
   550
            thread->disable_stack_yellow_reserved_zone();
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   551
            return 1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   552
          }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   553
        } else if (thread->in_stack_red_zone(addr)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   554
          // Fatal red zone violation.  Disable the guard pages and fall through
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   555
          // to handle_unexpected_exception way down below.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   556
          thread->disable_stack_red_zone();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   557
          tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   558
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   559
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   560
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   561
23487
0f7e268cd9e3 8037226: compiler/7196199/Test7196199.java fails on 32-bit linux with MaxVectorSize > 16
kvn
parents: 22234
diff changeset
   562
    if ((sig == SIGSEGV || sig == SIGBUS) && VM_Version::is_cpuinfo_segv_addr(pc)) {
0f7e268cd9e3 8037226: compiler/7196199/Test7196199.java fails on 32-bit linux with MaxVectorSize > 16
kvn
parents: 22234
diff changeset
   563
      // Verify that OS save/restore AVX registers.
0f7e268cd9e3 8037226: compiler/7196199/Test7196199.java fails on 32-bit linux with MaxVectorSize > 16
kvn
parents: 22234
diff changeset
   564
      stub = VM_Version::cpuinfo_cont_addr();
0f7e268cd9e3 8037226: compiler/7196199/Test7196199.java fails on 32-bit linux with MaxVectorSize > 16
kvn
parents: 22234
diff changeset
   565
    }
0f7e268cd9e3 8037226: compiler/7196199/Test7196199.java fails on 32-bit linux with MaxVectorSize > 16
kvn
parents: 22234
diff changeset
   566
13109
f9fff4a46910 7129715: MAC: SIGBUS in nsk stress test
roland
parents: 12740
diff changeset
   567
    // We test if stub is already set (by the stack overflow code
f9fff4a46910 7129715: MAC: SIGBUS in nsk stress test
roland
parents: 12740
diff changeset
   568
    // above) so it is not overwritten by the code that follows. This
f9fff4a46910 7129715: MAC: SIGBUS in nsk stress test
roland
parents: 12740
diff changeset
   569
    // check is not required on other platforms, because on other
f9fff4a46910 7129715: MAC: SIGBUS in nsk stress test
roland
parents: 12740
diff changeset
   570
    // platforms we check for SIGSEGV only or SIGBUS only, where here
f9fff4a46910 7129715: MAC: SIGBUS in nsk stress test
roland
parents: 12740
diff changeset
   571
    // we have to check for both SIGSEGV and SIGBUS.
f9fff4a46910 7129715: MAC: SIGBUS in nsk stress test
roland
parents: 12740
diff changeset
   572
    if (thread->thread_state() == _thread_in_Java && stub == NULL) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   573
      // Java thread running in Java code => find exception handler if any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   574
      // a fault inside compiled code, the interpreter, or a stub
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   575
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   576
      if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   577
        stub = SharedRuntime::get_poll_stub(pc);
12740
fa38bd69a34b 7167254: Crash on OSX in Enumerator.nextElement() with compressed oops
roland
parents: 11961
diff changeset
   578
#if defined(__APPLE__)
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   579
      // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
12740
fa38bd69a34b 7167254: Crash on OSX in Enumerator.nextElement() with compressed oops
roland
parents: 11961
diff changeset
   580
      // 64-bit Darwin may also use a SIGBUS (seen with compressed oops).
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   581
      // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   582
      // being called, so only do so if the implicit NULL check is not necessary.
52462
4ad404da0088 8213199: GC abstraction for Assembler::needs_explicit_null_check()
rkennke
parents: 52460
diff changeset
   583
      } else if (sig == SIGBUS && !MacroAssembler::uses_implicit_null_check(info->si_addr)) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   584
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   585
      } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   586
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   587
        // BugId 4454115: A read from a MappedByteBuffer can fault
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   588
        // here if the underlying file has been truncated.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   589
        // Do not crash the VM in such a case.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   590
        CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 37430
diff changeset
   591
        CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   592
        bool is_unsafe_arraycopy = thread->doing_unsafe_access() && UnsafeCopyMemory::contains_pc(pc);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   593
        if ((nm != NULL && nm->has_unsafe_access()) || is_unsafe_arraycopy) {
38209
b2a58604e046 8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents: 38190
diff changeset
   594
          address next_pc = Assembler::locate_next_instruction(pc);
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   595
          if (is_unsafe_arraycopy) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   596
            next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   597
          }
38209
b2a58604e046 8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents: 38190
diff changeset
   598
          stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   599
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   600
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   601
      else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   602
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   603
#ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   604
      if (sig == SIGFPE  &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   605
          (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   606
        stub =
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   607
          SharedRuntime::
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   608
          continuation_for_implicit_exception(thread,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   609
                                              pc,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   610
                                              SharedRuntime::
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   611
                                              IMPLICIT_DIVIDE_BY_ZERO);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   612
#ifdef __APPLE__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   613
      } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   614
        int op = pc[0];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   615
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   616
        // Skip REX
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   617
        if ((pc[0] & 0xf0) == 0x40) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   618
          op = pc[1];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   619
        } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   620
          op = pc[0];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   621
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   622
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   623
        // Check for IDIV
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   624
        if (op == 0xF7) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   625
          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   626
        } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   627
          // TODO: handle more cases if we are using other x86 instructions
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   628
          //   that can generate SIGFPE signal.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   629
          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   630
          fatal("please update this code.");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   631
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   632
#endif /* __APPLE__ */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   633
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   634
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   635
      if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   636
        // HACK: si_code does not work on bsd 2.2.12-20!!!
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   637
        int op = pc[0];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   638
        if (op == 0xDB) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   639
          // FIST
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   640
          // TODO: The encoding of D2I in i486.ad can cause an exception
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   641
          // prior to the fist instruction if there was an invalid operation
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   642
          // pending. We want to dismiss that exception. From the win_32
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   643
          // side it also seems that if it really was the fist causing
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   644
          // the exception that we do the d2i by hand with different
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   645
          // rounding. Seems kind of weird.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   646
          // NOTE: that we take the exception at the NEXT floating point instruction.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   647
          assert(pc[0] == 0xDB, "not a FIST opcode");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   648
          assert(pc[1] == 0x14, "not a FIST opcode");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   649
          assert(pc[2] == 0x24, "not a FIST opcode");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   650
          return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   651
        } else if (op == 0xF7) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   652
          // IDIV
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   653
          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   654
        } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   655
          // TODO: handle more cases if we are using other x86 instructions
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   656
          //   that can generate SIGFPE signal on bsd.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   657
          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   658
          fatal("please update this code.");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   659
        }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   660
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   661
      } else if ((sig == SIGSEGV || sig == SIGBUS) &&
52462
4ad404da0088 8213199: GC abstraction for Assembler::needs_explicit_null_check()
rkennke
parents: 52460
diff changeset
   662
                 MacroAssembler::uses_implicit_null_check(info->si_addr)) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   663
          // Determination of interpreter/vtable stub/compiled code null exception
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   664
          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   665
      }
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   666
    } else if ((thread->thread_state() == _thread_in_vm ||
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   667
                thread->thread_state() == _thread_in_native) &&
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   668
               sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   669
               thread->doing_unsafe_access()) {
38209
b2a58604e046 8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents: 38190
diff changeset
   670
        address next_pc = Assembler::locate_next_instruction(pc);
55490
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   671
        if (UnsafeCopyMemory::contains_pc(pc)) {
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   672
          next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);
3f3dc00a69a5 8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents: 53605
diff changeset
   673
        }
38209
b2a58604e046 8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents: 38190
diff changeset
   674
        stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   675
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   676
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   677
    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   678
    // and the heap gets shrunk before the field access.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   679
    if ((sig == SIGSEGV) || (sig == SIGBUS)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   680
      address addr = JNI_FastGetField::find_slowcase_pc(pc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   681
      if (addr != (address)-1) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   682
        stub = addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   683
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   684
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   685
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   686
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   687
#ifndef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   688
  // Execution protection violation
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   689
  //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   690
  // This should be kept as the last step in the triage.  We don't
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   691
  // have a dedicated trap number for a no-execute fault, so be
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   692
  // conservative and allow other handlers the first shot.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   693
  //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   694
  // Note: We don't test that info->si_code == SEGV_ACCERR here.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   695
  // this si_code is so generic that it is almost meaningless; and
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   696
  // the si_code for this condition may change in the future.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   697
  // Furthermore, a false-positive should be harmless.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   698
  if (UnguardOnExecutionViolation > 0 &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   699
      (sig == SIGSEGV || sig == SIGBUS) &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   700
      uc->context_trapno == trap_page_fault) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   701
    int page_size = os::vm_page_size();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   702
    address addr = (address) info->si_addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   703
    address pc = os::Bsd::ucontext_get_pc(uc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   704
    // Make sure the pc and the faulting address are sane.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   705
    //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   706
    // If an instruction spans a page boundary, and the page containing
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   707
    // the beginning of the instruction is executable but the following
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   708
    // page is not, the pc and the faulting address might be slightly
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   709
    // different - we still want to unguard the 2nd page in this case.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   710
    //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   711
    // 15 bytes seems to be a (very) safe value for max instruction size.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   712
    bool pc_is_near_addr =
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   713
      (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   714
    bool instr_spans_page_boundary =
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   715
      (align_down((intptr_t) pc ^ (intptr_t) addr,
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   716
                       (intptr_t) page_size) > 0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   717
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   718
    if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   719
      static volatile address last_addr =
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   720
        (address) os::non_memory_address_word();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   721
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   722
      // In conservative mode, don't unguard unless the address is in the VM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   723
      if (addr != last_addr &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   724
          (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   725
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   726
        // Set memory to RWX and retry
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   727
        address page_start = align_down(addr, page_size);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   728
        bool res = os::protect_memory((char*) page_start, page_size,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   729
                                      os::MEM_PROT_RWX);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   730
37430
fd743dadef12 8151939: VM_Version_init() print buffer is too small
coleenp
parents: 35201
diff changeset
   731
        log_debug(os)("Execution protection violation "
fd743dadef12 8151939: VM_Version_init() print buffer is too small
coleenp
parents: 35201
diff changeset
   732
                      "at " INTPTR_FORMAT
fd743dadef12 8151939: VM_Version_init() print buffer is too small
coleenp
parents: 35201
diff changeset
   733
                      ", unguarding " INTPTR_FORMAT ": %s, errno=%d", p2i(addr),
fd743dadef12 8151939: VM_Version_init() print buffer is too small
coleenp
parents: 35201
diff changeset
   734
                      p2i(page_start), (res ? "success" : "failed"), errno);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   735
        stub = pc;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   736
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   737
        // Set last_addr so if we fault again at the same address, we don't end
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   738
        // up in an endless loop.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   739
        //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   740
        // There are two potential complications here.  Two threads trapping at
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   741
        // the same address at the same time could cause one of the threads to
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   742
        // think it already unguarded, and abort the VM.  Likely very rare.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   743
        //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   744
        // The other race involves two threads alternately trapping at
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   745
        // different addresses and failing to unguard the page, resulting in
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   746
        // an endless loop.  This condition is probably even more unlikely than
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   747
        // the first.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   748
        //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   749
        // Although both cases could be avoided by using locks or thread local
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   750
        // last_addr, these solutions are unnecessary complication: this
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   751
        // handler is a best-effort safety net, not a complete solution.  It is
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   752
        // disabled by default and should only be used as a workaround in case
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   753
        // we missed any no-execute-unsafe VM code.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   754
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   755
        last_addr = addr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   756
      }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   757
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   758
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   759
#endif // !AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   760
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   761
  if (stub != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   762
    // save all thread context in case we need to restore it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   763
    if (thread != NULL) thread->set_saved_exception_pc(pc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   764
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 26576
diff changeset
   765
    os::Bsd::ucontext_set_pc(uc, stub);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   766
    return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   767
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   768
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   769
  // signal-chaining
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   770
  if (os::Bsd::chained_handler(sig, info, ucVoid)) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   771
     return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   772
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   773
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   774
  if (!abort_if_unrecognized) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   775
    // caller wants another chance, so give it to him
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   776
    return false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   777
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   778
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   779
  if (pc == NULL && uc != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   780
    pc = os::Bsd::ucontext_get_pc(uc);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   781
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   782
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   783
  // unmask current signal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   784
  sigset_t newset;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   785
  sigemptyset(&newset);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   786
  sigaddset(&newset, sig);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   787
  sigprocmask(SIG_UNBLOCK, &newset, NULL);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   788
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32080
diff changeset
   789
  VMError::report_and_die(t, sig, pc, info, ucVoid);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   790
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   791
  ShouldNotReachHere();
19336
ddceb0657500 8022956: Clang: enable return type warnings on BSD
twisti
parents: 18945
diff changeset
   792
  return false;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   793
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   794
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   795
// From solaris_i486.s ported to bsd_i486.s
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   796
extern "C" void fixcw();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   797
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   798
void os::Bsd::init_thread_fpu_state(void) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   799
#ifndef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   800
  // Set fpu to 53 bit precision. This happens too early to use a stub.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   801
  fixcw();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   802
#endif // !AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   803
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   804
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   805
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   806
// Check that the bsd kernel version is 2.4 or higher since earlier
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   807
// versions do not support SSE without patches.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   808
bool os::supports_sse() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   809
  return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   810
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   811
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   812
bool os::is_allocatable(size_t bytes) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   813
#ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   814
  // unused on amd64?
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   815
  return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   816
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   817
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   818
  if (bytes < 2 * G) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   819
    return true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   820
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   821
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   822
  char* addr = reserve_memory(bytes, NULL);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   823
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   824
  if (addr != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   825
    release_memory(addr, bytes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   826
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   827
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   828
  return addr != NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   829
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   830
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   831
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   832
////////////////////////////////////////////////////////////////////////////////
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   833
// thread stack
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   834
42906
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   835
// Minimum usable stack sizes required to get to user code. Space for
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   836
// HotSpot guard pages is added later.
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   837
size_t os::Posix::_compiler_thread_min_stack_allowed = 48 * K;
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   838
size_t os::Posix::_java_thread_min_stack_allowed = 48 * K;
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   839
#ifdef _LP64
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40384
diff changeset
   840
size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   841
#else
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40384
diff changeset
   842
size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
42906
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   843
#endif // _LP64
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   844
42906
1a8db9cf1407 8170655: [posix] Fix minimum stack size computations
goetz
parents: 42905
diff changeset
   845
#ifndef AMD64
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   846
#ifdef __GNUC__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   847
#define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   848
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   849
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   850
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   851
// return default stack size for thr_type
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 40384
diff changeset
   852
size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   853
  // default stack size (compiler thread needs larger stack)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   854
#ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   855
  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   856
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   857
  size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   858
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   859
  return s;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   860
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   861
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   862
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   863
// Java thread:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   864
//
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   865
//   Low memory addresses
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   866
//    +------------------------+
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   867
//    |                        |\  Java thread created by VM does not have glibc
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   868
//    |    glibc guard page    | - guard, attached Java thread usually has
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   869
//    |                        |/  1 glibc guard page.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   870
// P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   871
//    |                        |\
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   872
//    |  HotSpot Guard Pages   | - red, yellow and reserved pages
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   873
//    |                        |/
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   874
//    +------------------------+ JavaThread::stack_reserved_zone_base()
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   875
//    |                        |\
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   876
//    |      Normal Stack      | -
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   877
//    |                        |/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   878
// P2 +------------------------+ Thread::stack_base()
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   879
//
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   880
// Non-Java thread:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   881
//
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   882
//   Low memory addresses
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   883
//    +------------------------+
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   884
//    |                        |\
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   885
//    |  glibc guard page      | - usually 1 page
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   886
//    |                        |/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   887
// P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   888
//    |                        |\
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   889
//    |      Normal Stack      | -
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   890
//    |                        |/
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   891
// P2 +------------------------+ Thread::stack_base()
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   892
//
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   893
// ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   894
//    pthread_attr_getstack()
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   895
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   896
static void current_stack_region(address * bottom, size_t * size) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   897
#ifdef __APPLE__
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   898
  pthread_t self = pthread_self();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   899
  void *stacktop = pthread_get_stackaddr_np(self);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   900
  *size = pthread_get_stacksize_np(self);
21184
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   901
  // workaround for OS X 10.9.0 (Mavericks)
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   902
  // pthread_get_stacksize_np returns 128 pages even though the actual size is 2048 pages
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   903
  if (pthread_main_np() == 1) {
46974
2c6c8846e176 8186286: [BSD] Primary thread's stack size is reported incorrectly
ghaug
parents: 46644
diff changeset
   904
    // At least on Mac OS 10.12 we have observed stack sizes not aligned
2c6c8846e176 8186286: [BSD] Primary thread's stack size is reported incorrectly
ghaug
parents: 46644
diff changeset
   905
    // to pages boundaries. This can be provoked by e.g. setrlimit() (ulimit -s xxxx in the
2c6c8846e176 8186286: [BSD] Primary thread's stack size is reported incorrectly
ghaug
parents: 46644
diff changeset
   906
    // shell). Apparently Mac OS actually rounds upwards to next multiple of page size,
2c6c8846e176 8186286: [BSD] Primary thread's stack size is reported incorrectly
ghaug
parents: 46644
diff changeset
   907
    // however, we round downwards here to be on the safe side.
2c6c8846e176 8186286: [BSD] Primary thread's stack size is reported incorrectly
ghaug
parents: 46644
diff changeset
   908
    *size = align_down(*size, getpagesize());
2c6c8846e176 8186286: [BSD] Primary thread's stack size is reported incorrectly
ghaug
parents: 46644
diff changeset
   909
21184
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   910
    if ((*size) < (DEFAULT_MAIN_THREAD_STACK_PAGES * (size_t)getpagesize())) {
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   911
      char kern_osrelease[256];
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   912
      size_t kern_osrelease_size = sizeof(kern_osrelease);
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   913
      int ret = sysctlbyname("kern.osrelease", kern_osrelease, &kern_osrelease_size, NULL, 0);
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   914
      if (ret == 0) {
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   915
        // get the major number, atoi will ignore the minor amd micro portions of the version string
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   916
        if (atoi(kern_osrelease) >= OS_X_10_9_0_KERNEL_MAJOR_VERSION) {
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   917
          *size = (DEFAULT_MAIN_THREAD_STACK_PAGES*getpagesize());
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   918
        }
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   919
      }
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   920
    }
f7cc37a4ea4d 8020753: JNI_CreateJavaVM on Mac OSX 10.9 Mavericks corrupts the callers stack size
iklam
parents: 19336
diff changeset
   921
  }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   922
  *bottom = (address) stacktop - *size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   923
#elif defined(__OpenBSD__)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   924
  stack_t ss;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   925
  int rslt = pthread_stackseg_np(pthread_self(), &ss);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   926
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   927
  if (rslt != 0)
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   928
    fatal("pthread_stackseg_np failed with error = %d", rslt);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   929
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   930
  *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   931
  *size   = ss.ss_size;
14286
ec9e76cd402f 8001619: Remove usage of _ALLBSD_SOURCE in bsd files
sla
parents: 13932
diff changeset
   932
#else
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   933
  pthread_attr_t attr;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   934
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   935
  int rslt = pthread_attr_init(&attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   936
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   937
  // JVM needs to know exact stack location, abort if it fails
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   938
  if (rslt != 0)
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   939
    fatal("pthread_attr_init failed with error = %d", rslt);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   940
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   941
  rslt = pthread_attr_get_np(pthread_self(), &attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   942
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   943
  if (rslt != 0)
42905
1af223983f82 8169373: Work around linux NPTL stack guard error.
goetz
parents: 41314
diff changeset
   944
    fatal("pthread_attr_get_np failed with error = %d", rslt);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   945
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   946
  if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   947
    pthread_attr_getstacksize(&attr, size) != 0) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   948
    fatal("Can not locate current stack attributes!");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   949
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   950
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   951
  pthread_attr_destroy(&attr);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   952
#endif
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   953
  assert(os::current_stack_pointer() >= *bottom &&
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   954
         os::current_stack_pointer() < *bottom + *size, "just checking");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   955
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   956
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   957
address os::current_stack_base() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   958
  address bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   959
  size_t size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   960
  current_stack_region(&bottom, &size);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   961
  return (bottom + size);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   962
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   963
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   964
size_t os::current_stack_size() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   965
  // stack size includes normal stack and HotSpot guard pages
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   966
  address bottom;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   967
  size_t size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   968
  current_stack_region(&bottom, &size);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   969
  return size;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   970
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   971
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   972
/////////////////////////////////////////////////////////////////////////////
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   973
// helper functions for fatal error handler
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   974
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   975
void os::print_context(outputStream *st, const void *context) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   976
  if (context == NULL) return;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   977
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   978
  const ucontext_t *uc = (const ucontext_t*)context;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   979
  st->print_cr("Registers:");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   980
#ifdef AMD64
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   981
  st->print(  "RAX=" INTPTR_FORMAT, (intptr_t)uc->context_rax);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   982
  st->print(", RBX=" INTPTR_FORMAT, (intptr_t)uc->context_rbx);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   983
  st->print(", RCX=" INTPTR_FORMAT, (intptr_t)uc->context_rcx);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   984
  st->print(", RDX=" INTPTR_FORMAT, (intptr_t)uc->context_rdx);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   985
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   986
  st->print(  "RSP=" INTPTR_FORMAT, (intptr_t)uc->context_rsp);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   987
  st->print(", RBP=" INTPTR_FORMAT, (intptr_t)uc->context_rbp);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   988
  st->print(", RSI=" INTPTR_FORMAT, (intptr_t)uc->context_rsi);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   989
  st->print(", RDI=" INTPTR_FORMAT, (intptr_t)uc->context_rdi);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   990
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   991
  st->print(  "R8 =" INTPTR_FORMAT, (intptr_t)uc->context_r8);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   992
  st->print(", R9 =" INTPTR_FORMAT, (intptr_t)uc->context_r9);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   993
  st->print(", R10=" INTPTR_FORMAT, (intptr_t)uc->context_r10);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   994
  st->print(", R11=" INTPTR_FORMAT, (intptr_t)uc->context_r11);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   995
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   996
  st->print(  "R12=" INTPTR_FORMAT, (intptr_t)uc->context_r12);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   997
  st->print(", R13=" INTPTR_FORMAT, (intptr_t)uc->context_r13);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   998
  st->print(", R14=" INTPTR_FORMAT, (intptr_t)uc->context_r14);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
   999
  st->print(", R15=" INTPTR_FORMAT, (intptr_t)uc->context_r15);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1000
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1001
  st->print(  "RIP=" INTPTR_FORMAT, (intptr_t)uc->context_rip);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1002
  st->print(", EFLAGS=" INTPTR_FORMAT, (intptr_t)uc->context_flags);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1003
  st->print(", ERR=" INTPTR_FORMAT, (intptr_t)uc->context_err);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1004
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1005
  st->print("  TRAPNO=" INTPTR_FORMAT, (intptr_t)uc->context_trapno);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1006
#else
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1007
  st->print(  "EAX=" INTPTR_FORMAT, (intptr_t)uc->context_eax);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1008
  st->print(", EBX=" INTPTR_FORMAT, (intptr_t)uc->context_ebx);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1009
  st->print(", ECX=" INTPTR_FORMAT, (intptr_t)uc->context_ecx);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1010
  st->print(", EDX=" INTPTR_FORMAT, (intptr_t)uc->context_edx);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1011
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1012
  st->print(  "ESP=" INTPTR_FORMAT, (intptr_t)uc->context_esp);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1013
  st->print(", EBP=" INTPTR_FORMAT, (intptr_t)uc->context_ebp);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1014
  st->print(", ESI=" INTPTR_FORMAT, (intptr_t)uc->context_esi);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1015
  st->print(", EDI=" INTPTR_FORMAT, (intptr_t)uc->context_edi);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1016
  st->cr();
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1017
  st->print(  "EIP=" INTPTR_FORMAT, (intptr_t)uc->context_eip);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1018
  st->print(", EFLAGS=" INTPTR_FORMAT, (intptr_t)uc->context_eflags);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1019
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1020
  st->cr();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1021
  st->cr();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1022
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1023
  intptr_t *sp = (intptr_t *)os::Bsd::ucontext_get_sp(uc);
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46625
diff changeset
  1024
  st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", (intptr_t)sp);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1025
  print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1026
  st->cr();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1027
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1028
  // Note: it may be unsafe to inspect memory near pc. For example, pc may
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1029
  // point to garbage if entry point in an nmethod is corrupted. Leave
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1030
  // this at the end, and hope for the best.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1031
  address pc = os::Bsd::ucontext_get_pc(uc);
53605
853c68ff2ed7 8217879: hs_err should print more instructions in hex dump
shade
parents: 52462
diff changeset
  1032
  print_instructions(st, pc, sizeof(char));
853c68ff2ed7 8217879: hs_err should print more instructions in hex dump
shade
parents: 52462
diff changeset
  1033
  st->cr();
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1034
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1035
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
  1036
void os::print_register_info(outputStream *st, const void *context) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1037
  if (context == NULL) return;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1038
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
  1039
  const ucontext_t *uc = (const ucontext_t*)context;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1040
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1041
  st->print_cr("Register to memory mapping:");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1042
  st->cr();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1043
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1044
  // this is horrendously verbose but the layout of the registers in the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1045
  // context does not match how we defined our abstract Register set, so
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1046
  // we can't just iterate through the gregs area
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1047
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1048
  // this is only for the "general purpose" registers
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1049
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1050
#ifdef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1051
  st->print("RAX="); print_location(st, uc->context_rax);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1052
  st->print("RBX="); print_location(st, uc->context_rbx);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1053
  st->print("RCX="); print_location(st, uc->context_rcx);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1054
  st->print("RDX="); print_location(st, uc->context_rdx);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1055
  st->print("RSP="); print_location(st, uc->context_rsp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1056
  st->print("RBP="); print_location(st, uc->context_rbp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1057
  st->print("RSI="); print_location(st, uc->context_rsi);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1058
  st->print("RDI="); print_location(st, uc->context_rdi);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1059
  st->print("R8 ="); print_location(st, uc->context_r8);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1060
  st->print("R9 ="); print_location(st, uc->context_r9);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1061
  st->print("R10="); print_location(st, uc->context_r10);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1062
  st->print("R11="); print_location(st, uc->context_r11);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1063
  st->print("R12="); print_location(st, uc->context_r12);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1064
  st->print("R13="); print_location(st, uc->context_r13);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1065
  st->print("R14="); print_location(st, uc->context_r14);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1066
  st->print("R15="); print_location(st, uc->context_r15);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1067
#else
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1068
  st->print("EAX="); print_location(st, uc->context_eax);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1069
  st->print("EBX="); print_location(st, uc->context_ebx);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1070
  st->print("ECX="); print_location(st, uc->context_ecx);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1071
  st->print("EDX="); print_location(st, uc->context_edx);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1072
  st->print("ESP="); print_location(st, uc->context_esp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1073
  st->print("EBP="); print_location(st, uc->context_ebp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1074
  st->print("ESI="); print_location(st, uc->context_esi);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1075
  st->print("EDI="); print_location(st, uc->context_edi);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1076
#endif // AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1077
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1078
  st->cr();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1079
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1080
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1081
void os::setup_fpu() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1082
#ifndef AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1083
  address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1084
  __asm__ volatile (  "fldcw (%0)" :
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1085
                      : "r" (fpu_cntrl) : "memory");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1086
#endif // !AMD64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
  1087
}
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 11723
diff changeset
  1088
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 11723
diff changeset
  1089
#ifndef PRODUCT
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 11723
diff changeset
  1090
void os::verify_stack_alignment() {
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 11723
diff changeset
  1091
}
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 11723
diff changeset
  1092
#endif
26576
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 24424
diff changeset
  1093
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 24424
diff changeset
  1094
int os::extra_bang_size_in_bytes() {
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 24424
diff changeset
  1095
  // JDK-8050147 requires the full cache line bang for x86.
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 24424
diff changeset
  1096
  return VM_Version::L1_line_size();
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 24424
diff changeset
  1097
}