summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_local_cache.h16
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_primary32.h25
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_primary64.h12
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_size_class_map.h21
4 files changed, 34 insertions, 40 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_local_cache.h b/lib/sanitizer_common/sanitizer_allocator_local_cache.h
index 780c45c0c..5c42707c6 100644
--- a/lib/sanitizer_common/sanitizer_allocator_local_cache.h
+++ b/lib/sanitizer_common/sanitizer_allocator_local_cache.h
@@ -109,10 +109,10 @@ struct SizeClassAllocatorLocalCache {
InitCache();
PerClass *c = &per_class_[class_id];
Batch *b = allocator->AllocateBatch(&stats_, this, class_id);
- CHECK_GT(b->Count(), 0);
- for (uptr i = 0; i < b->Count(); i++)
- c->batch[i] = b->Get(i);
- c->count = b->Count();
+ CHECK_GT(b->count, 0);
+ for (uptr i = 0; i < b->count; i++)
+ c->batch[i] = b->batch[i];
+ c->count = b->count;
DestroyBatch(class_id, allocator, b);
}
@@ -121,11 +121,13 @@ struct SizeClassAllocatorLocalCache {
PerClass *c = &per_class_[class_id];
Batch *b = CreateBatch(class_id, allocator, (Batch*)c->batch[0]);
uptr cnt = Min(c->max_count / 2, c->count);
- b->SetFromArray(c->batch, cnt);
- for (uptr i = 0; i < cnt; i++)
+ for (uptr i = 0; i < cnt; i++) {
+ b->batch[i] = c->batch[i];
c->batch[i] = c->batch[i + c->max_count / 2];
-
+ }
+ b->count = cnt;
c->count -= cnt;
+ CHECK_GT(b->count, 0);
allocator->DeallocateBatch(&stats_, class_id, b);
}
};
diff --git a/lib/sanitizer_common/sanitizer_allocator_primary32.h b/lib/sanitizer_common/sanitizer_allocator_primary32.h
index 50d7985b8..4b4574c1e 100644
--- a/lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ b/lib/sanitizer_common/sanitizer_allocator_primary32.h
@@ -96,7 +96,7 @@ class SizeClassAllocator32 {
CHECK_LT(class_id, kNumClasses);
SizeClassInfo *sci = GetSizeClassInfo(class_id);
SpinMutexLock l(&sci->mutex);
- CHECK_GT(b->Count(), 0);
+ CHECK_GT(b->count, 0);
sci->free_list.push_front(b);
}
@@ -229,15 +229,20 @@ class SizeClassAllocator32 {
uptr n_chunks = kRegionSize / (size + kMetadataSize);
uptr max_count = SizeClassMap::MaxCached(class_id);
Batch *b = nullptr;
-
- uptr beg = reg;
- uptr remaining_chunks = n_chunks;
- while (remaining_chunks) {
- b = c->CreateBatch(class_id, this, (Batch*)beg);
- uptr count = Min(remaining_chunks, max_count);
- b->SetFromRange(0, beg, size, count);
- remaining_chunks -= count;
- beg += count * size;
+ for (uptr i = reg; i < reg + n_chunks * size; i += size) {
+ if (!b) {
+ b = c->CreateBatch(class_id, this, (Batch*)i);
+ b->count = 0;
+ }
+ b->batch[b->count++] = (void*)i;
+ if (b->count == max_count) {
+ CHECK_GT(b->count, 0);
+ sci->free_list.push_back(b);
+ b = nullptr;
+ }
+ }
+ if (b) {
+ CHECK_GT(b->count, 0);
sci->free_list.push_back(b);
}
}
diff --git a/lib/sanitizer_common/sanitizer_allocator_primary64.h b/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 754962837..cc374109e 100644
--- a/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -76,15 +76,15 @@ class SizeClassAllocator64 {
Batch *b = region->free_list.Pop();
if (!b)
b = PopulateFreeList(stat, c, class_id, region);
- region->n_allocated += b->Count();
+ region->n_allocated += b->count;
return b;
}
NOINLINE void DeallocateBatch(AllocatorStats *stat, uptr class_id, Batch *b) {
RegionInfo *region = GetRegionInfo(class_id);
- CHECK_GT(b->Count(), 0);
+ CHECK_GT(b->count, 0);
region->free_list.Push(b);
- region->n_freed += b->Count();
+ region->n_freed += b->count;
}
bool PointerIsMine(const void *p) {
@@ -310,13 +310,15 @@ class SizeClassAllocator64 {
}
for (;;) {
b = c->CreateBatch(class_id, this, (Batch*)(region_beg + beg_idx));
- b->SetFromRange(region_beg, beg_idx, size, count);
+ b->count = count;
+ for (uptr i = 0; i < count; i++)
+ b->batch[i] = (void*)(region_beg + beg_idx + i * size);
region->allocated_user += count * size;
CHECK_LE(region->allocated_user, region->mapped_user);
beg_idx += count * size;
if (beg_idx + count * size + size > region->mapped_user)
break;
- CHECK_GT(b->Count(), 0);
+ CHECK_GT(b->count, 0);
region->free_list.Push(b);
}
return b;
diff --git a/lib/sanitizer_common/sanitizer_allocator_size_class_map.h b/lib/sanitizer_common/sanitizer_allocator_size_class_map.h
index 88c74fe01..212614b2d 100644
--- a/lib/sanitizer_common/sanitizer_allocator_size_class_map.h
+++ b/lib/sanitizer_common/sanitizer_allocator_size_class_map.h
@@ -96,25 +96,9 @@ class SizeClassMap {
// For large size classes we use one of the chunks to store the batch.
// sizeof(TransferBatch) must be a power of 2 for more efficient allocation.
struct TransferBatch {
- void SetFromRange(uptr region_beg, uptr beg_offset, uptr step, uptr count) {
- count_ = count;
- for (uptr i = 0; i < count; i++)
- batch_[i] = (void*)(region_beg + beg_offset + i * step);
- }
- void SetFromArray(void *batch[], uptr count) {
- count_ = count;
- for (uptr i = 0; i < count; i++)
- batch_[i] = batch[i];
- }
- void *Get(uptr idx) {
- CHECK_LT(idx, count_);
- return batch_[idx];
- }
- uptr Count() const { return count_; }
TransferBatch *next;
- private:
- uptr count_;
- void *batch_[kMaxNumCached];
+ uptr count;
+ void *batch[kMaxNumCached];
};
static const uptr kBatchSize = sizeof(TransferBatch);
COMPILER_CHECK((kBatchSize & (kBatchSize - 1)) == 0);
@@ -225,3 +209,4 @@ class SizeClassMap {
typedef SizeClassMap<17, 126, 16> DefaultSizeClassMap;
typedef SizeClassMap<17, 62, 14> CompactSizeClassMap;
template<class SizeClassAllocator> struct SizeClassAllocatorLocalCache;
+