Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * Copyright 2012, 2014 SAP AG. All rights reserved. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | // no precompiled headers |
aoqi@0 | 27 | #include "assembler_ppc.inline.hpp" |
aoqi@0 | 28 | #include "classfile/classLoader.hpp" |
aoqi@0 | 29 | #include "classfile/systemDictionary.hpp" |
aoqi@0 | 30 | #include "classfile/vmSymbols.hpp" |
aoqi@0 | 31 | #include "code/icBuffer.hpp" |
aoqi@0 | 32 | #include "code/vtableStubs.hpp" |
aoqi@0 | 33 | #include "interpreter/interpreter.hpp" |
aoqi@0 | 34 | #include "jvm_aix.h" |
aoqi@0 | 35 | #include "memory/allocation.inline.hpp" |
aoqi@0 | 36 | #include "mutex_aix.inline.hpp" |
aoqi@0 | 37 | #include "nativeInst_ppc.hpp" |
aoqi@0 | 38 | #include "os_share_aix.hpp" |
aoqi@0 | 39 | #include "prims/jniFastGetField.hpp" |
aoqi@0 | 40 | #include "prims/jvm.h" |
aoqi@0 | 41 | #include "prims/jvm_misc.hpp" |
aoqi@0 | 42 | #include "runtime/arguments.hpp" |
aoqi@0 | 43 | #include "runtime/extendedPC.hpp" |
aoqi@0 | 44 | #include "runtime/frame.inline.hpp" |
aoqi@0 | 45 | #include "runtime/interfaceSupport.hpp" |
aoqi@0 | 46 | #include "runtime/java.hpp" |
aoqi@0 | 47 | #include "runtime/javaCalls.hpp" |
aoqi@0 | 48 | #include "runtime/mutexLocker.hpp" |
aoqi@0 | 49 | #include "runtime/osThread.hpp" |
aoqi@0 | 50 | #include "runtime/sharedRuntime.hpp" |
aoqi@0 | 51 | #include "runtime/stubRoutines.hpp" |
aoqi@0 | 52 | #include "runtime/thread.inline.hpp" |
aoqi@0 | 53 | #include "runtime/timer.hpp" |
aoqi@0 | 54 | #include "utilities/events.hpp" |
aoqi@0 | 55 | #include "utilities/vmError.hpp" |
aoqi@0 | 56 | #ifdef COMPILER1 |
aoqi@0 | 57 | #include "c1/c1_Runtime1.hpp" |
aoqi@0 | 58 | #endif |
aoqi@0 | 59 | #ifdef COMPILER2 |
aoqi@0 | 60 | #include "opto/runtime.hpp" |
aoqi@0 | 61 | #endif |
aoqi@0 | 62 | |
aoqi@0 | 63 | // put OS-includes here |
aoqi@0 | 64 | # include <ucontext.h> |
aoqi@0 | 65 | |
aoqi@0 | 66 | address os::current_stack_pointer() { |
aoqi@0 | 67 | address csp; |
aoqi@0 | 68 | |
aoqi@0 | 69 | #if !defined(USE_XLC_BUILTINS) |
aoqi@0 | 70 | // inline assembly for `mr regno(csp), R1_SP': |
aoqi@0 | 71 | __asm__ __volatile__ ("mr %0, 1":"=r"(csp):); |
aoqi@0 | 72 | #else |
aoqi@0 | 73 | csp = (address) __builtin_frame_address(0); |
aoqi@0 | 74 | #endif |
aoqi@0 | 75 | |
aoqi@0 | 76 | return csp; |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | char* os::non_memory_address_word() { |
aoqi@0 | 80 | // Must never look like an address returned by reserve_memory, |
aoqi@0 | 81 | // even in its subfields (as defined by the CPU immediate fields, |
aoqi@0 | 82 | // if the CPU splits constants across multiple instructions). |
aoqi@0 | 83 | |
aoqi@0 | 84 | return (char*) -1; |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | // OS specific thread initialization |
aoqi@0 | 88 | // |
aoqi@0 | 89 | // Calculate and store the limits of the memory stack. |
aoqi@0 | 90 | void os::initialize_thread(Thread *thread) { } |
aoqi@0 | 91 | |
aoqi@0 | 92 | // Frame information (pc, sp, fp) retrieved via ucontext |
aoqi@0 | 93 | // always looks like a C-frame according to the frame |
aoqi@0 | 94 | // conventions in frame_ppc64.hpp. |
aoqi@0 | 95 | address os::Aix::ucontext_get_pc(ucontext_t * uc) { |
aoqi@0 | 96 | return (address)uc->uc_mcontext.jmp_context.iar; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | intptr_t* os::Aix::ucontext_get_sp(ucontext_t * uc) { |
aoqi@0 | 100 | // gpr1 holds the stack pointer on aix |
aoqi@0 | 101 | return (intptr_t*)uc->uc_mcontext.jmp_context.gpr[1/*REG_SP*/]; |
aoqi@0 | 102 | } |
aoqi@0 | 103 | |
aoqi@0 | 104 | intptr_t* os::Aix::ucontext_get_fp(ucontext_t * uc) { |
aoqi@0 | 105 | return NULL; |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | void os::Aix::ucontext_set_pc(ucontext_t* uc, address new_pc) { |
aoqi@0 | 109 | uc->uc_mcontext.jmp_context.iar = (uint64_t) new_pc; |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | ExtendedPC os::fetch_frame_from_context(void* ucVoid, |
aoqi@0 | 113 | intptr_t** ret_sp, intptr_t** ret_fp) { |
aoqi@0 | 114 | |
aoqi@0 | 115 | ExtendedPC epc; |
aoqi@0 | 116 | ucontext_t* uc = (ucontext_t*)ucVoid; |
aoqi@0 | 117 | |
aoqi@0 | 118 | if (uc != NULL) { |
aoqi@0 | 119 | epc = ExtendedPC(os::Aix::ucontext_get_pc(uc)); |
aoqi@0 | 120 | if (ret_sp) *ret_sp = os::Aix::ucontext_get_sp(uc); |
aoqi@0 | 121 | if (ret_fp) *ret_fp = os::Aix::ucontext_get_fp(uc); |
aoqi@0 | 122 | } else { |
aoqi@0 | 123 | // construct empty ExtendedPC for return value checking |
aoqi@0 | 124 | epc = ExtendedPC(NULL); |
aoqi@0 | 125 | if (ret_sp) *ret_sp = (intptr_t *)NULL; |
aoqi@0 | 126 | if (ret_fp) *ret_fp = (intptr_t *)NULL; |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | return epc; |
aoqi@0 | 130 | } |
aoqi@0 | 131 | |
aoqi@0 | 132 | frame os::fetch_frame_from_context(void* ucVoid) { |
aoqi@0 | 133 | intptr_t* sp; |
aoqi@0 | 134 | intptr_t* fp; |
aoqi@0 | 135 | ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); |
aoqi@0 | 136 | // Avoid crash during crash if pc broken. |
aoqi@0 | 137 | if (epc.pc()) { |
aoqi@0 | 138 | frame fr(sp, epc.pc()); |
aoqi@0 | 139 | return fr; |
aoqi@0 | 140 | } |
aoqi@0 | 141 | frame fr(sp); |
aoqi@0 | 142 | return fr; |
aoqi@0 | 143 | } |
aoqi@0 | 144 | |
aoqi@0 | 145 | frame os::get_sender_for_C_frame(frame* fr) { |
aoqi@0 | 146 | if (*fr->sp() == NULL) { |
aoqi@0 | 147 | // fr is the last C frame |
aoqi@0 | 148 | return frame(NULL, NULL); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | return frame(fr->sender_sp(), fr->sender_pc()); |
aoqi@0 | 151 | } |
aoqi@0 | 152 | |
aoqi@0 | 153 | |
aoqi@0 | 154 | frame os::current_frame() { |
aoqi@0 | 155 | intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer()); |
aoqi@0 | 156 | // hack. |
aoqi@0 | 157 | frame topframe(csp, (address)0x8); |
aoqi@0 | 158 | // return sender of current topframe which hopefully has pc != NULL. |
aoqi@0 | 159 | return os::get_sender_for_C_frame(&topframe); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | // Utility functions |
aoqi@0 | 163 | |
aoqi@0 | 164 | extern "C" JNIEXPORT int |
aoqi@0 | 165 | JVM_handle_aix_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { |
aoqi@0 | 166 | |
aoqi@0 | 167 | ucontext_t* uc = (ucontext_t*) ucVoid; |
aoqi@0 | 168 | |
aoqi@0 | 169 | Thread* t = ThreadLocalStorage::get_thread_slow(); // slow & steady |
aoqi@0 | 170 | |
aoqi@0 | 171 | SignalHandlerMark shm(t); |
aoqi@0 | 172 | |
aoqi@0 | 173 | // Note: it's not uncommon that JNI code uses signal/sigset to install |
aoqi@0 | 174 | // then restore certain signal handler (e.g. to temporarily block SIGPIPE, |
aoqi@0 | 175 | // or have a SIGILL handler when detecting CPU type). When that happens, |
aoqi@0 | 176 | // JVM_handle_aix_signal() might be invoked with junk info/ucVoid. To |
aoqi@0 | 177 | // avoid unnecessary crash when libjsig is not preloaded, try handle signals |
aoqi@0 | 178 | // that do not require siginfo/ucontext first. |
aoqi@0 | 179 | |
aoqi@0 | 180 | if (sig == SIGPIPE) { |
aoqi@0 | 181 | if (os::Aix::chained_handler(sig, info, ucVoid)) { |
aoqi@0 | 182 | return 1; |
aoqi@0 | 183 | } else { |
aoqi@0 | 184 | if (PrintMiscellaneous && (WizardMode || Verbose)) { |
aoqi@0 | 185 | warning("Ignoring SIGPIPE - see bug 4229104"); |
aoqi@0 | 186 | } |
aoqi@0 | 187 | return 1; |
aoqi@0 | 188 | } |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | JavaThread* thread = NULL; |
aoqi@0 | 192 | VMThread* vmthread = NULL; |
aoqi@0 | 193 | if (os::Aix::signal_handlers_are_installed) { |
aoqi@0 | 194 | if (t != NULL) { |
aoqi@0 | 195 | if(t->is_Java_thread()) { |
aoqi@0 | 196 | thread = (JavaThread*)t; |
aoqi@0 | 197 | } |
aoqi@0 | 198 | else if(t->is_VM_thread()) { |
aoqi@0 | 199 | vmthread = (VMThread *)t; |
aoqi@0 | 200 | } |
aoqi@0 | 201 | } |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | // Decide if this trap can be handled by a stub. |
aoqi@0 | 205 | address stub = NULL; |
aoqi@0 | 206 | |
aoqi@0 | 207 | // retrieve program counter |
aoqi@0 | 208 | address const pc = uc ? os::Aix::ucontext_get_pc(uc) : NULL; |
aoqi@0 | 209 | |
aoqi@0 | 210 | // retrieve crash address |
aoqi@0 | 211 | address const addr = info ? (const address) info->si_addr : NULL; |
aoqi@0 | 212 | |
aoqi@0 | 213 | // SafeFetch 32 handling: |
aoqi@0 | 214 | // - make it work if _thread is null |
aoqi@0 | 215 | // - make it use the standard os::...::ucontext_get/set_pc APIs |
aoqi@0 | 216 | if (uc) { |
aoqi@0 | 217 | address const pc = os::Aix::ucontext_get_pc(uc); |
aoqi@0 | 218 | if (pc && StubRoutines::is_safefetch_fault(pc)) { |
aoqi@0 | 219 | os::Aix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); |
aoqi@0 | 220 | return true; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | // Handle SIGDANGER right away. AIX would raise SIGDANGER whenever available swap |
aoqi@0 | 225 | // space falls below 30%. This is only a chance for the process to gracefully abort. |
aoqi@0 | 226 | // We can't hope to proceed after SIGDANGER since SIGKILL tailgates. |
aoqi@0 | 227 | if (sig == SIGDANGER) { |
aoqi@0 | 228 | goto report_and_die; |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | if (info == NULL || uc == NULL || thread == NULL && vmthread == NULL) { |
aoqi@0 | 232 | goto run_chained_handler; |
aoqi@0 | 233 | } |
aoqi@0 | 234 | |
aoqi@0 | 235 | // If we are a java thread... |
aoqi@0 | 236 | if (thread != NULL) { |
aoqi@0 | 237 | |
aoqi@0 | 238 | // Handle ALL stack overflow variations here |
aoqi@0 | 239 | if (sig == SIGSEGV && (addr < thread->stack_base() && |
aoqi@0 | 240 | addr >= thread->stack_base() - thread->stack_size())) { |
aoqi@0 | 241 | // stack overflow |
aoqi@0 | 242 | // |
aoqi@0 | 243 | // If we are in a yellow zone and we are inside java, we disable the yellow zone and |
aoqi@0 | 244 | // throw a stack overflow exception. |
aoqi@0 | 245 | // If we are in native code or VM C code, we report-and-die. The original coding tried |
aoqi@0 | 246 | // to continue with yellow zone disabled, but that doesn't buy us much and prevents |
aoqi@0 | 247 | // hs_err_pid files. |
aoqi@0 | 248 | if (thread->in_stack_yellow_zone(addr)) { |
aoqi@0 | 249 | thread->disable_stack_yellow_zone(); |
aoqi@0 | 250 | if (thread->thread_state() == _thread_in_Java) { |
aoqi@0 | 251 | // Throw a stack overflow exception. |
aoqi@0 | 252 | // Guard pages will be reenabled while unwinding the stack. |
aoqi@0 | 253 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); |
aoqi@0 | 254 | goto run_stub; |
aoqi@0 | 255 | } else { |
aoqi@0 | 256 | // Thread was in the vm or native code. Return and try to finish. |
aoqi@0 | 257 | return 1; |
aoqi@0 | 258 | } |
aoqi@0 | 259 | } else if (thread->in_stack_red_zone(addr)) { |
aoqi@0 | 260 | // Fatal red zone violation. Disable the guard pages and fall through |
aoqi@0 | 261 | // to handle_unexpected_exception way down below. |
aoqi@0 | 262 | thread->disable_stack_red_zone(); |
aoqi@0 | 263 | tty->print_raw_cr("An irrecoverable stack overflow has occurred."); |
aoqi@0 | 264 | goto report_and_die; |
aoqi@0 | 265 | } else { |
aoqi@0 | 266 | // This means a segv happened inside our stack, but not in |
aoqi@0 | 267 | // the guarded zone. I'd like to know when this happens, |
aoqi@0 | 268 | tty->print_raw_cr("SIGSEGV happened inside stack but outside yellow and red zone."); |
aoqi@0 | 269 | goto report_and_die; |
aoqi@0 | 270 | } |
aoqi@0 | 271 | |
aoqi@0 | 272 | } // end handle SIGSEGV inside stack boundaries |
aoqi@0 | 273 | |
aoqi@0 | 274 | if (thread->thread_state() == _thread_in_Java) { |
aoqi@0 | 275 | // Java thread running in Java code |
aoqi@0 | 276 | |
aoqi@0 | 277 | // The following signals are used for communicating VM events: |
aoqi@0 | 278 | // |
aoqi@0 | 279 | // SIGILL: the compiler generates illegal opcodes |
aoqi@0 | 280 | // at places where it wishes to interrupt the VM: |
aoqi@0 | 281 | // Safepoints, Unreachable Code, Entry points of Zombie methods, |
aoqi@0 | 282 | // This results in a SIGILL with (*pc) == inserted illegal instruction. |
aoqi@0 | 283 | // |
aoqi@0 | 284 | // (so, SIGILLs with a pc inside the zero page are real errors) |
aoqi@0 | 285 | // |
aoqi@0 | 286 | // SIGTRAP: |
aoqi@0 | 287 | // The ppc trap instruction raises a SIGTRAP and is very efficient if it |
aoqi@0 | 288 | // does not trap. It is used for conditional branches that are expected |
aoqi@0 | 289 | // to be never taken. These are: |
aoqi@0 | 290 | // - zombie methods |
aoqi@0 | 291 | // - IC (inline cache) misses. |
aoqi@0 | 292 | // - null checks leading to UncommonTraps. |
aoqi@0 | 293 | // - range checks leading to Uncommon Traps. |
aoqi@0 | 294 | // On Aix, these are especially null checks, as the ImplicitNullCheck |
aoqi@0 | 295 | // optimization works only in rare cases, as the page at address 0 is only |
aoqi@0 | 296 | // write protected. // |
aoqi@0 | 297 | // Note: !UseSIGTRAP is used to prevent SIGTRAPS altogether, to facilitate debugging. |
aoqi@0 | 298 | // |
aoqi@0 | 299 | // SIGSEGV: |
aoqi@0 | 300 | // used for safe point polling: |
aoqi@0 | 301 | // To notify all threads that they have to reach a safe point, safe point polling is used: |
aoqi@0 | 302 | // All threads poll a certain mapped memory page. Normally, this page has read access. |
aoqi@0 | 303 | // If the VM wants to inform the threads about impending safe points, it puts this |
aoqi@0 | 304 | // page to read only ("poisens" the page), and the threads then reach a safe point. |
aoqi@0 | 305 | // used for null checks: |
aoqi@0 | 306 | // If the compiler finds a store it uses it for a null check. Unfortunately this |
aoqi@0 | 307 | // happens rarely. In heap based and disjoint base compressd oop modes also loads |
aoqi@0 | 308 | // are used for null checks. |
aoqi@0 | 309 | |
aoqi@0 | 310 | // A VM-related SIGILL may only occur if we are not in the zero page. |
aoqi@0 | 311 | // On AIX, we get a SIGILL if we jump to 0x0 or to somewhere else |
aoqi@0 | 312 | // in the zero page, because it is filled with 0x0. We ignore |
aoqi@0 | 313 | // explicit SIGILLs in the zero page. |
aoqi@0 | 314 | if (sig == SIGILL && (pc < (address) 0x200)) { |
aoqi@0 | 315 | if (TraceTraps) { |
aoqi@0 | 316 | tty->print_raw_cr("SIGILL happened inside zero page."); |
aoqi@0 | 317 | } |
aoqi@0 | 318 | goto report_and_die; |
aoqi@0 | 319 | } |
aoqi@0 | 320 | |
aoqi@0 | 321 | // Handle signal from NativeJump::patch_verified_entry(). |
aoqi@0 | 322 | if (( TrapBasedNotEntrantChecks && sig == SIGTRAP && nativeInstruction_at(pc)->is_sigtrap_zombie_not_entrant()) || |
aoqi@0 | 323 | (!TrapBasedNotEntrantChecks && sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant())) { |
aoqi@0 | 324 | if (TraceTraps) { |
aoqi@0 | 325 | tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL"); |
aoqi@0 | 326 | } |
aoqi@0 | 327 | stub = SharedRuntime::get_handle_wrong_method_stub(); |
aoqi@0 | 328 | goto run_stub; |
aoqi@0 | 329 | } |
aoqi@0 | 330 | |
aoqi@0 | 331 | else if (sig == SIGSEGV && os::is_poll_address(addr)) { |
aoqi@0 | 332 | if (TraceTraps) { |
aoqi@0 | 333 | tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", pc); |
aoqi@0 | 334 | } |
aoqi@0 | 335 | stub = SharedRuntime::get_poll_stub(pc); |
aoqi@0 | 336 | goto run_stub; |
aoqi@0 | 337 | } |
aoqi@0 | 338 | |
aoqi@0 | 339 | // SIGTRAP-based ic miss check in compiled code. |
aoqi@0 | 340 | else if (sig == SIGTRAP && TrapBasedICMissChecks && |
aoqi@0 | 341 | nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) { |
aoqi@0 | 342 | if (TraceTraps) { |
aoqi@0 | 343 | tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", pc); |
aoqi@0 | 344 | } |
aoqi@0 | 345 | stub = SharedRuntime::get_ic_miss_stub(); |
aoqi@0 | 346 | goto run_stub; |
aoqi@0 | 347 | } |
aoqi@0 | 348 | |
aoqi@0 | 349 | // SIGTRAP-based implicit null check in compiled code. |
aoqi@0 | 350 | else if (sig == SIGTRAP && TrapBasedNullChecks && |
aoqi@0 | 351 | nativeInstruction_at(pc)->is_sigtrap_null_check()) { |
aoqi@0 | 352 | if (TraceTraps) { |
aoqi@0 | 353 | tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", pc); |
aoqi@0 | 354 | } |
aoqi@0 | 355 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
aoqi@0 | 356 | goto run_stub; |
aoqi@0 | 357 | } |
aoqi@0 | 358 | |
aoqi@0 | 359 | // SIGSEGV-based implicit null check in compiled code. |
aoqi@0 | 360 | else if (sig == SIGSEGV && ImplicitNullChecks && |
aoqi@0 | 361 | CodeCache::contains((void*) pc) && |
aoqi@0 | 362 | !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) { |
aoqi@0 | 363 | if (TraceTraps) { |
aoqi@0 | 364 | tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc); |
aoqi@0 | 365 | } |
aoqi@0 | 366 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
aoqi@0 | 367 | } |
aoqi@0 | 368 | |
aoqi@0 | 369 | #ifdef COMPILER2 |
aoqi@0 | 370 | // SIGTRAP-based implicit range check in compiled code. |
aoqi@0 | 371 | else if (sig == SIGTRAP && TrapBasedRangeChecks && |
aoqi@0 | 372 | nativeInstruction_at(pc)->is_sigtrap_range_check()) { |
aoqi@0 | 373 | if (TraceTraps) { |
aoqi@0 | 374 | tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", pc); |
aoqi@0 | 375 | } |
aoqi@0 | 376 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
aoqi@0 | 377 | goto run_stub; |
aoqi@0 | 378 | } |
aoqi@0 | 379 | #endif |
aoqi@0 | 380 | |
aoqi@0 | 381 | else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) { |
aoqi@0 | 382 | if (TraceTraps) { |
aoqi@0 | 383 | tty->print_raw_cr("Fix SIGFPE handler, trying divide by zero handler."); |
aoqi@0 | 384 | } |
aoqi@0 | 385 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); |
aoqi@0 | 386 | goto run_stub; |
aoqi@0 | 387 | } |
aoqi@0 | 388 | |
aoqi@0 | 389 | else if (sig == SIGBUS) { |
aoqi@0 | 390 | // BugId 4454115: A read from a MappedByteBuffer can fault here if the |
aoqi@0 | 391 | // underlying file has been truncated. Do not crash the VM in such a case. |
aoqi@0 | 392 | CodeBlob* cb = CodeCache::find_blob_unsafe(pc); |
aoqi@0 | 393 | nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; |
aoqi@0 | 394 | if (nm != NULL && nm->has_unsafe_access()) { |
aoqi@0 | 395 | // We don't really need a stub here! Just set the pending exeption and |
aoqi@0 | 396 | // continue at the next instruction after the faulting read. Returning |
aoqi@0 | 397 | // garbage from this read is ok. |
aoqi@0 | 398 | thread->set_pending_unsafe_access_error(); |
aoqi@0 | 399 | uc->uc_mcontext.jmp_context.iar = ((unsigned long)pc) + 4; |
aoqi@0 | 400 | return 1; |
aoqi@0 | 401 | } |
aoqi@0 | 402 | } |
aoqi@0 | 403 | } |
aoqi@0 | 404 | |
aoqi@0 | 405 | else { // thread->thread_state() != _thread_in_Java |
aoqi@0 | 406 | // Detect CPU features. This is only done at the very start of the VM. Later, the |
aoqi@0 | 407 | // VM_Version::is_determine_features_test_running() flag should be false. |
aoqi@0 | 408 | |
aoqi@0 | 409 | if (sig == SIGILL && VM_Version::is_determine_features_test_running()) { |
aoqi@0 | 410 | // SIGILL must be caused by VM_Version::determine_features(). |
aoqi@0 | 411 | *(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL, |
aoqi@0 | 412 | // flushing of icache is not necessary. |
aoqi@0 | 413 | stub = pc + 4; // continue with next instruction. |
aoqi@0 | 414 | goto run_stub; |
aoqi@0 | 415 | } |
aoqi@0 | 416 | else if (thread->thread_state() == _thread_in_vm && |
aoqi@0 | 417 | sig == SIGBUS && thread->doing_unsafe_access()) { |
aoqi@0 | 418 | // We don't really need a stub here! Just set the pending exeption and |
aoqi@0 | 419 | // continue at the next instruction after the faulting read. Returning |
aoqi@0 | 420 | // garbage from this read is ok. |
aoqi@0 | 421 | thread->set_pending_unsafe_access_error(); |
aoqi@0 | 422 | uc->uc_mcontext.jmp_context.iar = ((unsigned long)pc) + 4; |
aoqi@0 | 423 | return 1; |
aoqi@0 | 424 | } |
aoqi@0 | 425 | } |
aoqi@0 | 426 | |
aoqi@0 | 427 | // Check to see if we caught the safepoint code in the |
aoqi@0 | 428 | // process of write protecting the memory serialization page. |
aoqi@0 | 429 | // It write enables the page immediately after protecting it |
aoqi@0 | 430 | // so we can just return to retry the write. |
aoqi@0 | 431 | if ((sig == SIGSEGV) && |
aoqi@0 | 432 | os::is_memory_serialize_page(thread, addr)) { |
aoqi@0 | 433 | // Synchronization problem in the pseudo memory barrier code (bug id 6546278) |
aoqi@0 | 434 | // Block current thread until the memory serialize page permission restored. |
aoqi@0 | 435 | os::block_on_serialize_page_trap(); |
aoqi@0 | 436 | return true; |
aoqi@0 | 437 | } |
aoqi@0 | 438 | } |
aoqi@0 | 439 | |
aoqi@0 | 440 | run_stub: |
aoqi@0 | 441 | |
aoqi@0 | 442 | // One of the above code blocks ininitalized the stub, so we want to |
aoqi@0 | 443 | // delegate control to that stub. |
aoqi@0 | 444 | if (stub != NULL) { |
aoqi@0 | 445 | // Save all thread context in case we need to restore it. |
aoqi@0 | 446 | if (thread != NULL) thread->set_saved_exception_pc(pc); |
aoqi@0 | 447 | uc->uc_mcontext.jmp_context.iar = (unsigned long)stub; |
aoqi@0 | 448 | return 1; |
aoqi@0 | 449 | } |
aoqi@0 | 450 | |
aoqi@0 | 451 | run_chained_handler: |
aoqi@0 | 452 | |
aoqi@0 | 453 | // signal-chaining |
aoqi@0 | 454 | if (os::Aix::chained_handler(sig, info, ucVoid)) { |
aoqi@0 | 455 | return 1; |
aoqi@0 | 456 | } |
aoqi@0 | 457 | if (!abort_if_unrecognized) { |
aoqi@0 | 458 | // caller wants another chance, so give it to him |
aoqi@0 | 459 | return 0; |
aoqi@0 | 460 | } |
aoqi@0 | 461 | |
aoqi@0 | 462 | report_and_die: |
aoqi@0 | 463 | |
aoqi@0 | 464 | // Use sigthreadmask instead of sigprocmask on AIX and unmask current signal. |
aoqi@0 | 465 | sigset_t newset; |
aoqi@0 | 466 | sigemptyset(&newset); |
aoqi@0 | 467 | sigaddset(&newset, sig); |
aoqi@0 | 468 | sigthreadmask(SIG_UNBLOCK, &newset, NULL); |
aoqi@0 | 469 | |
aoqi@0 | 470 | VMError err(t, sig, pc, info, ucVoid); |
aoqi@0 | 471 | err.report_and_die(); |
aoqi@0 | 472 | |
aoqi@0 | 473 | ShouldNotReachHere(); |
aoqi@0 | 474 | return 0; |
aoqi@0 | 475 | } |
aoqi@0 | 476 | |
aoqi@0 | 477 | void os::Aix::init_thread_fpu_state(void) { |
aoqi@0 | 478 | #if !defined(USE_XLC_BUILTINS) |
aoqi@0 | 479 | // Disable FP exceptions. |
aoqi@0 | 480 | __asm__ __volatile__ ("mtfsfi 6,0"); |
aoqi@0 | 481 | #else |
aoqi@0 | 482 | __mtfsfi(6, 0); |
aoqi@0 | 483 | #endif |
aoqi@0 | 484 | } |
aoqi@0 | 485 | |
aoqi@0 | 486 | //////////////////////////////////////////////////////////////////////////////// |
aoqi@0 | 487 | // thread stack |
aoqi@0 | 488 | |
aoqi@0 | 489 | size_t os::Aix::min_stack_allowed = 768*K; |
aoqi@0 | 490 | |
aoqi@0 | 491 | // Aix is always in floating stack mode. The stack size for a new |
aoqi@0 | 492 | // thread can be set via pthread_attr_setstacksize(). |
aoqi@0 | 493 | bool os::Aix::supports_variable_stack_size() { return true; } |
aoqi@0 | 494 | |
aoqi@0 | 495 | // return default stack size for thr_type |
aoqi@0 | 496 | size_t os::Aix::default_stack_size(os::ThreadType thr_type) { |
aoqi@0 | 497 | // default stack size (compiler thread needs larger stack) |
aoqi@0 | 498 | // Notice that the setting for compiler threads here have no impact |
aoqi@0 | 499 | // because of the strange 'fallback logic' in os::create_thread(). |
aoqi@0 | 500 | // Better set CompilerThreadStackSize in globals_<os_cpu>.hpp if you want to |
aoqi@0 | 501 | // specify a different stack size for compiler threads! |
aoqi@0 | 502 | size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K); |
aoqi@0 | 503 | return s; |
aoqi@0 | 504 | } |
aoqi@0 | 505 | |
aoqi@0 | 506 | size_t os::Aix::default_guard_size(os::ThreadType thr_type) { |
aoqi@0 | 507 | return 2 * page_size(); |
aoqi@0 | 508 | } |
aoqi@0 | 509 | |
aoqi@0 | 510 | ///////////////////////////////////////////////////////////////////////////// |
aoqi@0 | 511 | // helper functions for fatal error handler |
aoqi@0 | 512 | |
aoqi@0 | 513 | void os::print_context(outputStream *st, void *context) { |
aoqi@0 | 514 | if (context == NULL) return; |
aoqi@0 | 515 | |
aoqi@0 | 516 | ucontext_t* uc = (ucontext_t*)context; |
aoqi@0 | 517 | |
aoqi@0 | 518 | st->print_cr("Registers:"); |
aoqi@0 | 519 | st->print("pc =" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.iar); |
aoqi@0 | 520 | st->print("lr =" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.lr); |
aoqi@0 | 521 | st->print("ctr=" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.ctr); |
aoqi@0 | 522 | st->cr(); |
aoqi@0 | 523 | for (int i = 0; i < 32; i++) { |
aoqi@0 | 524 | st->print("r%-2d=" INTPTR_FORMAT " ", i, uc->uc_mcontext.jmp_context.gpr[i]); |
aoqi@0 | 525 | if (i % 3 == 2) st->cr(); |
aoqi@0 | 526 | } |
aoqi@0 | 527 | st->cr(); |
aoqi@0 | 528 | st->cr(); |
aoqi@0 | 529 | |
aoqi@0 | 530 | intptr_t *sp = (intptr_t *)os::Aix::ucontext_get_sp(uc); |
aoqi@0 | 531 | st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); |
aoqi@0 | 532 | print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t)); |
aoqi@0 | 533 | st->cr(); |
aoqi@0 | 534 | |
aoqi@0 | 535 | // Note: it may be unsafe to inspect memory near pc. For example, pc may |
aoqi@0 | 536 | // point to garbage if entry point in an nmethod is corrupted. Leave |
aoqi@0 | 537 | // this at the end, and hope for the best. |
aoqi@0 | 538 | address pc = os::Aix::ucontext_get_pc(uc); |
aoqi@0 | 539 | st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); |
aoqi@0 | 540 | print_hex_dump(st, pc - 64, pc + 64, /*instrsize=*/4); |
aoqi@0 | 541 | st->cr(); |
aoqi@0 | 542 | |
aoqi@0 | 543 | // Try to decode the instructions. |
aoqi@0 | 544 | st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", pc); |
aoqi@0 | 545 | st->print("<TODO: PPC port - print_context>"); |
aoqi@0 | 546 | // TODO: PPC port Disassembler::decode(pc, 16, 16, st); |
aoqi@0 | 547 | st->cr(); |
aoqi@0 | 548 | } |
aoqi@0 | 549 | |
aoqi@0 | 550 | void os::print_register_info(outputStream *st, void *context) { |
aoqi@0 | 551 | if (context == NULL) return; |
aoqi@0 | 552 | st->print("Not ported - print_register_info\n"); |
aoqi@0 | 553 | } |
aoqi@0 | 554 | |
aoqi@0 | 555 | extern "C" { |
aoqi@0 | 556 | int SpinPause() { |
aoqi@0 | 557 | return 0; |
aoqi@0 | 558 | } |
aoqi@0 | 559 | } |
aoqi@0 | 560 | |
aoqi@0 | 561 | #ifndef PRODUCT |
aoqi@0 | 562 | void os::verify_stack_alignment() { |
aoqi@0 | 563 | assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment"); |
aoqi@0 | 564 | } |
aoqi@0 | 565 | #endif |