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 "gperftools/malloc_extension_c.h" |
51 #include "maybe_threads.h" | 52 #include "maybe_threads.h" |
52 | 53 |
53 using STL_NAMESPACE::string; | 54 using STL_NAMESPACE::string; |
54 using STL_NAMESPACE::vector; | 55 using STL_NAMESPACE::vector; |
55 | 56 |
56 static void DumpAddressMap(string* result) { | 57 static void DumpAddressMap(string* result) { |
57 *result += "\nMAPPED_LIBRARIES:\n"; | 58 *result += "\nMAPPED_LIBRARIES:\n"; |
58 // We keep doubling until we get a fit | 59 // We keep doubling until we get a fit |
59 const size_t old_resultlen = result->size(); | 60 const size_t old_resultlen = result->size(); |
60 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... |
100 dummy += "!"; // so the definition of dummy isn't optimized out | 101 dummy += "!"; // so the definition of dummy isn't optimized out |
101 #endif /* __GLIBC__ */ | 102 #endif /* __GLIBC__ */ |
102 } | 103 } |
103 | 104 |
104 // SysAllocator implementation | 105 // SysAllocator implementation |
105 SysAllocator::~SysAllocator() {} | 106 SysAllocator::~SysAllocator() {} |
106 | 107 |
107 // Default implementation -- does nothing | 108 // Default implementation -- does nothing |
108 MallocExtension::~MallocExtension() { } | 109 MallocExtension::~MallocExtension() { } |
109 bool MallocExtension::VerifyAllMemory() { return true; } | 110 bool MallocExtension::VerifyAllMemory() { return true; } |
110 bool MallocExtension::VerifyNewMemory(void* p) { return true; } | 111 bool MallocExtension::VerifyNewMemory(const void* p) { return true; } |
111 bool MallocExtension::VerifyArrayNewMemory(void* p) { return true; } | 112 bool MallocExtension::VerifyArrayNewMemory(const void* p) { return true; } |
112 bool MallocExtension::VerifyMallocMemory(void* p) { return true; } | 113 bool MallocExtension::VerifyMallocMemory(const void* p) { return true; } |
113 | 114 |
114 bool MallocExtension::GetNumericProperty(const char* property, size_t* value) { | 115 bool MallocExtension::GetNumericProperty(const char* property, size_t* value) { |
115 return false; | 116 return false; |
116 } | 117 } |
117 | 118 |
118 bool MallocExtension::SetNumericProperty(const char* property, size_t value) { | 119 bool MallocExtension::SetNumericProperty(const char* property, size_t value) { |
119 return false; | 120 return false; |
120 } | 121 } |
121 | 122 |
122 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... |
169 } | 170 } |
170 | 171 |
171 double MallocExtension::GetMemoryReleaseRate() { | 172 double MallocExtension::GetMemoryReleaseRate() { |
172 return -1.0; | 173 return -1.0; |
173 } | 174 } |
174 | 175 |
175 size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) { | 176 size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) { |
176 return size; | 177 return size; |
177 } | 178 } |
178 | 179 |
179 size_t MallocExtension::GetAllocatedSize(void* p) { | 180 size_t MallocExtension::GetAllocatedSize(const void* p) { |
| 181 assert(GetOwnership(p) != kNotOwned); |
180 return 0; | 182 return 0; |
181 } | 183 } |
182 | 184 |
| 185 MallocExtension::Ownership MallocExtension::GetOwnership(const void* p) { |
| 186 return kUnknownOwnership; |
| 187 } |
| 188 |
183 void MallocExtension::GetFreeListSizes( | 189 void MallocExtension::GetFreeListSizes( |
184 vector<MallocExtension::FreeListInfo>* v) { | 190 vector<MallocExtension::FreeListInfo>* v) { |
185 v->clear(); | 191 v->clear(); |
186 } | 192 } |
187 | 193 |
188 // The current malloc extension object. | 194 // The current malloc extension object. |
189 | 195 |
190 static pthread_once_t module_init = PTHREAD_ONCE_INIT; | 196 static pthread_once_t module_init = PTHREAD_ONCE_INIT; |
191 static MallocExtension* current_instance = NULL; | 197 static MallocExtension* current_instance = NULL; |
192 | 198 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 return reinterpret_cast<uintptr_t>(entry[2]); | 237 return reinterpret_cast<uintptr_t>(entry[2]); |
232 } | 238 } |
233 void* PC(void** entry, int i) { | 239 void* PC(void** entry, int i) { |
234 return entry[3+i]; | 240 return entry[3+i]; |
235 } | 241 } |
236 | 242 |
237 void PrintCountAndSize(MallocExtensionWriter* writer, | 243 void PrintCountAndSize(MallocExtensionWriter* writer, |
238 uintptr_t count, uintptr_t size) { | 244 uintptr_t count, uintptr_t size) { |
239 char buf[100]; | 245 char buf[100]; |
240 snprintf(buf, sizeof(buf), | 246 snprintf(buf, sizeof(buf), |
241 "%6lld: %8lld [%6lld: %8lld] @", | 247 "%6"PRIu64": %8"PRIu64" [%6"PRIu64": %8"PRIu64"] @", |
242 static_cast<long long>(count), | 248 static_cast<uint64>(count), |
243 static_cast<long long>(size), | 249 static_cast<uint64>(size), |
244 static_cast<long long>(count), | 250 static_cast<uint64>(count), |
245 static_cast<long long>(size)); | 251 static_cast<uint64>(size)); |
246 writer->append(buf, strlen(buf)); | 252 writer->append(buf, strlen(buf)); |
247 } | 253 } |
248 | 254 |
249 void PrintHeader(MallocExtensionWriter* writer, | 255 void PrintHeader(MallocExtensionWriter* writer, |
250 const char* label, void** entries) { | 256 const char* label, void** entries) { |
251 // Compute the total count and total size | 257 // Compute the total count and total size |
252 uintptr_t total_count = 0; | 258 uintptr_t total_count = 0; |
253 uintptr_t total_size = 0; | 259 uintptr_t total_size = 0; |
254 for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) { | 260 for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) { |
255 total_count += Count(entry); | 261 total_count += Count(entry); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 336 } |
331 | 337 |
332 // These are C shims that work on the current instance. | 338 // These are C shims that work on the current instance. |
333 | 339 |
334 #define C_SHIM(fn, retval, paramlist, arglist) \ | 340 #define C_SHIM(fn, retval, paramlist, arglist) \ |
335 extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \ | 341 extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \ |
336 return MallocExtension::instance()->fn arglist; \ | 342 return MallocExtension::instance()->fn arglist; \ |
337 } | 343 } |
338 | 344 |
339 C_SHIM(VerifyAllMemory, int, (void), ()); | 345 C_SHIM(VerifyAllMemory, int, (void), ()); |
340 C_SHIM(VerifyNewMemory, int, (void* p), (p)); | 346 C_SHIM(VerifyNewMemory, int, (const void* p), (p)); |
341 C_SHIM(VerifyArrayNewMemory, int, (void* p), (p)); | 347 C_SHIM(VerifyArrayNewMemory, int, (const void* p), (p)); |
342 C_SHIM(VerifyMallocMemory, int, (void* p), (p)); | 348 C_SHIM(VerifyMallocMemory, int, (const void* p), (p)); |
343 C_SHIM(MallocMemoryStats, int, | 349 C_SHIM(MallocMemoryStats, int, |
344 (int* blocks, size_t* total, int histogram[kMallocHistogramSize]), | 350 (int* blocks, size_t* total, int histogram[kMallocHistogramSize]), |
345 (blocks, total, histogram)); | 351 (blocks, total, histogram)); |
346 | 352 |
347 C_SHIM(GetStats, void, | 353 C_SHIM(GetStats, void, |
348 (char* buffer, int buffer_length), (buffer, buffer_length)); | 354 (char* buffer, int buffer_length), (buffer, buffer_length)); |
349 C_SHIM(GetNumericProperty, int, | 355 C_SHIM(GetNumericProperty, int, |
350 (const char* property, size_t* value), (property, value)); | 356 (const char* property, size_t* value), (property, value)); |
351 C_SHIM(SetNumericProperty, int, | 357 C_SHIM(SetNumericProperty, int, |
352 (const char* property, size_t value), (property, value)); | 358 (const char* property, size_t value), (property, value)); |
353 | 359 |
354 C_SHIM(MarkThreadIdle, void, (void), ()); | 360 C_SHIM(MarkThreadIdle, void, (void), ()); |
355 C_SHIM(MarkThreadBusy, void, (void), ()); | 361 C_SHIM(MarkThreadBusy, void, (void), ()); |
356 C_SHIM(ReleaseFreeMemory, void, (void), ()); | 362 C_SHIM(ReleaseFreeMemory, void, (void), ()); |
357 C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); | 363 C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); |
358 C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); | 364 C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); |
359 C_SHIM(GetAllocatedSize, size_t, (void* p), (p)); | 365 C_SHIM(GetAllocatedSize, size_t, (const void* p), (p)); |
| 366 |
| 367 // Can't use the shim here because of the need to translate the enums. |
| 368 extern "C" |
| 369 MallocExtension_Ownership MallocExtension_GetOwnership(const void* p) { |
| 370 return static_cast<MallocExtension_Ownership>( |
| 371 MallocExtension::instance()->GetOwnership(p)); |
| 372 } |
OLD | NEW |