Skip to content

Commit 9e566d7

Browse files
committed
8327971: Multiple ASAN errors reported for metaspace
8327988: When running ASAN, disable dangerous NMT test Reviewed-by: jsjolen, rkennke
1 parent 8fc9097 commit 9e566d7

File tree

9 files changed

+50
-2
lines changed

9 files changed

+50
-2
lines changed

src/hotspot/share/memory/metaspace/metachunk.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2017, 2021 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -34,6 +34,7 @@
3434
#include "utilities/align.hpp"
3535
#include "utilities/copy.hpp"
3636
#include "utilities/debug.hpp"
37+
#include "utilities/macros.hpp"
3738
#include "utilities/ostream.hpp"
3839

3940
namespace metaspace {
@@ -285,7 +286,9 @@ void Metachunk::verify() const {
285286
const size_t required_alignment = word_size() * sizeof(MetaWord);
286287
assert_is_aligned(base(), required_alignment);
287288

288-
// Test accessing the committed area.
289+
// Test accessing the committed area. But not for ASAN. We don't know which portions
290+
// of the chunk are still poisoned.
291+
#if !INCLUDE_ASAN
289292
SOMETIMES(
290293
if (_committed_words > 0) {
291294
for (const MetaWord* p = _base; p < _base + _committed_words; p += os::vm_page_size()) {
@@ -294,6 +297,7 @@ void Metachunk::verify() const {
294297
dummy = *(_base + _committed_words - 1);
295298
}
296299
)
300+
#endif // !INCLUDE_ASAN
297301
}
298302
#endif // ASSERT
299303

src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "utilities/align.hpp"
4949
#include "utilities/debug.hpp"
5050
#include "utilities/globalDefinitions.hpp"
51+
#include "utilities/macros.hpp"
5152
#include "utilities/ostream.hpp"
5253

5354
namespace metaspace {
@@ -433,13 +434,17 @@ void VirtualSpaceNode::verify_locked() const {
433434
_commit_mask.verify();
434435

435436
// Verify memory against commit mask.
437+
// Down here, from ASAN's view, this memory may be poisoned, since we only unpoison
438+
// way up at the ChunkManager level.
439+
#if !INCLUDE_ASAN
436440
SOMETIMES(
437441
for (MetaWord* p = base(); p < base() + used_words(); p += os::vm_page_size()) {
438442
if (_commit_mask.is_committed_address(p)) {
439443
test_access += *(uint*)p;
440444
}
441445
}
442446
)
447+
#endif // !INCLUDE_ASAN
443448

444449
assert(committed_words() <= word_size(), "Sanity");
445450
assert_is_aligned(committed_words(), Settings::commit_granule_words());

src/hotspot/share/nmt/mallocTracker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "runtime/safefetch.hpp"
4141
#include "services/mallocLimit.hpp"
4242
#include "utilities/debug.hpp"
43+
#include "utilities/macros.hpp"
4344
#include "utilities/ostream.hpp"
4445
#include "utilities/vmError.hpp"
4546
#include "utilities/globalDefinitions.hpp"
@@ -226,6 +227,8 @@ void MallocTracker::deaccount(MallocHeader::FreeInfo free_info) {
226227
bool MallocTracker::print_pointer_information(const void* p, outputStream* st) {
227228
assert(MemTracker::enabled(), "NMT not enabled");
228229

230+
#if !INCLUDE_ASAN
231+
229232
address addr = (address)p;
230233

231234
// Carefully feel your way upwards and try to find a malloc header. Then check if
@@ -303,5 +306,8 @@ bool MallocTracker::print_pointer_information(const void* p, outputStream* st) {
303306
}
304307
return true;
305308
}
309+
310+
#endif // !INCLUDE_ASAN
311+
306312
return false;
307313
}

src/hotspot/share/runtime/os.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "utilities/defaultStream.hpp"
7676
#include "utilities/events.hpp"
7777
#include "utilities/fastrand.hpp"
78+
#include "utilities/macros.hpp"
7879
#include "utilities/powerOfTwo.hpp"
7980

8081
#ifndef _WINDOWS
@@ -1199,6 +1200,8 @@ void os::print_location(outputStream* st, intptr_t x, bool verbose) {
11991200
return;
12001201
}
12011202

1203+
#if !INCLUDE_ASAN
1204+
12021205
bool accessible = is_readable_pointer(addr);
12031206

12041207
// Check if addr is a JNI handle.
@@ -1285,7 +1288,10 @@ void os::print_location(outputStream* st, intptr_t x, bool verbose) {
12851288
return;
12861289
}
12871290

1291+
#endif // !INCLUDE_ASAN
1292+
12881293
st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
1294+
12891295
}
12901296

12911297
static bool is_pointer_bad(intptr_t* ptr) {

src/hotspot/share/utilities/macros.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,10 @@
635635
#define NOT_CDS_JAVA_HEAP_RETURN_(code) { return code; }
636636
#endif
637637

638+
#ifdef ADDRESS_SANITIZER
639+
#define INCLUDE_ASAN 1
640+
#else
641+
#define INCLUDE_ASAN 0
642+
#endif
643+
638644
#endif // SHARE_UTILITIES_MACROS_HPP

test/hotspot/gtest/metaspace/test_virtualspacenode.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "memory/metaspace/virtualSpaceNode.hpp"
3535
#include "runtime/mutexLocker.hpp"
3636
#include "sanitizers/address.hpp"
37+
#include "utilities/macros.hpp"
3738
#include "utilities/debug.hpp"
3839
//#define LOG_PLEASE
3940
#include "metaspaceGtestCommon.hpp"
@@ -156,6 +157,11 @@ class VirtualSpaceNodeTest {
156157
// The chunk should be as far committed as was requested
157158
EXPECT_GE(c->committed_words(), request_commit_words);
158159

160+
// At the VirtualSpaceNode level, all memory is still poisoned.
161+
// Since we bypass the normal way of allocating chunks (ChunkManager::get_chunk), we
162+
// need to unpoison this chunk.
163+
ASAN_UNPOISON_MEMORY_REGION(c->base(), c->committed_words() * BytesPerWord);
164+
159165
// Zap committed portion.
160166
DEBUG_ONLY(zap_range(c->base(), c->committed_words());)
161167

test/hotspot/gtest/nmt/test_nmt_buffer_overflow_detection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
#include "memory/allocation.hpp"
2727
#include "nmt/memTracker.hpp"
2828
#include "runtime/os.hpp"
29+
#include "sanitizers/address.hpp"
2930
#include "utilities/debug.hpp"
3031
#include "utilities/ostream.hpp"
3132
#include "unittest.hpp"
3233
#include "testutils.hpp"
3334

35+
#if !INCLUDE_ASAN
36+
3437
// This prefix shows up on any c heap corruption NMT detects. If unsure which assert will
3538
// come, just use this one.
3639
#define COMMON_NMT_HEAP_CORRUPTION_MESSAGE_PREFIX "NMT corruption"
@@ -161,3 +164,5 @@ TEST_VM(NMT, test_realloc) {
161164
}
162165
}
163166
}
167+
168+
#endif // !INCLUDE_ASAN

test/hotspot/gtest/nmt/test_nmt_cornercases.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "nmt/mallocTracker.hpp"
2929
#include "nmt/memTracker.hpp"
3030
#include "runtime/os.hpp"
31+
#include "sanitizers/address.hpp"
3132
#include "testutils.hpp"
3233
#include "unittest.hpp"
3334

@@ -38,6 +39,9 @@ static void check_expected_malloc_header(const void* payload, MEMFLAGS type, siz
3839
EXPECT_EQ(hdr->flags(), type);
3940
}
4041

42+
// ASAN complains about allocating very large sizes
43+
#if !INCLUDE_ASAN
44+
4145
// Check that a malloc with an overflowing size is rejected.
4246
TEST_VM(NMT, malloc_failure1) {
4347
void* p = os::malloc(SIZE_MAX, mtTest);
@@ -85,6 +89,7 @@ TEST_VM(NMT, realloc_failure_overflowing_size) {
8589
TEST_VM(NMT, realloc_failure_gigantic_size) {
8690
check_failing_realloc(SIZE_MAX - M);
8791
}
92+
#endif // !INCLUDE_ASAN
8893

8994
static void* do_realloc(void* p, size_t old_size, size_t new_size, uint8_t old_content, bool check_nmt_header) {
9095

test/hotspot/gtest/nmt/test_nmt_locationprinting.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
#include "nmt/mallocHeader.inline.hpp"
2828
#include "nmt/memTracker.hpp"
2929
#include "runtime/os.hpp"
30+
#include "sanitizers/address.hpp"
3031
#include "unittest.hpp"
3132

3233
// Uncomment to get test output
3334
//#define LOG_PLEASE
3435
#include "testutils.hpp"
3536

37+
#if !INCLUDE_ASAN
38+
3639
using ::testing::HasSubstr;
3740

3841
static void test_pointer(const void* p, bool expected_return_code, const char* expected_message) {
@@ -123,3 +126,5 @@ static void test_for_mmap(size_t sz, ssize_t offset) {
123126

124127
TEST_VM(NMT, location_printing_mmap_1) { test_for_mmap(os::vm_page_size(), 0); }
125128
TEST_VM(NMT, location_printing_mmap_2) { test_for_mmap(os::vm_page_size(), os::vm_page_size() - 1); }
129+
130+
#endif // !INCLUDE_ASAN

0 commit comments

Comments
 (0)