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