[llvm-commits] [compiler-rt] r169128 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_allocator64.h tests/sanitizer_allocator64_test.cc
Kostya Serebryany
kcc at google.com
Mon Dec 3 07:00:33 PST 2012
Author: kcc
Date: Mon Dec 3 09:00:33 2012
New Revision: 169128
URL: http://llvm.org/viewvc/llvm-project?rev=169128&view=rev
Log:
[tsan] add CompactSizeClassMap as an alternative (more compact) size class map. Not used yet.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h?rev=169128&r1=169127&r2=169128&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h Mon Dec 3 09:00:33 2012
@@ -30,7 +30,10 @@
namespace __sanitizer {
// Maps size class id to size and back.
-class DefaultSizeClassMap {
+template <uptr l0, uptr l1, uptr l2, uptr l3, uptr l4, uptr l5,
+ uptr s0, uptr s1, uptr s2, uptr s3, uptr s4,
+ uptr c0, uptr c1, uptr c2, uptr c3, uptr c4>
+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 @@
// 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: 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<AllocatorListNode> 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.
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc?rev=169128&r1=169127&r2=169128&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc Mon Dec 3 09:00:33 2012
@@ -23,15 +23,16 @@
typedef SizeClassAllocatorLocalCache<Allocator::kNumClasses, Allocator>
AllocatorCache;
-TEST(SanitizerCommon, DefaultSizeClassMap) {
+template <class SizeClassMap>
+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) {
+ TestSizeClassMap<DefaultSizeClassMap>();
+}
+
+TEST(SanitizerCommon, CompactSizeClassMap) {
+ TestSizeClassMap<CompactSizeClassMap>();
+}
+
TEST(SanitizerCommon, SizeClassAllocator64) {
Allocator a;
a.Init();
More information about the llvm-commits
mailing list