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