| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 #endif | 226 #endif |
| 227 return MallocExtension::instance()->GetAllocatedSize(p); | 227 return MallocExtension::instance()->GetAllocatedSize(p); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // This is included to resolve references from libcmt. | 230 // This is included to resolve references from libcmt. |
| 231 extern "C" intptr_t _get_heap_handle() { | 231 extern "C" intptr_t _get_heap_handle() { |
| 232 return 0; | 232 return 0; |
| 233 } | 233 } |
| 234 | 234 |
| 235 static bool get_jemalloc_property_thunk(const char* name, size_t* value) { | 235 static bool get_allocator_waste_size_thunk(size_t* size) { |
| 236 jemalloc_stats_t stats; | 236 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
| 237 jemalloc_stats(&stats); | 237 switch (allocator) { |
| 238 #define EXTRACT_JEMALLOC_PROPERTY(property) \ | 238 case JEMALLOC: |
| 239 if (strcmp(name, "jemalloc." #property) == 0) \ | 239 case WINHEAP: |
| 240 return *value = stats.property, true; | 240 case WINLFH: |
| 241 EXTRACT_JEMALLOC_PROPERTY(narenas); | 241 // TODO(alexeif): Implement for allocators other than tcmalloc. |
| 242 EXTRACT_JEMALLOC_PROPERTY(balance_threshold); | 242 return false; |
| 243 EXTRACT_JEMALLOC_PROPERTY(quantum); | 243 } |
| 244 EXTRACT_JEMALLOC_PROPERTY(small_max); | 244 #endif |
| 245 EXTRACT_JEMALLOC_PROPERTY(large_max); | 245 size_t heap_size, allocated_bytes, unmapped_bytes; |
| 246 EXTRACT_JEMALLOC_PROPERTY(chunksize); | 246 MallocExtension* ext = MallocExtension::instance(); |
| 247 EXTRACT_JEMALLOC_PROPERTY(dirty_max); | 247 if (ext->GetNumericProperty("generic.heap_size", &heap_size) && |
| 248 EXTRACT_JEMALLOC_PROPERTY(reserve_min); | 248 ext->GetNumericProperty("generic.current_allocated_bytes", |
| 249 EXTRACT_JEMALLOC_PROPERTY(reserve_max); | 249 &allocated_bytes) && |
| 250 EXTRACT_JEMALLOC_PROPERTY(mapped); | 250 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", |
| 251 EXTRACT_JEMALLOC_PROPERTY(committed); | 251 &unmapped_bytes)) { |
| 252 EXTRACT_JEMALLOC_PROPERTY(allocated); | 252 *size = heap_size - allocated_bytes - unmapped_bytes; |
| 253 EXTRACT_JEMALLOC_PROPERTY(dirty); | 253 return true; |
| 254 EXTRACT_JEMALLOC_PROPERTY(reserve_cur); | 254 } |
| 255 #undef EXTRACT_JEMALLOC_PROPERTY | |
| 256 return false; | 255 return false; |
| 257 } | 256 } |
| 258 | 257 |
| 259 static bool get_property_thunk(const char* name, size_t* value) { | |
| 260 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING | |
| 261 switch (allocator) { | |
| 262 case JEMALLOC: | |
| 263 return get_jemalloc_property_thunk(name, value); | |
| 264 case WINHEAP: | |
| 265 case WINLFH: | |
| 266 // TODO(alexeif): Implement for other allocators. | |
| 267 return false; | |
| 268 } | |
| 269 #endif | |
| 270 return MallocExtension::instance()->GetNumericProperty(name, value); | |
| 271 } | |
| 272 | |
| 273 static void get_stats_thunk(char* buffer, int buffer_length) { | 258 static void get_stats_thunk(char* buffer, int buffer_length) { |
| 274 MallocExtension::instance()->GetStats(buffer, buffer_length); | 259 MallocExtension::instance()->GetStats(buffer, buffer_length); |
| 275 } | 260 } |
| 276 | 261 |
| 277 static void release_free_memory_thunk() { | 262 static void release_free_memory_thunk() { |
| 278 MallocExtension::instance()->ReleaseFreeMemory(); | 263 MallocExtension::instance()->ReleaseFreeMemory(); |
| 279 } | 264 } |
| 280 | 265 |
| 281 // The CRT heap initialization stub. | 266 // The CRT heap initialization stub. |
| 282 extern "C" int _heap_init() { | 267 extern "C" int _heap_init() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // basis. Only set the hook if the environment indicates this needs to be | 301 // basis. Only set the hook if the environment indicates this needs to be |
| 317 // enabled. | 302 // enabled. |
| 318 const char* profiling = | 303 const char* profiling = |
| 319 GetenvBeforeMain(tracked_objects::kAlternateProfilerTime); | 304 GetenvBeforeMain(tracked_objects::kAlternateProfilerTime); |
| 320 if (profiling && *profiling == '1') { | 305 if (profiling && *profiling == '1') { |
| 321 tracked_objects::SetAlternateTimeSource( | 306 tracked_objects::SetAlternateTimeSource( |
| 322 tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread, | 307 tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread, |
| 323 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); | 308 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); |
| 324 } | 309 } |
| 325 | 310 |
| 326 base::allocator::thunks::SetGetPropertyFunction(get_property_thunk); | 311 base::allocator::thunks::SetGetAllocatorWasteSizeFunction( |
| 312 get_allocator_waste_size_thunk); |
| 327 base::allocator::thunks::SetGetStatsFunction(get_stats_thunk); | 313 base::allocator::thunks::SetGetStatsFunction(get_stats_thunk); |
| 328 base::allocator::thunks::SetReleaseFreeMemoryFunction( | 314 base::allocator::thunks::SetReleaseFreeMemoryFunction( |
| 329 release_free_memory_thunk); | 315 release_free_memory_thunk); |
| 330 | 316 |
| 331 return 1; | 317 return 1; |
| 332 } | 318 } |
| 333 | 319 |
| 334 // The CRT heap cleanup stub. | 320 // The CRT heap cleanup stub. |
| 335 extern "C" void _heap_term() {} | 321 extern "C" void _heap_term() {} |
| 336 | 322 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 void TCMallocDoFreeForTest(void* ptr) { | 422 void TCMallocDoFreeForTest(void* ptr) { |
| 437 do_free(ptr); | 423 do_free(ptr); |
| 438 } | 424 } |
| 439 | 425 |
| 440 size_t ExcludeSpaceForMarkForTest(size_t size) { | 426 size_t ExcludeSpaceForMarkForTest(size_t size) { |
| 441 return ExcludeSpaceForMark(size); | 427 return ExcludeSpaceForMark(size); |
| 442 } | 428 } |
| 443 | 429 |
| 444 } // namespace allocator. | 430 } // namespace allocator. |
| 445 } // namespace base. | 431 } // namespace base. |
| OLD | NEW |