diff -r 5f5c3544ccb4 src/hotspot/os/windows/os_windows.cpp --- a/src/hotspot/os/windows/os_windows.cpp Sun Aug 09 09:20:02 2020 +0200 +++ b/src/hotspot/os/windows/os_windows.cpp Tue Dec 01 13:31:25 2020 +0100 @@ -3081,8 +3081,9 @@ assert(extra_size >= size, "overflow, size is too large to allow alignment"); char* aligned_base = NULL; - - do { + static const int max_attempts = 20; + + for (int attempt = 0; attempt < max_attempts && aligned_base == NULL; attempt ++) { char* extra_base = os::reserve_memory(extra_size, NULL, alignment, file_desc); if (extra_base == NULL) { return NULL; @@ -3090,15 +3091,22 @@ // Do manual alignment aligned_base = align_up(extra_base, alignment); + bool rc = false; if (file_desc != -1) { - os::unmap_memory(extra_base, extra_size); + rc = os::unmap_memory(extra_base, extra_size); } else { - os::release_memory(extra_base, extra_size); + rc = os::release_memory(extra_base, extra_size); } + assert(rc, "release failed"); + if (!rc) { + return NULL; + } aligned_base = os::reserve_memory(size, aligned_base, 0, file_desc); - } while (aligned_base == NULL); + } + + assert(aligned_base != NULL, "Did not manage to re-map after %d attempts?", max_attempts); return aligned_base; }