< prev index next >

src/hotspot/os/bsd/os_bsd.cpp

Print this page




1813 
1814   return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
1815 }
1816 
1817 void os::signal_raise(int signal_number) {
1818   ::raise(signal_number);
1819 }
1820 
1821 // The following code is moved from os.cpp for making this
1822 // code platform specific, which it is by its very nature.
1823 
1824 // Will be modified when max signal is changed to be dynamic
1825 int os::sigexitnum_pd() {
1826   return NSIG;
1827 }
1828 
1829 // a counter for each possible signal value
1830 static volatile jint pending_signals[NSIG+1] = { 0 };
1831 static Semaphore* sig_sem = NULL;
1832 
1833 void os::signal_init_pd() {
1834   // Initialize signal structures
1835   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
1836 
1837   // Initialize signal semaphore
1838   sig_sem = new Semaphore();
1839 }
1840 
1841 void os::signal_notify(int sig) {
1842   if (sig_sem != NULL) {
1843     Atomic::inc(&pending_signals[sig]);
1844     sig_sem->signal();
1845   } else {
1846     // Signal thread is not created with ReduceSignalUsage and signal_init_pd
1847     // initialization isn't called.
1848     assert(ReduceSignalUsage, "signal semaphore should be created");
1849   }
1850 }
1851 
1852 static int check_pending_signals() {
1853   Atomic::store(0, &sigint_count);
1854   for (;;) {
1855     for (int i = 0; i < NSIG + 1; i++) {
1856       jint n = pending_signals[i];
1857       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
1858         return i;
1859       }
1860     }
1861     JavaThread *thread = JavaThread::current();
1862     ThreadBlockInVM tbivm(thread);
1863 
1864     bool threadIsSuspended;
1865     do {
1866       thread->set_suspend_equivalent();


2756 // the VM performs its own checks.  Naturally, the user code would be making
2757 // a serious error if it tried to handle an exception (such as a null check
2758 // or breakpoint) that the VM was generating for its own correct operation.
2759 //
2760 // This routine may recognize any of the following kinds of signals:
2761 //    SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
2762 // It should be consulted by handlers for any of those signals.
2763 //
2764 // The caller of this routine must pass in the three arguments supplied
2765 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
2766 // field of the structure passed to sigaction().  This routine assumes that
2767 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
2768 //
2769 // Note that the VM will print warnings if it detects conflicting signal
2770 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
2771 //
2772 extern "C" JNIEXPORT int JVM_handle_bsd_signal(int signo, siginfo_t* siginfo,
2773                                                void* ucontext,
2774                                                int abort_if_unrecognized);
2775 
2776 void signalHandler(int sig, siginfo_t* info, void* uc) {
2777   assert(info != NULL && uc != NULL, "it must be old kernel");
2778   int orig_errno = errno;  // Preserve errno value over signal handler.
2779   JVM_handle_bsd_signal(sig, info, uc, true);
2780   errno = orig_errno;
2781 }
2782 
2783 
2784 // This boolean allows users to forward their own non-matching signals
2785 // to JVM_handle_bsd_signal, harmlessly.
2786 bool os::Bsd::signal_handlers_are_installed = false;
2787 
2788 // For signal-chaining
2789 struct sigaction sigact[NSIG];
2790 uint32_t sigs = 0;
2791 #if (32 < NSIG-1)
2792 #error "Not all signals can be encoded in sigs. Adapt its type!"
2793 #endif
2794 bool os::Bsd::libjsig_is_loaded = false;
2795 typedef struct sigaction *(*get_signal_t)(int);
2796 get_signal_t os::Bsd::get_signal_action = NULL;


3284 // To install functions for atexit system call
3285 extern "C" {
3286   static void perfMemory_exit_helper() {
3287     perfMemory_exit();
3288   }
3289 }
3290 
3291 // this is called _after_ the global arguments have been parsed
3292 jint os::init_2(void) {
3293 
3294   os::Posix::init_2();
3295 
3296   // initialize suspend/resume support - must do this before signal_sets_init()
3297   if (SR_initialize() != 0) {
3298     perror("SR_initialize failed");
3299     return JNI_ERR;
3300   }
3301 
3302   Bsd::signal_sets_init();
3303   Bsd::install_signal_handlers();




3304 
3305   // Check and sets minimum stack sizes against command line options
3306   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
3307     return JNI_ERR;
3308   }
3309 
3310   if (MaxFDLimit) {
3311     // set the number of file descriptors to max. print out error
3312     // if getrlimit/setrlimit fails but continue regardless.
3313     struct rlimit nbr_files;
3314     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3315     if (status != 0) {
3316       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3317     } else {
3318       nbr_files.rlim_cur = nbr_files.rlim_max;
3319 
3320 #ifdef __APPLE__
3321       // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
3322       // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
3323       // be used instead




1813 
1814   return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
1815 }
1816 
1817 void os::signal_raise(int signal_number) {
1818   ::raise(signal_number);
1819 }
1820 
1821 // The following code is moved from os.cpp for making this
1822 // code platform specific, which it is by its very nature.
1823 
1824 // Will be modified when max signal is changed to be dynamic
1825 int os::sigexitnum_pd() {
1826   return NSIG;
1827 }
1828 
1829 // a counter for each possible signal value
1830 static volatile jint pending_signals[NSIG+1] = { 0 };
1831 static Semaphore* sig_sem = NULL;
1832 
1833 static void jdk_misc_signal_init() {
1834   // Initialize signal structures
1835   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
1836 
1837   // Initialize signal semaphore
1838   sig_sem = new Semaphore();
1839 }
1840 
1841 void os::signal_notify(int sig) {
1842   if (sig_sem != NULL) {
1843     Atomic::inc(&pending_signals[sig]);
1844     sig_sem->signal();
1845   } else {
1846     // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
1847     // initialization isn't called.
1848     assert(ReduceSignalUsage, "signal semaphore should be created");
1849   }
1850 }
1851 
1852 static int check_pending_signals() {
1853   Atomic::store(0, &sigint_count);
1854   for (;;) {
1855     for (int i = 0; i < NSIG + 1; i++) {
1856       jint n = pending_signals[i];
1857       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
1858         return i;
1859       }
1860     }
1861     JavaThread *thread = JavaThread::current();
1862     ThreadBlockInVM tbivm(thread);
1863 
1864     bool threadIsSuspended;
1865     do {
1866       thread->set_suspend_equivalent();


2756 // the VM performs its own checks.  Naturally, the user code would be making
2757 // a serious error if it tried to handle an exception (such as a null check
2758 // or breakpoint) that the VM was generating for its own correct operation.
2759 //
2760 // This routine may recognize any of the following kinds of signals:
2761 //    SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
2762 // It should be consulted by handlers for any of those signals.
2763 //
2764 // The caller of this routine must pass in the three arguments supplied
2765 // to the function referred to in the "sa_sigaction" (not the "sa_handler")
2766 // field of the structure passed to sigaction().  This routine assumes that
2767 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
2768 //
2769 // Note that the VM will print warnings if it detects conflicting signal
2770 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
2771 //
2772 extern "C" JNIEXPORT int JVM_handle_bsd_signal(int signo, siginfo_t* siginfo,
2773                                                void* ucontext,
2774                                                int abort_if_unrecognized);
2775 
2776 static void signalHandler(int sig, siginfo_t* info, void* uc) {
2777   assert(info != NULL && uc != NULL, "it must be old kernel");
2778   int orig_errno = errno;  // Preserve errno value over signal handler.
2779   JVM_handle_bsd_signal(sig, info, uc, true);
2780   errno = orig_errno;
2781 }
2782 
2783 
2784 // This boolean allows users to forward their own non-matching signals
2785 // to JVM_handle_bsd_signal, harmlessly.
2786 bool os::Bsd::signal_handlers_are_installed = false;
2787 
2788 // For signal-chaining
2789 struct sigaction sigact[NSIG];
2790 uint32_t sigs = 0;
2791 #if (32 < NSIG-1)
2792 #error "Not all signals can be encoded in sigs. Adapt its type!"
2793 #endif
2794 bool os::Bsd::libjsig_is_loaded = false;
2795 typedef struct sigaction *(*get_signal_t)(int);
2796 get_signal_t os::Bsd::get_signal_action = NULL;


3284 // To install functions for atexit system call
3285 extern "C" {
3286   static void perfMemory_exit_helper() {
3287     perfMemory_exit();
3288   }
3289 }
3290 
3291 // this is called _after_ the global arguments have been parsed
3292 jint os::init_2(void) {
3293 
3294   os::Posix::init_2();
3295 
3296   // initialize suspend/resume support - must do this before signal_sets_init()
3297   if (SR_initialize() != 0) {
3298     perror("SR_initialize failed");
3299     return JNI_ERR;
3300   }
3301 
3302   Bsd::signal_sets_init();
3303   Bsd::install_signal_handlers();
3304   // Initialize data for jdk.internal.misc.Signal
3305   if (!ReduceSignalUsage) {
3306     jdk_misc_signal_init();
3307   }
3308 
3309   // Check and sets minimum stack sizes against command line options
3310   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
3311     return JNI_ERR;
3312   }
3313 
3314   if (MaxFDLimit) {
3315     // set the number of file descriptors to max. print out error
3316     // if getrlimit/setrlimit fails but continue regardless.
3317     struct rlimit nbr_files;
3318     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3319     if (status != 0) {
3320       log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
3321     } else {
3322       nbr_files.rlim_cur = nbr_files.rlim_max;
3323 
3324 #ifdef __APPLE__
3325       // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
3326       // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
3327       // be used instead


< prev index next >