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
4851public:
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
171189bool ZMapperTest::_initialized = false ;
172190ZMemoryManager* 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
174198TEST_VM_F (ZMapperTest, test_alloc_low_address) {
175199 test_alloc_low_address ();
0 commit comments