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