src/hotspot/os_cpu/windows_x86/os_windows_x86.cpp
author coleenp
Fri, 16 Mar 2018 09:12:13 -0400
changeset 49449 ef5d5d343e2a
parent 48468 7cc7de9bf4a4
child 52302 912b79d983d9
permissions -rw-r--r--
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files Summary: interfaceSupport.hpp is an inline file so moved to interfaceSupport.inline.hpp and stopped including it in .hpp files Reviewed-by: stefank, rehn, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46792
1f9002906ea9 8185706: [windows] Native callstacks printing terminates prematurely
stuefe
parents: 40384
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    25
// no precompiled headers
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47666
diff changeset
    26
#include "jvm.h"
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 14284
diff changeset
    27
#include "asm/macroAssembler.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    28
#include "classfile/classLoader.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    29
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    30
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    31
#include "code/icBuffer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    32
#include "code/vtableStubs.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    33
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    34
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35903
diff changeset
    35
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    36
#include "nativeInst_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    37
#include "os_share_windows.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    38
#include "prims/jniFastGetField.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    39
#include "prims/jvm_misc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    40
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    41
#include "runtime/extendedPC.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    42
#include "runtime/frame.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 48468
diff changeset
    43
#include "runtime/interfaceSupport.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    44
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    45
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    46
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    47
#include "runtime/osThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    48
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    49
#include "runtime/stubRoutines.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 14284
diff changeset
    50
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    51
#include "runtime/timer.hpp"
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
    52
#include "symbolengine.hpp"
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46792
diff changeset
    53
#include "unwind_windows_x86.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    54
#include "utilities/events.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    55
#include "utilities/vmError.hpp"
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46792
diff changeset
    56
#include "windbghelp.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    57
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46792
diff changeset
    58
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
#undef REG_SP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#undef REG_FP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
#undef REG_PC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
#define REG_SP Rsp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#define REG_FP Rbp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
#define REG_PC Rip
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
#define REG_SP Esp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
#define REG_FP Ebp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
#define REG_PC Eip
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
// Install a win32 structured exception handler around thread.
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 27694
diff changeset
    75
