Chromium Code Reviews| Index: third_party/tcmalloc/chromium/src/memory_region_map.h |
| diff --git a/third_party/tcmalloc/chromium/src/memory_region_map.h b/third_party/tcmalloc/chromium/src/memory_region_map.h |
| index 988ea707375aed124136fe0bb7db105dbb2952a7..843d852cfc1447611e3412fb28066098681b65bd 100644 |
| --- a/third_party/tcmalloc/chromium/src/memory_region_map.h |
| +++ b/third_party/tcmalloc/chromium/src/memory_region_map.h |
| @@ -45,6 +45,7 @@ |
| #include "base/spinlock.h" |
| #include "base/thread_annotations.h" |
| #include "base/low_level_alloc.h" |
| +#include "heap-profile-stats.h" |
| // TODO(maxim): add a unittest: |
| // execute a bunch of mmaps and compare memory map what strace logs |
| @@ -72,6 +73,8 @@ class MemoryRegionMap { |
| // don't take the address of it! |
| static const int kMaxStackDepth = 32; |
| + static const int kHashTableSize = 179999; |
| + |
| public: |
| // interface ================================================================ |
| @@ -91,7 +94,7 @@ class MemoryRegionMap { |
| // and initialize arena_ and our hook and locks, hence one can use |
| // MemoryRegionMap::Lock()/Unlock() to manage the locks. |
| // Uses Lock/Unlock inside. |
| - static void Init(int max_stack_depth); |
| + static void Init(int max_stack_depth, bool use_buckets); |
| // Try to shutdown this module undoing what Init() did. |
| // Returns true iff could do full shutdown (or it was not attempted). |
| @@ -99,6 +102,8 @@ class MemoryRegionMap { |
| // the number of Init() calls. |
| static bool Shutdown(); |
| + static bool IsWorking(); |
| + |
| // Locks to protect our internal data structures. |
| // These also protect use of arena_ if our Init() has been done. |
| // The lock is recursive. |
| @@ -118,6 +123,10 @@ class MemoryRegionMap { |
| DISALLOW_COPY_AND_ASSIGN(LockHolder); |
| }; |
| + // Profile stats. |
| + typedef HeapProfileStats::Stats Stats; |
| + typedef HeapProfileStats::Bucket Bucket; |
| + |
| // A memory region that we know about through malloc_hook-s. |
| // This is essentially an interface through which MemoryRegionMap |
| // exports the collected data to its clients. Thread-compatible. |
| @@ -214,6 +223,11 @@ class MemoryRegionMap { |
| // Returns success. Uses Lock/Unlock inside. |
| static bool FindAndMarkStackRegion(uintptr_t stack_top, Region* result); |
| + template<class Type> |
| + static void IterateBuckets(void (*callback)(const Bucket*, Type), Type arg); |
| + |
| + static Bucket* GetBucket(int depth, const void* const key[]); |
| + |
| private: // our internal types ============================================== |
| // Region comparator for sorting with STL |
| @@ -295,6 +309,21 @@ class MemoryRegionMap { |
| // Total size of all unmapped pages so far |
| static int64 unmap_size_; |
| + // Bucket hash table. |
| + static Bucket** bucket_table_; |
| + static int num_buckets_; |
| + |
| + // Number of unprocessed bucket inserts. |
| + static int saved_buckets_count_; |
| + |
| + // Unprocessed inserts (must be big enough to hold all mmaps that can be |
| + // caused by a GetBucket call). |
| + // Bucket has no constructor, so that c-tor execution does not interfere |
| + // with the any-time use of the static memory behind saved_buckets. |
| + static Bucket saved_buckets_[20]; |
| + |
| + static const void* saved_buckets_keys_[20][kMaxStackDepth]; |
| + |
| // helpers ================================================================== |
| // Helper for FindRegion and FindAndMarkStackRegion: |
| @@ -308,6 +337,9 @@ class MemoryRegionMap { |
| // by calling insert_func on them. |
| inline static void HandleSavedRegionsLocked( |
| void (*insert_func)(const Region& region)); |
| + |
| + inline static void HandleSavedBucketsLocked(); |
| + |
| // Wrapper around DoInsertRegionLocked |
| // that handles the case of recursive allocator calls. |
| inline static void InsertRegionLocked(const Region& region); |
| @@ -337,4 +369,14 @@ class MemoryRegionMap { |
| DISALLOW_COPY_AND_ASSIGN(MemoryRegionMap); |
| }; |
| +template <class Type> |
| +void MemoryRegionMap::IterateBuckets( |
| + void (*callback)(const Bucket*, Type), Type arg) { |
| + for (int b = 0; b < kHashTableSize; b++) { |
| + for (Bucket* x = bucket_table_[b]; x != 0; x = x->next) { |
|
Alexander Potapenko
2013/03/07 06:08:25
x != NULL this is.
Dai Mikurube (NOT FULLTIME)
2013/03/07 12:32:16
Done.
|
| + callback(x, arg); |
| + } |
| + } |
| +} |
| + |
| #endif // BASE_MEMORY_REGION_MAP_H_ |