<div dir="ltr">Do you plan to call InitIfLinkerInitialized() to another sanitizers that use linker-initialized allocator (e.g. ASan)?</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 17, 2014 at 3:06 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kcc<br>
Date: Wed Dec 17 17:06:36 2014<br>
New Revision: 224469<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=224469&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=224469&view=rev</a><br>
Log:<br>
[sanitizer] add CombinedAllocator::InitIfLinkerInitialized and use it in lsan: speeds up lsan start-up time by ~25%<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/lsan/lsan_allocator.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h<br>
<br>
Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=224469&r1=224468&r2=224469&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=224469&r1=224468&r2=224469&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)<br>
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Wed Dec 17 17:06:36 2014<br>
@@ -47,7 +47,7 @@ static Allocator allocator;<br>
 static THREADLOCAL AllocatorCache cache;<br>
<br>
 void InitializeAllocator() {<br>
-  allocator.Init(common_flags()->allocator_may_return_null);<br>
+  allocator.InitIfLinkerInitialized(common_flags()->allocator_may_return_null);<br>
 }<br>
<br>
 void AllocatorThreadFinish() {<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=224469&r1=224468&r2=224469&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=224469&r1=224468&r2=224469&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Wed Dec 17 17:06:36 2014<br>
@@ -211,6 +211,7 @@ class AllocatorStats {<br>
   void Init() {<br>
     internal_memset(this, 0, sizeof(*this));<br>
   }<br>
+  void InitIfLinkerInitialized() {}<br>
<br>
   void Add(AllocatorStat i, uptr v) {<br>
     v += atomic_load(&stats_[i], memory_order_relaxed);<br>
@@ -240,11 +241,14 @@ class AllocatorStats {<br>
 // Global stats, used for aggregation and querying.<br>
 class AllocatorGlobalStats : public AllocatorStats {<br>
  public:<br>
-  void Init() {<br>
-    internal_memset(this, 0, sizeof(*this));<br>
+  void InitIfLinkerInitialized() {<br>
     next_ = this;<br>
     prev_ = this;<br>
   }<br>
+  void Init() {<br>
+    internal_memset(this, 0, sizeof(*this));<br>
+    InitIfLinkerInitialized();<br>
+  }<br>
<br>
   void Register(AllocatorStats *s) {<br>
     SpinMutexLock l(&mu_);<br>
@@ -1002,12 +1006,16 @@ struct SizeClassAllocatorLocalCache {<br>
 template <class MapUnmapCallback = NoOpMapUnmapCallback><br>
 class LargeMmapAllocator {<br>
  public:<br>
-  void Init(bool may_return_null) {<br>
-    internal_memset(this, 0, sizeof(*this));<br>
+  void InitIfLinkerInitialized(bool may_return_null) {<br>
     page_size_ = GetPageSizeCached();<br>
     atomic_store(&may_return_null_, may_return_null, memory_order_relaxed);<br>
   }<br>
<br>
+  void Init(bool may_return_null) {<br>
+    internal_memset(this, 0, sizeof(*this));<br>
+    InitIfLinkerInitialized(may_return_null);<br>
+  }<br>
+<br>
   void *Allocate(AllocatorStats *stat, uptr size, uptr alignment) {<br>
     CHECK(IsPowerOfTwo(alignment));<br>
     uptr map_size = RoundUpMapSize(size);<br>
@@ -1253,11 +1261,21 @@ template <class PrimaryAllocator, class<br>
           class SecondaryAllocator>  // NOLINT<br>
 class CombinedAllocator {<br>
  public:<br>
-  void Init(bool may_return_null) {<br>
+  void InitCommon(bool may_return_null) {<br>
     primary_.Init();<br>
+    atomic_store(&may_return_null_, may_return_null, memory_order_relaxed);<br>
+  }<br>
+<br>
+  void InitIfLinkerInitialized(bool may_return_null) {<br>
+    secondary_.InitIfLinkerInitialized(may_return_null);<br>
+    stats_.InitIfLinkerInitialized();<br>
+    InitCommon(may_return_null);<br>
+  }<br>
+<br>
+  void Init(bool may_return_null) {<br>
     secondary_.Init(may_return_null);<br>
     stats_.Init();<br>
-    atomic_store(&may_return_null_, may_return_null, memory_order_relaxed);<br>
+    InitCommon(may_return_null);<br>
   }<br>
<br>
   void *Allocate(AllocatorCache *cache, uptr size, uptr alignment,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div>