[compiler-rt] r193072 - [asan] count the size of QuarantineBatch in the total Quarantine size; make QuarantineBatch fit into 8K, fix a MSVC compile warning

Kostya Serebryany kcc at google.com
Mon Oct 21 01:36:11 PDT 2013


Author: kcc
Date: Mon Oct 21 03:36:10 2013
New Revision: 193072

URL: http://llvm.org/viewvc/llvm-project?rev=193072&view=rev
Log:
[asan] count the size of QuarantineBatch in the total Quarantine size; make QuarantineBatch fit into 8K, fix a MSVC compile warning

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h?rev=193072&r1=193071&r2=193072&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h Mon Oct 21 03:36:10 2013
@@ -26,13 +26,15 @@ namespace __sanitizer {
 template<typename Node> class QuarantineCache;
 
 struct QuarantineBatch {
-  static const uptr kSize = 1024;
+  static const uptr kSize = 1021;
   QuarantineBatch *next;
   uptr size;
   uptr count;
   void *batch[kSize];
 };
 
+COMPILER_CHECK(sizeof(QuarantineBatch) <= (1 << 13));  // 8Kb.
+
 // The callback interface is:
 // void Callback::Recycle(Node *ptr);
 // void *cb.Allocate(uptr size);
@@ -123,8 +125,10 @@ class QuarantineCache {
   }
 
   void Enqueue(Callback cb, void *ptr, uptr size) {
-    if (list_.empty() || list_.back()->count == QuarantineBatch::kSize)
+    if (list_.empty() || list_.back()->count == QuarantineBatch::kSize) {
       AllocBatch(cb);
+      size += sizeof(QuarantineBatch);  // Count the batch in Quarantine size.
+    }
     QuarantineBatch *b = list_.back();
     b->batch[b->count++] = ptr;
     b->size += size;
@@ -147,9 +151,7 @@ class QuarantineCache {
       return 0;
     QuarantineBatch *b = list_.front();
     list_.pop_front();
-    // FIXME: should probably add SizeSub method?
-    // See https://code.google.com/p/thread-sanitizer/issues/detail?id=20
-    SizeAdd(0 - b->size);
+    SizeSub(b->size);
     return b;
   }
 
@@ -160,6 +162,9 @@ class QuarantineCache {
   void SizeAdd(uptr add) {
     atomic_store(&size_, Size() + add, memory_order_relaxed);
   }
+  void SizeSub(uptr sub) {
+    atomic_store(&size_, Size() - sub, memory_order_relaxed);
+  }
 
   NOINLINE QuarantineBatch* AllocBatch(Callback cb) {
     QuarantineBatch *b = (QuarantineBatch *)cb.Allocate(sizeof(*b));





More information about the llvm-commits mailing list