[llvm-commits] [compiler-rt] r145838 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_interface.h asan_internal.h asan_rtl.cc asan_stats.cc tests/asan_interface_test.cc tests/asan_noinst_test.cc

Kostya Serebryany kcc at google.com
Mon Dec 5 11:17:53 PST 2011


Author: kcc
Date: Mon Dec  5 13:17:53 2011
New Revision: 145838

URL: http://llvm.org/viewvc/llvm-project?rev=145838&view=rev
Log:
[asan] always collect malloc statstics (removed FLAG_stats)

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator.cc
    compiler-rt/trunk/lib/asan/asan_interface.h
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/asan_stats.cc
    compiler-rt/trunk/lib/asan/tests/asan_interface_test.cc
    compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc

Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Mon Dec  5 13:17:53 2011
@@ -491,13 +491,12 @@
     m->next = free_lists_[size_class];
     free_lists_[size_class] = m;
 
-    if (FLAG_stats) {
-      AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
-      thread_stats.real_frees++;
-      thread_stats.really_freed += m->used_size;
-      thread_stats.really_freed_redzones += m->Size() - m->used_size;
-      thread_stats.really_freed_by_size[m->SizeClass()]++;
-    }
+    // Statistics.
+    AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
+    thread_stats.real_frees++;
+    thread_stats.really_freed += m->used_size;
+    thread_stats.really_freed_redzones += m->Size() - m->used_size;
+    thread_stats.really_freed_by_size[m->SizeClass()]++;
   }
 
   // Get a list of newly allocated chunks.
@@ -517,12 +516,13 @@
     }
     CHECK(n_chunks > 0);
     uint8_t *mem = MmapNewPagesAndPoisonShadow(mmap_size);
