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 // Handle ALL stack overflow variations here 361 if (sig == SIGSEGV) { 362 address addr = (address) info->si_addr; 363 364 // check if fault address is within thread stack 365 if (thread->on_local_stack(addr)) { 366 // stack overflow 367 if (thread->in_stack_yellow_reserved_zone(addr)) { 368 thread->disable_stack_yellow_reserved_zone(); 369 if (thread->thread_state() == _thread_in_Java) { 370 if (thread->in_stack_reserved_zone(addr)) { 371 frame fr; 372 if (os::Linux::get_frame_at_stack_banging_point(thread, uc, &fr)) { 373 assert(fr.is_java_frame(), "Must be a Java frame"); 374 frame activation = 375 SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr); 376 if (activation.sp() != NULL) { 377 thread->disable_stack_reserved_zone(); 378 if (activation.is_interpreted_frame()) { 379 thread->set_reserved_stack_activation((address)( 380 activation.fp() + frame::interpreter_frame_initial_sp_offset)); 381 } else { 382 thread->set_reserved_stack_activation((address)activation.unextended_sp()); 383 } 384 return 1; 385 } 386 } 387 } 388 // Throw a stack overflow exception. Guard pages will be reenabled 389 // while unwinding the stack. 390 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); 391 } else { 392 // Thread was in the vm or native code. Return and try to finish. 393 return 1; 394 } 395 } else if (thread->in_stack_red_zone(addr)) { 396 // Fatal red zone violation. Disable the guard pages and fall through 397 // to handle_unexpected_exception way down below. 398 thread->disable_stack_red_zone(); 399 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 400 401 // This is a likely cause, but hard to verify. Let's just print 402 // it as a hint. 403 tty->print_raw_cr("Please check if any of your loaded .so files has " 404 "enabled executable stack (see man page execstack(8))"); 405 } else { 406 // Accessing stack address below sp may cause SEGV if current 407 // thread has MAP_GROWSDOWN stack. This should only happen when 408 // current thread was created by user code with MAP_GROWSDOWN flag 409 // and then attached to VM. See notes in os_linux.cpp. 410 if (thread->osthread()->expanding_stack() == 0) { 411 thread->osthread()->set_expanding_stack(); 412 if (os::Linux::manually_expand_stack(thread, addr)) { 413 thread->osthread()->clear_expanding_stack(); 414 return 1; 415 } 416 thread->osthread()->clear_expanding_stack(); 417 } else { 418 fatal("recursive segv. expanding stack."); 419 } 420 } 421 } 422 } 423 424 if (thread->thread_state() == _thread_in_Java) { 425 // Java thread running in Java code => find exception handler if any 426 // a fault inside compiled code, the interpreter, or a stub 427 428 // Handle signal from NativeJump::patch_verified_entry(). 429 if ((sig == SIGILL || sig == SIGTRAP) 430 && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) { 431 if (TraceTraps) { 432 tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL"); 433 } 434 stub = SharedRuntime::get_handle_wrong_method_stub(); 435 } else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) { 436 stub = SharedRuntime::get_poll_stub(pc); 437 } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) { 438 // BugId 4454115: A read from a MappedByteBuffer can fault 439 // here if the underlying file has been truncated. 440 // Do not crash the VM in such a case. 441 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 442 CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; 443 if (nm != NULL && nm->has_unsafe_access()) { 444 address next_pc = pc + NativeCall::instruction_size; 445 stub = SharedRuntime::handle_unsafe_access(thread, next_pc); 446 } 447 } 448 else 449 450 if (sig == SIGFPE && 451 (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) { 452 stub = 453 SharedRuntime:: 454 continuation_for_implicit_exception(thread, 455 pc, 456 SharedRuntime:: 457 IMPLICIT_DIVIDE_BY_ZERO); 458 } else if (sig == SIGSEGV && 459 !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { 460 // Determination of interpreter/vtable stub/compiled code null exception 461 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); 462 } 463 } else if (thread->thread_state() == _thread_in_vm && 464 sig == SIGBUS && /* info->si_code == BUS_OBJERR && */ 465 thread->doing_unsafe_access()) { 466 address next_pc = pc + NativeCall::instruction_size; 467 stub = SharedRuntime::handle_unsafe_access(thread, next_pc); 468 } 469 470 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 471 // and the heap gets shrunk before the field access. 472 if ((sig == SIGSEGV) || (sig == SIGBUS)) { 473 address addr = JNI_FastGetField::find_slowcase_pc(pc); 474 if (addr != (address)-1) { 475 stub = addr; 476 } 477 } 478 479 // Check to see if we caught the safepoint code in the 480 // process of write protecting the memory serialization page. 481 // It write enables the page immediately after protecting it 482 // so we can just return to retry the write. 483 if ((sig == SIGSEGV) && 484 os::is_memory_serialize_page(thread, (address) info->si_addr)) { 485 // Block current thread until the memory serialize page permission restored. 486 os::block_on_serialize_page_trap(); 487 return true; 488 } 489 } 490 491 if (stub != NULL) { 492 // save all thread context in case we need to restore it 493 if (thread != NULL) thread->set_saved_exception_pc(pc); 494 495 os::Linux::ucontext_set_pc(uc, stub); 496 return true; 497 } 498 499 // signal-chaining 500 if (os::Linux::chained_handler(sig, info, ucVoid)) { 501 return true; 502 } 503 504 if (!abort_if_unrecognized) { 505 // caller wants another chance, so give it to him 506 return false; 507 } 508 509 if (pc == NULL && uc != NULL) { 510 pc = os::Linux::ucontext_get_pc(uc); 511 } 512 513 // unmask current signal 514 sigset_t newset; 515 sigemptyset(&newset); 516 sigaddset(&newset, sig); 517 sigprocmask(SIG_UNBLOCK, &newset, NULL); 518 519 VMError::report_and_die(t, sig, pc, info, ucVoid); 520 521 ShouldNotReachHere(); 522 return true; // Mute compiler 523 } 524 525 void os::Linux::init_thread_fpu_state(void) { 526 } 527 528 int os::Linux::get_fpu_control_word(void) { 529 return 0; 530 } 531 532 void os::Linux::set_fpu_control_word(int fpu_control) { 533 } 534 535 // Check that the linux kernel version is 2.4 or higher since earlier 536 // versions do not support SSE without patches. 537 bool os::supports_sse() { 538 return true; 539 } 540 541 bool os::is_allocatable(size_t bytes) { 542 return true; 543 } 544 545 //////////////////////////////////////////////////////////////////////////////// 546 // thread stack 547 548 // Minimum usable stack sizes required to get to user code. Space for 549 // HotSpot guard pages is added later. 550 size_t os::Posix::_compiler_thread_min_stack_allowed = 72 * K; 551 size_t os::Posix::_java_thread_min_stack_allowed = 72 * K; 552 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 72 * K; 553 554 // return default stack size for thr_type 555 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { 556 // default stack size (compiler thread needs larger stack) 557 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); 558 return s; 559 } 560 561 ///////////////////////////////////////////////////////////////////////////// 562 // helper functions for fatal error handler 563 564 void os::print_context(outputStream *st, const void *context) { 565 if (context == NULL) return; 566 567 const ucontext_t *uc = (const ucontext_t*)context; 568 st->print_cr("Registers:"); 569 #ifdef BUILTIN_SIM 570 st->print( "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]); 571 st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]); 572 st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]); 573 st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]); 574 st->cr(); 575 st->print( "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]); 576 st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]); 577 st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]); 578 st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]); 579 st->cr(); 580 st->print( "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]); 581 st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]); 582 st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]); 583 st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]); 584 st->cr(); 585 st->print( "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]); 586 st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]); 587 st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]); 588 st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]); 589 st->cr(); 590 st->print( "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]); 591 st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]); 592 st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]); 593 st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]); 594 st->cr(); 595 st->print(" TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]); 596 st->cr(); 597 #else 598 for (int r = 0; r < 31; r++) { 599 st->print("R%-2d=", r); 600 print_location(st, uc->uc_mcontext.regs[r]); 601 } 602 #endif 603 st->cr(); 604 605 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 606 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp)); 607 print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t)); 608 st->cr(); 609 610 // Note: it may be unsafe to inspect memory near pc. For example, pc may 611 // point to garbage if entry point in an nmethod is corrupted. Leave 612 // this at the end, and hope for the best. 613 address pc = os::Linux::ucontext_get_pc(uc); 614 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc)); 615 print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); 616 } 617 618 void os::print_register_info(outputStream *st, const void *context) { 619 if (context == NULL) return; 620 621 const ucontext_t *uc = (const ucontext_t*)context; 622 623 st->print_cr("Register to memory mapping:"); 624 st->cr(); 625 626 // this is horrendously verbose but the layout of the registers in the 627 // context does not match how we defined our abstract Register set, so 628 // we can't just iterate through the gregs area 629 630 // this is only for the "general purpose" registers 631 632 #ifdef BUILTIN_SIM 633 st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]); 634 st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]); 635 st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]); 636 st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]); 637 st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]); 638 st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]); 639 st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]); 640 st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]); 641 st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]); 642 st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]); 643 st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]); 644 st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]); 645 st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]); 646 st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]); 647 st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]); 648 st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]); 649 #else 650 for (int r = 0; r < 31; r++) 651 st->print_cr( "R%d=" INTPTR_FORMAT, r, (uintptr_t)uc->uc_mcontext.regs[r]); 652 #endif 653 st->cr(); 654 } 655 656 void os::setup_fpu() { 657 } 658 659 #ifndef PRODUCT 660 void os::verify_stack_alignment() { 661 assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment"); 662 } 663 #endif 664 665 int os::extra_bang_size_in_bytes() { 666 // AArch64 does not require the additional stack bang. 667 return 0; 668 } 669 670 extern "C" { 671 int SpinPause() { 672 return 0; 673 } 674 675 void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 676 if (from > to) { 677 jshort *end = from + count; 678 while (from < end) 679 *(to++) = *(from++); 680 } 681 else if (from < to) { 682 jshort *end = from; 683 from += count - 1; 684 to += count - 1; 685 while (from >= end) 686 *(to--) = *(from--); 687 } 688 } 689 void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 690 if (from > to) { 691 jint *end = from + count; 692 while (from < end) 693 *(to++) = *(from++); 694 } 695 else if (from < to) { 696 jint *end = from; 697 from += count - 1; 698 to += count - 1; 699 while (from >= end) 700 *(to--) = *(from--); 701 } 702 } 703 void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { 704 if (from > to) { 705 jlong *end = from + count; 706 while (from < end) 707 os::atomic_copy64(from++, to++); 708 } 709 else if (from < to) { 710 jlong *end = from; 711 from += count - 1; 712 to += count - 1; 713 while (from >= end) 714 os::atomic_copy64(from--, to--); 715 } 716 } 717 718 void _Copy_arrayof_conjoint_bytes(HeapWord* from, 719 HeapWord* to, 720 size_t count) { 721 memmove(to, from, count); 722 } 723 void _Copy_arrayof_conjoint_jshorts(HeapWord* from, 724 HeapWord* to, 725 size_t count) { 726 memmove(to, from, count * 2); 727 } 728 void _Copy_arrayof_conjoint_jints(HeapWord* from, 729 HeapWord* to, 730 size_t count) { 731 memmove(to, from, count * 4); 732 } 733 void _Copy_arrayof_conjoint_jlongs(HeapWord* from, 734 HeapWord* to, 735 size_t count) { 736 memmove(to, from, count * 8); 737 } 738 };