src/os/windows/vm/os_windows.cpp

Print this page

        

@@ -3779,12 +3779,12 @@
   jio_snprintf(ebuf, ebuflen,
                "os::win32::load_windows_dll() cannot load %s from system directories.", name);
   return NULL;
 }
 
-#define MAX_EXIT_HANDLES    16
-#define EXIT_TIMEOUT      1000 /* 1 sec */
+#define MAX_EXIT_HANDLES NOT_DEBUG(32)   DEBUG_ONLY(128)
+#define EXIT_TIMEOUT     NOT_DEBUG(1000) DEBUG_ONLY(4000) /*1 sec in product, 4 sec in debug*/
 
 static BOOL CALLBACK init_crit_sect_call(PINIT_ONCE, PVOID pcrit_sect, PVOID*) {
   InitializeCriticalSection((CRITICAL_SECTION*)pcrit_sect);
   return TRUE;
 }

@@ -3831,10 +3831,13 @@
         }
 
         // If there's no free slot in the array of the kept handles, we'll have to
         // wait until at least one thread completes exiting.
         if ((handle_count = j) == MAX_EXIT_HANDLES) {
+          // Rise the priority of the oldest exiting thread to increase its chances
+          // to be closed soon.
+          SetThreadPriority(handles[0], THREAD_PRIORITY_HIGHEST);
           res = WaitForMultipleObjects(MAX_EXIT_HANDLES, handles, FALSE, EXIT_TIMEOUT);
           if (res >= WAIT_OBJECT_0 && res < (WAIT_OBJECT_0 + MAX_EXIT_HANDLES)) {
             i = (res - WAIT_OBJECT_0);
             handle_count = MAX_EXIT_HANDLES - 1;
             for (; i < handle_count; ++i) {

@@ -3865,10 +3868,13 @@
 
       } else { // what != EPT_THREAD
         if (handle_count > 0) {
           // Before ending the process, make sure all the threads that had called
           // _endthreadex() completed.
+          for (i = 0; i < handle_count; ++i) {
+            SetThreadPriority(handles[i], THREAD_PRIORITY_HIGHEST);
+          }
           res = WaitForMultipleObjects(handle_count, handles, TRUE, EXIT_TIMEOUT);
           if (res == WAIT_FAILED) {
             warning("WaitForMultipleObjects failed in %s: %d\n", __FILE__, __LINE__);
           }
           for (i = 0; i < handle_count; ++i) {