| Index: third_party/tcmalloc/chromium/src/allocated_type_map.cc
|
| diff --git a/third_party/tcmalloc/chromium/src/allocated_type_map.cc b/third_party/tcmalloc/chromium/src/allocated_type_map.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..dd1ae64ec1f0a6f5dd18e08ffcc3ec856f391633
|
| --- /dev/null
|
| +++ b/third_party/tcmalloc/chromium/src/allocated_type_map.cc
|
| @@ -0,0 +1,89 @@
|
| +// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <config.h>
|
| +
|
| +#include <new>
|
| +#include <typeinfo>
|
| +
|
| +#include <gperftools/allocated_type_map.h>
|
| +
|
| +#include "addressmap-inl.h"
|
| +#include "base/logging.h"
|
| +#include "base/low_level_alloc.h"
|
| +#include "base/spinlock.h"
|
| +#include "tcmalloc_guard.h"
|
| +
|
| +static const TCMallocGuard tcmalloc_initializer;
|
| +
|
| +//----------------------------------------------------------------------
|
| +// Locking
|
| +//----------------------------------------------------------------------
|
| +
|
| +static SpinLock g_allocated_type_lock(SpinLock::LINKER_INITIALIZED);
|
| +
|
| +//----------------------------------------------------------------------
|
| +// Simple allocator for allocated type map's internal memory
|
| +//----------------------------------------------------------------------
|
| +
|
| +static LowLevelAlloc::Arena* g_allocated_type_map_memory = NULL;
|
| +
|
| +static void* AllocatedTypeMalloc(size_t bytes) {
|
| + return LowLevelAlloc::AllocWithArena(bytes, g_allocated_type_map_memory);
|
| +}
|
| +
|
| +static void AllocatedTypeFree(void* p) {
|
| + LowLevelAlloc::Free(p);
|
| +}
|
| +
|
| +//----------------------------------------------------------------------
|
| +// Profiling control/state data
|
| +//----------------------------------------------------------------------
|
| +
|
| +static AddressMap<AllocatedObject>* g_allocated_type_map = NULL;
|
| +
|
| +//----------------------------------------------------------------------
|
| +// Manage allocated type map
|
| +//----------------------------------------------------------------------
|
| +
|
| +static void InitializeAllocatedTypeMemory() {
|
| + if (g_allocated_type_map_memory != NULL) {
|
| + RAW_DCHECK(g_allocated_type_map != NULL, "AllocatedTypeMap is NULL");
|
| + return;
|
| + }
|
| +
|
| + g_allocated_type_map_memory =
|
| + LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena());
|
| +
|
| + g_allocated_type_map =
|
| + new(AllocatedTypeMalloc(sizeof(AddressMap<AllocatedObject>)))
|
| + AddressMap<AllocatedObject>(AllocatedTypeMalloc, AllocatedTypeFree);
|
| +}
|
| +
|
| +void InsertAllocatedType(void* address,
|
| + unsigned int size,
|
| + const std::type_info& type) {
|
| + SpinLockHolder lock(&g_allocated_type_lock);
|
| + InitializeAllocatedTypeMemory();
|
| +
|
| + g_allocated_type_map->Insert(address, AllocatedObject(size, &type));
|
| +}
|
| +
|
| +void EraseAllocatedType(void* address) {
|
| + SpinLockHolder lock(&g_allocated_type_lock);
|
| + InitializeAllocatedTypeMemory();
|
| +
|
| + AllocatedObject obj;
|
| + g_allocated_type_map->FindAndRemove(address, &obj);
|
| +}
|
| +
|
| +const std::type_info* LookupAllocatedType(const void* address) {
|
| + SpinLockHolder lock(&g_allocated_type_lock);
|
| + InitializeAllocatedTypeMemory();
|
| +
|
| + const AllocatedObject* found = g_allocated_type_map->Find(address);
|
| + if (found == NULL)
|
| + return NULL;
|
| + return found->type;
|
| +}
|
|
|