src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp

Tue, 01 Feb 2011 11:23:19 -0500

author
coleenp
date
Tue, 01 Feb 2011 11:23:19 -0500
changeset 2507
d70fe6ab4436
parent 2322
828eafbd85cc
child 2708
1d1603768966
permissions
-rw-r--r--

6588413: Use -fvisibility=hidden for gcc compiles
Summary: Add option for gcc 4 and above, define JNIEXPORT and JNIIMPORT to visibility=default, add for jio_snprintf and others since -fvisibility=hidden overrides --version-script definitions.
Reviewed-by: kamg, never

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

mercurial