| 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 27 matching lines...) Expand all Loading... |
| 38 #include <stdint.h> | 38 #include <stdint.h> |
| 39 #elif defined HAVE_INTTYPES_H | 39 #elif defined HAVE_INTTYPES_H |
| 40 #include <inttypes.h> | 40 #include <inttypes.h> |
| 41 #else | 41 #else |
| 42 #include <sys/types.h> | 42 #include <sys/types.h> |
| 43 #endif | 43 #endif |
| 44 #include <string> | 44 #include <string> |
| 45 #include "base/dynamic_annotations.h" | 45 #include "base/dynamic_annotations.h" |
| 46 #include "base/sysinfo.h" // for FillProcSelfMaps | 46 #include "base/sysinfo.h" // for FillProcSelfMaps |
| 47 #ifndef NO_HEAP_CHECK | 47 #ifndef NO_HEAP_CHECK |
| 48 #include "google/heap-checker.h" | 48 #include "gperftools/heap-checker.h" |
| 49 #endif | 49 #endif |
| 50 #include "google/malloc_extension.h" | 50 #include "gperftools/malloc_extension.h" |
| 51 #include "google/malloc_extension_c.h" | 51 #include "gperftools/malloc_extension_c.h" |
| 52 #include "maybe_threads.h" | 52 #include "maybe_threads.h" |
| 53 | 53 |
| 54 using STL_NAMESPACE::string; | 54 using STL_NAMESPACE::string; |
| 55 using STL_NAMESPACE::vector; | 55 using STL_NAMESPACE::vector; |
| 56 | 56 |
| 57 static void DumpAddressMap(string* result) { | 57 static void DumpAddressMap(string* result) { |
| 58 *result += "\nMAPPED_LIBRARIES:\n"; | 58 *result += "\nMAPPED_LIBRARIES:\n"; |
| 59 // We keep doubling until we get a fit | 59 // We keep doubling until we get a fit |
| 60 const size_t old_resultlen = result->size(); | 60 const size_t old_resultlen = result->size(); |
| 61 for (int amap_size = 10240; amap_size < 10000000; amap_size *= 2) { | 61 for (int amap_size = 10240; amap_size < 10000000; amap_size *= 2) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 dummy += "!"; // so the definition of dummy isn't optimized out | 101 dummy += "!"; // so the definition of dummy isn't optimized out |
| 102 #endif /* __GLIBC__ */ | 102 #endif /* __GLIBC__ */ |
| 103 } | 103 } |
| 104 | 104 |
| 105 // SysAllocator implementation | 105 // SysAllocator implementation |
| 106 SysAllocator::~SysAllocator() {} | 106 SysAllocator::~SysAllocator() {} |
| 107 | 107 |
| 108 // Default implementation -- does nothing | 108 // Default implementation -- does nothing |
| 109 MallocExtension::~MallocExtension() { } | 109 MallocExtension::~MallocExtension() { } |
| 110 bool MallocExtension::VerifyAllMemory() { return true; } | 110 bool MallocExtension::VerifyAllMemory() { return true; } |
| 111 bool MallocExtension::VerifyNewMemory(void* p) { return true; } | 111 bool MallocExtension::VerifyNewMemory(const void* p) { return true; } |
| 112 bool MallocExtension::VerifyArrayNewMemory(void* p) { return true; } | 112 bool MallocExtension::VerifyArrayNewMemory(const void* p) { return true; } |
| 113 bool MallocExtension::VerifyMallocMemory(void* p) { return true; } | 113 bool MallocExtension::VerifyMallocMemory(const void* p) { return true; } |
| 114 | 114 |
| 115 bool MallocExtension::GetNumericProperty(const char* property, size_t* value) { | 115 bool MallocExtension::GetNumericProperty(const char* property, size_t* value) { |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool MallocExtension::SetNumericProperty(const char* property, size_t value) { | 119 bool MallocExtension::SetNumericProperty(const char* property, size_t value) { |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void MallocExtension::GetStats(char* buffer, int length) { | 123 void MallocExtension::GetStats(char* buffer, int length) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 double MallocExtension::GetMemoryReleaseRate() { | 172 double MallocExtension::GetMemoryReleaseRate() { |
| 173 return -1.0; | 173 return -1.0; |
| 174 } | 174 } |
| 175 | 175 |
| 176 size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) { | 176 size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) { |
| 177 return size; | 177 return size; |
| 178 } | 178 } |
| 179 | 179 |
| 180 size_t MallocExtension::GetAllocatedSize(void* p) { | 180 size_t MallocExtension::GetAllocatedSize(const void* p) { |
| 181 assert(GetOwnership(p) != kNotOwned); | 181 assert(GetOwnership(p) != kNotOwned); |
| 182 return 0; | 182 return 0; |
| 183 } | 183 } |
| 184 | 184 |
| 185 MallocExtension::Ownership MallocExtension::GetOwnership(const void* p) { | 185 MallocExtension::Ownership MallocExtension::GetOwnership(const void* p) { |
| 186 return kUnknownOwnership; | 186 return kUnknownOwnership; |
| 187 } | 187 } |
| 188 | 188 |
| 189 void MallocExtension::GetFreeListSizes( | 189 void MallocExtension::GetFreeListSizes( |
| 190 vector<MallocExtension::FreeListInfo>* v) { | 190 vector<MallocExtension::FreeListInfo>* v) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 336 } |
| 337 | 337 |
| 338 // These are C shims that work on the current instance. | 338 // These are C shims that work on the current instance. |
| 339 | 339 |
| 340 #define C_SHIM(fn, retval, paramlist, arglist) \ | 340 #define C_SHIM(fn, retval, paramlist, arglist) \ |
| 341 extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \ | 341 extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \ |
| 342 return MallocExtension::instance()->fn arglist; \ | 342 return MallocExtension::instance()->fn arglist; \ |
| 343 } | 343 } |
| 344 | 344 |
| 345 C_SHIM(VerifyAllMemory, int, (void), ()); | 345 C_SHIM(VerifyAllMemory, int, (void), ()); |
| 346 C_SHIM(VerifyNewMemory, int, (void* p), (p)); | 346 C_SHIM(VerifyNewMemory, int, (const void* p), (p)); |
| 347 C_SHIM(VerifyArrayNewMemory, int, (void* p), (p)); | 347 C_SHIM(VerifyArrayNewMemory, int, (const void* p), (p)); |
| 348 C_SHIM(VerifyMallocMemory, int, (void* p), (p)); | 348 C_SHIM(VerifyMallocMemory, int, (const void* p), (p)); |
| 349 C_SHIM(MallocMemoryStats, int, | 349 C_SHIM(MallocMemoryStats, int, |
| 350 (int* blocks, size_t* total, int histogram[kMallocHistogramSize]), | 350 (int* blocks, size_t* total, int histogram[kMallocHistogramSize]), |
| 351 (blocks, total, histogram)); | 351 (blocks, total, histogram)); |
| 352 | 352 |
| 353 C_SHIM(GetStats, void, | 353 C_SHIM(GetStats, void, |
| 354 (char* buffer, int buffer_length), (buffer, buffer_length)); | 354 (char* buffer, int buffer_length), (buffer, buffer_length)); |
| 355 C_SHIM(GetNumericProperty, int, | 355 C_SHIM(GetNumericProperty, int, |
| 356 (const char* property, size_t* value), (property, value)); | 356 (const char* property, size_t* value), (property, value)); |
| 357 C_SHIM(SetNumericProperty, int, | 357 C_SHIM(SetNumericProperty, int, |
| 358 (const char* property, size_t value), (property, value)); | 358 (const char* property, size_t value), (property, value)); |
| 359 | 359 |
| 360 C_SHIM(MarkThreadIdle, void, (void), ()); | 360 C_SHIM(MarkThreadIdle, void, (void), ()); |
| 361 C_SHIM(MarkThreadBusy, void, (void), ()); | 361 C_SHIM(MarkThreadBusy, void, (void), ()); |
| 362 C_SHIM(ReleaseFreeMemory, void, (void), ()); | 362 C_SHIM(ReleaseFreeMemory, void, (void), ()); |
| 363 C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); | 363 C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); |
| 364 C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); | 364 C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); |
| 365 C_SHIM(GetAllocatedSize, size_t, (void* p), (p)); | 365 C_SHIM(GetAllocatedSize, size_t, (const void* p), (p)); |
| 366 | 366 |
| 367 // Can't use the shim here because of the need to translate the enums. | 367 // Can't use the shim here because of the need to translate the enums. |
| 368 extern "C" | 368 extern "C" |
| 369 MallocExtension_Ownership MallocExtension_GetOwnership(const void* p) { | 369 MallocExtension_Ownership MallocExtension_GetOwnership(const void* p) { |
| 370 return static_cast<MallocExtension_Ownership>( | 370 return static_cast<MallocExtension_Ownership>( |
| 371 MallocExtension::instance()->GetOwnership(p)); | 371 MallocExtension::instance()->GetOwnership(p)); |
| 372 } | 372 } |
| OLD | NEW |