1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,757 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// no precompiled headers 1.29 +#include "asm/macroAssembler.hpp" 1.30 +#include "classfile/classLoader.hpp" 1.31 +#include "classfile/systemDictionary.hpp" 1.32 +#include "classfile/vmSymbols.hpp" 1.33 +#include "code/icBuffer.hpp" 1.34 +#include "code/vtableStubs.hpp" 1.35 +#include "interpreter/interpreter.hpp" 1.36 +#include "jvm_linux.h" 1.37 +#include "memory/allocation.inline.hpp" 1.38 +#include "mutex_linux.inline.hpp" 1.39 +#include "nativeInst_sparc.hpp" 1.40 +#include "os_share_linux.hpp" 1.41 +#include "prims/jniFastGetField.hpp" 1.42 +#include "prims/jvm.h" 1.43 +#include "prims/jvm_misc.hpp" 1.44 +#include "runtime/arguments.hpp" 1.45 +#include "runtime/extendedPC.hpp" 1.46 +#include "runtime/frame.inline.hpp" 1.47 +#include "runtime/interfaceSupport.hpp" 1.48 +#include "runtime/java.hpp" 1.49 +#include "runtime/javaCalls.hpp" 1.50 +#include "runtime/mutexLocker.hpp" 1.51 +#include "runtime/osThread.hpp" 1.52 +#include "runtime/sharedRuntime.hpp" 1.53 +#include "runtime/stubRoutines.hpp" 1.54 +#include "runtime/thread.inline.hpp" 1.55 +#include "runtime/timer.hpp" 1.56 +#include "utilities/events.hpp" 1.57 +#include "utilities/vmError.hpp" 1.58 + 1.59 +// Linux/Sparc has rather obscure naming of registers in sigcontext 1.60 +// different between 32 and 64 bits 1.61 +#ifdef _LP64 1.62 +#define SIG_PC(x) ((x)->sigc_regs.tpc) 1.63 +#define SIG_NPC(x) ((x)->sigc_regs.tnpc) 1.64 +#define SIG_REGS(x) ((x)->sigc_regs) 1.65 +#else 1.66 +#define SIG_PC(x) ((x)->si_regs.pc) 1.67 +#define SIG_NPC(x) ((x)->si_regs.npc) 1.68 +#define SIG_REGS(x) ((x)->si_regs) 1.69 +#endif 1.70 + 1.71 +// those are to reference registers in sigcontext 1.72 +enum { 1.73 + CON_G0 = 0, 1.74 + CON_G1, 1.75 + CON_G2, 1.76 + CON_G3, 1.77 + CON_G4, 1.78 + CON_G5, 1.79 + CON_G6, 1.80 + CON_G7, 1.81 + CON_O0, 1.82 + CON_O1, 1.83 + CON_O2, 1.84 + CON_O3, 1.85 + CON_O4, 1.86 + CON_O5, 1.87 + CON_O6, 1.88 + CON_O7, 1.89 +}; 1.90 + 1.91 +static inline void set_cont_address(sigcontext* ctx, address addr) { 1.92 + SIG_PC(ctx) = (intptr_t)addr; 1.93 + SIG_NPC(ctx) = (intptr_t)(addr+4); 1.94 +} 1.95 + 1.96 +// For Forte Analyzer AsyncGetCallTrace profiling support - thread is 1.97 +// currently interrupted by SIGPROF. 1.98 +// os::Solaris::fetch_frame_from_ucontext() tries to skip nested 1.99 +// signal frames. Currently we don't do that on Linux, so it's the 1.100 +// same as os::fetch_frame_from_context(). 1.101 +ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, 1.102 + ucontext_t* uc, 1.103 + intptr_t** ret_sp, 1.104 + intptr_t** ret_fp) { 1.105 + assert(thread != NULL, "just checking"); 1.106 + assert(ret_sp != NULL, "just checking"); 1.107 + assert(ret_fp != NULL, "just checking"); 1.108 + 1.109 + return os::fetch_frame_from_context(uc, ret_sp, ret_fp); 1.110 +} 1.111 + 1.112 +ExtendedPC os::fetch_frame_from_context(void* ucVoid, 1.113 + intptr_t** ret_sp, 1.114 + intptr_t** ret_fp) { 1.115 + ucontext_t* uc = (ucontext_t*) ucVoid; 1.116 + ExtendedPC epc; 1.117 + 1.118 + if (uc != NULL) { 1.119 + epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); 1.120 + if (ret_sp) { 1.121 + *ret_sp = os::Linux::ucontext_get_sp(uc); 1.122 + } 1.123 + if (ret_fp) { 1.124 + *ret_fp = os::Linux::ucontext_get_fp(uc); 1.125 + } 1.126 + } else { 1.127 + // construct empty ExtendedPC for return value checking 1.128 + epc = ExtendedPC(NULL); 1.129 + if (ret_sp) { 1.130 + *ret_sp = (intptr_t*) NULL; 1.131 + } 1.132 + if (ret_fp) { 1.133 + *ret_fp = (intptr_t*) NULL; 1.134 + } 1.135 + } 1.136 + 1.137 + return epc; 1.138 +} 1.139 + 1.140 +frame os::fetch_frame_from_context(void* ucVoid) { 1.141 + intptr_t* sp; 1.142 + intptr_t* fp; 1.143 + ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); 1.144 + return frame(sp, fp, epc.pc()); 1.145 +} 1.146 + 1.147 +frame os::get_sender_for_C_frame(frame* fr) { 1.148 + return frame(fr->sender_sp(), fr->link(), fr->sender_pc()); 1.149 +} 1.150 + 1.151 +frame os::current_frame() { 1.152 + fprintf(stderr, "current_frame()"); 1.153 + 1.154 + intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); 1.155 + frame myframe(sp, frame::unpatchable, 1.156 + CAST_FROM_FN_PTR(address, os::current_frame)); 1.157 + if (os::is_first_C_frame(&myframe)) { 1.158 + // stack is not walkable 1.159 + return frame(NULL, frame::unpatchable, NULL); 1.160 + } else { 1.161 + return os::get_sender_for_C_frame(&myframe); 1.162 + } 1.163 +} 1.164 + 1.165 +address os::current_stack_pointer() { 1.166 + register void *sp __asm__ ("sp"); 1.167 + return (address)sp; 1.168 +} 1.169 + 1.170 +static void current_stack_region(address* bottom, size_t* size) { 1.171 + if (os::Linux::is_initial_thread()) { 1.172 + // initial thread needs special handling because pthread_getattr_np() 1.173 + // may return bogus value. 1.174 + *bottom = os::Linux::initial_thread_stack_bottom(); 1.175 + *size = os::Linux::initial_thread_stack_size(); 1.176 + } else { 1.177 + pthread_attr_t attr; 1.178 + 1.179 + int rslt = pthread_getattr_np(pthread_self(), &attr); 1.180 + 1.181 + // JVM needs to know exact stack location, abort if it fails 1.182 + if (rslt != 0) { 1.183 + if (rslt == ENOMEM) { 1.184 + vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); 1.185 + } else { 1.186 + fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); 1.187 + } 1.188 + } 1.189 + 1.190 + if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) { 1.191 + fatal("Can not locate current stack attributes!"); 1.192 + } 1.193 + 1.194 + pthread_attr_destroy(&attr); 1.195 + } 1.196 + assert(os::current_stack_pointer() >= *bottom && 1.197 + os::current_stack_pointer() < *bottom + *size, "just checking"); 1.198 +} 1.199 + 1.200 +address os::current_stack_base() { 1.201 + address bottom; 1.202 + size_t size; 1.203 + current_stack_region(&bottom, &size); 1.204 + return bottom + size; 1.205 +} 1.206 + 1.207 +size_t os::current_stack_size() { 1.208 + // stack size includes normal stack and HotSpot guard pages 1.209 + address bottom; 1.210 + size_t size; 1.211 + current_stack_region(&bottom, &size); 1.212 + return size; 1.213 +} 1.214 + 1.215 +char* os::non_memory_address_word() { 1.216 + // Must never look like an address returned by reserve_memory, 1.217 + // even in its subfields (as defined by the CPU immediate fields, 1.218 + // if the CPU splits constants across multiple instructions). 1.219 + // On SPARC, 0 != %hi(any real address), because there is no 1.220 + // allocation in the first 1Kb of the virtual address space. 1.221 + return (char*) 0; 1.222 +} 1.223 + 1.224 +void os::initialize_thread(Thread* thr) {} 1.225 + 1.226 +void os::print_context(outputStream *st, void *context) { 1.227 + if (context == NULL) return; 1.228 + 1.229 + ucontext_t* uc = (ucontext_t*)context; 1.230 + sigcontext* sc = (sigcontext*)context; 1.231 + st->print_cr("Registers:"); 1.232 + 1.233 + st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT 1.234 + " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, 1.235 + SIG_REGS(sc).u_regs[CON_G1], 1.236 + SIG_REGS(sc).u_regs[CON_G2], 1.237 + SIG_REGS(sc).u_regs[CON_G3], 1.238 + SIG_REGS(sc).u_regs[CON_G4]); 1.239 + st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT 1.240 + " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, 1.241 + SIG_REGS(sc).u_regs[CON_G5], 1.242 + SIG_REGS(sc).u_regs[CON_G6], 1.243 + SIG_REGS(sc).u_regs[CON_G7], 1.244 + SIG_REGS(sc).y); 1.245 + st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT 1.246 + " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, 1.247 + SIG_REGS(sc).u_regs[CON_O0], 1.248 + SIG_REGS(sc).u_regs[CON_O1], 1.249 + SIG_REGS(sc).u_regs[CON_O2], 1.250 + SIG_REGS(sc).u_regs[CON_O3]); 1.251 + st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT 1.252 + " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, 1.253 + SIG_REGS(sc).u_regs[CON_O4], 1.254 + SIG_REGS(sc).u_regs[CON_O5], 1.255 + SIG_REGS(sc).u_regs[CON_O6], 1.256 + SIG_REGS(sc).u_regs[CON_O7]); 1.257 + 1.258 + 1.259 + intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 1.260 + st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT 1.261 + " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, 1.262 + sp[L0->sp_offset_in_saved_window()], 1.263 + sp[L1->sp_offset_in_saved_window()], 1.264 + sp[L2->sp_offset_in_saved_window()], 1.265 + sp[L3->sp_offset_in_saved_window()]); 1.266 + st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT 1.267 + " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, 1.268 + sp[L4->sp_offset_in_saved_window()], 1.269 + sp[L5->sp_offset_in_saved_window()], 1.270 + sp[L6->sp_offset_in_saved_window()], 1.271 + sp[L7->sp_offset_in_saved_window()]); 1.272 + st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT 1.273 + " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, 1.274 + sp[I0->sp_offset_in_saved_window()], 1.275 + sp[I1->sp_offset_in_saved_window()], 1.276 + sp[I2->sp_offset_in_saved_window()], 1.277 + sp[I3->sp_offset_in_saved_window()]); 1.278 + st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT 1.279 + " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, 1.280 + sp[I4->sp_offset_in_saved_window()], 1.281 + sp[I5->sp_offset_in_saved_window()], 1.282 + sp[I6->sp_offset_in_saved_window()], 1.283 + sp[I7->sp_offset_in_saved_window()]); 1.284 + 1.285 + st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, 1.286 + SIG_PC(sc), 1.287 + SIG_NPC(sc)); 1.288 + st->cr(); 1.289 + st->cr(); 1.290 + 1.291 + st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); 1.292 + print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); 1.293 + st->cr(); 1.294 + 1.295 + // Note: it may be unsafe to inspect memory near pc. For example, pc may 1.296 + // point to garbage if entry point in an nmethod is corrupted. Leave 1.297 + // this at the end, and hope for the best. 1.298 + address pc = os::Linux::ucontext_get_pc(uc); 1.299 + st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); 1.300 + print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); 1.301 +} 1.302 + 1.303 + 1.304 +void os::print_register_info(outputStream *st, void *context) { 1.305 + if (context == NULL) return; 1.306 + 1.307 + ucontext_t *uc = (ucontext_t*)context; 1.308 + sigcontext* sc = (sigcontext*)context; 1.309 + intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 1.310 + 1.311 + st->print_cr("Register to memory mapping:"); 1.312 + st->cr(); 1.313 + 1.314 + // this is only for the "general purpose" registers 1.315 + st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]); 1.316 + st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]); 1.317 + st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]); 1.318 + st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]); 1.319 + st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]); 1.320 + st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]); 1.321 + st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]); 1.322 + st->cr(); 1.323 + 1.324 + st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]); 1.325 + st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]); 1.326 + st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]); 1.327 + st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]); 1.328 + st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]); 1.329 + st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]); 1.330 + st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]); 1.331 + st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]); 1.332 + st->cr(); 1.333 + 1.334 + st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); 1.335 + st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); 1.336 + st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); 1.337 + st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); 1.338 + st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); 1.339 + st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); 1.340 + st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); 1.341 + st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); 1.342 + st->cr(); 1.343 + 1.344 + st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); 1.345 + st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); 1.346 + st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); 1.347 + st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); 1.348 + st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); 1.349 + st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); 1.350 + st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); 1.351 + st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); 1.352 + st->cr(); 1.353 +} 1.354 + 1.355 + 1.356 +address os::Linux::ucontext_get_pc(ucontext_t* uc) { 1.357 + return (address) SIG_PC((sigcontext*)uc); 1.358 +} 1.359 + 1.360 +intptr_t* os::Linux::ucontext_get_sp(ucontext_t *uc) { 1.361 + return (intptr_t*) 1.362 + ((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); 1.363 +} 1.364 + 1.365 +// not used on Sparc 1.366 +intptr_t* os::Linux::ucontext_get_fp(ucontext_t *uc) { 1.367 + ShouldNotReachHere(); 1.368 + return NULL; 1.369 +} 1.370 + 1.371 +// Utility functions 1.372 + 1.373 +inline static bool checkPrefetch(sigcontext* uc, address pc) { 1.374 + if (StubRoutines::is_safefetch_fault(pc)) { 1.375 + set_cont_address(uc, address(StubRoutines::continuation_for_safefetch_fault(pc))); 1.376 + return true; 1.377 + } 1.378 + return false; 1.379 +} 1.380 + 1.381 +inline static bool checkOverflow(sigcontext* uc, 1.382 + address pc, 1.383 + address addr, 1.384 + JavaThread* thread, 1.385 + address* stub) { 1.386 + // check if fault address is within thread stack 1.387 + if (addr < thread->stack_base() && 1.388 + addr >= thread->stack_base() - thread->stack_size()) { 1.389 + // stack overflow 1.390 + if (thread->in_stack_yellow_zone(addr)) { 1.391 + thread->disable_stack_yellow_zone(); 1.392 + if (thread->thread_state() == _thread_in_Java) { 1.393 + // Throw a stack overflow exception. Guard pages will be reenabled 1.394 + // while unwinding the stack. 1.395 + *stub = 1.396 + SharedRuntime::continuation_for_implicit_exception(thread, 1.397 + pc, 1.398 + SharedRuntime::STACK_OVERFLOW); 1.399 + } else { 1.400 + // Thread was in the vm or native code. Return and try to finish. 1.401 + return true; 1.402 + } 1.403 + } else if (thread->in_stack_red_zone(addr)) { 1.404 + // Fatal red zone violation. Disable the guard pages and fall through 1.405 + // to handle_unexpected_exception way down below. 1.406 + thread->disable_stack_red_zone(); 1.407 + tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 1.408 + 1.409 + // This is a likely cause, but hard to verify. Let's just print 1.410 + // it as a hint. 1.411 + tty->print_raw_cr("Please check if any of your loaded .so files has " 1.412 + "enabled executable stack (see man page execstack(8))"); 1.413 + } else { 1.414 + // Accessing stack address below sp may cause SEGV if current 1.415 + // thread has MAP_GROWSDOWN stack. This should only happen when 1.416 + // current thread was created by user code with MAP_GROWSDOWN flag 1.417 + // and then attached to VM. See notes in os_linux.cpp. 1.418 + if (thread->osthread()->expanding_stack() == 0) { 1.419 + thread->osthread()->set_expanding_stack(); 1.420 + if (os::Linux::manually_expand_stack(thread, addr)) { 1.421 + thread->osthread()->clear_expanding_stack(); 1.422 + return true; 1.423 + } 1.424 + thread->osthread()->clear_expanding_stack(); 1.425 + } else { 1.426 + fatal("recursive segv. expanding stack."); 1.427 + } 1.428 + } 1.429 + } 1.430 + return false; 1.431 +} 1.432 + 1.433 +inline static bool checkPollingPage(address pc, address fault, address* stub) { 1.434 + if (fault == os::get_polling_page()) { 1.435 + *stub = SharedRuntime::get_poll_stub(pc); 1.436 + return true; 1.437 + } 1.438 + return false; 1.439 +} 1.440 + 1.441 +inline static bool checkByteBuffer(address pc, address* stub) { 1.442 + // BugId 4454115: A read from a MappedByteBuffer can fault 1.443 + // here if the underlying file has been truncated. 1.444 + // Do not crash the VM in such a case. 1.445 + CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 1.446 + nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; 1.447 + if (nm != NULL && nm->has_unsafe_access()) { 1.448 + *stub = StubRoutines::handler_for_unsafe_access(); 1.449 + return true; 1.450 + } 1.451 + return false; 1.452 +} 1.453 + 1.454 +inline static bool checkVerifyOops(address pc, address fault, address* stub) { 1.455 + if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] 1.456 + && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { 1.457 + *stub = MacroAssembler::_verify_oop_implicit_branch[2]; 1.458 + warning("fixed up memory fault in +VerifyOops at address " 1.459 + INTPTR_FORMAT, fault); 1.460 + return true; 1.461 + } 1.462 + return false; 1.463 +} 1.464 + 1.465 +inline static bool checkFPFault(address pc, int code, 1.466 + JavaThread* thread, address* stub) { 1.467 + if (code == FPE_INTDIV || code == FPE_FLTDIV) { 1.468 + *stub = 1.469 + SharedRuntime:: 1.470 + continuation_for_implicit_exception(thread, 1.471 + pc, 1.472 + SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); 1.473 + return true; 1.474 + } 1.475 + return false; 1.476 +} 1.477 + 1.478 +inline static bool checkNullPointer(address pc, intptr_t fault, 1.479 + JavaThread* thread, address* stub) { 1.480 + if (!MacroAssembler::needs_explicit_null_check(fault)) { 1.481 + // Determination of interpreter/vtable stub/compiled code null 1.482 + // exception 1.483 + *stub = 1.484 + SharedRuntime:: 1.485 + continuation_for_implicit_exception(thread, pc, 1.486 + SharedRuntime::IMPLICIT_NULL); 1.487 + return true; 1.488 + } 1.489 + return false; 1.490 +} 1.491 + 1.492 +inline static bool checkFastJNIAccess(address pc, address* stub) { 1.493 + address addr = JNI_FastGetField::find_slowcase_pc(pc); 1.494 + if (addr != (address)-1) { 1.495 + *stub = addr; 1.496 + return true; 1.497 + } 1.498 + return false; 1.499 +} 1.500 + 1.501 +inline static bool checkSerializePage(JavaThread* thread, address addr) { 1.502 + return os::is_memory_serialize_page(thread, addr); 1.503 +} 1.504 + 1.505 +inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { 1.506 + if (nativeInstruction_at(*pc)->is_zombie()) { 1.507 + // zombie method (ld [%g0],%o7 instruction) 1.508 + *stub = SharedRuntime::get_handle_wrong_method_stub(); 1.509 + 1.510 + // At the stub it needs to look like a call from the caller of this 1.511 + // method (not a call from the segv site). 1.512 + *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; 1.513 + return true; 1.514 + } 1.515 + return false; 1.516 +} 1.517 + 1.518 +inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { 1.519 +#ifdef COMPILER2 1.520 + if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { 1.521 +#ifdef ASSERT 1.522 +#ifdef TIERED 1.523 + CodeBlob* cb = CodeCache::find_blob_unsafe(*pc); 1.524 + assert(cb->is_compiled_by_c2(), "Wrong compiler"); 1.525 +#endif // TIERED 1.526 +#endif // ASSERT 1.527 + // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. 1.528 + *stub = SharedRuntime::get_ic_miss_stub(); 1.529 + // At the stub it needs to look like a call from the caller of this 1.530 + // method (not a call from the segv site). 1.531 + *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; 1.532 + return true; 1.533 + } 1.534 +#endif // COMPILER2 1.535 + return false; 1.536 +} 1.537 + 1.538 +extern "C" JNIEXPORT int 1.539 +JVM_handle_linux_signal(int sig, 1.540 + siginfo_t* info, 1.541 + void* ucVoid, 1.542 + int abort_if_unrecognized) { 1.543 + // in fact this isn't ucontext_t* at all, but struct sigcontext* 1.544 + // but Linux porting layer uses ucontext_t, so to minimize code change 1.545 + // we cast as needed 1.546 + ucontext_t* ucFake = (ucontext_t*) ucVoid; 1.547 + sigcontext* uc = (sigcontext*)ucVoid; 1.548 + 1.549 + Thread* t = ThreadLocalStorage::get_thread_slow(); 1.550 + 1.551 + // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away 1.552 + // (no destructors can be run) 1.553 + os::WatcherThreadCrashProtection::check_crash_protection(sig, t); 1.554 + 1.555 + SignalHandlerMark shm(t); 1.556 + 1.557 + // Note: it's not uncommon that JNI code uses signal/sigset to install 1.558 + // then restore certain signal handler (e.g. to temporarily block SIGPIPE, 1.559 + // or have a SIGILL handler when detecting CPU type). When that happens, 1.560 + // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To 1.561 + // avoid unnecessary crash when libjsig is not preloaded, try handle signals 1.562 + // that do not require siginfo/ucontext first. 1.563 + 1.564 + if (sig == SIGPIPE || sig == SIGXFSZ) { 1.565 + // allow chained handler to go first 1.566 + if (os::Linux::chained_handler(sig, info, ucVoid)) { 1.567 + return true; 1.568 + } else { 1.569 + if (PrintMiscellaneous && (WizardMode || Verbose)) { 1.570 + char buf[64]; 1.571 + warning("Ignoring %s - see bugs 4229104 or 646499219", 1.572 + os::exception_name(sig, buf, sizeof(buf))); 1.573 + } 1.574 + return true; 1.575 + } 1.576 + } 1.577 + 1.578 + JavaThread* thread = NULL; 1.579 + VMThread* vmthread = NULL; 1.580 + if (os::Linux::signal_handlers_are_installed) { 1.581 + if (t != NULL ){ 1.582 + if(t->is_Java_thread()) { 1.583 + thread = (JavaThread*)t; 1.584 + } 1.585 + else if(t->is_VM_thread()){ 1.586 + vmthread = (VMThread *)t; 1.587 + } 1.588 + } 1.589 + } 1.590 + 1.591 + // decide if this trap can be handled by a stub 1.592 + address stub = NULL; 1.593 + address pc = NULL; 1.594 + address npc = NULL; 1.595 + 1.596 + //%note os_trap_1 1.597 + if (info != NULL && uc != NULL && thread != NULL) { 1.598 + pc = address(SIG_PC(uc)); 1.599 + npc = address(SIG_NPC(uc)); 1.600 + 1.601 + // Check to see if we caught the safepoint code in the 1.602 + // process of write protecting the memory serialization page. 1.603 + // It write enables the page immediately after protecting it 1.604 + // so we can just return to retry the write. 1.605 + if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { 1.606 + // Block current thread until the memory serialize page permission restored. 1.607 + os::block_on_serialize_page_trap(); 1.608 + return 1; 1.609 + } 1.610 + 1.611 + if (checkPrefetch(uc, pc)) { 1.612 + return 1; 1.613 + } 1.614 + 1.615 + // Handle ALL stack overflow variations here 1.616 + if (sig == SIGSEGV) { 1.617 + if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { 1.618 + return 1; 1.619 + } 1.620 + } 1.621 + 1.622 + if (sig == SIGBUS && 1.623 + thread->thread_state() == _thread_in_vm && 1.624 + thread->doing_unsafe_access()) { 1.625 + stub = StubRoutines::handler_for_unsafe_access(); 1.626 + } 1.627 + 1.628 + if (thread->thread_state() == _thread_in_Java) { 1.629 + do { 1.630 + // Java thread running in Java code => find exception handler if any 1.631 + // a fault inside compiled code, the interpreter, or a stub 1.632 + 1.633 + if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { 1.634 + break; 1.635 + } 1.636 + 1.637 + if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { 1.638 + break; 1.639 + } 1.640 + 1.641 + if ((sig == SIGSEGV || sig == SIGBUS) && 1.642 + checkVerifyOops(pc, (address)info->si_addr, &stub)) { 1.643 + break; 1.644 + } 1.645 + 1.646 + if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { 1.647 + break; 1.648 + } 1.649 + 1.650 + if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { 1.651 + break; 1.652 + } 1.653 + 1.654 + if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { 1.655 + break; 1.656 + } 1.657 + 1.658 + if ((sig == SIGSEGV) && 1.659 + checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { 1.660 + break; 1.661 + } 1.662 + } while (0); 1.663 + 1.664 + // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 1.665 + // and the heap gets shrunk before the field access. 1.666 + if ((sig == SIGSEGV) || (sig == SIGBUS)) { 1.667 + checkFastJNIAccess(pc, &stub); 1.668 + } 1.669 + } 1.670 + 1.671 + if (stub != NULL) { 1.672 + // save all thread context in case we need to restore it 1.673 + thread->set_saved_exception_pc(pc); 1.674 + thread->set_saved_exception_npc(npc); 1.675 + set_cont_address(uc, stub); 1.676 + return true; 1.677 + } 1.678 + } 1.679 + 1.680 + // signal-chaining 1.681 + if (os::Linux::chained_handler(sig, info, ucVoid)) { 1.682 + return true; 1.683 + } 1.684 + 1.685 + if (!abort_if_unrecognized) { 1.686 + // caller wants another chance, so give it to him 1.687 + return false; 1.688 + } 1.689 + 1.690 + if (pc == NULL && uc != NULL) { 1.691 + pc = os::Linux::ucontext_get_pc((ucontext_t*)uc); 1.692 + } 1.693 + 1.694 + // unmask current signal 1.695 + sigset_t newset; 1.696 + sigemptyset(&newset); 1.697 + sigaddset(&newset, sig); 1.698 + sigprocmask(SIG_UNBLOCK, &newset, NULL); 1.699 + 1.700 + VMError err(t, sig, pc, info, ucVoid); 1.701 + err.report_and_die(); 1.702 + 1.703 + ShouldNotReachHere(); 1.704 +} 1.705 + 1.706 +void os::Linux::init_thread_fpu_state(void) { 1.707 + // Nothing to do 1.708 +} 1.709 + 1.710 +int os::Linux::get_fpu_control_word() { 1.711 + return 0; 1.712 +} 1.713 + 1.714 +void os::Linux::set_fpu_control_word(int fpu) { 1.715 + // nothing 1.716 +} 1.717 + 1.718 +bool os::is_allocatable(size_t bytes) { 1.719 +#ifdef _LP64 1.720 + return true; 1.721 +#else 1.722 + if (bytes < 2 * G) { 1.723 + return true; 1.724 + } 1.725 + 1.726 + char* addr = reserve_memory(bytes, NULL); 1.727 + 1.728 + if (addr != NULL) { 1.729 + release_memory(addr, bytes); 1.730 + } 1.731 + 1.732 + return addr != NULL; 1.733 +#endif // _LP64 1.734 +} 1.735 + 1.736 +/////////////////////////////////////////////////////////////////////////////// 1.737 +// thread stack 1.738 + 1.739 +size_t os::Linux::min_stack_allowed = 128 * K; 1.740 + 1.741 +// pthread on Ubuntu is always in floating stack mode 1.742 +bool os::Linux::supports_variable_stack_size() { return true; } 1.743 + 1.744 +// return default stack size for thr_type 1.745 +size_t os::Linux::default_stack_size(os::ThreadType thr_type) { 1.746 + // default stack size (compiler thread needs larger stack) 1.747 + size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); 1.748 + return s; 1.749 +} 1.750 + 1.751 +size_t os::Linux::default_guard_size(os::ThreadType thr_type) { 1.752 + // Creating guard page is very expensive. Java thread has HotSpot 1.753 + // guard page, only enable glibc guard page for non-Java threads. 1.754 + return (thr_type == java_thread ? 0 : page_size()); 1.755 +} 1.756 + 1.757 +#ifndef PRODUCT 1.758 +void os::verify_stack_alignment() { 1.759 +} 1.760 +#endif