forked from OSchip/llvm-project
[tsan] add CompactSizeClassMap as an alternative (more compact) size class map. Not used yet.
llvm-svn: 169128
This commit is contained in:
parent
c1e1b26f0a
commit
485f7b4a70
|
@ -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 @@ 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<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.
|
||||
|
|
|
@ -23,15 +23,16 @@ typedef
|
|||
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) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(SanitizerCommon, DefaultSizeClassMap) {
|
||||
TestSizeClassMap<DefaultSizeClassMap>();
|
||||
}
|
||||
|
||||
TEST(SanitizerCommon, CompactSizeClassMap) {
|
||||
TestSizeClassMap<CompactSizeClassMap>();
|
||||
}
|
||||
|
||||
TEST(SanitizerCommon, SizeClassAllocator64) {
|
||||
Allocator a;
|
||||
a.Init();
|
||||
|
|
Loading…
Reference in New Issue