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

Kim Barrett kbarrett at openjdk.org
Tue Jul 22 20:06:56 UTC 2025


On Tue, 22 Jul 2025 07:44:26 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> test/hotspot/gtest/gc/g1/test_freeRegionList.cpp line 50:
>> 
>>> 48:   const size_t sz = szw * BytesPerWord;
>>> 49:   char* addr = os::reserve_memory(sz, mtTest);
>>> 50:   MemRegion heap((HeapWord*)addr, szw);
>> 
>> So far as I can tell, there's no guarantee that `os::reserve_memory` will return an address with any
>> particular alignment. Since the earlier attempt with unaligned storage failed, it may only be by accident
>> that this isn't failing as well.  We have `os::reserve_memory_aligned`, or could add an extra region to
>> the desired size and align up the result.
>
> `os::reserve_memory` addresses are always regular-page-aligned. But `os::reserve_memory_aligned` may be better here since I guess the addresses would better have been region-size-aligned, so aligned to G1HeapRegion::GrainWords. That could be larger than system page size.

Too bad the only way to find out about that alignment behavior is to dig into the sources for all ports
and read the documentation for the underlying OS function. :(

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26216#discussion_r2223717975


More information about the hotspot-runtime-dev mailing list