Skip to content

Commit ffca4f2

Browse files
committed
8353264: ZGC: Windows heap unreserving is broken
Reviewed-by: jsikstro, aboldtch, eosterlund, stuefe
1 parent f7a94fe commit ffca4f2

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/hotspot/os/windows/gc/z/zMapper_windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void ZMapper::unreserve(zaddress_unsafe addr, size_t size) {
7878
const bool res = ZSyscall::VirtualFreeEx(
7979
GetCurrentProcess(), // hProcess
8080
(void*)untype(addr), // lpAddress
81-
size, // dwSize
81+
0, // dwSize
8282
MEM_RELEASE // dwFreeType
8383
);
8484

test/hotspot/gtest/gc/z/test_zMapper_windows.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "gc/z/zAddress.inline.hpp"
2727
#include "gc/z/zGlobals.hpp"
2828
#include "gc/z/zList.inline.hpp"
29+
#include "gc/z/zMapper_windows.hpp"
2930
#include "gc/z/zMemory.inline.hpp"
3031
#include "gc/z/zSyscall_windows.hpp"
3132
#include "gc/z/zVirtualMemory.hpp"
@@ -43,7 +44,9 @@ class ZMapperTest : public Test {
4344
static bool _initialized;
4445
static ZMemoryManager* _va;
4546

46-
ZVirtualMemoryManager* _vmm;
47+
static ZVirtualMemoryManager* _vmm;
48+
49+
static bool _has_unreserved;
4750

4851
public:
4952
bool reserve_for_test() {
@@ -87,6 +90,7 @@ class ZMapperTest : public Test {
8790
}
8891

8992
_initialized = true;
93+
_has_unreserved = false;
9094
}
9195

9296
virtual void TearDown() {
@@ -95,12 +99,26 @@ class ZMapperTest : public Test {
9599
return;
96100
}
97101

98-
if (_initialized) {
102+
if (_initialized && !_has_unreserved) {
99103
_vmm->pd_unreserve(ZOffset::address_unsafe(zoffset(0)), 0);
100104
}
101105
os::free(_vmm);
102106
}
103107

108+
static void test_unreserve() {
109+
zoffset bottom = _va->alloc_low_address(ZGranuleSize);
110+
zoffset top = _va->alloc_high_address(ZGranuleSize);
111+
112+
// Unreserve the middle part
113+
ZMapper::unreserve(ZOffset::address_unsafe(bottom + ZGranuleSize), ZGranuleSize);
114+
115+
// Make sure that we still can unreserve the memory before and after
116+
ZMapper::unreserve(ZOffset::address_unsafe(bottom), ZGranuleSize);
117+
ZMapper::unreserve(ZOffset::address_unsafe(top), ZGranuleSize);
118+
119+
_has_unreserved = true;
120+
}
121+
104122
static void test_alloc_low_address() {
105123
// Verify that we get placeholder for first granule
106124
zoffset bottom = _va->alloc_low_address(ZGranuleSize);
@@ -170,6 +188,12 @@ class ZMapperTest : public Test {
170188

171189
bool ZMapperTest::_initialized = false;
172190
ZMemoryManager* ZMapperTest::_va = nullptr;
191+
ZVirtualMemoryManager* ZMapperTest::_vmm = nullptr;
192+
bool ZMapperTest::_has_unreserved;
193+
194+
TEST_VM_F(ZMapperTest, test_unreserve) {
195+
test_unreserve();
196+
}
173197

174198
TEST_VM_F(ZMapperTest, test_alloc_low_address) {
175199
test_alloc_low_address();

0 commit comments

Comments
 (0)