29182
|
1 |
/*
|
|
2 |
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
|
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
5 |
*
|
|
6 |
* This code is free software; you can redistribute it and/or modify it
|
|
7 |
* under the terms of the GNU General Public License version 2 only, as
|
|
8 |
* published by the Free Software Foundation.
|
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
// no precompiled headers
|
|
27 |
#include "asm/macroAssembler.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 "code/nativeInst.hpp"
|
|
34 |
#include "interpreter/interpreter.hpp"
|
|
35 |
#include "jvm_linux.h"
|
|
36 |
#include "memory/allocation.inline.hpp"
|
|
37 |
#include "mutex_linux.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 |
|
|
111 |
address os::Linux::ucontext_get_pc(ucontext_t * uc) {
|
|
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 |
|
29182
|
127 |
intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) {
|
|
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 |
|
|
135 |
intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) {
|
|
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,
|
|
149 |
ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
|
|
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 |
|
|
158 |
ExtendedPC os::fetch_frame_from_context(void* ucVoid,
|
|
159 |
intptr_t** ret_sp, intptr_t** ret_fp) {
|
|
160 |
|
|
161 |
ExtendedPC epc;
|
|
162 |
ucontext_t* uc = (ucontext_t*)ucVoid;
|
|
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 |
|
|
178 |
frame os::fetch_frame_from_context(void* ucVoid) {
|
|
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 |
// An operation in Unsafe has faulted. We're going to return to the
|
|
229 |
// instruction after the faulting load or store. We also set
|
|
230 |
// pending_unsafe_access_error so that at some point in the future our
|
|
231 |
// user will get a helpful message.
|
|
232 |
static address handle_unsafe_access(JavaThread* thread, address pc) {
|
|
233 |
// pc is the instruction which we must emulate
|
|
234 |
// doing a no-op is fine: return garbage from the load
|
|
235 |
// therefore, compute npc
|
|
236 |
address npc = pc + NativeCall::instruction_size;
|
|
237 |
|
|
238 |
// request an async exception
|
|
239 |
thread->set_pending_unsafe_access_error();
|
|
240 |
|
|
241 |
// return address of next instruction to execute
|
|
242 |
return npc;
|
|
243 |
}
|
|
244 |
|
|
245 |
extern "C" JNIEXPORT int
|
|
246 |
JVM_handle_linux_signal(int sig,
|
|
247 |
siginfo_t* info,
|
|
248 |
void* ucVoid,
|
|
249 |
int abort_if_unrecognized) {
|
|
250 |
ucontext_t* uc = (ucontext_t*) ucVoid;
|
|
251 |
|
|
252 |
Thread* t = ThreadLocalStorage::get_thread_slow();
|
|
253 |
|
|
254 |
// Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
|
|
255 |
// (no destructors can be run)
|
|
256 |
os::WatcherThreadCrashProtection::check_crash_protection(sig, t);
|
|
257 |
|
|
258 |
SignalHandlerMark shm(t);
|
|
259 |
|
|
260 |
// Note: it's not uncommon that JNI code uses signal/sigset to install
|
|
261 |
// then restore certain signal handler (e.g. to temporarily block SIGPIPE,
|
|
262 |
// or have a SIGILL handler when detecting CPU type). When that happens,
|
|
263 |
// JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
|
|
264 |
// avoid unnecessary crash when libjsig is not preloaded, try handle signals
|
|
265 |
// that do not require siginfo/ucontext first.
|
|
266 |
|
|
267 |
if (sig == SIGPIPE || sig == SIGXFSZ) {
|
|
268 |
// allow chained handler to go first
|
|
269 |
if (os::Linux::chained_handler(sig, info, ucVoid)) {
|
|
270 |
return true;
|
|
271 |
} else {
|
|
272 |
if (PrintMiscellaneous && (WizardMode || Verbose)) {
|
|
273 |
char buf[64];
|
|
274 |
warning("Ignoring %s - see bugs 4229104 or 646499219",
|
|
275 |
os::exception_name(sig, buf, sizeof(buf)));
|
|
276 |
}
|
|
277 |
return true;
|
|
278 |
}
|
|
279 |
}
|
|
280 |
|
|
281 |
JavaThread* thread = NULL;
|
|
282 |
VMThread* vmthread = NULL;
|
|
283 |
if (os::Linux::signal_handlers_are_installed) {
|
|
284 |
if (t != NULL ){
|
|
285 |
if(t->is_Java_thread()) {
|
|
286 |
thread = (JavaThread*)t;
|
|
287 |
}
|
|
288 |
else if(t->is_VM_thread()){
|
|
289 |
vmthread = (VMThread *)t;
|
|
290 |
}
|
|
291 |
}
|
|
292 |
}
|
|
293 |
/*
|
|
294 |
NOTE: does not seem to work on linux.
|
|
295 |
if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
|
|
296 |
// can't decode this kind of signal
|
|
297 |
info = NULL;
|
|
298 |
} else {
|
|
299 |
assert(sig == info->si_signo, "bad siginfo");
|
|
300 |
}
|
|
301 |
*/
|
|
302 |
// decide if this trap can be handled by a stub
|
|
303 |
address stub = NULL;
|
|
304 |
|
|
305 |
address pc = NULL;
|
|
306 |
|
|
307 |
//%note os_trap_1
|
|
308 |
if (info != NULL && uc != NULL && thread != NULL) {
|
|
309 |
pc = (address) os::Linux::ucontext_get_pc(uc);
|
|
310 |
|
|
311 |
#ifdef BUILTIN_SIM
|
|
312 |
if (pc == (address) Fetch32PFI) {
|
|
313 |
uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ;
|
|
314 |
return 1 ;
|
|
315 |
}
|
|
316 |
if (pc == (address) FetchNPFI) {
|
|
317 |
uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ;
|
|
318 |
return 1 ;
|
|
319 |
}
|
|
320 |
#else
|
|
321 |
if (StubRoutines::is_safefetch_fault(pc)) {
|
29679
|
322 |
os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
|
29182
|
323 |
return 1;
|
|
324 |
}
|
|
325 |
#endif
|
|
326 |
|
|
327 |
// Handle ALL stack overflow variations here
|
|
328 |
if (sig == SIGSEGV) {
|
|
329 |
address addr = (address) info->si_addr;
|
|
330 |
|
|
331 |
// check if fault address is within thread stack
|
|
332 |
if (addr < thread->stack_base() &&
|
|
333 |
addr >= thread->stack_base() - thread->stack_size()) {
|
|
334 |
// stack overflow
|
|
335 |
if (thread->in_stack_yellow_zone(addr)) {
|
|
336 |
thread->disable_stack_yellow_zone();
|
|
337 |
if (thread->thread_state() == _thread_in_Java) {
|
|
338 |
// Throw a stack overflow exception. Guard pages will be reenabled
|
|
339 |
// while unwinding the stack.
|
|
340 |
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
|
|
341 |
} else {
|
|
342 |
// Thread was in the vm or native code. Return and try to finish.
|
|
343 |
return 1;
|
|
344 |
}
|
|
345 |
} else if (thread->in_stack_red_zone(addr)) {
|
|
346 |
// Fatal red zone violation. Disable the guard pages and fall through
|
|
347 |
// to handle_unexpected_exception way down below.
|
|
348 |
thread->disable_stack_red_zone();
|
|
349 |
tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
|
|
350 |
|
|
351 |
// This is a likely cause, but hard to verify. Let's just print
|
|
352 |
// it as a hint.
|
|
353 |
tty->print_raw_cr("Please check if any of your loaded .so files has "
|
|
354 |
"enabled executable stack (see man page execstack(8))");
|
|
355 |
} else {
|
|
356 |
// Accessing stack address below sp may cause SEGV if current
|
|
357 |
// thread has MAP_GROWSDOWN stack. This should only happen when
|
|
358 |
// current thread was created by user code with MAP_GROWSDOWN flag
|
|
359 |
// and then attached to VM. See notes in os_linux.cpp.
|
|
360 |
if (thread->osthread()->expanding_stack() == 0) {
|
|
361 |
thread->osthread()->set_expanding_stack();
|
|
362 |
if (os::Linux::manually_expand_stack(thread, addr)) {
|
|
363 |
thread->osthread()->clear_expanding_stack();
|
|
364 |
return 1;
|
|
365 |
}
|
|
366 |
thread->osthread()->clear_expanding_stack();
|
|
367 |
} else {
|
|
368 |
fatal("recursive segv. expanding stack.");
|
|
369 |
}
|
|
370 |
}
|
|
371 |
}
|
|
372 |
}
|
|
373 |
|
|
374 |
if (thread->thread_state() == _thread_in_Java) {
|
|
375 |
// Java thread running in Java code => find exception handler if any
|
|
376 |
// a fault inside compiled code, the interpreter, or a stub
|
|
377 |
|
|
378 |
// Handle signal from NativeJump::patch_verified_entry().
|
|
379 |
if ((sig == SIGILL || sig == SIGTRAP)
|
|
380 |
&& nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
|
|
381 |
if (TraceTraps) {
|
|
382 |
tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL");
|
|
383 |
}
|
|
384 |
stub = SharedRuntime::get_handle_wrong_method_stub();
|
|
385 |
} else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
|
|
386 |
stub = SharedRuntime::get_poll_stub(pc);
|
|
387 |
} else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
|
|
388 |
// BugId 4454115: A read from a MappedByteBuffer can fault
|
|
389 |
// here if the underlying file has been truncated.
|
|
390 |
// Do not crash the VM in such a case.
|
|
391 |
CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
|
|
392 |
nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL;
|
|
393 |
if (nm != NULL && nm->has_unsafe_access()) {
|
|
394 |
stub = handle_unsafe_access(thread, pc);
|
|
395 |
}
|
|
396 |
}
|
|
397 |
else
|
|
398 |
|
|
399 |
if (sig == SIGFPE &&
|
|
400 |
(info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
|
|
401 |
stub =
|
|
402 |
SharedRuntime::
|
|
403 |
continuation_for_implicit_exception(thread,
|
|
404 |
pc,
|
|
405 |
SharedRuntime::
|
|
406 |
IMPLICIT_DIVIDE_BY_ZERO);
|
|
407 |
} else if (sig == SIGSEGV &&
|
|
408 |
!MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
|
|
409 |
// Determination of interpreter/vtable stub/compiled code null exception
|
|
410 |
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
|
|
411 |
}
|
|
412 |
} else if (thread->thread_state() == _thread_in_vm &&
|
|
413 |
sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
|
|
414 |
thread->doing_unsafe_access()) {
|
|
415 |
stub = handle_unsafe_access(thread, pc);
|
|
416 |
}
|
|
417 |
|
|
418 |
// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
|
|
419 |
// and the heap gets shrunk before the field access.
|
|
420 |
if ((sig == SIGSEGV) || (sig == SIGBUS)) {
|
|
421 |
address addr = JNI_FastGetField::find_slowcase_pc(pc);
|
|
422 |
if (addr != (address)-1) {
|
|
423 |
stub = addr;
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
// Check to see if we caught the safepoint code in the
|
|
428 |
// process of write protecting the memory serialization page.
|
|
429 |
// It write enables the page immediately after protecting it
|
|
430 |
// so we can just return to retry the write.
|
|
431 |
if ((sig == SIGSEGV) &&
|
|
432 |
os::is_memory_serialize_page(thread, (address) info->si_addr)) {
|
|
433 |
// Block current thread until the memory serialize page permission restored.
|
|
434 |
os::block_on_serialize_page_trap();
|
|
435 |
return true;
|
|
436 |
}
|
|
437 |
}
|
|
438 |
|
|
439 |
if (stub != NULL) {
|
|
440 |
// save all thread context in case we need to restore it
|
|
441 |
if (thread != NULL) thread->set_saved_exception_pc(pc);
|
|
442 |
|
29679
|
443 |
os::Linux::ucontext_set_pc(uc, stub);
|
29182
|
444 |
return true;
|
|
445 |
}
|
|
446 |
|
|
447 |
// signal-chaining
|
|
448 |
if (os::Linux::chained_handler(sig, info, ucVoid)) {
|
|
449 |
return true;
|
|
450 |
}
|
|
451 |
|
|
452 |
if (!abort_if_unrecognized) {
|
|
453 |
// caller wants another chance, so give it to him
|
|
454 |
return false;
|
|
455 |
}
|
|
456 |
|
|
457 |
if (pc == NULL && uc != NULL) {
|
|
458 |
pc = os::Linux::ucontext_get_pc(uc);
|
|
459 |
}
|
|
460 |
|
|
461 |
// unmask current signal
|
|
462 |
sigset_t newset;
|
|
463 |
sigemptyset(&newset);
|
|
464 |
sigaddset(&newset, sig);
|
|
465 |
sigprocmask(SIG_UNBLOCK, &newset, NULL);
|
|
466 |
|
|
467 |
VMError err(t, sig, pc, info, ucVoid);
|
|
468 |
err.report_and_die();
|
|
469 |
|
|
470 |
ShouldNotReachHere();
|
|
471 |
return true; // Mute compiler
|
|
472 |
}
|
|
473 |
|
|
474 |
void os::Linux::init_thread_fpu_state(void) {
|
|
475 |
}
|
|
476 |
|
|
477 |
int os::Linux::get_fpu_control_word(void) {
|
|
478 |
return 0;
|
|
479 |
}
|
|
480 |
|
|
481 |
void os::Linux::set_fpu_control_word(int fpu_control) {
|
|
482 |
}
|
|
483 |
|
|
484 |
// Check that the linux kernel version is 2.4 or higher since earlier
|
|
485 |
// versions do not support SSE without patches.
|
|
486 |
bool os::supports_sse() {
|
|
487 |
return true;
|
|
488 |
}
|
|
489 |
|
|
490 |
bool os::is_allocatable(size_t bytes) {
|
|
491 |
return true;
|
|
492 |
}
|
|
493 |
|
|
494 |
////////////////////////////////////////////////////////////////////////////////
|
|
495 |
// thread stack
|
|
496 |
|
|
497 |
size_t os::Linux::min_stack_allowed = 64 * K;
|
|
498 |
|
|
499 |
// aarch64: pthread on aarch64 is always in floating stack mode
|
|
500 |
bool os::Linux::supports_variable_stack_size() { return true; }
|
|
501 |
|
|
502 |
// return default stack size for thr_type
|
|
503 |
size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
|
|
504 |
// default stack size (compiler thread needs larger stack)
|
|
505 |
size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
|
|
506 |
return s;
|
|
507 |
}
|
|
508 |
|
|
509 |
size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
|
|
510 |
// Creating guard page is very expensive. Java thread has HotSpot
|
|
511 |
// guard page, only enable glibc guard page for non-Java threads.
|
|
512 |
return (thr_type == java_thread ? 0 : page_size());
|
|
513 |
}
|
|
514 |
|
|
515 |
// Java thread:
|
|
516 |
//
|
|
517 |
// Low memory addresses
|
|
518 |
// +------------------------+
|
|
519 |
// | |\ JavaThread created by VM does not have glibc
|
|
520 |
// | glibc guard page | - guard, attached Java thread usually has
|
|
521 |
// | |/ 1 page glibc guard.
|
|
522 |
// P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
|
|
523 |
// | |\
|
|
524 |
// | HotSpot Guard Pages | - red and yellow pages
|
|
525 |
// | |/
|
|
526 |
// +------------------------+ JavaThread::stack_yellow_zone_base()
|
|
527 |
// | |\
|
|
528 |
// | Normal Stack | -
|
|
529 |
// | |/
|
|
530 |
// P2 +------------------------+ Thread::stack_base()
|
|
531 |
//
|
|
532 |
// Non-Java thread:
|
|
533 |
//
|
|
534 |
// Low memory addresses
|
|
535 |
// +------------------------+
|
|
536 |
// | |\
|
|
537 |
// | glibc guard page | - usually 1 page
|
|
538 |
// | |/
|
|
539 |
// P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
|
|
540 |
// | |\
|
|
541 |
// | Normal Stack | -
|
|
542 |
// | |/
|
|
543 |
// P2 +------------------------+ Thread::stack_base()
|
|
544 |
//
|
|
545 |
// ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
|
|
546 |
// pthread_attr_getstack()
|
|
547 |
|
|
548 |
static void current_stack_region(address * bottom, size_t * size) {
|
|
549 |
if (os::Linux::is_initial_thread()) {
|
|
550 |
// initial thread needs special handling because pthread_getattr_np()
|
|
551 |
// may return bogus value.
|
|
552 |
*bottom = os::Linux::initial_thread_stack_bottom();
|
|
553 |
*size = os::Linux::initial_thread_stack_size();
|
|
554 |
} else {
|
|
555 |
pthread_attr_t attr;
|
|
556 |
|
|
557 |
int rslt = pthread_getattr_np(pthread_self(), &attr);
|
|
558 |
|
|
559 |
// JVM needs to know exact stack location, abort if it fails
|
|
560 |
if (rslt != 0) {
|
|
561 |
if (rslt == ENOMEM) {
|
|
562 |
vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
|
|
563 |
} else {
|
|
564 |
fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
|
|
565 |
}
|
|
566 |
}
|
|
567 |
|
|
568 |
if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
|
|
569 |
fatal("Can not locate current stack attributes!");
|
|
570 |
}
|
|
571 |
|
|
572 |
pthread_attr_destroy(&attr);
|
|
573 |
|
|
574 |
}
|
|
575 |
assert(os::current_stack_pointer() >= *bottom &&
|
|
576 |
os::current_stack_pointer() < *bottom + *size, "just checking");
|
|
577 |
}
|
|
578 |
|
|
579 |
address os::current_stack_base() {
|
|
580 |
address bottom;
|
|
581 |
size_t size;
|
|
582 |
current_stack_region(&bottom, &size);
|
|
583 |
return (bottom + size);
|
|
584 |
}
|
|
585 |
|
|
586 |
size_t os::current_stack_size() {
|
|
587 |
// stack size includes normal stack and HotSpot guard pages
|
|
588 |
address bottom;
|
|
589 |
size_t size;
|
|
590 |
current_stack_region(&bottom, &size);
|
|
591 |
return size;
|
|
592 |
}
|
|
593 |
|
|
594 |
/////////////////////////////////////////////////////////////////////////////
|
|
595 |
// helper functions for fatal error handler
|
|
596 |
|
|
597 |
void os::print_context(outputStream *st, void *context) {
|
|
598 |
if (context == NULL) return;
|
|
599 |
|
|
600 |
ucontext_t *uc = (ucontext_t*)context;
|
|
601 |
st->print_cr("Registers:");
|
|
602 |
#ifdef BUILTIN_SIM
|
|
603 |
st->print( "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
|
|
604 |
st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
|
|
605 |
st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]);
|
|
606 |
st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]);
|
|
607 |
st->cr();
|
|
608 |
st->print( "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]);
|
|
609 |
st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]);
|
|
610 |
st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]);
|
|
611 |
st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]);
|
|
612 |
st->cr();
|
|
613 |
st->print( "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]);
|
|
614 |
st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]);
|
|
615 |
st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]);
|
|
616 |
st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]);
|
|
617 |
st->cr();
|
|
618 |
st->print( "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]);
|
|
619 |
st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]);
|
|
620 |
st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]);
|
|
621 |
st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]);
|
|
622 |
st->cr();
|
|
623 |
st->print( "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]);
|
|
624 |
st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
|
|
625 |
st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]);
|
|
626 |
st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]);
|
|
627 |
st->cr();
|
|
628 |
st->print(" TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]);
|
|
629 |
st->cr();
|
|
630 |
#else
|
|
631 |
for (int r = 0; r < 31; r++)
|
|
632 |
st->print_cr( "R%d=" INTPTR_FORMAT, r, (size_t)uc->uc_mcontext.regs[r]);
|
|
633 |
#endif
|
|
634 |
st->cr();
|
|
635 |
|
|
636 |
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
|
|
637 |
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
|
|
638 |
print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
|
|
639 |
st->cr();
|
|
640 |
|
|
641 |
// Note: it may be unsafe to inspect memory near pc. For example, pc may
|
|
642 |
// point to garbage if entry point in an nmethod is corrupted. Leave
|
|
643 |
// this at the end, and hope for the best.
|
|
644 |
address pc = os::Linux::ucontext_get_pc(uc);
|
|
645 |
st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
|
|
646 |
print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
|
|
647 |
}
|
|
648 |
|
|
649 |
void os::print_register_info(outputStream *st, void *context) {
|
|
650 |
if (context == NULL) return;
|
|
651 |
|
|
652 |
ucontext_t *uc = (ucontext_t*)context;
|
|
653 |
|
|
654 |
st->print_cr("Register to memory mapping:");
|
|
655 |
st->cr();
|
|
656 |
|
|
657 |
// this is horrendously verbose but the layout of the registers in the
|
|
658 |
// context does not match how we defined our abstract Register set, so
|
|
659 |
// we can't just iterate through the gregs area
|
|
660 |
|
|
661 |
// this is only for the "general purpose" registers
|
|
662 |
|
|
663 |
#ifdef BUILTIN_SIM
|
|
664 |
st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]);
|
|
665 |
st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]);
|
|
666 |
st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]);
|
|
667 |
st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]);
|
|
668 |
st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]);
|
|
669 |
st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]);
|
|
670 |
st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]);
|
|
671 |
st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]);
|
|
672 |
st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]);
|
|
673 |
st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]);
|
|
674 |
st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]);
|
|
675 |
st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]);
|
|
676 |
st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]);
|
|
677 |
st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]);
|
|
678 |
st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]);
|
|
679 |
st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]);
|
|
680 |
#else
|
|
681 |
for (int r = 0; r < 31; r++)
|
|
682 |
st->print_cr( "R%d=" INTPTR_FORMAT, r, (uintptr_t)uc->uc_mcontext.regs[r]);
|
|
683 |
#endif
|
|
684 |
st->cr();
|
|
685 |
}
|
|
686 |
|
|
687 |
void os::setup_fpu() {
|
|
688 |
}
|
|
689 |
|
|
690 |
#ifndef PRODUCT
|
|
691 |
void os::verify_stack_alignment() {
|
|
692 |
assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
|
|
693 |
}
|
|
694 |
#endif
|
|
695 |
|
|
696 |
int os::extra_bang_size_in_bytes() {
|
|
697 |
// AArch64 does not require the additional stack bang.
|
|
698 |
return 0;
|
|
699 |
}
|
|
700 |
|
|
701 |
extern "C" {
|
|
702 |
int SpinPause() {
|
|
703 |
return 0;
|
|
704 |
}
|
|
705 |
|
|
706 |
void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
|
|
707 |
if (from > to) {
|
|
708 |
jshort *end = from + count;
|
|
709 |
while (from < end)
|
|
710 |
*(to++) = *(from++);
|
|
711 |
}
|
|
712 |
else if (from < to) {
|
|
713 |
jshort *end = from;
|
|
714 |
from += count - 1;
|
|
715 |
to += count - 1;
|
|
716 |
while (from >= end)
|
|
717 |
*(to--) = *(from--);
|
|
718 |
}
|
|
719 |
}
|
|
720 |
void _Copy_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
|
|
721 |
if (from > to) {
|
|
722 |
jint *end = from + count;
|
|
723 |
while (from < end)
|
|
724 |
*(to++) = *(from++);
|
|
725 |
}
|
|
726 |
else if (from < to) {
|
|
727 |
jint *end = from;
|
|
728 |
from += count - 1;
|
|
729 |
to += count - 1;
|
|
730 |
while (from >= end)
|
|
731 |
*(to--) = *(from--);
|
|
732 |
}
|
|
733 |
}
|
|
734 |
void _Copy_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
|
|
735 |
if (from > to) {
|
|
736 |
jlong *end = from + count;
|
|
737 |
while (from < end)
|
|
738 |
os::atomic_copy64(from++, to++);
|
|
739 |
}
|
|
740 |
else if (from < to) {
|
|
741 |
jlong *end = from;
|
|
742 |
from += count - 1;
|
|
743 |
to += count - 1;
|
|
744 |
while (from >= end)
|
|
745 |
os::atomic_copy64(from--, to--);
|
|
746 |
}
|
|
747 |
}
|
|
748 |
|
|
749 |
void _Copy_arrayof_conjoint_bytes(HeapWord* from,
|
|
750 |
HeapWord* to,
|
|
751 |
size_t count) {
|
|
752 |
memmove(to, from, count);
|
|
753 |
}
|
|
754 |
void _Copy_arrayof_conjoint_jshorts(HeapWord* from,
|
|
755 |
HeapWord* to,
|
|
756 |
size_t count) {
|
|
757 |
memmove(to, from, count * 2);
|
|
758 |
}
|
|
759 |
void _Copy_arrayof_conjoint_jints(HeapWord* from,
|
|
760 |
HeapWord* to,
|
|
761 |
size_t count) {
|
|
762 |
memmove(to, from, count * 4);
|
|
763 |
}
|
|
764 |
void _Copy_arrayof_conjoint_jlongs(HeapWord* from,
|
|
765 |
HeapWord* to,
|
|
766 |
size_t count) {
|
|
767 |
memmove(to, from, count * 8);
|
|
768 |
}
|
|
769 |
};
|