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

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

Issue 9311003: Update the tcmalloc chromium branch to r144 (gperftools 2.0), and merge chromium-specific changes. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebasec Created 8 years, 9 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();
106 virtual bool VerifyNewMemory(void* p); 103 virtual bool VerifyNewMemory(const void* p);
107 virtual bool VerifyArrayNewMemory(void* p); 104 virtual bool VerifyArrayNewMemory(const void* p);
108 virtual bool VerifyMallocMemory(void* p); 105 virtual bool VerifyMallocMemory(const void* p);
109 virtual bool MallocMemoryStats(int* blocks, size_t* total, 106 virtual bool MallocMemoryStats(int* blocks, size_t* total,
110 int histogram[kMallocHistogramSize]); 107 int histogram[kMallocHistogramSize]);
111 108
112 // Get a human readable description of the current state of the malloc 109 // Get a human readable description of the current state of the malloc
113 // data structures. The state is stored as a null-terminated string 110 // data structures. The state is stored as a null-terminated string
114 // in a prefix of "buffer[0,buffer_length-1]". 111 // in a prefix of "buffer[0,buffer_length-1]".
115 // REQUIRES: buffer_length > 0. 112 // REQUIRES: buffer_length > 0.
116 virtual void GetStats(char* buffer, int buffer_length); 113 virtual void GetStats(char* buffer, int buffer_length);
117 114
118 // Outputs to "writer" a sample of live objects and the stack traces 115 // Outputs to "writer" a sample of live objects and the stack traces
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // allocation). This number may be equal to or greater than the number 273 // allocation). This number may be equal to or greater than the number
277 // of bytes requested when p was allocated. 274 // of bytes requested when p was allocated.
278 // p must have been allocated by this malloc implementation, 275 // p must have been allocated by this malloc implementation,
279 // must not be an interior pointer -- that is, must be exactly 276 // must not be an interior pointer -- that is, must be exactly
280 // the pointer returned to by malloc() et al., not some offset 277 // 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. 278 // from that -- and should not have been freed yet. p may be NULL.
282 // (Currently only implemented in tcmalloc; other implementations 279 // (Currently only implemented in tcmalloc; other implementations
283 // will return 0.) 280 // will return 0.)
284 // This is equivalent to malloc_size() in OS X, malloc_usable_size() 281 // This is equivalent to malloc_size() in OS X, malloc_usable_size()
285 // in glibc, and _msize() for windows. 282 // in glibc, and _msize() for windows.
286 virtual size_t GetAllocatedSize(void* p); 283 virtual size_t GetAllocatedSize(const void* p);
284
285 // Returns kOwned if this malloc implementation allocated the memory
286 // pointed to by p, or kNotOwned if some other malloc implementation
287 // allocated it or p is NULL. May also return kUnknownOwnership if
288 // the malloc implementation does not keep track of ownership.
289 // REQUIRES: p must be a value returned from a previous call to
290 // malloc(), calloc(), realloc(), memalign(), posix_memalign(),
291 // valloc(), pvalloc(), new, or new[], and must refer to memory that
292 // is currently allocated (so, for instance, you should not pass in
293 // a pointer after having called free() on it).
294 enum Ownership {
295 // NOTE: Enum values MUST be kept in sync with the version in
296 // malloc_extension_c.h
297 kUnknownOwnership = 0,
298 kOwned,
299 kNotOwned
300 };
301 virtual Ownership GetOwnership(const void* p);
287 302
288 // The current malloc implementation. Always non-NULL. 303 // The current malloc implementation. Always non-NULL.
289 static MallocExtension* instance(); 304 static MallocExtension* instance();
290 305
291 // Change the malloc implementation. Typically called by the 306 // Change the malloc implementation. Typically called by the
292 // malloc implementation during initialization. 307 // malloc implementation during initialization.
293 static void Register(MallocExtension* implementation); 308 static void Register(MallocExtension* implementation);
294 309
295 // Returns detailed information about malloc's freelists. For each list, 310 // Returns detailed information about malloc's freelists. For each list,
296 // return a FreeListInfo: 311 // return a FreeListInfo:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 391
377 // Perhaps add the following: 392 // Perhaps add the following:
378 // - stack trace if this range was sampled 393 // - stack trace if this range was sampled
379 // - heap growth stack trace if applicable to this range 394 // - heap growth stack trace if applicable to this range
380 // - age when allocated (for inuse) or freed (if not in use) 395 // - age when allocated (for inuse) or freed (if not in use)
381 }; 396 };
382 397
383 } // namespace base 398 } // namespace base
384 399
385 #endif // BASE_MALLOC_EXTENSION_H_ 400 #endif // BASE_MALLOC_EXTENSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698