< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // Must be at least Windows Vista or Server 2008 to use InitOnceExecuteOnce
  26 #define _WIN32_WINNT 0x0600
  27 
  28 // no precompiled headers

  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "code/icBuffer.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/disassembler.hpp"
  36 #include "interpreter/interpreter.hpp"
  37 #include "jvm_windows.h"
  38 #include "logging/log.hpp"
  39 #include "memory/allocation.inline.hpp"
  40 #include "memory/filemap.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "os_share_windows.hpp"
  43 #include "os_windows.inline.hpp"
  44 #include "prims/jniFastGetField.hpp"
  45 #include "prims/jvm.h"
  46 #include "prims/jvm_misc.hpp"
  47 #include "runtime/arguments.hpp"
  48 #include "runtime/atomic.hpp"
  49 #include "runtime/extendedPC.hpp"
  50 #include "runtime/globals.hpp"
  51 #include "runtime/interfaceSupport.hpp"
  52 #include "runtime/java.hpp"
  53 #include "runtime/javaCalls.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/objectMonitor.hpp"
  56 #include "runtime/orderAccess.inline.hpp"
  57 #include "runtime/osThread.hpp"
  58 #include "runtime/perfMemory.hpp"
  59 #include "runtime/sharedRuntime.hpp"
  60 #include "runtime/statSampler.hpp"
  61 #include "runtime/stubRoutines.hpp"
  62 #include "runtime/thread.inline.hpp"
  63 #include "runtime/threadCritical.hpp"
  64 #include "runtime/timer.hpp"
  65 #include "runtime/vm_version.hpp"


  83 #endif
  84 
  85 
  86 #include <windows.h>
  87 #include <sys/types.h>
  88 #include <sys/stat.h>
  89 #include <sys/timeb.h>
  90 #include <objidl.h>
  91 #include <shlobj.h>
  92 
  93 #include <malloc.h>
  94 #include <signal.h>
  95 #include <direct.h>
  96 #include <errno.h>
  97 #include <fcntl.h>
  98 #include <io.h>
  99 #include <process.h>              // For _beginthreadex(), _endthreadex()
 100 #include <imagehlp.h>             // For os::dll_address_to_function_name
 101 // for enumerating dll libraries
 102 #include <vdmdbg.h>

 103 
 104 // for timer info max values which include all bits
 105 #define ALL_64_BITS CONST64(-1)
 106 
 107 // For DLL loading/load error detection
 108 // Values of PE COFF
 109 #define IMAGE_FILE_PTR_TO_SIGNATURE 0x3c
 110 #define IMAGE_FILE_SIGNATURE_LENGTH 4
 111 
 112 static HANDLE main_process;
 113 static HANDLE main_thread;
 114 static int    main_thread_id;
 115 
 116 static FILETIME process_creation_time;
 117 static FILETIME process_exit_time;
 118 static FILETIME process_user_time;
 119 static FILETIME process_kernel_time;
 120 
 121 #ifdef _M_AMD64
 122   #define __CPU__ amd64


