8241395: Factor out platform independent code for os::xxx_memory_special()

Reviewed-by: mbaesken, mdoerr, lucy
This commit is contained in:
Thomas Stuefe 2020-03-24 18:41:07 +01:00
parent b5897fe4ed
commit 40173c5042
7 changed files with 50 additions and 41 deletions

View File

@ -2528,17 +2528,13 @@ void os::large_page_init() {
return; // Nothing to do. See query_multipage_support and friends.
}
char* os::reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) {
// reserve_memory_special() is used to allocate large paged memory. On AIX, we implement
// 64k paged memory reservation using the normal memory allocation paths (os::reserve_memory()),
// so this is not needed.
assert(false, "should not be called on AIX");
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) {
fatal("os::reserve_memory_special should not be called on AIX.");
return NULL;
}
bool os::release_memory_special(char* base, size_t bytes) {
// Detaching the SHM segment will also delete it, see reserve_memory_special().
Unimplemented();
bool os::pd_release_memory_special(char* base, size_t bytes) {
fatal("os::release_memory_special should not be called on AIX.");
return false;
}

View File

@ -2133,12 +2133,12 @@ void os::large_page_init() {
}
char* os::reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) {
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) {
fatal("os::reserve_memory_special should not be called on BSD.");
return NULL;
}
bool os::release_memory_special(char* base, size_t bytes) {
bool os::pd_release_memory_special(char* base, size_t bytes) {
fatal("os::release_memory_special should not be called on BSD.");
return false;
}

View File

@ -4145,8 +4145,8 @@ char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes,
}
}
char* os::reserve_memory_special(size_t bytes, size_t alignment,
char* req_addr, bool exec) {
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment,
char* req_addr, bool exec) {
assert(UseLargePages, "only for large pages");
char* addr;
@ -4161,9 +4161,6 @@ char* os::reserve_memory_special(size_t bytes, size_t alignment,
if (UseNUMAInterleaving) {
numa_make_global(addr, bytes);
}
// The memory is committed
MemTracker::record_virtual_memory_reserve_and_commit((address)addr, bytes, CALLER_PC);
}
return addr;
@ -4178,22 +4175,7 @@ bool os::Linux::release_memory_special_huge_tlbfs(char* base, size_t bytes) {
return pd_release_memory(base, bytes);
}
bool os::release_memory_special(char* base, size_t bytes) {
bool res;
if (MemTracker::tracking_level() > NMT_minimal) {
Tracker tkr(Tracker::release);
res = os::Linux::release_memory_special_impl(base, bytes);
if (res) {
tkr.record((address)base, bytes);
}
} else {
res = os::Linux::release_memory_special_impl(base, bytes);
}
return res;
}
bool os::Linux::release_memory_special_impl(char* base, size_t bytes) {
bool os::pd_release_memory_special(char* base, size_t bytes) {
assert(UseLargePages, "only for large pages");
bool res;

View File

@ -2606,12 +2606,12 @@ bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes, size_t align) {
return true;
}
char* os::reserve_memory_special(size_t size, size_t alignment, char* addr, bool exec) {
char* os::pd_reserve_memory_special(size_t size, size_t alignment, char* addr, bool exec) {
fatal("os::reserve_memory_special should not be called on Solaris.");
return NULL;
}
bool os::release_memory_special(char* base, size_t bytes) {
bool os::pd_release_memory_special(char* base, size_t bytes) {
fatal("os::release_memory_special should not be called on Solaris.");
return false;
}

View File

@ -3176,8 +3176,8 @@ bool os::can_execute_large_page_memory() {
return true;
}
char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr,
bool exec) {
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, char* addr,
bool exec) {
assert(UseLargePages, "only for large pages");
if (!is_aligned(bytes, os::large_page_size()) || alignment > os::large_page_size()) {
@ -3214,17 +3214,14 @@ char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr,
// normal policy just allocate it all at once
DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
char * res = (char *)VirtualAlloc(addr, bytes, flag, prot);
if (res != NULL) {
MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, CALLER_PC);
}
return res;
}
}
bool os::release_memory_special(char* base, size_t bytes) {
bool os::pd_release_memory_special(char* base, size_t bytes) {
assert(base != NULL, "Sanity check");
return release_memory(base, bytes);
return pd_release_memory(base, bytes);
}
void os::print_statistics() {

View File

@ -1748,6 +1748,7 @@ bool os::uncommit_memory(char* addr, size_t bytes) {
bool os::release_memory(char* addr, size_t bytes) {
bool res;
if (MemTracker::tracking_level() > NMT_minimal) {
// Note: Tracker contains a ThreadCritical.
Tracker tkr(Tracker::release);
res = pd_release_memory(addr, bytes);
if (res) {
@ -1804,6 +1805,35 @@ void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
pd_realign_memory(addr, bytes, alignment_hint);
}
char* os::reserve_memory_special(size_t size, size_t alignment,
char* addr, bool executable) {
assert(is_aligned(addr, alignment), "Unaligned request address");
char* result = pd_reserve_memory_special(size, alignment, addr, executable);
if (result != NULL) {
// The memory is committed
MemTracker::record_virtual_memory_reserve_and_commit((address)result, size, CALLER_PC);
}
return result;
}
bool os::release_memory_special(char* addr, size_t bytes) {
bool res;
if (MemTracker::tracking_level() > NMT_minimal) {
// Note: Tracker contains a ThreadCritical.
Tracker tkr(Tracker::release);
res = pd_release_memory_special(addr, bytes);
if (res) {
tkr.record((address)addr, bytes);
}
} else {
res = pd_release_memory_special(addr, bytes);
}
return res;
}
#ifndef _WINDOWS
/* try to switch state from state "from" to state "to"
* returns the state set after the method is complete

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -144,6 +144,10 @@ class os: AllStatic {
static void pd_free_memory(char *addr, size_t bytes, size_t alignment_hint);
static void pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint);
static char* pd_reserve_memory_special(size_t size, size_t alignment,
char* addr, bool executable);
static bool pd_release_memory_special(char* addr, size_t bytes);
static size_t page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned);
// Get summary strings for system information in buffer provided