diff options
author | Kostya Serebryany <kcc@google.com> | 2012-12-04 14:15:17 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-12-04 14:15:17 +0000 |
commit | f299288f55f2f8c6ca56c3d18bfabb74b0ea590a (patch) | |
tree | dd7ac31dcf855e13168e15ed53a35e8bdc9f6f27 | |
parent | 4ef6b2bd037caa6702510f21b5a9a0100bb49e4b (diff) | |
download | bcm5719-llvm-f299288f55f2f8c6ca56c3d18bfabb74b0ea590a.tar.gz bcm5719-llvm-f299288f55f2f8c6ca56c3d18bfabb74b0ea590a.zip |
[tsan] minor interface refactoring
llvm-svn: 169267
4 files changed, 9 insertions, 8 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h index 23952f6eb3c..58d28604a72 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h @@ -41,11 +41,13 @@ class SplineSizeClassMap { static const uptr u4 = u3 + (l5 - l4) / s4; public: + // The number of size classes should be a power of two for fast division. static const uptr kNumClasses = u4 + 1; static const uptr kMaxSize = l5; static const uptr kMinSize = l0; COMPILER_CHECK(kNumClasses <= 256); + COMPILER_CHECK((kNumClasses & (kNumClasses - 1)) == 0); COMPILER_CHECK((kMaxSize & (kMaxSize - 1)) == 0); static uptr Size(uptr class_id) { @@ -100,9 +102,10 @@ typedef IntrusiveList<AllocatorListNode> AllocatorFreeList; // Objects of this type should be used as local caches for SizeClassAllocator64. // Since the typical use of this class is to have one object per thread in TLS, // is has to be POD. -template<const uptr kNumClasses, class SizeClassAllocator> +template<class SizeClassAllocator> struct SizeClassAllocatorLocalCache { typedef SizeClassAllocator Allocator; + static const uptr kNumClasses = SizeClassAllocator::kNumClasses; // Don't need to call Init if the object is a global (i.e. zero-initialized). void Init() { internal_memset(this, 0, sizeof(*this)); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h index 6314be919f6..68707448b62 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h @@ -139,8 +139,8 @@ class SizeClassAllocator64 { static uptr AllocBeg() { return kSpaceBeg; } static uptr AllocSize() { return kSpaceSize + AdditionalSize(); } - static const uptr kNumClasses = 256; // Power of two <= 256 typedef SizeClassMap SizeClassMapT; + static const uptr kNumClasses = SizeClassMap::kNumClasses; // 2^k <= 256 private: COMPILER_CHECK(kSpaceBeg % kSpaceSize == 0); 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 57e4045b848..68b730df4cc 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc @@ -260,7 +260,7 @@ void TestCombinedAllocator() { TEST(SanitizerCommon, CombinedAllocator) { TestCombinedAllocator<Allocator64, LargeMmapAllocator, - SizeClassAllocatorLocalCache<Allocator64::kNumClasses, Allocator64> > (); + SizeClassAllocatorLocalCache<Allocator64> > (); } template <class AllocatorCache> @@ -295,7 +295,6 @@ void TestSizeClassAllocatorLocalCache() { } TEST(SanitizerCommon, SizeClassAllocator64LocalCache) { - typedef SizeClassAllocatorLocalCache<Allocator64::kNumClasses, Allocator64> - AllocatorCache; - TestSizeClassAllocatorLocalCache<AllocatorCache> (); + TestSizeClassAllocatorLocalCache< + SizeClassAllocatorLocalCache<Allocator64> >(); } diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index 8366ef012ab..8437ab55bdf 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -58,8 +58,7 @@ const uptr kAllocatorSize = 0x10000000000ULL; // 1T. typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, sizeof(MBlock), DefaultSizeClassMap> PrimaryAllocator; -typedef SizeClassAllocatorLocalCache<PrimaryAllocator::kNumClasses, - PrimaryAllocator> AllocatorCache; +typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache; typedef LargeMmapAllocator SecondaryAllocator; typedef CombinedAllocator<PrimaryAllocator, AllocatorCache, SecondaryAllocator> Allocator; |