hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp
author ikrylov
Wed, 01 Dec 2010 18:26:32 -0500
changeset 7405 e6fc8d3926f8
parent 7397 5b173b4ca846
child 11961 0abd4cd26e5a
permissions -rw-r--r--
6348631: remove the use of the HPI library from Hotspot Summary: move functions from hpi library to hotspot, communicate with licensees and open source community, check jdk for dependency, file CCC request Reviewed-by: coleenp, acorn, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6176
diff changeset
     2
 * Copyright (c) 1999, 2010, 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
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    26
#include "assembler_x86.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    27
#include "classfile/classLoader.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    28
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    29
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    30
#include "code/icBuffer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    31
#include "code/vtableStubs.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    32
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    33
#include "jvm_windows.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    34
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    35
#include "mutex_windows.inline.hpp"
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.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    40
#include "prims/jvm_misc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    41
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    42
#include "runtime/extendedPC.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    43
#include "runtime/frame.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    44
#include "runtime/interfaceSupport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    45
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    46
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    47
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    48
#include "runtime/osThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    49
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    50
#include "runtime/stubRoutines.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    51
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    52
#include "thread_windows.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    53
#include "utilities/events.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    54
#include "utilities/vmError.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    55
#ifdef COMPILER1
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    56
#include "c1/c1_Runtime1.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    57
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    58
#ifdef COMPILER2
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    59
#include "opto/runtime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    60
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    61
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
# include "unwind_windows_x86.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
#undef REG_SP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#undef REG_FP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
#undef REG_PC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
#define REG_SP Rsp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
#define REG_FP Rbp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
#define REG_PC Rip
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
#define REG_SP Esp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
#define REG_FP Ebp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
#define REG_PC Eip
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// Install a win32 structured exception handler around thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  __try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // We store the current thread in this wrapperthread location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // and determine how far away this address is from the structured
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // execption pointer that FS:[0] points to.  This get_thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    // code can then get the thread pointer via FS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    // Warning:  This routine must NEVER be inlined since we'd end up with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    //           multiple offsets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    volatile Thread* wrapperthread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    if ( ThreadLocalStorage::get_thread_ptr_offset() == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      int thread_ptr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
        lea eax, dword ptr wrapperthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        sub eax, dword ptr FS:[0H];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        mov thread_ptr_offset, eax
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      ThreadLocalStorage::set_thread_ptr_offset(thread_ptr_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    // Verify that the offset hasn't changed since we initally captured
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // it. This might happen if we accidentally ended up with an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    // inlined version of this routine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      int test_thread_ptr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        lea eax, dword ptr wrapperthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        sub eax, dword ptr FS:[0H];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        mov test_thread_ptr_offset, eax
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      assert(test_thread_ptr_offset == ThreadLocalStorage::get_thread_ptr_offset(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
             "thread pointer offset from SEH changed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    f(value, method, args, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// This is the language specific handler for exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// originating from dynamically generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// We call the standard structured exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// We only expect Continued Execution since we cannot unwind
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// from generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
LONG HandleExceptionFromCodeCache(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  IN PEXCEPTION_RECORD ExceptionRecord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  IN ULONG64 EstablisherFrame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  IN OUT PCONTEXT ContextRecord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  IN OUT PDISPATCHER_CONTEXT DispatcherContext) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  EXCEPTION_POINTERS ep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  LONG result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  ep.ExceptionRecord = ExceptionRecord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  ep.ContextRecord = ContextRecord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  result = topLevelExceptionFilter(&ep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // We better only get a CONTINUE_EXECUTION from our handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // since we don't have unwind information registered.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  guarantee( result == EXCEPTION_CONTINUE_EXECUTION,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
             "Unexpected result from topLevelExceptionFilter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  return(ExceptionContinueExecution);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// Structure containing the Windows Data Structures required
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// to register our Code Cache exception handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// We put these in the CodeCache since the API requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// all addresses in these structures are relative to the Code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// area registered with RtlAddFunctionTable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
typedef struct {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  char ExceptionHandlerInstr[16];  // jmp HandleExceptionFromCodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  RUNTIME_FUNCTION rt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  UNWIND_INFO_EH_ONLY unw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
} DynamicCodeData, *pDynamicCodeData;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// Register our CodeCache area with the OS so it will dispatch exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// to our topLevelExceptionFilter when we take an exception in our
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// dynamically generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// Arguments:  low and high are the address of the full reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// codeCache area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
bool os::register_code_area(char *low, char *high) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  pDynamicCodeData pDCD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  PRUNTIME_FUNCTION prt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  PUNWIND_INFO_EH_ONLY punwind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // If we are using Vectored Exceptions we don't need this registration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  if (UseVectoredExceptions) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6176
diff changeset
   187
  BufferBlob* blob = BufferBlob::create("CodeCache Exception Handler", sizeof(DynamicCodeData));
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 6176
diff changeset
   188
  CodeBuffer cb(blob);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  MacroAssembler* masm = new MacroAssembler(&cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  pDCD = (pDynamicCodeData) masm->pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  masm->jump(ExternalAddress((address)&HandleExceptionFromCodeCache));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  masm->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // Create an Unwind Structure specifying no unwind info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // other than an Exception Handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  punwind = &pDCD->unw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  punwind->Version = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  punwind->Flags = UNW_FLAG_EHANDLER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  punwind->SizeOfProlog = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  punwind->CountOfCodes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  punwind->FrameRegister = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  punwind->FrameOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  punwind->ExceptionHandler = (char *)(&(pDCD->ExceptionHandlerInstr[0])) -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                              (char*)low;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  punwind->ExceptionData[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // This structure describes the covered dynamic code area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // Addresses are relative to the beginning on the code cache area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  prt = &pDCD->rt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  prt->BeginAddress = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  prt->EndAddress = (ULONG)(high - low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  prt->UnwindData = ((char *)punwind - low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  guarantee(RtlAddFunctionTable(prt, 1, (ULONGLONG)low),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
            "Failed to register Dynamic Code Exception Handler with RtlAddFunctionTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
void os::initialize_thread() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// Atomics and Stub Functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
typedef jint      xchg_func_t            (jint,     volatile jint*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
typedef intptr_t  xchg_ptr_func_t        (intptr_t, volatile intptr_t*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
typedef jint      cmpxchg_func_t         (jint,     volatile jint*,  jint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
typedef jlong     cmpxchg_long_func_t    (jlong,    volatile jlong*, jlong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
typedef jint      add_func_t             (jint,     volatile jint*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
typedef intptr_t  add_ptr_func_t         (intptr_t, volatile intptr_t*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    os::atomic_xchg_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    return (*func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  jint old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
intptr_t os::atomic_xchg_ptr_bootstrap(intptr_t exchange_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  xchg_ptr_func_t* func = CAST_TO_FN_PTR(xchg_ptr_func_t*, StubRoutines::atomic_xchg_ptr_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    os::atomic_xchg_ptr_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    return (*func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  intptr_t old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    os::atomic_cmpxchg_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    return (*func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  jint old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  if (old_value == compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  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
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    os::atomic_cmpxchg_long_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    return (*func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  jlong old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  if (old_value == compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    os::atomic_add_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    return (*func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  return (*dest) += add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
intptr_t os::atomic_add_ptr_bootstrap(intptr_t add_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  add_ptr_func_t* func = CAST_TO_FN_PTR(add_ptr_func_t*, StubRoutines::atomic_add_ptr_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    os::atomic_add_ptr_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    return (*func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  return (*dest) += add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
xchg_func_t*         os::atomic_xchg_func         = os::atomic_xchg_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
xchg_ptr_func_t*     os::atomic_xchg_ptr_func     = os::atomic_xchg_ptr_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
cmpxchg_func_t*      os::atomic_cmpxchg_func      = os::atomic_cmpxchg_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
add_func_t*          os::atomic_add_func          = os::atomic_add_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
add_ptr_func_t*      os::atomic_add_ptr_func      = os::atomic_add_ptr_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
ExtendedPC os::fetch_frame_from_context(void* ucVoid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
                    intptr_t** ret_sp, intptr_t** ret_fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  ExtendedPC  epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  CONTEXT* uc = (CONTEXT*)ucVoid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if (uc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    epc = ExtendedPC((address)uc->REG_PC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    if (ret_sp) *ret_sp = (intptr_t*)uc->REG_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    if (ret_fp) *ret_fp = (intptr_t*)uc->REG_FP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    // construct empty ExtendedPC for return value checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    epc = ExtendedPC(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    if (ret_sp) *ret_sp = (intptr_t *)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    if (ret_fp) *ret_fp = (intptr_t *)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  return epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
frame os::fetch_frame_from_context(void* ucVoid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  intptr_t* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  intptr_t* fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  return frame(sp, fp, epc.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
// VC++ does not save frame pointer on stack in optimized build. It
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// can be turned off by /Oy-. If we really want to walk C frames,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
// we can use the StackWalk() API.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
frame os::get_sender_for_C_frame(frame* fr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
intptr_t* _get_previous_fp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  intptr_t **frameptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    mov frameptr, ebp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  return *frameptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
frame os::current_frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // apparently _asm not supported on windows amd64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  typedef intptr_t*      get_fp_func           ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  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
   390
                                     StubRoutines::x86::get_previous_fp_entry());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  if (func == NULL) return frame(NULL, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  intptr_t* fp = (*func)();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  intptr_t* fp = _get_previous_fp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  frame myframe((intptr_t*)os::current_stack_pointer(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
                (intptr_t*)fp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
                CAST_FROM_FN_PTR(address, os::current_frame));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  if (os::is_first_C_frame(&myframe)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    // stack is not walkable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    return frame(NULL, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    return os::get_sender_for_C_frame(&myframe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
void os::print_context(outputStream *st, void *context) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  if (context == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  CONTEXT* uc = (CONTEXT*)context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  st->print_cr("Registers:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
#ifdef AMD64
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   415
  st->print(  "RAX=" INTPTR_FORMAT, uc->Rax);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   416
  st->print(", RBX=" INTPTR_FORMAT, uc->Rbx);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   417
  st->print(", RCX=" INTPTR_FORMAT, uc->Rcx);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   418
  st->print(", RDX=" INTPTR_FORMAT, uc->Rdx);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   419
  st->cr();
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   420
  st->print(  "RSP=" INTPTR_FORMAT, uc->Rsp);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   421
  st->print(", RBP=" INTPTR_FORMAT, uc->Rbp);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   422
  st->print(", RSI=" INTPTR_FORMAT, uc->Rsi);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   423
  st->print(", RDI=" INTPTR_FORMAT, uc->Rdi);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   424
  st->cr();
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   425
  st->print(  "R8 =" INTPTR_FORMAT, uc->R8);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   426
  st->print(", R9 =" INTPTR_FORMAT, uc->R9);
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   427
  st->print(", R10=" INTPTR_FORMAT, uc->R10);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   428
  st->print(", R11=" INTPTR_FORMAT, uc->R11);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   429
  st->cr();
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   430
  st->print(  "R12=" INTPTR_FORMAT, uc->R12);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   431
  st->print(", R13=" INTPTR_FORMAT, uc->R13);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   432
  st->print(", R14=" INTPTR_FORMAT, uc->R14);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   433
  st->print(", R15=" INTPTR_FORMAT, uc->R15);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   434
  st->cr();
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   435
  st->print(  "RIP=" INTPTR_FORMAT, uc->Rip);
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5547
diff changeset
   436
  st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  st->print(  "EAX=" INTPTR_FORMAT, uc->Eax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  st->print(", EBX=" INTPTR_FORMAT, uc->Ebx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  st->print(", ECX=" INTPTR_FORMAT, uc->Ecx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  st->print(", EDX=" INTPTR_FORMAT, uc->Edx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  st->print(  "ESP=" INTPTR_FORMAT, uc->Esp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  st->print(", EBP=" INTPTR_FORMAT, uc->Ebp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  st->print(", ESI=" INTPTR_FORMAT, uc->Esi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  st->print(", EDI=" INTPTR_FORMAT, uc->Edi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  st->print(  "EIP=" INTPTR_FORMAT, uc->Eip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  intptr_t *sp = (intptr_t *)uc->REG_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  // Note: it may be unsafe to inspect memory near pc. For example, pc may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // point to garbage if entry point in an nmethod is corrupted. Leave
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // this at the end, and hope for the best.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  address pc = (address)uc->REG_PC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   464
  print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   465
  st->cr();
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   466
}
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   467
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   468
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   469
void os::print_register_info(outputStream *st, void *context) {
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   470
  if (context == NULL) return;
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   471
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   472
  CONTEXT* uc = (CONTEXT*)context;
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   473
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   474
  st->print_cr("Register to memory mapping:");
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   475
  st->cr();
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   476
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   477
  // this is only for the "general purpose" registers
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   478
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   479
#ifdef AMD64
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   480
  st->print("RAX="); print_location(st, uc->Rax);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   481
  st->print("RBX="); print_location(st, uc->Rbx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   482
  st->print("RCX="); print_location(st, uc->Rcx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   483
  st->print("RDX="); print_location(st, uc->Rdx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   484
  st->print("RSP="); print_location(st, uc->Rsp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   485
  st->print("RBP="); print_location(st, uc->Rbp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   486
  st->print("RSI="); print_location(st, uc->Rsi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   487
  st->print("RDI="); print_location(st, uc->Rdi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   488
  st->print("R8 ="); print_location(st, uc->R8);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   489
  st->print("R9 ="); print_location(st, uc->R9);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   490
  st->print("R10="); print_location(st, uc->R10);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   491
  st->print("R11="); print_location(st, uc->R11);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   492
  st->print("R12="); print_location(st, uc->R12);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   493
  st->print("R13="); print_location(st, uc->R13);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   494
  st->print("R14="); print_location(st, uc->R14);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   495
  st->print("R15="); print_location(st, uc->R15);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   496
#else
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   497
  st->print("EAX="); print_location(st, uc->Eax);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   498
  st->print("EBX="); print_location(st, uc->Ebx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   499
  st->print("ECX="); print_location(st, uc->Ecx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   500
  st->print("EDX="); print_location(st, uc->Edx);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   501
  st->print("ESP="); print_location(st, uc->Esp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   502
  st->print("EBP="); print_location(st, uc->Ebp);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   503
  st->print("ESI="); print_location(st, uc->Esi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   504
  st->print("EDI="); print_location(st, uc->Edi);
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   505
#endif
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
   506
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
extern "C" int SafeFetch32 (int * adr, int Err) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
   int rv = Err ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
   _try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
       rv = *((volatile int *) adr) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
   } __except(EXCEPTION_EXECUTE_HANDLER) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
   return rv ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
extern "C" intptr_t SafeFetchN (intptr_t * adr, intptr_t Err) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
   intptr_t rv = Err ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
   _try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
       rv = *((volatile intptr_t *) adr) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
   } __except(EXCEPTION_EXECUTE_HANDLER) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
   return rv ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
extern "C" int SpinPause () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
   return 0 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
   // pause == rep:nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
   // On systems that don't support pause a rep:nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
   // is executed as a nop.  The rep: prefix is ignored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
   _asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      pause ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
   };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
   return 1 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
void os::setup_fpu() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  int fpu_cntrl_word = StubRoutines::fpu_cntrl_wrd_std();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  __asm fldcw fpu_cntrl_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
}