From 5afdca2ac8ccc9e6ba8deb1b9024730d03b59119 Mon Sep 17 00:00:00 2001 From: Afshin Zafari Date: Wed, 5 Nov 2025 15:48:33 +0100 Subject: [PATCH 1/4] 8361487: [ubsan] test_committed_virtualmemory.cpp check_covered_pages shows overflow --- test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp index 4d3fc1ff82e49..fbf95cbc77ebe 100644 --- a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp +++ b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp @@ -87,6 +87,9 @@ class CommittedVirtualMemoryTest { const size_t page_sz = os::vm_page_size(); size_t index; for (index = 0; index < touch_pages; index ++) { + if (page_num[index] < 0) { // negative values cause overflow in the following expression 'base + (-x) < base' + continue; + } address page_addr = base + page_num[index] * page_sz; // The range covers this page, marks the page if (page_addr >= addr && page_addr < addr + size) { From d45208dc04747c9c5c5744c0b3a5b3c430796e2a Mon Sep 17 00:00:00 2001 From: Afshin Zafari Date: Thu, 13 Nov 2025 14:20:41 +0100 Subject: [PATCH 2/4] more descriptive --- .../gtest/runtime/test_committed_virtualmemory.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp index fbf95cbc77ebe..c3fa22d411576 100644 --- a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp +++ b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp @@ -83,17 +83,21 @@ class CommittedVirtualMemoryTest { ASSERT_TRUE(found_stack_top); } + static constexpr int PAGE_CONTAINED_IN_RANGE_TAG = -1; + static constexpr bool IS_PAGE_CONTAINED_IN_COMMITTED_REGION(int a) { return (a == PAGE_CONTAINED_IN_RANGE_TAG); } + static constexpr 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 (page_num[index] < 0) { // negative values cause overflow in the following expression 'base + (-x) < base' + if (IS_PAGE_CONTAINED_IN_COMMITTED_REGION(page_num[index])) { // Already tagged continue; } address page_addr = base + page_num[index] * page_sz; // 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]); } } } @@ -138,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_CONTAINED_IN_COMMITTED_REGION(page_num[index])); } } From f3f3fe0e8312184d3d2535685592c8ae3a1d7ca2 Mon Sep 17 00:00:00 2001 From: Afshin Zafari Date: Thu, 13 Nov 2025 14:29:18 +0100 Subject: [PATCH 3/4] better comment --- test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp index c3fa22d411576..3549563ad2d05 100644 --- a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp +++ b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp @@ -91,7 +91,7 @@ class CommittedVirtualMemoryTest { const size_t page_sz = os::vm_page_size(); size_t index; for (index = 0; index < touch_pages; index ++) { - if (IS_PAGE_CONTAINED_IN_COMMITTED_REGION(page_num[index])) { // Already tagged + if (IS_PAGE_CONTAINED_IN_COMMITTED_REGION(page_num[index])) { // Already tagged? continue; } address page_addr = base + page_num[index] * page_sz; From 84a1e3c80e7a4cfa0cded241e091f0486af0b5ff Mon Sep 17 00:00:00 2001 From: Afshin Zafari Date: Thu, 13 Nov 2025 16:00:05 +0100 Subject: [PATCH 4/4] style and not constexpr --- .../gtest/runtime/test_committed_virtualmemory.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp index 3549563ad2d05..5b78a66a3ae59 100644 --- a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp +++ b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp @@ -83,21 +83,21 @@ class CommittedVirtualMemoryTest { ASSERT_TRUE(found_stack_top); } - static constexpr int PAGE_CONTAINED_IN_RANGE_TAG = -1; - static constexpr bool IS_PAGE_CONTAINED_IN_COMMITTED_REGION(int a) { return (a == PAGE_CONTAINED_IN_RANGE_TAG); } - static constexpr void SET_PAGE_AS_CONTAINED_IN_COMMITTED_REGION(int &a) { a = PAGE_CONTAINED_IN_RANGE_TAG; } + 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_CONTAINED_IN_COMMITTED_REGION(page_num[index])) { // Already tagged? + if (is_page_in_committed_region(page_num[index])) { // Already tagged? continue; } address page_addr = base + page_num[index] * page_sz; // The range covers this page, marks the page if (page_addr >= addr && page_addr < addr + size) { - SET_PAGE_AS_CONTAINED_IN_COMMITTED_REGION(page_num[index]); + set_page_as_contained_in_committed_region(page_num[index]); } } } @@ -142,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_TRUE(IS_PAGE_CONTAINED_IN_COMMITTED_REGION(page_num[index])); + ASSERT_TRUE(is_page_in_committed_region(page_num[index])); } }