[tsan] minor interface refactoring
authorKostya Serebryany <kcc@google.com>
Tue, 4 Dec 2012 14:15:17 +0000 (14:15 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 4 Dec 2012 14:15:17 +0000 (14:15 +0000)
llvm-svn: 169267

compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
compiler-rt/lib/sanitizer_common/sanitizer_allocator64.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc
compiler-rt/lib/tsan/rtl/tsan_rtl.h

index 23952f6..58d2860 100644 (file)
@@ -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));
index 6314be9..6870744 100644 (file)
@@ -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);
index 57e4045..68b730d 100644 (file)
@@ -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> >();
 }
index 8366ef0..8437ab5 100644 (file)
@@ -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;