src/os_cpu/linux_mips/vm/os_linux_mips.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
child 19
675330130fb8
permissions
-rw-r--r--

Added MIPS 64-bit port.

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@1 83 register void *sp __asm__ ("$29");
aoqi@1 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 //the next three method just exists in os::Linux, none in other os, by yjl 6/21/2005
aoqi@1 100 address os::Linux::ucontext_get_pc(ucontext_t * uc) {
aoqi@1 101 //return (address)uc->uc_mcontext.gregs[REG_PC];
aoqi@1 102 return (address)uc->uc_mcontext.pc;//aoqi:what is gregs?
aoqi@1 103 }
aoqi@1 104
aoqi@1 105 intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) {
aoqi@1 106 return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
aoqi@1 107 }
aoqi@1 108
aoqi@1 109 intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) {
aoqi@1 110 return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
aoqi@1 111 }
aoqi@1 112
aoqi@1 113 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
aoqi@1 114 // is currently interrupted by SIGPROF.
aoqi@1 115 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
aoqi@1 116 // frames. Currently we don't do that on Linux, so it's the same as
aoqi@1 117 // os::fetch_frame_from_context().
aoqi@1 118 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread,
aoqi@1 119 ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
aoqi@1 120
aoqi@1 121 assert(thread != NULL, "just checking");
aoqi@1 122 assert(ret_sp != NULL, "just checking");
aoqi@1 123 assert(ret_fp != NULL, "just checking");
aoqi@1 124
aoqi@1 125 return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
aoqi@1 126 }
aoqi@1 127
aoqi@1 128 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
aoqi@1 129 intptr_t** ret_sp, intptr_t** ret_fp) {
aoqi@1 130
aoqi@1 131 ExtendedPC epc;
aoqi@1 132 ucontext_t* uc = (ucontext_t*)ucVoid;
aoqi@1 133
aoqi@1 134 address pc = (address)os::Linux::ucontext_get_pc(uc);
aoqi@1 135
aoqi@1 136 /* Jin: to capture invalid 32-bit PC, for debbuging */
aoqi@1 137 if (((long)pc & 0xFFFFFFFF00000000UL) == 0)
aoqi@1 138 {
aoqi@1 139 pc = (address)((long)pc | 0x5500000000UL);
aoqi@1 140 tty->print_cr("<Error> 32-bit pc: %lx", pc);
aoqi@1 141 }
aoqi@1 142
aoqi@1 143 if (uc != NULL) {
aoqi@1 144 epc = ExtendedPC(pc);
aoqi@1 145 if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc);
aoqi@1 146 if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc);
aoqi@1 147 } else {
aoqi@1 148 // construct empty ExtendedPC for return value checking
aoqi@1 149 epc = ExtendedPC(NULL);
aoqi@1 150 if (ret_sp) *ret_sp = (intptr_t *)NULL;
aoqi@1 151 if (ret_fp) *ret_fp = (intptr_t *)NULL;
aoqi@1 152 }
aoqi@1 153
aoqi@1 154 return epc;
aoqi@1 155 }
aoqi@1 156
aoqi@1 157 frame os::fetch_frame_from_context(void* ucVoid) {
aoqi@1 158 intptr_t* sp;
aoqi@1 159 intptr_t* fp;
aoqi@1 160 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
aoqi@1 161 return frame(sp, fp, epc.pc());
aoqi@1 162 }
aoqi@1 163
aoqi@1 164 // By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
aoqi@1 165 // turned off by -fomit-frame-pointer,
aoqi@1 166 frame os::get_sender_for_C_frame(frame* fr) {
aoqi@1 167 //return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
aoqi@1 168 //tty->print("c frame sp = 0x%lx, fp=0x%lx, pc=0x%lx \n", (int)fr->sp(),(int)fr->fp(),(int)fr->pc());
aoqi@1 169 //tty->print("c frame send_sp =0x%lx, fp = 0x%lx, pc = 0x%lx \n",
aoqi@1 170 // (int) fr->sender_sp(), (int) fr->link(), (int)fr->sender_pc());
aoqi@1 171 return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
aoqi@1 172 }
aoqi@1 173
aoqi@1 174 //intptr_t* _get_previous_fp() {
aoqi@1 175 //see StubGenerator::generate_get_previous_fp in stubGenerator_gs2.cpp
aoqi@1 176 jint* os::get_previous_fp() {
aoqi@1 177 int *pc;
aoqi@1 178 int sp;
aoqi@1 179 int *pc_limit = (int*)(void*)&os::get_previous_fp;
aoqi@1 180 int insn;
aoqi@1 181
aoqi@1 182 {
aoqi@1 183 l_pc:;
aoqi@1 184 pc = (int*)&&l_pc;
aoqi@1 185 __asm__ __volatile__ ("move %0, $sp" : "=r" (sp));
aoqi@1 186 }
aoqi@1 187
aoqi@1 188 do {
aoqi@1 189 --pc;
aoqi@1 190 insn = *pc;
aoqi@1 191 switch(bitfield(insn, 16, 16)) {
aoqi@1 192 case 0x27bd: /* addiu $sp,$sp,-i */
aoqi@1 193 case 0x23bd: /* addi $sp,$sp,-i */
aoqi@1 194 case 0x67bd: /* daddiu $sp,$sp,-i */
aoqi@1 195 case 0x63bd: /* daddi $sp,$sp,-i */
aoqi@1 196 assert ((short)bitfield(insn, 0, 16)<0, "bad frame");
aoqi@1 197 sp -= (short)bitfield(insn, 0, 16);
aoqi@1 198 return (jint*)sp;
aoqi@1 199 }
aoqi@1 200 } while (pc>pc_limit);
aoqi@1 201
aoqi@1 202 ShouldNotReachHere();
aoqi@1 203 }
aoqi@1 204
aoqi@1 205 frame os::current_frame() {
aoqi@1 206 tty->print("@@@@@@@@@@@@@@@@@@@get_previous_fp = 0x%lx \n", (intptr_t)(get_previous_fp()));
aoqi@1 207 frame myframe((intptr_t*)os::current_stack_pointer(),
aoqi@1 208 (intptr_t*)get_previous_fp(),
aoqi@1 209 CAST_FROM_FN_PTR(address, os::current_frame));
aoqi@1 210 if (os::is_first_C_frame(&myframe)) {
aoqi@1 211 // stack is not walkable
aoqi@1 212 return frame(NULL, NULL, NULL);
aoqi@1 213 } else {
aoqi@1 214 return os::get_sender_for_C_frame(&myframe);
aoqi@1 215 }
aoqi@1 216 }
aoqi@1 217
aoqi@1 218 //x86 add 2 new assemble function here!
aoqi@1 219 extern "C" int
aoqi@1 220 JVM_handle_linux_signal(int sig,
aoqi@1 221 siginfo_t* info,
aoqi@1 222 void* ucVoid,
aoqi@1 223 int abort_if_unrecognized) {
aoqi@1 224 #ifndef PRODUCT
aoqi@1 225 tty->print_cr("Signal: signo=%d, sicode=%d, sierrno=%d, siaddr=%lx",
aoqi@1 226 info->si_signo,
aoqi@1 227 info->si_code,
aoqi@1 228 info->si_errno,
aoqi@1 229 info->si_addr);
aoqi@1 230 #endif
aoqi@1 231
aoqi@1 232 ucontext_t* uc = (ucontext_t*) ucVoid;
aoqi@1 233
aoqi@1 234 Thread* t = ThreadLocalStorage::get_thread_slow();
aoqi@1 235
aoqi@1 236 SignalHandlerMark shm(t);
aoqi@1 237
aoqi@1 238 // Note: it's not uncommon that JNI code uses signal/sigset to install
aoqi@1 239 // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
aoqi@1 240 // or have a SIGILL handler when detecting CPU type). When that happens,
aoqi@1 241 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
aoqi@1 242 // avoid unnecessary crash when libjsig is not preloaded, try handle signals
aoqi@1 243 // that do not require siginfo/ucontext first.
aoqi@1 244
aoqi@1 245 //if (sig == SIGPIPE || sig == SIGXFSZ) {
aoqi@1 246 if (sig == SIGPIPE) {
aoqi@1 247 // allow chained handler to go first
aoqi@1 248 if (os::Linux::chained_handler(sig, info, ucVoid)) {
aoqi@1 249 return true;
aoqi@1 250 } else {
aoqi@1 251 if (PrintMiscellaneous && (WizardMode || Verbose)) {
aoqi@1 252 warning("Ignoring SIGPIPE - see bug 4229104");
aoqi@1 253 }
aoqi@1 254 return true;
aoqi@1 255 }
aoqi@1 256 }
aoqi@1 257
aoqi@1 258 JavaThread* thread = NULL;
aoqi@1 259 VMThread* vmthread = NULL;
aoqi@1 260 if (os::Linux::signal_handlers_are_installed) {
aoqi@1 261 if (t != NULL ){
aoqi@1 262 if(t->is_Java_thread()) {
aoqi@1 263 #ifndef PRODUCT
aoqi@1 264 //tty->print_cr("this thread is a java thread");
aoqi@1 265 #endif
aoqi@1 266 thread = (JavaThread*)t;
aoqi@1 267 }
aoqi@1 268 else if(t->is_VM_thread()){
aoqi@1 269 #ifndef PRODUCT
aoqi@1 270 //tty->print_cr("this thread is a VM thread\n");
aoqi@1 271 #endif
aoqi@1 272 vmthread = (VMThread *)t;
aoqi@1 273 }
aoqi@1 274 }
aoqi@1 275 }
aoqi@1 276
aoqi@1 277 // decide if this trap can be handled by a stub
aoqi@1 278 address stub = NULL;
aoqi@1 279 address pc = NULL;
aoqi@1 280
aoqi@1 281 pc = (address) os::Linux::ucontext_get_pc(uc);
aoqi@1 282 #ifndef PRODUCT
aoqi@1 283 tty->print_cr("pc=%lx", pc);
aoqi@1 284 os::print_context(tty, uc);
aoqi@1 285 #endif
aoqi@1 286 //%note os_trap_1
aoqi@1 287 if (info != NULL && uc != NULL && thread != NULL) {
aoqi@1 288 pc = (address) os::Linux::ucontext_get_pc(uc);
aoqi@1 289 // Handle ALL stack overflow variations here
aoqi@1 290 if (sig == SIGSEGV) {
aoqi@1 291 address addr = (address) info->si_addr;
aoqi@1 292 // check if fault address is within thread stack
aoqi@1 293 #ifndef PRODUCT
aoqi@1 294 //tty->print("handle all stack overflow variations: ");
aoqi@1 295 /*tty->print("addr = %lx, stack base = %lx, stack top = %lx\n",
aoqi@1 296 addr,
aoqi@1 297 thread->stack_base(),
aoqi@1 298 thread->stack_base() - thread->stack_size());
aoqi@1 299 */
aoqi@1 300 #endif
aoqi@1 301
aoqi@1 302 if (addr < thread->stack_base() &&
aoqi@1 303 addr >= thread->stack_base() - thread->stack_size()) {
aoqi@1 304 // stack overflow
aoqi@1 305 #ifndef PRODUCT
aoqi@1 306 tty->print("stack exception check \n");
aoqi@1 307 #endif
aoqi@1 308 if (thread->in_stack_yellow_zone(addr)) {
aoqi@1 309 #ifndef PRODUCT
aoqi@1 310 tty->print("exception addr is in yellow zone\n");
aoqi@1 311 #endif
aoqi@1 312 thread->disable_stack_yellow_zone();
aoqi@1 313 if (thread->thread_state() == _thread_in_Java) {
aoqi@1 314 // Throw a stack overflow exception. Guard pages will be reenabled
aoqi@1 315 // while unwinding the stack.
aoqi@1 316 #ifndef PRODUCT
aoqi@1 317 tty->print("this thread is in java\n");
aoqi@1 318 #endif
aoqi@1 319 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
aoqi@1 320 } else {
aoqi@1 321 // Thread was in the vm or native code. Return and try to finish.
aoqi@1 322 #ifndef PRODUCT
aoqi@1 323 tty->print("this thread is in vm or native codes and return\n");
aoqi@1 324 #endif
aoqi@1 325 return 1;
aoqi@1 326 }
aoqi@1 327 } else if (thread->in_stack_red_zone(addr)) {
aoqi@1 328 // Fatal red zone violation. Disable the guard pages and fall through
aoqi@1 329 // to handle_unexpected_exception way down below.
aoqi@1 330 #ifndef PRODUCT
aoqi@1 331 tty->print("exception addr is in red zone\n");
aoqi@1 332 #endif
aoqi@1 333 thread->disable_stack_red_zone();
aoqi@1 334 #ifndef PRODUCT
aoqi@1 335 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
aoqi@1 336 #endif
aoqi@1 337 } else {
aoqi@1 338 // Accessing stack address below sp may cause SEGV if current
aoqi@1 339 // thread has MAP_GROWSDOWN stack. This should only happen when
aoqi@1 340 // current thread was created by user code with MAP_GROWSDOWN flag
aoqi@1 341 // and then attached to VM. See notes in os_linux.cpp.
aoqi@1 342 #ifndef PRODUCT
aoqi@1 343 tty->print("exception addr is neither in yellow zone nor in the red one\n");
aoqi@1 344 #endif
aoqi@1 345 if (thread->osthread()->expanding_stack() == 0) {
aoqi@1 346 thread->osthread()->set_expanding_stack();
aoqi@1 347 if (os::Linux::manually_expand_stack(thread, addr)) {
aoqi@1 348 thread->osthread()->clear_expanding_stack();
aoqi@1 349 return 1;
aoqi@1 350 }
aoqi@1 351 thread->osthread()->clear_expanding_stack();
aoqi@1 352 } else {
aoqi@1 353 fatal("recursive segv. expanding stack.");
aoqi@1 354 }
aoqi@1 355 }
aoqi@1 356 } //addr <
aoqi@1 357 } //sig == SIGSEGV
aoqi@1 358
aoqi@1 359 if (thread->thread_state() == _thread_in_Java) {
aoqi@1 360 // Java thread running in Java code => find exception handler if any
aoqi@1 361 // a fault inside compiled code, the interpreter, or a stub
aoqi@1 362 #ifndef PRODUCT
aoqi@1 363 tty->print("java thread running in java code\n");
aoqi@1 364 tty->print_cr("polling address = %lx, sig=%d", os::get_polling_page(), sig);
aoqi@1 365 #endif
aoqi@1 366 if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
aoqi@1 367
aoqi@1 368 stub = SharedRuntime::get_poll_stub(pc);
aoqi@1 369 } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
aoqi@1 370 // BugId 4454115: A read from a MappedByteBuffer can fault
aoqi@1 371 // here if the underlying file has been truncated.
aoqi@1 372 // Do not crash the VM in such a case.
aoqi@1 373 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
aoqi@1 374 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
aoqi@1 375 #ifndef PRODUCT
aoqi@1 376 tty->print("cb = %lx, nm = %lx\n", cb, nm);
aoqi@1 377 #endif
aoqi@1 378 if (nm != NULL && nm->has_unsafe_access()) {
aoqi@1 379 stub = StubRoutines::handler_for_unsafe_access();
aoqi@1 380 }
aoqi@1 381 } else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
aoqi@1 382 // HACK: si_code does not work on linux 2.2.12-20!!!
aoqi@1 383 int op = pc[0] & 0x3f;
aoqi@1 384 int op1 = pc[3] & 0x3f;
aoqi@1 385 //FIXME, Must port to mips code!!
aoqi@1 386 switch (op) {
aoqi@1 387 case 0x1e: //ddiv
aoqi@1 388 case 0x1f: //ddivu
aoqi@1 389 case 0x1a: //div
aoqi@1 390 case 0x1b: //divu
aoqi@1 391 case 0x34: //trap
aoqi@1 392 /* In MIPS, div_by_zero exception can only be triggered by explicit 'trap'.
aoqi@1 393 * Ref: [c1_LIRAssembler_mips.cpp] arithmetic_idiv()
aoqi@1 394 */
aoqi@1 395 stub = SharedRuntime::continuation_for_implicit_exception(thread,
aoqi@1 396 pc,
aoqi@1 397 SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
aoqi@1 398 break;
aoqi@1 399 default:
aoqi@1 400 // TODO: handle more cases if we are using other x86 instructions
aoqi@1 401 // that can generate SIGFPE signal on linux.
aoqi@1 402 tty->print_cr("unknown opcode 0x%X -0x%X with SIGFPE.", op, op1);
aoqi@1 403 //fatal("please update this code.");
aoqi@1 404 }
aoqi@1 405 }
aoqi@1 406 else if (sig == SIGSEGV &&
aoqi@1 407 !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
aoqi@1 408 // Determination of interpreter/vtable stub/compiled code null exception
aoqi@1 409 #ifndef PRODUCT
aoqi@1 410 tty->print("continuation for implicit exception\n");
aoqi@1 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@1 417 #ifndef PRODUCT
aoqi@1 418 tty->print_cr("SIGBUS in vm thread \n");
aoqi@1 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@1 426 #ifndef PRODUCT
aoqi@1 427 //tty->print("jni fast get trap: ");
aoqi@1 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@1 433 #ifndef PRODUCT
aoqi@1 434 //tty->print_cr("addr = %d, stub = %lx", addr, stub);
aoqi@1 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@1 445 #ifndef PRODUCT
aoqi@1 446 //tty->print("write protecting the memory serialiazation page\n");
aoqi@1 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@1 466 (sig == SIGSEGV || sig == SIGBUS
aoqi@1 467 #ifdef OPT_RANGECHECK
aoqi@1 468 || sig == SIGSYS
aoqi@1 469 #endif
aoqi@1 470 ) &&
aoqi@1 471 //(uc->uc_mcontext.cause == 2 || uc->uc_mcontext.cause == 3)) {
aoqi@1 472 (uc->uc_mcontext.hi1 == 2 || uc->uc_mcontext.hi1 == 3)) {
aoqi@1 473 //aoqi: copy from jdk1.5, dont understand the struct mcontext_t.
aoqi@1 474 #ifndef PRODUCT
aoqi@1 475 tty->print_cr("execution protection violation\n");
aoqi@1 476 #endif
aoqi@1 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@1 506 //bool res = os::protect_memory((char*) page_start, page_size,
aoqi@1 507 // os::MEM_PROT_RWX);
aoqi@1 508 bool res = os::unguard_memory((char*) page_start, page_size);//aoqi:?
aoqi@1 509
aoqi@1 510 if (PrintMiscellaneous && Verbose) {
aoqi@1 511 char buf[256];
aoqi@1 512 jio_snprintf(buf, sizeof(buf), "Execution protection violation "
aoqi@1 513 "at " INTPTR_FORMAT
aoqi@1 514 ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr,
aoqi@1 515 page_start, (res ? "success" : "failed"), errno);
aoqi@1 516 tty->print_raw_cr(buf);
aoqi@1 517 }
aoqi@1 518 stub = pc;
aoqi@1 519
aoqi@1 520 // Set last_addr so if we fault again at the same address, we don't end
aoqi@1 521 // up in an endless loop.
aoqi@1 522 //
aoqi@1 523 // There are two potential complications here. Two threads trapping at
aoqi@1 524 // the same address at the same time could cause one of the threads to
aoqi@1 525 // think it already unguarded, and abort the VM. Likely very rare.
aoqi@1 526 //
aoqi@1 527 // The other race involves two threads alternately trapping at
aoqi@1 528 // different addresses and failing to unguard the page, resulting in
aoqi@1 529 // an endless loop. This condition is probably even more unlikely than
aoqi@1 530 // the first.
aoqi@1 531 //
aoqi@1 532 // Although both cases could be avoided by using locks or thread local
aoqi@1 533 // last_addr, these solutions are unnecessary complication: this
aoqi@1 534 // handler is a best-effort safety net, not a complete solution. It is
aoqi@1 535 // disabled by default and should only be used as a workaround in case
aoqi@1 536 // we missed any no-execute-unsafe VM code.
aoqi@1 537
aoqi@1 538 last_addr = addr;
aoqi@1 539 }
aoqi@1 540 }
aoqi@1 541 }
aoqi@1 542
aoqi@1 543 if (stub != NULL) {
aoqi@1 544 #ifndef PRODUCT
aoqi@1 545 //tty->print_cr("resolved stub=%lx\n",stub);
aoqi@1 546 #endif
aoqi@1 547 // save all thread context in case we need to restore it
aoqi@1 548 if (thread != NULL) thread->set_saved_exception_pc(pc);
aoqi@1 549
aoqi@1 550 uc->uc_mcontext.pc = (greg_t)stub;
aoqi@1 551 return true;
aoqi@1 552 }
aoqi@1 553
aoqi@1 554 // signal-chaining
aoqi@1 555 if (os::Linux::chained_handler(sig, info, ucVoid)) {
aoqi@1 556 #ifndef PRODUCT
aoqi@1 557 tty->print_cr("signal chaining\n");
aoqi@1 558 #endif
aoqi@1 559 return true;
aoqi@1 560 }
aoqi@1 561
aoqi@1 562 if (!abort_if_unrecognized) {
aoqi@1 563 // caller wants another chance, so give it to him
aoqi@1 564 #ifndef PRODUCT
aoqi@1 565 tty->print_cr("abort becauce of unrecognized\n");
aoqi@1 566 #endif
aoqi@1 567 return false;
aoqi@1 568 }
aoqi@1 569
aoqi@1 570 if (pc == NULL && uc != NULL) {
aoqi@1 571 pc = os::Linux::ucontext_get_pc(uc);
aoqi@1 572 }
aoqi@1 573
aoqi@1 574 // unmask current signal
aoqi@1 575 sigset_t newset;
aoqi@1 576 sigemptyset(&newset);
aoqi@1 577 sigaddset(&newset, sig);
aoqi@1 578 sigprocmask(SIG_UNBLOCK, &newset, NULL);
aoqi@1 579 #ifndef PRODUCT
aoqi@1 580 tty->print_cr("VMError in signal handler\n");
aoqi@1 581 #endif
aoqi@1 582 VMError err(t, sig, pc, info, ucVoid);
aoqi@1 583 err.report_and_die();
aoqi@1 584
aoqi@1 585 ShouldNotReachHere();
aoqi@1 586 }
aoqi@1 587
aoqi@1 588 void os::Linux::init_thread_fpu_state(void) {
aoqi@1 589 // set fpu to 53 bit precision
aoqi@1 590 //set_fpu_control_word(0x27f);
aoqi@1 591 }
aoqi@1 592
aoqi@1 593 int os::Linux::get_fpu_control_word(void) {
aoqi@1 594 }
aoqi@1 595
aoqi@1 596 void os::Linux::set_fpu_control_word(int fpu_control) {
aoqi@1 597 }
aoqi@1 598
aoqi@1 599 bool os::is_allocatable(size_t bytes) {
aoqi@1 600
aoqi@1 601 if (bytes < 2 * G) {
aoqi@1 602 return true;
aoqi@1 603 }
aoqi@1 604
aoqi@1 605 char* addr = reserve_memory(bytes, NULL);
aoqi@1 606
aoqi@1 607 if (addr != NULL) {
aoqi@1 608 release_memory(addr, bytes);
aoqi@1 609 }
aoqi@1 610
aoqi@1 611 return addr != NULL;
aoqi@1 612 }
aoqi@1 613
aoqi@1 614 ////////////////////////////////////////////////////////////////////////////////
aoqi@1 615 // thread stack
aoqi@1 616
aoqi@1 617 size_t os::Linux::min_stack_allowed = 96 * K;
aoqi@1 618
aoqi@1 619
aoqi@1 620 // Test if pthread library can support variable thread stack size. LinuxThreads
aoqi@1 621 // in fixed stack mode allocates 2M fixed slot for each thread. LinuxThreads
aoqi@1 622 // in floating stack mode and NPTL support variable stack size.
aoqi@1 623 bool os::Linux::supports_variable_stack_size() {
aoqi@1 624 if (os::Linux::is_NPTL()) {
aoqi@1 625 // NPTL, yes
aoqi@1 626 return true;
aoqi@1 627
aoqi@1 628 } else {
aoqi@1 629 // Note: We can't control default stack size when creating a thread.
aoqi@1 630 // If we use non-default stack size (pthread_attr_setstacksize), both
aoqi@1 631 // floating stack and non-floating stack LinuxThreads will return the
aoqi@1 632 // same value. This makes it impossible to implement this function by
aoqi@1 633 // detecting thread stack size directly.
aoqi@1 634 //
aoqi@1 635 // An alternative approach is to check %gs. Fixed-stack LinuxThreads
aoqi@1 636 // do not use %gs, so its value is 0. Floating-stack LinuxThreads use
aoqi@1 637 // %gs (either as LDT selector or GDT selector, depending on kernel)
aoqi@1 638 // to access thread specific data.
aoqi@1 639 //
aoqi@1 640 // Note that %gs is a reserved glibc register since early 2001, so
aoqi@1 641 // applications are not allowed to change its value (Ulrich Drepper from
aoqi@1 642 // Red Hat confirmed that all known offenders have been modified to use
aoqi@1 643 // either %fs or TSD). In the worst case scenario, when VM is embedded in
aoqi@1 644 // a native application that plays with %gs, we might see non-zero %gs
aoqi@1 645 // even LinuxThreads is running in fixed stack mode. As the result, we'll
aoqi@1 646 // return true and skip _thread_safety_check(), so we may not be able to
aoqi@1 647 // detect stack-heap collisions. But otherwise it's harmless.
aoqi@1 648 //
aoqi@1 649 //FIXME we should do something here not just return false. by yjl 6/21/2005
aoqi@1 650 return false;
aoqi@1 651 }
aoqi@1 652 }
aoqi@1 653
aoqi@1 654 // return default stack size for thr_type
aoqi@1 655 //maybe we need change this, FIXME by yjl 6/21/2005
aoqi@1 656 size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
aoqi@1 657 // default stack size (compiler thread needs larger stack)
aoqi@1 658 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
aoqi@1 659 return s;
aoqi@1 660 }
aoqi@1 661
aoqi@1 662 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
aoqi@1 663 // Creating guard page is very expensive. Java thread has HotSpot
aoqi@1 664 // guard page, only enable glibc guard page for non-Java threads.
aoqi@1 665 return (thr_type == java_thread ? 0 : page_size());
aoqi@1 666 }
aoqi@1 667
aoqi@1 668 // Java thread:
aoqi@1 669 //
aoqi@1 670 // Low memory addresses
aoqi@1 671 // +------------------------+
aoqi@1 672 // | |\ JavaThread created by VM does not have glibc
aoqi@1 673 // | glibc guard page | - guard, attached Java thread usually has
aoqi@1 674 // | |/ 1 page glibc guard.
aoqi@1 675 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
aoqi@1 676 // | |\
aoqi@1 677 // | HotSpot Guard Pages | - red and yellow pages
aoqi@1 678 // | |/
aoqi@1 679 // +------------------------+ JavaThread::stack_yellow_zone_base()
aoqi@1 680 // | |\
aoqi@1 681 // | Normal Stack | -
aoqi@1 682 // | |/
aoqi@1 683 // P2 +------------------------+ Thread::stack_base()
aoqi@1 684 //
aoqi@1 685 // Non-Java thread:
aoqi@1 686 //
aoqi@1 687 // Low memory addresses
aoqi@1 688 // +------------------------+
aoqi@1 689 // | |\
aoqi@1 690 // | glibc guard page | - usually 1 page
aoqi@1 691 // | |/
aoqi@1 692 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
aoqi@1 693 // | |\
aoqi@1 694 // | Normal Stack | -
aoqi@1 695 // | |/
aoqi@1 696 // P2 +------------------------+ Thread::stack_base()
aoqi@1 697 //
aoqi@1 698 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
aoqi@1 699 // pthread_attr_getstack()
aoqi@1 700
aoqi@1 701 static void current_stack_region(address * bottom, size_t * size) {
aoqi@1 702 if (os::Linux::is_initial_thread()) {
aoqi@1 703 // initial thread needs special handling because pthread_getattr_np()
aoqi@1 704 // may return bogus value.
aoqi@1 705 *bottom = os::Linux::initial_thread_stack_bottom();
aoqi@1 706 *size = os::Linux::initial_thread_stack_size();
aoqi@1 707 } else {
aoqi@1 708 pthread_attr_t attr;
aoqi@1 709
aoqi@1 710 int rslt = pthread_getattr_np(pthread_self(), &attr);
aoqi@1 711
aoqi@1 712 // JVM needs to know exact stack location, abort if it fails
aoqi@1 713 if (rslt != 0) {
aoqi@1 714 if (rslt == ENOMEM) {
aoqi@1 715 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
aoqi@1 716 } else {
aoqi@1 717 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
aoqi@1 718 }
aoqi@1 719 }
aoqi@1 720
aoqi@1 721 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0 ) {
aoqi@1 722 fatal("Can not locate current stack attributes!");
aoqi@1 723 }
aoqi@1 724 /*
aoqi@1 725 void * top;
aoqi@1 726 if (pthread_attr_getstackaddr(&attr, &top) != 0 ||
aoqi@1 727 pthread_attr_getstacksize(&attr, size) != 0) {
aoqi@1 728 fatal("Can not locate current stack attributes!");
aoqi@1 729 }
aoqi@1 730 */
aoqi@1 731 pthread_attr_destroy(&attr);
aoqi@1 732
aoqi@1 733 //*bottom = (address) align_size_up((uintptr_t)top - *size, os::Linux::page_size());
aoqi@1 734 //*size = (address)top - *bottom;
aoqi@1 735 }
aoqi@1 736 assert(os::current_stack_pointer() >= *bottom &&
aoqi@1 737 os::current_stack_pointer() < *bottom + *size, "just checking");
aoqi@1 738 }
aoqi@1 739
aoqi@1 740 address os::current_stack_base() {
aoqi@1 741 address bottom;
aoqi@1 742 size_t size;
aoqi@1 743 current_stack_region(&bottom, &size);
aoqi@1 744 return (bottom + size);
aoqi@1 745 }
aoqi@1 746
aoqi@1 747 size_t os::current_stack_size() {
aoqi@1 748 // stack size includes normal stack and HotSpot guard pages
aoqi@1 749 address bottom;
aoqi@1 750 size_t size;
aoqi@1 751 current_stack_region(&bottom, &size);
aoqi@1 752 return size;
aoqi@1 753 }
aoqi@1 754
aoqi@1 755 /////////////////////////////////////////////////////////////////////////////
aoqi@1 756 // helper functions for fatal error handler
aoqi@1 757 void os::print_register_info(outputStream *st, void *context) {
aoqi@1 758 if (context == NULL) return;
aoqi@1 759
aoqi@1 760 ucontext_t *uc = (ucontext_t*)context;
aoqi@1 761
aoqi@1 762 st->print_cr("Register to memory mapping:");
aoqi@1 763 st->cr();
aoqi@1 764 // this is horrendously verbose but the layout of the registers in the
aoqi@1 765 // // context does not match how we defined our abstract Register set, so
aoqi@1 766 // // we can't just iterate through the gregs area
aoqi@1 767 //
aoqi@1 768 // // this is only for the "general purpose" registers
aoqi@1 769 st->print("R0=" ); print_location(st, uc->uc_mcontext.gregs[0]);
aoqi@1 770 st->print("AT=" ); print_location(st, uc->uc_mcontext.gregs[1]);
aoqi@1 771 st->print("V0=" ); print_location(st, uc->uc_mcontext.gregs[2]);
aoqi@1 772 st->print("V1=" ); print_location(st, uc->uc_mcontext.gregs[3]);
aoqi@1 773 st->cr();
aoqi@1 774 st->print("A0=" ); print_location(st, uc->uc_mcontext.gregs[4]);
aoqi@1 775 st->print("A1=" ); print_location(st, uc->uc_mcontext.gregs[5]);
aoqi@1 776 st->print("A2=" ); print_location(st, uc->uc_mcontext.gregs[6]);
aoqi@1 777 st->print("A3=" ); print_location(st, uc->uc_mcontext.gregs[7]);
aoqi@1 778 st->cr();
aoqi@1 779 st->print("A4=" ); print_location(st, uc->uc_mcontext.gregs[8]);
aoqi@1 780 st->print("A5=" ); print_location(st, uc->uc_mcontext.gregs[9]);
aoqi@1 781 st->print("A6=" ); print_location(st, uc->uc_mcontext.gregs[10]);
aoqi@1 782 st->print("A7=" ); print_location(st, uc->uc_mcontext.gregs[11]);
aoqi@1 783 st->cr();
aoqi@1 784 st->print("T0=" ); print_location(st, uc->uc_mcontext.gregs[12]);
aoqi@1 785 st->print("T1=" ); print_location(st, uc->uc_mcontext.gregs[13]);
aoqi@1 786 st->print("T2=" ); print_location(st, uc->uc_mcontext.gregs[14]);
aoqi@1 787 st->print("T3=" ); print_location(st, uc->uc_mcontext.gregs[15]);
aoqi@1 788 st->cr();
aoqi@1 789 st->print("S0=" ); print_location(st, uc->uc_mcontext.gregs[16]);
aoqi@1 790 st->print("S1=" ); print_location(st, uc->uc_mcontext.gregs[17]);
aoqi@1 791 st->print("S2=" ); print_location(st, uc->uc_mcontext.gregs[18]);
aoqi@1 792 st->print("S3=" ); print_location(st, uc->uc_mcontext.gregs[19]);
aoqi@1 793 st->cr();
aoqi@1 794 st->print("S4=" ); print_location(st, uc->uc_mcontext.gregs[20]);
aoqi@1 795 st->print("S5=" ); print_location(st, uc->uc_mcontext.gregs[21]);
aoqi@1 796 st->print("S6=" ); print_location(st, uc->uc_mcontext.gregs[22]);
aoqi@1 797 st->print("S7=" ); print_location(st, uc->uc_mcontext.gregs[23]);
aoqi@1 798 st->cr();
aoqi@1 799 st->print("T8=" ); print_location(st, uc->uc_mcontext.gregs[24]);
aoqi@1 800 st->print("T9=" ); print_location(st, uc->uc_mcontext.gregs[25]);
aoqi@1 801 st->print("K0=" ); print_location(st, uc->uc_mcontext.gregs[26]);
aoqi@1 802 st->print("K1=" ); print_location(st, uc->uc_mcontext.gregs[27]);
aoqi@1 803 st->cr();
aoqi@1 804 st->print("GP=" ); print_location(st, uc->uc_mcontext.gregs[28]);
aoqi@1 805 st->print("SP=" ); print_location(st, uc->uc_mcontext.gregs[29]);
aoqi@1 806 st->print("FP=" ); print_location(st, uc->uc_mcontext.gregs[30]);
aoqi@1 807 st->print("RA=" ); print_location(st, uc->uc_mcontext.gregs[31]);
aoqi@1 808 st->cr();
aoqi@1 809
aoqi@1 810 }
aoqi@1 811 void os::print_context(outputStream *st, void *context) {
aoqi@1 812 if (context == NULL) return;
aoqi@1 813
aoqi@1 814 ucontext_t *uc = (ucontext_t*)context;
aoqi@1 815 st->print_cr("Registers:");
aoqi@1 816 st->print( "R0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[0]);
aoqi@1 817 st->print(", AT=" INTPTR_FORMAT, uc->uc_mcontext.gregs[1]);
aoqi@1 818 st->print(", V0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[2]);
aoqi@1 819 st->print(", V1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[3]);
aoqi@1 820 st->cr();
aoqi@1 821 st->print( "A0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[4]);
aoqi@1 822 st->print(", A1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[5]);
aoqi@1 823 st->print(", A2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[6]);
aoqi@1 824 st->print(", A3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[7]);
aoqi@1 825 st->cr();
aoqi@1 826 st->print( "A4=" INTPTR_FORMAT, uc->uc_mcontext.gregs[8]);
aoqi@1 827 st->print(", A5=" INTPTR_FORMAT, uc->uc_mcontext.gregs[9]);
aoqi@1 828 st->print(", A6=" INTPTR_FORMAT, uc->uc_mcontext.gregs[10]);
aoqi@1 829 st->print(", A7=" INTPTR_FORMAT, uc->uc_mcontext.gregs[11]);
aoqi@1 830 st->cr();
aoqi@1 831 st->print( "T0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[12]);
aoqi@1 832 st->print(", T1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[13]);
aoqi@1 833 st->print(", T2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[14]);
aoqi@1 834 st->print(", T3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[15]);
aoqi@1 835 st->cr();
aoqi@1 836 st->print( "S0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[16]);
aoqi@1 837 st->print(", S1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[17]);
aoqi@1 838 st->print(", S2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[18]);
aoqi@1 839 st->print(", S3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[19]);
aoqi@1 840 st->cr();
aoqi@1 841 st->print( "S4=" INTPTR_FORMAT, uc->uc_mcontext.gregs[20]);
aoqi@1 842 st->print(", S5=" INTPTR_FORMAT, uc->uc_mcontext.gregs[21]);
aoqi@1 843 st->print(", S6=" INTPTR_FORMAT, uc->uc_mcontext.gregs[22]);
aoqi@1 844 st->print(", S7=" INTPTR_FORMAT, uc->uc_mcontext.gregs[23]);
aoqi@1 845 st->cr();
aoqi@1 846 st->print( "T8=" INTPTR_FORMAT, uc->uc_mcontext.gregs[24]);
aoqi@1 847 st->print(", T9=" INTPTR_FORMAT, uc->uc_mcontext.gregs[25]);
aoqi@1 848 st->print(", K0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[26]);
aoqi@1 849 st->print(", K1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[27]);
aoqi@1 850 st->cr();
aoqi@1 851 st->print( "GP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[28]);
aoqi@1 852 st->print(", SP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[29]);
aoqi@1 853 st->print(", FP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[30]);
aoqi@1 854 st->print(", RA=" INTPTR_FORMAT, uc->uc_mcontext.gregs[31]);
aoqi@1 855 st->cr();
aoqi@1 856 st->cr();
aoqi@1 857
aoqi@1 858 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
aoqi@1 859 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
aoqi@1 860 //print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
aoqi@1 861 print_hex_dump(st, (address)sp-32, (address)(sp + 32), sizeof(intptr_t));
aoqi@1 862 st->cr();
aoqi@1 863
aoqi@1 864 // Note: it may be unsafe to inspect memory near pc. For example, pc may
aoqi@1 865 // point to garbage if entry point in an nmethod is corrupted. Leave
aoqi@1 866 // this at the end, and hope for the best.
aoqi@1 867 address pc = os::Linux::ucontext_get_pc(uc);
aoqi@1 868 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
aoqi@1 869 print_hex_dump(st, pc - 64, pc + 64, sizeof(char));
aoqi@1 870 Disassembler::decode(pc - 80, pc + 80, st);
aoqi@1 871 }
aoqi@1 872
aoqi@1 873 #ifndef PRODUCT
aoqi@1 874 void os::verify_stack_alignment() {
aoqi@1 875 assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
aoqi@1 876 }
aoqi@1 877 #endif
aoqi@1 878

mercurial