From ceb0c0fc39c17793d13fff74e69f22ef07ec2c0f Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Wed, 23 Jul 2025 07:49:11 +0000 Subject: [PATCH] 8360941: [ubsan] MemRegion::end() shows runtime error: applying non-zero offset 8388608 to null pointer Co-authored-by: Kim Barrett Co-authored-by: Thomas Stuefe Reviewed-by: kbarrett, lucy --- test/hotspot/gtest/gc/g1/test_freeRegionList.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/hotspot/gtest/gc/g1/test_freeRegionList.cpp b/test/hotspot/gtest/gc/g1/test_freeRegionList.cpp index ea8027df2a7..e61ce43fdb6 100644 --- a/test/hotspot/gtest/gc/g1/test_freeRegionList.cpp +++ b/test/hotspot/gtest/gc/g1/test_freeRegionList.cpp @@ -44,7 +44,10 @@ TEST_OTHER_VM(G1FreeRegionList, length) { // Create a fake heap. It does not need to be valid, as the G1HeapRegion constructor // does not access it. - MemRegion heap(nullptr, num_regions_in_test * G1HeapRegion::GrainWords); + const size_t szw = num_regions_in_test * G1HeapRegion::GrainWords; + const size_t sz = szw * BytesPerWord; + char* addr = os::reserve_memory_aligned(sz, G1HeapRegion::GrainBytes, mtTest); + MemRegion heap((HeapWord*)addr, szw); // Allocate a fake BOT because the G1HeapRegion constructor initializes // the BOT. @@ -87,5 +90,6 @@ TEST_OTHER_VM(G1FreeRegionList, length) { bot_storage->uncommit_regions(0, num_regions_in_test); delete bot_storage; + os::release_memory(addr, sz); FREE_C_HEAP_ARRAY(HeapWord, bot_data); }