From ffca4f2da84cb8711794d8e692d176a7e785e7b1 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Thu, 3 Apr 2025 10:44:58 +0000 Subject: [PATCH] 8353264: ZGC: Windows heap unreserving is broken Reviewed-by: jsikstro, aboldtch, eosterlund, stuefe --- .../os/windows/gc/z/zMapper_windows.cpp | 2 +- .../gtest/gc/z/test_zMapper_windows.cpp | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/hotspot/os/windows/gc/z/zMapper_windows.cpp b/src/hotspot/os/windows/gc/z/zMapper_windows.cpp index eadabcbb030..d3d0a9766fd 100644 --- a/src/hotspot/os/windows/gc/z/zMapper_windows.cpp +++ b/src/hotspot/os/windows/gc/z/zMapper_windows.cpp @@ -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 ); diff --git a/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp b/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp index 02914abdf6d..79ad840b50b 100644 --- a/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp +++ b/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp @@ -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();