void os::os_exception_wrapper(java_call_t f, JavaValue* value, const methodHandle& method, JavaCallArguments* args, Thread* thread) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  __try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    // We store the current thread in this wrapperthread location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    // and determine how far away this address is from the structured
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    // execption pointer that FS:[0] points to.  This get_thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // code can then get the thread pointer via FS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // Warning:  This routine must NEVER be inlined since we'd end up with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    //           multiple offsets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    volatile Thread* wrapperthread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 33593
diff changeset
    89
    if (os::win32::get_thread_ptr_offset() == 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      int thread_ptr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        lea eax, dword ptr wrapperthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        sub eax, dword ptr FS:[0H];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        mov thread_ptr_offset, eax
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      };
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 33593
diff changeset
    96
      os::win32::set_thread_ptr_offset(thread_ptr_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // Verify that the offset hasn't changed since we initally captured
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    // it. This might happen if we accidentally ended up with an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    // inlined version of this routine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      int test_thread_ptr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        lea eax, dword ptr wrapperthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        sub eax, dword ptr FS:[0H];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        mov test_thread_ptr_offset, eax
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      };
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 33593
diff changeset
   109
      assert(test_thread_ptr_offset == os::win32::get_thread_ptr_offset(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
             "thread pointer offset from SEH changed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    f(value, method, args, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// This is the language specific handler for exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// originating from dynamically generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// We call the standard structured exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// We only expect Continued Execution since we cannot unwind
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// from generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
LONG HandleExceptionFromCodeCache(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  IN PEXCEPTION_RECORD ExceptionRecord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  IN ULONG64 EstablisherFrame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  IN OUT PCONTEXT ContextRecord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  IN OUT PDISPATCHER_CONTEXT DispatcherContext) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  EXCEPTION_POINTERS ep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  LONG result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  ep.ExceptionRecord = ExceptionRecord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  ep.ContextRecord = ContextRecord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  result = topLevelExceptionFilter(&ep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // We better only get a CONTINUE_EXECUTION from our handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // since we don't have unwind information registered.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  guarantee( result == EXCEPTION_CONTINUE_EXECUTION,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
             "Unexpected result from topLevelExceptionFilter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  return(ExceptionContinueExecution);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// Structure containing the Windows Data Structures required
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// to register our Code Cache exception handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// We put these in the CodeCache since the API requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// all addresses in these structures are relative to the Code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// area registered with RtlAddFunctionTable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
typedef struct {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  char ExceptionHandlerInstr[16];  // jmp HandleExceptionFromCodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  RUNTIME_FUNCTION rt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  UNWIND_INFO_EH_ONLY unw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
} DynamicCodeData, *pDynamicCodeData;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
// Register our CodeCache area with the OS so it will dispatch exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// to our topLevelExceptionFilter when we take an exception in our
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// dynamically generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// Arguments:  low and high are the address of the full reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// codeCache area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
bool os::register_code_area(char *low, char *high) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  pDynamicCodeData pDCD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  PRUNTIME_FUNCTION prt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  PUNWIND_INFO_EH_ONLY punwind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6176
diff changeset
   180
  BufferBlob* blob = BufferBlob::create("CodeCache Exception Handler", sizeof(DynamicCodeData));
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6176
diff changeset
   181
  CodeBuffer cb(blob);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  MacroAssembler* masm = new MacroAssembler(&cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  pDCD = (pDynamicCodeData) masm->pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  masm->jump(ExternalAddress((address)&HandleExceptionFromCodeCache));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  masm->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Create an Unwind Structure specifying no unwind info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // other than an Exception Handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  punwind = &pDCD->unw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  punwind->Version = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  punwind->Flags = UNW_FLAG_EHANDLER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  punwind->SizeOfProlog = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  punwind->CountOfCodes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  punwind->FrameRegister = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  punwind->FrameOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  punwind->ExceptionHandler = (char *)(&(pDCD->ExceptionHandlerInstr[0])) -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                              (char*)low;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  punwind->ExceptionData[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // This structure describes the covered dynamic code area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // Addresses are relative to the beginning on the code cache area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  prt = &pDCD->rt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  prt->BeginAddress = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  prt->EndAddress = (ULONG)(high - low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  prt->UnwindData = ((char *)punwind - low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  guarantee(RtlAddFunctionTable(prt, 1, (ULONGLONG)low),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
            "Failed to register Dynamic Code Exception Handler with RtlAddFunctionTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
13859
7fe4578493fc 7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents: 11961
diff changeset
   215
void os::initialize_thread(Thread* thr) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
// Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// Atomics and Stub Functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   221
typedef int32_t   xchg_func_t            (int32_t,  volatile int32_t*);
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   222
typedef int64_t   xchg_long_func_t       (int64_t,  volatile int64_t*);
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   223
typedef int32_t   cmpxchg_func_t         (int32_t,  volatile int32_t*, int32_t);
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   224
typedef int8_t    cmpxchg_byte_func_t    (int8_t,   volatile int8_t*,  int8_t);
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   225
typedef int64_t   cmpxchg_long_func_t    (int64_t,  volatile int64_t*, int64_t);
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   226
typedef int32_t   add_func_t             (int32_t,  volatile int32_t*);
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   227
typedef int64_t   add_long_func_t        (int64_t,  volatile int64_t*);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   231
int32_t os::atomic_xchg_bootstrap(int32_t exchange_value, volatile int32_t* dest) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    os::atomic_xchg_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    return (*func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   241
  int32_t old_value = *dest;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   246
int64_t os::atomic_xchg_long_bootstrap(int64_t exchange_value, volatile int64_t* dest) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // try to use the stub:
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   248
  xchg_long_func_t* func = CAST_TO_FN_PTR(xchg_long_func_t*, StubRoutines::atomic_xchg_long_entry());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  if (func != NULL) {
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   251
    os::atomic_xchg_long_func = func;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    return (*func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   256
  int64_t old_value = *dest;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   262
int32_t os::atomic_cmpxchg_bootstrap(int32_t exchange_value, volatile int32_t* dest, int32_t compare_value) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    os::atomic_cmpxchg_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    return (*func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   272
  int32_t old_value = *dest;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  if (old_value == compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
}
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   277
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   278
int8_t os::atomic_cmpxchg_byte_bootstrap(int8_t exchange_value, volatile int8_t* dest, int8_t compare_value) {
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   279
  // try to use the stub:
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   280
  cmpxchg_byte_func_t* func = CAST_TO_FN_PTR(cmpxchg_byte_func_t*, StubRoutines::atomic_cmpxchg_byte_entry());
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   281
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   282
  if (func != NULL) {
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   283
    os::atomic_cmpxchg_byte_func = func;
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   284
    return (*func)(exchange_value, dest, compare_value);
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   285
  }
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   286
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   287
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   288
  int8_t old_value = *dest;
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   289
  if (old_value == compare_value)
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   290
    *dest = exchange_value;
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   291
  return old_value;
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   292
}
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   293
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   296
int64_t os::atomic_cmpxchg_long_bootstrap(int64_t exchange_value, volatile int64_t* dest, int64_t compare_value) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    os::atomic_cmpxchg_long_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return (*func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   306
  int64_t old_value = *dest;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (old_value == compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   314
int32_t os::atomic_add_bootstrap(int32_t add_value, volatile int32_t* dest) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    os::atomic_add_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    return (*func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  return (*dest) += add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   327
int64_t os::atomic_add_long_bootstrap(int64_t add_value, volatile int64_t* dest) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // try to use the stub:
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   329
  add_long_func_t* func = CAST_TO_FN_PTR(add_long_func_t*, StubRoutines::atomic_add_long_entry());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  if (func != NULL) {
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   332
    os::atomic_add_long_func = func;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    return (*func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  return (*dest) += add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
xchg_func_t*         os::atomic_xchg_func         = os::atomic_xchg_bootstrap;
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   341
xchg_long_func_t*    os::atomic_xchg_long_func    = os::atomic_xchg_long_bootstrap;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
cmpxchg_func_t*      os::atomic_cmpxchg_func      = os::atomic_cmpxchg_bootstrap;
27691
733f189ad1f7 8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents: 26576
diff changeset
   343
cmpxchg_byte_func_t* os::atomic_cmpxchg_byte_func = os::atomic_cmpxchg_byte_bootstrap;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
add_func_t*          os::atomic_add_func          = os::atomic_add_bootstrap;
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47765
diff changeset
   345
add_long_func_t*     os::atomic_add_long_func     = os::atomic_add_long_bootstrap;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   351
#ifdef AMD64
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   352
/*
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   353
 * Windows/x64 does not use stack frames the way expected by Java:
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   354
 * [1] in most cases, there is no frame pointer. All locals are addressed via RSP
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   355
 * [2] in rare cases, when alloca() is used, a frame pointer is used, but this may
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   356
 *     not be RBP.
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   357
 * See http://msdn.microsoft.com/en-us/library/ew5tede7.aspx
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   358
 *
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   359
 * So it's not possible to print the native stack using the
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   360
 *     while (...) {...  fr = os::get_sender_for_C_frame(&fr); }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   361
 * loop in vmError.cpp. We need to roll our own loop.
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   362
 */
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   363
bool os::platform_print_native_stack(outputStream* st, const void* context,
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   364
                                     char *buf, int buf_size)
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   365
{
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   366
  CONTEXT ctx;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   367
  if (context != NULL) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   368
    memcpy(&ctx, context, sizeof(ctx));
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   369
  } else {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   370
    RtlCaptureContext(&ctx);
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   371
  }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   372
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   373
  st->print_cr("Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)");
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   374
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   375
  STACKFRAME stk;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   376
  memset(&stk, 0, sizeof(stk));
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   377
  stk.AddrStack.Offset    = ctx.Rsp;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   378
  stk.AddrStack.Mode      = AddrModeFlat;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   379
  stk.AddrFrame.Offset    = ctx.Rbp;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   380
  stk.AddrFrame.Mode      = AddrModeFlat;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   381
  stk.AddrPC.Offset       = ctx.Rip;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   382
  stk.AddrPC.Mode         = AddrModeFlat;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   383
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   384
  int count = 0;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   385
  address lastpc = 0;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   386
  while (count++ < StackPrintLimit) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   387
    intptr_t* sp = (intptr_t*)stk.AddrStack.Offset;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   388
    intptr_t* fp = (intptr_t*)stk.AddrFrame.Offset; // NOT necessarily the same as ctx.Rbp!
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   389
    address pc = (address)stk.AddrPC.Offset;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   390
46792
1f9002906ea9 8185706: [windows] Native callstacks printing terminates prematurely
stuefe
parents: 40384
diff changeset
   391
    if (pc != NULL) {
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   392
      if (count == 2 && lastpc == pc) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   393
        // Skip it -- StackWalk64() may return the same PC
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   394
        // (but different SP) on the first try.
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   395
      } else {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   396
        // Don't try to create a frame(sp, fp, pc) -- on WinX64, stk.AddrFrame
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   397
        // may not contain what Java expects, and may cause the frame() constructor
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   398
        // to crash. Let's just print out the symbolic address.
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   399
        frame::print_C_frame(st, buf, buf_size, pc);
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
   400
        // print source file and line, if available
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
   401
        char buf[128];
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
   402
        int line_no;
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
   403
        if (SymbolEngine::get_source_info(pc, buf, sizeof(buf), &line_no)) {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
   404
          st->print("  (%s:%d)", buf, line_no);
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47634
diff changeset
   405
        }
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   406
        st->cr();
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   407
      }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   408
      lastpc = pc;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   409
    }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   410
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46792
diff changeset
   411
    PVOID p = WindowsDbgHelp::symFunctionTableAccess64(GetCurrentProcess(), stk.AddrPC.Offset);
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   412
    if (!p) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   413
      // StackWalk64() can't handle this PC. Calling StackWalk64 again may cause crash.
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   414
      break;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   415
    }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   416
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46792
diff changeset
   417
    BOOL result = WindowsDbgHelp::stackWalk64(
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   418
        IMAGE_FILE_MACHINE_AMD64,  // __in      DWORD MachineType,
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   419
        GetCurrentProcess(),       // __in      HANDLE hProcess,
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   420
        GetCurrentThread(),        // __in      HANDLE hThread,
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   421
        &stk,                      // __inout   LP STACKFRAME64 StackFrame,
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46792
diff changeset
   422
        &ctx);                     // __inout   PVOID ContextRecord,
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   423
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   424
    if (!result) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   425
      break;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   426
    }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   427
  }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   428
  if (count > StackPrintLimit) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   429
    st->print_cr("...<more frames>...");
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   430
  }
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   431
  st->cr();
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   432
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   433
  return true;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   434
}
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   435
#endif // AMD64
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   436
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   437
ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                    intptr_t** ret_sp, intptr_t** ret_fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  ExtendedPC  epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  CONTEXT* uc = (CONTEXT*)ucVoid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  if (uc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    epc = ExtendedPC((address)uc->REG_PC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    if (ret_sp) *ret_sp = (intptr_t*)uc->REG_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    if (ret_fp) *ret_fp = (intptr_t*)uc->REG_FP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    // construct empty ExtendedPC for return value checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    epc = ExtendedPC(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    if (ret_sp) *ret_sp = (intptr_t *)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    if (ret_fp) *ret_fp = (intptr_t *)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  return epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   457
frame os::fetch_frame_from_context(const void* ucVoid) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  intptr_t* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  intptr_t* fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  return frame(sp, fp, epc.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
// VC++ does not save frame pointer on stack in optimized build. It
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
// can be turned off by /Oy-. If we really want to walk C frames,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
// we can use the StackWalk() API.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
frame os::get_sender_for_C_frame(frame* fr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   471
#ifndef AMD64
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   472
// Returns an estimate of the current stack pointer. Result must be guaranteed
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   473
// to point into the calling threads stack, and be no lower than the current
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   474
// stack pointer.
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   475
address os::current_stack_pointer() {
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   476
  int dummy;
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   477
  address sp = (address)&dummy;
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   478
  return sp;
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   479
}
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   480
#else
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   481
// Returns the current stack pointer. Accurate value needed for
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   482
// os::verify_stack_alignment().
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   483
address os::current_stack_pointer() {
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   484
  typedef address get_sp_func();
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   485
  get_sp_func* func = CAST_TO_FN_PTR(get_sp_func*,
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   486
                                     StubRoutines::x86::get_previous_sp_entry());
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   487
  return (*func)();
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   488
}
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   489
#endif
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   490
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
intptr_t* _get_previous_fp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  intptr_t **frameptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    mov frameptr, ebp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  };
40384
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   498
  // ebp (frameptr) 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
   499
  // 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
   500
  // 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
   501
  // 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
   502
#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
   503
  return **(intptr_t***)frameptr;
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   504
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  return *frameptr;
40384
43db0d4b6e14 8133740: NMT for Linux/x86/x64 and bsd/x64 slowdebug builds includes NativeCallStack::NativeCallStack() frame in backtrace
cjplummer
parents: 40010
diff changeset
   506
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
frame os::current_frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  // apparently _asm not supported on windows amd64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  typedef intptr_t*      get_fp_func           ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  get_fp_func* func = CAST_TO_FN_PTR(get_fp_func*,
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   516
                                     StubRoutines::x86::get_previous_fp_entry());
15468
4a274f843f41 8006508: Wrong frame constructor is called in os_linux_x86.cpp
dholmes
parents: 14633
diff changeset
   517
  if (func == NULL) return frame();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  intptr_t* fp = (*func)();
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   519
  if (fp == NULL) {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   520
    return frame();
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 18740
diff changeset
   521
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  intptr_t* fp = _get_previous_fp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  frame myframe((intptr_t*)os::current_stack_pointer(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
                (intptr_t*)fp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
                CAST_FROM_FN_PTR(address, os::current_frame));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  if (os::is_first_C_frame(&myframe)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    // stack is not walkable
15468
4a274f843f41 8006508: Wrong frame constructor is called in os_linux_x86.cpp
dholmes
parents: 14633
diff changeset
   531
    return frame();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    return os::get_sender_for_C_frame(&myframe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   537
void os::print_context(outputStream *st, const void *context) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  if (context == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   540
  const CONTEXT* uc = (const CONTEXT*)context;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  st->print_cr("Registers:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
#ifdef AMD64
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   544
  st->print(  "RAX=" INTPTR_FORMAT, uc->Rax);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   545
  st->print(", RBX=" INTPTR_FORMAT, uc->Rbx);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   546
  st->print(", RCX=" INTPTR_FORMAT, uc->Rcx);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   547
  st->print(", RDX=" INTPTR_FORMAT, uc->Rdx);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   548
  st->cr();
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   549
  st->print(  "RSP=" INTPTR_FORMAT, uc->Rsp);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   550
  st->print(", RBP=" INTPTR_FORMAT, uc->Rbp);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   551
  st->print(", RSI=" INTPTR_FORMAT, uc->Rsi);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   552
  st->print(", RDI=" INTPTR_FORMAT, uc->Rdi);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   553
  st->cr();
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   554
  st->print(  "R8 =" INTPTR_FORMAT, uc->R8);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   555
  st->print(", R9 =" INTPTR_FORMAT, uc->R9);
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   556
  st->print(", R10=" INTPTR_FORMAT, uc->R10);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   557
  st->print(", R11=" INTPTR_FORMAT, uc->R11);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   558
  st->cr();
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   559
  st->print(  "R12=" INTPTR_FORMAT, uc->R12);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   560
  st->print(", R13=" INTPTR_FORMAT, uc->R13);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   561
  st->print(", R14=" INTPTR_FORMAT, uc->R14);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   562
  st->print(", R15=" INTPTR_FORMAT, uc->R15);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   563
  st->cr();
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   564
  st->print(  "RIP=" INTPTR_FORMAT, uc->Rip);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   565
  st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  st->print(  "EAX=" INTPTR_FORMAT, uc->Eax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  st->print(", EBX=" INTPTR_FORMAT, uc->Ebx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  st->print(", ECX=" INTPTR_FORMAT, uc->Ecx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  st->print(", EDX=" INTPTR_FORMAT, uc->Edx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  st->print(  "ESP=" INTPTR_FORMAT, uc->Esp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  st->print(", EBP=" INTPTR_FORMAT, uc->Ebp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  st->print(", ESI=" INTPTR_FORMAT, uc->Esi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  st->print(", EDI=" INTPTR_FORMAT, uc->Edi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  st->print(  "EIP=" INTPTR_FORMAT, uc->Eip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  intptr_t *sp = (intptr_t *)uc->REG_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  // Note: it may be unsafe to inspect memory near pc. For example, pc may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // point to garbage if entry point in an nmethod is corrupted. Leave
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  // this at the end, and hope for the best.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  address pc = (address)uc->REG_PC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   593
  print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   594
  st->cr();
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   595
}
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   596
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   597
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   598
void os::print_register_info(outputStream *st, const void *context) {
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   599
  if (context == NULL) return;
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   600
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 34633
diff changeset
   601
  const CONTEXT* uc = (const CONTEXT*)context;
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   602
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   603
  st->print_cr("Register to memory mapping:");
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   604
  st->cr();
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   605
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   606
  // this is only for the "general purpose" registers
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   607
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   608
#ifdef AMD64
35903
049dfbdc3ced 8147510: [windows] no text locations shown for register info in hs-err file
stuefe
parents: 35077
diff changeset
   609
  st->print("RIP="); print_location(st, uc->Rip);
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   610
  st->print("RAX="); print_location(st, uc->Rax);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   611
  st->print("RBX="); print_location(st, uc->Rbx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   612
  st->print("RCX="); print_location(st, uc->Rcx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   613
  st->print("RDX="); print_location(st, uc->Rdx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   614
  st->print("RSP="); print_location(st, uc->Rsp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   615
  st->print("RBP="); print_location(st, uc->Rbp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   616
  st->print("RSI="); print_location(st, uc->Rsi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   617
  st->print("RDI="); print_location(st, uc->Rdi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   618
  st->print("R8 ="); print_location(st, uc->R8);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   619
  st->print("R9 ="); print_location(st, uc->R9);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   620
  st->print("R10="); print_location(st, uc->R10);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   621
  st->print("R11="); print_location(st, uc->R11);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   622
  st->print("R12="); print_location(st, uc->R12);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   623
  st->print("R13="); print_location(st, uc->R13);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   624
  st->print("R14="); print_location(st, uc->R14);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   625
  st->print("R15="); print_location(st, uc->R15);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   626
#else
35903
049dfbdc3ced 8147510: [windows] no text locations shown for register info in hs-err file
stuefe
parents: 35077
diff changeset
   627
  st->print("EIP="); print_location(st, uc->Eip);
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   628
  st->print("EAX="); print_location(st, uc->Eax);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   629
  st->print("EBX="); print_location(st, uc->Ebx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   630
  st->print("ECX="); print_location(st, uc->Ecx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   631
  st->print("EDX="); print_location(st, uc->Edx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   632
  st->print("ESP="); print_location(st, uc->Esp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   633
  st->print("EBP="); print_location(st, uc->Ebp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   634
  st->print("ESI="); print_location(st, uc->Esi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   635
  st->print("EDI="); print_location(st, uc->Edi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   636
#endif
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   637
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
extern "C" int SpinPause () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
   return 0 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
   // pause == rep:nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
   // On systems that don't support pause a rep:nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
   // is executed as a nop.  The rep: prefix is ignored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
   _asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      pause ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
   };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
   return 1 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
void os::setup_fpu() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  int fpu_cntrl_word = StubRoutines::fpu_cntrl_wrd_std();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  __asm fldcw fpu_cntrl_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
}
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   662
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   663
#ifndef PRODUCT
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   664
void os::verify_stack_alignment() {
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   665
#ifdef AMD64
27649
0e79b173cc5e 8054008: Using -XX:-LazyBootClassLoader crashes with ACCESS_VIOLATION on Win 64bit.
jiangli
parents: 26576
diff changeset
   666
  // The current_stack_pointer() calls generated get_previous_sp stub routine.
0e79b173cc5e 8054008: Using -XX:-LazyBootClassLoader crashes with ACCESS_VIOLATION on Win 64bit.
jiangli
parents: 26576
diff changeset
   667
  // Only enable the assert after the routine becomes available.
0e79b173cc5e 8054008: Using -XX:-LazyBootClassLoader crashes with ACCESS_VIOLATION on Win 64bit.
jiangli
parents: 26576
diff changeset
   668
  if (StubRoutines::code1() != NULL) {
0e79b173cc5e 8054008: Using -XX:-LazyBootClassLoader crashes with ACCESS_VIOLATION on Win 64bit.
jiangli
parents: 26576
diff changeset
   669
    assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
0e79b173cc5e 8054008: Using -XX:-LazyBootClassLoader crashes with ACCESS_VIOLATION on Win 64bit.
jiangli
parents: 26576
diff changeset
   670
  }
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   671
#endif
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   672
}
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 7405
diff changeset
   673
#endif
26576
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   674
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   675
int os::extra_bang_size_in_bytes() {
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   676
  // JDK-8050147 requires the full cache line bang for x86.
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   677
  return VM_Version::L1_line_size();
a9429d24d429 8050147: StoreLoad barrier interferes with stack usages
shade
parents: 22234
diff changeset
   678
}