src/os/windows/vm/os_windows.cpp

Print this page

        

@@ -3766,11 +3766,10 @@
   jio_snprintf(ebuf, ebuflen,
                "os::win32::load_windows_dll() cannot load %s from system directories.", name);
   return NULL;
 }
 
-#define MAX_EXIT_HANDLES PRODUCT_ONLY(32)   NOT_PRODUCT(128)
 #define EXIT_TIMEOUT     PRODUCT_ONLY(1000) NOT_PRODUCT(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;

@@ -3785,11 +3784,11 @@
   if (os::win32::has_exit_bug()) {
     // The array holds handles of the threads that have started exiting by calling
     // _endthreadex().
     // Should be large enough to avoid blocking the exiting thread due to lack of
     // a free slot.
-    static HANDLE handles[MAX_EXIT_HANDLES];
+    static HANDLE handles[MAXIMUM_WAIT_OBJECTS];
     static int handle_count = 0;
 
     static INIT_ONCE init_once_crit_sect = INIT_ONCE_STATIC_INIT;
     static CRITICAL_SECTION crit_sect;
     int i, j;

@@ -3807,36 +3806,38 @@
         for (i = 0, j = 0; i < handle_count; ++i) {
           res = WaitForSingleObject(handles[i], 0 /* don't wait */);
           if (res == WAIT_TIMEOUT) {
             handles[j++] = handles[i];
           } else {
-            if (res != WAIT_OBJECT_0) {
-              warning("WaitForSingleObject failed in %s: %d\n", __FILE__, __LINE__);
-              // Don't keep the handle, if we failed waiting for it.
+            if (res == WAIT_FAILED) {
+              warning("WaitForSingleObject failed (%u) in %s: %d\n",
+                      GetLastError(), __FILE__, __LINE__);
             }
+            // Don't keep the handle, if we failed waiting for it.
             CloseHandle(handles[i]);
           }
         }
 
         // 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) {
+        if ((handle_count = j) == MAXIMUM_WAIT_OBJECTS) {
           // Raise the priority of the oldest exiting thread to increase its chances
           // to complete sooner.
           SetThreadPriority(handles[0], THREAD_PRIORITY_ABOVE_NORMAL);
-          res = WaitForMultipleObjects(MAX_EXIT_HANDLES, handles, FALSE, EXIT_TIMEOUT);
-          if (res >= WAIT_OBJECT_0 && res < (WAIT_OBJECT_0 + MAX_EXIT_HANDLES)) {
+          res = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, handles, FALSE, EXIT_TIMEOUT);
+          if (res >= WAIT_OBJECT_0 && res < (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS)) {
             i = (res - WAIT_OBJECT_0);
-            handle_count = MAX_EXIT_HANDLES - 1;
+            handle_count = MAXIMUM_WAIT_OBJECTS - 1;
             for (; i < handle_count; ++i) {
               handles[i] = handles[i + 1];
             }
           } else {
-            warning("WaitForMultipleObjects %s in %s: %d\n",
-                    (res == WAIT_FAILED ? "failed" : "timed out"), __FILE__, __LINE__);
+            warning("WaitForMultipleObjects %s (%u) in %s: %d\n",
+                    (res == WAIT_FAILED ? "failed" : "timed out"),
+                    GetLastError(), __FILE__, __LINE__);
             // Don't keep handles, if we failed waiting for them.
-            for (i = 0; i < MAX_EXIT_HANDLES; ++i) {
+            for (i = 0; i < MAXIMUM_WAIT_OBJECTS; ++i) {
               CloseHandle(handles[i]);
             }
             handle_count = 0;
           }
         }

@@ -3844,11 +3845,12 @@
         // Store a duplicate of the current thread handle in the array of handles.
         hproc = GetCurrentProcess();
         hthr = GetCurrentThread();
         if (!DuplicateHandle(hproc, hthr, hproc, &handles[handle_count],
                              0, FALSE, DUPLICATE_SAME_ACCESS)) {
-          warning("DuplicateHandle failed in %s: %d\n", __FILE__, __LINE__);
+          warning("DuplicateHandle failed (%u) in %s: %d\n",
+                  GetLastError(), __FILE__, __LINE__);
         } else {
           ++handle_count;
         }
 
         // The current exiting thread has stored its handle in the array, and now

@@ -3867,13 +3869,14 @@
           SetThreadPriority(hthr, THREAD_PRIORITY_ABOVE_NORMAL);
           for (i = 0; i < handle_count; ++i) {
             SetThreadPriority(handles[i], THREAD_PRIORITY_ABOVE_NORMAL);
           }
           res = WaitForMultipleObjects(handle_count, handles, TRUE, EXIT_TIMEOUT);
-          if (res < WAIT_OBJECT_0 || res >= (WAIT_OBJECT_0 + MAX_EXIT_HANDLES)) {
-            warning("WaitForMultipleObjects %s in %s: %d\n",
-                    (res == WAIT_FAILED ? "failed" : "timed out"), __FILE__, __LINE__);
+          if (res == WAIT_FAILED || res == WAIT_TIMEOUT) {
+            warning("WaitForMultipleObjects %s (%u) in %s: %d\n",
+                    (res == WAIT_FAILED ? "failed" : "timed out"),
+                    GetLastError(), __FILE__, __LINE__);
           }
           for (i = 0; i < handle_count; ++i) {
             CloseHandle(handles[i]);
           }
           handle_count = 0;

@@ -3907,11 +3910,10 @@
 
   // Should not reach here
   return exit_code;
 }
 
-#undef MAX_EXIT_HANDLES
 #undef EXIT_TIMEOUT
 
 void os::win32::setmode_streams() {
   _setmode(_fileno(stdin), _O_BINARY);
   _setmode(_fileno(stdout), _O_BINARY);