hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp
author martin
Mon, 10 Mar 2008 23:23:47 -0700
changeset 58 55e9cd9ade0b
parent 1 489c9b5090e2
child 1066 717c3345024f
permissions -rw-r--r--
6612102: (coll) IdentityHashMap.iterator().remove() might decrement size twice Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// do not include  precompiled  header file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_os_windows_x86.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
# include "unwind_windows_x86.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#undef REG_SP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#undef REG_FP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#undef REG_PC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
#define REG_SP Rsp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
#define REG_FP Rbp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#define REG_PC Rip
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
#define REG_SP Esp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#define REG_FP Ebp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
#define REG_PC Eip
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// Install a win32 structured exception handler around thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  __try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    // We store the current thread in this wrapperthread location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    // and determine how far away this address is from the structured
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    // execption pointer that FS:[0] points to.  This get_thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    // code can then get the thread pointer via FS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // Warning:  This routine must NEVER be inlined since we'd end up with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    //           multiple offsets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    volatile Thread* wrapperthread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if ( ThreadLocalStorage::get_thread_ptr_offset() == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      int thread_ptr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
        lea eax, dword ptr wrapperthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
        sub eax, dword ptr FS:[0H];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        mov thread_ptr_offset, eax
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      ThreadLocalStorage::set_thread_ptr_offset(thread_ptr_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    // Verify that the offset hasn't changed since we initally captured
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    // it. This might happen if we accidentally ended up with an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    // inlined version of this routine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      int test_thread_ptr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        lea eax, dword ptr wrapperthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        sub eax, dword ptr FS:[0H];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        mov test_thread_ptr_offset, eax
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      assert(test_thread_ptr_offset == ThreadLocalStorage::get_thread_ptr_offset(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
             "thread pointer offset from SEH changed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    f(value, method, args, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// This is the language specific handler for exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// originating from dynamically generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// We call the standard structured exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// We only expect Continued Execution since we cannot unwind
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// from generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
LONG HandleExceptionFromCodeCache(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  IN PEXCEPTION_RECORD ExceptionRecord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  IN ULONG64 EstablisherFrame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  IN OUT PCONTEXT ContextRecord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  IN OUT PDISPATCHER_CONTEXT DispatcherContext) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  EXCEPTION_POINTERS ep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  LONG result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ep.ExceptionRecord = ExceptionRecord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  ep.ContextRecord = ContextRecord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  result = topLevelExceptionFilter(&ep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // We better only get a CONTINUE_EXECUTION from our handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // since we don't have unwind information registered.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  guarantee( result == EXCEPTION_CONTINUE_EXECUTION,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
             "Unexpected result from topLevelExceptionFilter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  return(ExceptionContinueExecution);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Structure containing the Windows Data Structures required
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// to register our Code Cache exception handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// We put these in the CodeCache since the API requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// all addresses in these structures are relative to the Code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// area registered with RtlAddFunctionTable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
typedef struct {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  char ExceptionHandlerInstr[16];  // jmp HandleExceptionFromCodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  RUNTIME_FUNCTION rt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  UNWIND_INFO_EH_ONLY unw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
} DynamicCodeData, *pDynamicCodeData;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// Register our CodeCache area with the OS so it will dispatch exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// to our topLevelExceptionFilter when we take an exception in our
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// dynamically generated code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// Arguments:  low and high are the address of the full reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
// codeCache area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
bool os::register_code_area(char *low, char *high) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  pDynamicCodeData pDCD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  PRUNTIME_FUNCTION prt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  PUNWIND_INFO_EH_ONLY punwind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // If we are using Vectored Exceptions we don't need this registration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  if (UseVectoredExceptions) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  BufferBlob* b = BufferBlob::create("CodeCache Exception Handler", sizeof (DynamicCodeData));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  CodeBuffer cb(b->instructions_begin(), b->instructions_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  MacroAssembler* masm = new MacroAssembler(&cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  pDCD = (pDynamicCodeData) masm->pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  masm->jump(ExternalAddress((address)&HandleExceptionFromCodeCache));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  masm->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Create an Unwind Structure specifying no unwind info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // other than an Exception Handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  punwind = &pDCD->unw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  punwind->Version = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  punwind->Flags = UNW_FLAG_EHANDLER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  punwind->SizeOfProlog = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  punwind->CountOfCodes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  punwind->FrameRegister = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  punwind->FrameOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  punwind->ExceptionHandler = (char *)(&(pDCD->ExceptionHandlerInstr[0])) -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
                              (char*)low;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  punwind->ExceptionData[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // This structure describes the covered dynamic code area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Addresses are relative to the beginning on the code cache area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  prt = &pDCD->rt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  prt->BeginAddress = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  prt->EndAddress = (ULONG)(high - low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  prt->UnwindData = ((char *)punwind - low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  guarantee(RtlAddFunctionTable(prt, 1, (ULONGLONG)low),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
            "Failed to register Dynamic Code Exception Handler with RtlAddFunctionTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
void os::initialize_thread() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// Atomics and Stub Functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
typedef jint      xchg_func_t            (jint,     volatile jint*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
typedef intptr_t  xchg_ptr_func_t        (intptr_t, volatile intptr_t*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
typedef jint      cmpxchg_func_t         (jint,     volatile jint*,  jint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
typedef jlong     cmpxchg_long_func_t    (jlong,    volatile jlong*, jlong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
typedef jint      add_func_t             (jint,     volatile jint*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
typedef intptr_t  add_ptr_func_t         (intptr_t, volatile intptr_t*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
typedef void      fence_func_t           ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    os::atomic_xchg_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    return (*func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  jint old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
intptr_t os::atomic_xchg_ptr_bootstrap(intptr_t exchange_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  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
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    os::atomic_xchg_ptr_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    return (*func)(exchange_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  intptr_t old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    os::atomic_cmpxchg_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    return (*func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  jint old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (old_value == compare_value)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    *dest = exchange_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  return old_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  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
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    os::atomic_cmpxchg_long_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    return (*func)(exchange_value, dest, compare_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  jlong old_value = *dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  if (old_value == compare_value)
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
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    os::atomic_add_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    return (*func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  return (*dest) += add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
intptr_t os::atomic_add_ptr_bootstrap(intptr_t add_value, volatile intptr_t* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  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
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    os::atomic_add_ptr_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    return (*func)(add_value, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  assert(Threads::number_of_threads() == 0, "for bootstrap only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  return (*dest) += add_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
void os::fence_bootstrap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // try to use the stub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  fence_func_t* func = CAST_TO_FN_PTR(fence_func_t*, StubRoutines::fence_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  if (func != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    os::fence_func = func;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    (*func)();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return;
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // don't have to do anything for a single thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
xchg_func_t*         os::atomic_xchg_func         = os::atomic_xchg_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
xchg_ptr_func_t*     os::atomic_xchg_ptr_func     = os::atomic_xchg_ptr_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
cmpxchg_func_t*      os::atomic_cmpxchg_func      = os::atomic_cmpxchg_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
add_func_t*          os::atomic_add_func          = os::atomic_add_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
add_ptr_func_t*      os::atomic_add_ptr_func      = os::atomic_add_ptr_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
fence_func_t*        os::fence_func               = os::fence_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
ExtendedPC os::fetch_frame_from_context(void* ucVoid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
                    intptr_t** ret_sp, intptr_t** ret_fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  ExtendedPC  epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  CONTEXT* uc = (CONTEXT*)ucVoid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  if (uc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    epc = ExtendedPC((address)uc->REG_PC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    if (ret_sp) *ret_sp = (intptr_t*)uc->REG_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    if (ret_fp) *ret_fp = (intptr_t*)uc->REG_FP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    // construct empty ExtendedPC for return value checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    epc = ExtendedPC(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    if (ret_sp) *ret_sp = (intptr_t *)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    if (ret_fp) *ret_fp = (intptr_t *)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  return epc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
frame os::fetch_frame_from_context(void* ucVoid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  intptr_t* sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  intptr_t* fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  return frame(sp, fp, epc.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
// VC++ does not save frame pointer on stack in optimized build. It
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
// can be turned off by /Oy-. If we really want to walk C frames,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
// we can use the StackWalk() API.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
frame os::get_sender_for_C_frame(frame* fr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
intptr_t* _get_previous_fp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  intptr_t **frameptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    mov frameptr, ebp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  return *frameptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
frame os::current_frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  // apparently _asm not supported on windows amd64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  typedef intptr_t*      get_fp_func           ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  get_fp_func* func = CAST_TO_FN_PTR(get_fp_func*,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                                     StubRoutines::amd64::get_previous_fp_entry());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  if (func == NULL) return frame(NULL, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  intptr_t* fp = (*func)();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  intptr_t* fp = _get_previous_fp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  frame myframe((intptr_t*)os::current_stack_pointer(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                (intptr_t*)fp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                CAST_FROM_FN_PTR(address, os::current_frame));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  if (os::is_first_C_frame(&myframe)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    // stack is not walkable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    return frame(NULL, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    return os::get_sender_for_C_frame(&myframe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
void os::print_context(outputStream *st, void *context) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  if (context == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  CONTEXT* uc = (CONTEXT*)context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  st->print_cr("Registers:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  st->print(  "EAX=" INTPTR_FORMAT, uc->Rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  st->print(", EBX=" INTPTR_FORMAT, uc->Rbx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  st->print(", ECX=" INTPTR_FORMAT, uc->Rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  st->print(", EDX=" INTPTR_FORMAT, uc->Rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  st->print(  "ESP=" INTPTR_FORMAT, uc->Rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  st->print(", EBP=" INTPTR_FORMAT, uc->Rbp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  st->print(", ESI=" INTPTR_FORMAT, uc->Rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  st->print(", EDI=" INTPTR_FORMAT, uc->Rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  st->print(  "EIP=" INTPTR_FORMAT, uc->Rip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  st->print(  "EAX=" INTPTR_FORMAT, uc->Eax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  st->print(", EBX=" INTPTR_FORMAT, uc->Ebx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  st->print(", ECX=" INTPTR_FORMAT, uc->Ecx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  st->print(", EDX=" INTPTR_FORMAT, uc->Edx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  st->print(  "ESP=" INTPTR_FORMAT, uc->Esp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  st->print(", EBP=" INTPTR_FORMAT, uc->Ebp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  st->print(", ESI=" INTPTR_FORMAT, uc->Esi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  st->print(", EDI=" INTPTR_FORMAT, uc->Edi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  st->print(  "EIP=" INTPTR_FORMAT, uc->Eip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  st->print(", EFLAGS=" INTPTR_FORMAT, uc->EFlags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  intptr_t *sp = (intptr_t *)uc->REG_SP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  // Note: it may be unsafe to inspect memory near pc. For example, pc may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // point to garbage if entry point in an nmethod is corrupted. Leave
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // this at the end, and hope for the best.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  address pc = (address)uc->REG_PC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  print_hex_dump(st, pc - 16, pc + 16, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
extern "C" int SafeFetch32 (int * adr, int Err) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
   int rv = Err ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
   _try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
       rv = *((volatile int *) adr) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
   } __except(EXCEPTION_EXECUTE_HANDLER) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
   return rv ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
extern "C" intptr_t SafeFetchN (intptr_t * adr, intptr_t Err) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
   intptr_t rv = Err ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
   _try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
       rv = *((volatile intptr_t *) adr) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
   } __except(EXCEPTION_EXECUTE_HANDLER) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
   return rv ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
extern "C" int SpinPause () {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
   return 0 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
   // pause == rep:nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
   // On systems that don't support pause a rep:nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
   // is executed as a nop.  The rep: prefix is ignored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
   _asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      pause ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
   };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
   return 1 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
void os::setup_fpu() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
#ifndef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  int fpu_cntrl_word = StubRoutines::fpu_cntrl_wrd_std();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  __asm fldcw fpu_cntrl_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
#endif // !AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
}