3639   InitializeCriticalSection((CRITICAL_SECTION*)pcrit_sect);
3640   return TRUE;
3641 }
3642 
3643 int os::win32::exit_process_or_thread(Ept what, int exit_code) {
3644   // Basic approach:
3645   //  - Each exiting thread registers its intent to exit and then does so.
3646   //  - A thread trying to terminate the process must wait for all
3647   //    threads currently exiting to complete their exit.
3648 
3649   if (os::win32::has_exit_bug()) {
3650     // The array holds handles of the threads that have started exiting by calling
3651     // _endthreadex().
3652     // Should be large enough to avoid blocking the exiting thread due to lack of
3653     // a free slot.
3654     static HANDLE handles[MAXIMUM_THREADS_TO_KEEP];
3655     static int handle_count = 0;
3656 
3657     static INIT_ONCE init_once_crit_sect = INIT_ONCE_STATIC_INIT;
3658     static CRITICAL_SECTION crit_sect;
3659     static volatile jint process_exiting = 0;
3660     int i, j;
3661     DWORD res;
3662     HANDLE hproc, hthr;
3663 
3664     // We only attempt to register threads until a process exiting
3665     // thread manages to set the process_exiting flag. Any threads
3666     // that come through here after the process_exiting flag is set
3667     // are unregistered and will be caught in the SuspendThread()
3668     // infinite loop below.
3669     bool registered = false;
3670 
3671     // The first thread that reached this point, initializes the critical section.
3672     if (!InitOnceExecuteOnce(&init_once_crit_sect, init_crit_sect_call, &crit_sect, NULL)) {
3673       warning("crit_sect initialization failed in %s: %d\n", __FILE__, __LINE__);
3674     } else if (OrderAccess::load_acquire(&process_exiting) == 0) {
3675       if (what != EPT_THREAD) {
3676         // Atomically set process_exiting before the critical section
3677         // to increase the visibility between racing threads.
3678         Atomic::cmpxchg((jint)GetCurrentThreadId(), &process_exiting, 0);
3679       }
3680       EnterCriticalSection(&crit_sect);
3681 
3682       if (what == EPT_THREAD && OrderAccess::load_acquire(&process_exiting) == 0) {
3683         // Remove from the array those handles of the threads that have completed exiting.
3684         for (i = 0, j = 0; i < handle_count; ++i) {
3685           res = WaitForSingleObject(handles[i], 0 /* don't wait */);
3686           if (res == WAIT_TIMEOUT) {
3687             handles[j++] = handles[i];
3688           } else {
3689             if (res == WAIT_FAILED) {
3690               warning("WaitForSingleObject failed (%u) in %s: %d\n",
3691                       GetLastError(), __FILE__, __LINE__);
3692             }
3693             // Don't keep the handle, if we failed waiting for it.
3694             CloseHandle(handles[i]);
3695           }
3696         }
3697 
3698         // If there's no free slot in the array of the kept handles, we'll have to




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // Must be at least Windows Vista or Server 2008 to use InitOnceExecuteOnce
  26 #define _WIN32_WINNT 0x0600
  27 
  28 // no precompiled headers
  29 #include "jvm.h"
  30 #include "classfile/classLoader.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "classfile/vmSymbols.hpp"
  33 #include "code/icBuffer.hpp"
  34 #include "code/vtableStubs.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "compiler/disassembler.hpp"
  37 #include "interpreter/interpreter.hpp"

  38 #include "logging/log.hpp"
  39 #include "memory/allocation.inline.hpp"
  40 #include "memory/filemap.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "os_share_windows.hpp"
  43 #include "os_windows.inline.hpp"
  44 #include "prims/jniFastGetField.hpp"

  45 #include "prims/jvm_misc.hpp"
  46 #include "runtime/arguments.hpp"
  47 #include "runtime/atomic.hpp"
  48 #include "runtime/extendedPC.hpp"
  49 #include "runtime/globals.hpp"
  50 #include "runtime/interfaceSupport.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/mutexLocker.hpp"
  54 #include "runtime/objectMonitor.hpp"
  55 #include "runtime/orderAccess.inline.hpp"
  56 #include "runtime/osThread.hpp"
  57 #include "runtime/perfMemory.hpp"
  58 #include "runtime/sharedRuntime.hpp"
  59 #include "runtime/statSampler.hpp"
  60 #include "runtime/stubRoutines.hpp"
  61 #include "runtime/thread.inline.hpp"
  62 #include "runtime/threadCritical.hpp"
  63 #include "runtime/timer.hpp"
  64 #include "runtime/vm_version.hpp"


  82 #endif
  83 
  84 
  85 #include <windows.h>
  86 #include <sys/types.h>
  87 #include <sys/stat.h>
  88 #include <sys/timeb.h>
  89 #include <objidl.h>
  90 #include <shlobj.h>
  91 
  92 #include <malloc.h>
  93 #include <signal.h>
  94 #include <direct.h>
  95 #include <errno.h>
  96 #include <fcntl.h>
  97 #include <io.h>
  98 #include <process.h>              // For _beginthreadex(), _endthreadex()
  99 #include <imagehlp.h>             // For os::dll_address_to_function_name
 100 // for enumerating dll libraries
 101 #include <vdmdbg.h>
 102 #include <psapi.h>
 103 
 104 // for timer info max values which include all bits
 105 #define ALL_64_BITS CONST64(-1)
 106 
 107 // For DLL loading/load error detection
 108 // Values of PE COFF
 109 #define IMAGE_FILE_PTR_TO_SIGNATURE 0x3c
 110 #define IMAGE_FILE_SIGNATURE_LENGTH 4
 111 
 112 static HANDLE main_process;
 113 static HANDLE main_thread;
 114 static int    main_thread_id;
 115 
 116 static FILETIME process_creation_time;
 117 static FILETIME process_exit_time;
 118 static FILETIME process_user_time;
 119 static FILETIME process_kernel_time;
 120 
 121 #ifdef _M_AMD64
 122   #define __CPU__ amd64


3639   InitializeCriticalSection((CRITICAL_SECTION*)pcrit_sect);
3640   return TRUE;
3641 }
3642 
3643 int os::win32::exit_process_or_thread(Ept what, int exit_code) {
3644   // Basic approach:
3645   //  - Each exiting thread registers its intent to exit and then does so.
3646   //  - A thread trying to terminate the process must wait for all
3647   //    threads currently exiting to complete their exit.
3648 
3649   if (os::win32::has_exit_bug()) {
3650     // The array holds handles of the threads that have started exiting by calling
3651     // _endthreadex().
3652     // Should be large enough to avoid blocking the exiting thread due to lack of
3653     // a free slot.
3654     static HANDLE handles[MAXIMUM_THREADS_TO_KEEP];
3655     static int handle_count = 0;
3656 
3657     static INIT_ONCE init_once_crit_sect = INIT_ONCE_STATIC_INIT;
3658     static CRITICAL_SECTION crit_sect;
3659     static volatile int process_exiting = 0;
3660     int i, j;
3661     DWORD res;
3662     HANDLE hproc, hthr;
3663 
3664     // We only attempt to register threads until a process exiting
3665     // thread manages to set the process_exiting flag. Any threads
3666     // that come through here after the process_exiting flag is set
3667     // are unregistered and will be caught in the SuspendThread()
3668     // infinite loop below.
3669     bool registered = false;
3670 
3671     // The first thread that reached this point, initializes the critical section.
3672     if (!InitOnceExecuteOnce(&init_once_crit_sect, init_crit_sect_call, &crit_sect, NULL)) {
3673       warning("crit_sect initialization failed in %s: %d\n", __FILE__, __LINE__);
3674     } else if (OrderAccess::load_acquire(&process_exiting) == 0) {
3675       if (what != EPT_THREAD) {
3676         // Atomically set process_exiting before the critical section
3677         // to increase the visibility between racing threads.
3678         Atomic::cmpxchg((int)GetCurrentThreadId(), &process_exiting, 0);
3679       }
3680       EnterCriticalSection(&crit_sect);
3681 
3682       if (what == EPT_THREAD && OrderAccess::load_acquire(&process_exiting) == 0) {
3683         // Remove from the array those handles of the threads that have completed exiting.
3684         for (i = 0, j = 0; i < handle_count; ++i) {
3685           res = WaitForSingleObject(handles[i], 0 /* don't wait */);
3686           if (res == WAIT_TIMEOUT) {
3687             handles[j++] = handles[i];
3688           } else {
3689             if (res == WAIT_FAILED) {
3690               warning("WaitForSingleObject failed (%u) in %s: %d\n",
3691                       GetLastError(), __FILE__, __LINE__);
3692             }
3693             // Don't keep the handle, if we failed waiting for it.
3694             CloseHandle(handles[i]);
3695           }
3696         }
3697 
3698         // If there's no free slot in the array of the kept handles, we'll have to


< prev index next >