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

Side by Side Diff: third_party/tcmalloc/chromium/src/google/heap-checker.h

Issue 9320005: [NOT TO COMMIT!] Replace third_party/tcmalloc/chromium with tcmalloc r136 (the latest). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 10 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 class Disabler { 174 class Disabler {
175 public: 175 public:
176 Disabler(); 176 Disabler();
177 ~Disabler(); 177 ~Disabler();
178 private: 178 private:
179 Disabler(const Disabler&); // disallow copy 179 Disabler(const Disabler&); // disallow copy
180 void operator=(const Disabler&); // and assign 180 void operator=(const Disabler&); // and assign
181 }; 181 };
182 182
183 // Ignore an object located at 'ptr' (can go at the start or into the object) 183 // Ignore an object located at 'ptr' (can go at the start or into the object)
184 // as well as all heap objects (transitively) referenced from it 184 // as well as all heap objects (transitively) referenced from it for the
185 // for the purposes of heap leak checking. 185 // purposes of heap leak checking. Returns 'ptr' so that one can write
186 // If 'ptr' does not point to an active allocated object 186 // static T* obj = IgnoreObject(new T(...));
187 // at the time of this call, it is ignored; 187 //
188 // but if it does, the object must not get deleted from the heap later on; 188 // If 'ptr' does not point to an active allocated object at the time of this
189 // it must also be not already ignored at the time of this call. 189 // call, it is ignored; but if it does, the object must not get deleted from
190 // the heap later on.
190 // 191 //
191 // See also HiddenPointer, below, if you need to prevent a pointer from 192 // See also HiddenPointer, below, if you need to prevent a pointer from
192 // being traversed by the heap checker but do not wish to transitively 193 // being traversed by the heap checker but do not wish to transitively
193 // whitelist objects referenced through it. 194 // whitelist objects referenced through it.
194 static void IgnoreObject(const void* ptr); 195 template <typename T>
196 static T* IgnoreObject(T* ptr) {
197 DoIgnoreObject(static_cast<const void*>(const_cast<const T*>(ptr)));
198 return ptr;
199 }
195 200
196 // Undo what an earlier IgnoreObject() call promised and asked to do. 201 // Undo what an earlier IgnoreObject() call promised and asked to do.
197 // At the time of this call 'ptr' must point at or inside of an active 202 // At the time of this call 'ptr' must point at or inside of an active
198 // allocated object which was previously registered with IgnoreObject(). 203 // allocated object which was previously registered with IgnoreObject().
199 static void UnIgnoreObject(const void* ptr); 204 static void UnIgnoreObject(const void* ptr);
200 205
201 // ----------------------------------------------------------------------- // 206 // ----------------------------------------------------------------------- //
202 // Initialization; to be called from main() only.
203
204 // Full starting of recommended whole-program checking.
205 static void InternalInitStart();
206
207 // ----------------------------------------------------------------------- //
208 // Internal types defined in .cc 207 // Internal types defined in .cc
209 208
210 class Allocator; 209 class Allocator;
211 struct RangeValue; 210 struct RangeValue;
212 211
213 private: 212 private:
214 213
215 // ----------------------------------------------------------------------- // 214 // ----------------------------------------------------------------------- //
216 // Various helpers 215 // Various helpers
217 216
218 // Create the name of the heap profile file. 217 // Create the name of the heap profile file.
219 // Should be deleted via Allocator::Free(). 218 // Should be deleted via Allocator::Free().
220 char* MakeProfileNameLocked(); 219 char* MakeProfileNameLocked();
221 220
222 // Helper for constructors 221 // Helper for constructors
223 void Create(const char *name, bool make_start_snapshot); 222 void Create(const char *name, bool make_start_snapshot);
224 223
225 enum ShouldSymbolize { SYMBOLIZE, DO_NOT_SYMBOLIZE }; 224 enum ShouldSymbolize { SYMBOLIZE, DO_NOT_SYMBOLIZE };
226 225
227 // Helper for *NoLeaks and *SameHeap 226 // Helper for *NoLeaks and *SameHeap
228 bool DoNoLeaks(ShouldSymbolize should_symbolize); 227 bool DoNoLeaks(ShouldSymbolize should_symbolize);
229 228
229 // Helper for NoGlobalLeaks, also called by the global destructor.
230 static bool NoGlobalLeaksMaybeSymbolize(ShouldSymbolize should_symbolize);
231
230 // These used to be public, but they are now deprecated. 232 // These used to be public, but they are now deprecated.
231 // Will remove entirely when all internal uses are fixed. 233 // Will remove entirely when all internal uses are fixed.
232 // In the meantime, use friendship so the unittest can still test them. 234 // In the meantime, use friendship so the unittest can still test them.
233 static void* GetDisableChecksStart(); 235 static void* GetDisableChecksStart();
234 static void DisableChecksToHereFrom(const void* start_address); 236 static void DisableChecksToHereFrom(const void* start_address);
235 static void DisableChecksIn(const char* pattern); 237 static void DisableChecksIn(const char* pattern);
236 friend void RangeDisabledLeaks(); 238 friend void RangeDisabledLeaks();
237 friend void NamedTwoDisabledLeaks(); 239 friend void NamedTwoDisabledLeaks();
238 friend void* RunNamedDisabledLeaks(void*); 240 friend void* RunNamedDisabledLeaks(void*);
239 friend void TestHeapLeakCheckerNamedDisabling(); 241 friend void TestHeapLeakCheckerNamedDisabling();
240 friend int main(int, char**); 242 friend int main(int, char**);
241 243
242 244
243 // Helper for DisableChecksIn 245 // Actually implements IgnoreObject().
244 static void DisableChecksInLocked(const char* pattern); 246 static void DoIgnoreObject(const void* ptr);
245 247
246 // Disable checks based on stack trace entry at a depth <= 248 // Disable checks based on stack trace entry at a depth <=
247 // max_depth. Used to hide allocations done inside some special 249 // max_depth. Used to hide allocations done inside some special
248 // libraries. 250 // libraries.
249 static void DisableChecksFromToLocked(const void* start_address, 251 static void DisableChecksFromToLocked(const void* start_address,
250 const void* end_address, 252 const void* end_address,
251 int max_depth); 253 int max_depth);
252 254
253 // Helper for DoNoLeaks to ignore all objects reachable from all live data 255 // Helper for DoNoLeaks to ignore all objects reachable from all live data
254 static void IgnoreAllLiveObjectsLocked(const void* self_stack_top); 256 static void IgnoreAllLiveObjectsLocked(const void* self_stack_top);
(...skipping 24 matching lines...) Expand all
279 281
280 // Helper for IgnoreNonThreadLiveObjectsLocked and IgnoreLiveThreadsLocked 282 // Helper for IgnoreNonThreadLiveObjectsLocked and IgnoreLiveThreadsLocked
281 // to discover and ignore all heap objects 283 // to discover and ignore all heap objects
282 // reachable from currently considered live objects 284 // reachable from currently considered live objects
283 // (live_objects static global variable in out .cc file). 285 // (live_objects static global variable in out .cc file).
284 // "name", "name2" are two strings that we print one after another 286 // "name", "name2" are two strings that we print one after another
285 // in a debug message to describe what kind of live object sources 287 // in a debug message to describe what kind of live object sources
286 // are being used. 288 // are being used.
287 static void IgnoreLiveObjectsLocked(const char* name, const char* name2); 289 static void IgnoreLiveObjectsLocked(const char* name, const char* name2);
288 290
289 // Runs REGISTER_HEAPCHECK_CLEANUP cleanups and potentially
290 // calls DoMainHeapCheck
291 static void RunHeapCleanups();
292
293 // Do the overall whole-program heap leak check if needed; 291 // Do the overall whole-program heap leak check if needed;
294 // returns true when did the leak check. 292 // returns true when did the leak check.
295 static bool DoMainHeapCheck(); 293 static bool DoMainHeapCheck();
296 294
297 // Type of task for UseProcMapsLocked 295 // Type of task for UseProcMapsLocked
298 enum ProcMapsTask { 296 enum ProcMapsTask {
299 RECORD_GLOBAL_DATA, 297 RECORD_GLOBAL_DATA,
300 DISABLE_LIBRARY_ALLOCS 298 DISABLE_LIBRARY_ALLOCS
301 }; 299 };
302 300
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 static const void* GetAllocCaller(void* ptr); 339 static const void* GetAllocCaller(void* ptr);
342 friend void VerifyHeapProfileTableStackGet(); 340 friend void VerifyHeapProfileTableStackGet();
343 341
344 // This gets to execute before constructors for all global objects 342 // This gets to execute before constructors for all global objects
345 static void BeforeConstructorsLocked(); 343 static void BeforeConstructorsLocked();
346 friend void HeapLeakChecker_BeforeConstructors(); 344 friend void HeapLeakChecker_BeforeConstructors();
347 345
348 // This gets to execute after destructors for all global objects 346 // This gets to execute after destructors for all global objects
349 friend void HeapLeakChecker_AfterDestructors(); 347 friend void HeapLeakChecker_AfterDestructors();
350 348
349 // Full starting of recommended whole-program checking.
350 friend void HeapLeakChecker_InternalInitStart();
351
352 // Runs REGISTER_HEAPCHECK_CLEANUP cleanups and potentially
353 // calls DoMainHeapCheck
354 friend void HeapLeakChecker_RunHeapCleanups();
355
351 // ----------------------------------------------------------------------- // 356 // ----------------------------------------------------------------------- //
352 // Member data. 357 // Member data.
353 358
354 class SpinLock* lock_; // to make HeapLeakChecker objects thread-safe 359 class SpinLock* lock_; // to make HeapLeakChecker objects thread-safe
355 const char* name_; // our remembered name (we own it) 360 const char* name_; // our remembered name (we own it)
356 // NULL means this leak checker is a noop 361 // NULL means this leak checker is a noop
357 362
358 // Snapshot taken when the checker was created. May be NULL 363 // Snapshot taken when the checker was created. May be NULL
359 // for the global heap checker object. We use void* instead of 364 // for the global heap checker object. We use void* instead of
360 // HeapProfileTable::Snapshot* to avoid including heap-profile-table.h. 365 // HeapProfileTable::Snapshot* to avoid including heap-profile-table.h.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // (they run only if we are doing heap leak checking.) 414 // (they run only if we are doing heap leak checking.)
410 // 'body' should be the cleanup code to run. 'name' doesn't matter, 415 // 'body' should be the cleanup code to run. 'name' doesn't matter,
411 // but must be unique amongst all REGISTER_HEAPCHECK_CLEANUP calls. 416 // but must be unique amongst all REGISTER_HEAPCHECK_CLEANUP calls.
412 #define REGISTER_HEAPCHECK_CLEANUP(name, body) \ 417 #define REGISTER_HEAPCHECK_CLEANUP(name, body) \
413 namespace { \ 418 namespace { \
414 void heapcheck_cleanup_##name() { body; } \ 419 void heapcheck_cleanup_##name() { body; } \
415 static HeapCleaner heapcheck_cleaner_##name(&heapcheck_cleanup_##name); \ 420 static HeapCleaner heapcheck_cleaner_##name(&heapcheck_cleanup_##name); \
416 } 421 }
417 422
418 #endif // BASE_HEAP_CHECKER_H_ 423 #endif // BASE_HEAP_CHECKER_H_
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/debugallocation.cc ('k') | third_party/tcmalloc/chromium/src/google/malloc_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698