From 485f7b4a70eafc299b8e31cf37f3ef3c7e904592 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Mon, 3 Dec 2012 15:00:33 +0000 Subject: [PATCH] [tsan] add CompactSizeClassMap as an alternative (more compact) size class map. Not used yet. llvm-svn: 169128 --- .../lib/sanitizer_common/sanitizer_allocator64.h | 42 +++++++++++----------- .../tests/sanitizer_allocator64_test.cc | 17 ++++++--- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h index f045bde..e3a395b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h @@ -30,7 +30,10 @@ namespace __sanitizer { // Maps size class id to size and back. -class DefaultSizeClassMap { +template +class SplineSizeClassMap { private: // Here we use a spline composed of 5 polynomials of oder 1. // The first size class is l0, then the classes go with step s0 @@ -38,32 +41,12 @@ class DefaultSizeClassMap { // Steps should be powers of two for cheap division. // The size of the last size class should be a power of two. // There should be at most 256 size classes. - static const uptr l0 = 1 << 4; - static const uptr l1 = 1 << 9; - static const uptr l2 = 1 << 12; - static const uptr l3 = 1 << 15; - static const uptr l4 = 1 << 18; - static const uptr l5 = 1 << 21; - - static const uptr s0 = 1 << 4; - static const uptr s1 = 1 << 6; - static const uptr s2 = 1 << 9; - static const uptr s3 = 1 << 12; - static const uptr s4 = 1 << 15; - static const uptr u0 = 0 + (l1 - l0) / s0; static const uptr u1 = u0 + (l2 - l1) / s1; static const uptr u2 = u1 + (l3 - l2) / s2; static const uptr u3 = u2 + (l4 - l3) / s3; static const uptr u4 = u3 + (l5 - l4) / s4; - // Max cached in local cache blocks. - static const uptr c0 = 256; - static const uptr c1 = 64; - static const uptr c2 = 16; - static const uptr c3 = 4; - static const uptr c4 = 1; - public: static const uptr kNumClasses = u4 + 1; static const uptr kMaxSize = l5; @@ -99,13 +82,28 @@ class DefaultSizeClassMap { } }; +class DefaultSizeClassMap: public SplineSizeClassMap< + /* l: */1 << 4, 1 << 9, 1 << 12, 1 << 15, 1 << 18, 1 << 21, + /* s: */1 << 4, 1 << 6, 1 << 9, 1 << 12, 1 << 15, + /* c: */256, 64, 16, 4, 1> { + private: + COMPILER_CHECK(kNumClasses == 256); +}; + +class CompactSizeClassMap: public SplineSizeClassMap< + /* l: */1 << 3, 1 << 4, 1 << 7, 1 << 8, 1 << 12, 1 << 15, + /* s: */1 << 3, 1 << 4, 1 << 7, 1 << 8, 1 << 12, + /* c: */256, 64, 16, 4, 1> { + private: + COMPILER_CHECK(kNumClasses <= 32); +}; + struct AllocatorListNode { AllocatorListNode *next; }; typedef IntrusiveList AllocatorFreeList; - // Space: a portion of address space of kSpaceSize bytes starting at // a fixed address (kSpaceBeg). Both constants are powers of two and // kSpaceBeg is kSpaceSize-aligned. diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc index de7092f..de6491d 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc @@ -23,15 +23,16 @@ typedef typedef SizeClassAllocatorLocalCache AllocatorCache; -TEST(SanitizerCommon, DefaultSizeClassMap) { +template +void TestSizeClassMap() { + typedef SizeClassMap SCMap; #if 0 for (uptr i = 0; i < SCMap::kNumClasses; i++) { - printf("c%ld => %ld cached=%ld(%ld)\n", - i, SCMap::Size(i), SCMap::MaxCached(i) * SCMap::Size(i), + printf("c%ld => %ld (%lx) cached=%ld(%ld)\n", + i, SCMap::Size(i), SCMap::Size(i), SCMap::MaxCached(i) * SCMap::Size(i), SCMap::MaxCached(i)); } #endif - for (uptr c = 0; c < SCMap::kNumClasses; c++) { uptr s = SCMap::Size(c); CHECK_EQ(SCMap::ClassID(s), c); @@ -52,6 +53,14 @@ TEST(SanitizerCommon, DefaultSizeClassMap) { } } +TEST(SanitizerCommon, DefaultSizeClassMap) { + TestSizeClassMap(); +} + +TEST(SanitizerCommon, CompactSizeClassMap) { + TestSizeClassMap(); +} + TEST(SanitizerCommon, SizeClassAllocator64) { Allocator a; a.Init(); -- 2.7.4