hotspot/src/os/linux/vm/os_linux.cpp
changeset 22894 870fbe165d06
parent 22891 1f5d1fff23fa
parent 22876 57aa8995d43b
child 23185 a2143156a0a0
equal deleted inserted replaced
22893:e3a2b513713a 22894:870fbe165d06
   137 
   137 
   138 static int clock_tics_per_sec = 100;
   138 static int clock_tics_per_sec = 100;
   139 
   139 
   140 // For diagnostics to print a message once. see run_periodic_checks
   140 // For diagnostics to print a message once. see run_periodic_checks
   141 static sigset_t check_signal_done;
   141 static sigset_t check_signal_done;
   142 static bool check_signals = true;;
   142 static bool check_signals = true;
   143 
   143 
   144 static pid_t _initial_pid = 0;
   144 static pid_t _initial_pid = 0;
   145 
   145 
   146 /* Signal number used to suspend/resume a thread */
   146 /* Signal number used to suspend/resume a thread */
   147 
   147 
   255 static char cpu_arch[] = "i386";
   255 static char cpu_arch[] = "i386";
   256 #elif defined(AMD64)
   256 #elif defined(AMD64)
   257 static char cpu_arch[] = "amd64";
   257 static char cpu_arch[] = "amd64";
   258 #elif defined(ARM)
   258 #elif defined(ARM)
   259 static char cpu_arch[] = "arm";
   259 static char cpu_arch[] = "arm";
   260 #elif defined(PPC)
   260 #elif defined(PPC32)
   261 static char cpu_arch[] = "ppc";
   261 static char cpu_arch[] = "ppc";
       
   262 #elif defined(PPC64)
       
   263 static char cpu_arch[] = "ppc64";
   262 #elif defined(SPARC)
   264 #elif defined(SPARC)
   263 #  ifdef _LP64
   265 #  ifdef _LP64
   264 static char cpu_arch[] = "sparcv9";
   266 static char cpu_arch[] = "sparcv9";
   265 #  else
   267 #  else
   266 static char cpu_arch[] = "sparc";
   268 static char cpu_arch[] = "sparc";
   528   sigemptyset(&allowdebug_blocked_sigs);
   530   sigemptyset(&allowdebug_blocked_sigs);
   529   sigaddset(&unblocked_sigs, SIGILL);
   531   sigaddset(&unblocked_sigs, SIGILL);
   530   sigaddset(&unblocked_sigs, SIGSEGV);
   532   sigaddset(&unblocked_sigs, SIGSEGV);
   531   sigaddset(&unblocked_sigs, SIGBUS);
   533   sigaddset(&unblocked_sigs, SIGBUS);
   532   sigaddset(&unblocked_sigs, SIGFPE);
   534   sigaddset(&unblocked_sigs, SIGFPE);
       
   535 #if defined(PPC64)
       
   536   sigaddset(&unblocked_sigs, SIGTRAP);
       
   537 #endif
   533   sigaddset(&unblocked_sigs, SR_signum);
   538   sigaddset(&unblocked_sigs, SR_signum);
   534 
   539 
   535   if (!ReduceSignalUsage) {
   540   if (!ReduceSignalUsage) {
   536    if (!os::Linux::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
   541    if (!os::Linux::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
   537       sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
   542       sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
  2258     st->print("  <Not Available>");
  2263     st->print("  <Not Available>");
  2259   }
  2264   }
  2260   st->cr();
  2265   st->cr();
  2261 }
  2266 }
  2262 
  2267 
  2263 // Taken from /usr/include/bits/siginfo.h  Supposed to be architecture specific
       
  2264 // but they're the same for all the linux arch that we support
       
  2265 // and they're the same for solaris but there's no common place to put this.
       
  2266 const char *ill_names[] = { "ILL0", "ILL_ILLOPC", "ILL_ILLOPN", "ILL_ILLADR",
       
  2267                           "ILL_ILLTRP", "ILL_PRVOPC", "ILL_PRVREG",
       
  2268                           "ILL_COPROC", "ILL_BADSTK" };
       
  2269 
       
  2270 const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV",
       
  2271                           "FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES",
       
  2272                           "FPE_FLTINV", "FPE_FLTSUB", "FPE_FLTDEN" };
       
  2273 
       
  2274 const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" };
       
  2275 
       
  2276 const char *bus_names[] = { "BUS0", "BUS_ADRALN", "BUS_ADRERR", "BUS_OBJERR" };
       
  2277 
       
  2278 void os::print_siginfo(outputStream* st, void* siginfo) {
  2268 void os::print_siginfo(outputStream* st, void* siginfo) {
  2279   st->print("siginfo:");
  2269   const siginfo_t* si = (const siginfo_t*)siginfo;
  2280 
  2270 
  2281   const int buflen = 100;
  2271   os::Posix::print_siginfo_brief(st, si);
  2282   char buf[buflen];
  2272 
  2283   siginfo_t *si = (siginfo_t*)siginfo;
  2273   if (si && (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
  2284   st->print("si_signo=%s: ", os::exception_name(si->si_signo, buf, buflen));
       
  2285   if (si->si_errno != 0 && strerror_r(si->si_errno, buf, buflen) == 0) {
       
  2286     st->print("si_errno=%s", buf);
       
  2287   } else {
       
  2288     st->print("si_errno=%d", si->si_errno);
       
  2289   }
       
  2290   const int c = si->si_code;
       
  2291   assert(c > 0, "unexpected si_code");
       
  2292   switch (si->si_signo) {
       
  2293   case SIGILL:
       
  2294     st->print(", si_code=%d (%s)", c, c > 8 ? "" : ill_names[c]);
       
  2295     st->print(", si_addr=" PTR_FORMAT, si->si_addr);
       
  2296     break;
       
  2297   case SIGFPE:
       
  2298     st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]);
       
  2299     st->print(", si_addr=" PTR_FORMAT, si->si_addr);
       
  2300     break;
       
  2301   case SIGSEGV:
       
  2302     st->print(", si_code=%d (%s)", c, c > 2 ? "" : segv_names[c]);
       
  2303     st->print(", si_addr=" PTR_FORMAT, si->si_addr);
       
  2304     break;
       
  2305   case SIGBUS:
       
  2306     st->print(", si_code=%d (%s)", c, c > 3 ? "" : bus_names[c]);
       
  2307     st->print(", si_addr=" PTR_FORMAT, si->si_addr);
       
  2308     break;
       
  2309   default:
       
  2310     st->print(", si_code=%d", si->si_code);
       
  2311     // no si_addr
       
  2312   }
       
  2313 
       
  2314   if ((si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
       
  2315       UseSharedSpaces) {
  2274       UseSharedSpaces) {
  2316     FileMapInfo* mapinfo = FileMapInfo::current_info();
  2275     FileMapInfo* mapinfo = FileMapInfo::current_info();
  2317     if (mapinfo->is_in_shared_space(si->si_addr)) {
  2276     if (mapinfo->is_in_shared_space(si->si_addr)) {
  2318       st->print("\n\nError accessing class data sharing archive."   \
  2277       st->print("\n\nError accessing class data sharing archive."   \
  2319                 " Mapped file inaccessible during execution, "      \
  2278                 " Mapped file inaccessible during execution, "      \
  2339   print_signal_handler(st, SR_signum, buf, buflen);
  2298   print_signal_handler(st, SR_signum, buf, buflen);
  2340   print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
  2299   print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
  2341   print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
  2300   print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
  2342   print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
  2301   print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
  2343   print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
  2302   print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
       
  2303 #if defined(PPC64)
       
  2304   print_signal_handler(st, SIGTRAP, buf, buflen);
       
  2305 #endif
  2344 }
  2306 }
  2345 
  2307 
  2346 static char saved_jvm_path[MAXPATHLEN] = {0};
  2308 static char saved_jvm_path[MAXPATHLEN] = {0};
  2347 
  2309 
  2348 // Find the full path to the current module, libjvm.so
  2310 // Find the full path to the current module, libjvm.so
  4372     set_signal_handler(SIGSEGV, true);
  4334     set_signal_handler(SIGSEGV, true);
  4373     set_signal_handler(SIGPIPE, true);
  4335     set_signal_handler(SIGPIPE, true);
  4374     set_signal_handler(SIGBUS, true);
  4336     set_signal_handler(SIGBUS, true);
  4375     set_signal_handler(SIGILL, true);
  4337     set_signal_handler(SIGILL, true);
  4376     set_signal_handler(SIGFPE, true);
  4338     set_signal_handler(SIGFPE, true);
       
  4339 #if defined(PPC64)
       
  4340     set_signal_handler(SIGTRAP, true);
       
  4341 #endif
  4377     set_signal_handler(SIGXFSZ, true);
  4342     set_signal_handler(SIGXFSZ, true);
  4378 
  4343 
  4379     if (libjsig_is_loaded) {
  4344     if (libjsig_is_loaded) {
  4380       // Tell libjsig jvm finishes setting signal handlers
  4345       // Tell libjsig jvm finishes setting signal handlers
  4381       (*end_signal_setting)();
  4346       (*end_signal_setting)();
  4465     st->print("SIG_IGN");
  4430     st->print("SIG_IGN");
  4466   } else {
  4431   } else {
  4467     st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
  4432     st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
  4468   }
  4433   }
  4469 
  4434 
  4470   st->print(", sa_mask[0]=" PTR32_FORMAT, *(uint32_t*)&sa.sa_mask);
  4435   st->print(", sa_mask[0]=");
       
  4436   os::Posix::print_signal_set_short(st, &sa.sa_mask);
  4471 
  4437 
  4472   address rh = VMError::get_resetted_sighandler(sig);
  4438   address rh = VMError::get_resetted_sighandler(sig);
  4473   // May be, handler was resetted by VMError?
  4439   // May be, handler was resetted by VMError?
  4474   if(rh != NULL) {
  4440   if(rh != NULL) {
  4475     handler = rh;
  4441     handler = rh;
  4476     sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK;
  4442     sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK;
  4477   }
  4443   }
  4478 
  4444 
  4479   st->print(", sa_flags="   PTR32_FORMAT, sa.sa_flags);
  4445   st->print(", sa_flags=");
       
  4446   os::Posix::print_sa_flags(st, sa.sa_flags);
  4480 
  4447 
  4481   // Check: is it our handler?
  4448   // Check: is it our handler?
  4482   if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) ||
  4449   if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) ||
  4483      handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
  4450      handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
  4484     // It is our signal handler
  4451     // It is our signal handler
  4512   DO_SIGNAL_CHECK(SIGILL);
  4479   DO_SIGNAL_CHECK(SIGILL);
  4513   DO_SIGNAL_CHECK(SIGFPE);
  4480   DO_SIGNAL_CHECK(SIGFPE);
  4514   DO_SIGNAL_CHECK(SIGBUS);
  4481   DO_SIGNAL_CHECK(SIGBUS);
  4515   DO_SIGNAL_CHECK(SIGPIPE);
  4482   DO_SIGNAL_CHECK(SIGPIPE);
  4516   DO_SIGNAL_CHECK(SIGXFSZ);
  4483   DO_SIGNAL_CHECK(SIGXFSZ);
  4517 
  4484 #if defined(PPC64)
       
  4485   DO_SIGNAL_CHECK(SIGTRAP);
       
  4486 #endif
  4518 
  4487 
  4519   // ReduceSignalUsage allows the user to override these handlers
  4488   // ReduceSignalUsage allows the user to override these handlers
  4520   // see comments at the very top and jvm_solaris.h
  4489   // see comments at the very top and jvm_solaris.h
  4521   if (!ReduceSignalUsage) {
  4490   if (!ReduceSignalUsage) {
  4522     DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
  4491     DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
  4834 
  4803 
  4835     // note: perfMemory_exit_helper atexit function may be removed in
  4804     // note: perfMemory_exit_helper atexit function may be removed in
  4836     // the future if the appropriate cleanup code can be added to the
  4805     // the future if the appropriate cleanup code can be added to the
  4837     // VM_Exit VMOperation's doit method.
  4806     // VM_Exit VMOperation's doit method.
  4838     if (atexit(perfMemory_exit_helper) != 0) {
  4807     if (atexit(perfMemory_exit_helper) != 0) {
  4839       warning("os::init2 atexit(perfMemory_exit_helper) failed");
  4808       warning("os::init_2 atexit(perfMemory_exit_helper) failed");
  4840     }
  4809     }
  4841   }
  4810   }
  4842 
  4811 
  4843   // initialize thread priority policy
  4812   // initialize thread priority policy
  4844   prio_init();
  4813   prio_init();
  4845 
  4814 
  4846   return JNI_OK;
  4815   return JNI_OK;
  4847 }
  4816 }
  4848 
  4817 
  4849 // this is called at the end of vm_initialization
  4818 // this is called at the end of vm_initialization
  4850 void os::init_3(void)
  4819 void os::init_3(void) {
  4851 {
       
  4852 #ifdef JAVASE_EMBEDDED
  4820 #ifdef JAVASE_EMBEDDED
  4853   // Start the MemNotifyThread
  4821   // Start the MemNotifyThread
  4854   if (LowMemoryProtection) {
  4822   if (LowMemoryProtection) {
  4855     MemNotifyThread::start();
  4823     MemNotifyThread::start();
  4856   }
  4824   }