Skip to content
Closed
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
11 changes: 9 additions & 2 deletions test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ class CommittedVirtualMemoryTest {
ASSERT_TRUE(found_stack_top);
}

static const int PAGE_CONTAINED_IN_RANGE_TAG = -1;
static bool is_page_in_committed_region(int a) { return (a == PAGE_CONTAINED_IN_RANGE_TAG); }
static void set_page_as_contained_in_committed_region(int &a) { a = PAGE_CONTAINED_IN_RANGE_TAG; }

static void check_covered_pages(address addr, size_t size, address base, size_t touch_pages, int* page_num) {
const size_t page_sz = os::vm_page_size();
size_t index;
for (index = 0; index < touch_pages; index ++) {
if (is_page_in_committed_region(page_num[index])) { // Already tagged?
continue;
}
address page_addr = base + page_num[index] * page_sz;
Copy link
Member

Choose a reason for hiding this comment

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

What if we assert(page_num[index] >= 0) at this point if we know that negative numbers may cause overflows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Negative numbers are not bug/invalid. They are used as a marker that the page is inside a committed region.
In the test we list/iterate all committed regions of a reserved memory are. For each committed region we check a list of pages whether the page is inside the committed region or not. if yes, we mark the page with -1. There two loops here one for committed regions and for list of page numbers.
After loops, we check and expect that all the pages were marked as being inside committed regions.

// The range covers this page, marks the page
if (page_addr >= addr && page_addr < addr + size) {
page_num[index] = -1;
set_page_as_contained_in_committed_region(page_num[index]);
}
}
}
Expand Down Expand Up @@ -135,7 +142,7 @@ class CommittedVirtualMemoryTest {
if (precise_tracking_supported) {
// All touched pages should be committed
for (size_t index = 0; index < touch_pages; index ++) {
ASSERT_EQ(page_num[index], -1);
ASSERT_TRUE(is_page_in_committed_region(page_num[index]));
}
}

Expand Down