annotate hotspot/src/os_cpu/linux_s390/vm/os_linux_s390.cpp @ 46361:b4c026dd6128

8176872: [s390] wrong pc shown in error logs Reviewed-by: dholmes, dsamersoff
author stuefe
date Tue, 21 Mar 2017 14:14:06 +0100
parents a056d6465ef9
children a5813fb66270
rev   line source
goetz@42065 1 /*
goetz@42065 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
goetz@42065 3 * Copyright (c) 2016 SAP SE. All rights reserved.
goetz@42065 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@42065 5 *
goetz@42065 6 * This code is free software; you can redistribute it and/or modify it
goetz@42065 7 * under the terms of the GNU General Public License version 2 only, as
goetz@42065 8 * published by the Free Software Foundation.
goetz@42065 9 *
goetz@42065 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@42065 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@42065 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@42065 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@42065 14 * accompanied this code).
goetz@42065 15 *
goetz@42065 16 * You should have received a copy of the GNU General Public License version
goetz@42065 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@42065 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@42065 19 *
goetz@42065 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@42065 21 * or visit www.oracle.com if you need additional information or have any
goetz@42065 22 * questions.
goetz@42065 23 *
goetz@42065 24 */
goetz@42065 25
goetz@42065 26 // This file is organized as os_linux_x86.cpp.
goetz@42065 27
goetz@42065 28 // no precompiled headers
goetz@42065 29 #include "asm/assembler.inline.hpp"
goetz@42065 30 #include "classfile/classLoader.hpp"
goetz@42065 31 #include "classfile/systemDictionary.hpp"
goetz@42065 32 #include "classfile/vmSymbols.hpp"
goetz@42065 33 #include "code/icBuffer.hpp"
goetz@42065 34 #include "code/nativeInst.hpp"
goetz@42065 35 #include "code/vtableStubs.hpp"
goetz@42065 36 #include "compiler/disassembler.hpp"
goetz@42065 37 #include "interpreter/interpreter.hpp"
goetz@42065 38 #include "jvm_linux.h"
goetz@42065 39 #include "memory/allocation.inline.hpp"
goetz@42065 40 #include "nativeInst_s390.hpp"
goetz@42065 41 #include "os_share_linux.hpp"
goetz@42065 42 #include "prims/jniFastGetField.hpp"
goetz@42065 43 #include "prims/jvm.h"
goetz@42065 44 #include "prims/jvm_misc.hpp"
goetz@42065 45 #include "runtime/arguments.hpp"
goetz@42065 46 #include "runtime/extendedPC.hpp"
goetz@42065 47 #include "runtime/frame.inline.hpp"
goetz@42065 48 #include "runtime/interfaceSupport.hpp"
goetz@42065 49 #include "runtime/java.hpp"
goetz@42065 50 #include "runtime/javaCalls.hpp"
goetz@42065 51 #include "runtime/mutexLocker.hpp"
goetz@42065 52 #include "runtime/osThread.hpp"
goetz@42065 53 #include "runtime/sharedRuntime.hpp"
goetz@42065 54 #include "runtime/stubRoutines.hpp"
goetz@42065 55 #include "runtime/thread.inline.hpp"
goetz@42065 56 #include "runtime/timer.hpp"
goetz@42065 57 #include "utilities/events.hpp"
goetz@42065 58 #include "utilities/vmError.hpp"
goetz@42065 59
goetz@42065 60 // put OS-includes here
goetz@42065 61 # include <sys/types.h>
goetz@42065 62 # include <sys/mman.h>
goetz@42065 63 # include <pthread.h>
goetz@42065 64 # include <signal.h>
goetz@42065 65 # include <errno.h>
goetz@42065 66 # include <dlfcn.h>
goetz@42065 67 # include <stdlib.h>
goetz@42065 68 # include <stdio.h>
goetz@42065 69 # include <unistd.h>
goetz@42065 70 # include <sys/resource.h>
goetz@42065 71 # include <pthread.h>
goetz@42065 72 # include <sys/stat.h>
goetz@42065 73 # include <sys/time.h>
goetz@42065 74 # include <sys/utsname.h>
goetz@42065 75 # include <sys/socket.h>
goetz@42065 76 # include <sys/wait.h>
goetz@42065 77 # include <pwd.h>
goetz@42065 78 # include <poll.h>
goetz@42065 79 # include <ucontext.h>
goetz@42065 80
goetz@42065 81 address os::current_stack_pointer() {
goetz@42065 82 intptr_t* csp;
goetz@42065 83
goetz@42065 84 // Inline assembly for `z_lgr regno(csp), Z_SP' (Z_SP = Z_R15):
goetz@42065 85 __asm__ __volatile__ ("lgr %0, 15":"=r"(csp):);
goetz@42065 86
goetz@42065 87 assert(((uint64_t)csp & (frame::alignment_in_bytes-1)) == 0, "SP must be aligned");
goetz@42065 88 return (address) csp;
goetz@42065 89 }
goetz@42065 90
goetz@42065 91 char* os::non_memory_address_word() {
goetz@42065 92 // Must never look like an address returned by reserve_memory,
goetz@42065 93 // even in its subfields (as defined by the CPU immediate fields,
goetz@42065 94 // if the CPU splits constants across multiple instructions).
goetz@42065 95 return (char*) -1;
goetz@42065 96 }
goetz@42065 97
goetz@42065 98 // OS specific thread initialization.
goetz@42065 99 void os::initialize_thread(Thread* thread) { }
goetz@42065 100
goetz@42065 101 // Frame information (pc, sp, fp) retrieved via ucontext
goetz@42065 102 // always looks like a C-frame according to the frame
goetz@42065 103 // conventions in frame_s390.hpp.
goetz@42065 104 address os::Linux::ucontext_get_pc(const ucontext_t * uc) {
goetz@42065 105 return (address)uc->uc_mcontext.psw.addr;
goetz@42065 106 }
goetz@42065 107
goetz@42065 108 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
goetz@42065 109 uc->uc_mcontext.psw.addr = (unsigned long)pc;
goetz@42065 110 }
goetz@42065 111
goetz@42065 112 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
goetz@42065 113 return (intptr_t*)uc->uc_mcontext.gregs[15/*REG_SP*/];
goetz@42065 114 }
goetz@42065 115
goetz@42065 116 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
goetz@42065 117 return NULL;
goetz@42065 118 }
goetz@42065 119
goetz@42065 120 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
goetz@42065 121 intptr_t** ret_sp, intptr_t** ret_fp) {
goetz@42065 122
goetz@42065 123 ExtendedPC epc;
goetz@42065 124 const ucontext_t* uc = (const ucontext_t*)ucVoid;
goetz@42065 125
goetz@42065 126 if (uc != NULL) {
goetz@42065 127 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
goetz@42065 128 if (ret_sp) { *ret_sp = os::Linux::ucontext_get_sp(uc); }
goetz@42065 129 if (ret_fp) { *ret_fp = os::Linux::ucontext_get_fp(uc); }
goetz@42065 130 } else {
goetz@42065 131 // Construct empty ExtendedPC for return value checking.
goetz@42065 132 epc = ExtendedPC(NULL);
goetz@42065 133 if (ret_sp) { *ret_sp = (intptr_t *)NULL; }
goetz@42065 134 if (ret_fp) { *ret_fp = (intptr_t *)NULL; }
goetz@42065 135 }
goetz@42065 136
goetz@42065 137 return epc;
goetz@42065 138 }
goetz@42065 139
goetz@42065 140 frame os::fetch_frame_from_context(const void* ucVoid) {
goetz@42065 141 intptr_t* sp;
goetz@42065 142 intptr_t* fp;
goetz@42065 143 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
goetz@42065 144 return frame(sp, epc.pc());
goetz@42065 145 }
goetz@42065 146
goetz@43420 147 bool os::Linux::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
goetz@43420 148 address pc = (address) os::Linux::ucontext_get_pc(uc);
goetz@43420 149 if (Interpreter::contains(pc)) {
goetz@43420 150 // Interpreter performs stack banging after the fixed frame header has
goetz@43420 151 // been generated while the compilers perform it before. To maintain
goetz@43420 152 // semantic consistency between interpreted and compiled frames, the
goetz@43420 153 // method returns the Java sender of the current frame.
goetz@43420 154 *fr = os::fetch_frame_from_context(uc);
goetz@43420 155 if (!fr->is_first_java_frame()) {
goetz@43420 156 assert(fr->safe_for_sender(thread), "Safety check");
goetz@43420 157 *fr = fr->java_sender();
goetz@43420 158 }
goetz@43420 159 } else {
goetz@43420 160 // More complex code with compiled code.
goetz@43420 161 assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
goetz@43420 162 CodeBlob* cb = CodeCache::find_blob(pc);
goetz@43420 163 if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
goetz@43420 164 // Not sure where the pc points to, fallback to default
goetz@43420 165 // stack overflow handling. In compiled code, we bang before
goetz@43420 166 // the frame is complete.
goetz@43420 167 return false;
goetz@43420 168 } else {
goetz@43420 169 intptr_t* fp = os::Linux::ucontext_get_fp(uc);
goetz@43420 170 intptr_t* sp = os::Linux::ucontext_get_sp(uc);
goetz@43420 171 *fr = frame(sp, (address)*sp);
goetz@43420 172 if (!fr->is_java_frame()) {
goetz@43420 173 assert(fr->safe_for_sender(thread), "Safety check");
goetz@43420 174 assert(!fr->is_first_frame(), "Safety check");
goetz@43420 175 *fr = fr->java_sender();
goetz@43420 176 }
goetz@43420 177 }
goetz@43420 178 }
goetz@43420 179 assert(fr->is_java_frame(), "Safety check");
goetz@43420 180 return true;
goetz@43420 181 }
goetz@43420 182
goetz@42065 183 frame os::get_sender_for_C_frame(frame* fr) {
goetz@42065 184 if (*fr->sp() == 0) {
goetz@42065 185 // fr is the last C frame.
goetz@42065 186 return frame();
goetz@42065 187 }
goetz@42065 188
goetz@42065 189 // If its not one of our frames, the return pc is saved at gpr14
goetz@42065 190 // stack slot. The call_stub stores the return_pc to the stack slot
goetz@42065 191 // of gpr10.
goetz@42065 192 if ((Interpreter::code() != NULL && Interpreter::contains(fr->pc())) ||
goetz@42065 193 (CodeCache::contains(fr->pc()) && !StubRoutines::contains(fr->pc()))) {
goetz@42065 194 return frame(fr->sender_sp(), fr->sender_pc());
goetz@42065 195 } else {
goetz@42065 196 if (StubRoutines::contains(fr->pc())) {
goetz@42065 197 StubCodeDesc* desc = StubCodeDesc::desc_for(fr->pc());
goetz@42065 198 if (desc && !strcmp(desc->name(),"call_stub")) {
goetz@42065 199 return frame(fr->sender_sp(), fr->callstub_sender_pc());
goetz@42065 200 } else {
goetz@42065 201 return frame(fr->sender_sp(), fr->sender_pc());
goetz@42065 202 }
goetz@42065 203 } else {
goetz@42065 204 return frame(fr->sender_sp(), fr->native_sender_pc());
goetz@42065 205 }
goetz@42065 206 }
goetz@42065 207 }
goetz@42065 208
goetz@42065 209 frame os::current_frame() {
goetz@42556 210 // Expected to return the stack pointer of this method.
goetz@42556 211 // But if inlined, returns the stack pointer of our caller!
goetz@42065 212 intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
goetz@42065 213 assert (csp != NULL, "sp should not be NULL");
goetz@42065 214 // Pass a dummy pc. This way we don't have to load it from the
goetz@42065 215 // stack, since we don't know in which slot we can find it.
goetz@42065 216 frame topframe(csp, (address)0x8);
goetz@42065 217 if (os::is_first_C_frame(&topframe)) {
goetz@42065 218 // Stack is not walkable.
goetz@42065 219 return frame();
goetz@42065 220 } else {
goetz@42065 221 frame senderFrame = os::get_sender_for_C_frame(&topframe);
goetz@42065 222 assert(senderFrame.pc() != NULL, "Sender pc should not be NULL");
goetz@42065 223 // Return sender of sender of current topframe which hopefully
goetz@42065 224 // both have pc != NULL.
goetz@42556 225 #ifdef _NMT_NOINLINE_ // Is set in slowdebug builds.
goetz@42556 226 // Current_stack_pointer is not inlined, we must pop one more frame.
goetz@42065 227 frame tmp = os::get_sender_for_C_frame(&topframe);
goetz@42065 228 return os::get_sender_for_C_frame(&tmp);
goetz@42556 229 #else
goetz@42556 230 return os::get_sender_for_C_frame(&topframe);
goetz@42556 231 #endif
goetz@42065 232 }
goetz@42065 233 }
goetz@42065 234
goetz@42065 235 // Utility functions
goetz@42065 236
goetz@42065 237 extern "C" JNIEXPORT int
goetz@42065 238 JVM_handle_linux_signal(int sig,
goetz@42065 239 siginfo_t* info,
goetz@42065 240 void* ucVoid,
goetz@42065 241 int abort_if_unrecognized) {
goetz@42065 242 ucontext_t* uc = (ucontext_t*) ucVoid;
goetz@42065 243
goetz@42065 244 Thread* t = Thread::current_or_null_safe();
goetz@42065 245
goetz@42065 246 // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
goetz@42065 247 // (no destructors can be run).
goetz@42065 248 os::WatcherThreadCrashProtection::check_crash_protection(sig, t);
goetz@42065 249
goetz@42065 250 SignalHandlerMark shm(t);
goetz@42065 251
goetz@42065 252 // Note: it's not uncommon that JNI code uses signal/sigset to install
goetz@42065 253 // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
goetz@42065 254 // or have a SIGILL handler when detecting CPU type). When that happens,
goetz@42065 255 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
goetz@42065 256 // avoid unnecessary crash when libjsig is not preloaded, try handle signals
goetz@42065 257 // that do not require siginfo/ucontext first.
goetz@42065 258
goetz@42065 259 if (sig == SIGPIPE) {
goetz@42065 260 if (os::Linux::chained_handler(sig, info, ucVoid)) {
goetz@42065 261 return true;
goetz@42065 262 } else {
goetz@42065 263 if (PrintMiscellaneous && (WizardMode || Verbose)) {
goetz@42065 264 warning("Ignoring SIGPIPE - see bug 4229104");
goetz@42065 265 }
goetz@42065 266 return true;
goetz@42065 267 }
goetz@42065 268 }
goetz@42065 269
goetz@42065 270 JavaThread* thread = NULL;
goetz@42065 271 VMThread* vmthread = NULL;
goetz@42065 272 if (os::Linux::signal_handlers_are_installed) {
goetz@42065 273 if (t != NULL) {
goetz@42065 274 if(t->is_Java_thread()) {
goetz@42065 275 thread = (JavaThread*)t;
goetz@42065 276 } else if(t->is_VM_thread()) {
goetz@42065 277 vmthread = (VMThread *)t;
goetz@42065 278 }
goetz@42065 279 }
goetz@42065 280 }
goetz@42065 281
goetz@42065 282 // Moved SafeFetch32 handling outside thread!=NULL conditional block to make
goetz@42065 283 // it work if no associated JavaThread object exists.
goetz@42065 284 if (uc) {
goetz@42065 285 address const pc = os::Linux::ucontext_get_pc(uc);
goetz@42065 286 if (pc && StubRoutines::is_safefetch_fault(pc)) {
goetz@42065 287 os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
goetz@42065 288 return true;
goetz@42065 289 }
goetz@42065 290 }
goetz@42065 291
goetz@42065 292 // Decide if this trap can be handled by a stub.
goetz@42065 293 address stub = NULL;
goetz@42065 294 address pc = NULL; // Pc as retrieved from PSW. Usually points past failing instruction.
goetz@42065 295 address trap_pc = NULL; // Pc of the instruction causing the trap.
goetz@42065 296
goetz@42065 297 //%note os_trap_1
goetz@42065 298 if (info != NULL && uc != NULL && thread != NULL) {
goetz@42065 299 pc = os::Linux::ucontext_get_pc(uc);
goetz@42065 300 if (TraceTraps) {
goetz@42065 301 tty->print_cr(" pc at " INTPTR_FORMAT, p2i(pc));
goetz@42065 302 }
goetz@42065 303 if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {
goetz@42065 304 trap_pc = (address)info->si_addr;
goetz@42065 305 if (TraceTraps) {
goetz@42065 306 tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));
goetz@42065 307 }
goetz@42065 308 }
goetz@42065 309
goetz@42065 310 // Handle ALL stack overflow variations here
goetz@42065 311 if (sig == SIGSEGV) {
goetz@42065 312 address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.
goetz@42065 313
goetz@42065 314 // Check if fault address is within thread stack.
goetz@42065 315 if (thread->on_local_stack(addr)) {
goetz@42065 316 // stack overflow
goetz@42065 317 if (thread->in_stack_yellow_reserved_zone(addr)) {
goetz@42065 318 if (thread->thread_state() == _thread_in_Java) {
goetz@43420 319 if (thread->in_stack_reserved_zone(addr)) {
goetz@43420 320 frame fr;
goetz@43420 321 if (os::Linux::get_frame_at_stack_banging_point(thread, uc, &fr)) {
goetz@43420 322 assert(fr.is_java_frame(), "Must be a Javac frame");
goetz@43420 323 frame activation =
goetz@43420 324 SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
goetz@43420 325 if (activation.sp() != NULL) {
goetz@43420 326 thread->disable_stack_reserved_zone();
goetz@43420 327 if (activation.is_interpreted_frame()) {
goetz@43420 328 thread->set_reserved_stack_activation((address)activation.fp());
goetz@43420 329 } else {
goetz@43420 330 thread->set_reserved_stack_activation((address)activation.unextended_sp());
goetz@43420 331 }
goetz@43420 332 return 1;
goetz@43420 333 }
goetz@43420 334 }
goetz@43420 335 }
goetz@42065 336 // Throw a stack overflow exception.
goetz@42065 337 // Guard pages will be reenabled while unwinding the stack.
goetz@43420 338 thread->disable_stack_yellow_reserved_zone();
goetz@42065 339 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
goetz@42065 340 } else {
goetz@42065 341 // Thread was in the vm or native code. Return and try to finish.
goetz@43420 342 thread->disable_stack_yellow_reserved_zone();
goetz@42065 343 return 1;
goetz@42065 344 }
goetz@42065 345 } else if (thread->in_stack_red_zone(addr)) {
goetz@42065 346 // Fatal red zone violation. Disable the guard pages and fall through
goetz@42065 347 // to handle_unexpected_exception way down below.
goetz@42065 348 thread->disable_stack_red_zone();
goetz@42065 349 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
goetz@42065 350
goetz@42065 351 // This is a likely cause, but hard to verify. Let's just print
goetz@42065 352 // it as a hint.
goetz@42065 353 tty->print_raw_cr("Please check if any of your loaded .so files has "
goetz@42065 354 "enabled executable stack (see man page execstack(8))");
goetz@42065 355 } else {
goetz@42065 356 // Accessing stack address below sp may cause SEGV if current
goetz@42065 357 // thread has MAP_GROWSDOWN stack. This should only happen when
goetz@42065 358 // current thread was created by user code with MAP_GROWSDOWN flag
goetz@42065 359 // and then attached to VM. See notes in os_linux.cpp.
goetz@42065 360 if (thread->osthread()->expanding_stack() == 0) {
goetz@42065 361 thread->osthread()->set_expanding_stack();
goetz@42065 362 if (os::Linux::manually_expand_stack(thread, addr)) {
goetz@42065 363 thread->osthread()->clear_expanding_stack();
goetz@42065 364 return 1;
goetz@42065 365 }
goetz@42065 366 thread->osthread()->clear_expanding_stack();
goetz@42065 367 } else {
goetz@42065 368 fatal("recursive segv. expanding stack.");
goetz@42065 369 }
goetz@42065 370 }
goetz@42065 371 }
goetz@42065 372 }
goetz@42065 373
goetz@42065 374 if (thread->thread_state() == _thread_in_Java) {
goetz@42065 375 // Java thread running in Java code => find exception handler if any
goetz@42065 376 // a fault inside compiled code, the interpreter, or a stub
goetz@42065 377
goetz@42065 378 // Handle signal from NativeJump::patch_verified_entry().
goetz@42065 379 if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
goetz@42065 380 if (TraceTraps) {
goetz@42065 381 tty->print_cr("trap: zombie_not_entrant (SIGILL)");
goetz@42065 382 }
goetz@42065 383 stub = SharedRuntime::get_handle_wrong_method_stub();
goetz@42065 384 }
goetz@42065 385
goetz@42065 386 else if (sig == SIGSEGV &&
goetz@42065 387 os::is_poll_address((address)info->si_addr)) {
goetz@42065 388 if (TraceTraps) {
goetz@42065 389 tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
goetz@42065 390 }
goetz@42065 391 stub = SharedRuntime::get_poll_stub(pc);
goetz@42065 392
goetz@42065 393 // Info->si_addr only points to the page base address, so we
goetz@42065 394 // must extract the real si_addr from the instruction and the
goetz@42065 395 // ucontext.
goetz@42065 396 assert(((NativeInstruction*)pc)->is_safepoint_poll(), "must be safepoint poll");
goetz@42065 397 const address real_si_addr = ((NativeInstruction*)pc)->get_poll_address(uc);
goetz@42065 398 }
goetz@42065 399
goetz@42065 400 // SIGTRAP-based implicit null check in compiled code.
goetz@42065 401 else if ((sig == SIGFPE) &&
goetz@42065 402 TrapBasedNullChecks &&
goetz@42065 403 (trap_pc != NULL) &&
goetz@42065 404 Assembler::is_sigtrap_zero_check(trap_pc)) {
goetz@42065 405 if (TraceTraps) {
goetz@42065 406 tty->print_cr("trap: NULL_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
goetz@42065 407 }
goetz@42065 408 stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
goetz@42065 409 }
goetz@42065 410
goetz@42065 411 else if (sig == SIGSEGV && ImplicitNullChecks &&
goetz@42065 412 CodeCache::contains((void*) pc) &&
goetz@42065 413 !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
goetz@42065 414 if (TraceTraps) {
goetz@42065 415 tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
goetz@42065 416 }
goetz@42065 417 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
goetz@42065 418 }
goetz@42065 419
goetz@42065 420 // SIGTRAP-based implicit range check in compiled code.
goetz@42065 421 else if (sig == SIGFPE && TrapBasedRangeChecks &&
goetz@42065 422 (trap_pc != NULL) &&
goetz@42065 423 Assembler::is_sigtrap_range_check(trap_pc)) {
goetz@42065 424 if (TraceTraps) {
goetz@42065 425 tty->print_cr("trap: RANGE_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
goetz@42065 426 }
goetz@42065 427 stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
goetz@42065 428 }
goetz@42065 429
goetz@42065 430 else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
goetz@42065 431 stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
goetz@42065 432 }
goetz@42065 433
goetz@42065 434 else if (sig == SIGBUS) {
goetz@42065 435 // BugId 4454115: A read from a MappedByteBuffer can fault here if the
goetz@42065 436 // underlying file has been truncated. Do not crash the VM in such a case.
goetz@42065 437 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
goetz@42556 438 CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
goetz@42065 439 if (nm != NULL && nm->has_unsafe_access()) {
goetz@42065 440 // We don't really need a stub here! Just set the pending exeption and
goetz@42065 441 // continue at the next instruction after the faulting read. Returning
goetz@42065 442 // garbage from this read is ok.
goetz@42065 443 thread->set_pending_unsafe_access_error();
goetz@42065 444 uc->uc_mcontext.psw.addr = ((unsigned long)pc) + Assembler::instr_len(pc);
goetz@42065 445 return true;
goetz@42065 446 }
goetz@42065 447 }
goetz@42065 448 }
goetz@42065 449
goetz@42065 450 else { // thread->thread_state() != _thread_in_Java
goetz@42065 451 if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
goetz@42065 452 // SIGILL must be caused by VM_Version::determine_features().
goetz@42065 453 //*(int *) (pc-6)=0; // Patch instruction to 0 to indicate that it causes a SIGILL.
goetz@42065 454 // Flushing of icache is not necessary.
goetz@42065 455 stub = pc; // Continue with next instruction.
goetz@42065 456 } else if (thread->thread_state() == _thread_in_vm &&
goetz@42065 457 sig == SIGBUS && thread->doing_unsafe_access()) {
goetz@42065 458 // We don't really need a stub here! Just set the pending exeption and
goetz@42065 459 // continue at the next instruction after the faulting read. Returning
goetz@42065 460 // garbage from this read is ok.
goetz@42065 461 thread->set_pending_unsafe_access_error();
goetz@42065 462 os::Linux::ucontext_set_pc(uc, pc + Assembler::instr_len(pc));
goetz@42065 463 return true;
goetz@42065 464 }
goetz@42065 465 }
goetz@42065 466
goetz@42065 467 // Check to see if we caught the safepoint code in the
goetz@42065 468 // process of write protecting the memory serialization page.
goetz@42065 469 // It write enables the page immediately after protecting it
goetz@42065 470 // so we can just return to retry the write.
goetz@42065 471 // Info->si_addr need not be the exact address, it is only
goetz@42065 472 // guaranteed to be on the same page as the address that caused
goetz@42065 473 // the SIGSEGV.
goetz@42065 474 if ((sig == SIGSEGV) &&
goetz@42065 475 (os::get_memory_serialize_page() ==
goetz@42065 476 (address)((uintptr_t)info->si_addr & ~(os::vm_page_size()-1)))) {
goetz@42065 477 return true;
goetz@42065 478 }
goetz@42065 479 }
goetz@42065 480
goetz@42065 481 if (stub != NULL) {
goetz@42065 482 // Save all thread context in case we need to restore it.
goetz@42065 483 if (thread != NULL) thread->set_saved_exception_pc(pc);
goetz@42065 484 os::Linux::ucontext_set_pc(uc, stub);
goetz@42065 485 return true;
goetz@42065 486 }
goetz@42065 487
goetz@42065 488 // signal-chaining
goetz@42065 489 if (os::Linux::chained_handler(sig, info, ucVoid)) {
goetz@42065 490 return true;
goetz@42065 491 }
goetz@42065 492
goetz@42065 493 if (!abort_if_unrecognized) {
goetz@42065 494 // caller wants another chance, so give it to him
goetz@42065 495 return false;
goetz@42065 496 }
goetz@42065 497
goetz@42065 498 if (pc == NULL && uc != NULL) {
goetz@42065 499 pc = os::Linux::ucontext_get_pc(uc);
goetz@42065 500 }
goetz@42065 501
goetz@42065 502 // unmask current signal
goetz@42065 503 sigset_t newset;
goetz@42065 504 sigemptyset(&newset);
goetz@42065 505 sigaddset(&newset, sig);
goetz@42065 506 sigprocmask(SIG_UNBLOCK, &newset, NULL);
goetz@42065 507
stuefe@46361 508 // Hand down correct pc for SIGILL, SIGFPE. pc from context
stuefe@46361 509 // usually points to the instruction after the failing instruction.
stuefe@46361 510 // Note: this should be combined with the trap_pc handling above,
stuefe@46361 511 // because it handles the same issue.
stuefe@46361 512 if (sig == SIGILL || sig == SIGFPE) {
stuefe@46361 513 pc = (address) info->si_addr;
stuefe@46361 514 }
stuefe@46361 515
goetz@42065 516 VMError::report_and_die(t, sig, pc, info, ucVoid);
goetz@42065 517
goetz@42065 518 ShouldNotReachHere();
goetz@42065 519 return false;
goetz@42065 520 }
goetz@42065 521
goetz@42065 522 void os::Linux::init_thread_fpu_state(void) {
goetz@42065 523 // Nothing to do on z/Architecture.
goetz@42065 524 }
goetz@42065 525
goetz@42065 526 int os::Linux::get_fpu_control_word(void) {
goetz@42065 527 // Nothing to do on z/Architecture.
goetz@42065 528 return 0;
goetz@42065 529 }
goetz@42065 530
goetz@42065 531 void os::Linux::set_fpu_control_word(int fpu_control) {
goetz@42065 532 // Nothing to do on z/Architecture.
goetz@42065 533 }
goetz@42065 534
goetz@42065 535 ////////////////////////////////////////////////////////////////////////////////
goetz@42065 536 // thread stack
goetz@42065 537
goetz@42906 538 // Minimum usable stack sizes required to get to user code. Space for
goetz@42906 539 // HotSpot guard pages is added later.
goetz@42906 540 size_t os::Posix::_compiler_thread_min_stack_allowed = (52 DEBUG_ONLY(+ 32)) * K;
goetz@42906 541 size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 8)) * K;
goetz@42906 542 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 32 * K;
goetz@42065 543
goetz@42905 544 // Return default stack size for thr_type.
goetz@42065 545 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
goetz@42905 546 // Default stack size (compiler thread needs larger stack).
goetz@42065 547 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
goetz@42065 548 return s;
goetz@42065 549 }
goetz@42065 550
goetz@42065 551 /////////////////////////////////////////////////////////////////////////////
goetz@42065 552 // helper functions for fatal error handler
goetz@42065 553
goetz@42065 554 void os::print_context(outputStream *st, const void *context) {
goetz@42065 555 if (context == NULL) return;
goetz@42065 556
goetz@42065 557 const ucontext_t* uc = (const ucontext_t*)context;
goetz@42065 558
goetz@42065 559 st->print_cr("Processor state:");
goetz@42065 560 st->print_cr("----------------");
goetz@42065 561 st->print_cr(" ip = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.addr);
goetz@42065 562 st->print_cr(" proc mask = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.mask);
goetz@42065 563 st->print_cr(" fpc reg = 0x%8.8x " , uc->uc_mcontext.fpregs.fpc);
goetz@42065 564 st->cr();
goetz@42065 565
goetz@42065 566 st->print_cr("General Purpose Registers:");
goetz@42065 567 st->print_cr("--------------------------");
goetz@42065 568 for( int i = 0; i < 16; i+=2 ) {
goetz@42065 569 st->print(" r%-2d = " INTPTR_FORMAT " " , i, uc->uc_mcontext.gregs[i]);
goetz@42065 570 st->print(" r%-2d = " INTPTR_FORMAT " |", i+1, uc->uc_mcontext.gregs[i+1]);
goetz@42065 571 st->print(" r%-2d = %23.1ld " , i, uc->uc_mcontext.gregs[i]);
goetz@42065 572 st->print(" r%-2d = %23.1ld " , i+1, uc->uc_mcontext.gregs[i+1]);
goetz@42065 573 st->cr();
goetz@42065 574 }
goetz@42065 575 st->cr();
goetz@42065 576
goetz@42065 577 st->print_cr("Access Registers:");
goetz@42065 578 st->print_cr("-----------------");
goetz@42065 579 for( int i = 0; i < 16; i+=2 ) {
goetz@42065 580 st->print(" ar%-2d = 0x%8.8x ", i, uc->uc_mcontext.aregs[i]);
goetz@42065 581 st->print(" ar%-2d = 0x%8.8x ", i+1, uc->uc_mcontext.aregs[i+1]);
goetz@42065 582 st->cr();
goetz@42065 583 }
goetz@42065 584 st->cr();
goetz@42065 585
goetz@42065 586 st->print_cr("Float Registers:");
goetz@42065 587 st->print_cr("----------------");
goetz@42065 588 for (int i = 0; i < 16; i += 2) {
goetz@42065 589 st->print(" fr%-2d = " INTPTR_FORMAT " " , i, (int64_t)(uc->uc_mcontext.fpregs.fprs[i].d));
goetz@42065 590 st->print(" fr%-2d = " INTPTR_FORMAT " |", i+1, (int64_t)(uc->uc_mcontext.fpregs.fprs[i+1].d));
goetz@42065 591 st->print(" fr%-2d = %23.15e " , i, (uc->uc_mcontext.fpregs.fprs[i].d));
goetz@42065 592 st->print(" fr%-2d = %23.15e " , i+1, (uc->uc_mcontext.fpregs.fprs[i+1].d));
goetz@42065 593 st->cr();
goetz@42065 594 }
goetz@42065 595 st->cr();
goetz@42065 596 st->cr();
goetz@42065 597
goetz@42065 598 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
goetz@42065 599 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
goetz@42065 600 print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
goetz@42065 601 st->cr();
goetz@42065 602
goetz@42065 603 // Note: it may be unsafe to inspect memory near pc. For example, pc may
goetz@42065 604 // point to garbage if entry point in an nmethod is corrupted. Leave
goetz@42065 605 // this at the end, and hope for the best.
goetz@42065 606 address pc = os::Linux::ucontext_get_pc(uc);
goetz@42065 607 if (Verbose) { st->print_cr("pc at " PTR_FORMAT, p2i(pc)); }
goetz@42065 608 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
goetz@42065 609 print_hex_dump(st, pc-64, pc+64, /*intrsize=*/4);
goetz@42065 610 st->cr();
goetz@42065 611 }
goetz@42065 612
goetz@42065 613 void os::print_register_info(outputStream *st, const void *context) {
goetz@42065 614 st->print("Not ported\n");
goetz@42065 615 }
goetz@42065 616
goetz@42065 617 #ifndef PRODUCT
goetz@42065 618 void os::verify_stack_alignment() {
goetz@42065 619 }
goetz@42065 620 #endif
goetz@42065 621
goetz@42065 622 int os::extra_bang_size_in_bytes() {
goetz@42065 623 // z/Architecture does not require the additional stack bang.
goetz@42065 624 return 0;
goetz@42065 625 }