8245035: Clean up os::split_reserved_memory()

Reviewed-by: coleenp, stefank
This commit is contained in:
Thomas Stuefe 2020-05-19 21:04:44 +02:00
parent d3e0c4ce9c
commit 939c0a46a7
11 changed files with 48 additions and 59 deletions

View File

@ -49,13 +49,6 @@ inline bool os::must_commit_stack_guard_pages() {
return false;
}
// On Aix, reservations are made on a page by page basis, nothing to do.
inline void os::pd_split_reserved_memory(char *base, size_t size,
size_t split, bool realloc) {
// TODO: Determine whether Sys V memory is split. If yes, we need to treat
// this the same way Windows treats its VirtualAlloc allocations.
}
// Bang the shadow pages if they need to be touched to be mapped.
inline void os::map_stack_shadow_pages(address sp) {
}

View File

@ -52,13 +52,6 @@ inline bool os::must_commit_stack_guard_pages() {
#endif
}
// On Bsd, reservations are made on a page by page basis, nothing to do.
inline void os::pd_split_reserved_memory(char *base, size_t size,
size_t split, bool realloc) {
}
// Bang the shadow pages if they need to be touched to be mapped.
inline void os::map_stack_shadow_pages(address sp) {
}

View File

@ -44,13 +44,6 @@ inline bool os::must_commit_stack_guard_pages() {
return true;
}
// On Linux, reservations are made on a page by page basis, nothing to do.
inline void os::pd_split_reserved_memory(char *base, size_t size,
size_t split, bool realloc) {
}
// Bang the shadow pages if they need to be touched to be mapped.
inline void os::map_stack_shadow_pages(address sp) {
}

View File

@ -362,6 +362,16 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) {
return aligned_base;
}
// On Posix platforms, reservations are done using mmap which can be released in parts. So splitting is a no-op.
void os::split_reserved_memory(char *base, size_t size, size_t split) {
char* const split_address = base + split;
assert(size > 0, "Sanity");
assert(size > split, "Sanity");
assert(split > 0, "Sanity");
assert(is_aligned(base, os::vm_allocation_granularity()), "Sanity");
assert(is_aligned(split_address, os::vm_allocation_granularity()), "Sanity");
}
int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
// All supported POSIX platforms provide C99 semantics.
int result = ::vsnprintf(buf, len, fmt, args);

View File

@ -49,12 +49,6 @@ inline bool os::must_commit_stack_guard_pages() {
}
// On Solaris, reservations are made on a page by page basis, nothing to do.
inline void os::pd_split_reserved_memory(char *base, size_t size,
size_t split, bool realloc) {
}
// Bang the shadow pages if they need to be touched to be mapped.
inline void os::map_stack_shadow_pages(address sp) {
}

View File

@ -3071,17 +3071,19 @@ char* os::replace_existing_mapping_with_file_mapping(char* base, size_t size, in
// On win32, one cannot release just a part of reserved memory, it's an
// all or nothing deal. When we split a reservation, we must break the
// reservation into two reservations.
void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
bool realloc) {
if (size > 0) {
release_memory(base, size);
if (realloc) {
reserve_memory(split, base);
}
if (size != split) {
reserve_memory(size - split, base + split);
}
}
void os::split_reserved_memory(char *base, size_t size, size_t split) {
char* const split_address = base + split;
assert(size > 0, "Sanity");
assert(size > split, "Sanity");
assert(split > 0, "Sanity");
assert(is_aligned(base, os::vm_allocation_granularity()), "Sanity");
assert(is_aligned(split_address, os::vm_allocation_granularity()), "Sanity");
release_memory(base, size);
reserve_memory(split, base);
reserve_memory(size - split, split_address);
}
// Multiple threads can race in this code but it's not possible to unmap small sections of

View File

@ -122,11 +122,11 @@ jint GenCollectedHeap::initialize() {
bs->initialize();
BarrierSet::set_barrier_set(bs);
ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size(), false, false);
ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size());
_young_gen = _young_gen_spec->init(young_rs, rem_set());
ReservedSpace old_rs = heap_rs.last_part(_young_gen_spec->max_size());
old_rs = old_rs.first_part(_old_gen_spec->max_size(), false, false);
old_rs = old_rs.first_part(_old_gen_spec->max_size());
_old_gen = _old_gen_spec->init(old_rs, rem_set());
clear_incremental_collection_failed();

