[compiler-rt] r190661 - [asan] use TLS on Linux to get the FakeStack. Saves 15% performance

Kostya Serebryany kcc at google.com
Thu Sep 12 23:04:18 PDT 2013


Author: kcc
Date: Fri Sep 13 01:04:18 2013
New Revision: 190661

URL: http://llvm.org/viewvc/llvm-project?rev=190661&view=rev
Log:
[asan] use TLS on Linux to get the FakeStack. Saves 15% performance

Modified:
    compiler-rt/trunk/lib/asan/asan_fake_stack.cc

Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.cc?rev=190661&r1=190660&r2=190661&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Fri Sep 13 01:04:18 2013
@@ -122,10 +122,25 @@ NOINLINE void FakeStack::GC(uptr real_st
   needs_gc_ = false;
 }
 
-ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size, uptr real_stack) {
+static FakeStack *GetFakeStack() {
   AsanThread *t = GetCurrentThread();
-  if (!t) return real_stack;
-  FakeStack *fs = t->fake_stack();
+  if (!t) return 0;
+  return t->fake_stack();
+}
+
+static FakeStack *GetFakeStackFast() {
+#if SANITIZER_LINUX
+  static THREADLOCAL FakeStack *fake_stack;
+  if (!fake_stack)
+    fake_stack = GetFakeStack();
+  return fake_stack;
+#else
+  return GetFakeStack();
+#endif
+}
+
+ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size, uptr real_stack) {
+  FakeStack *fs = GetFakeStackFast();
   if (!fs) return real_stack;
   FakeFrame *ff = fs->Allocate(fs->stack_size_log(), class_id, real_stack);
   uptr ptr = reinterpret_cast<uptr>(ff);
@@ -136,9 +151,7 @@ ALWAYS_INLINE uptr OnMalloc(uptr class_i
 ALWAYS_INLINE void OnFree(uptr ptr, uptr class_id, uptr size, uptr real_stack) {
   if (ptr == real_stack)
     return;
-  AsanThread *t = GetCurrentThread();
-  if (!t) return;
-  FakeStack *fs = t->fake_stack();
+  FakeStack *fs = GetFakeStackFast();  // Must not be 0.
   FakeFrame *ff = reinterpret_cast<FakeFrame *>(ptr);
   fs->Deallocate(ff, fs->stack_size_log(), class_id, real_stack);
   SetShadow(ptr, size, class_id, kMagic8);





More information about the llvm-commits mailing list