< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page




1976     break;
1977   default:
1978     break;
1979   }
1980   return FALSE;
1981 }
1982 
1983 // The following code is moved from os.cpp for making this
1984 // code platform specific, which it is by its very nature.
1985 
1986 // Return maximum OS signal used + 1 for internal use only
1987 // Used as exit signal for signal_thread
1988 int os::sigexitnum_pd() {
1989   return NSIG;
1990 }
1991 
1992 // a counter for each possible signal value, including signal_thread exit signal
1993 static volatile jint pending_signals[NSIG+1] = { 0 };
1994 static Semaphore* sig_sem = NULL;
1995 
1996 void os::signal_init_pd() {
1997   // Initialize signal structures
1998   memset((void*)pending_signals, 0, sizeof(pending_signals));
1999 
2000   // Initialize signal semaphore
2001   sig_sem = new Semaphore();
2002 
2003   // Programs embedding the VM do not want it to attempt to receive
2004   // events like CTRL_LOGOFF_EVENT, which are used to implement the
2005   // shutdown hooks mechanism introduced in 1.3.  For example, when
2006   // the VM is run as part of a Windows NT service (i.e., a servlet
2007   // engine in a web server), the correct behavior is for any console
2008   // control handler to return FALSE, not TRUE, because the OS's
2009   // "final" handler for such events allows the process to continue if
2010   // it is a service (while terminating it if it is not a service).
2011   // To make this behavior uniform and the mechanism simpler, we
2012   // completely disable the VM's usage of these console events if -Xrs
2013   // (=ReduceSignalUsage) is specified.  This means, for example, that
2014   // the CTRL-BREAK thread dump mechanism is also disabled in this
2015   // case.  See bugs 4323062, 4345157, and related bugs.
2016 
2017   if (!ReduceSignalUsage) {
2018     // Add a CTRL-C handler
2019     SetConsoleCtrlHandler(consoleHandler, TRUE);
2020   }
2021 }
2022 
2023 void os::signal_notify(int sig) {
2024   if (sig_sem != NULL) {
2025     Atomic::inc(&pending_signals[sig]);
2026     sig_sem->signal();
2027   } else {
2028     // Signal thread is not created with ReduceSignalUsage and signal_init_pd
2029     // initialization isn't called.
2030     assert(ReduceSignalUsage, "signal semaphore should be created");
2031   }
2032 }
2033 
2034 static int check_pending_signals() {
2035   while (true) {
2036     for (int i = 0; i < NSIG + 1; i++) {
2037       jint n = pending_signals[i];
2038       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2039         return i;
2040       }
2041     }
2042     JavaThread *thread = JavaThread::current();
2043 
2044     ThreadBlockInVM tbivm(thread);
2045 
2046     bool threadIsSuspended;
2047     do {
2048       thread->set_suspend_equivalent();


4114 #endif
4115 
4116   // initialize thread priority policy
4117   prio_init();
4118 
4119   if (UseNUMA && !ForceNUMA) {
4120     UseNUMA = false; // We don't fully support this yet
4121   }
4122 
4123   if (UseNUMAInterleaving) {
4124     // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
4125     bool success = numa_interleaving_init();
4126     if (!success) UseNUMAInterleaving = false;
4127   }
4128 
4129   if (initSock() != JNI_OK) {
4130     return JNI_ERR;
4131   }
4132 
4133   SymbolEngine::recalc_search_path();





4134 
4135   return JNI_OK;
4136 }
4137 
4138 // Mark the polling page as unreadable
4139 void os::make_polling_page_unreadable(void) {
4140   DWORD old_status;
4141   if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4142                       PAGE_NOACCESS, &old_status)) {
4143     fatal("Could not disable polling page");
4144   }
4145 }
4146 
4147 // Mark the polling page as readable
4148 void os::make_polling_page_readable(void) {
4149   DWORD old_status;
4150   if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4151                       PAGE_READONLY, &old_status)) {
4152     fatal("Could not enable polling page");
4153   }




