Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion test/hotspot/gtest/gc/g1/test_freeRegionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


// Allocate a fake BOT because the G1HeapRegion constructor initializes
// the BOT.
Expand Down Expand Up @@ -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);
}