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