1976     break;
1977   default:
1978     break;
1979   }
1980   return FALSE;
1981 }
1982 
1983 // The following code is moved from os.cpp for making this
1984 // code platform specific, which it is by its very nature.
1985 
1986 // Return maximum OS signal used + 1 for internal use only
1987 // Used as exit signal for signal_thread
1988 int os::sigexitnum_pd() {
1989   return NSIG;
1990 }
1991 
1992 // a counter for each possible signal value, including signal_thread exit signal
1993 static volatile jint pending_signals[NSIG+1] = { 0 };
1994 static Semaphore* sig_sem = NULL;
1995 
1996 static void jdk_misc_signal_init() {
1997   // Initialize signal structures
1998   memset((void*)pending_signals, 0, sizeof(pending_signals));
1999 
2000   // Initialize signal semaphore
2001   sig_sem = new Semaphore();
2002 
2003   // Programs embedding the VM do not want it to attempt to receive
2004   // events like CTRL_LOGOFF_EVENT, which are used to implement the
2005   // shutdown hooks mechanism introduced in 1.3.  For example, when
2006   // the VM is run as part of a Windows NT service (i.e., a servlet
2007   // engine in a web server), the correct behavior is for any console
2008   // control handler to return FALSE, not TRUE, because the OS's
2009   // "final" handler for such events allows the process to continue if
2010   // it is a service (while terminating it if it is not a service).
2011   // To make this behavior uniform and the mechanism simpler, we
2012   // completely disable the VM's usage of these console events if -Xrs
2013   // (=ReduceSignalUsage) is specified.  This means, for example, that
2014   // the CTRL-BREAK thread dump mechanism is also disabled in this
2015   // case.  See bugs 4323062, 4345157, and related bugs.
2016 

2017   // Add a CTRL-C handler
2018   SetConsoleCtrlHandler(consoleHandler, TRUE);

2019 }
2020 
2021 void os::signal_notify(int sig) {
2022   if (sig_sem != NULL) {
2023     Atomic::inc(&pending_signals[sig]);
2024     sig_sem->signal();
2025   } else {
2026     // Signal thread is not created with ReduceSignalUsage and jdk_misc_signal_init
2027     // initialization isn't called.
2028     assert(ReduceSignalUsage, "signal semaphore should be created");
2029   }
2030 }
2031 
2032 static int check_pending_signals() {
2033   while (true) {
2034     for (int i = 0; i < NSIG + 1; i++) {
2035       jint n = pending_signals[i];
2036       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
2037         return i;
2038       }
2039     }
2040     JavaThread *thread = JavaThread::current();
2041 
2042     ThreadBlockInVM tbivm(thread);
2043 
2044     bool threadIsSuspended;
2045     do {
2046       thread->set_suspend_equivalent();


4112 #endif
4113 
4114   // initialize thread priority policy
4115   prio_init();
4116 
4117   if (UseNUMA && !ForceNUMA) {
4118     UseNUMA = false; // We don't fully support this yet
4119   }
4120 
4121   if (UseNUMAInterleaving) {
4122     // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
4123     bool success = numa_interleaving_init();
4124     if (!success) UseNUMAInterleaving = false;
4125   }
4126 
4127   if (initSock() != JNI_OK) {
4128     return JNI_ERR;
4129   }
4130 
4131   SymbolEngine::recalc_search_path();
4132 
4133   // Initialize data for jdk.internal.misc.Signal
4134   if (!ReduceSignalUsage) {
4135     jdk_misc_signal_init();
4136   }
4137 
4138   return JNI_OK;
4139 }
4140 
4141 // Mark the polling page as unreadable
4142 void os::make_polling_page_unreadable(void) {
4143   DWORD old_status;
4144   if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4145                       PAGE_NOACCESS, &old_status)) {
4146     fatal("Could not disable polling page");
4147   }
4148 }
4149 
4150 // Mark the polling page as readable
4151 void os::make_polling_page_readable(void) {
4152   DWORD old_status;
4153   if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4154                       PAGE_READONLY, &old_status)) {
4155     fatal("Could not enable polling page");
4156   }


< prev index next >