From 42adbb1b2d8fff7dc8e495f2954ec965acf65d91 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 21 Jun 2023 13:04:34 -0700 Subject: [PATCH] [NFC][sanitizer] Remove MapUnmapCallback from sanitizer_flat_map.h It's used by test only to test "test-only" code. --- .../lib/sanitizer_common/sanitizer_allocator.h | 5 +++++ .../lib/sanitizer_common/sanitizer_flat_map.h | 17 +++-------------- .../tests/sanitizer_flat_map_test.cpp | 20 ++------------------ 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h index 76b936f..166a053 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h @@ -62,6 +62,11 @@ inline void RandomShuffle(T *a, u32 n, u32 *rand_state) { *rand_state = state; } +struct NoOpMapUnmapCallback { + void OnMap(uptr p, uptr size) const {} + void OnUnmap(uptr p, uptr size) const {} +}; + #include "sanitizer_allocator_size_class_map.h" #include "sanitizer_allocator_stats.h" #include "sanitizer_allocator_primary64.h" diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h index 05fb554..8bb8304 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h @@ -21,12 +21,6 @@ namespace __sanitizer { -// Call these callbacks on mmap/munmap. -struct NoOpMapUnmapCallback { - void OnMap(uptr p, uptr size) const {} - void OnUnmap(uptr p, uptr size) const {} -}; - // Maps integers in rage [0, kSize) to values. template @@ -62,8 +56,7 @@ class FlatMap { // Each value is initially zero and can be set to something else only once. // Setting and getting values from multiple threads is safe w/o extra locking. template + typename AddressSpaceViewTy = LocalAddressSpaceView> class TwoLevelMap { static_assert(IsPowerOfTwo(kSize2), "Use a power of two for performance."); @@ -79,7 +72,6 @@ class TwoLevelMap { T *p = Get(i); if (!p) continue; - MapUnmapCallback().OnUnmap(reinterpret_cast(p), MmapSize()); UnmapOrDie(p, kSize2); } Init(); @@ -149,7 +141,6 @@ class TwoLevelMap { T *res = Get(idx); if (!res) { res = reinterpret_cast(MmapOrDie(MmapSize(), "TwoLevelMap")); - MapUnmapCallback().OnMap(reinterpret_cast(res), kSize2); atomic_store(&map1_[idx], reinterpret_cast(res), memory_order_release); } @@ -164,10 +155,8 @@ template using FlatByteMap = FlatMap; template -using TwoLevelByteMap = - TwoLevelMap; + typename AddressSpaceViewTy = LocalAddressSpaceView> +using TwoLevelByteMap = TwoLevelMap; } // namespace __sanitizer #endif diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_flat_map_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_flat_map_test.cpp index d7b4194..61136c1 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_flat_map_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_flat_map_test.cpp @@ -14,13 +14,6 @@ using namespace __sanitizer; namespace { -struct TestMapUnmapCallback1 { - static int map_count, unmap_count; - void OnMap(uptr p, uptr size) const { map_count++; } - void OnUnmap(uptr p, uptr size) const { unmap_count++; } -}; -int TestMapUnmapCallback1::map_count; -int TestMapUnmapCallback1::unmap_count; struct TestStruct { int data[125] = {}; @@ -63,8 +56,7 @@ TYPED_TEST(FlatMapTest, TwoLevelByteMap) { } template -using TestMapASVT = TwoLevelMap; +using TestMapASVT = TwoLevelMap; template using TestMap = TestMapASVT; @@ -89,8 +81,6 @@ static void *TwoLevelMapUserThread(void *param) { TYPED_TEST(FlatMapTest, ThreadedTwoLevelByteMap) { TestMap m; m.Init(); - TestMapUnmapCallback1::map_count = 0; - TestMapUnmapCallback1::unmap_count = 0; static const int kNumThreads = 4; pthread_t t[kNumThreads]; TestMapParam p[kNumThreads]; @@ -100,14 +90,8 @@ TYPED_TEST(FlatMapTest, ThreadedTwoLevelByteMap) { p[i].num_shards = kNumThreads; PTHREAD_CREATE(&t[i], 0, TwoLevelMapUserThread, &p[i]); } - for (int i = 0; i < kNumThreads; i++) { - PTHREAD_JOIN(t[i], 0); - } - EXPECT_EQ((uptr)TestMapUnmapCallback1::map_count, m.size1()); - EXPECT_EQ((uptr)TestMapUnmapCallback1::unmap_count, 0UL); + for (int i = 0; i < kNumThreads; i++) PTHREAD_JOIN(t[i], 0); m.TestOnlyUnmap(); - EXPECT_EQ((uptr)TestMapUnmapCallback1::map_count, m.size1()); - EXPECT_EQ((uptr)TestMapUnmapCallback1::unmap_count, m.size1()); } } // namespace -- 2.7.4