diff options
author | Kostya Serebryany <kcc@google.com> | 2014-12-17 23:06:36 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2014-12-17 23:06:36 +0000 |
commit | 296f4b520813ea846c3711102bfd33739913000d (patch) | |
tree | 55af33478e621cf25fbfe97b36f93ee2a0cb70a0 /lib/sanitizer_common/sanitizer_allocator.h | |
parent | 95966b064a5b9f58a6c110e1b9eabf0052cbb876 (diff) | |
download | compiler-rt-296f4b520813ea846c3711102bfd33739913000d.tar.gz |
[sanitizer] add CombinedAllocator::InitIfLinkerInitialized and use it in lsan: speeds up lsan start-up time by ~25%
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator.h | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator.h b/lib/sanitizer_common/sanitizer_allocator.h index d0ae90b01..71930ba6b 100644 --- a/lib/sanitizer_common/sanitizer_allocator.h +++ b/lib/sanitizer_common/sanitizer_allocator.h @@ -211,6 +211,7 @@ class AllocatorStats { void Init() { internal_memset(this, 0, sizeof(*this)); } + void InitIfLinkerInitialized() {} void Add(AllocatorStat i, uptr v) { v += atomic_load(&stats_[i], memory_order_relaxed); @@ -240,11 +241,14 @@ class AllocatorStats { // Global stats, used for aggregation and querying. class AllocatorGlobalStats : public AllocatorStats { public: - void Init() { - internal_memset(this, 0, sizeof(*this)); + void InitIfLinkerInitialized() { next_ = this; prev_ = this; } + void Init() { + internal_memset(this, 0, sizeof(*this)); + InitIfLinkerInitialized(); + } void Register(AllocatorStats *s) { SpinMutexLock l(&mu_); @@ -1002,12 +1006,16 @@ struct SizeClassAllocatorLocalCache { template <class MapUnmapCallback = NoOpMapUnmapCallback> class LargeMmapAllocator { public: - void Init(bool may_return_null) { - internal_memset(this, 0, sizeof(*this)); + void InitIfLinkerInitialized(bool may_return_null) { page_size_ = GetPageSizeCached(); atomic_store(&may_return_null_, may_return_null, memory_order_relaxed); } + void Init(bool may_return_null) { + internal_memset(this, 0, sizeof(*this)); + InitIfLinkerInitialized(may_return_null); + } + void *Allocate(AllocatorStats *stat, uptr size, uptr alignment) { CHECK(IsPowerOfTwo(alignment)); uptr map_size = RoundUpMapSize(size); @@ -1253,11 +1261,21 @@ template <class PrimaryAllocator, class AllocatorCache, class SecondaryAllocator> // NOLINT class CombinedAllocator { public: - void Init(bool may_return_null) { + void InitCommon(bool may_return_null) { primary_.Init(); + atomic_store(&may_return_null_, may_return_null, memory_order_relaxed); + } + + void InitIfLinkerInitialized(bool may_return_null) { + secondary_.InitIfLinkerInitialized(may_return_null); + stats_.InitIfLinkerInitialized(); + InitCommon(may_return_null); + } + + void Init(bool may_return_null) { secondary_.Init(may_return_null); stats_.Init(); - atomic_store(&may_return_null_, may_return_null, memory_order_relaxed); + InitCommon(may_return_null); } void *Allocate(AllocatorCache *cache, uptr size, uptr alignment, |