Skip to content

Commit d27cbed

Browse files
author
duke
committedJul 18, 2024
Automatic merge of jdk:master into master
2 parents 2b0d8a7 + 4a73ed4 commit d27cbed

File tree

10 files changed

+38
-20
lines changed

10 files changed

+38
-20
lines changed
 

‎src/hotspot/os/aix/os_aix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ bool os::remove_stack_guard_pages(char* addr, size_t size) {
18461846
void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
18471847
}
18481848

1849-
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
1849+
void os::pd_disclaim_memory(char *addr, size_t bytes) {
18501850
}
18511851

18521852
size_t os::pd_pretouch_memory(void* first, void* last, size_t page_size) {

‎src/hotspot/os/bsd/os_bsd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ void os::pd_commit_memory_or_exit(char* addr, size_t size,
16841684
void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
16851685
}
16861686

1687-
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
1687+
void os::pd_disclaim_memory(char *addr, size_t bytes) {
16881688
::madvise(addr, bytes, MADV_DONTNEED);
16891689
}
16901690

‎src/hotspot/os/linux/os_linux.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -3035,15 +3035,10 @@ void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
30353035
}
30363036
}
30373037

3038-
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
3039-
// This method works by doing an mmap over an existing mmaping and effectively discarding
3040-
// the existing pages. However it won't work for SHM-based large pages that cannot be
3041-
// uncommitted at all. We don't do anything in this case to avoid creating a segment with
3042-
// small pages on top of the SHM segment. This method always works for small pages, so we
3043-
// allow that in any case.
3044-
if (alignment_hint <= os::vm_page_size() || can_commit_large_page_memory()) {
3045-
commit_memory(addr, bytes, alignment_hint, !ExecMem);
3046-
}
3038+
// Hints to the OS that the memory is no longer needed and may be reclaimed by the OS when convenient.
3039+
// The memory will be re-acquired on touch without needing explicit recommitting.
3040+
void os::pd_disclaim_memory(char *addr, size_t bytes) {
3041+
::madvise(addr, bytes, MADV_DONTNEED);
30473042
}
30483043

30493044
size_t os::pd_pretouch_memory(void* first, void* last, size_t page_size) {

‎src/hotspot/os/windows/os_windows.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3893,7 +3893,7 @@ bool os::unguard_memory(char* addr, size_t bytes) {
38933893
}
38943894

38953895
void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) { }
3896-
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) { }
3896+
void os::pd_disclaim_memory(char *addr, size_t bytes) { }
38973897

38983898
size_t os::pd_pretouch_memory(void* first, void* last, size_t page_size) {
38993899
return page_size;

‎src/hotspot/share/gc/parallel/mutableNUMASpace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void MutableNUMASpace::bias_region(MemRegion mr, uint lgrp_id) {
213213
// Then we uncommit the pages in the range.
214214
// The alignment_hint argument must be less than or equal to the small page
215215
// size if not using large pages or else this function does nothing.
216-
os::free_memory((char*)aligned_region.start(), aligned_region.byte_size(), os_align);
216+
os::disclaim_memory((char*)aligned_region.start(), aligned_region.byte_size());
217217
// And make them local/first-touch biased.
218218
os::numa_make_local((char*)aligned_region.start(), aligned_region.byte_size(), checked_cast<int>(lgrp_id));
219219
}

‎src/hotspot/share/gc/parallel/mutableSpace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void MutableSpace::numa_setup_pages(MemRegion mr, size_t page_size, bool clear_s
5353
size_t size = pointer_delta(end, start, sizeof(char));
5454
if (clear_space) {
5555
// Prefer page reallocation to migration.
56-
os::free_memory((char*)start, size, page_size);
56+
os::disclaim_memory((char*)start, size);
5757
}
5858
os::numa_make_global((char*)start, size);
5959
}

‎src/hotspot/share/runtime/os.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2271,8 +2271,8 @@ bool os::unmap_memory(char *addr, size_t bytes) {
22712271
return result;
22722272
}
22732273

2274-
void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) {
2275-
pd_free_memory(addr, bytes, alignment_hint);
2274+
void os::disclaim_memory(char *addr, size_t bytes) {
2275+
pd_disclaim_memory(addr, bytes);
22762276
}
22772277

22782278
void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) {

‎src/hotspot/share/runtime/os.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class os: AllStatic {
231231
char *addr, size_t bytes, bool read_only = false,
232232
bool allow_exec = false);
233233
static bool pd_unmap_memory(char *addr, size_t bytes);
234-
static void pd_free_memory(char *addr, size_t bytes, size_t alignment_hint);
234+
static void pd_disclaim_memory(char *addr, size_t bytes);
235235
static void pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint);
236236

237237
// Returns 0 if pretouch is done via platform dependent method, or otherwise
@@ -520,7 +520,7 @@ class os: AllStatic {
520520
char *addr, size_t bytes, bool read_only = false,
521521
bool allow_exec = false, MEMFLAGS flags = mtNone);
522522
static bool unmap_memory(char *addr, size_t bytes);
523-
static void free_memory(char *addr, size_t bytes, size_t alignment_hint);
523+
static void disclaim_memory(char *addr, size_t bytes);
524524
static void realign_memory(char *addr, size_t bytes, size_t alignment_hint);
525525

526526
// NUMA-specific interface

‎test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class CommittedVirtualMemoryTest {
132132
}
133133

134134
// Cleanup
135-
os::free_memory(base, size, page_sz);
135+
os::disclaim_memory(base, size);
136136
VirtualMemoryTracker::remove_released_region((address)base, size);
137137

138138
rmr = VirtualMemoryTracker::_reserved_regions->find(ReservedMemoryRegion((address)base, size));

‎test/hotspot/gtest/runtime/test_os.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
2423
#include "precompiled.hpp"
2524
#include "memory/allocation.hpp"
2625
#include "memory/resourceArea.hpp"
@@ -977,3 +976,27 @@ TEST_VM(os, vm_min_address) {
977976
#endif
978977
}
979978

979+
#if !defined(_WINDOWS) && !defined(_AIX)
980+
TEST_VM(os, free_without_uncommit) {
981+
const size_t page_sz = os::vm_page_size();
982+
const size_t pages = 64;
983+
const size_t size = pages * page_sz;
984+
985+
char* base = os::reserve_memory(size, false, mtTest);
986+
ASSERT_NE(base, (char*) nullptr);
987+
ASSERT_TRUE(os::commit_memory(base, size, false));
988+
989+
for (size_t index = 0; index < pages; index++) {
990+
base[index * page_sz] = 'a';
991+
}
992+
993+
os::disclaim_memory(base, size);
994+
995+
// Ensure we can still use the memory without having to recommit.
996+
for (size_t index = 0; index < pages; index++) {
997+
base[index * page_sz] = 'a';
998+
}
999+
1000+
os::release_memory(base, size);
1001+
}
1002+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.