author | kzhaldyb |
Wed, 28 Sep 2016 17:18:45 +0300 | |
changeset 42018 | 921e8769926b |
parent 41070 | 496463b4e206 |
child 42905 | 1af223983f82 |
child 42880 | f71e11a0567d |
permissions | -rw-r--r-- |
29182 | 1 |
/* |
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
35201
diff
changeset
|
2 |
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
29182 | 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 "asm/macroAssembler.hpp" |
|
28 |
#include "classfile/classLoader.hpp" |
|
29 |
#include "classfile/systemDictionary.hpp" |
|
30 |
#include "classfile/vmSymbols.hpp" |
|
34667 | 31 |
#include "code/codeCache.hpp" |
29182 | 32 |
#include "code/icBuffer.hpp" |
33 |
#include "code/vtableStubs.hpp" |
|
34 |
#include "code/nativeInst.hpp" |
|
35 |
#include "interpreter/interpreter.hpp" |
|
36 |
#include "jvm_linux.h" |
|
37 |
#include "memory/allocation.inline.hpp" |
|
38 |
#include "os_share_linux.hpp" |
|
39 |
#include "prims/jniFastGetField.hpp" |
|
40 |
#include "prims/jvm.h" |
|
41 |
#include "prims/jvm_misc.hpp" |
|
42 |
#include "runtime/arguments.hpp" |
|
43 |
#include "runtime/extendedPC.hpp" |
|
44 |
#include "runtime/frame.inline.hpp" |
|
45 |
#include "runtime/interfaceSupport.hpp" |
|
46 |
#include "runtime/java.hpp" |
|
47 |
#include "runtime/javaCalls.hpp" |
|
48 |
#include "runtime/mutexLocker.hpp" |
|
49 |
#include "runtime/osThread.hpp" |
|
50 |
#include "runtime/sharedRuntime.hpp" |
|
51 |
#include "runtime/stubRoutines.hpp" |
|
52 |
#include "runtime/thread.inline.hpp" |
|
53 |
#include "runtime/timer.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 |
||
91 |
#define SPELL_REG_SP "sp" |
|
92 |
#define SPELL_REG_FP "x29" |
|
93 |
#endif |
|
94 |
||
95 |
address os::current_stack_pointer() { |
|
96 |
register void *esp __asm__ (SPELL_REG_SP); |
|
97 |
return (address) esp; |
|
98 |
} |
|
99 |
||
100 |
char* os::non_memory_address_word() { |
|
101 |
// Must never look like an address returned by reserve_memory, |
|
102 |
// even in its subfields (as defined by the CPU immediate fields, |
|
103 |
// if the CPU splits constants across multiple instructions). |
|
104 |
||
105 |
return (char*) 0xffffffffffff; |
|
106 |
} |
|
107 |
||
108 |
void os::initialize_thread(Thread *thr) { |
|
109 |
} |
|
110 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
111 |
address os::Linux::ucontext_get_pc(const ucontext_t * uc) { |
29182 | 112 |
#ifdef BUILTIN_SIM |
113 |
return (address)uc->uc_mcontext.gregs[REG_PC]; |
|
114 |
#else |
|
115 |
return (address)uc->uc_mcontext.pc; |
|
116 |
#endif |
|
117 |
} |
|
118 |
||
29679 | 119 |
void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) { |
120 |
#ifdef BUILTIN_SIM |
|
121 |
uc->uc_mcontext.gregs[REG_PC] = (intptr_t)pc; |
|
122 |
#else |
|
123 |
uc->uc_mcontext.pc = (intptr_t)pc; |
|
124 |
#endif |
|
125 |
} |
|
126 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
127 |
intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) { |
29182 | 128 |
#ifdef BUILTIN_SIM |
129 |
return (intptr_t*)uc->uc_mcontext.gregs[REG_SP]; |
|
130 |
#else |
|
131 |
return (intptr_t*)uc->uc_mcontext.sp; |
|
132 |
#endif |
|
133 |
} |
|
134 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
135 |
intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) { |
29182 | 136 |
#ifdef BUILTIN_SIM |
137 |
return (intptr_t*)uc->uc_mcontext.gregs[REG_FP]; |
|
138 |
#else |
|
139 |
return (intptr_t*)uc->uc_mcontext.regs[REG_FP]; |
|
140 |
#endif |
|
141 |
} |
|
142 |
||
143 |
// For Forte Analyzer AsyncGetCallTrace profiling support - thread |
|
144 |
// is currently interrupted by SIGPROF. |
|
145 |
// os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal |
|
146 |
// frames. Currently we don't do that on Linux, so it's the same as |
|
147 |
// os::fetch_frame_from_context(). |
|
148 |
ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
149 |
const ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { |
29182 | 150 |
|
151 |
assert(thread != NULL, "just checking"); |
|
152 |
assert(ret_sp != NULL, "just checking"); |
|
153 |
assert(ret_fp != NULL, "just checking"); |
|
154 |
||
155 |
return os::fetch_frame_from_context(uc, ret_sp, ret_fp); |
|
156 |
} |
|
157 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
158 |
ExtendedPC os::fetch_frame_from_context(const void* ucVoid, |
29182 | 159 |
intptr_t** ret_sp, intptr_t** ret_fp) { |
160 |
||
161 |
ExtendedPC epc; |
|
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
162 |
const ucontext_t* uc = (const ucontext_t*)ucVoid; |
29182 | 163 |
|
164 |
if (uc != NULL) { |
|
165 |
epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); |
|
166 |
if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc); |
|
167 |
if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc); |
|
168 |
} else { |
|
169 |
// construct empty ExtendedPC for return value checking |
|
170 |
epc = ExtendedPC(NULL); |
|
171 |
if (ret_sp) *ret_sp = (intptr_t *)NULL; |
|
172 |
if (ret_fp) *ret_fp = (intptr_t *)NULL; |
|
173 |
} |
|
174 |
||
175 |
return epc; |
|
176 |
} |
|
177 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
178 |
frame os::fetch_frame_from_context(const void* ucVoid) { |
29182 | 179 |
intptr_t* sp; |
180 |
intptr_t* fp; |
|
181 |
ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); |
|
182 |
return frame(sp, fp, epc.pc()); |
|
183 |
} |
|
184 |
||
185 |
// By default, gcc always saves frame pointer rfp on this stack. This |
|
186 |
// may get turned off by -fomit-frame-pointer. |
|
187 |
frame os::get_sender_for_C_frame(frame* fr) { |
|
188 |
#ifdef BUILTIN_SIM |
|
189 |
return frame(fr->sender_sp(), fr->link(), fr->sender_pc()); |
|
190 |
#else |
|
191 |
return frame(fr->link(), fr->link(), fr->sender_pc()); |
|
192 |
#endif |
|
193 |
} |
|
194 |
||
195 |
intptr_t* _get_previous_fp() { |
|
196 |
register intptr_t **ebp __asm__ (SPELL_REG_FP); |
|
197 |
return (intptr_t*) *ebp; // we want what it points to. |
|
198 |
} |
|
199 |
||
200 |
||
201 |
frame os::current_frame() { |
|
202 |
intptr_t* fp = _get_previous_fp(); |
|
203 |
frame myframe((intptr_t*)os::current_stack_pointer(), |
|
204 |
(intptr_t*)fp, |
|
205 |
CAST_FROM_FN_PTR(address, os::current_frame)); |
|
206 |
if (os::is_first_C_frame(&myframe)) { |
|
207 |
// stack is not walkable |
|
208 |
return frame(); |
|
209 |
} else { |
|
210 |
return os::get_sender_for_C_frame(&myframe); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
// Utility functions |
|
215 |
||
216 |
// From IA32 System Programming Guide |
|
217 |
enum { |
|
218 |
trap_page_fault = 0xE |
|
219 |
}; |
|
220 |
||
221 |
#ifdef BUILTIN_SIM |
|
222 |
extern "C" void Fetch32PFI () ; |
|
223 |
extern "C" void Fetch32Resume () ; |
|
224 |
extern "C" void FetchNPFI () ; |
|
225 |
extern "C" void FetchNResume () ; |
|
226 |
#endif |
|
227 |
||
228 |
extern "C" JNIEXPORT int |
|
229 |
JVM_handle_linux_signal(int sig, |
|
230 |
siginfo_t* info, |
|
231 |
void* ucVoid, |
|
232 |
int abort_if_unrecognized) { |
|
233 |
ucontext_t* uc = (ucontext_t*) ucVoid; |
|
234 |
||
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33105
diff
changeset
|
235 |
Thread* t = Thread::current_or_null_safe(); |
29182 | 236 |
|
237 |
// Must do this before SignalHandlerMark, if crash protection installed we will longjmp away |
|
238 |
// (no destructors can be run) |
|
239 |
os::WatcherThreadCrashProtection::check_crash_protection(sig, t); |
|
240 |
||
241 |
SignalHandlerMark shm(t); |
|
242 |
||
243 |
// Note: it's not uncommon that JNI code uses signal/sigset to install |
|
244 |
// then restore certain signal handler (e.g. to temporarily block SIGPIPE, |
|
245 |
// or have a SIGILL handler when detecting CPU type). When that happens, |
|
246 |
// JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To |
|
247 |
// avoid unnecessary crash when libjsig is not preloaded, try handle signals |
|
248 |
// that do not require siginfo/ucontext first. |
|
249 |
||
250 |
if (sig == SIGPIPE || sig == SIGXFSZ) { |
|
251 |
// allow chained handler to go first |
|
252 |
if (os::Linux::chained_handler(sig, info, ucVoid)) { |
|
253 |
return true; |
|
254 |
} else { |
|
37430
fd743dadef12
8151939: VM_Version_init() print buffer is too small
coleenp
parents:
35201
diff
changeset
|
255 |
// Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219 |
29182 | 256 |
return true; |
257 |
} |
|
258 |
} |
|
259 |
||
260 |
JavaThread* thread = NULL; |
|
261 |
VMThread* vmthread = NULL; |
|
262 |
if (os::Linux::signal_handlers_are_installed) { |
|
263 |
if (t != NULL ){ |
|
264 |
if(t->is_Java_thread()) { |
|
265 |
thread = (JavaThread*)t; |
|
266 |
} |
|
267 |
else if(t->is_VM_thread()){ |
|
268 |
vmthread = (VMThread *)t; |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
/* |
|
273 |
NOTE: does not seem to work on linux. |
|
274 |
if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { |
|
275 |
// can't decode this kind of signal |
|
276 |
info = NULL; |
|
277 |
} else { |
|
278 |
assert(sig == info->si_signo, "bad siginfo"); |
|
279 |
} |
|
280 |
*/ |
|
281 |
// decide if this trap can be handled by a stub |
|
282 |
address stub = NULL; |
|
283 |
||
284 |
address pc = NULL; |
|
285 |
||
286 |
//%note os_trap_1 |
|
287 |
if (info != NULL && uc != NULL && thread != NULL) { |
|
288 |
pc = (address) os::Linux::ucontext_get_pc(uc); |
|
289 |
||
290 |
#ifdef BUILTIN_SIM |
|
291 |
if (pc == (address) Fetch32PFI) { |
|
292 |
uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ; |
|
293 |
return 1 ; |
|
294 |
} |
|
295 |
if (pc == (address) FetchNPFI) { |
|
296 |
uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ; |
|
297 |
return 1 ; |
|
298 |
} |
|
299 |
#else |
|
300 |
if (StubRoutines::is_safefetch_fault(pc)) { |
|
29679 | 301 |
os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); |
29182 | 302 |
return 1; |
303 |
} |
|
304 |
#endif |
|
305 |
||
306 |
// Handle ALL stack overflow variations here |
|
307 |
if (sig == SIGSEGV) { |
|
308 |
address addr = (address) info->si_addr; |
|
309 |
||
310 |
// check if fault address is within thread stack |
|
35201
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
311 |
if (thread->on_local_stack(addr)) { |
29182 | 312 |
// stack overflow |
35201
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
313 |
if (thread->in_stack_yellow_reserved_zone(addr)) { |
996db89f378e
8139864: Improve handling of stack protection zones.
goetz
parents:
35077
diff
changeset
|
314 |
thread->disable_stack_yellow_reserved_zone(); |
29182 | 315 |
if (thread->thread_state() == _thread_in_Java) { |
316 |
// Throw a stack overflow exception. Guard pages will be reenabled |
|
317 |
// while unwinding the stack. |
|
318 |
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); |
|
319 |
} else { |
|
320 |
// Thread was in the vm or native code. Return and try to finish. |
|
321 |
return 1; |
|
322 |
} |
|
323 |
} else if (thread->in_stack_red_zone(addr)) { |
|
324 |
// Fatal red zone violation. Disable the guard pages and fall through |
|
325 |
// to handle_unexpected_exception way down below. |
|
326 |
thread->disable_stack_red_zone(); |
|
327 |
tty->print_raw_cr("An irrecoverable stack overflow has occurred."); |
|
328 |
||
329 |
// This is a likely cause, but hard to verify. Let's just print |
|
330 |
// it as a hint. |
|
331 |
tty->print_raw_cr("Please check if any of your loaded .so files has " |
|
332 |
"enabled executable stack (see man page execstack(8))"); |
|
333 |
} else { |
|
334 |
// Accessing stack address below sp may cause SEGV if current |
|
335 |
// thread has MAP_GROWSDOWN stack. This should only happen when |
|
336 |
// current thread was created by user code with MAP_GROWSDOWN flag |
|
337 |
// and then attached to VM. See notes in os_linux.cpp. |
|
338 |
if (thread->osthread()->expanding_stack() == 0) { |
|
339 |
thread->osthread()->set_expanding_stack(); |
|
340 |
if (os::Linux::manually_expand_stack(thread, addr)) { |
|
341 |
thread->osthread()->clear_expanding_stack(); |
|
342 |
return 1; |
|
343 |
} |
|
344 |
thread->osthread()->clear_expanding_stack(); |
|
345 |
} else { |
|
346 |
fatal("recursive segv. expanding stack."); |
|
347 |
} |
|
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
if (thread->thread_state() == _thread_in_Java) { |
|
353 |
// Java thread running in Java code => find exception handler if any |
|
354 |
// a fault inside compiled code, the interpreter, or a stub |
|
355 |
||
356 |
// Handle signal from NativeJump::patch_verified_entry(). |
|
357 |
if ((sig == SIGILL || sig == SIGTRAP) |
|
358 |
&& nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) { |
|
359 |
if (TraceTraps) { |
|
360 |
tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL"); |
|
361 |
} |
|
362 |
stub = SharedRuntime::get_handle_wrong_method_stub(); |
|
363 |
} else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) { |
|
364 |
stub = SharedRuntime::get_poll_stub(pc); |
|
365 |
} else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) { |
|
366 |
// BugId 4454115: A read from a MappedByteBuffer can fault |
|
367 |
// here if the underlying file has been truncated. |
|
368 |
// Do not crash the VM in such a case. |
|
369 |
CodeBlob* cb = CodeCache::find_blob_unsafe(pc); |
|
38133
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
37430
diff
changeset
|
370 |
CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; |
29182 | 371 |
if (nm != NULL && nm->has_unsafe_access()) { |
38209
b2a58604e046
8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents:
38190
diff
changeset
|
372 |
address next_pc = pc + NativeCall::instruction_size; |
b2a58604e046
8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents:
38190
diff
changeset
|
373 |
stub = SharedRuntime::handle_unsafe_access(thread, next_pc); |
29182 | 374 |
} |
375 |
} |
|
376 |
else |
|
377 |
||
378 |
if (sig == SIGFPE && |
|
379 |
(info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) { |
|
380 |
stub = |
|
381 |
SharedRuntime:: |
|
382 |
continuation_for_implicit_exception(thread, |
|
383 |
pc, |
|
384 |
SharedRuntime:: |
|
385 |
IMPLICIT_DIVIDE_BY_ZERO); |
|
386 |
} else if (sig == SIGSEGV && |
|
387 |
!MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { |
|
388 |
// Determination of interpreter/vtable stub/compiled code null exception |
|
389 |
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
|
390 |
} |
|
391 |
} else if (thread->thread_state() == _thread_in_vm && |
|
392 |
sig == SIGBUS && /* info->si_code == BUS_OBJERR && */ |
|
393 |
thread->doing_unsafe_access()) { |
|
38209
b2a58604e046
8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents:
38190
diff
changeset
|
394 |
address next_pc = pc + NativeCall::instruction_size; |
b2a58604e046
8156088: Reintegrate 8153892: Handle unsafe access error directly in signal handler instead of going through a stub
mikael
parents:
38190
diff
changeset
|
395 |
stub = SharedRuntime::handle_unsafe_access(thread, next_pc); |
29182 | 396 |
} |
397 |
||
398 |
// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in |
|
399 |
// and the heap gets shrunk before the field access. |
|
400 |
if ((sig == SIGSEGV) || (sig == SIGBUS)) { |
|
401 |
address addr = JNI_FastGetField::find_slowcase_pc(pc); |
|
402 |
if (addr != (address)-1) { |
|
403 |
stub = addr; |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
// Check to see if we caught the safepoint code in the |
|
408 |
// process of write protecting the memory serialization page. |
|
409 |
// It write enables the page immediately after protecting it |
|
410 |
// so we can just return to retry the write. |
|
411 |
if ((sig == SIGSEGV) && |
|
412 |
os::is_memory_serialize_page(thread, (address) info->si_addr)) { |
|
413 |
// Block current thread until the memory serialize page permission restored. |
|
414 |
os::block_on_serialize_page_trap(); |
|
415 |
return true; |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
if (stub != NULL) { |
|
420 |
// save all thread context in case we need to restore it |
|
421 |
if (thread != NULL) thread->set_saved_exception_pc(pc); |
|
422 |
||
29679 | 423 |
os::Linux::ucontext_set_pc(uc, stub); |
29182 | 424 |
return true; |
425 |
} |
|
426 |
||
427 |
// signal-chaining |
|
428 |
if (os::Linux::chained_handler(sig, info, ucVoid)) { |
|
429 |
return true; |
|
430 |
} |
|
431 |
||
432 |
if (!abort_if_unrecognized) { |
|
433 |
// caller wants another chance, so give it to him |
|
434 |
return false; |
|
435 |
} |
|
436 |
||
437 |
if (pc == NULL && uc != NULL) { |
|
438 |
pc = os::Linux::ucontext_get_pc(uc); |
|
439 |
} |
|
440 |
||
441 |
// unmask current signal |
|
442 |
sigset_t newset; |
|
443 |
sigemptyset(&newset); |
|
444 |
sigaddset(&newset, sig); |
|
445 |
sigprocmask(SIG_UNBLOCK, &newset, NULL); |
|
446 |
||
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32080
diff
changeset
|
447 |
VMError::report_and_die(t, sig, pc, info, ucVoid); |
29182 | 448 |
|
449 |
ShouldNotReachHere(); |
|
450 |
return true; // Mute compiler |
|
451 |
} |
|
452 |
||
453 |
void os::Linux::init_thread_fpu_state(void) { |
|
454 |
} |
|
455 |
||
456 |
int os::Linux::get_fpu_control_word(void) { |
|
457 |
return 0; |
|
458 |
} |
|
459 |
||
460 |
void os::Linux::set_fpu_control_word(int fpu_control) { |
|
461 |
} |
|
462 |
||
463 |
// Check that the linux kernel version is 2.4 or higher since earlier |
|
464 |
// versions do not support SSE without patches. |
|
465 |
bool os::supports_sse() { |
|
466 |
return true; |
|
467 |
} |
|
468 |
||
469 |
bool os::is_allocatable(size_t bytes) { |
|
470 |
return true; |
|
471 |
} |
|
472 |
||
473 |
//////////////////////////////////////////////////////////////////////////////// |
|
474 |
// thread stack |
|
475 |
||
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40010
diff
changeset
|
476 |
size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40010
diff
changeset
|
477 |
size_t os::Posix::_java_thread_min_stack_allowed = 64 * K; |
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40010
diff
changeset
|
478 |
size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K; |
29182 | 479 |
|
480 |
// return default stack size for thr_type |
|
41070
496463b4e206
8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents:
40010
diff
changeset
|
481 |
size_t os::Posix::default_stack_size(os::ThreadType thr_type) { |
29182 | 482 |
// default stack size (compiler thread needs larger stack) |
483 |
size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); |
|
484 |
return s; |
|
485 |
} |
|
486 |
||
487 |
size_t os::Linux::default_guard_size(os::ThreadType thr_type) { |
|
488 |
// Creating guard page is very expensive. Java thread has HotSpot |
|
489 |
// guard page, only enable glibc guard page for non-Java threads. |
|
490 |
return (thr_type == java_thread ? 0 : page_size()); |
|
491 |
} |
|
492 |
||
493 |
// Java thread: |
|
494 |
// |
|
495 |
// Low memory addresses |
|
496 |
// +------------------------+ |
|
497 |
// | |\ JavaThread created by VM does not have glibc |
|
498 |
// | glibc guard page | - guard, attached Java thread usually has |
|
499 |
// | |/ 1 page glibc guard. |
|
500 |
// P1 +------------------------+ Thread::stack_base() - Thread::stack_size() |
|
501 |
// | |\ |
|
502 |
// | HotSpot Guard Pages | - red and yellow pages |
|
503 |
// | |/ |
|
504 |
// +------------------------+ JavaThread::stack_yellow_zone_base() |
|
505 |
// | |\ |
|
506 |
// | Normal Stack | - |
|
507 |
// | |/ |
|
508 |
// P2 +------------------------+ Thread::stack_base() |
|
509 |
// |
|
510 |
// Non-Java thread: |
|
511 |
// |
|
512 |
// Low memory addresses |
|
513 |
// +------------------------+ |
|
514 |
// | |\ |
|
515 |
// | glibc guard page | - usually 1 page |
|
516 |
// | |/ |
|
517 |
// P1 +------------------------+ Thread::stack_base() - Thread::stack_size() |
|
518 |
// | |\ |
|
519 |
// | Normal Stack | - |
|
520 |
// | |/ |
|
521 |
// P2 +------------------------+ Thread::stack_base() |
|
522 |
// |
|
523 |
// ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from |
|
524 |
// pthread_attr_getstack() |
|
525 |
||
526 |
static void current_stack_region(address * bottom, size_t * size) { |
|
527 |
if (os::Linux::is_initial_thread()) { |
|
528 |
// initial thread needs special handling because pthread_getattr_np() |
|
529 |
// may return bogus value. |
|
530 |
*bottom = os::Linux::initial_thread_stack_bottom(); |
|
531 |
*size = os::Linux::initial_thread_stack_size(); |
|
532 |
} else { |
|
533 |
pthread_attr_t attr; |
|
534 |
||
535 |
int rslt = pthread_getattr_np(pthread_self(), &attr); |
|
536 |
||
537 |
// JVM needs to know exact stack location, abort if it fails |
|
538 |
if (rslt != 0) { |
|
539 |
if (rslt == ENOMEM) { |
|
540 |
vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); |
|
541 |
} else { |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32080
diff
changeset
|
542 |
fatal("pthread_getattr_np failed with errno = %d", rslt); |
29182 | 543 |
} |
544 |
} |
|
545 |
||
546 |
if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) { |
|
547 |
fatal("Can not locate current stack attributes!"); |
|
548 |
} |
|
549 |
||
550 |
pthread_attr_destroy(&attr); |
|
551 |
||
552 |
} |
|
553 |
assert(os::current_stack_pointer() >= *bottom && |
|
554 |
os::current_stack_pointer() < *bottom + *size, "just checking"); |
|
555 |
} |
|
556 |
||
557 |
address os::current_stack_base() { |
|
558 |
address bottom; |
|
559 |
size_t size; |
|
560 |
current_stack_region(&bottom, &size); |
|
561 |
return (bottom + size); |
|
562 |
} |
|
563 |
||
564 |
size_t os::current_stack_size() { |
|
565 |
// stack size includes normal stack and HotSpot guard pages |
|
566 |
address bottom; |
|
567 |
size_t size; |
|
568 |
current_stack_region(&bottom, &size); |
|
569 |
return size; |
|
570 |
} |
|
571 |
||
572 |
///////////////////////////////////////////////////////////////////////////// |
|
573 |
// helper functions for fatal error handler |
|
574 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
575 |
void os::print_context(outputStream *st, const void *context) { |
29182 | 576 |
if (context == NULL) return; |
577 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
578 |
const ucontext_t *uc = (const ucontext_t*)context; |
29182 | 579 |
st->print_cr("Registers:"); |
580 |
#ifdef BUILTIN_SIM |
|
581 |
st->print( "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]); |
|
582 |
st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]); |
|
583 |
st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]); |
|
584 |
st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]); |
|
585 |
st->cr(); |
|
586 |
st->print( "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]); |
|
587 |
st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]); |
|
588 |
st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]); |
|
589 |
st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]); |
|
590 |
st->cr(); |
|
591 |
st->print( "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]); |
|
592 |
st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]); |
|
593 |
st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]); |
|
594 |
st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]); |
|
595 |
st->cr(); |
|
596 |
st->print( "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]); |
|
597 |
st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]); |
|
598 |
st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]); |
|
599 |
st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]); |
|
600 |
st->cr(); |
|
601 |
st->print( "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]); |
|
602 |
st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]); |
|
603 |
st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]); |
|
604 |
st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]); |
|
605 |
st->cr(); |
|
606 |
st->print(" TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]); |
|
607 |
st->cr(); |
|
608 |
#else |
|
609 |
for (int r = 0; r < 31; r++) |
|
610 |
st->print_cr( "R%d=" INTPTR_FORMAT, r, (size_t)uc->uc_mcontext.regs[r]); |
|
611 |
#endif |
|
612 |
st->cr(); |
|
613 |
||
614 |
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); |
|
615 |
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp)); |
|
616 |
print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t)); |
|
617 |
st->cr(); |
|
618 |
||
619 |
// Note: it may be unsafe to inspect memory near pc. For example, pc may |
|
620 |
// point to garbage if entry point in an nmethod is corrupted. Leave |
|
621 |
// this at the end, and hope for the best. |
|
622 |
address pc = os::Linux::ucontext_get_pc(uc); |
|
623 |
st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc)); |
|
624 |
print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); |
|
625 |
} |
|
626 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
627 |
void os::print_register_info(outputStream *st, const void *context) { |
29182 | 628 |
if (context == NULL) return; |
629 |
||
35077
8b86440d3bf1
8145114: const-correctness for ucontext_t* reading functions
stuefe
parents:
34667
diff
changeset
|
630 |
const ucontext_t *uc = (const ucontext_t*)context; |
29182 | 631 |
|
632 |
st->print_cr("Register to memory mapping:"); |
|
633 |
st->cr(); |
|
634 |
||
635 |
// this is horrendously verbose but the layout of the registers in the |
|
636 |
// context does not match how we defined our abstract Register set, so |
|
637 |
// we can't just iterate through the gregs area |
|
638 |
||
639 |
// this is only for the "general purpose" registers |
|
640 |
||
641 |
#ifdef BUILTIN_SIM |
|
642 |
st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]); |
|
643 |
st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]); |
|
644 |
st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]); |
|
645 |
st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]); |
|
646 |
st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]); |
|
647 |
st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]); |
|
648 |
st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]); |
|
649 |
st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]); |
|
650 |
st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]); |
|
651 |
st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]); |
|
652 |
st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]); |
|
653 |
st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]); |
|
654 |
st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]); |
|
655 |
st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]); |
|
656 |
st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]); |
|
657 |
st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]); |
|
658 |
#else |
|
659 |
for (int r = 0; r < 31; r++) |
|
660 |
st->print_cr( "R%d=" INTPTR_FORMAT, r, (uintptr_t)uc->uc_mcontext.regs[r]); |
|
661 |
#endif |
|
662 |
st->cr(); |
|
663 |
} |
|
664 |
||
665 |
void os::setup_fpu() { |
|
666 |
} |
|
667 |
||
668 |
#ifndef PRODUCT |
|
669 |
void os::verify_stack_alignment() { |
|
670 |
assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment"); |
|
671 |
} |
|
672 |
#endif |
|
673 |
||
674 |
int os::extra_bang_size_in_bytes() { |
|
675 |
// AArch64 does not require the additional stack bang. |
|
676 |
return 0; |
|
677 |
} |
|
678 |
||
679 |
extern "C" { |
|
680 |
int SpinPause() { |
|
681 |
return 0; |
|
682 |
} |
|
683 |
||
684 |
void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { |
|
685 |
if (from > to) { |
|
686 |
jshort *end = from + count; |
|
687 |
while (from < end) |
|
688 |
*(to++) = *(from++); |
|
689 |
} |
|
690 |
else if (from < to) { |
|
691 |
jshort *end = from; |
|
692 |
from += count - 1; |
|
693 |
to += count - 1; |
|
694 |
while (from >= end) |
|
695 |
*(to--) = *(from--); |
|
696 |
} |
|
697 |
} |
|
698 |
void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) { |
|
699 |
if (from > to) { |
|
700 |
jint *end = from + count; |
|
701 |
while (from < end) |
|
702 |
*(to++) = *(from++); |
|
703 |
} |
|
704 |
else if (from < to) { |
|
705 |
jint *end = from; |
|
706 |
from += count - 1; |
|
707 |
to += count - 1; |
|
708 |
while (from >= end) |
|
709 |
*(to--) = *(from--); |
|
710 |
} |
|
711 |
} |
|
712 |
void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { |
|
713 |
if (from > to) { |
|
714 |
jlong *end = from + count; |
|
715 |
while (from < end) |
|
716 |
os::atomic_copy64(from++, to++); |
|
717 |
} |
|
718 |
else if (from < to) { |
|
719 |
jlong *end = from; |
|
720 |
from += count - 1; |
|
721 |
to += count - 1; |
|
722 |
while (from >= end) |
|
723 |
os::atomic_copy64(from--, to--); |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
void _Copy_arrayof_conjoint_bytes(HeapWord* from, |
|
728 |
HeapWord* to, |
|
729 |
size_t count) { |
|
730 |
memmove(to, from, count); |
|
731 |
} |
|
732 |
void _Copy_arrayof_conjoint_jshorts(HeapWord* from, |
|
733 |
HeapWord* to, |
|
734 |
size_t count) { |
|
735 |
memmove(to, from, count * 2); |
|
736 |
} |
|
737 |
void _Copy_arrayof_conjoint_jints(HeapWord* from, |
|
738 |
HeapWord* to, |
|
739 |
size_t count) { |
|
740 |
memmove(to, from, count * 4); |
|
741 |
} |
|
742 |
void _Copy_arrayof_conjoint_jlongs(HeapWord* from, |
|
743 |
HeapWord* to, |
|
744 |
size_t count) { |
|
745 |
memmove(to, from, count * 8); |
|
746 |
} |
|
747 |
}; |