diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h index 1e540a180d4ec..952b069763625 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 class PackedCounterArray { public: + template 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( - memory_mapper->MapPackedCounterArrayBuffer(buffer_size)); + buffer = reinterpret_cast( + 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 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 a5076da5aa18f..2e1f59c11def9 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 - 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 - 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));