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