forked from OSchip/llvm-project
[asan] count the size of QuarantineBatch in the total Quarantine size; make QuarantineBatch fit into 8K, fix a MSVC compile warning
llvm-svn: 193072
This commit is contained in:
parent
88033d7a97
commit
b773785a59
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue