| 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..644a7b25d50585513730bb5635ded681c4d32d4a 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;
 | 
| +  typedef HeapProfileBucket 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);
 | 
| @@ -319,6 +351,11 @@ class MemoryRegionMap {
 | 
|    // (called from our munmap/mremap/sbrk hooks).
 | 
|    static void RecordRegionRemoval(const void* start, size_t size);
 | 
|  
 | 
| +  // Record deletion of a memory region in a bucket.
 | 
| +  static void RecordRegionRemovalInBucket(int depth,
 | 
| +                                          const void* const key[],
 | 
| +                                          size_t size);
 | 
| +
 | 
|    // Hooks for MallocHook
 | 
|    static void MmapHook(const void* result,
 | 
|                         const void* start, size_t size,
 | 
| @@ -337,4 +374,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 != NULL; x = x->next) {
 | 
| +      callback(x, arg);
 | 
| +    }
 | 
| +  }
 | 
| +}
 | 
| +
 | 
|  #endif  // BASE_MEMORY_REGION_MAP_H_
 | 
| 
 |