src/os_cpu/linux_mips/vm/os_linux_mips.cpp

Tue, 15 Nov 2016 17:27:50 +0800

author
aoqi
date
Tue, 15 Nov 2016 17:27:50 +0800
changeset 181
721d96d20be1
parent 179
e67dc9f1ba90
child 182
d150daa954c4
permissions
-rw-r--r--

disable JVM_handle_linux_signal output in non-product mode.

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 // do not include precompiled header file
aoqi@1 27 #include "asm/macroAssembler.hpp"
aoqi@1 28 #include "classfile/classLoader.hpp"
aoqi@1 29 #include "classfile/systemDictionary.hpp"
aoqi@1 30 #include "classfile/vmSymbols.hpp"
aoqi@1 31 #include "code/icBuffer.hpp"
aoqi@1 32 #include "code/vtableStubs.hpp"
aoqi@1 33 #include "interpreter/interpreter.hpp"
aoqi@1 34 #include "jvm_linux.h"
aoqi@1 35 #include "memory/allocation.inline.hpp"
aoqi@1 36 #include "mutex_linux.inline.hpp"
aoqi@1 37 #include "os_share_linux.hpp"
aoqi@1 38 #include "prims/jniFastGetField.hpp"
aoqi@1 39 #include "prims/jvm.h"
aoqi@1 40 #include "prims/jvm_misc.hpp"
aoqi@1 41 #include "runtime/arguments.hpp"
aoqi@1 42 #include "runtime/extendedPC.hpp"
aoqi@1 43 #include "runtime/frame.inline.hpp"
aoqi@1 44 #include "runtime/interfaceSupport.hpp"
aoqi@1 45 #include "runtime/java.hpp"
aoqi@1 46 #include "runtime/javaCalls.hpp"
aoqi@1 47 #include "runtime/mutexLocker.hpp"
aoqi@1 48 #include "runtime/osThread.hpp"
aoqi@1 49 #include "runtime/sharedRuntime.hpp"
aoqi@1 50 #include "runtime/stubRoutines.hpp"
aoqi@1 51 #include "runtime/thread.inline.hpp"
aoqi@1 52 #include "runtime/timer.hpp"
aoqi@1 53 #include "utilities/events.hpp"
aoqi@1 54 #include "utilities/vmError.hpp"
aoqi@1 55 #include "utilities/debug.hpp"
aoqi@1 56 #include "compiler/disassembler.hpp"
aoqi@1 57 // put OS-includes here
aoqi@1 58 # include <sys/types.h>
aoqi@1 59 # include <sys/mman.h>
aoqi@1 60 # include <pthread.h>
aoqi@1 61 # include <signal.h>
aoqi@1 62 # include <errno.h>
aoqi@1 63 # include <dlfcn.h>
aoqi@1 64 # include <stdlib.h>
aoqi@1 65 # include <stdio.h>
aoqi@1 66 # include <unistd.h>
aoqi@1 67 # include <sys/resource.h>
aoqi@1 68 # include <pthread.h>
aoqi@1 69 # include <sys/stat.h>
aoqi@1 70 # include <sys/time.h>
aoqi@1 71 # include <sys/utsname.h>
aoqi@1 72 # include <sys/socket.h>
aoqi@1 73 # include <sys/wait.h>
aoqi@1 74 # include <pwd.h>
aoqi@1 75 # include <poll.h>
aoqi@1 76 # include <ucontext.h>
aoqi@1 77 # include <fpu_control.h>
aoqi@1 78
aoqi@1 79 #define REG_SP 29
aoqi@1 80 #define REG_FP 30
aoqi@1 81
aoqi@1 82 address os::current_stack_pointer() {
aoqi@179 83 register void *sp __asm__ ("$29");
aoqi@179 84 return (address) sp;
aoqi@1 85 }
aoqi@1 86
aoqi@1 87 char* os::non_memory_address_word() {
aoqi@1 88 // Must never look like an address returned by reserve_memory,
aoqi@1 89 // even in its subfields (as defined by the CPU immediate fields,
aoqi@1 90 // if the CPU splits constants across multiple instructions).
aoqi@1 91
aoqi@1 92 return (char*) -1;
aoqi@1 93 }
aoqi@1 94
aoqi@1 95 void os::initialize_thread(Thread* thr) {
aoqi@1 96 // Nothing to do.
aoqi@1 97 }
aoqi@1 98
aoqi@1 99 address os::Linux::ucontext_get_pc(ucontext_t * uc) {
aoqi@1 100 //return (address)uc->uc_mcontext.gregs[REG_PC];
aoqi@1 101 return (address)uc->uc_mcontext.pc;//aoqi:what is gregs?
aoqi@1 102 }
aoqi@1 103
aoqi@1 104 intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) {
aoqi@1 105 return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
aoqi@1 106 }
aoqi@1 107
aoqi@1 108 intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) {
aoqi@1 109 return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
aoqi@1 110 }
aoqi@1 111
aoqi@1 112 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
aoqi@1 113 // is currently interrupted by SIGPROF.
aoqi@1 114 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
aoqi@1 115 // frames. Currently we don't do that on Linux, so it's the same as
aoqi@1 116 // os::fetch_frame_from_context().
aoqi@1 117 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread,
aoqi@1 118 ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
aoqi@1 119
aoqi@1 120 assert(thread != NULL, "just checking");
aoqi@1 121 assert(ret_sp != NULL, "just checking");
aoqi@1 122 assert(ret_fp != NULL, "just checking");
aoqi@1 123
aoqi@1 124 return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
aoqi@1 125 }
aoqi@1 126
aoqi@1 127 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
aoqi@1 128 intptr_t** ret_sp, intptr_t** ret_fp) {
aoqi@1 129
aoqi@1 130 ExtendedPC epc;
aoqi@1 131 ucontext_t* uc = (ucontext_t*)ucVoid;
aoqi@1 132
aoqi@1 133 address pc = (address)os::Linux::ucontext_get_pc(uc);
aoqi@1 134
aoqi@1 135 /* Jin: to capture invalid 32-bit PC, for debbuging */
aoqi@1 136 if (((long)pc & 0xFFFFFFFF00000000UL) == 0)
aoqi@1 137 {
aoqi@1 138 pc = (address)((long)pc | 0x5500000000UL);
aoqi@1 139 tty->print_cr("<Error> 32-bit pc: %lx", pc);
aoqi@1 140 }
aoqi@1 141
aoqi@1 142 if (uc != NULL) {
aoqi@1 143 epc = ExtendedPC(pc);
aoqi@1 144 if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc);
aoqi@1 145 if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc);
aoqi@1 146 } else {
aoqi@1 147 // construct empty ExtendedPC for return value checking
aoqi@1 148 epc = ExtendedPC(NULL);
aoqi@1 149 if (ret_sp) *ret_sp = (intptr_t *)NULL;
aoqi@1 150 if (ret_fp) *ret_fp = (intptr_t *)NULL;
aoqi@1 151 }
aoqi@1 152
aoqi@1 153 return epc;
aoqi@1 154 }
aoqi@1 155
aoqi@1 156 frame os::fetch_frame_from_context(void* ucVoid) {
aoqi@1 157 intptr_t* sp;
aoqi@1 158 intptr_t* fp;
aoqi@1 159 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
aoqi@1 160 return frame(sp, fp, epc.pc());
aoqi@1 161 }
aoqi@1 162
aoqi@1 163 // By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
aoqi@1 164 // turned off by -fomit-frame-pointer,
aoqi@1 165 frame os::get_sender_for_C_frame(frame* fr) {
aoqi@1 166 //return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
aoqi@1 167 //tty->print("c frame sp = 0x%lx, fp=0x%lx, pc=0x%lx \n", (int)fr->sp(),(int)fr->fp(),(int)fr->pc());
aoqi@179 168 //tty->print("c frame send_sp =0x%lx, fp = 0x%lx, pc = 0x%lx \n",
aoqi@179 169 // (int) fr->sender_sp(), (int) fr->link(), (int)fr->sender_pc());
aoqi@179 170 return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
aoqi@1 171 }
aoqi@1 172
aoqi@1 173 //intptr_t* _get_previous_fp() {
aoqi@1 174 //see StubGenerator::generate_get_previous_fp in stubGenerator_gs2.cpp
aoqi@1 175 jint* os::get_previous_fp() {
aoqi@179 176 int *pc;
aoqi@179 177 int sp;
aoqi@179 178 int *pc_limit = (int*)(void*)&os::get_previous_fp;
aoqi@179 179 int insn;
aoqi@1 180
aoqi@179 181 {
aoqi@179 182 l_pc:;
aoqi@179 183 pc = (int*)&&l_pc;
aoqi@179 184 __asm__ __volatile__ ("move %0, $sp" : "=r" (sp));
aoqi@179 185 }
aoqi@1 186
aoqi@179 187 do {
aoqi@179 188 --pc;
aoqi@179 189 insn = *pc;
aoqi@179 190 switch(bitfield(insn, 16, 16)) {
aoqi@179 191 case 0x27bd: /* addiu $sp,$sp,-i */
aoqi@179 192 case 0x23bd: /* addi $sp,$sp,-i */
aoqi@179 193 case 0x67bd: /* daddiu $sp,$sp,-i */
aoqi@179 194 case 0x63bd: /* daddi $sp,$sp,-i */
aoqi@179 195 assert ((short)bitfield(insn, 0, 16)<0, "bad frame");
aoqi@179 196 sp -= (short)bitfield(insn, 0, 16);
aoqi@179 197 return (jint*)sp;
aoqi@179 198 }
aoqi@179 199 } while (pc>pc_limit);
aoqi@1 200
aoqi@179 201 ShouldNotReachHere();
aoqi@1 202 }
aoqi@1 203
aoqi@1 204 frame os::current_frame() {
aoqi@179 205 //tty->print("@@@@@@@@@@@@@@@@@@@get_previous_fp = 0x%lx \n", (intptr_t)(get_previous_fp()));
aoqi@179 206 frame myframe((intptr_t*)os::current_stack_pointer(),
aoqi@1 207 (intptr_t*)get_previous_fp(),
aoqi@1 208 CAST_FROM_FN_PTR(address, os::current_frame));
aoqi@1 209 if (os::is_first_C_frame(&myframe)) {
aoqi@1 210 // stack is not walkable
aoqi@1 211 return frame(NULL, NULL, NULL);
aoqi@1 212 } else {
aoqi@1 213 return os::get_sender_for_C_frame(&myframe);
aoqi@1 214 }
aoqi@1 215 }
aoqi@1 216
aoqi@1 217 //x86 add 2 new assemble function here!
aoqi@179 218 extern "C" int
aoqi@1 219 JVM_handle_linux_signal(int sig,
aoqi@1 220 siginfo_t* info,
aoqi@1 221 void* ucVoid,
aoqi@1 222 int abort_if_unrecognized) {
aoqi@181 223 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 224 tty->print_cr("Signal: signo=%d, sicode=%d, sierrno=%d, siaddr=%lx",
aoqi@179 225 info->si_signo,
aoqi@179 226 info->si_code,
aoqi@179 227 info->si_errno,
aoqi@179 228 info->si_addr);
aoqi@179 229 #endif
aoqi@1 230
aoqi@1 231 ucontext_t* uc = (ucontext_t*) ucVoid;
aoqi@1 232
aoqi@1 233 Thread* t = ThreadLocalStorage::get_thread_slow();
aoqi@1 234
aoqi@1 235 SignalHandlerMark shm(t);
aoqi@1 236
aoqi@1 237 // Note: it's not uncommon that JNI code uses signal/sigset to install
aoqi@1 238 // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
aoqi@1 239 // or have a SIGILL handler when detecting CPU type). When that happens,
aoqi@1 240 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
aoqi@1 241 // avoid unnecessary crash when libjsig is not preloaded, try handle signals
aoqi@1 242 // that do not require siginfo/ucontext first.
aoqi@1 243
aoqi@1 244 //if (sig == SIGPIPE || sig == SIGXFSZ) {
aoqi@1 245 if (sig == SIGPIPE) {
aoqi@1 246 // allow chained handler to go first
aoqi@1 247 if (os::Linux::chained_handler(sig, info, ucVoid)) {
aoqi@1 248 return true;
aoqi@1 249 } else {
aoqi@1 250 if (PrintMiscellaneous && (WizardMode || Verbose)) {
aoqi@1 251 warning("Ignoring SIGPIPE - see bug 4229104");
aoqi@1 252 }
aoqi@1 253 return true;
aoqi@1 254 }
aoqi@1 255 }
aoqi@1 256
aoqi@1 257 JavaThread* thread = NULL;
aoqi@1 258 VMThread* vmthread = NULL;
aoqi@1 259 if (os::Linux::signal_handlers_are_installed) {
aoqi@1 260 if (t != NULL ){
aoqi@1 261 if(t->is_Java_thread()) {
aoqi@181 262 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 263 //tty->print_cr("this thread is a java thread");
aoqi@179 264 #endif
aoqi@1 265 thread = (JavaThread*)t;
aoqi@1 266 }
aoqi@1 267 else if(t->is_VM_thread()){
aoqi@181 268 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 269 //tty->print_cr("this thread is a VM thread\n");
aoqi@179 270 #endif
aoqi@1 271 vmthread = (VMThread *)t;
aoqi@1 272 }
aoqi@1 273 }
aoqi@1 274 }
aoqi@1 275
aoqi@1 276 // decide if this trap can be handled by a stub
aoqi@1 277 address stub = NULL;
aoqi@1 278 address pc = NULL;
aoqi@1 279
aoqi@1 280 pc = (address) os::Linux::ucontext_get_pc(uc);
aoqi@181 281 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 282 tty->print_cr("pc=%lx", pc);
aoqi@1 283 os::print_context(tty, uc);
aoqi@1 284 #endif
aoqi@1 285 //%note os_trap_1
aoqi@1 286 if (info != NULL && uc != NULL && thread != NULL) {
aoqi@1 287 pc = (address) os::Linux::ucontext_get_pc(uc);
aoqi@1 288 // Handle ALL stack overflow variations here
aoqi@1 289 if (sig == SIGSEGV) {
aoqi@1 290 address addr = (address) info->si_addr;
aoqi@1 291 // check if fault address is within thread stack
aoqi@181 292 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 293 //tty->print("handle all stack overflow variations: ");
aoqi@1 294 /*tty->print("addr = %lx, stack base = %lx, stack top = %lx\n",
aoqi@179 295 addr,
aoqi@179 296 thread->stack_base(),
aoqi@179 297 thread->stack_base() - thread->stack_size());
aoqi@179 298 */
aoqi@179 299 #endif
aoqi@1 300
aoqi@1 301 if (addr < thread->stack_base() &&
aoqi@1 302 addr >= thread->stack_base() - thread->stack_size()) {
aoqi@1 303 // stack overflow
aoqi@181 304 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 305 tty->print("stack exception check \n");
aoqi@179 306 #endif
aoqi@1 307 if (thread->in_stack_yellow_zone(addr)) {
aoqi@181 308 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 309 tty->print("exception addr is in yellow zone\n");
aoqi@179 310 #endif
aoqi@1 311 thread->disable_stack_yellow_zone();
aoqi@1 312 if (thread->thread_state() == _thread_in_Java) {
aoqi@1 313 // Throw a stack overflow exception. Guard pages will be reenabled
aoqi@1 314 // while unwinding the stack.
aoqi@181 315 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 316 tty->print("this thread is in java\n");
aoqi@179 317 #endif
aoqi@1 318 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
aoqi@1 319 } else {
aoqi@1 320 // Thread was in the vm or native code. Return and try to finish.
aoqi@181 321 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 322 tty->print("this thread is in vm or native codes and return\n");
aoqi@179 323 #endif
aoqi@1 324 return 1;
aoqi@1 325 }
aoqi@1 326 } else if (thread->in_stack_red_zone(addr)) {
aoqi@1 327 // Fatal red zone violation. Disable the guard pages and fall through
aoqi@1 328 // to handle_unexpected_exception way down below.
aoqi@181 329 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 330 tty->print("exception addr is in red zone\n");
aoqi@179 331 #endif
aoqi@1 332 thread->disable_stack_red_zone();
aoqi@181 333 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 334 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
aoqi@179 335 #endif
aoqi@1 336 } else {
aoqi@1 337 // Accessing stack address below sp may cause SEGV if current
aoqi@1 338 // thread has MAP_GROWSDOWN stack. This should only happen when
aoqi@1 339 // current thread was created by user code with MAP_GROWSDOWN flag
aoqi@1 340 // and then attached to VM. See notes in os_linux.cpp.
aoqi@181 341 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 342 tty->print("exception addr is neither in yellow zone nor in the red one\n");
aoqi@179 343 #endif
aoqi@1 344 if (thread->osthread()->expanding_stack() == 0) {
aoqi@1 345 thread->osthread()->set_expanding_stack();
aoqi@1 346 if (os::Linux::manually_expand_stack(thread, addr)) {
aoqi@1 347 thread->osthread()->clear_expanding_stack();
aoqi@1 348 return 1;
aoqi@1 349 }
aoqi@1 350 thread->osthread()->clear_expanding_stack();
aoqi@1 351 } else {
aoqi@1 352 fatal("recursive segv. expanding stack.");
aoqi@1 353 }
aoqi@1 354 }
aoqi@1 355 } //addr <
aoqi@1 356 } //sig == SIGSEGV
aoqi@1 357
aoqi@1 358 if (thread->thread_state() == _thread_in_Java) {
aoqi@1 359 // Java thread running in Java code => find exception handler if any
aoqi@1 360 // a fault inside compiled code, the interpreter, or a stub
aoqi@181 361 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 362 tty->print("java thread running in java code\n");
aoqi@1 363 tty->print_cr("polling address = %lx, sig=%d", os::get_polling_page(), sig);
aoqi@179 364 #endif
aoqi@1 365 if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
aoqi@1 366
aoqi@1 367 stub = SharedRuntime::get_poll_stub(pc);
aoqi@1 368 } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
aoqi@1 369 // BugId 4454115: A read from a MappedByteBuffer can fault
aoqi@1 370 // here if the underlying file has been truncated.
aoqi@1 371 // Do not crash the VM in such a case.
aoqi@1 372 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
aoqi@1 373 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
aoqi@181 374 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 375 tty->print("cb = %lx, nm = %lx\n", cb, nm);
aoqi@179 376 #endif
aoqi@1 377 if (nm != NULL && nm->has_unsafe_access()) {
aoqi@1 378 stub = StubRoutines::handler_for_unsafe_access();
aoqi@1 379 }
aoqi@1 380 } else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
aoqi@1 381 // HACK: si_code does not work on linux 2.2.12-20!!!
aoqi@1 382 int op = pc[0] & 0x3f;
aoqi@179 383 int op1 = pc[3] & 0x3f;
aoqi@179 384 tty->print_cr("unknown opcode 0x%X -0x%X with SIGFPE.", op, op1);
aoqi@179 385 //FIXME, Must port to mips code!!
aoqi@1 386 switch (op) {
aoqi@179 387 case 0x1e: //ddiv
aoqi@179 388 case 0x1f: //ddivu
aoqi@179 389 case 0x1a: //div
aoqi@179 390 case 0x1b: //divu
aoqi@179 391 case 0x34: //trap
aoqi@179 392 /* In MIPS, div_by_zero exception can only be triggered by explicit 'trap'.
aoqi@179 393 * Ref: [c1_LIRAssembler_mips.cpp] arithmetic_idiv()
aoqi@179 394 */
aoqi@179 395 stub = SharedRuntime::continuation_for_implicit_exception(thread,
aoqi@179 396 pc,
aoqi@1 397 SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
aoqi@179 398 break;
aoqi@1 399 default:
aoqi@179 400 // TODO: handle more cases if we are using other x86 instructions
aoqi@179 401 // that can generate SIGFPE signal on linux.
aoqi@179 402 tty->print_cr("unknown opcode 0x%X -0x%X with SIGFPE.", op, op1);
aoqi@179 403 //fatal("please update this code.");
aoqi@179 404 }
aoqi@1 405 }
aoqi@179 406 else if (sig == SIGSEGV &&
aoqi@179 407 !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
aoqi@179 408 // Determination of interpreter/vtable stub/compiled code null exception
aoqi@181 409 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 410 tty->print("continuation for implicit exception\n");
aoqi@179 411 #endif
aoqi@1 412 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
aoqi@1 413 }
aoqi@1 414 } else if (thread->thread_state() == _thread_in_vm &&
aoqi@1 415 sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
aoqi@1 416 thread->doing_unsafe_access()) {
aoqi@181 417 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 418 tty->print_cr("SIGBUS in vm thread \n");
aoqi@179 419 #endif
aoqi@1 420 stub = StubRoutines::handler_for_unsafe_access();
aoqi@1 421 }
aoqi@1 422
aoqi@1 423 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
aoqi@1 424 // and the heap gets shrunk before the field access.
aoqi@1 425 if ((sig == SIGSEGV) || (sig == SIGBUS)) {
aoqi@181 426 #ifdef PRINT_SIGNAL_HANDLE
aoqi@179 427 //tty->print("jni fast get trap: ");
aoqi@179 428 #endif
aoqi@1 429 address addr = JNI_FastGetField::find_slowcase_pc(pc);
aoqi@1 430 if (addr != (address)-1) {
aoqi@1 431 stub = addr;
aoqi@1 432 }
aoqi@181 433 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 434 //tty->print_cr("addr = %d, stub = %lx", addr, stub);
aoqi@179 435 #endif
aoqi@1 436 }
aoqi@1 437
aoqi@1 438 // Check to see if we caught the safepoint code in the
aoqi@1 439 // process of write protecting the memory serialization page.
aoqi@1 440 // It write enables the page immediately after protecting it
aoqi@1 441 // so we can just return to retry the write.
aoqi@1 442 if ((sig == SIGSEGV) &&
aoqi@1 443 os::is_memory_serialize_page(thread, (address) info->si_addr)) {
aoqi@1 444 // Block current thread until the memory serialize page permission restored.
aoqi@181 445 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 446 //tty->print("write protecting the memory serialiazation page\n");
aoqi@179 447 #endif
aoqi@1 448 os::block_on_serialize_page_trap();
aoqi@1 449 return true;
aoqi@1 450 }
aoqi@1 451 }
aoqi@1 452
aoqi@1 453 // Execution protection violation
aoqi@1 454 //
aoqi@1 455 // This should be kept as the last step in the triage. We don't
aoqi@1 456 // have a dedicated trap number for a no-execute fault, so be
aoqi@1 457 // conservative and allow other handlers the first shot.
aoqi@1 458 //
aoqi@1 459 // Note: We don't test that info->si_code == SEGV_ACCERR here.
aoqi@1 460 // this si_code is so generic that it is almost meaningless; and
aoqi@1 461 // the si_code for this condition may change in the future.
aoqi@1 462 // Furthermore, a false-positive should be harmless.
aoqi@1 463 if (UnguardOnExecutionViolation > 0 &&
aoqi@1 464 //(sig == SIGSEGV || sig == SIGBUS) &&
aoqi@1 465 //uc->uc_mcontext.gregs[REG_TRAPNO] == trap_page_fault) {
aoqi@179 466 (sig == SIGSEGV || sig == SIGBUS
aoqi@1 467 #ifdef OPT_RANGECHECK
aoqi@179 468 || sig == SIGSYS
aoqi@1 469 #endif
aoqi@179 470 ) &&
aoqi@179 471 //(uc->uc_mcontext.cause == 2 || uc->uc_mcontext.cause == 3)) {
aoqi@179 472 (uc->uc_mcontext.hi1 == 2 || uc->uc_mcontext.hi1 == 3)) {
aoqi@179 473 //aoqi: copy from jdk1.5, dont understand the struct mcontext_t.
aoqi@181 474 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 475 tty->print_cr("execution protection violation\n");
aoqi@1 476 #endif
aoqi@179 477
aoqi@1 478 int page_size = os::vm_page_size();
aoqi@1 479 address addr = (address) info->si_addr;
aoqi@1 480 address pc = os::Linux::ucontext_get_pc(uc);
aoqi@1 481 // Make sure the pc and the faulting address are sane.
aoqi@1 482 //
aoqi@1 483 // If an instruction spans a page boundary, and the page containing
aoqi@1 484 // the beginning of the instruction is executable but the following
aoqi@1 485 // page is not, the pc and the faulting address might be slightly
aoqi@1 486 // different - we still want to unguard the 2nd page in this case.
aoqi@1 487 //
aoqi@1 488 // 15 bytes seems to be a (very) safe value for max instruction size.
aoqi@1 489 bool pc_is_near_addr =
aoqi@1 490 (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
aoqi@1 491 bool instr_spans_page_boundary =
aoqi@1 492 (align_size_down((intptr_t) pc ^ (intptr_t) addr,
aoqi@1 493 (intptr_t) page_size) > 0);
aoqi@1 494
aoqi@1 495 if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
aoqi@1 496 static volatile address last_addr =
aoqi@1 497 (address) os::non_memory_address_word();
aoqi@1 498
aoqi@1 499 // In conservative mode, don't unguard unless the address is in the VM
aoqi@1 500 if (addr != last_addr &&
aoqi@1 501 (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
aoqi@1 502
aoqi@1 503 // Set memory to RWX and retry
aoqi@1 504 address page_start =
aoqi@1 505 (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
aoqi@19 506 bool res = os::protect_memory((char*) page_start, page_size,
aoqi@19 507 os::MEM_PROT_RWX);
aoqi@1 508
aoqi@1 509 if (PrintMiscellaneous && Verbose) {
aoqi@1 510 char buf[256];
aoqi@1 511 jio_snprintf(buf, sizeof(buf), "Execution protection violation "
aoqi@1 512 "at " INTPTR_FORMAT
aoqi@1 513 ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr,
aoqi@1 514 page_start, (res ? "success" : "failed"), errno);
aoqi@1 515 tty->print_raw_cr(buf);
aoqi@1 516 }
aoqi@1 517 stub = pc;
aoqi@1 518
aoqi@1 519 // Set last_addr so if we fault again at the same address, we don't end
aoqi@1 520 // up in an endless loop.
aoqi@1 521 //
aoqi@1 522 // There are two potential complications here. Two threads trapping at
aoqi@1 523 // the same address at the same time could cause one of the threads to
aoqi@1 524 // think it already unguarded, and abort the VM. Likely very rare.
aoqi@1 525 //
aoqi@1 526 // The other race involves two threads alternately trapping at
aoqi@1 527 // different addresses and failing to unguard the page, resulting in
aoqi@1 528 // an endless loop. This condition is probably even more unlikely than
aoqi@1 529 // the first.
aoqi@1 530 //
aoqi@1 531 // Although both cases could be avoided by using locks or thread local
aoqi@1 532 // last_addr, these solutions are unnecessary complication: this
aoqi@1 533 // handler is a best-effort safety net, not a complete solution. It is
aoqi@1 534 // disabled by default and should only be used as a workaround in case
aoqi@1 535 // we missed any no-execute-unsafe VM code.
aoqi@1 536
aoqi@1 537 last_addr = addr;
aoqi@1 538 }
aoqi@1 539 }
aoqi@1 540 }
aoqi@1 541
aoqi@1 542 if (stub != NULL) {
aoqi@181 543 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 544 //tty->print_cr("resolved stub=%lx\n",stub);
aoqi@179 545 #endif
aoqi@1 546 // save all thread context in case we need to restore it
aoqi@1 547 if (thread != NULL) thread->set_saved_exception_pc(pc);
aoqi@1 548
aoqi@1 549 uc->uc_mcontext.pc = (greg_t)stub;
aoqi@1 550 return true;
aoqi@1 551 }
aoqi@1 552
aoqi@1 553 // signal-chaining
aoqi@1 554 if (os::Linux::chained_handler(sig, info, ucVoid)) {
aoqi@181 555 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 556 tty->print_cr("signal chaining\n");
aoqi@179 557 #endif
aoqi@1 558 return true;
aoqi@1 559 }
aoqi@1 560
aoqi@1 561 if (!abort_if_unrecognized) {
aoqi@1 562 // caller wants another chance, so give it to him
aoqi@181 563 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 564 tty->print_cr("abort becauce of unrecognized\n");
aoqi@179 565 #endif
aoqi@1 566 return false;
aoqi@1 567 }
aoqi@1 568
aoqi@1 569 if (pc == NULL && uc != NULL) {
aoqi@1 570 pc = os::Linux::ucontext_get_pc(uc);
aoqi@1 571 }
aoqi@1 572
aoqi@1 573 // unmask current signal
aoqi@1 574 sigset_t newset;
aoqi@1 575 sigemptyset(&newset);
aoqi@1 576 sigaddset(&newset, sig);
aoqi@1 577 sigprocmask(SIG_UNBLOCK, &newset, NULL);
aoqi@181 578 #ifdef PRINT_SIGNAL_HANDLE
aoqi@1 579 tty->print_cr("VMError in signal handler\n");
aoqi@179 580 #endif
aoqi@1 581 VMError err(t, sig, pc, info, ucVoid);
aoqi@1 582 err.report_and_die();
aoqi@1 583
aoqi@1 584 ShouldNotReachHere();
aoqi@1 585 }
aoqi@1 586
aoqi@179 587 // FCSR:...|24| 23 |22|21|...
aoqi@179 588 // ...|FS|FCC0|FO|FN|...
aoqi@1 589 void os::Linux::init_thread_fpu_state(void) {
aoqi@179 590 if (SetFSFOFN == 999)
aoqi@179 591 return;
aoqi@179 592 assert(fs == 1 || fs == 0, "SetFSFOFN should be one of 000 100 111 110 101");
aoqi@179 593 assert(fo == 1 || fo == 0, "SetFSFOFN should be one of 000 100 111 110 101");
aoqi@179 594 assert(fn == 1 || fn == 0, "SetFSFOFN should be one of 000 100 111 110 101");
aoqi@179 595 int fs = (SetFSFOFN / 100)? 1:0;
aoqi@179 596 int fo = ((SetFSFOFN % 100) / 10)? 1:0;
aoqi@179 597 int fn = (SetFSFOFN % 10)? 1:0;
aoqi@179 598 int mask = fs << 24 | fo << 22 | fn << 21;
aoqi@179 599
aoqi@179 600 int fcsr = get_fpu_control_word();
aoqi@179 601 fcsr = fcsr | mask;
aoqi@179 602 set_fpu_control_word(fcsr);
aoqi@179 603 /*
aoqi@179 604 if (fcsr != get_fpu_control_word())
aoqi@179 605 tty->print_cr(" fail to set to %lx, get_fpu_control_word:%lx", fcsr, get_fpu_control_word());
aoqi@179 606 */
aoqi@1 607 }
aoqi@1 608
aoqi@1 609 int os::Linux::get_fpu_control_word(void) {
aoqi@179 610 int fcsr;
aoqi@179 611 asm volatile(
aoqi@179 612 ".set noat;"
aoqi@179 613 "daddiu %0, $0, 0;"
aoqi@179 614 "cfc1 %0, $31;"
aoqi@179 615 : "=r" (fcsr)
aoqi@179 616 );
aoqi@179 617 return fcsr;
aoqi@1 618 }
aoqi@1 619
aoqi@1 620 void os::Linux::set_fpu_control_word(int fpu_control) {
aoqi@179 621 asm volatile(
aoqi@179 622 ".set noat;"
aoqi@179 623 "ctc1 %0, $31;"
aoqi@179 624 :
aoqi@179 625 : "r" (fpu_control)
aoqi@179 626 );
aoqi@1 627 }
aoqi@1 628
aoqi@1 629 bool os::is_allocatable(size_t bytes) {
aoqi@1 630
aoqi@1 631 if (bytes < 2 * G) {
aoqi@1 632 return true;
aoqi@1 633 }
aoqi@1 634
aoqi@1 635 char* addr = reserve_memory(bytes, NULL);
aoqi@1 636
aoqi@1 637 if (addr != NULL) {
aoqi@1 638 release_memory(addr, bytes);
aoqi@1 639 }
aoqi@1 640
aoqi@1 641 return addr != NULL;
aoqi@1 642 }
aoqi@1 643
aoqi@1 644 ////////////////////////////////////////////////////////////////////////////////
aoqi@1 645 // thread stack
aoqi@1 646
aoqi@1 647 size_t os::Linux::min_stack_allowed = 96 * K;
aoqi@1 648
aoqi@1 649
aoqi@1 650 // Test if pthread library can support variable thread stack size. LinuxThreads
aoqi@1 651 // in fixed stack mode allocates 2M fixed slot for each thread. LinuxThreads
aoqi@1 652 // in floating stack mode and NPTL support variable stack size.
aoqi@1 653 bool os::Linux::supports_variable_stack_size() {
aoqi@1 654 if (os::Linux::is_NPTL()) {
aoqi@1 655 // NPTL, yes
aoqi@1 656 return true;
aoqi@1 657
aoqi@1 658 } else {
aoqi@1 659 // Note: We can't control default stack size when creating a thread.
aoqi@1 660 // If we use non-default stack size (pthread_attr_setstacksize), both
aoqi@1 661 // floating stack and non-floating stack LinuxThreads will return the
aoqi@1 662 // same value. This makes it impossible to implement this function by
aoqi@1 663 // detecting thread stack size directly.
aoqi@1 664 //
aoqi@1 665 // An alternative approach is to check %gs. Fixed-stack LinuxThreads
aoqi@1 666 // do not use %gs, so its value is 0. Floating-stack LinuxThreads use
aoqi@1 667 // %gs (either as LDT selector or GDT selector, depending on kernel)
aoqi@1 668 // to access thread specific data.
aoqi@1 669 //
aoqi@1 670 // Note that %gs is a reserved glibc register since early 2001, so
aoqi@1 671 // applications are not allowed to change its value (Ulrich Drepper from
aoqi@179 672 // Redhat confirmed that all known offenders have been modified to use
aoqi@1 673 // either %fs or TSD). In the worst case scenario, when VM is embedded in
aoqi@1 674 // a native application that plays with %gs, we might see non-zero %gs
aoqi@1 675 // even LinuxThreads is running in fixed stack mode. As the result, we'll
aoqi@1 676 // return true and skip _thread_safety_check(), so we may not be able to
aoqi@1 677 // detect stack-heap collisions. But otherwise it's harmless.
aoqi@1 678 //
aoqi@1 679 return false;
aoqi@1 680 }
aoqi@1 681 }
aoqi@1 682
aoqi@1 683 // return default stack size for thr_type
aoqi@1 684 size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
aoqi@1 685 // default stack size (compiler thread needs larger stack)
aoqi@1 686 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
aoqi@1 687 return s;
aoqi@1 688 }
aoqi@1 689
aoqi@1 690 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
aoqi@1 691 // Creating guard page is very expensive. Java thread has HotSpot
aoqi@1 692 // guard page, only enable glibc guard page for non-Java threads.
aoqi@1 693 return (thr_type == java_thread ? 0 : page_size());
aoqi@1 694 }
aoqi@1 695
aoqi@1 696 // Java thread:
aoqi@1 697 //
aoqi@1 698 // Low memory addresses
aoqi@1 699 // +------------------------+
aoqi@1 700 // | |\ JavaThread created by VM does not have glibc
aoqi@1 701 // | glibc guard page | - guard, attached Java thread usually has
aoqi@1 702 // | |/ 1 page glibc guard.
aoqi@1 703 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
aoqi@1 704 // | |\
aoqi@1 705 // | HotSpot Guard Pages | - red and yellow pages
aoqi@1 706 // | |/
aoqi@1 707 // +------------------------+ JavaThread::stack_yellow_zone_base()
aoqi@1 708 // | |\
aoqi@1 709 // | Normal Stack | -
aoqi@1 710 // | |/
aoqi@1 711 // P2 +------------------------+ Thread::stack_base()
aoqi@1 712 //
aoqi@1 713 // Non-Java thread:
aoqi@1 714 //
aoqi@1 715 // Low memory addresses
aoqi@1 716 // +------------------------+
aoqi@1 717 // | |\
aoqi@1 718 // | glibc guard page | - usually 1 page
aoqi@1 719 // | |/
aoqi@1 720 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
aoqi@1 721 // | |\
aoqi@1 722 // | Normal Stack | -
aoqi@1 723 // | |/
aoqi@1 724 // P2 +------------------------+ Thread::stack_base()
aoqi@1 725 //
aoqi@1 726 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
aoqi@1 727 // pthread_attr_getstack()
aoqi@1 728
aoqi@1 729 static void current_stack_region(address * bottom, size_t * size) {
aoqi@1 730 if (os::Linux::is_initial_thread()) {
aoqi@1 731 // initial thread needs special handling because pthread_getattr_np()
aoqi@1 732 // may return bogus value.
aoqi@1 733 *bottom = os::Linux::initial_thread_stack_bottom();
aoqi@1 734 *size = os::Linux::initial_thread_stack_size();
aoqi@1 735 } else {
aoqi@1 736 pthread_attr_t attr;
aoqi@1 737
aoqi@1 738 int rslt = pthread_getattr_np(pthread_self(), &attr);
aoqi@1 739
aoqi@1 740 // JVM needs to know exact stack location, abort if it fails
aoqi@1 741 if (rslt != 0) {
aoqi@1 742 if (rslt == ENOMEM) {
aoqi@1 743 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
aoqi@1 744 } else {
aoqi@1 745 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
aoqi@1 746 }
aoqi@1 747 }
aoqi@1 748
aoqi@179 749 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
aoqi@179 750 fatal("Can not locate current stack attributes!");
aoqi@179 751 }
aoqi@179 752
aoqi@1 753 pthread_attr_destroy(&attr);
aoqi@1 754
aoqi@1 755 }
aoqi@1 756 assert(os::current_stack_pointer() >= *bottom &&
aoqi@1 757 os::current_stack_pointer() < *bottom + *size, "just checking");
aoqi@1 758 }
aoqi@1 759
aoqi@1 760 address os::current_stack_base() {
aoqi@1 761 address bottom;
aoqi@1 762 size_t size;
aoqi@1 763 current_stack_region(&bottom, &size);
aoqi@1 764 return (bottom + size);
aoqi@1 765 }
aoqi@1 766
aoqi@1 767 size_t os::current_stack_size() {
aoqi@1 768 // stack size includes normal stack and HotSpot guard pages
aoqi@1 769 address bottom;
aoqi@1 770 size_t size;
aoqi@1 771 current_stack_region(&bottom, &size);
aoqi@1 772 return size;
aoqi@1 773 }
aoqi@1 774
aoqi@1 775 /////////////////////////////////////////////////////////////////////////////
aoqi@1 776 // helper functions for fatal error handler
aoqi@1 777 void os::print_register_info(outputStream *st, void *context) {
aoqi@1 778 if (context == NULL) return;
aoqi@1 779
aoqi@1 780 ucontext_t *uc = (ucontext_t*)context;
aoqi@1 781
aoqi@1 782 st->print_cr("Register to memory mapping:");
aoqi@1 783 st->cr();
aoqi@1 784 // this is horrendously verbose but the layout of the registers in the
aoqi@1 785 // // context does not match how we defined our abstract Register set, so
aoqi@1 786 // // we can't just iterate through the gregs area
aoqi@1 787 //
aoqi@1 788 // // this is only for the "general purpose" registers
aoqi@1 789 st->print("R0=" ); print_location(st, uc->uc_mcontext.gregs[0]);
aoqi@1 790 st->print("AT=" ); print_location(st, uc->uc_mcontext.gregs[1]);
aoqi@1 791 st->print("V0=" ); print_location(st, uc->uc_mcontext.gregs[2]);
aoqi@1 792 st->print("V1=" ); print_location(st, uc->uc_mcontext.gregs[3]);
aoqi@1 793 st->cr();
aoqi@1 794 st->print("A0=" ); print_location(st, uc->uc_mcontext.gregs[4]);
aoqi@1 795 st->print("A1=" ); print_location(st, uc->uc_mcontext.gregs[5]);
aoqi@1 796 st->print("A2=" ); print_location(st, uc->uc_mcontext.gregs[6]);
aoqi@1 797 st->print("A3=" ); print_location(st, uc->uc_mcontext.gregs[7]);
aoqi@1 798 st->cr();
aoqi@1 799 st->print("A4=" ); print_location(st, uc->uc_mcontext.gregs[8]);
aoqi@1 800 st->print("A5=" ); print_location(st, uc->uc_mcontext.gregs[9]);
aoqi@1 801 st->print("A6=" ); print_location(st, uc->uc_mcontext.gregs[10]);
aoqi@1 802 st->print("A7=" ); print_location(st, uc->uc_mcontext.gregs[11]);
aoqi@1 803 st->cr();
aoqi@1 804 st->print("T0=" ); print_location(st, uc->uc_mcontext.gregs[12]);
aoqi@1 805 st->print("T1=" ); print_location(st, uc->uc_mcontext.gregs[13]);
aoqi@1 806 st->print("T2=" ); print_location(st, uc->uc_mcontext.gregs[14]);
aoqi@1 807 st->print("T3=" ); print_location(st, uc->uc_mcontext.gregs[15]);
aoqi@1 808 st->cr();
aoqi@1 809 st->print("S0=" ); print_location(st, uc->uc_mcontext.gregs[16]);
aoqi@1 810 st->print("S1=" ); print_location(st, uc->uc_mcontext.gregs[17]);
aoqi@1 811 st->print("S2=" ); print_location(st, uc->uc_mcontext.gregs[18]);
aoqi@1 812 st->print("S3=" ); print_location(st, uc->uc_mcontext.gregs[19]);
aoqi@1 813 st->cr();
aoqi@1 814 st->print("S4=" ); print_location(st, uc->uc_mcontext.gregs[20]);
aoqi@1 815 st->print("S5=" ); print_location(st, uc->uc_mcontext.gregs[21]);
aoqi@1 816 st->print("S6=" ); print_location(st, uc->uc_mcontext.gregs[22]);
aoqi@1 817 st->print("S7=" ); print_location(st, uc->uc_mcontext.gregs[23]);
aoqi@1 818 st->cr();
aoqi@1 819 st->print("T8=" ); print_location(st, uc->uc_mcontext.gregs[24]);
aoqi@1 820 st->print("T9=" ); print_location(st, uc->uc_mcontext.gregs[25]);
aoqi@1 821 st->print("K0=" ); print_location(st, uc->uc_mcontext.gregs[26]);
aoqi@1 822 st->print("K1=" ); print_location(st, uc->uc_mcontext.gregs[27]);
aoqi@1 823 st->cr();
aoqi@1 824 st->print("GP=" ); print_location(st, uc->uc_mcontext.gregs[28]);
aoqi@1 825 st->print("SP=" ); print_location(st, uc->uc_mcontext.gregs[29]);
aoqi@1 826 st->print("FP=" ); print_location(st, uc->uc_mcontext.gregs[30]);
aoqi@1 827 st->print("RA=" ); print_location(st, uc->uc_mcontext.gregs[31]);
aoqi@1 828 st->cr();
aoqi@179 829
aoqi@1 830 }
aoqi@1 831 void os::print_context(outputStream *st, void *context) {
aoqi@1 832 if (context == NULL) return;
aoqi@1 833
aoqi@1 834 ucontext_t *uc = (ucontext_t*)context;
aoqi@1 835 st->print_cr("Registers:");
aoqi@1 836 st->print( "R0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[0]);
aoqi@1 837 st->print(", AT=" INTPTR_FORMAT, uc->uc_mcontext.gregs[1]);
aoqi@1 838 st->print(", V0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[2]);
aoqi@1 839 st->print(", V1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[3]);
aoqi@1 840 st->cr();
aoqi@1 841 st->print( "A0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[4]);
aoqi@1 842 st->print(", A1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[5]);
aoqi@1 843 st->print(", A2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[6]);
aoqi@1 844 st->print(", A3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[7]);
aoqi@1 845 st->cr();
aoqi@1 846 st->print( "A4=" INTPTR_FORMAT, uc->uc_mcontext.gregs[8]);
aoqi@1 847 st->print(", A5=" INTPTR_FORMAT, uc->uc_mcontext.gregs[9]);
aoqi@1 848 st->print(", A6=" INTPTR_FORMAT, uc->uc_mcontext.gregs[10]);
aoqi@1 849 st->print(", A7=" INTPTR_FORMAT, uc->uc_mcontext.gregs[11]);
aoqi@1 850 st->cr();
aoqi@1 851 st->print( "T0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[12]);
aoqi@1 852 st->print(", T1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[13]);
aoqi@1 853 st->print(", T2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[14]);
aoqi@1 854 st->print(", T3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[15]);
aoqi@1 855 st->cr();
aoqi@1 856 st->print( "S0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[16]);
aoqi@1 857 st->print(", S1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[17]);
aoqi@1 858 st->print(", S2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[18]);
aoqi@1 859 st->print(", S3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[19]);
aoqi@1 860 st->cr();
aoqi@1 861 st->print( "S4=" INTPTR_FORMAT, uc->uc_mcontext.gregs[20]);
aoqi@1 862 st->print(", S5=" INTPTR_FORMAT, uc->uc_mcontext.gregs[21]);
aoqi@1 863 st->print(", S6=" INTPTR_FORMAT, uc->uc_mcontext.gregs[22]);
aoqi@1 864 st->print(", S7=" INTPTR_FORMAT, uc->uc_mcontext.gregs[23]);
aoqi@1 865 st->cr();
aoqi@1 866 st->print( "T8=" INTPTR_FORMAT, uc->uc_mcontext.gregs[24]);
aoqi@1 867 st->print(", T9=" INTPTR_FORMAT, uc->uc_mcontext.gregs[25]);
aoqi@1 868 st->print(", K0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[26]);
aoqi@1 869 st->print(", K1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[27]);
aoqi@1 870 st->cr();
aoqi@1 871 st->print( "GP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[28]);
aoqi@1 872 st->print(", SP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[29]);
aoqi@1 873 st->print(", FP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[30]);
aoqi@1 874 st->print(", RA=" INTPTR_FORMAT, uc->uc_mcontext.gregs[31]);
aoqi@1 875 st->cr();
aoqi@1 876 st->cr();
aoqi@1 877
aoqi@1 878 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
aoqi@1 879 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
aoqi@1 880 //print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
aoqi@1 881 print_hex_dump(st, (address)sp-32, (address)(sp + 32), sizeof(intptr_t));
aoqi@1 882 st->cr();
aoqi@1 883
aoqi@1 884 // Note: it may be unsafe to inspect memory near pc. For example, pc may
aoqi@1 885 // point to garbage if entry point in an nmethod is corrupted. Leave
aoqi@1 886 // this at the end, and hope for the best.
aoqi@1 887 address pc = os::Linux::ucontext_get_pc(uc);
aoqi@1 888 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
aoqi@1 889 print_hex_dump(st, pc - 64, pc + 64, sizeof(char));
aoqi@1 890 Disassembler::decode(pc - 80, pc + 80, st);
aoqi@1 891 }
aoqi@1 892
aoqi@179 893 void os::setup_fpu() {
aoqi@179 894 /*
aoqi@179 895 //no use for MIPS
aoqi@179 896 int fcsr;
aoqi@179 897 address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std();
aoqi@179 898 __asm__ volatile (
aoqi@179 899 ".set noat;"
aoqi@179 900 "cfc1 %0, $31;"
aoqi@179 901 "sw %0, 0(%1);"
aoqi@179 902 : "=r" (fcsr)
aoqi@179 903 : "r" (fpu_cntrl)
aoqi@179 904 : "memory"
aoqi@179 905 );
aoqi@179 906 printf("fpu_cntrl: %lx\n", fpu_cntrl);
aoqi@179 907 */
aoqi@179 908 }
aoqi@179 909
aoqi@1 910 #ifndef PRODUCT
aoqi@1 911 void os::verify_stack_alignment() {
aoqi@1 912 assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
aoqi@1 913 }
aoqi@1 914 #endif

mercurial