1 /* 2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 // no precompiled headers 26 #include "assembler_sparc.inline.hpp" 27 #include "classfile/classLoader.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "code/icBuffer.hpp" 31 #include "code/vtableStubs.hpp" 32 #include "interpreter/interpreter.hpp" 33 #include "jvm_linux.h" 34 #include "memory/allocation.inline.hpp" 35 #include "mutex_linux.inline.hpp" 36 #include "nativeInst_sparc.hpp" 37 #include "os_share_linux.hpp" 38 #include "prims/jniFastGetField.hpp" 39 #include "prims/jvm.h" 40 #include "prims/jvm_misc.hpp" 41 #include "runtime/arguments.hpp" 42 #include "runtime/extendedPC.hpp" 43 #include "runtime/frame.inline.hpp" 44 #include "runtime/interfaceSupport.hpp" 45 #include "runtime/java.hpp" 46 #include "runtime/javaCalls.hpp" 47 #include "runtime/mutexLocker.hpp" 48 #include "runtime/osThread.hpp" 49 #include "runtime/sharedRuntime.hpp" 50 #include "runtime/stubRoutines.hpp" 51 #include "runtime/timer.hpp" 52 #include "thread_linux.inline.hpp" 53 #include "utilities/events.hpp" 54 #include "utilities/vmError.hpp" 55 56 // Linux/Sparc has rather obscure naming of registers in sigcontext 57 // different between 32 and 64 bits 58 #ifdef _LP64 59 #define SIG_PC(x) ((x)->sigc_regs.tpc) 60 #define SIG_NPC(x) ((x)->sigc_regs.tnpc) 61 #define SIG_REGS(x) ((x)->sigc_regs) 62 #else 63 #define SIG_PC(x) ((x)->si_regs.pc) 64 #define SIG_NPC(x) ((x)->si_regs.npc) 65 #define SIG_REGS(x) ((x)->si_regs) 66 #endif 67 68 // those are to reference registers in sigcontext 69 enum { 70 CON_G0 = 0, 71 CON_G1, 72 CON_G2, 73 CON_G3, 74 CON_G4, 75 CON_G5, 76 CON_G6, 77 CON_G7, 78 CON_O0, 79 CON_O1, 80 CON_O2, 81 CON_O3, 82 CON_O4, 83 CON_O5, 84 CON_O6, 85 CON_O7, 86 }; 87 88 static inline void set_cont_address(sigcontext* ctx, address addr) { 89 SIG_PC(ctx) = (intptr_t)addr; 90 SIG_NPC(ctx) = (intptr_t)(addr+4); 91 } 92 93 // For Forte Analyzer AsyncGetCallTrace profiling support - thread is 94 // currently interrupted by SIGPROF. 95 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested 96 // signal frames. Currently we don't do that on Linux, so it's the 97 // same as os::fetch_frame_from_context(). 98 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, 99 ucontext_t* uc, 100 intptr_t** ret_sp, 101 intptr_t** ret_fp) { 102 assert(thread != NULL, "just checking"); 103 assert(ret_sp != NULL, "just checking"); 104 assert(ret_fp != NULL, "just checking"); 105 106 return os::fetch_frame_from_context(uc, ret_sp, ret_fp); 107 } 108 109 ExtendedPC os::fetch_frame_from_context(void* ucVoid, 110 intptr_t** ret_sp, 111 intptr_t** ret_fp) { 112 ucontext_t* uc = (ucontext_t*) ucVoid; 113 ExtendedPC epc; 114 115 if (uc != NULL) { 116 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); 117 if (ret_sp) { 118 *ret_sp = os::Linux::ucontext_get_sp(uc); 119 } 120 if (ret_fp) { 121 *ret_fp = os::Linux::ucontext_get_fp(uc); 122 } 123 } else { 124 // construct empty ExtendedPC for return value checking 125 epc = ExtendedPC(NULL); 126 if (ret_sp) { 127 *ret_sp = (intptr_t*) NULL; 128 } 129 if (ret_fp) { 130 *ret_fp = (intptr_t*) NULL; 131 } 132 } 133 134 return epc; 135 } 136 137 frame os::fetch_frame_from_context(void* ucVoid) { 138 intptr_t* sp; 139 intptr_t* fp; 140 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); 141 return frame(sp, fp, epc.pc()); 142 } 143 144 frame os::get_sender_for_C_frame(frame* fr) { 145 return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); 146 } 147 148 frame os::current_frame() { 149 intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); 150 frame myframe(sp, frame::unpatchable, 151 CAST_FROM_FN_PTR(address, os::current_frame)); 152 if (os::is_first_C_frame(&myframe)) { 153 // stack is not walkable 154 return frame(NULL, frame::unpatchable, NULL); 155 } else { 156 return os::get_sender_for_C_frame(&myframe); 157 } 158 } 159 160 address os::current_stack_pointer() { 161 register void *sp __asm__ ("sp"); 162 return (address)sp; 163 } 164 165 static void current_stack_region(address* bottom, size_t* size) { 166 if (os::Linux::is_initial_thread()) { 167 // initial thread needs special handling because pthread_getattr_np() 168 // may return bogus value. 169 *bottom = os::Linux::initial_thread_stack_bottom(); 170 *size = os::Linux::initial_thread_stack_size(); 171 } else { 172 pthread_attr_t attr; 173 174 int rslt = pthread_getattr_np(pthread_self(), &attr); 175 176 // JVM needs to know exact stack location, abort if it fails 177 if (rslt != 0) { 178 if (rslt == ENOMEM) { 179 vm_exit_out_of_memory(0, "pthread_getattr_np"); 180 } else { 181 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); 182 } 183 } 184 185 if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) { 186 fatal("Can not locate current stack attributes!"); 187 } 188 189 pthread_attr_destroy(&attr); 190 } 191 assert(os::current_stack_pointer() >= *bottom && 192 os::current_stack_pointer() < *bottom + *size, "just checking"); 193 } 194 195 address os::current_stack_base() { 196 address bottom; 197 size_t size; 198 current_stack_region(&bottom, &size); 199 return bottom + size; 200 } 201 202 size_t os::current_stack_size() { 203 // stack size includes normal stack and HotSpot guard pages 204 address bottom; 205 size_t size; 206 current_stack_region(&bottom, &size); 207 return size; 208 } 209 210 char* os::non_memory_address_word() { 211 // Must never look like an address returned by reserve_memory, 212 // even in its subfields (as defined by the CPU immediate fields, 213 // if the CPU splits constants across multiple instructions). 214 // On SPARC, 0 != %hi(any real address), because there is no 215 // allocation in the first 1Kb of the virtual address space. 216 return (char*) 0; 217 } 218 219 void os::initialize_thread(Thread* thr) {} 220 221 void os::print_context(outputStream *st, void *context) { 222 if (context == NULL) return; 223 224 ucontext_t* uc = (ucontext_t*)context; 225 sigcontext* sc = (sigcontext*)context; 226 st->print_cr("Registers:"); 227 228 st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT 229 " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, 230 SIG_REGS(sc).u_regs[CON_G1], 231 SIG_REGS(sc).u_regs[CON_G2], 232 SIG_REGS(sc).u_regs[CON_G3], 233 SIG_REGS(sc).u_regs[CON_G4]); 234 st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT 235 " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, 236 SIG_REGS(sc).u_regs[CON_G5], 237 SIG_REGS(sc).u_regs[CON_G6], 238 SIG_REGS(sc).u_regs[CON_G7], 239 SIG_REGS(sc).y); 240 st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT 241 " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, 242 SIG_REGS(sc).u_regs[CON_O0], 243 SIG_REGS(sc).u_regs[CON_O1], 244 SIG_REGS(sc).u_regs[CON_O2], 245 SIG_REGS(sc).u_regs[CON_O3]); 246 st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT 247 " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, 248 SIG_REGS(sc).u_regs[CON_O4], 249 SIG_REGS(sc).u_regs[CON_O5], 250 SIG_REGS(sc).u_regs[CON_O6], 251 SIG_REGS(sc).u_regs[CON_O7]); 252 253 254 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 255 st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT 256 " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, 257 sp[L0->sp_offset_in_saved_window()], 258 sp[L1->sp_offset_in_saved_window()], 259 sp[L2->sp_offset_in_saved_window()], 260 sp[L3->sp_offset_in_saved_window()]); 261 st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT 262 " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, 263 sp[L4->sp_offset_in_saved_window()], 264 sp[L5->sp_offset_in_saved_window()], 265 sp[L6->sp_offset_in_saved_window()], 266 sp[L7->sp_offset_in_saved_window()]); 267 st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT 268 " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, 269 sp[I0->sp_offset_in_saved_window()], 270 sp[I1->sp_offset_in_saved_window()], 271 sp[I2->sp_offset_in_saved_window()], 272 sp[I3->sp_offset_in_saved_window()]); 273 st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT 274 " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, 275 sp[I4->sp_offset_in_saved_window()], 276 sp[I5->sp_offset_in_saved_window()], 277 sp[I6->sp_offset_in_saved_window()], 278 sp[I7->sp_offset_in_saved_window()]); 279 280 st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, 281 SIG_PC(sc), 282 SIG_NPC(sc)); 283 st->cr(); 284 st->cr(); 285 286 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); 287 print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); 288 st->cr(); 289 290 // Note: it may be unsafe to inspect memory near pc. For example, pc may 291 // point to garbage if entry point in an nmethod is corrupted. Leave 292 // this at the end, and hope for the best. 293 address pc = os::Linux::ucontext_get_pc(uc); 294 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); 295 print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); 296 } 297 298 299 void os::print_register_info(outputStream *st, void *context) { 300 if (context == NULL) return; 301 302 ucontext_t *uc = (ucontext_t*)context; 303 sigcontext* sc = (sigcontext*)context; 304 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 305 306 st->print_cr("Register to memory mapping:"); 307 st->cr(); 308 309 // this is only for the "general purpose" registers 310 st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]); 311 st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]); 312 st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]); 313 st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]); 314 st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]); 315 st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]); 316 st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]); 317 st->cr(); 318 319 st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]); 320 st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]); 321 st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]); 322 st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]); 323 st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]); 324 st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]); 325 st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]); 326 st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]); 327 st->cr(); 328 329 st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); 330 st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); 331 st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); 332 st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); 333 st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); 334 st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); 335 st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); 336 st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); 337 st->cr(); 338 339 st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); 340 st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); 341 st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); 342 st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); 343 st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); 344 st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); 345 st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); 346 st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); 347 st->cr(); 348 } 349 350 351 address os::Linux::ucontext_get_pc(ucontext_t* uc) { 352 return (address) SIG_PC((sigcontext*)uc); 353 } 354 355 intptr_t* os::Linux::ucontext_get_sp(ucontext_t *uc) { 356 return (intptr_t*) 357 ((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); 358 } 359 360 // not used on Sparc 361 intptr_t* os::Linux::ucontext_get_fp(ucontext_t *uc) { 362 ShouldNotReachHere(); 363 return NULL; 364 } 365 366 // Utility functions 367 368 extern "C" void Fetch32PFI(); 369 extern "C" void Fetch32Resume(); 370 extern "C" void FetchNPFI(); 371 extern "C" void FetchNResume(); 372 373 inline static bool checkPrefetch(sigcontext* uc, address pc) { 374 if (pc == (address) Fetch32PFI) { 375 set_cont_address(uc, address(Fetch32Resume)); 376 return true; 377 } 378 if (pc == (address) FetchNPFI) { 379 set_cont_address(uc, address(FetchNResume)); 380 return true; 381 } 382 return false; 383 } 384 385 inline static bool checkOverflow(sigcontext* uc, 386 address pc, 387 address addr, 388 JavaThread* thread, 389 address* stub) { 390 // check if fault address is within thread stack 391 if (addr < thread->stack_base() && 392 addr >= thread->stack_base() - thread->stack_size()) { 393 // stack overflow 394 if (thread->in_stack_yellow_zone(addr)) { 395 thread->disable_stack_yellow_zone(); 396 if (thread->thread_state() == _thread_in_Java) { 397 // Throw a stack overflow exception. Guard pages will be reenabled 398 // while unwinding the stack. 399 *stub = 400 SharedRuntime::continuation_for_implicit_exception(thread, 401 pc, 402 SharedRuntime::STACK_OVERFLOW); 403 } else { 404 // Thread was in the vm or native code. Return and try to finish. 405 return true; 406 } 407 } else if (thread->in_stack_red_zone(addr)) { 408 // Fatal red zone violation. Disable the guard pages and fall through 409 // to handle_unexpected_exception way down below. 410 thread->disable_stack_red_zone(); 411 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 412 413 // This is a likely cause, but hard to verify. Let's just print 414 // it as a hint. 415 tty->print_raw_cr("Please check if any of your loaded .so files has " 416 "enabled executable stack (see man page execstack(8))"); 417 } else { 418 // Accessing stack address below sp may cause SEGV if current 419 // thread has MAP_GROWSDOWN stack. This should only happen when 420 // current thread was created by user code with MAP_GROWSDOWN flag 421 // and then attached to VM. See notes in os_linux.cpp. 422 if (thread->osthread()->expanding_stack() == 0) { 423 thread->osthread()->set_expanding_stack(); 424 if (os::Linux::manually_expand_stack(thread, addr)) { 425 thread->osthread()->clear_expanding_stack(); 426 return true; 427 } 428 thread->osthread()->clear_expanding_stack(); 429 } else { 430 fatal("recursive segv. expanding stack."); 431 } 432 } 433 } 434 return false; 435 } 436 437 inline static bool checkPollingPage(address pc, address fault, address* stub) { 438 if (fault == os::get_polling_page()) { 439 *stub = SharedRuntime::get_poll_stub(pc); 440 return true; 441 } 442 return false; 443 } 444 445 inline static bool checkByteBuffer(address pc, address* stub) { 446 // BugId 4454115: A read from a MappedByteBuffer can fault 447 // here if the underlying file has been truncated. 448 // Do not crash the VM in such a case. 449 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 450 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; 451 if (nm != NULL && nm->has_unsafe_access()) { 452 *stub = StubRoutines::handler_for_unsafe_access(); 453 return true; 454 } 455 return false; 456 } 457 458 inline static bool checkVerifyOops(address pc, address fault, address* stub) { 459 if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] 460 && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { 461 *stub = MacroAssembler::_verify_oop_implicit_branch[2]; 462 warning("fixed up memory fault in +VerifyOops at address " 463 INTPTR_FORMAT, fault); 464 return true; 465 } 466 return false; 467 } 468 469 inline static bool checkFPFault(address pc, int code, 470 JavaThread* thread, address* stub) { 471 if (code == FPE_INTDIV || code == FPE_FLTDIV) { 472 *stub = 473 SharedRuntime:: 474 continuation_for_implicit_exception(thread, 475 pc, 476 SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); 477 return true; 478 } 479 return false; 480 } 481 482 inline static bool checkNullPointer(address pc, intptr_t fault, 483 JavaThread* thread, address* stub) { 484 if (!MacroAssembler::needs_explicit_null_check(fault)) { 485 // Determination of interpreter/vtable stub/compiled code null 486 // exception 487 *stub = 488 SharedRuntime:: 489 continuation_for_implicit_exception(thread, pc, 490 SharedRuntime::IMPLICIT_NULL); 491 return true; 492 } 493 return false; 494 } 495 496 inline static bool checkFastJNIAccess(address pc, address* stub) { 497 address addr = JNI_FastGetField::find_slowcase_pc(pc); 498 if (addr != (address)-1) { 499 *stub = addr; 500 return true; 501 } 502 return false; 503 } 504 505 inline static bool checkSerializePage(JavaThread* thread, address addr) { 506 return os::is_memory_serialize_page(thread, addr); 507 } 508 509 inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { 510 if (nativeInstruction_at(*pc)->is_zombie()) { 511 // zombie method (ld [%g0],%o7 instruction) 512 *stub = SharedRuntime::get_handle_wrong_method_stub(); 513 514 // At the stub it needs to look like a call from the caller of this 515 // method (not a call from the segv site). 516 *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; 517 return true; 518 } 519 return false; 520 } 521 522 inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { 523 #ifdef COMPILER2 524 if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { 525 #ifdef ASSERT 526 #ifdef TIERED 527 CodeBlob* cb = CodeCache::find_blob_unsafe(*pc); 528 assert(cb->is_compiled_by_c2(), "Wrong compiler"); 529 #endif // TIERED 530 #endif // ASSERT 531 // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. 532 *stub = SharedRuntime::get_ic_miss_stub(); 533 // At the stub it needs to look like a call from the caller of this 534 // method (not a call from the segv site). 535 *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; 536 return true; 537 } 538 #endif // COMPILER2 539 return false; 540 } 541 542 extern "C" JNIEXPORT int 543 JVM_handle_linux_signal(int sig, 544 siginfo_t* info, 545 void* ucVoid, 546 int abort_if_unrecognized) { 547 // in fact this isn't ucontext_t* at all, but struct sigcontext* 548 // but Linux porting layer uses ucontext_t, so to minimize code change 549 // we cast as needed 550 ucontext_t* ucFake = (ucontext_t*) ucVoid; 551 sigcontext* uc = (sigcontext*)ucVoid; 552 553 Thread* t = ThreadLocalStorage::get_thread_slow(); 554 555 // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away 556 // (no destructors can be run) 557 os::WatcherThreadCrashProtection::check_crash_protection(sig, t); 558 559 SignalHandlerMark shm(t); 560 561 // Note: it's not uncommon that JNI code uses signal/sigset to install 562 // then restore certain signal handler (e.g. to temporarily block SIGPIPE, 563 // or have a SIGILL handler when detecting CPU type). When that happens, 564 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To 565 // avoid unnecessary crash when libjsig is not preloaded, try handle signals 566 // that do not require siginfo/ucontext first. 567 568 if (sig == SIGPIPE || sig == SIGXFSZ) { 569 // allow chained handler to go first 570 if (os::Linux::chained_handler(sig, info, ucVoid)) { 571 return true; 572 } else { 573 if (PrintMiscellaneous && (WizardMode || Verbose)) { 574 char buf[64]; 575 warning("Ignoring %s - see bugs 4229104 or 646499219", 576 os::exception_name(sig, buf, sizeof(buf))); 577 } 578 return true; 579 } 580 } 581 582 JavaThread* thread = NULL; 583 VMThread* vmthread = NULL; 584 if (os::Linux::signal_handlers_are_installed) { 585 if (t != NULL ){ 586 if(t->is_Java_thread()) { 587 thread = (JavaThread*)t; 588 } 589 else if(t->is_VM_thread()){ 590 vmthread = (VMThread *)t; 591 } 592 } 593 } 594 595 // decide if this trap can be handled by a stub 596 address stub = NULL; 597 address pc = NULL; 598 address npc = NULL; 599 600 //%note os_trap_1 601 if (info != NULL && uc != NULL && thread != NULL) { 602 pc = address(SIG_PC(uc)); 603 npc = address(SIG_NPC(uc)); 604 605 // Check to see if we caught the safepoint code in the 606 // process of write protecting the memory serialization page. 607 // It write enables the page immediately after protecting it 608 // so we can just return to retry the write. 609 if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { 610 // Block current thread until the memory serialize page permission restored. 611 os::block_on_serialize_page_trap(); 612 return 1; 613 } 614 615 if (checkPrefetch(uc, pc)) { 616 return 1; 617 } 618 619 // Handle ALL stack overflow variations here 620 if (sig == SIGSEGV) { 621 if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { 622 return 1; 623 } 624 } 625 626 if (sig == SIGBUS && 627 thread->thread_state() == _thread_in_vm && 628 thread->doing_unsafe_access()) { 629 stub = StubRoutines::handler_for_unsafe_access(); 630 } 631 632 if (thread->thread_state() == _thread_in_Java) { 633 do { 634 // Java thread running in Java code => find exception handler if any 635 // a fault inside compiled code, the interpreter, or a stub 636 637 if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { 638 break; 639 } 640 641 if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { 642 break; 643 } 644 645 if ((sig == SIGSEGV || sig == SIGBUS) && 646 checkVerifyOops(pc, (address)info->si_addr, &stub)) { 647 break; 648 } 649 650 if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { 651 break; 652 } 653 654 if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { 655 break; 656 } 657 658 if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { 659 break; 660 } 661 662 if ((sig == SIGSEGV) && 663 checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { 664 break; 665 } 666 } while (0); 667 668 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 669 // and the heap gets shrunk before the field access. 670 if ((sig == SIGSEGV) || (sig == SIGBUS)) { 671 checkFastJNIAccess(pc, &stub); 672 } 673 } 674 675 if (stub != NULL) { 676 // save all thread context in case we need to restore it 677 thread->set_saved_exception_pc(pc); 678 thread->set_saved_exception_npc(npc); 679 set_cont_address(uc, stub); 680 return true; 681 } 682 } 683 684 // signal-chaining 685 if (os::Linux::chained_handler(sig, info, ucVoid)) { 686 return true; 687 } 688 689 if (!abort_if_unrecognized) { 690 // caller wants another chance, so give it to him 691 return false; 692 } 693 694 if (pc == NULL && uc != NULL) { 695 pc = os::Linux::ucontext_get_pc((ucontext_t*)uc); 696 } 697 698 // unmask current signal 699 sigset_t newset; 700 sigemptyset(&newset); 701 sigaddset(&newset, sig); 702 sigprocmask(SIG_UNBLOCK, &newset, NULL); 703 704 VMError err(t, sig, pc, info, ucVoid); 705 err.report_and_die(); 706 707 ShouldNotReachHere(); 708 } 709 710 void os::Linux::init_thread_fpu_state(void) { 711 // Nothing to do 712 } 713 714 int os::Linux::get_fpu_control_word() { 715 return 0; 716 } 717 718 void os::Linux::set_fpu_control_word(int fpu) { 719 // nothing 720 } 721 722 bool os::is_allocatable(size_t bytes) { 723 #ifdef _LP64 724 return true; 725 #else 726 if (bytes < 2 * G) { 727 return true; 728 } 729 730 char* addr = reserve_memory(bytes, NULL); 731 732 if (addr != NULL) { 733 release_memory(addr, bytes); 734 } 735 736 return addr != NULL; 737 #endif // _LP64 738 } 739 740 /////////////////////////////////////////////////////////////////////////////// 741 // thread stack 742 743 size_t os::Linux::min_stack_allowed = 128 * K; 744 745 // pthread on Ubuntu is always in floating stack mode 746 bool os::Linux::supports_variable_stack_size() { return true; } 747 748 // return default stack size for thr_type 749 size_t os::Linux::default_stack_size(os::ThreadType thr_type) { 750 // default stack size (compiler thread needs larger stack) 751 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); 752 return s; 753 } 754 755 size_t os::Linux::default_guard_size(os::ThreadType thr_type) { 756 // Creating guard page is very expensive. Java thread has HotSpot 757 // guard page, only enable glibc guard page for non-Java threads. 758 return (thr_type == java_thread ? 0 : page_size()); 759 } 760 761 #ifndef PRODUCT 762 void os::verify_stack_alignment() { 763 } 764 #endif