hotspot/src/os/windows/vm/os_windows.cpp
changeset 27873 60cce297ef8e
parent 27474 2b061fd571eb
child 27880 afb974a04396
equal deleted inserted replaced
27676:08763f9ed22c 27873:60cce297ef8e
  3779   jio_snprintf(ebuf, ebuflen,
  3779   jio_snprintf(ebuf, ebuflen,
  3780                "os::win32::load_windows_dll() cannot load %s from system directories.", name);
  3780                "os::win32::load_windows_dll() cannot load %s from system directories.", name);
  3781   return NULL;
  3781   return NULL;
  3782 }
  3782 }
  3783 
  3783 
  3784 #define MAX_EXIT_HANDLES    16
  3784 #define MAX_EXIT_HANDLES PRODUCT_ONLY(32)   NOT_PRODUCT(128)
  3785 #define EXIT_TIMEOUT      1000 /* 1 sec */
  3785 #define EXIT_TIMEOUT     PRODUCT_ONLY(1000) NOT_PRODUCT(4000) /* 1 sec in product, 4 sec in debug */
  3786 
  3786 
  3787 static BOOL CALLBACK init_crit_sect_call(PINIT_ONCE, PVOID pcrit_sect, PVOID*) {
  3787 static BOOL CALLBACK init_crit_sect_call(PINIT_ONCE, PVOID pcrit_sect, PVOID*) {
  3788   InitializeCriticalSection((CRITICAL_SECTION*)pcrit_sect);
  3788   InitializeCriticalSection((CRITICAL_SECTION*)pcrit_sect);
  3789   return TRUE;
  3789   return TRUE;
  3790 }
  3790 }
  3831         }
  3831         }
  3832 
  3832 
  3833         // If there's no free slot in the array of the kept handles, we'll have to
  3833         // If there's no free slot in the array of the kept handles, we'll have to
  3834         // wait until at least one thread completes exiting.
  3834         // wait until at least one thread completes exiting.
  3835         if ((handle_count = j) == MAX_EXIT_HANDLES) {
  3835         if ((handle_count = j) == MAX_EXIT_HANDLES) {
       
  3836           // Raise the priority of the oldest exiting thread to increase its chances
       
  3837           // to complete sooner.
       
  3838           SetThreadPriority(handles[0], THREAD_PRIORITY_ABOVE_NORMAL);
  3836           res = WaitForMultipleObjects(MAX_EXIT_HANDLES, handles, FALSE, EXIT_TIMEOUT);
  3839           res = WaitForMultipleObjects(MAX_EXIT_HANDLES, handles, FALSE, EXIT_TIMEOUT);
  3837           if (res >= WAIT_OBJECT_0 && res < (WAIT_OBJECT_0 + MAX_EXIT_HANDLES)) {
  3840           if (res >= WAIT_OBJECT_0 && res < (WAIT_OBJECT_0 + MAX_EXIT_HANDLES)) {
  3838             i = (res - WAIT_OBJECT_0);
  3841             i = (res - WAIT_OBJECT_0);
  3839             handle_count = MAX_EXIT_HANDLES - 1;
  3842             handle_count = MAX_EXIT_HANDLES - 1;
  3840             for (; i < handle_count; ++i) {
  3843             for (; i < handle_count; ++i) {
  3841               handles[i] = handles[i + 1];
  3844               handles[i] = handles[i + 1];
  3842             }
  3845             }
  3843           } else {
  3846           } else {
  3844             warning("WaitForMultipleObjects failed in %s: %d\n", __FILE__, __LINE__);
  3847             warning("WaitForMultipleObjects %s in %s: %d\n",
       
  3848                     (res == WAIT_FAILED ? "failed" : "timed out"), __FILE__, __LINE__);
  3845             // Don't keep handles, if we failed waiting for them.
  3849             // Don't keep handles, if we failed waiting for them.
  3846             for (i = 0; i < MAX_EXIT_HANDLES; ++i) {
  3850             for (i = 0; i < MAX_EXIT_HANDLES; ++i) {
  3847               CloseHandle(handles[i]);
  3851               CloseHandle(handles[i]);
  3848             }
  3852             }
  3849             handle_count = 0;
  3853             handle_count = 0;
  3865 
  3869 
  3866       } else { // what != EPT_THREAD
  3870       } else { // what != EPT_THREAD
  3867         if (handle_count > 0) {
  3871         if (handle_count > 0) {
  3868           // Before ending the process, make sure all the threads that had called
  3872           // Before ending the process, make sure all the threads that had called
  3869           // _endthreadex() completed.
  3873           // _endthreadex() completed.
       
  3874 
       
  3875           // Set the priority level of the current thread to the same value as
       
  3876           // the priority level of exiting threads.
       
  3877           // This is to ensure it will be given a fair chance to execute if
       
  3878           // the timeout expires.
       
  3879           hthr = GetCurrentThread();
       
  3880           SetThreadPriority(hthr, THREAD_PRIORITY_ABOVE_NORMAL);
       
  3881           for (i = 0; i < handle_count; ++i) {
       
  3882             SetThreadPriority(handles[i], THREAD_PRIORITY_ABOVE_NORMAL);
       
  3883           }
  3870           res = WaitForMultipleObjects(handle_count, handles, TRUE, EXIT_TIMEOUT);
  3884           res = WaitForMultipleObjects(handle_count, handles, TRUE, EXIT_TIMEOUT);
  3871           if (res == WAIT_FAILED) {
  3885           if (res < WAIT_OBJECT_0 || res >= (WAIT_OBJECT_0 + MAX_EXIT_HANDLES)) {
  3872             warning("WaitForMultipleObjects failed in %s: %d\n", __FILE__, __LINE__);
  3886             warning("WaitForMultipleObjects %s in %s: %d\n",
       
  3887                     (res == WAIT_FAILED ? "failed" : "timed out"), __FILE__, __LINE__);
  3873           }
  3888           }
  3874           for (i = 0; i < handle_count; ++i) {
  3889           for (i = 0; i < handle_count; ++i) {
  3875             CloseHandle(handles[i]);
  3890             CloseHandle(handles[i]);
  3876           }
  3891           }
  3877           handle_count = 0;
  3892           handle_count = 0;