OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
6 | 6 |
7 #include <config.h> | 7 #include <config.h> |
8 #include "base/allocator/allocator_extension_thunks.h" | 8 #include "base/allocator/allocator_extension_thunks.h" |
9 #include "base/profiler/alternate_timer.h" | 9 #include "base/profiler/alternate_timer.h" |
10 #include "base/sysinfo.h" | 10 #include "base/sysinfo.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 224 } |
225 #endif | 225 #endif |
226 return MallocExtension::instance()->GetAllocatedSize(p); | 226 return MallocExtension::instance()->GetAllocatedSize(p); |
227 } | 227 } |
228 | 228 |
229 // This is included to resolve references from libcmt. | 229 // This is included to resolve references from libcmt. |
230 extern "C" intptr_t _get_heap_handle() { | 230 extern "C" intptr_t _get_heap_handle() { |
231 return 0; | 231 return 0; |
232 } | 232 } |
233 | 233 |
| 234 static bool get_jemalloc_property_thunk(const char* name, size_t* value) { |
| 235 jemalloc_stats_t stats; |
| 236 jemalloc_stats(&stats); |
| 237 #define EXTRACT_JEMALLOC_PROPERTY(property) \ |
| 238 if (strcmp(name, "jemalloc." #property) == 0) \ |
| 239 return *value = stats.property, true; |
| 240 EXTRACT_JEMALLOC_PROPERTY(narenas); |
| 241 EXTRACT_JEMALLOC_PROPERTY(balance_threshold); |
| 242 EXTRACT_JEMALLOC_PROPERTY(quantum); |
| 243 EXTRACT_JEMALLOC_PROPERTY(small_max); |
| 244 EXTRACT_JEMALLOC_PROPERTY(large_max); |
| 245 EXTRACT_JEMALLOC_PROPERTY(chunksize); |
| 246 EXTRACT_JEMALLOC_PROPERTY(dirty_max); |
| 247 EXTRACT_JEMALLOC_PROPERTY(reserve_min); |
| 248 EXTRACT_JEMALLOC_PROPERTY(reserve_max); |
| 249 EXTRACT_JEMALLOC_PROPERTY(mapped); |
| 250 EXTRACT_JEMALLOC_PROPERTY(committed); |
| 251 EXTRACT_JEMALLOC_PROPERTY(allocated); |
| 252 EXTRACT_JEMALLOC_PROPERTY(dirty); |
| 253 EXTRACT_JEMALLOC_PROPERTY(reserve_cur); |
| 254 #undef EXTRACT_JEMALLOC_PROPERTY |
| 255 return false; |
| 256 } |
| 257 |
| 258 static bool get_property_thunk(const char* name, size_t* value) { |
| 259 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
| 260 switch (allocator) { |
| 261 case JEMALLOC: |
| 262 return get_jemalloc_property_thunk(name, value); |
| 263 case WINHEAP: |
| 264 case WINLFH: |
| 265 // TODO(alexeif): Implement for other allocators. |
| 266 return false; |
| 267 } |
| 268 #endif |
| 269 return MallocExtension::instance()->GetNumerticProperty(name, value); |
| 270 } |
| 271 |
234 static void get_stats_thunk(char* buffer, int buffer_length) { | 272 static void get_stats_thunk(char* buffer, int buffer_length) { |
235 MallocExtension::instance()->GetStats(buffer, buffer_length); | 273 MallocExtension::instance()->GetStats(buffer, buffer_length); |
236 } | 274 } |
237 | 275 |
238 static void release_free_memory_thunk() { | 276 static void release_free_memory_thunk() { |
239 MallocExtension::instance()->ReleaseFreeMemory(); | 277 MallocExtension::instance()->ReleaseFreeMemory(); |
240 } | 278 } |
241 | 279 |
242 // The CRT heap initialization stub. | 280 // The CRT heap initialization stub. |
243 extern "C" int _heap_init() { | 281 extern "C" int _heap_init() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // basis. Only set the hook if the environment indicates this needs to be | 315 // basis. Only set the hook if the environment indicates this needs to be |
278 // enabled. | 316 // enabled. |
279 const char* profiling = | 317 const char* profiling = |
280 GetenvBeforeMain(tracked_objects::kAlternateProfilerTime); | 318 GetenvBeforeMain(tracked_objects::kAlternateProfilerTime); |
281 if (profiling && *profiling == '1') { | 319 if (profiling && *profiling == '1') { |
282 tracked_objects::SetAlternateTimeSource( | 320 tracked_objects::SetAlternateTimeSource( |
283 tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread, | 321 tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread, |
284 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); | 322 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); |
285 } | 323 } |
286 | 324 |
| 325 base::allocator::thunks::SetGetPropertyFunction(get_property_thunk); |
287 base::allocator::thunks::SetGetStatsFunction(get_stats_thunk); | 326 base::allocator::thunks::SetGetStatsFunction(get_stats_thunk); |
288 base::allocator::thunks::SetReleaseFreeMemoryFunction( | 327 base::allocator::thunks::SetReleaseFreeMemoryFunction( |
289 release_free_memory_thunk); | 328 release_free_memory_thunk); |
290 | 329 |
291 return 1; | 330 return 1; |
292 } | 331 } |
293 | 332 |
294 // The CRT heap cleanup stub. | 333 // The CRT heap cleanup stub. |
295 extern "C" void _heap_term() {} | 334 extern "C" void _heap_term() {} |
296 | 335 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 void TCMallocDoFreeForTest(void* ptr) { | 435 void TCMallocDoFreeForTest(void* ptr) { |
397 do_free(ptr); | 436 do_free(ptr); |
398 } | 437 } |
399 | 438 |
400 size_t ExcludeSpaceForMarkForTest(size_t size) { | 439 size_t ExcludeSpaceForMarkForTest(size_t size) { |
401 return ExcludeSpaceForMark(size); | 440 return ExcludeSpaceForMark(size); |
402 } | 441 } |
403 | 442 |
404 } // namespace allocator. | 443 } // namespace allocator. |
405 } // namespace base. | 444 } // namespace base. |
OLD | NEW |