1 /* 2 * Copyright (c) 2008, 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 "jvm.h" 27 #include "assembler_arm.inline.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 "nativeInst_arm.hpp" 36 #include "os_share_linux.hpp" 37 #include "prims/jniFastGetField.hpp" 38 #include "prims/jvm_misc.hpp" 39 #include "runtime/arguments.hpp" 40 #include "runtime/extendedPC.hpp" 41 #include "runtime/frame.inline.hpp" 42 #include "runtime/interfaceSupport.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/timer.hpp" 50 #include "utilities/events.hpp" 51 #include "utilities/vmError.hpp" 52 53 // put OS-includes here 54 # include <sys/types.h> 55 # include <sys/mman.h> 56 # include <pthread.h> 57 # include <signal.h> 58 # include <errno.h> 59 # include <dlfcn.h> 60 # include <stdlib.h> 61 # include <stdio.h> 62 # include <unistd.h> 63 # include <sys/resource.h> 64 # include <pthread.h> 65 # include <sys/stat.h> 66 # include <sys/time.h> 67 # include <sys/utsname.h> 68 # include <sys/socket.h> 69 # include <sys/wait.h> 70 # include <pwd.h> 71 # include <poll.h> 72 # include <ucontext.h> 73 # include <fpu_control.h> 74 # include <asm/ptrace.h> 75 76 #define SPELL_REG_SP "sp" 77 78 // Don't #define SPELL_REG_FP for thumb because it is not safe to use, so this makes sure we never fetch it. 79 #ifndef __thumb__ 80 #define SPELL_REG_FP AARCH64_ONLY("x29") NOT_AARCH64("fp") 81 #endif 82 83 address os::current_stack_pointer() { 84 register address sp __asm__ (SPELL_REG_SP); 85 return sp; 86 } 87 88 char* os::non_memory_address_word() { 89 // Must never look like an address returned by reserve_memory 90 return (char*) -1; 91 } 92 93 void os::initialize_thread(Thread* thr) { 94 // Nothing to do 95 } 96 97 #ifdef AARCH64 98 99 #define arm_pc pc 100 #define arm_sp sp 101 #define arm_fp regs[29] 102 #define arm_r0 regs[0] 103 #define ARM_REGS_IN_CONTEXT 31 104 105 #else 106 107 #if NGREG == 16 108 // These definitions are based on the observation that until 109 // the certain version of GCC mcontext_t was defined as 110 // a structure containing gregs[NGREG] array with 16 elements. 111 // In later GCC versions mcontext_t was redefined as struct sigcontext, 112 // along with NGREG constant changed to 18. 113 #define arm_pc gregs[15] 114 #define arm_sp gregs[13] 115 #define arm_fp gregs[11] 116 #define arm_r0 gregs[0] 117 #endif 118 119 #define ARM_REGS_IN_CONTEXT 16 120 121 #endif // AARCH64 122 123 address os::Linux::ucontext_get_pc(const ucontext_t* uc) { 124 return (address)uc->uc_mcontext.arm_pc; 125 } 126 127 void os::Linux::ucontext_set_pc(ucontext_t* uc, address pc) { 128 uc->uc_mcontext.arm_pc = (uintx)pc; 129 } 130 131 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t* uc) { 132 return (intptr_t*)uc->uc_mcontext.arm_sp; 133 } 134 135 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t* uc) { 136 return (intptr_t*)uc->uc_mcontext.arm_fp; 137 } 138 139 bool is_safe_for_fp(address pc) { 140 #ifdef __thumb__ 141 if (CodeCache::find_blob(pc) != NULL) { 142 return true; 143 } 144 // For thumb C frames, given an fp we have no idea how to access the frame contents. 145 return false; 146 #else 147 // Calling os::address_is_in_vm() here leads to a dladdr call. Calling any libc 148 // function during os::get_native_stack() can result in a deadlock if JFR is 149 // enabled. For now, be more lenient and allow all pc's. There are other 150 // frame sanity checks in shared code, and to date they have been sufficient 151 // for other platforms. 152 //return os::address_is_in_vm(pc); 153 return true; 154 #endif 155 } 156 157 // For Forte Analyzer AsyncGetCallTrace profiling support - thread 158 // is currently interrupted by SIGPROF. 159 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal 160 // frames. Currently we don't do that on Linux, so it's the same as 161 // os::fetch_frame_from_context(). 162 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, 163 const ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { 164 165 assert(thread != NULL, "just checking"); 166 assert(ret_sp != NULL, "just checking"); 167 assert(ret_fp != NULL, "just checking"); 168 169 return os::fetch_frame_from_context(uc, ret_sp, ret_fp); 170 } 171 172 ExtendedPC os::fetch_frame_from_context(const void* ucVoid, 173 intptr_t** ret_sp, intptr_t** ret_fp) { 174 175 ExtendedPC epc; 176 const ucontext_t* uc = (const ucontext_t*)ucVoid; 177 178 if (uc != NULL) { 179 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); 180 if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc); 181 if (ret_fp) { 182 intptr_t* fp = os::Linux::ucontext_get_fp(uc); 183 #ifndef __thumb__ 184 if (CodeCache::find_blob(epc.pc()) == NULL) { 185 // It's a C frame. We need to adjust the fp. 186 fp += os::C_frame_offset; 187 } 188 #endif 189 // Clear FP when stack walking is dangerous so that 190 // the frame created will not be walked. 191 // However, ensure FP is set correctly when reliable and 192 // potentially necessary. 193 if (!is_safe_for_fp(epc.pc())) { 194 // FP unreliable 195 fp = (intptr_t *)NULL; 196 } 197 *ret_fp = fp; 198 } 199 } else { 200 // construct empty ExtendedPC for return value checking 201 epc = ExtendedPC(NULL); 202 if (ret_sp) *ret_sp = (intptr_t *)NULL; 203 if (ret_fp) *ret_fp = (intptr_t *)NULL; 204 } 205 206 return epc; 207 } 208 209 frame os::fetch_frame_from_context(const void* ucVoid) { 210 intptr_t* sp; 211 intptr_t* fp; 212 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); 213 return frame(sp, fp, epc.pc()); 214 } 215 216 frame os::get_sender_for_C_frame(frame* fr) { 217 #ifdef __thumb__ 218 // We can't reliably get anything from a thumb C frame. 219 return frame(); 220 #else 221 address pc = fr->sender_pc(); 222 if (! is_safe_for_fp(pc)) { 223 return frame(fr->sender_sp(), (intptr_t *)NULL, pc); 224 } else { 225 return frame(fr->sender_sp(), fr->link() + os::C_frame_offset, pc); 226 } 227 #endif 228 } 229 230 // 231 // This actually returns two frames up. It does not return os::current_frame(), 232 // which is the actual current frame. Nor does it return os::get_native_stack(), 233 // which is the caller. It returns whoever called os::get_native_stack(). Not 234 // very intuitive, but consistent with how this API is implemented on other 235 // platforms. 236 // 237 frame os::current_frame() { 238 #ifdef __thumb__ 239 // We can't reliably get anything from a thumb C frame. 240 return frame(); 241 #else 242 register intptr_t* fp __asm__ (SPELL_REG_FP); 243 // fp is for os::current_frame. We want the fp for our caller. 244 frame myframe((intptr_t*)os::current_stack_pointer(), fp + os::C_frame_offset, 245 CAST_FROM_FN_PTR(address, os::current_frame)); 246 frame caller_frame = os::get_sender_for_C_frame(&myframe); 247 248 if (os::is_first_C_frame(&caller_frame)) { 249 // stack is not walkable 250 // Assert below was added because it does not seem like this can ever happen. 251 // How can this frame ever be the first C frame since it is called from C code? 252 // If it does ever happen, undo the assert and comment here on when/why it happens. 253 assert(false, "this should never happen"); 254 return frame(); 255 } 256 257 // return frame for our caller's caller 258 return os::get_sender_for_C_frame(&caller_frame); 259 #endif 260 } 261 262 #ifndef AARCH64 263 extern "C" address check_vfp_fault_instr; 264 extern "C" address check_vfp3_32_fault_instr; 265 266 address check_vfp_fault_instr = NULL; 267 address check_vfp3_32_fault_instr = NULL; 268 #endif // !AARCH64 269 extern "C" address check_simd_fault_instr; 270 address check_simd_fault_instr = NULL; 271 272 // Utility functions 273 274 extern "C" int JVM_handle_linux_signal(int sig, siginfo_t* info, 275 void* ucVoid, int abort_if_unrecognized) { 276 ucontext_t* uc = (ucontext_t*) ucVoid; 277 278 Thread* t = Thread::current_or_null_safe(); 279 280 // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away 281 // (no destructors can be run) 282 os::ThreadCrashProtection::check_crash_protection(sig, t); 283 284 SignalHandlerMark shm(t); 285 286 if (sig == SIGILL && 287 ((info->si_addr == (caddr_t)check_simd_fault_instr) 288 NOT_AARCH64(|| info->si_addr == (caddr_t)check_vfp_fault_instr) 289 NOT_AARCH64(|| info->si_addr == (caddr_t)check_vfp3_32_fault_instr))) { 290 // skip faulty instruction + instruction that sets return value to 291 // success and set return value to failure. 292 os::Linux::ucontext_set_pc(uc, (address)info->si_addr + 8); 293 uc->uc_mcontext.arm_r0 = 0; 294 return true; 295 } 296 297 // Note: it's not uncommon that JNI code uses signal/sigset to install 298 // then restore certain signal handler (e.g. to temporarily block SIGPIPE, 299 // or have a SIGILL handler when detecting CPU type). When that happens, 300 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To 301 // avoid unnecessary crash when libjsig is not preloaded, try handle signals 302 // that do not require siginfo/ucontext first. 303 304 if (sig == SIGPIPE || sig == SIGXFSZ) { 305 // allow chained handler to go first 306 if (os::Linux::chained_handler(sig, info, ucVoid)) { 307 return true; 308 } else { 309 // Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219 310 return true; 311 } 312 } 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 address stub = NULL; 328 address pc = NULL; 329 bool unsafe_access = false; 330 331 if (info != NULL && uc != NULL && thread != NULL) { 332 pc = (address) os::Linux::ucontext_get_pc(uc); 333 334 // Handle ALL stack overflow variations here 335 if (sig == SIGSEGV) { 336 address addr = (address) info->si_addr; 337 338 if (StubRoutines::is_safefetch_fault(pc)) { 339 os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); 340 return 1; 341 } 342 // check if fault address is within thread stack 343 if (addr < thread->stack_base() && 344 addr >= thread->stack_base() - thread->stack_size()) { 345 // stack overflow 346 if (thread->in_stack_yellow_reserved_zone(addr)) { 347 thread->disable_stack_yellow_reserved_zone(); 348 if (thread->thread_state() == _thread_in_Java) { 349 // Throw a stack overflow exception. Guard pages will be reenabled 350 // while unwinding the stack. 351 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); 352 } else { 353 // Thread was in the vm or native code. Return and try to finish. 354 return 1; 355 } 356 } else if (thread->in_stack_red_zone(addr)) { 357 // Fatal red zone violation. Disable the guard pages and fall through 358 // to handle_unexpected_exception way down below. 359 thread->disable_stack_red_zone(); 360 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 361 } else { 362 // Accessing stack address below sp may cause SEGV if current 363 // thread has MAP_GROWSDOWN stack. This should only happen when 364 // current thread was created by user code with MAP_GROWSDOWN flag 365 // and then attached to VM. See notes in os_linux.cpp. 366 if (thread->osthread()->expanding_stack() == 0) { 367 thread->osthread()->set_expanding_stack(); 368 if (os::Linux::manually_expand_stack(thread, addr)) { 369 thread->osthread()->clear_expanding_stack(); 370 return 1; 371 } 372 thread->osthread()->clear_expanding_stack(); 373 } else { 374 fatal("recursive segv. expanding stack."); 375 } 376 } 377 } 378 } 379 380 if (thread->thread_state() == _thread_in_Java) { 381 // Java thread running in Java code => find exception handler if any 382 // a fault inside compiled code, the interpreter, or a stub 383 384 if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) { 385 stub = SharedRuntime::get_poll_stub(pc); 386 } else if (sig == SIGBUS) { 387 // BugId 4454115: A read from a MappedByteBuffer can fault 388 // here if the underlying file has been truncated. 389 // Do not crash the VM in such a case. 390 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 391 CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; 392 if (nm != NULL && nm->has_unsafe_access()) { 393 unsafe_access = true; 394 } 395 } else if (sig == SIGSEGV && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { 396 // Determination of interpreter/vtable stub/compiled code null exception 397 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 398 if (cb != NULL) { 399 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); 400 } 401 } else if (sig == SIGILL && *(int *)pc == NativeInstruction::zombie_illegal_instruction) { 402 // Zombie 403 stub = SharedRuntime::get_handle_wrong_method_stub(); 404 } 405 } else if (thread->thread_state() == _thread_in_vm && 406 sig == SIGBUS && thread->doing_unsafe_access()) { 407 unsafe_access = true; 408 } 409 410 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 411 // and the heap gets shrunk before the field access. 412 if (sig == SIGSEGV || sig == SIGBUS) { 413 address addr = JNI_FastGetField::find_slowcase_pc(pc); 414 if (addr != (address)-1) { 415 stub = addr; 416 } 417 } 418 419 // Check to see if we caught the safepoint code in the 420 // process of write protecting the memory serialization page. 421 // It write enables the page immediately after protecting it 422 // so we can just return to retry the write. 423 if (sig == SIGSEGV && os::is_memory_serialize_page(thread, (address) info->si_addr)) { 424 // Block current thread until the memory serialize page permission restored. 425 os::block_on_serialize_page_trap(); 426 return true; 427 } 428 } 429 430 if (unsafe_access && stub == NULL) { 431 // it can be an unsafe access and we haven't found 432 // any other suitable exception reason, 433 // so assume it is an unsafe access. 434 address next_pc = pc + Assembler::InstructionSize; 435 #ifdef __thumb__ 436 if (uc->uc_mcontext.arm_cpsr & PSR_T_BIT) { 437 next_pc = (address)((intptr_t)next_pc | 0x1); 438 } 439 #endif 440 441 stub = SharedRuntime::handle_unsafe_access(thread, next_pc); 442 } 443 444 if (stub != NULL) { 445 #ifdef __thumb__ 446 if (uc->uc_mcontext.arm_cpsr & PSR_T_BIT) { 447 intptr_t p = (intptr_t)pc | 0x1; 448 pc = (address)p; 449 450 // Clear Thumb mode bit if we're redirected into the ARM ISA based code 451 if (((intptr_t)stub & 0x1) == 0) { 452 uc->uc_mcontext.arm_cpsr &= ~PSR_T_BIT; 453 } 454 } else { 455 // No Thumb2 compiled stubs are triggered from ARM ISA compiled JIT'd code today. 456 // The support needs to be added if that changes 457 assert((((intptr_t)stub & 0x1) == 0), "can't return to Thumb code"); 458 } 459 #endif 460 461 // save all thread context in case we need to restore it 462 if (thread != NULL) thread->set_saved_exception_pc(pc); 463 464 os::Linux::ucontext_set_pc(uc, stub); 465 return true; 466 } 467 468 // signal-chaining 469 if (os::Linux::chained_handler(sig, info, ucVoid)) { 470 return true; 471 } 472 473 if (!abort_if_unrecognized) { 474 // caller wants another chance, so give it to him 475 return false; 476 } 477 478 if (pc == NULL && uc != NULL) { 479 pc = os::Linux::ucontext_get_pc(uc); 480 } 481 482 // unmask current signal 483 sigset_t newset; 484 sigemptyset(&newset); 485 sigaddset(&newset, sig); 486 sigprocmask(SIG_UNBLOCK, &newset, NULL); 487 488 VMError::report_and_die(t, sig, pc, info, ucVoid); 489 490 ShouldNotReachHere(); 491 return false; 492 } 493 494 void os::Linux::init_thread_fpu_state(void) { 495 os::setup_fpu(); 496 } 497 498 int os::Linux::get_fpu_control_word(void) { 499 return 0; 500 } 501 502 void os::Linux::set_fpu_control_word(int fpu_control) { 503 // Nothing to do 504 } 505 506 void os::setup_fpu() { 507 #ifdef AARCH64 508 __asm__ volatile ("msr fpcr, xzr"); 509 #else 510 #if !defined(__SOFTFP__) && defined(__VFP_FP__) 511 // Turn on IEEE-754 compliant VFP mode 512 __asm__ volatile ( 513 "mov %%r0, #0;" 514 "fmxr fpscr, %%r0" 515 : /* no output */ : /* no input */ : "r0" 516 ); 517 #endif 518 #endif // AARCH64 519 } 520 521 bool os::is_allocatable(size_t bytes) { 522 return true; 523 } 524 525 //////////////////////////////////////////////////////////////////////////////// 526 // thread stack 527 528 // Minimum usable stack sizes required to get to user code. Space for 529 // HotSpot guard pages is added later. 530 size_t os::Posix::_compiler_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 4)) * K; 531 size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 4)) * K; 532 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K; 533 534 // return default stack size for thr_type 535 size_t os::Posix::default_stack_size(os::ThreadType thr_type) { 536 // default stack size (compiler thread needs larger stack) 537 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); 538 return s; 539 } 540 541 ///////////////////////////////////////////////////////////////////////////// 542 // helper functions for fatal error handler 543 544 void os::print_context(outputStream *st, const void *context) { 545 if (context == NULL) return; 546 const ucontext_t *uc = (const ucontext_t*)context; 547 548 st->print_cr("Registers:"); 549 intx* reg_area = (intx*)&uc->uc_mcontext.arm_r0; 550 for (int r = 0; r < ARM_REGS_IN_CONTEXT; r++) { 551 st->print_cr(" %-3s = " INTPTR_FORMAT, as_Register(r)->name(), reg_area[r]); 552 } 553 #define U64_FORMAT "0x%016llx" 554 #ifdef AARCH64 555 st->print_cr(" %-3s = " U64_FORMAT, "sp", uc->uc_mcontext.sp); 556 st->print_cr(" %-3s = " U64_FORMAT, "pc", uc->uc_mcontext.pc); 557 st->print_cr(" %-3s = " U64_FORMAT, "pstate", uc->uc_mcontext.pstate); 558 #else 559 // now print flag register 560 st->print_cr(" %-4s = 0x%08lx", "cpsr",uc->uc_mcontext.arm_cpsr); 561 #endif 562 st->cr(); 563 564 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 565 st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", p2i(sp)); 566 print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t)); 567 st->cr(); 568 569 // Note: it may be unsafe to inspect memory near pc. For example, pc may 570 // point to garbage if entry point in an nmethod is corrupted. Leave 571 // this at the end, and hope for the best. 572 address pc = os::Linux::ucontext_get_pc(uc); 573 st->print_cr("Instructions: (pc=" INTPTR_FORMAT ")", p2i(pc)); 574 print_hex_dump(st, pc - 32, pc + 32, Assembler::InstructionSize); 575 } 576 577 void os::print_register_info(outputStream *st, const void *context) { 578 if (context == NULL) return; 579 580 const ucontext_t *uc = (const ucontext_t*)context; 581 intx* reg_area = (intx*)&uc->uc_mcontext.arm_r0; 582 583 st->print_cr("Register to memory mapping:"); 584 st->cr(); 585 for (int r = 0; r < ARM_REGS_IN_CONTEXT; r++) { 586 st->print_cr(" %-3s = " INTPTR_FORMAT, as_Register(r)->name(), reg_area[r]); 587 print_location(st, reg_area[r]); 588 st->cr(); 589 } 590 #ifdef AARCH64 591 st->print_cr(" %-3s = " U64_FORMAT, "pc", uc->uc_mcontext.pc); 592 print_location(st, uc->uc_mcontext.pc); 593 st->cr(); 594 #endif 595 st->cr(); 596 } 597 598 599 #ifndef AARCH64 600 601 typedef int64_t cmpxchg_long_func_t(int64_t, int64_t, volatile int64_t*); 602 603 cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap; 604 605 int64_t os::atomic_cmpxchg_long_bootstrap(int64_t compare_value, int64_t exchange_value, volatile int64_t* dest) { 606 // try to use the stub: 607 cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry()); 608 609 if (func != NULL) { 610 os::atomic_cmpxchg_long_func = func; 611 return (*func)(compare_value, exchange_value, dest); 612 } 613 assert(Threads::number_of_threads() == 0, "for bootstrap only"); 614 615 int64_t old_value = *dest; 616 if (old_value == compare_value) 617 *dest = exchange_value; 618 return old_value; 619 } 620 typedef int64_t load_long_func_t(const volatile int64_t*); 621 622 load_long_func_t* os::atomic_load_long_func = os::atomic_load_long_bootstrap; 623 624 int64_t os::atomic_load_long_bootstrap(const volatile int64_t* src) { 625 // try to use the stub: 626 load_long_func_t* func = CAST_TO_FN_PTR(load_long_func_t*, StubRoutines::atomic_load_long_entry()); 627 628 if (func != NULL) { 629 os::atomic_load_long_func = func; 630 return (*func)(src); 631 } 632 assert(Threads::number_of_threads() == 0, "for bootstrap only"); 633 634 int64_t old_value = *src; 635 return old_value; 636 } 637 638 typedef void store_long_func_t(int64_t, volatile int64_t*); 639 640 store_long_func_t* os::atomic_store_long_func = os::atomic_store_long_bootstrap; 641 642 void os::atomic_store_long_bootstrap(int64_t val, volatile int64_t* dest) { 643 // try to use the stub: 644 store_long_func_t* func = CAST_TO_FN_PTR(store_long_func_t*, StubRoutines::atomic_store_long_entry()); 645 646 if (func != NULL) { 647 os::atomic_store_long_func = func; 648 return (*func)(val, dest); 649 } 650 assert(Threads::number_of_threads() == 0, "for bootstrap only"); 651 652 *dest = val; 653 } 654 655 typedef int32_t atomic_add_func_t(int32_t add_value, volatile int32_t *dest); 656 657 atomic_add_func_t * os::atomic_add_func = os::atomic_add_bootstrap; 658 659 int32_t os::atomic_add_bootstrap(int32_t add_value, volatile int32_t *dest) { 660 atomic_add_func_t * func = CAST_TO_FN_PTR(atomic_add_func_t*, 661 StubRoutines::atomic_add_entry()); 662 if (func != NULL) { 663 os::atomic_add_func = func; 664 return (*func)(add_value, dest); 665 } 666 667 int32_t old_value = *dest; 668 *dest = old_value + add_value; 669 return (old_value + add_value); 670 } 671 672 typedef int32_t atomic_xchg_func_t(int32_t exchange_value, volatile int32_t *dest); 673 674 atomic_xchg_func_t * os::atomic_xchg_func = os::atomic_xchg_bootstrap; 675 676 int32_t os::atomic_xchg_bootstrap(int32_t exchange_value, volatile int32_t *dest) { 677 atomic_xchg_func_t * func = CAST_TO_FN_PTR(atomic_xchg_func_t*, 678 StubRoutines::atomic_xchg_entry()); 679 if (func != NULL) { 680 os::atomic_xchg_func = func; 681 return (*func)(exchange_value, dest); 682 } 683 684 int32_t old_value = *dest; 685 *dest = exchange_value; 686 return (old_value); 687 } 688 689 typedef int32_t cmpxchg_func_t(int32_t, int32_t, volatile int32_t*); 690 691 cmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap; 692 693 int32_t os::atomic_cmpxchg_bootstrap(int32_t compare_value, int32_t exchange_value, volatile int32_t* dest) { 694 // try to use the stub: 695 cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry()); 696 697 if (func != NULL) { 698 os::atomic_cmpxchg_func = func; 699 return (*func)(compare_value, exchange_value, dest); 700 } 701 assert(Threads::number_of_threads() == 0, "for bootstrap only"); 702 703 int32_t old_value = *dest; 704 if (old_value == compare_value) 705 *dest = exchange_value; 706 return old_value; 707 } 708 709 #endif // !AARCH64 710 711 #ifndef PRODUCT 712 void os::verify_stack_alignment() { 713 } 714 #endif 715 716 int os::extra_bang_size_in_bytes() { 717 // ARM does not require an additional stack bang. 718 return 0; 719 } 720