8325133: Missing MEMFLAGS parameter in parts of os API

Reviewed-by: stefank, gziemski
This commit is contained in:
Johan Sjölen 2024-02-05 09:27:07 +00:00
parent df35462a4e
commit 0377f1abe1
4 changed files with 21 additions and 21 deletions
src/hotspot
os
share/runtime

@ -265,7 +265,7 @@ bool os::dir_is_empty(const char* path) {
return result;
}
static char* reserve_mmapped_memory(size_t bytes, char* requested_addr) {
static char* reserve_mmapped_memory(size_t bytes, char* requested_addr, MEMFLAGS flag) {
char * addr;
int flags = MAP_PRIVATE NOT_AIX( | MAP_NORESERVE ) | MAP_ANONYMOUS;
if (requested_addr != nullptr) {
@ -280,7 +280,7 @@ static char* reserve_mmapped_memory(size_t bytes, char* requested_addr) {
flags, -1, 0);
if (addr != MAP_FAILED) {
MemTracker::record_virtual_memory_reserve((address)addr, bytes, CALLER_PC);
MemTracker::record_virtual_memory_reserve((address)addr, bytes, CALLER_PC, flag);
return addr;
}
return nullptr;
@ -393,7 +393,7 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, bool exec) {
return chop_extra_memory(size, alignment, extra_base, extra_size);
}
char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int file_desc) {
char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int file_desc, MEMFLAGS flag) {
size_t extra_size = calculate_aligned_extra_size(size, alignment);
// For file mapping, we do not call os:map_memory_to_file(size,fd) since:
// - we later chop away parts of the mapping using os::release_memory and that could fail if the
@ -401,7 +401,7 @@ char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int file_des
// - The memory API os::reserve_memory uses is an implementation detail. It may (and usually is)
// mmap but it also may System V shared memory which cannot be uncommitted as a whole, so
// chopping off and unmapping excess bits back and front (see below) would not work.
char* extra_base = reserve_mmapped_memory(extra_size, nullptr);
char* extra_base = reserve_mmapped_memory(extra_size, nullptr, flag);
if (extra_base == nullptr) {
return nullptr;
}

@ -3344,7 +3344,7 @@ char* os::replace_existing_mapping_with_file_mapping(char* base, size_t size, in
// Multiple threads can race in this code but it's not possible to unmap small sections of
// virtual space to get requested alignment, like posix-like os's.
// Windows prevents multiple thread from remapping over each other so this loop is thread-safe.
static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int file_desc) {
static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int file_desc, MEMFLAGS flag = mtNone) {
assert(is_aligned(alignment, os::vm_allocation_granularity()),
"Alignment must be a multiple of allocation granularity (page size)");
assert(is_aligned(size, os::vm_allocation_granularity()),
@ -3357,8 +3357,8 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi
static const int max_attempts = 20;
for (int attempt = 0; attempt < max_attempts && aligned_base == nullptr; attempt ++) {
char* extra_base = file_desc != -1 ? os::map_memory_to_file(extra_size, file_desc) :
os::reserve_memory(extra_size);
char* extra_base = file_desc != -1 ? os::map_memory_to_file(extra_size, file_desc, flag) :
os::reserve_memory(extra_size, false, flag);
if (extra_base == nullptr) {
return nullptr;
}
@ -3374,8 +3374,8 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi
// 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);
aligned_base = file_desc != -1 ? os::attempt_map_memory_to_file_at(aligned_base, size, file_desc, flag) :
os::attempt_reserve_memory_at(aligned_base, size, false, flag);
}
assert(aligned_base != nullptr, "Did not manage to re-map after %d attempts?", max_attempts);
@ -3388,8 +3388,8 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, bool exec) {
return map_or_reserve_memory_aligned(size, alignment, -1 /* file_desc */);
}
char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int fd) {
return map_or_reserve_memory_aligned(size, alignment, fd);
char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int fd, MEMFLAGS flag) {
return map_or_reserve_memory_aligned(size, alignment, fd, flag);
}
char* os::pd_reserve_memory(size_t bytes, bool exec) {

@ -1816,10 +1816,10 @@ char* os::reserve_memory(size_t bytes, bool executable, MEMFLAGS flags) {
return result;
}
char* os::attempt_reserve_memory_at(char* addr, size_t bytes, bool executable) {
char* os::attempt_reserve_memory_at(char* addr, size_t bytes, bool executable, MEMFLAGS flag) {
char* result = SimulateFullAddressSpace ? nullptr : pd_attempt_reserve_memory_at(addr, bytes, executable);
if (result != nullptr) {
MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC, flag);
log_debug(os)("Reserved memory at " INTPTR_FORMAT " for " SIZE_FORMAT " bytes.", p2i(addr), bytes);
} else {
log_debug(os)("Attempt to reserve memory at " INTPTR_FORMAT " for "
@ -2130,21 +2130,21 @@ void os::pretouch_memory(void* start, void* end, size_t page_size) {
}
}
char* os::map_memory_to_file(size_t bytes, int file_desc) {
char* os::map_memory_to_file(size_t bytes, int file_desc, MEMFLAGS flag) {
// Could have called pd_reserve_memory() followed by replace_existing_mapping_with_file_mapping(),
// but AIX may use SHM in which case its more trouble to detach the segment and remap memory to the file.
// On all current implementations null is interpreted as any available address.
char* result = os::map_memory_to_file(nullptr /* addr */, bytes, file_desc);
if (result != nullptr) {
MemTracker::record_virtual_memory_reserve_and_commit(result, bytes, CALLER_PC);
MemTracker::record_virtual_memory_reserve_and_commit(result, bytes, CALLER_PC, flag);
}
return result;
}
char* os::attempt_map_memory_to_file_at(char* addr, size_t bytes, int file_desc) {
char* os::attempt_map_memory_to_file_at(char* addr, size_t bytes, int file_desc, MEMFLAGS flag) {
char* result = pd_attempt_map_memory_to_file_at(addr, bytes, file_desc);
if (result != nullptr) {
MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC);
MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC, flag);
}
return result;
}

@ -445,7 +445,7 @@ class os: AllStatic {
// Attempts to reserve the virtual memory at [addr, addr + bytes).
// Does not overwrite existing mappings.
static char* attempt_reserve_memory_at(char* addr, size_t bytes, bool executable = false);
static char* attempt_reserve_memory_at(char* addr, size_t bytes, bool executable = false, MEMFLAGS flag = mtNone);
// Given an address range [min, max), attempts to reserve memory within this area, with the given alignment.
// If randomize is true, the location will be randomized.
@ -497,10 +497,10 @@ class os: AllStatic {
static int create_file_for_heap(const char* dir);
// Map memory to the file referred by fd. This function is slightly different from map_memory()
// and is added to be used for implementation of -XX:AllocateHeapAt
static char* map_memory_to_file(size_t size, int fd);
static char* map_memory_to_file_aligned(size_t size, size_t alignment, int fd);
static char* map_memory_to_file(size_t size, int fd, MEMFLAGS flag = mtNone);
static char* map_memory_to_file_aligned(size_t size, size_t alignment, int fd, MEMFLAGS flag = mtNone);
static char* map_memory_to_file(char* base, size_t size, int fd);
static char* attempt_map_memory_to_file_at(char* base, size_t size, int fd);
static char* attempt_map_memory_to_file_at(char* base, size_t size, int fd, MEMFLAGS flag = mtNone);
// Replace existing reserved memory with file mapping
static char* replace_existing_mapping_with_file_mapping(char* base, size_t size, int fd);