8360941: [ubsan] MemRegion::end() shows runtime error: applying non-zero offset 8388608 to null pointer

Co-authored-by: Kim Barrett <kbarrett@openjdk.org>
Co-authored-by: Thomas Stuefe <stuefe@openjdk.org>
Reviewed-by: kbarrett, lucy
This commit is contained in:
Matthias Baesken 2025-07-23 07:49:11 +00:00
parent 5160cfb496
commit ceb0c0fc39

View File

@ -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);
}