[llvm-commits] [compiler-rt] r169503 - /compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h

Kostya Serebryany kcc at google.com
Thu Dec 6 05:34:11 PST 2012


Author: kcc
Date: Thu Dec  6 07:34:11 2012
New Revision: 169503

URL: http://llvm.org/viewvc/llvm-project?rev=169503&view=rev
Log:
[asan/msan] refactor allocator's BulkAllocate (move to AllocatorFreeList) 

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

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=169503&r1=169502&r2=169503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Thu Dec  6 07:34:11 2012
@@ -97,7 +97,26 @@
   AllocatorListNode *next;
 };
 
-typedef IntrusiveList<AllocatorListNode> AllocatorFreeList;
+class AllocatorFreeList: public IntrusiveList<AllocatorListNode> {
+ public:
+  // Move at most max_count chunks to other_free_list.
+  void BulkAllocate(uptr max_count, AllocatorFreeList *other_free_list) {
+    CHECK(!empty());
+    CHECK(other_free_list->empty());
+    if (size() <= max_count) {
+      other_free_list->append_front(this);
+      CHECK(empty());
+    } else {
+      for (uptr i = 0; i < max_count; i++) {
+        AllocatorListNode *node = front();
+        pop_front();
+        other_free_list->push_front(node);
+      }
+      CHECK(!empty());
+    }
+    CHECK(!other_free_list->empty());
+  }
+};
 
 // SizeClassAllocator64 -- allocator for 64-bit address space.
 //
@@ -146,18 +165,8 @@
     if (region->free_list.empty()) {
       PopulateFreeList(class_id, region);
     }
-    CHECK(!region->free_list.empty());
-    uptr count = SizeClassMap::MaxCached(class_id);
-    if (region->free_list.size() <= count) {
-      free_list->append_front(&region->free_list);
-    } else {
-      for (uptr i = 0; i < count; i++) {
-        AllocatorListNode *node = region->free_list.front();
-        region->free_list.pop_front();
-        free_list->push_front(node);
-      }
-    }
-    CHECK(!free_list->empty());
+    region->free_list.BulkAllocate(
+        SizeClassMap::MaxCached(class_id), free_list);
   }
 
   // Swallow the entire free_list for the given class_id.





More information about the llvm-commits mailing list