Fri, 27 Feb 2009 13:27:09 -0800
6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // do not include precompiled header file |
duke@435 | 26 | |
duke@435 | 27 | # include <signal.h> // needed first to avoid name collision for "std" with SC 5.0 |
duke@435 | 28 | |
duke@435 | 29 | # include "incls/_os_solaris_sparc.cpp.incl" |
duke@435 | 30 | |
duke@435 | 31 | // put OS-includes here |
duke@435 | 32 | # include <sys/types.h> |
duke@435 | 33 | # include <sys/mman.h> |
duke@435 | 34 | # include <pthread.h> |
duke@435 | 35 | # include <errno.h> |
duke@435 | 36 | # include <dlfcn.h> |
duke@435 | 37 | # include <stdio.h> |
duke@435 | 38 | # include <unistd.h> |
duke@435 | 39 | # include <sys/resource.h> |
duke@435 | 40 | # include <thread.h> |
duke@435 | 41 | # include <sys/stat.h> |
duke@435 | 42 | # include <sys/time.h> |
duke@435 | 43 | # include <sys/filio.h> |
duke@435 | 44 | # include <sys/utsname.h> |
duke@435 | 45 | # include <sys/systeminfo.h> |
duke@435 | 46 | # include <sys/socket.h> |
duke@435 | 47 | # include <sys/lwp.h> |
duke@435 | 48 | # include <pwd.h> |
duke@435 | 49 | # include <poll.h> |
duke@435 | 50 | # include <sys/lwp.h> |
duke@435 | 51 | |
duke@435 | 52 | # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later |
duke@435 | 53 | # include <sys/procfs.h> // see comment in <sys/procfs.h> |
duke@435 | 54 | |
duke@435 | 55 | #define MAX_PATH (2 * K) |
duke@435 | 56 | |
duke@435 | 57 | // Minimum stack size for the VM. It's easier to document a constant |
duke@435 | 58 | // but it's different for x86 and sparc because the page sizes are different. |
duke@435 | 59 | #ifdef _LP64 |
duke@435 | 60 | size_t os::Solaris::min_stack_allowed = 128*K; |
duke@435 | 61 | #else |
duke@435 | 62 | size_t os::Solaris::min_stack_allowed = 96*K; |
duke@435 | 63 | #endif |
duke@435 | 64 | |
duke@435 | 65 | int os::Solaris::max_register_window_saves_before_flushing() { |
duke@435 | 66 | // We should detect this at run time. For now, filling |
duke@435 | 67 | // in with a constant. |
duke@435 | 68 | return 8; |
duke@435 | 69 | } |
duke@435 | 70 | |
duke@435 | 71 | static void handle_unflushed_register_windows(gwindows_t *win) { |
duke@435 | 72 | int restore_count = win->wbcnt; |
duke@435 | 73 | int i; |
duke@435 | 74 | |
duke@435 | 75 | for(i=0; i<restore_count; i++) { |
duke@435 | 76 | address sp = ((address)win->spbuf[i]) + STACK_BIAS; |
duke@435 | 77 | address reg_win = (address)&win->wbuf[i]; |
duke@435 | 78 | memcpy(sp,reg_win,sizeof(struct rwindow)); |
duke@435 | 79 | } |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | char* os::non_memory_address_word() { |
duke@435 | 83 | // Must never look like an address returned by reserve_memory, |
duke@435 | 84 | // even in its subfields (as defined by the CPU immediate fields, |
duke@435 | 85 | // if the CPU splits constants across multiple instructions). |
duke@435 | 86 | // On SPARC, 0 != %hi(any real address), because there is no |
duke@435 | 87 | // allocation in the first 1Kb of the virtual address space. |
duke@435 | 88 | return (char*) 0; |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | // Validate a ucontext retrieved from walking a uc_link of a ucontext. |
duke@435 | 92 | // There are issues with libthread giving out uc_links for different threads |
duke@435 | 93 | // on the same uc_link chain and bad or circular links. |
duke@435 | 94 | // |
duke@435 | 95 | bool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) { |
duke@435 | 96 | if (valid >= suspect || |
duke@435 | 97 | valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags || |
duke@435 | 98 | valid->uc_stack.ss_sp != suspect->uc_stack.ss_sp || |
duke@435 | 99 | valid->uc_stack.ss_size != suspect->uc_stack.ss_size) { |
duke@435 | 100 | DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");) |
duke@435 | 101 | return false; |
duke@435 | 102 | } |
duke@435 | 103 | |
duke@435 | 104 | if (thread->is_Java_thread()) { |
duke@435 | 105 | if (!valid_stack_address(thread, (address)suspect)) { |
duke@435 | 106 | DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");) |
duke@435 | 107 | return false; |
duke@435 | 108 | } |
duke@435 | 109 | address _sp = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS); |
duke@435 | 110 | if (!valid_stack_address(thread, _sp) || |
duke@435 | 111 | !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) { |
duke@435 | 112 | DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");) |
duke@435 | 113 | return false; |
duke@435 | 114 | } |
duke@435 | 115 | } |
duke@435 | 116 | return true; |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | // We will only follow one level of uc_link since there are libthread |
duke@435 | 120 | // issues with ucontext linking and it is better to be safe and just |
duke@435 | 121 | // let caller retry later. |
duke@435 | 122 | ucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread, |
duke@435 | 123 | ucontext_t *uc) { |
duke@435 | 124 | |
duke@435 | 125 | ucontext_t *retuc = NULL; |
duke@435 | 126 | |
duke@435 | 127 | // Sometimes the topmost register windows are not properly flushed. |
duke@435 | 128 | // i.e., if the kernel would have needed to take a page fault |
duke@435 | 129 | if (uc != NULL && uc->uc_mcontext.gwins != NULL) { |
duke@435 | 130 | ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | if (uc != NULL) { |
duke@435 | 134 | if (uc->uc_link == NULL) { |
duke@435 | 135 | // cannot validate without uc_link so accept current ucontext |
duke@435 | 136 | retuc = uc; |
duke@435 | 137 | } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) { |
duke@435 | 138 | // first ucontext is valid so try the next one |
duke@435 | 139 | uc = uc->uc_link; |
duke@435 | 140 | if (uc->uc_link == NULL) { |
duke@435 | 141 | // cannot validate without uc_link so accept current ucontext |
duke@435 | 142 | retuc = uc; |
duke@435 | 143 | } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) { |
duke@435 | 144 | // the ucontext one level down is also valid so return it |
duke@435 | 145 | retuc = uc; |
duke@435 | 146 | } |
duke@435 | 147 | } |
duke@435 | 148 | } |
duke@435 | 149 | return retuc; |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | // Assumes ucontext is valid |
duke@435 | 153 | ExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) { |
duke@435 | 154 | address pc = (address)uc->uc_mcontext.gregs[REG_PC]; |
duke@435 | 155 | // set npc to zero to avoid using it for safepoint, good for profiling only |
duke@435 | 156 | return ExtendedPC(pc); |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | // Assumes ucontext is valid |
duke@435 | 160 | intptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) { |
duke@435 | 161 | return (intptr_t*)((intptr_t)uc->uc_mcontext.gregs[REG_SP] + STACK_BIAS); |
duke@435 | 162 | } |
duke@435 | 163 | |
duke@435 | 164 | // Solaris X86 only |
duke@435 | 165 | intptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) { |
duke@435 | 166 | ShouldNotReachHere(); |
duke@435 | 167 | return NULL; |
duke@435 | 168 | } |
duke@435 | 169 | |
duke@435 | 170 | // For Forte Analyzer AsyncGetCallTrace profiling support - thread |
duke@435 | 171 | // is currently interrupted by SIGPROF. |
duke@435 | 172 | // |
duke@435 | 173 | // ret_fp parameter is only used by Solaris X86. |
duke@435 | 174 | // |
duke@435 | 175 | // The difference between this and os::fetch_frame_from_context() is that |
duke@435 | 176 | // here we try to skip nested signal frames. |
duke@435 | 177 | ExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread, |
duke@435 | 178 | ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { |
duke@435 | 179 | |
duke@435 | 180 | assert(thread != NULL, "just checking"); |
duke@435 | 181 | assert(ret_sp != NULL, "just checking"); |
duke@435 | 182 | assert(ret_fp == NULL, "just checking"); |
duke@435 | 183 | |
duke@435 | 184 | ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc); |
duke@435 | 185 | |
duke@435 | 186 | return os::fetch_frame_from_context(luc, ret_sp, ret_fp); |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | |
duke@435 | 190 | // ret_fp parameter is only used by Solaris X86. |
duke@435 | 191 | ExtendedPC os::fetch_frame_from_context(void* ucVoid, |
duke@435 | 192 | intptr_t** ret_sp, intptr_t** ret_fp) { |
duke@435 | 193 | |
duke@435 | 194 | ExtendedPC epc; |
duke@435 | 195 | ucontext_t *uc = (ucontext_t*)ucVoid; |
duke@435 | 196 | |
duke@435 | 197 | if (uc != NULL) { |
duke@435 | 198 | epc = os::Solaris::ucontext_get_ExtendedPC(uc); |
duke@435 | 199 | if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc); |
duke@435 | 200 | } else { |
duke@435 | 201 | // construct empty ExtendedPC for return value checking |
duke@435 | 202 | epc = ExtendedPC(NULL); |
duke@435 | 203 | if (ret_sp) *ret_sp = (intptr_t *)NULL; |
duke@435 | 204 | } |
duke@435 | 205 | |
duke@435 | 206 | return epc; |
duke@435 | 207 | } |
duke@435 | 208 | |
duke@435 | 209 | frame os::fetch_frame_from_context(void* ucVoid) { |
duke@435 | 210 | intptr_t* sp; |
duke@435 | 211 | intptr_t* fp; |
duke@435 | 212 | ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); |
duke@435 | 213 | return frame(sp, frame::unpatchable, epc.pc()); |
duke@435 | 214 | } |
duke@435 | 215 | |
duke@435 | 216 | frame os::get_sender_for_C_frame(frame* fr) { |
duke@435 | 217 | return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); |
duke@435 | 218 | } |
duke@435 | 219 | |
duke@435 | 220 | frame os::current_frame() { |
duke@435 | 221 | intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); |
duke@435 | 222 | frame myframe(sp, frame::unpatchable, |
duke@435 | 223 | CAST_FROM_FN_PTR(address, os::current_frame)); |
duke@435 | 224 | if (os::is_first_C_frame(&myframe)) { |
duke@435 | 225 | // stack is not walkable |
duke@435 | 226 | return frame(NULL, NULL, NULL); |
duke@435 | 227 | } else { |
duke@435 | 228 | return os::get_sender_for_C_frame(&myframe); |
duke@435 | 229 | } |
duke@435 | 230 | } |
duke@435 | 231 | |
duke@435 | 232 | |
duke@435 | 233 | void GetThreadPC_Callback::execute(OSThread::InterruptArguments *args) { |
duke@435 | 234 | Thread* thread = args->thread(); |
duke@435 | 235 | ucontext_t* uc = args->ucontext(); |
duke@435 | 236 | intptr_t* sp; |
duke@435 | 237 | |
duke@435 | 238 | assert(ProfileVM && thread->is_VM_thread(), "just checking"); |
duke@435 | 239 | |
duke@435 | 240 | // Skip the mcontext corruption verification. If if occasionally |
duke@435 | 241 | // things get corrupt, it is ok for profiling - we will just get an unresolved |
duke@435 | 242 | // function name |
duke@435 | 243 | ExtendedPC new_addr((address)uc->uc_mcontext.gregs[REG_PC]); |
duke@435 | 244 | _addr = new_addr; |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | |
duke@435 | 248 | static int threadgetstate(thread_t tid, int *flags, lwpid_t *lwp, stack_t *ss, gregset_t rs, lwpstatus_t *lwpstatus) { |
duke@435 | 249 | char lwpstatusfile[PROCFILE_LENGTH]; |
duke@435 | 250 | int lwpfd, err; |
duke@435 | 251 | |
duke@435 | 252 | if (err = os::Solaris::thr_getstate(tid, flags, lwp, ss, rs)) |
duke@435 | 253 | return (err); |
duke@435 | 254 | if (*flags == TRS_LWPID) { |
duke@435 | 255 | sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(), |
duke@435 | 256 | *lwp); |
duke@435 | 257 | if ((lwpfd = open(lwpstatusfile, O_RDONLY)) < 0) { |
duke@435 | 258 | perror("thr_mutator_status: open lwpstatus"); |
duke@435 | 259 | return (EINVAL); |
duke@435 | 260 | } |
duke@435 | 261 | if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) != |
duke@435 | 262 | sizeof (lwpstatus_t)) { |
duke@435 | 263 | perror("thr_mutator_status: read lwpstatus"); |
duke@435 | 264 | (void) close(lwpfd); |
duke@435 | 265 | return (EINVAL); |
duke@435 | 266 | } |
duke@435 | 267 | (void) close(lwpfd); |
duke@435 | 268 | } |
duke@435 | 269 | return (0); |
duke@435 | 270 | } |
duke@435 | 271 | |
duke@435 | 272 | |
duke@435 | 273 | bool os::is_allocatable(size_t bytes) { |
duke@435 | 274 | #ifdef _LP64 |
duke@435 | 275 | return true; |
duke@435 | 276 | #else |
duke@435 | 277 | return (bytes <= (size_t)3835*M); |
duke@435 | 278 | #endif |
duke@435 | 279 | } |
duke@435 | 280 | |
duke@435 | 281 | extern "C" void Fetch32PFI () ; |
duke@435 | 282 | extern "C" void Fetch32Resume () ; |
duke@435 | 283 | extern "C" void FetchNPFI () ; |
duke@435 | 284 | extern "C" void FetchNResume () ; |
duke@435 | 285 | |
duke@435 | 286 | extern "C" int JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); |
duke@435 | 287 | |
duke@435 | 288 | int JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) { |
duke@435 | 289 | ucontext_t* uc = (ucontext_t*) ucVoid; |
duke@435 | 290 | |
duke@435 | 291 | Thread* t = ThreadLocalStorage::get_thread_slow(); |
duke@435 | 292 | |
duke@435 | 293 | SignalHandlerMark shm(t); |
duke@435 | 294 | |
duke@435 | 295 | if(sig == SIGPIPE || sig == SIGXFSZ) { |
duke@435 | 296 | if (os::Solaris::chained_handler(sig, info, ucVoid)) { |
duke@435 | 297 | return true; |
duke@435 | 298 | } else { |
duke@435 | 299 | if (PrintMiscellaneous && (WizardMode || Verbose)) { |
duke@435 | 300 | char buf[64]; |
duke@435 | 301 | warning("Ignoring %s - see 4229104 or 6499219", |
duke@435 | 302 | os::exception_name(sig, buf, sizeof(buf))); |
duke@435 | 303 | |
duke@435 | 304 | } |
duke@435 | 305 | return true; |
duke@435 | 306 | } |
duke@435 | 307 | } |
duke@435 | 308 | |
duke@435 | 309 | JavaThread* thread = NULL; |
duke@435 | 310 | VMThread* vmthread = NULL; |
duke@435 | 311 | if (os::Solaris::signal_handlers_are_installed) { |
duke@435 | 312 | if (t != NULL ){ |
duke@435 | 313 | if(t->is_Java_thread()) { |
duke@435 | 314 | thread = (JavaThread*)t; |
duke@435 | 315 | } |
duke@435 | 316 | else if(t->is_VM_thread()){ |
duke@435 | 317 | vmthread = (VMThread *)t; |
duke@435 | 318 | } |
duke@435 | 319 | } |
duke@435 | 320 | } |
duke@435 | 321 | |
duke@435 | 322 | guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs"); |
duke@435 | 323 | |
duke@435 | 324 | if (sig == os::Solaris::SIGasync()) { |
duke@435 | 325 | if (thread) { |
duke@435 | 326 | OSThread::InterruptArguments args(thread, uc); |
duke@435 | 327 | thread->osthread()->do_interrupt_callbacks_at_interrupt(&args); |
duke@435 | 328 | return true; |
duke@435 | 329 | } else if (vmthread) { |
duke@435 | 330 | OSThread::InterruptArguments args(vmthread, uc); |
duke@435 | 331 | vmthread->osthread()->do_interrupt_callbacks_at_interrupt(&args); |
duke@435 | 332 | return true; |
duke@435 | 333 | } else if (os::Solaris::chained_handler(sig, info, ucVoid)) { |
duke@435 | 334 | return true; |
duke@435 | 335 | } else { |
duke@435 | 336 | // If os::Solaris::SIGasync not chained, and this is a non-vm and |
duke@435 | 337 | // non-java thread |
duke@435 | 338 | return true; |
duke@435 | 339 | } |
duke@435 | 340 | } |
duke@435 | 341 | |
duke@435 | 342 | if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { |
duke@435 | 343 | // can't decode this kind of signal |
duke@435 | 344 | info = NULL; |
duke@435 | 345 | } else { |
duke@435 | 346 | assert(sig == info->si_signo, "bad siginfo"); |
duke@435 | 347 | } |
duke@435 | 348 | |
duke@435 | 349 | // decide if this trap can be handled by a stub |
duke@435 | 350 | address stub = NULL; |
duke@435 | 351 | |
duke@435 | 352 | address pc = NULL; |
duke@435 | 353 | address npc = NULL; |
duke@435 | 354 | |
duke@435 | 355 | //%note os_trap_1 |
duke@435 | 356 | if (info != NULL && uc != NULL && thread != NULL) { |
duke@435 | 357 | // factor me: getPCfromContext |
duke@435 | 358 | pc = (address) uc->uc_mcontext.gregs[REG_PC]; |
duke@435 | 359 | npc = (address) uc->uc_mcontext.gregs[REG_nPC]; |
duke@435 | 360 | |
duke@435 | 361 | // SafeFetch() support |
duke@435 | 362 | // Implemented with either a fixed set of addresses such |
duke@435 | 363 | // as Fetch32*, or with Thread._OnTrap. |
duke@435 | 364 | if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(Fetch32PFI)) { |
duke@435 | 365 | uc->uc_mcontext.gregs [REG_PC] = intptr_t(Fetch32Resume) ; |
duke@435 | 366 | uc->uc_mcontext.gregs [REG_nPC] = intptr_t(Fetch32Resume) + 4 ; |
duke@435 | 367 | return true ; |
duke@435 | 368 | } |
duke@435 | 369 | if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(FetchNPFI)) { |
duke@435 | 370 | uc->uc_mcontext.gregs [REG_PC] = intptr_t(FetchNResume) ; |
duke@435 | 371 | uc->uc_mcontext.gregs [REG_nPC] = intptr_t(FetchNResume) + 4 ; |
duke@435 | 372 | return true ; |
duke@435 | 373 | } |
duke@435 | 374 | |
duke@435 | 375 | // Handle ALL stack overflow variations here |
duke@435 | 376 | if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) { |
duke@435 | 377 | address addr = (address) info->si_addr; |
duke@435 | 378 | if (thread->in_stack_yellow_zone(addr)) { |
duke@435 | 379 | thread->disable_stack_yellow_zone(); |
duke@435 | 380 | // Sometimes the register windows are not properly flushed. |
duke@435 | 381 | if(uc->uc_mcontext.gwins != NULL) { |
duke@435 | 382 | ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); |
duke@435 | 383 | } |
duke@435 | 384 | if (thread->thread_state() == _thread_in_Java) { |
duke@435 | 385 | // Throw a stack overflow exception. Guard pages will be reenabled |
duke@435 | 386 | // while unwinding the stack. |
duke@435 | 387 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); |
duke@435 | 388 | } else { |
duke@435 | 389 | // Thread was in the vm or native code. Return and try to finish. |
duke@435 | 390 | return true; |
duke@435 | 391 | } |
duke@435 | 392 | } else if (thread->in_stack_red_zone(addr)) { |
duke@435 | 393 | // Fatal red zone violation. Disable the guard pages and fall through |
duke@435 | 394 | // to handle_unexpected_exception way down below. |
duke@435 | 395 | thread->disable_stack_red_zone(); |
duke@435 | 396 | tty->print_raw_cr("An irrecoverable stack overflow has occurred."); |
duke@435 | 397 | // Sometimes the register windows are not properly flushed. |
duke@435 | 398 | if(uc->uc_mcontext.gwins != NULL) { |
duke@435 | 399 | ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); |
duke@435 | 400 | } |
duke@435 | 401 | } |
duke@435 | 402 | } |
duke@435 | 403 | |
duke@435 | 404 | |
duke@435 | 405 | if (thread->thread_state() == _thread_in_vm) { |
duke@435 | 406 | if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) { |
duke@435 | 407 | stub = StubRoutines::handler_for_unsafe_access(); |
duke@435 | 408 | } |
duke@435 | 409 | } |
duke@435 | 410 | |
duke@435 | 411 | else if (thread->thread_state() == _thread_in_Java) { |
duke@435 | 412 | // Java thread running in Java code => find exception handler if any |
duke@435 | 413 | // a fault inside compiled code, the interpreter, or a stub |
duke@435 | 414 | |
duke@435 | 415 | // Support Safepoint Polling |
duke@435 | 416 | if ( sig == SIGSEGV && (address)info->si_addr == os::get_polling_page() ) { |
duke@435 | 417 | stub = SharedRuntime::get_poll_stub(pc); |
duke@435 | 418 | } |
duke@435 | 419 | |
duke@435 | 420 | // Not needed on x86 solaris because verify_oops doesn't generate |
duke@435 | 421 | // SEGV/BUS like sparc does. |
duke@435 | 422 | if ( (sig == SIGSEGV || sig == SIGBUS) |
duke@435 | 423 | && pc >= MacroAssembler::_verify_oop_implicit_branch[0] |
duke@435 | 424 | && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { |
duke@435 | 425 | stub = MacroAssembler::_verify_oop_implicit_branch[2]; |
duke@435 | 426 | warning("fixed up memory fault in +VerifyOops at address " INTPTR_FORMAT, info->si_addr); |
duke@435 | 427 | } |
duke@435 | 428 | |
duke@435 | 429 | // This is not factored because on x86 solaris the patching for |
duke@435 | 430 | // zombies does not generate a SEGV. |
duke@435 | 431 | else if (sig == SIGSEGV && nativeInstruction_at(pc)->is_zombie()) { |
duke@435 | 432 | // zombie method (ld [%g0],%o7 instruction) |
duke@435 | 433 | stub = SharedRuntime::get_handle_wrong_method_stub(); |
duke@435 | 434 | |
duke@435 | 435 | // At the stub it needs to look like a call from the caller of this |
duke@435 | 436 | // method (not a call from the segv site). |
duke@435 | 437 | pc = (address)uc->uc_mcontext.gregs[REG_O7]; |
duke@435 | 438 | } |
duke@435 | 439 | else if (sig == SIGBUS && info->si_code == BUS_OBJERR) { |
duke@435 | 440 | // BugId 4454115: A read from a MappedByteBuffer can fault |
duke@435 | 441 | // here if the underlying file has been truncated. |
duke@435 | 442 | // Do not crash the VM in such a case. |
duke@435 | 443 | CodeBlob* cb = CodeCache::find_blob_unsafe(pc); |
duke@435 | 444 | nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; |
duke@435 | 445 | if (nm != NULL && nm->has_unsafe_access()) { |
duke@435 | 446 | stub = StubRoutines::handler_for_unsafe_access(); |
duke@435 | 447 | } |
duke@435 | 448 | } |
duke@435 | 449 | |
duke@435 | 450 | else if (sig == SIGFPE && info->si_code == FPE_INTDIV) { |
duke@435 | 451 | // integer divide by zero |
duke@435 | 452 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); |
duke@435 | 453 | } |
duke@435 | 454 | else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) { |
duke@435 | 455 | // floating-point divide by zero |
duke@435 | 456 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); |
duke@435 | 457 | } |
duke@435 | 458 | #ifdef COMPILER2 |
duke@435 | 459 | else if (sig == SIGILL && nativeInstruction_at(pc)->is_ic_miss_trap()) { |
duke@435 | 460 | #ifdef ASSERT |
duke@435 | 461 | #ifdef TIERED |
duke@435 | 462 | CodeBlob* cb = CodeCache::find_blob_unsafe(pc); |
duke@435 | 463 | assert(cb->is_compiled_by_c2(), "Wrong compiler"); |
duke@435 | 464 | #endif // TIERED |
duke@435 | 465 | #endif // ASSERT |
duke@435 | 466 | // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. |
duke@435 | 467 | stub = SharedRuntime::get_ic_miss_stub(); |
duke@435 | 468 | // At the stub it needs to look like a call from the caller of this |
duke@435 | 469 | // method (not a call from the segv site). |
duke@435 | 470 | pc = (address)uc->uc_mcontext.gregs[REG_O7]; |
duke@435 | 471 | } |
duke@435 | 472 | #endif // COMPILER2 |
duke@435 | 473 | |
duke@435 | 474 | else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { |
duke@435 | 475 | // Determination of interpreter/vtable stub/compiled code null exception |
duke@435 | 476 | stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
duke@435 | 477 | } |
duke@435 | 478 | } |
duke@435 | 479 | |
duke@435 | 480 | // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in |
duke@435 | 481 | // and the heap gets shrunk before the field access. |
duke@435 | 482 | if ((sig == SIGSEGV) || (sig == SIGBUS)) { |
duke@435 | 483 | address addr = JNI_FastGetField::find_slowcase_pc(pc); |
duke@435 | 484 | if (addr != (address)-1) { |
duke@435 | 485 | stub = addr; |
duke@435 | 486 | } |
duke@435 | 487 | } |
duke@435 | 488 | |
duke@435 | 489 | // Check to see if we caught the safepoint code in the |
duke@435 | 490 | // process of write protecting the memory serialization page. |
duke@435 | 491 | // It write enables the page immediately after protecting it |
duke@435 | 492 | // so just return. |
duke@435 | 493 | if ((sig == SIGSEGV) && |
duke@435 | 494 | os::is_memory_serialize_page(thread, (address)info->si_addr)) { |
duke@435 | 495 | // Block current thread until the memory serialize page permission restored. |
duke@435 | 496 | os::block_on_serialize_page_trap(); |
duke@435 | 497 | return true; |
duke@435 | 498 | } |
duke@435 | 499 | } |
duke@435 | 500 | |
duke@435 | 501 | if (stub != NULL) { |
duke@435 | 502 | // save all thread context in case we need to restore it |
duke@435 | 503 | |
duke@435 | 504 | thread->set_saved_exception_pc(pc); |
duke@435 | 505 | thread->set_saved_exception_npc(npc); |
duke@435 | 506 | |
duke@435 | 507 | // simulate a branch to the stub (a "call" in the safepoint stub case) |
duke@435 | 508 | // factor me: setPC |
duke@435 | 509 | uc->uc_mcontext.gregs[REG_PC ] = (greg_t)stub; |
duke@435 | 510 | uc->uc_mcontext.gregs[REG_nPC] = (greg_t)(stub + 4); |
duke@435 | 511 | |
duke@435 | 512 | #ifndef PRODUCT |
duke@435 | 513 | if (TraceJumps) thread->record_jump(stub, NULL, __FILE__, __LINE__); |
duke@435 | 514 | #endif /* PRODUCT */ |
duke@435 | 515 | |
duke@435 | 516 | return true; |
duke@435 | 517 | } |
duke@435 | 518 | |
duke@435 | 519 | // signal-chaining |
duke@435 | 520 | if (os::Solaris::chained_handler(sig, info, ucVoid)) { |
duke@435 | 521 | return true; |
duke@435 | 522 | } |
duke@435 | 523 | |
duke@435 | 524 | if (!abort_if_unrecognized) { |
duke@435 | 525 | // caller wants another chance, so give it to him |
duke@435 | 526 | return false; |
duke@435 | 527 | } |
duke@435 | 528 | |
duke@435 | 529 | if (!os::Solaris::libjsig_is_loaded) { |
duke@435 | 530 | struct sigaction oldAct; |
duke@435 | 531 | sigaction(sig, (struct sigaction *)0, &oldAct); |
duke@435 | 532 | if (oldAct.sa_sigaction != signalHandler) { |
duke@435 | 533 | void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) |
duke@435 | 534 | : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); |
twisti@1040 | 535 | warning("Unexpected Signal %d occurred under user-defined signal handler " INTPTR_FORMAT, sig, (intptr_t)sighand); |
duke@435 | 536 | } |
duke@435 | 537 | } |
duke@435 | 538 | |
duke@435 | 539 | if (pc == NULL && uc != NULL) { |
duke@435 | 540 | pc = (address) uc->uc_mcontext.gregs[REG_PC]; |
duke@435 | 541 | } |
duke@435 | 542 | |
duke@435 | 543 | // unmask current signal |
duke@435 | 544 | sigset_t newset; |
duke@435 | 545 | sigemptyset(&newset); |
duke@435 | 546 | sigaddset(&newset, sig); |
duke@435 | 547 | sigprocmask(SIG_UNBLOCK, &newset, NULL); |
duke@435 | 548 | |
duke@435 | 549 | VMError err(t, sig, pc, info, ucVoid); |
duke@435 | 550 | err.report_and_die(); |
duke@435 | 551 | |
duke@435 | 552 | ShouldNotReachHere(); |
duke@435 | 553 | } |
duke@435 | 554 | |
duke@435 | 555 | void os::print_context(outputStream *st, void *context) { |
duke@435 | 556 | if (context == NULL) return; |
duke@435 | 557 | |
duke@435 | 558 | ucontext_t *uc = (ucontext_t*)context; |
duke@435 | 559 | st->print_cr("Registers:"); |
duke@435 | 560 | |
duke@435 | 561 | st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT |
duke@435 | 562 | " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, |
duke@435 | 563 | uc->uc_mcontext.gregs[REG_O0], |
duke@435 | 564 | uc->uc_mcontext.gregs[REG_O1], |
duke@435 | 565 | uc->uc_mcontext.gregs[REG_O2], |
duke@435 | 566 | uc->uc_mcontext.gregs[REG_O3]); |
duke@435 | 567 | st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT |
duke@435 | 568 | " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, |
duke@435 | 569 | uc->uc_mcontext.gregs[REG_O4], |
duke@435 | 570 | uc->uc_mcontext.gregs[REG_O5], |
duke@435 | 571 | uc->uc_mcontext.gregs[REG_O6], |
duke@435 | 572 | uc->uc_mcontext.gregs[REG_O7]); |
duke@435 | 573 | |
duke@435 | 574 | st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT |
duke@435 | 575 | " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, |
duke@435 | 576 | uc->uc_mcontext.gregs[REG_G1], |
duke@435 | 577 | uc->uc_mcontext.gregs[REG_G2], |
duke@435 | 578 | uc->uc_mcontext.gregs[REG_G3], |
duke@435 | 579 | uc->uc_mcontext.gregs[REG_G4]); |
duke@435 | 580 | st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT |
duke@435 | 581 | " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, |
duke@435 | 582 | uc->uc_mcontext.gregs[REG_G5], |
duke@435 | 583 | uc->uc_mcontext.gregs[REG_G6], |
duke@435 | 584 | uc->uc_mcontext.gregs[REG_G7], |
duke@435 | 585 | uc->uc_mcontext.gregs[REG_Y]); |
duke@435 | 586 | |
duke@435 | 587 | st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, |
duke@435 | 588 | uc->uc_mcontext.gregs[REG_PC], |
duke@435 | 589 | uc->uc_mcontext.gregs[REG_nPC]); |
duke@435 | 590 | st->cr(); |
duke@435 | 591 | st->cr(); |
duke@435 | 592 | |
duke@435 | 593 | intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc); |
duke@435 | 594 | st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); |
duke@435 | 595 | print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); |
duke@435 | 596 | st->cr(); |
duke@435 | 597 | |
duke@435 | 598 | // Note: it may be unsafe to inspect memory near pc. For example, pc may |
duke@435 | 599 | // point to garbage if entry point in an nmethod is corrupted. Leave |
duke@435 | 600 | // this at the end, and hope for the best. |
duke@435 | 601 | ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc); |
duke@435 | 602 | address pc = epc.pc(); |
duke@435 | 603 | st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); |
duke@435 | 604 | print_hex_dump(st, pc - 16, pc + 16, sizeof(char)); |
duke@435 | 605 | } |
duke@435 | 606 | |
duke@435 | 607 | void os::Solaris::init_thread_fpu_state(void) { |
duke@435 | 608 | // Nothing needed on Sparc. |
duke@435 | 609 | } |
duke@435 | 610 | |
duke@435 | 611 | #if !defined(COMPILER2) && !defined(_LP64) |
duke@435 | 612 | |
duke@435 | 613 | // These routines are the initial value of atomic_xchg_entry(), |
duke@435 | 614 | // atomic_cmpxchg_entry(), atomic_add_entry() and fence_entry() |
duke@435 | 615 | // until initialization is complete. |
duke@435 | 616 | // TODO - remove when the VM drops support for V8. |
duke@435 | 617 | |
duke@435 | 618 | typedef jint xchg_func_t (jint, volatile jint*); |
duke@435 | 619 | typedef jint cmpxchg_func_t (jint, volatile jint*, jint); |
duke@435 | 620 | typedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong); |
duke@435 | 621 | typedef jint add_func_t (jint, volatile jint*); |
duke@435 | 622 | typedef void fence_func_t (); |
duke@435 | 623 | |
duke@435 | 624 | jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) { |
duke@435 | 625 | // try to use the stub: |
duke@435 | 626 | xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry()); |
duke@435 | 627 | |
duke@435 | 628 | if (func != NULL) { |
duke@435 | 629 | os::atomic_xchg_func = func; |
duke@435 | 630 | return (*func)(exchange_value, dest); |
duke@435 | 631 | } |
duke@435 | 632 | assert(Threads::number_of_threads() == 0, "for bootstrap only"); |
duke@435 | 633 | |
duke@435 | 634 | jint old_value = *dest; |
duke@435 | 635 | *dest = exchange_value; |
duke@435 | 636 | return old_value; |
duke@435 | 637 | } |
duke@435 | 638 | |
duke@435 | 639 | jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) { |
duke@435 | 640 | // try to use the stub: |
duke@435 | 641 | cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry()); |
duke@435 | 642 | |
duke@435 | 643 | if (func != NULL) { |
duke@435 | 644 | os::atomic_cmpxchg_func = func; |
duke@435 | 645 | return (*func)(exchange_value, dest, compare_value); |
duke@435 | 646 | } |
duke@435 | 647 | assert(Threads::number_of_threads() == 0, "for bootstrap only"); |
duke@435 | 648 | |
duke@435 | 649 | jint old_value = *dest; |
duke@435 | 650 | if (old_value == compare_value) |
duke@435 | 651 | *dest = exchange_value; |
duke@435 | 652 | return old_value; |
duke@435 | 653 | } |
duke@435 | 654 | |
duke@435 | 655 | jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) { |
duke@435 | 656 | // try to use the stub: |
duke@435 | 657 | cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry()); |
duke@435 | 658 | |
duke@435 | 659 | if (func != NULL) { |
duke@435 | 660 | os::atomic_cmpxchg_long_func = func; |
duke@435 | 661 | return (*func)(exchange_value, dest, compare_value); |
duke@435 | 662 | } |
duke@435 | 663 | assert(Threads::number_of_threads() == 0, "for bootstrap only"); |
duke@435 | 664 | |
duke@435 | 665 | jlong old_value = *dest; |
duke@435 | 666 | if (old_value == compare_value) |
duke@435 | 667 | *dest = exchange_value; |
duke@435 | 668 | return old_value; |
duke@435 | 669 | } |
duke@435 | 670 | |
duke@435 | 671 | jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) { |
duke@435 | 672 | // try to use the stub: |
duke@435 | 673 | add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry()); |
duke@435 | 674 | |
duke@435 | 675 | if (func != NULL) { |
duke@435 | 676 | os::atomic_add_func = func; |
duke@435 | 677 | return (*func)(add_value, dest); |
duke@435 | 678 | } |
duke@435 | 679 | assert(Threads::number_of_threads() == 0, "for bootstrap only"); |
duke@435 | 680 | |
duke@435 | 681 | return (*dest) += add_value; |
duke@435 | 682 | } |
duke@435 | 683 | |
duke@435 | 684 | void os::fence_bootstrap() { |
duke@435 | 685 | // try to use the stub: |
duke@435 | 686 | fence_func_t* func = CAST_TO_FN_PTR(fence_func_t*, StubRoutines::fence_entry()); |
duke@435 | 687 | |
duke@435 | 688 | if (func != NULL) { |
duke@435 | 689 | os::fence_func = func; |
duke@435 | 690 | (*func)(); |
duke@435 | 691 | return; |
duke@435 | 692 | } |
duke@435 | 693 | assert(Threads::number_of_threads() == 0, "for bootstrap only"); |
duke@435 | 694 | |
duke@435 | 695 | // don't have to do anything for a single thread |
duke@435 | 696 | } |
duke@435 | 697 | |
duke@435 | 698 | xchg_func_t* os::atomic_xchg_func = os::atomic_xchg_bootstrap; |
duke@435 | 699 | cmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap; |
duke@435 | 700 | cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap; |
duke@435 | 701 | add_func_t* os::atomic_add_func = os::atomic_add_bootstrap; |
duke@435 | 702 | fence_func_t* os::fence_func = os::fence_bootstrap; |
duke@435 | 703 | |
duke@435 | 704 | #endif // !_LP64 && !COMPILER2 |
duke@435 | 705 | |
duke@435 | 706 | #if defined(__sparc) && defined(COMPILER2) && defined(_GNU_SOURCE) |
duke@435 | 707 | // See file build/solaris/makefiles/$compiler.make |
duke@435 | 708 | // For compiler1 the architecture is v8 and frps isn't present in v8 |
duke@435 | 709 | extern "C" void _mark_fpu_nosave() { |
duke@435 | 710 | __asm__ __volatile__ ("wr %%g0, 0, %%fprs \n\t" : : :); |
duke@435 | 711 | } |
duke@435 | 712 | #endif //defined(__sparc) && defined(COMPILER2) |