Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tcmalloc/metadata_object_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include "absl/base/const_init.h"
#include "absl/base/dynamic_annotations.h"
#include "absl/base/internal/spinlock.h"
#include "absl/base/nullability.h"
#include "absl/base/optimization.h"
#include "absl/base/thread_annotations.h"
#include "absl/functional/function_ref.h"
#include "tcmalloc/arena.h"
#include "tcmalloc/common.h"
#include "tcmalloc/internal/allocation_guard.h"
Expand Down Expand Up @@ -73,7 +75,16 @@ class MetadataObjectAllocator {

void Delete(T* p) ABSL_ATTRIBUTE_NONNULL() {
p->~T();
LockAndDeleteMemory(p);
AllocationGuardSpinLockHolder l(metadata_lock_);
DeleteMemory(p);
}

void Delete(absl::FunctionRef<T* absl_nullable()> callback) {
AllocationGuardSpinLockHolder l(metadata_lock_);
while (T* p = callback()) {
p->~T();
DeleteMemory(p);
}
}

[[nodiscard]] AllocatorStats stats() const {
Expand Down Expand Up @@ -117,9 +128,8 @@ class MetadataObjectAllocator {
return result;
}

void LockAndDeleteMemory(T* p) ABSL_ATTRIBUTE_NONNULL() {
AllocationGuardSpinLockHolder l(metadata_lock_);

void DeleteMemory(T* p) ABSL_ATTRIBUTE_NONNULL()
ABSL_EXCLUSIVE_LOCKS_REQUIRED(metadata_lock_) {
*(reinterpret_cast<void**>(p)) = free_list_;
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
// Poison the object on the freelist. We do not dereference it after this
Expand Down
13 changes: 9 additions & 4 deletions tcmalloc/stack_trace_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ StackTraceTable::StackTraceTable(ProfileType type)

StackTraceTable::~StackTraceTable() {
LinkedSample* cur = all_;
while (cur != nullptr) {
LinkedSample* next = cur->next;
tc_globals.linked_sample_allocator().Delete(cur);
cur = next;
if (cur == nullptr) {
return;
}
tc_globals.linked_sample_allocator().Delete([&]() -> LinkedSample* {
LinkedSample* s = cur;
if (s != nullptr) {
cur = s->next;
}
return s;
});
all_ = nullptr;
}

Expand Down
Loading