Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit

Permalink
8256287: [windows] add loop fuse to map_or_reserve_memory_aligned
Browse files Browse the repository at this point in the history
Reviewed-by: luhenry, iklam, minqi
  • Loading branch information
tstuefe committed Nov 16, 2020
1 parent 6e35bcb commit 0357db3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3238,28 +3238,31 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi
assert(extra_size >= size, "overflow, size is too large to allow alignment");

char* aligned_base = NULL;
static const int max_attempts = 20;

do {
char* extra_base = file_desc != -1 ?
os::map_memory_to_file(extra_size, file_desc) :
os::reserve_memory(extra_size);
for (int attempt = 0; attempt < max_attempts && aligned_base == NULL; attempt ++) {
char* extra_base = file_desc != -1 ? os::map_memory_to_file(extra_size, file_desc) :
os::reserve_memory(extra_size);
if (extra_base == NULL) {
return NULL;
}
// Do manual alignment
aligned_base = align_up(extra_base, alignment);

if (file_desc != -1) {
os::unmap_memory(extra_base, extra_size);
} else {
os::release_memory(extra_base, extra_size);
bool rc = (file_desc != -1) ? os::unmap_memory(extra_base, extra_size) :
os::release_memory(extra_base, extra_size);
assert(rc, "release failed");
if (!rc) {
return NULL;
}

aligned_base = file_desc != -1 ?
os::attempt_map_memory_to_file_at(aligned_base, size, file_desc) :
os::attempt_reserve_memory_at(aligned_base, size);
// Attempt to map, into the just vacated space, the slightly smaller aligned area.
// Which may fail, hence the loop.
aligned_base = file_desc != -1 ? os::attempt_map_memory_to_file_at(aligned_base, size, file_desc) :
os::attempt_reserve_memory_at(aligned_base, size);
}

} while (aligned_base == NULL);
assert(aligned_base != NULL, "Did not manage to re-map after %d attempts?", max_attempts);

return aligned_base;
}
Expand Down

0 comments on commit 0357db3

Please sign in to comment.