View File

@ -226,11 +226,10 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
}
}
ReservedSpace ReservedSpace::first_part(size_t partition_size, size_t alignment,
bool split, bool realloc) {
ReservedSpace ReservedSpace::first_part(size_t partition_size, size_t alignment, bool split) {
assert(partition_size <= size(), "partition failed");
if (split) {
os::split_reserved_memory(base(), size(), partition_size, realloc);
if (split && partition_size > 0 && partition_size < size()) {
os::split_reserved_memory(base(), size(), partition_size);
}
ReservedSpace result(base(), partition_size, alignment, special(),
executable());

View File

@ -75,13 +75,16 @@ class ReservedSpace {
void release();
// Splitting
ReservedSpace first_part(size_t partition_size, size_t alignment,
bool split = false, bool realloc = true);
// This splits the space into two spaces, the first part of which will be returned.
// If split==true, the resulting two spaces can be released independently from each other.
// This may cause the original space to loose its content.
// If split==false, the resulting space will be just a hotspot-internal representation
// of a sub section of the underlying mapping.
ReservedSpace first_part(size_t partition_size, size_t alignment, bool split = false);
ReservedSpace last_part (size_t partition_size, size_t alignment);
// These simply call the above using the default alignment.
inline ReservedSpace first_part(size_t partition_size,
bool split = false, bool realloc = true);
inline ReservedSpace first_part(size_t partition_size, bool split = false);
inline ReservedSpace last_part (size_t partition_size);
// Alignment
@ -94,9 +97,9 @@ class ReservedSpace {
};
ReservedSpace
ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
ReservedSpace::first_part(size_t partition_size, bool split)
{
return first_part(partition_size, alignment(), split, realloc);
return first_part(partition_size, alignment(), split);
}
ReservedSpace ReservedSpace::last_part(size_t partition_size)

View File

@ -1697,11 +1697,6 @@ char* os::attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc) {
return result;
}
void os::split_reserved_memory(char *base, size_t size,
size_t split, bool realloc) {
pd_split_reserved_memory(base, size, split, realloc);
}
bool os::commit_memory(char* addr, size_t bytes, bool executable) {
bool res = pd_commit_memory(addr, bytes, executable);
if (res) {

View File

@ -119,8 +119,6 @@ class os: AllStatic {
size_t alignment_hint = 0);
static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr);
static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc);
static void pd_split_reserved_memory(char *base, size_t size,
size_t split, bool realloc);
static bool pd_commit_memory(char* addr, size_t bytes, bool executable);
static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
bool executable);
@ -320,8 +318,17 @@ class os: AllStatic {
size_t alignment_hint, MEMFLAGS flags);
static char* reserve_memory_aligned(size_t size, size_t alignment, int file_desc = -1);
static char* attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc = -1);
static void split_reserved_memory(char *base, size_t size,
size_t split, bool realloc);
// Split a reserved memory region [base, base+size) into two regions [base, base+split) and
// [base+split, base+size).
// This may remove the original mapping, so its content may be lost.
// Both base and split point must be aligned to allocation granularity; split point shall
// be >0 and <size.
// Splitting guarantees that the resulting two memory regions can be released independently
// from each other using os::release_memory().
static void split_reserved_memory(char *base, size_t size, size_t split);
static bool commit_memory(char* addr, size_t bytes, bool executable);
static bool commit_memory(char* addr, size_t size, size_t alignment_hint,
bool executable);