< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




2515 
2516 void os::signal_raise(int signal_number) {
2517   ::raise(signal_number);
2518 }
2519 
2520 // The following code is moved from os.cpp for making this
2521 // code platform specific, which it is by its very nature.
2522 
2523 // Will be modified when max signal is changed to be dynamic
2524 int os::sigexitnum_pd() {
2525   return NSIG;
2526 }
2527 
2528 // a counter for each possible signal value
2529 static volatile jint pending_signals[NSIG+1] = { 0 };
2530 
2531 // Linux(POSIX) specific hand shaking semaphore.
2532 static Semaphore* sig_sem = NULL;
2533 static PosixSemaphore sr_semaphore;
2534 
2535 void os::signal_init_pd() {
2536   // Initialize signal structures
2537   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
2538 
2539   // Initialize signal semaphore
2540   sig_sem = new Semaphore();
2541 }
2542 
2543 void os::signal_notify(int sig) {
2544   if (sig_sem != NULL) {
2545     Atomic::inc(&pending_signals[sig]);
2546     sig_sem->signal();
2547   } else {
2548     // Signal thread is not created with ReduceSignalUsage and signal_init_pd
2549     // initialization isn't called.
2550     assert(ReduceSignalUsage, "signal semaphore should be created");
2551   }
2552 }
2553 
2554 static int check_pending_signals() {
2555   Atomic::store(0, &sigint_count);
2556   for (;;) {
2557     for (int i = 0; i < NSIG + 1; i++) {
2558       jint n = pending_signals[i];
2559       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2560         return i;
2561       }
2562     }
2563     JavaThread *thread = JavaThread::current();
2564     ThreadBlockInVM tbivm(thread);
2565 
2566     bool threadIsSuspended;
2567     do {
2568       thread->set_suspend_equivalent();


4435 // a serious error if it tried to handle an exception (such as a null check
4436 // or breakpoint) that the VM was generating for its own correct operation.
4437 //
4438 // This routine may recognize any of the following kinds of signals:
4439 //    SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
4440 // It should be consulted by handlers for any of those signals.
4441 //
4442 // The caller of this routine must pass in the three arguments supplied
4443 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
4444 // field of the structure passed to sigaction().  This routine assumes that
4445 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
4446 //
4447 // Note that the VM will print warnings if it detects conflicting signal
4448 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
4449 //
4450 extern "C" JNIEXPORT int JVM_handle_linux_signal(int signo,
4451                                                  siginfo_t* siginfo,
4452                                                  void* ucontext,
4453                                                  int abort_if_unrecognized);
4454 
4455 void signalHandler(int sig, siginfo_t* info, void* uc) {
4456   assert(info != NULL && uc != NULL, "it must be old kernel");
4457   int orig_errno = errno;  // Preserve errno value over signal handler.
4458   JVM_handle_linux_signal(sig, info, uc, true);
4459   errno = orig_errno;
4460 }
4461 
4462 
4463 // This boolean allows users to forward their own non-matching signals
4464 // to JVM_handle_linux_signal, harmlessly.
4465 bool os::Linux::signal_handlers_are_installed = false;
4466 
4467 // For signal-chaining
4468 struct sigaction sigact[NSIG];
4469 uint64_t sigs = 0;
4470 #if (64 < NSIG-1)
4471 #error "Not all signals can be encoded in sigs. Adapt its type!"
4472 #endif
4473 bool os::Linux::libjsig_is_loaded = false;
4474 typedef struct sigaction *(*get_signal_t)(int);
4475 get_signal_t os::Linux::get_signal_action = NULL;


4983 
4984 void os::pd_init_container_support() {
4985   OSContainer::init();
4986 }
4987 
4988 // this is called _after_ the global arguments have been parsed
4989 jint os::init_2(void) {
4990 
4991   os::Posix::init_2();
4992 
4993   Linux::fast_thread_clock_init();
4994 
4995   // initialize suspend/resume support - must do this before signal_sets_init()
4996   if (SR_initialize() != 0) {
4997     perror("SR_initialize failed");
4998     return JNI_ERR;
4999   }
5000 
5001   Linux::signal_sets_init();
5002   Linux::install_signal_handlers();




5003 
5004   // Check and sets minimum stack sizes against command line options
5005   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
5006     return JNI_ERR;
5007   }
5008 
5009   suppress_primordial_thread_resolution = Arguments::created_by_java_launcher();
5010   if (!suppress_primordial_thread_resolution) {
5011     Linux::capture_initial_stack(JavaThread::stack_size_at_create());
5012   }
5013 
5014 #if defined(IA32)
5015   workaround_expand_exec_shield_cs_limit();
5016 #endif
5017 
5018   Linux::libpthread_init();
5019   Linux::sched_getcpu_init();
5020   log_info(os)("HotSpot is running with %s, %s",
5021                Linux::glibc_version(), Linux::libpthread_version());
5022 




2515 
2516 void os::signal_raise(int signal_number) {
2517   ::raise(signal_number);
2518 }
2519 
2520 // The following code is moved from os.cpp for making this
2521 // code platform specific, which it is by its very nature.
2522 
2523 // Will be modified when max signal is changed to be dynamic
2524 int os::sigexitnum_pd() {
2525   return NSIG;
2526 }
2527 
2528 // a counter for each possible signal value
2529 static volatile jint pending_signals[NSIG+1] = { 0 };
2530 
2531 // Linux(POSIX) specific hand shaking semaphore.
2532 static Semaphore* sig_sem = NULL;
2533 static PosixSemaphore sr_semaphore;
2534 
2535 static void jdk_misc_signal_init() {
2536   // Initialize signal structures
2537   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
2538 
2539   // Initialize signal semaphore
2540   sig_sem = new Semaphore();
2541 }
2542 
2543 void os::signal_notify(int sig) {
2544   if (sig_sem != NULL) {
2545     Atomic::inc(&pending_signals[sig]);
2546     sig_sem->signal();
2547   } else {
2548     // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2549     // initialization isn't called.
2550     assert(ReduceSignalUsage, "signal semaphore should be created");
2551   }
2552 }
2553 
2554 static int check_pending_signals() {
2555   Atomic::store(0, &sigint_count);
2556   for (;;) {
2557     for (int i = 0; i < NSIG + 1; i++) {
2558       jint n = pending_signals[i];
2559       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2560         return i;
2561       }
2562     }
2563     JavaThread *thread = JavaThread::current();
2564     ThreadBlockInVM tbivm(thread);
2565 
2566     bool threadIsSuspended;
2567     do {
2568       thread->set_suspend_equivalent();


4435 // a serious error if it tried to handle an exception (such as a null check
4436 // or breakpoint) that the VM was generating for its own correct operation.
4437 //
4438 // This routine may recognize any of the following kinds of signals:
4439 //    SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
4440 // It should be consulted by handlers for any of those signals.
4441 //
4442 // The caller of this routine must pass in the three arguments supplied
4443 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
4444 // field of the structure passed to sigaction().  This routine assumes that
4445 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
4446 //
4447 // Note that the VM will print warnings if it detects conflicting signal
4448 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
4449 //
4450 extern "C" JNIEXPORT int JVM_handle_linux_signal(int signo,
4451                                                  siginfo_t* siginfo,
4452                                                  void* ucontext,
4453                                                  int abort_if_unrecognized);
4454 
4455 static void signalHandler(int sig, siginfo_t* info, void* uc) {
4456   assert(info != NULL && uc != NULL, "it must be old kernel");
4457   int orig_errno = errno;  // Preserve errno value over signal handler.
4458   JVM_handle_linux_signal(sig, info, uc, true);
4459   errno = orig_errno;
4460 }
4461 
4462 
4463 // This boolean allows users to forward their own non-matching signals
4464 // to JVM_handle_linux_signal, harmlessly.
4465 bool os::Linux::signal_handlers_are_installed = false;
4466 
4467 // For signal-chaining
4468 struct sigaction sigact[NSIG];
4469 uint64_t sigs = 0;
4470 #if (64 < NSIG-1)
4471 #error "Not all signals can be encoded in sigs. Adapt its type!"
4472 #endif
4473 bool os::Linux::libjsig_is_loaded = false;
4474 typedef struct sigaction *(*get_signal_t)(int);
4475 get_signal_t os::Linux::get_signal_action = NULL;


4983 
4984 void os::pd_init_container_support() {
4985   OSContainer::init();
4986 }
4987 
4988 // this is called _after_ the global arguments have been parsed
4989 jint os::init_2(void) {
4990 
4991   os::Posix::init_2();
4992 
4993   Linux::fast_thread_clock_init();
4994 
4995   // initialize suspend/resume support - must do this before signal_sets_init()
4996   if (SR_initialize() != 0) {
4997     perror("SR_initialize failed");
4998     return JNI_ERR;
4999   }
5000 
5001   Linux::signal_sets_init();
5002   Linux::install_signal_handlers();
5003   // Initialize data for jdk.internal.misc.Signal
5004   if (!ReduceSignalUsage) {
5005     jdk_misc_signal_init();
5006   }
5007 
5008   // Check and sets minimum stack sizes against command line options
5009   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
5010     return JNI_ERR;
5011   }
5012 
5013   suppress_primordial_thread_resolution = Arguments::created_by_java_launcher();
5014   if (!suppress_primordial_thread_resolution) {
5015     Linux::capture_initial_stack(JavaThread::stack_size_at_create());
5016   }
5017 
5018 #if defined(IA32)
5019   workaround_expand_exec_shield_cs_limit();
5020 #endif
5021 
5022   Linux::libpthread_init();
5023   Linux::sched_getcpu_init();
5024   log_info(os)("HotSpot is running with %s, %s",
5025                Linux::glibc_version(), Linux::libpthread_version());
5026 


< prev index next >