-    if (FLAG_stats) {
-      AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
-      thread_stats.mmaps++;
-      thread_stats.mmaped += mmap_size;
-      thread_stats.mmaped_by_size[size_class] += n_chunks;
-    }
+
+    // Statistics.
+    AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
+    thread_stats.mmaps++;
+    thread_stats.mmaped += mmap_size;
+    thread_stats.mmaped_by_size[size_class] += n_chunks;
+
     AsanChunk *res = NULL;
     for (size_t i = 0; i < n_chunks; i++) {
       AsanChunk *m = (AsanChunk*)(mem + i * size);
@@ -623,29 +623,24 @@
 
   AsanThread *t = asanThreadRegistry().GetCurrent();
   AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
-  if (FLAG_stats) {
-    thread_stats.mallocs++;
-    thread_stats.malloced += size;
-    thread_stats.malloced_redzones += size_to_allocate - size;
-    thread_stats.malloced_by_size[size_class]++;
-  }
+  // Statistics
+  thread_stats.mallocs++;
+  thread_stats.malloced += size;
+  thread_stats.malloced_redzones += size_to_allocate - size;
+  thread_stats.malloced_by_size[size_class]++;
 
   AsanChunk *m = NULL;
   if (!t || size_to_allocate >= kMaxSizeForThreadLocalFreeList) {
     // get directly from global storage.
     m = malloc_info.AllocateChunks(size_class, 1);
-    if (FLAG_stats) {
-      thread_stats.malloc_large++;
-    }
+    thread_stats.malloc_large++;
   } else {
     // get from the thread-local storage.
     AsanChunk **fl = &t->malloc_storage().free_lists_[size_class];
     if (!*fl) {
       size_t n_new_chunks = kMaxSizeForThreadLocalFreeList / size_to_allocate;
       *fl = malloc_info.AllocateChunks(size_class, n_new_chunks);
-      if (FLAG_stats) {
-        thread_stats.malloc_small_slow++;
-      }
+      thread_stats.malloc_small_slow++;
     }
     m = *fl;
     *fl = (*fl)->next;
@@ -714,12 +709,11 @@
   size_t rounded_size = RoundUpTo(m->used_size, REDZONE);
   PoisonShadow((uintptr_t)ptr, rounded_size, kAsanHeapFreeMagic);
 
-  if (FLAG_stats) {
-    AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
-    thread_stats.frees++;
-    thread_stats.freed += m->used_size;
-    thread_stats.freed_by_size[m->SizeClass()]++;
-  }
+  // Statistics.
+  AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
+  thread_stats.frees++;
+  thread_stats.freed += m->used_size;
+  thread_stats.freed_by_size[m->SizeClass()]++;
 
   m->chunk_state = CHUNK_QUARANTINE;
   if (t) {
@@ -739,11 +733,12 @@
 static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size,
                            AsanStackTrace *stack) {
   CHECK(old_ptr && new_size);
-  if (FLAG_stats) {
-    AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
-    thread_stats.reallocs++;
-    thread_stats.realloced += new_size;
-  }
+
+  // Statistics.
+  AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
+  thread_stats.reallocs++;
+  thread_stats.realloced += new_size;
+
   AsanChunk *m = PtrToChunk((uintptr_t)old_ptr);
   CHECK(m->chunk_state == CHUNK_ALLOCATED);
   size_t old_size = m->used_size;

Modified: compiler-rt/trunk/lib/asan/asan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interface.h?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interface.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interface.h Mon Dec  5 13:17:53 2011
@@ -126,8 +126,6 @@
   // Number of bytes in unmapped pages, that are released to OS. Currently,
   // always returns 0.
   size_t __asan_get_unmapped_bytes();
-  // Turns on/off statistics update. Returns the previous value.
-  bool __asan_enable_statistics(bool enable);
   // Prints accumulated stats to stderr. Used for debugging.
   void __asan_print_accumulated_stats();
 }  // namespace

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Mon Dec  5 13:17:53 2011
@@ -97,7 +97,6 @@
 extern bool   FLAG_poison_shadow;
 extern int    FLAG_report_globals;
 extern size_t FLAG_malloc_context_size;
-extern bool   FLAG_stats;
 extern bool   FLAG_replace_str;
 extern bool   FLAG_replace_intrin;
 extern bool   FLAG_replace_cfallocator;

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Dec  5 13:17:53 2011
@@ -73,7 +73,6 @@
 bool   FLAG_replace_str;
 bool   FLAG_replace_intrin;
 bool   FLAG_replace_cfallocator;  // Used on Mac only.
-bool   FLAG_stats;
 size_t FLAG_max_malloc_fill_size = 0;
 bool   FLAG_use_fake_stack;
 int    FLAG_exitcode = EXIT_FAILURE;
@@ -661,7 +660,6 @@
   FLAG_handle_segv = IntFlagValue(options, "handle_segv=",
                                          ASAN_NEEDS_SEGV);
   FLAG_handle_sigill = IntFlagValue(options, "handle_sigill=", 0);
-  FLAG_stats = IntFlagValue(options, "stats=", 0);
   FLAG_symbolize = IntFlagValue(options, "symbolize=", 1);
   FLAG_demangle = IntFlagValue(options, "demangle=", 1);
   FLAG_debug = IntFlagValue(options, "debug=", 0);

Modified: compiler-rt/trunk/lib/asan/asan_stats.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stats.cc?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stats.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stats.cc Mon Dec  5 13:17:53 2011
@@ -56,7 +56,6 @@
 static AsanLock print_lock(LINKER_INITIALIZED);
 
 static void PrintAccumulatedStats() {
-  if (!FLAG_stats) return;
   AsanStats stats = asanThreadRegistry().GetAccumulatedStats();
   // Use lock to keep reports from mixing up.
   ScopedLock lock(&print_lock);
@@ -84,12 +83,6 @@
   return 0;
 }
 
-bool __asan_enable_statistics(bool enable) {
-  bool old_flag = FLAG_stats;
-  FLAG_stats = enable;
-  return old_flag;
-}
-
 void __asan_print_accumulated_stats() {
   PrintAccumulatedStats();
 }

Modified: compiler-rt/trunk/lib/asan/tests/asan_interface_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_interface_test.cc?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_interface_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_interface_test.cc Mon Dec  5 13:17:53 2011
@@ -63,17 +63,10 @@
   delete int_ptr;
 }
 
-TEST(AddressSanitizerInterface, EnableStatisticsTest) {
-  bool old_stats_value = __asan_enable_statistics(true);
-  EXPECT_EQ(true, __asan_enable_statistics(false));
-  EXPECT_EQ(false, __asan_enable_statistics(old_stats_value));
-}
-
 TEST(AddressSanitizerInterface, GetCurrentAllocatedBytesTest) {
   size_t before_malloc, after_malloc, after_free;
   char *array;
   const size_t kMallocSize = 100;
-  bool old_stats_value = __asan_enable_statistics(true);
   before_malloc = __asan_get_current_allocated_bytes();
 
   array = Ident((char*)malloc(kMallocSize));
@@ -83,14 +76,6 @@
   free(array);
   after_free = __asan_get_current_allocated_bytes();
   EXPECT_EQ(before_malloc, after_free);
-
-  __asan_enable_statistics(false);
-  array = Ident((char*)malloc(kMallocSize));
-  after_malloc = __asan_get_current_allocated_bytes();
-  EXPECT_EQ(before_malloc, after_malloc);
-
-  free(array);
-  __asan_enable_statistics(old_stats_value);
 }
 
 static void DoDoubleFree() {
@@ -106,7 +91,6 @@
   size_t old_heap_size, new_heap_size, heap_growth;
   // We unlikely have have chunk of this size in free list.
   static const size_t kLargeMallocSize = 1 << 29;  // 512M
-  __asan_enable_statistics(true);
   old_heap_size = __asan_get_heap_size();
   fprintf(stderr, "allocating %zu bytes:\n", kLargeMallocSize);
   free(Ident(malloc(kLargeMallocSize)));
@@ -136,7 +120,6 @@
 static void DoLargeMallocForGetFreeBytesTestAndDie() {
   size_t old_free_bytes, new_free_bytes;
   static const size_t kLargeMallocSize = 1 << 29;  // 512M
-  __asan_enable_statistics(true);
   // If we malloc and free a large memory chunk, it will not fall
   // into quarantine and will be available for future requests.
   old_free_bytes = __asan_get_free_bytes();
@@ -156,7 +139,6 @@
   char *chunks[kNumOfChunks];
   size_t i;
   size_t old_free_bytes, new_free_bytes;
-  bool old_stats_value = __asan_enable_statistics(true);
   // Allocate a small chunk. Now allocator probably has a lot of these
   // chunks to fulfill future requests. So, future requests will decrease
   // the number of free bytes.
@@ -175,7 +157,6 @@
     EXPECT_EQ(old_free_bytes, __asan_get_free_bytes());
   }
   EXPECT_DEATH(DoLargeMallocForGetFreeBytesTestAndDie(), "double-free");
-  __asan_enable_statistics(old_stats_value);
 }
 
 static const size_t kManyThreadsMallocSizes[] = {5, 1UL<<10, 1UL<<20, 357};
@@ -194,7 +175,6 @@
 TEST(AddressSanitizerInterface, ManyThreadsWithStatsStressTest) {
   size_t before_test, after_test, i;
   pthread_t threads[kManyThreadsNumThreads];
-  bool old_stats_value = __asan_enable_statistics(true);
   before_test = __asan_get_current_allocated_bytes();
   for (i = 0; i < kManyThreadsNumThreads; i++) {
     pthread_create(&threads[i], 0,
@@ -207,7 +187,6 @@
   // ASan stats also reflect memory usage of internal ASan RTL structs,
   // so we can't check for equality here.
   EXPECT_LT(after_test, before_test + (1UL<<20));
-  __asan_enable_statistics(old_stats_value);
 }
 
 TEST(AddressSanitizerInterface, ExitCode) {

Modified: compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=145838&r1=145837&r2=145838&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc Mon Dec  5 13:17:53 2011
@@ -290,7 +290,6 @@
 // destroyed.
 TEST(AddressSanitizer, ThreadedQuarantineTest) {
   const int n_threads = 3000;
-  bool old_flag_stats = __asan_enable_statistics(true);
   size_t mmaped1 = __asan_get_heap_size();
   for (int i = 0; i < n_threads; i++) {
     pthread_t t;
@@ -299,7 +298,6 @@
     size_t mmaped2 = __asan_get_heap_size();
     EXPECT_LT(mmaped2 - mmaped1, 320U * (1 << 20));
   }
-  __asan_enable_statistics(old_flag_stats);
 }
 
 void *ThreadedOneSizeMallocStress(void *unused) {





More information about the llvm-commits mailing list