8353264: ZGC: Windows heap unreserving is broken

Reviewed-by: jsikstro, aboldtch, eosterlund, stuefe
This commit is contained in:
Stefan Karlsson 2025-04-03 10:44:58 +00:00
parent f7a94feedd
commit ffca4f2da8
2 changed files with 27 additions and 3 deletions

View File

@ -78,7 +78,7 @@ void ZMapper::unreserve(zaddress_unsafe addr, size_t size) {
const bool res = ZSyscall::VirtualFreeEx(
GetCurrentProcess(), // hProcess
(void*)untype(addr), // lpAddress
size, // dwSize
0, // dwSize
MEM_RELEASE // dwFreeType
);

View File

@ -26,6 +26,7 @@
#include "gc/z/zAddress.inline.hpp"
#include "gc/z/zGlobals.hpp"
#include "gc/z/zList.inline.hpp"
#include "gc/z/zMapper_windows.hpp"
#include "gc/z/zMemory.inline.hpp"
#include "gc/z/zSyscall_windows.hpp"
#include "gc/z/zVirtualMemory.hpp"
@ -43,7 +44,9 @@ private:
static bool _initialized;
static ZMemoryManager* _va;
ZVirtualMemoryManager* _vmm;
static ZVirtualMemoryManager* _vmm;
static bool _has_unreserved;
public:
bool reserve_for_test() {
@ -87,6 +90,7 @@ public:
}
_initialized = true;
_has_unreserved = false;
}
virtual void TearDown() {
@ -95,12 +99,26 @@ public:
return;
}
if (_initialized) {
if (_initialized && !_has_unreserved) {
_vmm->pd_unreserve(ZOffset::address_unsafe(zoffset(0)), 0);
}
os::free(_vmm);
}
static void test_unreserve() {
zoffset bottom = _va->alloc_low_address(ZGranuleSize);
zoffset top = _va->alloc_high_address(ZGranuleSize);
// Unreserve the middle part
ZMapper::unreserve(ZOffset::address_unsafe(bottom + ZGranuleSize), ZGranuleSize);
// Make sure that we still can unreserve the memory before and after
ZMapper::unreserve(ZOffset::address_unsafe(bottom), ZGranuleSize);
ZMapper::unreserve(ZOffset::address_unsafe(top), ZGranuleSize);
_has_unreserved = true;
}
static void test_alloc_low_address() {
// Verify that we get placeholder for first granule
zoffset bottom = _va->alloc_low_address(ZGranuleSize);
@ -170,6 +188,12 @@ public:
bool ZMapperTest::_initialized = false;
ZMemoryManager* ZMapperTest::_va = nullptr;
ZVirtualMemoryManager* ZMapperTest::_vmm = nullptr;
bool ZMapperTest::_has_unreserved;
TEST_VM_F(ZMapperTest, test_unreserve) {
test_unreserve();
}
TEST_VM_F(ZMapperTest, test_alloc_low_address) {
test_alloc_low_address();