1 /* 2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 // no precompiled headers 27 #include "jvm.h" 28 #include "asm/macroAssembler.hpp" 29 #include "classfile/classLoader.hpp" 30 #include "classfile/systemDictionary.hpp" 31 #include "classfile/vmSymbols.hpp" 32 #include "code/codeCache.hpp" 33 #include "code/icBuffer.hpp" 34 #include "code/vtableStubs.hpp" 35 #include "code/nativeInst.hpp" 36 #include "interpreter/interpreter.hpp" 37 #include "memory/allocation.inline.hpp" 38 #include "os_share_linux.hpp" 39 #include "prims/jniFastGetField.hpp" 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.inline.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 "utilities/debug.hpp" 54 #include "utilities/events.hpp" 55 #include "utilities/vmError.hpp" 56 #ifdef BUILTIN_SIM 57 #include "../../../../../../simulator/simulator.hpp" 58 #endif 59 60 // put OS-includes here 61 # include <sys/types.h> 62 # include <sys/mman.h> 63 # include <pthread.h> 64 # include <signal.h> 65 # include <errno.h> 66 # include <dlfcn.h> 67 # include <stdlib.h> 68 # include <stdio.h> 69 # include <unistd.h> 70 # include <sys/resource.h> 71 # include <pthread.h> 72 # include <sys/stat.h> 73 # include <sys/time.h> 74 # include <sys/utsname.h> 75 # include <sys/socket.h> 76 # include <sys/wait.h> 77 # include <pwd.h> 78 # include <poll.h> 79 # include <ucontext.h> 80 # include <fpu_control.h> 81 82 #ifdef BUILTIN_SIM 83 #define REG_SP REG_RSP 84 #define REG_PC REG_RIP 85 #define REG_FP REG_RBP 86 #define SPELL_REG_SP "rsp" 87 #define SPELL_REG_FP "rbp" 88 #else 89 #define REG_FP 29 90 #define REG_LR 30 91 92 #define SPELL_REG_SP "sp" 93 #define SPELL_REG_FP "x29" 94 #endif 95 96 address os::current_stack_pointer() { 97 register void *esp __asm__ (SPELL_REG_SP); 98 return (address) esp; 99 } 100 101 char* os::non_memory_address_word() { 102 // Must never look like an address returned by reserve_memory, 103 // even in its subfields (as defined by the CPU immediate fields, 104 // if the CPU splits constants across multiple instructions). 105 106 return (char*) 0xffffffffffff; 107 } 108 109 address os::Linux::ucontext_get_pc(const ucontext_t * uc) { 110 #ifdef BUILTIN_SIM 111 return (address)uc->uc_mcontext.gregs[REG_PC]; 112 #else 113 return (address)uc->uc_mcontext.pc; 114 #endif 115 } 116 117 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) { 118 #ifdef BUILTIN_SIM 119 uc->uc_mcontext.gregs[REG_PC] = (intptr_t)pc; 120 #else 121 uc->uc_mcontext.pc = (intptr_t)pc; 122 #endif 123 } 124 125 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) { 126 #ifdef BUILTIN_SIM 127 return (intptr_t*)uc->uc_mcontext.gregs[REG_SP]; 128 #else 129 return (intptr_t*)uc->uc_mcontext.sp; 130 #endif 131 } 132 133 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) { 134 #ifdef BUILTIN_SIM 135 return (intptr_t*)uc->uc_mcontext.gregs[REG_FP]; 136 #else 137 return (intptr_t*)uc->uc_mcontext.regs[REG_FP]; 138 #endif 139 } 140 141 // For Forte Analyzer AsyncGetCallTrace profiling support - thread 142 // is currently interrupted by SIGPROF. 143 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal 144 // frames. Currently we don't do that on Linux, so it's the same as 145 // os::fetch_frame_from_context(). 146 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, 147 const ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { 148 149 assert(thread != NULL, "just checking"); 150 assert(ret_sp != NULL, "just checking"); 151 assert(ret_fp != NULL, "just checking"); 152 153 return os::fetch_frame_from_context(uc, ret_sp, ret_fp); 154 } 155 156 ExtendedPC os::fetch_frame_from_context(const void* ucVoid, 157 intptr_t** ret_sp, intptr_t** ret_fp) { 158 159 ExtendedPC epc; 160 const ucontext_t* uc = (const ucontext_t*)ucVoid; 161 162 if (uc != NULL) { 163 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); 164 if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc); 165 if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc); 166 } else { 167 // construct empty ExtendedPC for return value checking 168 epc = ExtendedPC(NULL); 169 if (ret_sp) *ret_sp = (intptr_t *)NULL; 170 if (ret_fp) *ret_fp = (intptr_t *)NULL; 171 } 172 173 return epc; 174 } 175 176 frame os::fetch_frame_from_context(const void* ucVoid) { 177 intptr_t* sp; 178 intptr_t* fp; 179 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); 180 return frame(sp, fp, epc.pc()); 181 } 182 183 bool os::Linux::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) { 184 address pc = (address) os::Linux::ucontext_get_pc(uc); 185 if (Interpreter::contains(pc)) { 186 // interpreter performs stack banging after the fixed frame header has 187 // been generated while the compilers perform it before. To maintain 188 // semantic consistency between interpreted and compiled frames, the 189 // method returns the Java sender of the current frame. 190 *fr = os::fetch_frame_from_context(uc); 191 if (!fr->is_first_java_frame()) { 192 assert(fr->safe_for_sender(thread), "Safety check"); 193 *fr = fr->java_sender(); 194 } 195 } else { 196 // more complex code with compiled code 197 assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above"); 198 CodeBlob* cb = CodeCache::find_blob(pc); 199 if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) { 200 // Not sure where the pc points to, fallback to default 201 // stack overflow handling 202 return false; 203 } else { 204 // In compiled code, the stack banging is performed before LR 205 // has been saved in the frame. LR is live, and SP and FP 206 // belong to the caller. 207 intptr_t* fp = os::Linux::ucontext_get_fp(uc); 208 intptr_t* sp = os::Linux::ucontext_get_sp(uc); 209 address pc = (address)(uc->uc_mcontext.regs[REG_LR] 210 - NativeInstruction::instruction_size); 211 *fr = frame(sp, fp, pc); 212 if (!fr->is_java_frame()) { 213 assert(fr->safe_for_sender(thread), "Safety check"); 214 assert(!fr->is_first_frame(), "Safety check"); 215 *fr = fr->java_sender(); 216 } 217 } 218 } 219 assert(fr->is_java_frame(), "Safety check"); 220 return true; 221 } 222 223 // By default, gcc always saves frame pointer rfp on this stack. This 224 // may get turned off by -fomit-frame-pointer. 225 frame os::get_sender_for_C_frame(frame* fr) { 226 #ifdef BUILTIN_SIM 227 return frame(fr->sender_sp(), fr->link(), fr->sender_pc()); 228 #else 229 return frame(fr->link(), fr->link(), fr->sender_pc()); 230 #endif 231 } 232 233 intptr_t* _get_previous_fp() { 234 register intptr_t **fp __asm__ (SPELL_REG_FP); 235 236 // fp is for this frame (_get_previous_fp). We want the fp for the 237 // caller of os::current_frame*(), so go up two frames. However, for 238 // optimized builds, _get_previous_fp() will be inlined, so only go 239 // up 1 frame in that case. 240 #ifdef _NMT_NOINLINE_ 241 return **(intptr_t***)fp; 242 #else 243 return *fp; 244 #endif 245 } 246 247 248 frame os::current_frame() { 249 intptr_t* fp = _get_previous_fp(); 250 frame myframe((intptr_t*)os::current_stack_pointer(), 251 (intptr_t*)fp, 252 CAST_FROM_FN_PTR(address, os::current_frame)); 253 if (os::is_first_C_frame(&myframe)) { 254 // stack is not walkable 255 return frame(); 256 } else { 257 return os::get_sender_for_C_frame(&myframe); 258 } 259 } 260 261 // Utility functions 262 263 // From IA32 System Programming Guide 264 enum { 265 trap_page_fault = 0xE 266 }; 267 268 #ifdef BUILTIN_SIM 269 extern "C" void Fetch32PFI () ; 270 extern "C" void Fetch32Resume () ; 271 extern "C" void FetchNPFI () ; 272 extern "C" void FetchNResume () ; 273 #endif 274 275 extern "C" JNIEXPORT int 276 JVM_handle_linux_signal(int sig, 277 siginfo_t* info, 278 void* ucVoid, 279 int abort_if_unrecognized) { 280 ucontext_t* uc = (ucontext_t*) ucVoid; 281 282 Thread* t = Thread::current_or_null_safe(); 283 284 // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away 285 // (no destructors can be run) 286 os::ThreadCrashProtection::check_crash_protection(sig, t); 287 288 SignalHandlerMark shm(t); 289 290 // Note: it's not uncommon that JNI code uses signal/sigset to install 291 // then restore certain signal handler (e.g. to temporarily block SIGPIPE, 292 // or have a SIGILL handler when detecting CPU type). When that happens, 293 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To 294 // avoid unnecessary crash when libjsig is not preloaded, try handle signals 295 // that do not require siginfo/ucontext first. 296 297 if (sig == SIGPIPE || sig == SIGXFSZ) { 298 // allow chained handler to go first 299 if (os::Linux::chained_handler(sig, info, ucVoid)) { 300 return true; 301 } else { 302 // Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219 303 return true; 304 } 305 } 306 307 #ifdef CAN_SHOW_REGISTERS_ON_ASSERT 308 if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) { 309 handle_assert_poison_fault(ucVoid, info->si_addr); 310 return 1; 311 } 312 #endif 313 314 JavaThread* thread = NULL; 315 VMThread* vmthread = NULL; 316 if (os::Linux::signal_handlers_are_installed) { 317 if (t != NULL ){ 318 if(t->is_Java_thread()) { 319 thread = (JavaThread*)t; 320 } 321 else if(t->is_VM_thread()){ 322 vmthread = (VMThread *)t; 323 } 324 } 325 } 326 /* 327 NOTE: does not seem to work on linux. 328 if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { 329 // can't decode this kind of signal 330 info = NULL; 331 } else { 332 assert(sig == info->si_signo, "bad siginfo"); 333 } 334 */ 335 // decide if this trap can be handled by a stub 336 address stub = NULL; 337 338 address pc = NULL; 339 340 //%note os_trap_1 341 if (info != NULL && uc != NULL && thread != NULL) { 342 pc = (address) os::Linux::ucontext_get_pc(uc); 343 344 #ifdef BUILTIN_SIM 345 if (pc == (address) Fetch32PFI) { 346 uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ; 347 return 1 ; 348 } 349 if (pc == (address) FetchNPFI) { 350 uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ; 351 return 1 ; 352 } 353 #else 354 if (StubRoutines::is_safefetch_fault(pc)) { 355 os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); 356 return 1; 357 } 358 #endif 359 360 address addr = (address) info->si_addr; 361 362 // Make sure the high order byte is sign extended, as it may be masked away by the hardware. 363 if ((uintptr_t(addr) & (uintptr_t(1) << 55)) != 0) { 364 addr = address(uintptr_t(addr) | (uintptr_t(0xFF) << 56)); 365 } 366 367 // Handle ALL stack overflow variations here 368 if (sig == SIGSEGV) { 369 // check if fault address is within thread stack 370 if (thread->on_local_stack(addr)) { 371 // stack overflow 372 if (thread->in_stack_yellow_reserved_zone(addr)) { 373 thread->disable_stack_yellow_reserved_zone(); 374 if (thread->thread_state() == _thread_in_Java) { 375 if (thread->in_stack_reserved_zone(addr)) { 376 frame fr; 377 if (os::Linux::get_frame_at_stack_banging_point(thread, uc, &fr)) { 378 assert(fr.is_java_frame(), "Must be a Java frame"); 379 frame activation = 380 SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr); 381 if (activation.sp() != NULL) { 382 thread->disable_stack_reserved_zone(); 383 if (activation.is_interpreted_frame()) { 384 thread->set_reserved_stack_activation((address)( 385 activation.fp() + frame::interpreter_frame_initial_sp_offset)); 386 } else { 387 thread->set_reserved_stack_activation((address)activation.unextended_sp()); 388 } 389 return 1; 390 } 391 } 392 } 393 // Throw a stack overflow exception. Guard pages will be reenabled 394 // while unwinding the stack. 395 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); 396 } else { 397 // Thread was in the vm or native code. Return and try to finish. 398 return 1; 399 } 400 } else if (thread->in_stack_red_zone(addr)) { 401 // Fatal red zone violation. Disable the guard pages and fall through 402 // to handle_unexpected_exception way down below. 403 thread->disable_stack_red_zone(); 404 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 405 406 // This is a likely cause, but hard to verify. Let's just print 407 // it as a hint. 408 tty->print_raw_cr("Please check if any of your loaded .so files has " 409 "enabled executable stack (see man page execstack(8))"); 410 } else { 411 // Accessing stack address below sp may cause SEGV if current 412 // thread has MAP_GROWSDOWN stack. This should only happen when 413 // current thread was created by user code with MAP_GROWSDOWN flag 414 // and then attached to VM. See notes in os_linux.cpp. 415 if (thread->osthread()->expanding_stack() == 0) { 416 thread->osthread()->set_expanding_stack(); 417 if (os::Linux::manually_expand_stack(thread, addr)) { 418 thread->osthread()->clear_expanding_stack(); 419 return 1; 420 } 421 thread->osthread()->clear_expanding_stack(); 422 } else { 423 fatal("recursive segv. expanding stack."); 424 } 425 } 426 } 427 } 428 429 if (thread->thread_state() == _thread_in_Java) { 430 // Java thread running in Java code => find exception handler if any 431 // a fault inside compiled code, the interpreter, or a stub 432 433 // Handle signal from NativeJump::patch_verified_entry(). 434 if ((sig == SIGILL || sig == SIGTRAP) 435 && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) { 436 if (TraceTraps) { 437 tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL"); 438 } 439 stub = SharedRuntime::get_handle_wrong_method_stub(); 440 } else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) { 441 stub = SharedRuntime::get_poll_stub(pc); 442 } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) { 443 // BugId 4454115: A read from a MappedByteBuffer can fault 444 // here if the underlying file has been truncated. 445 // Do not crash the VM in such a case. 446 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 447 CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; 448 if (nm != NULL && nm->has_unsafe_access()) { 449 address next_pc = pc + NativeCall::instruction_size; 450 stub = SharedRuntime::handle_unsafe_access(thread, next_pc); 451 } 452 } 453 else 454 455 if (sig == SIGFPE && 456 (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) { 457 stub = 458 SharedRuntime:: 459 continuation_for_implicit_exception(thread, 460 pc, 461 SharedRuntime:: 462 IMPLICIT_DIVIDE_BY_ZERO); 463 } else if (sig == SIGSEGV && 464 MacroAssembler::uses_implicit_null_check((void*)addr)) { 465 // Determination of interpreter/vtable stub/compiled code null exception 466 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); 467 } 468 } else if (thread->thread_state() == _thread_in_vm && 469 sig == SIGBUS && /* info->si_code == BUS_OBJERR && */ 470 thread->doing_unsafe_access()) { 471 address next_pc = pc + NativeCall::instruction_size; 472 stub = SharedRuntime::handle_unsafe_access(thread, next_pc); 473 } 474 475 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 476 // and the heap gets shrunk before the field access. 477 if ((sig == SIGSEGV) || (sig == SIGBUS)) { 478 address addr = JNI_FastGetField::find_slowcase_pc(pc); 479 if (addr != (address)-1) { 480 stub = addr; 481 } 482 } 483 484 // Check to see if we caught the safepoint code in the 485 // process of write protecting the memory serialization page. 486 // It write enables the page immediately after protecting it 487 // so we can just return to retry the write. 488 if ((sig == SIGSEGV) && 489 os::is_memory_serialize_page(thread, (address) info->si_addr)) { 490 // Block current thread until the memory serialize page permission restored. 491 os::block_on_serialize_page_trap(); 492 return true; 493 } 494 } 495 496 if (stub != NULL) { 497 // save all thread context in case we need to restore it 498 if (thread != NULL) thread->set_saved_exception_pc(pc); 499 500 os::Linux::ucontext_set_pc(uc, stub); 501 return true; 502 } 503 504 // signal-chaining 505 if (os::Linux::chained_handler(sig, info, ucVoid)) { 506 return true; 507 } 508 509 if (!abort_if_unrecognized) { 510 // caller wants another chance, so give it to him 511 return false; 512 } 513 514 if (pc == NULL && uc != NULL) { 515 pc = os::Linux::ucontext_get_pc(uc); 516 } 517 518 // unmask current signal 519 sigset_t newset; 520 sigemptyset(&newset); 521 sigaddset(&newset, sig); 522 sigprocmask(SIG_UNBLOCK, &newset, NULL); 523 524 VMError::report_and_die(t, sig, pc, info, ucVoid); 525 526 ShouldNotReachHere(); 527 return true; // Mute compiler 528 } 529 530 void os::Linux::init_thread_fpu_state(void) { 531 } 532 533 int os::Linux::get_fpu_control_word(void) { 534 return 0; 535 } 536 537 void os::Linux::set_fpu_control_word(int fpu_control) { 538 } 539 540 // Check that the linux kernel version is 2.4 or higher since earlier 541 // versions do not support SSE without patches. 542 bool os::supports_sse() { 543 return true; 544 } 545 546 bool os::is_allocatable(size_t bytes) { 547 return true; 548 } 549 550 //////////////////////////////////////////////////////////////////////////////// 551 // thread stack 552 553 // Minimum usable stack sizes required to get to user code. Space for 554 // HotSpot guard pages is added later. 555 size_t os::Posix::_compiler_thread_min_stack_allowed = 72 * K; 556 size_t os::Posix::_java_thread_min_stack_allowed = 72 * K; 557 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 72 * K; 558 559 // return default stack size for thr_type 560 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { 561 // default stack size (compiler thread needs larger stack) 562 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); 563 return s; 564 } 565 566 ///////////////////////////////////////////////////////////////////////////// 567 // helper functions for fatal error handler 568 569 void os::print_context(outputStream *st, const void *context) { 570 if (context == NULL) return; 571 572 const ucontext_t *uc = (const ucontext_t*)context; 573 st->print_cr("Registers:"); 574 #ifdef BUILTIN_SIM 575 st->print( "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]); 576 st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]); 577 st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]); 578 st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]); 579 st->cr(); 580 st->print( "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]); 581 st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]); 582 st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]); 583 st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]); 584 st->cr(); 585 st->print( "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]); 586 st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]); 587 st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]); 588 st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]); 589 st->cr(); 590 st->print( "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]); 591 st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]); 592 st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]); 593 st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]); 594 st->cr(); 595 st->print( "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]); 596 st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]); 597 st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]); 598 st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]); 599 st->cr(); 600 st->print(" TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]); 601 st->cr(); 602 #else 603 for (int r = 0; r < 31; r++) { 604 st->print("R%-2d=", r); 605 print_location(st, uc->uc_mcontext.regs[r]); 606 } 607 #endif 608 st->cr(); 609 610 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 611 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp)); 612 print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t)); 613 st->cr(); 614 615 // Note: it may be unsafe to inspect memory near pc. For example, pc may 616 // point to garbage if entry point in an nmethod is corrupted. Leave 617 // this at the end, and hope for the best. 618 address pc = os::Linux::ucontext_get_pc(uc); 619 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc)); 620 print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); 621 } 622 623 void os::print_register_info(outputStream *st, const void *context) { 624 if (context == NULL) return; 625 626 const ucontext_t *uc = (const ucontext_t*)context; 627 628 st->print_cr("Register to memory mapping:"); 629 st->cr(); 630 631 // this is horrendously verbose but the layout of the registers in the 632 // context does not match how we defined our abstract Register set, so 633 // we can't just iterate through the gregs area 634 635 // this is only for the "general purpose" registers 636 637 #ifdef BUILTIN_SIM 638 st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]); 639 st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]); 640 st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]); 641 st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]); 642 st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]); 643 st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]); 644 st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]); 645 st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]); 646 st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]); 647 st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]); 648 st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]); 649 st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]); 650 st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]); 651 st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]); 652 st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]); 653 st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]); 654 #else 655 for (int r = 0; r < 31; r++) 656 st->print_cr( "R%d=" INTPTR_FORMAT, r, (uintptr_t)uc->uc_mcontext.regs[r]); 657 #endif 658 st->cr(); 659 } 660 661 void os::setup_fpu() { 662 } 663 664 #ifndef PRODUCT 665 void os::verify_stack_alignment() { 666 assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment"); 667 } 668 #endif 669 670 int os::extra_bang_size_in_bytes() { 671 // AArch64 does not require the additional stack bang. 672 return 0; 673 } 674 675 extern "C" { 676 int SpinPause() { 677 return 0; 678 } 679 680 void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 681 if (from > to) { 682 jshort *end = from + count; 683 while (from < end) 684 *(to++) = *(from++); 685 } 686 else if (from < to) { 687 jshort *end = from; 688 from += count - 1; 689 to += count - 1; 690 while (from >= end) 691 *(to--) = *(from--); 692 } 693 } 694 void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 695 if (from > to) { 696 jint *end = from + count; 697 while (from < end) 698 *(to++) = *(from++); 699 } 700 else if (from < to) { 701 jint *end = from; 702 from += count - 1; 703 to += count - 1; 704 while (from >= end) 705 *(to--) = *(from--); 706 } 707 } 708 void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { 709 if (from > to) { 710 jlong *end = from + count; 711 while (from < end) 712 os::atomic_copy64(from++, to++); 713 } 714 else if (from < to) { 715 jlong *end = from; 716 from += count - 1; 717 to += count - 1; 718 while (from >= end) 719 os::atomic_copy64(from--, to--); 720 } 721 } 722 723 void _Copy_arrayof_conjoint_bytes(HeapWord* from, 724 HeapWord* to, 725 size_t count) { 726 memmove(to, from, count); 727 } 728 void _Copy_arrayof_conjoint_jshorts(HeapWord* from, 729 HeapWord* to, 730 size_t count) { 731 memmove(to, from, count * 2); 732 } 733 void _Copy_arrayof_conjoint_jints(HeapWord* from, 734 HeapWord* to, 735 size_t count) { 736 memmove(to, from, count * 4); 737 } 738 void _Copy_arrayof_conjoint_jlongs(HeapWord* from, 739 HeapWord* to, 740 size_t count) { 741 memmove(to, from, count * 8); 742 } 743 };