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 30 matching lines...) Expand all Loading... |
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 "google/heap-checker.h" |
49 #endif | 49 #endif |
50 #include "google/malloc_extension.h" | 50 #include "google/malloc_extension.h" |
| 51 #include "google/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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, (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 |