| 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/process/memory.h" |
| 9 #include "base/profiler/alternate_timer.h" | 10 #include "base/profiler/alternate_timer.h" |
| 10 #include "base/sysinfo.h" | 11 #include "base/sysinfo.h" |
| 11 #include "jemalloc.h" | 12 #include "jemalloc.h" |
| 12 | 13 |
| 13 // When defined, different heap allocators can be used via an environment | 14 // When defined, different heap allocators can be used via an environment |
| 14 // variable set before running the program. This may reduce the amount | 15 // variable set before running the program. This may reduce the amount |
| 15 // of inlining that we get with malloc/free/etc. Disabling makes it | 16 // of inlining that we get with malloc/free/etc. Disabling makes it |
| 16 // so that only tcmalloc can be used. | 17 // so that only tcmalloc can be used. |
| 17 #define ENABLE_DYNAMIC_ALLOCATOR_SWITCHING | 18 #define ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
| 18 | 19 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 do_free(p); | 396 do_free(p); |
| 396 } | 397 } |
| 397 | 398 |
| 398 #endif // WIN32 | 399 #endif // WIN32 |
| 399 | 400 |
| 400 #include "generic_allocators.cc" | 401 #include "generic_allocators.cc" |
| 401 | 402 |
| 402 } // extern C | 403 } // extern C |
| 403 | 404 |
| 404 namespace base { | 405 namespace base { |
| 406 |
| 407 void* UncheckedMalloc(size_t size) { |
| 408 switch (allocator) { |
| 409 case JEMALLOC: |
| 410 return je_malloc(size); |
| 411 case WINHEAP: |
| 412 case WINLFH: |
| 413 return win_heap_malloc(size); |
| 414 case TCMALLOC: |
| 415 return do_malloc(size); |
| 416 } |
| 417 } |
| 418 |
| 405 namespace allocator { | 419 namespace allocator { |
| 406 | 420 |
| 407 void SetupSubprocessAllocator() { | 421 void SetupSubprocessAllocator() { |
| 408 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING | 422 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
| 409 size_t primary_length = 0; | 423 size_t primary_length = 0; |
| 410 getenv_s(&primary_length, NULL, 0, primary_name); | 424 getenv_s(&primary_length, NULL, 0, primary_name); |
| 411 | 425 |
| 412 size_t secondary_length = 0; | 426 size_t secondary_length = 0; |
| 413 char buffer[20]; | 427 char buffer[20]; |
| 414 getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name); | 428 getenv_s(&secondary_length, buffer, sizeof(buffer), secondary_name); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 437 void TCMallocDoFreeForTest(void* ptr) { | 451 void TCMallocDoFreeForTest(void* ptr) { |
| 438 do_free(ptr); | 452 do_free(ptr); |
| 439 } | 453 } |
| 440 | 454 |
| 441 size_t ExcludeSpaceForMarkForTest(size_t size) { | 455 size_t ExcludeSpaceForMarkForTest(size_t size) { |
| 442 return ExcludeSpaceForMark(size); | 456 return ExcludeSpaceForMark(size); |
| 443 } | 457 } |
| 444 | 458 |
| 445 } // namespace allocator. | 459 } // namespace allocator. |
| 446 } // namespace base. | 460 } // namespace base. |
| OLD | NEW |