annotate src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp @ 122:435e64505015

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