[compiler-rt] 7140382 - [NFC][sanitizer] Move MemoryMapper template parameter

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 13 16:52:33 PDT 2021


Author: Vitaly Buka
Date: 2021-07-13T16:52:22-07:00
New Revision: 7140382b17df7c33145cc6e9a2df7e84a2259444

URL: https://github.com/llvm/llvm-project/commit/7140382b17df7c33145cc6e9a2df7e84a2259444
DIFF: https://github.com/llvm/llvm-project/commit/7140382b17df7c33145cc6e9a2df7e84a2259444.diff

LOG: [NFC][sanitizer] Move MemoryMapper template parameter

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
    compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 1e540a180d4e..952b06976362 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -419,11 +419,11 @@ class SizeClassAllocator64 {
   // For the performance sake, none of the accessors check the validity of the
   // arguments, it is assumed that index is always in [0, n) range and the value
   // is not incremented past max_value.
-  template <typename MemoryMapper>
   class PackedCounterArray {
    public:
+    template <typename MemoryMapper>
     PackedCounterArray(u64 num_counters, u64 max_value, MemoryMapper *mapper)
-        : n(num_counters), memory_mapper(mapper) {
+        : n(num_counters) {
       CHECK_GT(num_counters, 0);
       CHECK_GT(max_value, 0);
       constexpr u64 kMaxCounterBits = sizeof(*buffer) * 8ULL;
@@ -443,8 +443,8 @@ class SizeClassAllocator64 {
       buffer_size =
           (RoundUpTo(n, 1ULL << packing_ratio_log) >> packing_ratio_log) *
           sizeof(*buffer);
-      buffer = reinterpret_cast<u64*>(
-          memory_mapper->MapPackedCounterArrayBuffer(buffer_size));
+      buffer = reinterpret_cast<u64 *>(
+          mapper->MapPackedCounterArrayBuffer(buffer_size));
     }
 
     bool IsAllocated() const {
@@ -482,7 +482,6 @@ class SizeClassAllocator64 {
     u64 packing_ratio_log;
     u64 bit_offset_mask;
 
-    MemoryMapper *const memory_mapper;
     u64 buffer_size;
     u64* buffer;
   };
@@ -574,8 +573,8 @@ class SizeClassAllocator64 {
       UNREACHABLE("All chunk_size/page_size ratios must be handled.");
     }
 
-    PackedCounterArray<MemoryMapper> counters(
-        allocated_pages_count, full_pages_chunk_count_max, memory_mapper);
+    PackedCounterArray counters(allocated_pages_count,
+                                full_pages_chunk_count_max, memory_mapper);
     if (!counters.IsAllocated())
       return;
 

diff  --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
index a5076da5aa18..2e1f59c11def 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
@@ -1188,35 +1188,31 @@ class RedZoneMemoryMapper {
 
 TEST(SanitizerCommon, SizeClassAllocator64PackedCounterArray) {
   NoMemoryMapper no_memory_mapper;
-  typedef Allocator64::PackedCounterArray<NoMemoryMapper>
-      NoMemoryPackedCounterArray;
-
   for (int i = 0; i < 64; i++) {
     // Various valid counter's max values packed into one word.
-    NoMemoryPackedCounterArray counters_2n(1, 1ULL << i, &no_memory_mapper);
+    Allocator64::PackedCounterArray counters_2n(1, 1ULL << i,
+                                                &no_memory_mapper);
     EXPECT_EQ(8ULL, no_memory_mapper.last_request_buffer_size);
 
     // Check the "all bit set" values too.
-    NoMemoryPackedCounterArray counters_2n1_1(1, ~0ULL >> i, &no_memory_mapper);
+    Allocator64::PackedCounterArray counters_2n1_1(1, ~0ULL >> i,
+                                                   &no_memory_mapper);
     EXPECT_EQ(8ULL, no_memory_mapper.last_request_buffer_size);
 
     // Verify the packing ratio, the counter is expected to be packed into the
     // closest power of 2 bits.
-    NoMemoryPackedCounterArray counters(64, 1ULL << i, &no_memory_mapper);
+    Allocator64::PackedCounterArray counters(64, 1ULL << i, &no_memory_mapper);
     EXPECT_EQ(8ULL * RoundUpToPowerOfTwo(i + 1),
               no_memory_mapper.last_request_buffer_size);
   }
 
   RedZoneMemoryMapper memory_mapper;
-  typedef Allocator64::PackedCounterArray<RedZoneMemoryMapper>
-      RedZonePackedCounterArray;
   // Go through 1, 2, 4, 8, .. 64 bits per counter.
   for (int i = 0; i < 7; i++) {
     // Make sure counters request one memory page for the buffer.
     const u64 kNumCounters = (GetPageSize() / 8) * (64 >> i);
-    RedZonePackedCounterArray counters(kNumCounters,
-                                       1ULL << ((1 << i) - 1),
-                                       &memory_mapper);
+    Allocator64::PackedCounterArray counters(
+        kNumCounters, 1ULL << ((1 << i) - 1), &memory_mapper);
     counters.Inc(0);
     for (u64 c = 1; c < kNumCounters - 1; c++) {
       ASSERT_EQ(0ULL, counters.Get(c));


        


More information about the llvm-commits mailing list