[compiler-rt] r195570 - [lsan] Use real memset to clear memory in standalone LSan.
Sergey Matveev
earthdok at google.com
Sun Nov 24 06:28:19 PST 2013
Author: smatveev
Date: Sun Nov 24 08:28:18 2013
New Revision: 195570
URL: http://llvm.org/viewvc/llvm-project?rev=195570&view=rev
Log:
[lsan] Use real memset to clear memory in standalone LSan.
Performance improvement. Also, the allocator was using CompactSizeClassMap for
no good reason, so I switched it to DefaultSizeClassMap.
Modified:
compiler-rt/trunk/lib/lsan/lsan_allocator.cc
Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=195570&r1=195569&r2=195570&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Sun Nov 24 08:28:18 2013
@@ -20,6 +20,8 @@
#include "sanitizer_common/sanitizer_stacktrace.h"
#include "lsan_common.h"
+extern "C" void *memset(void *ptr, int value, uptr num);
+
namespace __lsan {
static const uptr kMaxAllowedMallocSize = 8UL << 30;
@@ -34,7 +36,7 @@ struct ChunkMetadata {
};
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize,
- sizeof(ChunkMetadata), CompactSizeClassMap> PrimaryAllocator;
+ sizeof(ChunkMetadata), DefaultSizeClassMap> PrimaryAllocator;
typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
typedef LargeMmapAllocator<> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
@@ -80,7 +82,10 @@ void *Allocate(const StackTrace &stack,
Report("WARNING: LeakSanitizer failed to allocate %zu bytes\n", size);
return 0;
}
- void *p = allocator.Allocate(&cache, size, alignment, cleared);
+ void *p = allocator.Allocate(&cache, size, alignment, false);
+ // Do not rely on the allocator to clear the memory (it's slow).
+ if (cleared && allocator.FromPrimary(p))
+ memset(p, 0, size);
RegisterAllocation(stack, p, size);
return p;
}
More information about the llvm-commits
mailing list