| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ | 5 #ifndef BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ |
| 6 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ | 6 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // config (tcmalloc, glibc, ...). | 39 // config (tcmalloc, glibc, ...). |
| 40 // | 40 // |
| 41 // It is possible to dynamically insert further AllocatorDispatch stages | 41 // It is possible to dynamically insert further AllocatorDispatch stages |
| 42 // to the front of the chain, for debugging / profiling purposes. | 42 // to the front of the chain, for debugging / profiling purposes. |
| 43 // | 43 // |
| 44 // All the functions must be thred safe. The shim does not enforce any | 44 // All the functions must be thred safe. The shim does not enforce any |
| 45 // serialization. This is to route to thread-aware allocators (e.g, tcmalloc) | 45 // serialization. This is to route to thread-aware allocators (e.g, tcmalloc) |
| 46 // wihout introducing unnecessary perf hits. | 46 // wihout introducing unnecessary perf hits. |
| 47 | 47 |
| 48 struct AllocatorDispatch { | 48 struct AllocatorDispatch { |
| 49 using AllocFn = void*(const AllocatorDispatch* self, size_t size); | 49 using AllocFn = void*(const AllocatorDispatch* self, |
| 50 size_t size, |
| 51 void* context); |
| 50 using AllocZeroInitializedFn = void*(const AllocatorDispatch* self, | 52 using AllocZeroInitializedFn = void*(const AllocatorDispatch* self, |
| 51 size_t n, | 53 size_t n, |
| 52 size_t size); | 54 size_t size, |
| 55 void* context); |
| 53 using AllocAlignedFn = void*(const AllocatorDispatch* self, | 56 using AllocAlignedFn = void*(const AllocatorDispatch* self, |
| 54 size_t alignment, | 57 size_t alignment, |
| 55 size_t size); | 58 size_t size, |
| 59 void* context); |
| 56 using ReallocFn = void*(const AllocatorDispatch* self, | 60 using ReallocFn = void*(const AllocatorDispatch* self, |
| 57 void* address, | 61 void* address, |
| 58 size_t size); | 62 size_t size, |
| 59 using FreeFn = void(const AllocatorDispatch* self, void* address); | 63 void* context); |
| 64 using FreeFn = void(const AllocatorDispatch* self, |
| 65 void* address, |
| 66 void* context); |
| 60 // Returns the best available estimate for the actual amount of memory | 67 // Returns the best available estimate for the actual amount of memory |
| 61 // consumed by the allocation |address|. If possible, this should include | 68 // consumed by the allocation |address|. If possible, this should include |
| 62 // heap overhead or at least a decent estimate of the full cost of the | 69 // heap overhead or at least a decent estimate of the full cost of the |
| 63 // allocation. If no good estimate is possible, returns zero. | 70 // allocation. If no good estimate is possible, returns zero. |
| 64 using GetSizeEstimateFn = size_t(const AllocatorDispatch* self, | 71 using GetSizeEstimateFn = size_t(const AllocatorDispatch* self, |
| 65 void* address); | 72 void* address, |
| 73 void* context); |
| 66 using BatchMallocFn = unsigned(const AllocatorDispatch* self, | 74 using BatchMallocFn = unsigned(const AllocatorDispatch* self, |
| 67 size_t size, | 75 size_t size, |
| 68 void** results, | 76 void** results, |
| 69 unsigned num_requested); | 77 unsigned num_requested, |
| 78 void* context); |
| 70 using BatchFreeFn = void(const AllocatorDispatch* self, | 79 using BatchFreeFn = void(const AllocatorDispatch* self, |
| 71 void** to_be_freed, | 80 void** to_be_freed, |
| 72 unsigned num_to_be_freed); | 81 unsigned num_to_be_freed, |
| 82 void* context); |
| 73 using FreeDefiniteSizeFn = void(const AllocatorDispatch* self, | 83 using FreeDefiniteSizeFn = void(const AllocatorDispatch* self, |
| 74 void* ptr, | 84 void* ptr, |
| 75 size_t size); | 85 size_t size, |
| 86 void* context); |
| 76 | 87 |
| 77 AllocFn* const alloc_function; | 88 AllocFn* const alloc_function; |
| 78 AllocZeroInitializedFn* const alloc_zero_initialized_function; | 89 AllocZeroInitializedFn* const alloc_zero_initialized_function; |
| 79 AllocAlignedFn* const alloc_aligned_function; | 90 AllocAlignedFn* const alloc_aligned_function; |
| 80 ReallocFn* const realloc_function; | 91 ReallocFn* const realloc_function; |
| 81 FreeFn* const free_function; | 92 FreeFn* const free_function; |
| 82 GetSizeEstimateFn* const get_size_estimate_function; | 93 GetSizeEstimateFn* const get_size_estimate_function; |
| 83 BatchMallocFn* const batch_malloc_function; | 94 BatchMallocFn* const batch_malloc_function; |
| 84 BatchFreeFn* const batch_free_function; | 95 BatchFreeFn* const batch_free_function; |
| 85 FreeDefiniteSizeFn* const free_definite_size_function; | 96 FreeDefiniteSizeFn* const free_definite_size_function; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 113 | 124 |
| 114 #if defined(OS_MACOSX) | 125 #if defined(OS_MACOSX) |
| 115 // On macOS, the allocator shim needs to be turned on during runtime. | 126 // On macOS, the allocator shim needs to be turned on during runtime. |
| 116 BASE_EXPORT void InitializeAllocatorShim(); | 127 BASE_EXPORT void InitializeAllocatorShim(); |
| 117 #endif // defined(OS_MACOSX) | 128 #endif // defined(OS_MACOSX) |
| 118 | 129 |
| 119 } // namespace allocator | 130 } // namespace allocator |
| 120 } // namespace base | 131 } // namespace base |
| 121 | 132 |
| 122 #endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ | 133 #endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ |
| OLD | NEW |