[compiler-rt] 42adbb1 - [NFC][sanitizer] Remove MapUnmapCallback from sanitizer_flat_map.h
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 21 13:14:42 PDT 2023
Author: Vitaly Buka
Date: 2023-06-21T13:14:30-07:00
New Revision: 42adbb1b2d8fff7dc8e495f2954ec965acf65d91
URL: https://github.com/llvm/llvm-project/commit/42adbb1b2d8fff7dc8e495f2954ec965acf65d91
DIFF: https://github.com/llvm/llvm-project/commit/42adbb1b2d8fff7dc8e495f2954ec965acf65d91.diff
LOG: [NFC][sanitizer] Remove MapUnmapCallback from sanitizer_flat_map.h
It's used by test only to test "test-only" code.
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
compiler-rt/lib/sanitizer_common/sanitizer_flat_map.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_flat_map_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
index 76b936ff5eaa6..166a0539e4ba0 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 05fb554d20c14..8bb8304910c73 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 <typename T, u64 kSize,
typename AddressSpaceViewTy = LocalAddressSpaceView>
@@ -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 T, u64 kSize1, u64 kSize2,
- typename AddressSpaceViewTy = LocalAddressSpaceView,
- class MapUnmapCallback = NoOpMapUnmapCallback>
+ 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<uptr>(p), MmapSize());
UnmapOrDie(p, kSize2);
}
Init();
@@ -149,7 +141,6 @@ class TwoLevelMap {
T *res = Get(idx);
if (!res) {
res = reinterpret_cast<T *>(MmapOrDie(MmapSize(), "TwoLevelMap"));
- MapUnmapCallback().OnMap(reinterpret_cast<uptr>(res), kSize2);
atomic_store(&map1_[idx], reinterpret_cast<uptr>(res),
memory_order_release);
}
@@ -164,10 +155,8 @@ template <u64 kSize, typename AddressSpaceViewTy = LocalAddressSpaceView>
using FlatByteMap = FlatMap<u8, kSize, AddressSpaceViewTy>;
template <u64 kSize1, u64 kSize2,
- typename AddressSpaceViewTy = LocalAddressSpaceView,
- class MapUnmapCallback = NoOpMapUnmapCallback>
-using TwoLevelByteMap =
- TwoLevelMap<u8, kSize1, kSize2, AddressSpaceViewTy, MapUnmapCallback>;
+ typename AddressSpaceViewTy = LocalAddressSpaceView>
+using TwoLevelByteMap = TwoLevelMap<u8, kSize1, kSize2, AddressSpaceViewTy>;
} // 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 d7b4194bb57e3..61136c14521c2 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 <typename TypeParam, typename AddressSpaceView>
-using TestMapASVT = TwoLevelMap<TypeParam, 1 << 8, 1 << 7, AddressSpaceView,
- TestMapUnmapCallback1>;
+using TestMapASVT = TwoLevelMap<TypeParam, 1 << 8, 1 << 7, AddressSpaceView>;
template <typename TypeParam>
using TestMap = TestMapASVT<TypeParam, LocalAddressSpaceView>;
@@ -89,8 +81,6 @@ static void *TwoLevelMapUserThread(void *param) {
TYPED_TEST(FlatMapTest, ThreadedTwoLevelByteMap) {
TestMap<TypeParam> m;
m.Init();
- TestMapUnmapCallback1::map_count = 0;
- TestMapUnmapCallback1::unmap_count = 0;
static const int kNumThreads = 4;
pthread_t t[kNumThreads];
TestMapParam<TypeParam> p[kNumThreads];
@@ -100,14 +90,8 @@ TYPED_TEST(FlatMapTest, ThreadedTwoLevelByteMap) {
p[i].num_shards = kNumThreads;
PTHREAD_CREATE(&t[i], 0, TwoLevelMapUserThread<TypeParam>, &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
More information about the llvm-commits
mailing list