Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: third_party/tcmalloc/chromium/src/google/malloc_extension.h

Issue 7430007: Merge tcmalloc r111 (perftools v. 1.8) with the chromium/ branch. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 class SysAllocator { 74 class SysAllocator {
75 public: 75 public:
76 SysAllocator() { 76 SysAllocator() {
77 } 77 }
78 virtual ~SysAllocator(); 78 virtual ~SysAllocator();
79 79
80 // Allocates "size"-byte of memory from system aligned with "alignment". 80 // Allocates "size"-byte of memory from system aligned with "alignment".
81 // Returns NULL if failed. Otherwise, the returned pointer p up to and 81 // Returns NULL if failed. Otherwise, the returned pointer p up to and
82 // including (p + actual_size -1) have been allocated. 82 // including (p + actual_size -1) have been allocated.
83 virtual void* Alloc(size_t size, size_t *actual_size, size_t alignment) = 0; 83 virtual void* Alloc(size_t size, size_t *actual_size, size_t alignment) = 0;
84
85 // Notification that command-line flags have been initialized.
86 virtual void FlagsInitialized() = 0;
87 }; 84 };
88 85
89 // The default implementations of the following routines do nothing. 86 // The default implementations of the following routines do nothing.
90 // All implementations should be thread-safe; the current one 87 // All implementations should be thread-safe; the current one
91 // (TCMallocImplementation) is. 88 // (TCMallocImplementation) is.
92 class PERFTOOLS_DLL_DECL MallocExtension { 89 class PERFTOOLS_DLL_DECL MallocExtension {
93 public: 90 public:
94 virtual ~MallocExtension(); 91 virtual ~MallocExtension();
95 92
96 // Call this very early in the program execution -- say, in a global 93 // Call this very early in the program execution -- say, in a global
97 // constructor -- to set up parameters and state needed by all 94 // constructor -- to set up parameters and state needed by all
98 // instrumented malloc implemenatations. One example: this routine 95 // instrumented malloc implemenatations. One example: this routine
99 // sets environemnt variables to tell STL to use libc's malloc() 96 // sets environemnt variables to tell STL to use libc's malloc()
100 // instead of doing its own memory management. This is safe to call 97 // instead of doing its own memory management. This is safe to call
101 // multiple times, as long as each time is before threads start up. 98 // multiple times, as long as each time is before threads start up.
102 static void Initialize(); 99 static void Initialize();
103 100
104 // See "verify_memory.h" to see what these routines do 101 // See "verify_memory.h" to see what these routines do
105 virtual bool VerifyAllMemory(); 102 virtual bool VerifyAllMemory();
103 // TODO(csilvers): change these to const void*.
106 virtual bool VerifyNewMemory(void* p); 104 virtual bool VerifyNewMemory(void* p);
107 virtual bool VerifyArrayNewMemory(void* p); 105 virtual bool VerifyArrayNewMemory(void* p);
108 virtual bool VerifyMallocMemory(void* p); 106 virtual bool VerifyMallocMemory(void* p);
109 virtual bool MallocMemoryStats(int* blocks, size_t* total, 107 virtual bool MallocMemoryStats(int* blocks, size_t* total,
110 int histogram[kMallocHistogramSize]); 108 int histogram[kMallocHistogramSize]);
111 109
112 // Get a human readable description of the current state of the malloc 110 // Get a human readable description of the current state of the malloc
113 // data structures. The state is stored as a null-terminated string 111 // data structures. The state is stored as a null-terminated string
114 // in a prefix of "buffer[0,buffer_length-1]". 112 // in a prefix of "buffer[0,buffer_length-1]".
115 // REQUIRES: buffer_length > 0. 113 // REQUIRES: buffer_length > 0.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // allocation). This number may be equal to or greater than the number 274 // allocation). This number may be equal to or greater than the number
277 // of bytes requested when p was allocated. 275 // of bytes requested when p was allocated.
278 // p must have been allocated by this malloc implementation, 276 // p must have been allocated by this malloc implementation,
279 // must not be an interior pointer -- that is, must be exactly 277 // must not be an interior pointer -- that is, must be exactly
280 // the pointer returned to by malloc() et al., not some offset 278 // the pointer returned to by malloc() et al., not some offset
281 // from that -- and should not have been freed yet. p may be NULL. 279 // from that -- and should not have been freed yet. p may be NULL.
282 // (Currently only implemented in tcmalloc; other implementations 280 // (Currently only implemented in tcmalloc; other implementations
283 // will return 0.) 281 // will return 0.)
284 // This is equivalent to malloc_size() in OS X, malloc_usable_size() 282 // This is equivalent to malloc_size() in OS X, malloc_usable_size()
285 // in glibc, and _msize() for windows. 283 // in glibc, and _msize() for windows.
284 // TODO(csilvers): change to const void*.
286 virtual size_t GetAllocatedSize(void* p); 285 virtual size_t GetAllocatedSize(void* p);
287 286
287 // Returns kOwned if this malloc implementation allocated the memory
288 // pointed to by p, or kNotOwned if some other malloc implementation
289 // allocated it or p is NULL. May also return kUnknownOwnership if
290 // the malloc implementation does not keep track of ownership.
291 // REQUIRES: p must be a value returned from a previous call to
292 // malloc(), calloc(), realloc(), memalign(), posix_memalign(),
293 // valloc(), pvalloc(), new, or new[], and must refer to memory that
294 // is currently allocated (so, for instance, you should not pass in
295 // a pointer after having called free() on it).
296 enum Ownership {
297 // NOTE: Enum values MUST be kept in sync with the version in
298 // malloc_extension_c.h
299 kUnknownOwnership = 0,
300 kOwned,
301 kNotOwned
302 };
303 virtual Ownership GetOwnership(const void* p);
304
288 // The current malloc implementation. Always non-NULL. 305 // The current malloc implementation. Always non-NULL.
289 static MallocExtension* instance(); 306 static MallocExtension* instance();
290 307
291 // Change the malloc implementation. Typically called by the 308 // Change the malloc implementation. Typically called by the
292 // malloc implementation during initialization. 309 // malloc implementation during initialization.
293 static void Register(MallocExtension* implementation); 310 static void Register(MallocExtension* implementation);
294 311
295 // Returns detailed information about malloc's freelists. For each list, 312 // Returns detailed information about malloc's freelists. For each list,
296 // return a FreeListInfo: 313 // return a FreeListInfo:
297 struct FreeListInfo { 314 struct FreeListInfo {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 393
377 // Perhaps add the following: 394 // Perhaps add the following:
378 // - stack trace if this range was sampled 395 // - stack trace if this range was sampled
379 // - heap growth stack trace if applicable to this range 396 // - heap growth stack trace if applicable to this range
380 // - age when allocated (for inuse) or freed (if not in use) 397 // - age when allocated (for inuse) or freed (if not in use)
381 }; 398 };
382 399
383 } // namespace base 400 } // namespace base
384 401
385 #endif // BASE_MALLOC_EXTENSION_H_ 402 #endif // BASE_MALLOC_EXTENSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698