changeset 50768:1a4101ebec92

8202014: Possible to receive signal before signal semaphore created Summary: initialize jdk.internal.misc.Signal in os_init2 and rename initialization functions. Reviewed-by: dholmes, stuefe
author coleenp
date Fri, 18 May 2018 15:56:42 -0400
parents 4befb3c9c758
children 97be261ebcdd
files src/hotspot/os/aix/os_aix.cpp src/hotspot/os/aix/os_share_aix.hpp src/hotspot/os/bsd/os_bsd.cpp src/hotspot/os/bsd/os_share_bsd.hpp src/hotspot/os/linux/os_linux.cpp src/hotspot/os/linux/os_share_linux.hpp src/hotspot/os/solaris/os_solaris.cpp src/hotspot/os/windows/os_windows.cpp src/hotspot/share/runtime/os.cpp src/hotspot/share/runtime/os.hpp src/hotspot/share/runtime/thread.cpp
diffstat 11 files changed, 41 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/aix/os_aix.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/aix/os_aix.cpp	Fri May 18 15:56:42 2018 -0400
@@ -1798,7 +1798,7 @@
   }
 }
 
-void os::signal_init_pd() {
+static void jdk_misc_signal_init() {
   // Initialize signal structures
   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
 
@@ -3023,7 +3023,7 @@
 }
 
 // Renamed from 'signalHandler' to avoid collision with other shared libs.
-void javaSignalHandler(int sig, siginfo_t* info, void* uc) {
+static void javaSignalHandler(int sig, siginfo_t* info, void* uc) {
   assert(info != NULL && uc != NULL, "it must be old kernel");
 
   // Never leave program error signals blocked;
@@ -3582,6 +3582,10 @@
 
   Aix::signal_sets_init();
   Aix::install_signal_handlers();
+  // Initialize data for jdk.internal.misc.Signal
+  if (!ReduceSignalUsage) {
+    jdk_misc_signal_init();
+  }
 
   // Check and sets minimum stack sizes against command line options
   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
--- a/src/hotspot/os/aix/os_share_aix.hpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/aix/os_share_aix.hpp	Fri May 18 15:56:42 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 #define OS_AIX_VM_OS_SHARE_AIX_HPP
 
 // misc
-void signalHandler(int, siginfo_t*, ucontext_t*);
 void handle_unexpected_exception(Thread* thread, int sig, siginfo_t* info, address pc, address adjusted_pc);
 #ifndef PRODUCT
 void continue_with_dump(void);
--- a/src/hotspot/os/bsd/os_bsd.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Fri May 18 15:56:42 2018 -0400
@@ -1818,7 +1818,7 @@
 static volatile jint pending_signals[NSIG+1] = { 0 };
 static Semaphore* sig_sem = NULL;
 
-void os::signal_init_pd() {
+static void jdk_misc_signal_init() {
   // Initialize signal structures
   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
 
@@ -1831,7 +1831,7 @@
     Atomic::inc(&pending_signals[sig]);
     sig_sem->signal();
   } else {
-    // Signal thread is not created with ReduceSignalUsage and signal_init_pd
+    // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
     // initialization isn't called.
     assert(ReduceSignalUsage, "signal semaphore should be created");
   }
@@ -2761,7 +2761,7 @@
                                                void* ucontext,
                                                int abort_if_unrecognized);
 
-void signalHandler(int sig, siginfo_t* info, void* uc) {
+static void signalHandler(int sig, siginfo_t* info, void* uc) {
   assert(info != NULL && uc != NULL, "it must be old kernel");
   int orig_errno = errno;  // Preserve errno value over signal handler.
   JVM_handle_bsd_signal(sig, info, uc, true);
@@ -3289,6 +3289,10 @@
 
   Bsd::signal_sets_init();
   Bsd::install_signal_handlers();
+  // Initialize data for jdk.internal.misc.Signal
+  if (!ReduceSignalUsage) {
+    jdk_misc_signal_init();
+  }
 
   // Check and sets minimum stack sizes against command line options
   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
--- a/src/hotspot/os/bsd/os_share_bsd.hpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/bsd/os_share_bsd.hpp	Fri May 18 15:56:42 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 #define OS_BSD_VM_OS_SHARE_BSD_HPP
 
 // misc
-void signalHandler(int, siginfo_t*, ucontext_t*);
 void handle_unexpected_exception(Thread* thread, int sig, siginfo_t* info, address pc, address adjusted_pc);
 #ifndef PRODUCT
 void continue_with_dump(void);
--- a/src/hotspot/os/linux/os_linux.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/linux/os_linux.cpp	Fri May 18 15:56:42 2018 -0400
@@ -2520,7 +2520,7 @@
 static Semaphore* sig_sem = NULL;
 static PosixSemaphore sr_semaphore;
 
-void os::signal_init_pd() {
+static void jdk_misc_signal_init() {
   // Initialize signal structures
   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
 
@@ -2533,7 +2533,7 @@
     Atomic::inc(&pending_signals[sig]);
     sig_sem->signal();
   } else {
-    // Signal thread is not created with ReduceSignalUsage and signal_init_pd
+    // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
     // initialization isn't called.
     assert(ReduceSignalUsage, "signal semaphore should be created");
   }
@@ -4444,7 +4444,7 @@
                                                  void* ucontext,
                                                  int abort_if_unrecognized);
 
-void signalHandler(int sig, siginfo_t* info, void* uc) {
+static void signalHandler(int sig, siginfo_t* info, void* uc) {
   assert(info != NULL && uc != NULL, "it must be old kernel");
   int orig_errno = errno;  // Preserve errno value over signal handler.
   JVM_handle_linux_signal(sig, info, uc, true);
@@ -4992,6 +4992,10 @@
 
   Linux::signal_sets_init();
   Linux::install_signal_handlers();
+  // Initialize data for jdk.internal.misc.Signal
+  if (!ReduceSignalUsage) {
+    jdk_misc_signal_init();
+  }
 
   // Check and sets minimum stack sizes against command line options
   if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
--- a/src/hotspot/os/linux/os_share_linux.hpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/linux/os_share_linux.hpp	Fri May 18 15:56:42 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
 #define OS_LINUX_VM_OS_SHARE_LINUX_HPP
 
 // misc
-void signalHandler(int, siginfo_t*, ucontext_t*);
 void handle_unexpected_exception(Thread* thread, int sig, siginfo_t* info, address pc, address adjusted_pc);
 #ifndef PRODUCT
 void continue_with_dump(void);
--- a/src/hotspot/os/solaris/os_solaris.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Fri May 18 15:56:42 2018 -0400
@@ -2124,7 +2124,7 @@
   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
 }
 
-void os::signal_init_pd() {
+static void jdk_misc_signal_init() {
   // Initialize signal semaphore
   sig_sem = new Semaphore();
 }
@@ -2134,7 +2134,7 @@
     Atomic::inc(&pending_signals[sig]);
     sig_sem->signal();
   } else {
-    // Signal thread is not created with ReduceSignalUsage and signal_init_pd
+    // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
     // initialization isn't called.
     assert(ReduceSignalUsage, "signal semaphore should be created");
   }
@@ -4243,6 +4243,10 @@
   Solaris::signal_sets_init();
   Solaris::init_signal_mem();
   Solaris::install_signal_handlers();
+  // Initialize data for jdk.internal.misc.Signal
+  if (!ReduceSignalUsage) {
+    jdk_misc_signal_init();
+  }
 
   // initialize synchronization primitives to use either thread or
   // lwp synchronization (controlled by UseLWPSynchronization)
--- a/src/hotspot/os/windows/os_windows.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/os/windows/os_windows.cpp	Fri May 18 15:56:42 2018 -0400
@@ -1993,7 +1993,7 @@
 static volatile jint pending_signals[NSIG+1] = { 0 };
 static Semaphore* sig_sem = NULL;
 
-void os::signal_init_pd() {
+static void jdk_misc_signal_init() {
   // Initialize signal structures
   memset((void*)pending_signals, 0, sizeof(pending_signals));
 
@@ -2014,10 +2014,8 @@
   // the CTRL-BREAK thread dump mechanism is also disabled in this
   // case.  See bugs 4323062, 4345157, and related bugs.
 
-  if (!ReduceSignalUsage) {
-    // Add a CTRL-C handler
-    SetConsoleCtrlHandler(consoleHandler, TRUE);
-  }
+  // Add a CTRL-C handler
+  SetConsoleCtrlHandler(consoleHandler, TRUE);
 }
 
 void os::signal_notify(int sig) {
@@ -2025,7 +2023,7 @@
     Atomic::inc(&pending_signals[sig]);
     sig_sem->signal();
   } else {
-    // Signal thread is not created with ReduceSignalUsage and signal_init_pd
+    // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
     // initialization isn't called.
     assert(ReduceSignalUsage, "signal semaphore should be created");
   }
@@ -4132,6 +4130,11 @@
 
   SymbolEngine::recalc_search_path();
 
+  // Initialize data for jdk.internal.misc.Signal
+  if (!ReduceSignalUsage) {
+    jdk_misc_signal_init();
+  }
+
   return JNI_OK;
 }
 
--- a/src/hotspot/share/runtime/os.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/share/runtime/os.cpp	Fri May 18 15:56:42 2018 -0400
@@ -443,7 +443,7 @@
   VM_Version::init_before_ergo();
 }
 
-void os::signal_init(TRAPS) {
+void os::initialize_jdk_signal_support(TRAPS) {
   if (!ReduceSignalUsage) {
     // Setup JavaThread for processing signals
     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK);
@@ -473,8 +473,6 @@
                             thread_oop,         // ARG 1
                             CHECK);
 
-    os::signal_init_pd();
-
     { MutexLocker mu(Threads_lock);
       JavaThread* signal_thread = new JavaThread(&signal_thread_entry);
 
--- a/src/hotspot/share/runtime/os.hpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/share/runtime/os.hpp	Fri May 18 15:56:42 2018 -0400
@@ -784,8 +784,7 @@
   static struct hostent* get_host_by_name(char* name);
 
   // Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
-  static void  signal_init(TRAPS);
-  static void  signal_init_pd();
+  static void  initialize_jdk_signal_support(TRAPS);
   static void  signal_notify(int signal_number);
   static void* signal(int signal_number, void* handler);
   static void  signal_raise(int signal_number);
--- a/src/hotspot/share/runtime/thread.cpp	Fri May 18 12:45:05 2018 -0700
+++ b/src/hotspot/share/runtime/thread.cpp	Fri May 18 15:56:42 2018 -0400
@@ -3813,7 +3813,7 @@
 #endif // INCLUDE_MANAGEMENT
 
   // Signal Dispatcher needs to be started before VMInit event is posted
-  os::signal_init(CHECK_JNI_ERR);
+  os::initialize_jdk_signal_support(CHECK_JNI_ERR);
 
   // Start Attach Listener if +StartAttachListener or it can't be started lazily
   if (!DisableAttachMechanism) {