| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include <sys/mman.h> | 45 #include <sys/mman.h> |
| 46 #endif | 46 #endif |
| 47 #ifdef HAVE_PTHREAD | 47 #ifdef HAVE_PTHREAD |
| 48 #include <pthread.h> | 48 #include <pthread.h> |
| 49 #endif | 49 #endif |
| 50 #include <sys/stat.h> | 50 #include <sys/stat.h> |
| 51 #include <sys/types.h> | 51 #include <sys/types.h> |
| 52 #include <time.h> | 52 #include <time.h> |
| 53 #include <assert.h> | 53 #include <assert.h> |
| 54 | 54 |
| 55 #ifdef HAVE_LINUX_PTRACE_H | 55 #if defined(HAVE_LINUX_PTRACE_H) && !defined(__native_client__) |
| 56 #include <linux/ptrace.h> | 56 #include <linux/ptrace.h> |
| 57 #endif | 57 #endif |
| 58 #ifdef HAVE_SYS_SYSCALL_H | 58 #ifdef HAVE_SYS_SYSCALL_H |
| 59 #include <sys/syscall.h> | 59 #include <sys/syscall.h> |
| 60 #endif | 60 #endif |
| 61 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(_
_MINGW32__) | 61 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(_
_MINGW32__) |
| 62 #include <wtypes.h> | 62 #include <wtypes.h> |
| 63 #include <winbase.h> | 63 #include <winbase.h> |
| 64 #undef ERROR // windows defines these as macros, which can cause trouble | 64 #undef ERROR // windows defines these as macros, which can cause trouble |
| 65 #undef max | 65 #undef max |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 static pid_t heap_checker_pid = 0; | 271 static pid_t heap_checker_pid = 0; |
| 272 | 272 |
| 273 // If we did heap profiling during global constructors execution | 273 // If we did heap profiling during global constructors execution |
| 274 static bool constructor_heap_profiling = false; | 274 static bool constructor_heap_profiling = false; |
| 275 | 275 |
| 276 // RAW_VLOG level we dump key INFO messages at. If you want to turn | 276 // RAW_VLOG level we dump key INFO messages at. If you want to turn |
| 277 // off these messages, set the environment variable PERFTOOLS_VERBOSE=-1. | 277 // off these messages, set the environment variable PERFTOOLS_VERBOSE=-1. |
| 278 static const int heap_checker_info_level = 0; | 278 static const int heap_checker_info_level = 0; |
| 279 | 279 |
| 280 //---------------------------------------------------------------------- | 280 //---------------------------------------------------------------------- |
| 281 // Cancel our InitialMallocHook_* if present. | |
| 282 static void CancelInitialMallocHooks(); // defined below | |
| 283 | |
| 284 //---------------------------------------------------------------------- | |
| 285 // HeapLeakChecker's own memory allocator that is | 281 // HeapLeakChecker's own memory allocator that is |
| 286 // independent of the normal program allocator. | 282 // independent of the normal program allocator. |
| 287 //---------------------------------------------------------------------- | 283 //---------------------------------------------------------------------- |
| 288 | 284 |
| 289 // Wrapper of LowLevelAlloc for STL_Allocator and direct use. | 285 // Wrapper of LowLevelAlloc for STL_Allocator and direct use. |
| 290 // We always access this class under held heap_checker_lock, | 286 // We always access this class under held heap_checker_lock, |
| 291 // this allows us to in particular protect the period when threads are stopped | 287 // this allows us to in particular protect the period when threads are stopped |
| 292 // at random spots with ListAllProcessThreads by heap_checker_lock, | 288 // at random spots with ListAllProcessThreads by heap_checker_lock, |
| 293 // w/o worrying about the lock in LowLevelAlloc::Arena. | 289 // w/o worrying about the lock in LowLevelAlloc::Arena. |
| 294 // We rely on the fact that we use an own arena with an own lock here. | 290 // We rely on the fact that we use an own arena with an own lock here. |
| (...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 if (!HaveOnHeapLocked(&ptr, &object_size)) { | 1462 if (!HaveOnHeapLocked(&ptr, &object_size)) { |
| 1467 RAW_LOG(ERROR, "No live heap object at %p to ignore", ptr); | 1463 RAW_LOG(ERROR, "No live heap object at %p to ignore", ptr); |
| 1468 } else { | 1464 } else { |
| 1469 RAW_VLOG(10, "Going to ignore live object at %p of %"PRIuS" bytes", | 1465 RAW_VLOG(10, "Going to ignore live object at %p of %"PRIuS" bytes", |
| 1470 ptr, object_size); | 1466 ptr, object_size); |
| 1471 if (ignored_objects == NULL) { | 1467 if (ignored_objects == NULL) { |
| 1472 ignored_objects = new(Allocator::Allocate(sizeof(IgnoredObjectsMap))) | 1468 ignored_objects = new(Allocator::Allocate(sizeof(IgnoredObjectsMap))) |
| 1473 IgnoredObjectsMap; | 1469 IgnoredObjectsMap; |
| 1474 } | 1470 } |
| 1475 if (!ignored_objects->insert(make_pair(AsInt(ptr), object_size)).second) { | 1471 if (!ignored_objects->insert(make_pair(AsInt(ptr), object_size)).second) { |
| 1476 RAW_LOG(FATAL, "Object at %p is already being ignored", ptr); | 1472 RAW_LOG(WARNING, "Object at %p is already being ignored", ptr); |
| 1477 } | 1473 } |
| 1478 } | 1474 } |
| 1479 } | 1475 } |
| 1480 | 1476 |
| 1481 // static | 1477 // static |
| 1482 void HeapLeakChecker::UnIgnoreObject(const void* ptr) { | 1478 void HeapLeakChecker::UnIgnoreObject(const void* ptr) { |
| 1483 SpinLockHolder l(&heap_checker_lock); | 1479 SpinLockHolder l(&heap_checker_lock); |
| 1484 if (!heap_checker_on) return; | 1480 if (!heap_checker_on) return; |
| 1485 size_t object_size; | 1481 size_t object_size; |
| 1486 if (!HaveOnHeapLocked(&ptr, &object_size)) { | 1482 if (!HaveOnHeapLocked(&ptr, &object_size)) { |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2289 // static | 2285 // static |
| 2290 const void* HeapLeakChecker::GetAllocCaller(void* ptr) { | 2286 const void* HeapLeakChecker::GetAllocCaller(void* ptr) { |
| 2291 // this is used only in the unittest, so the heavy checks are fine | 2287 // this is used only in the unittest, so the heavy checks are fine |
| 2292 HeapProfileTable::AllocInfo info; | 2288 HeapProfileTable::AllocInfo info; |
| 2293 { SpinLockHolder l(&heap_checker_lock); | 2289 { SpinLockHolder l(&heap_checker_lock); |
| 2294 RAW_CHECK(heap_profile->FindAllocDetails(ptr, &info), ""); | 2290 RAW_CHECK(heap_profile->FindAllocDetails(ptr, &info), ""); |
| 2295 } | 2291 } |
| 2296 RAW_CHECK(info.stack_depth >= 1, ""); | 2292 RAW_CHECK(info.stack_depth >= 1, ""); |
| 2297 return info.call_stack[0]; | 2293 return info.call_stack[0]; |
| 2298 } | 2294 } |
| OLD | NEW |