| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 WTF_Allocator_h | 5 #ifndef WTF_Allocator_h |
| 6 #define WTF_Allocator_h | 6 #define WTF_Allocator_h |
| 7 | 7 |
| 8 #include "base/allocator/partition_allocator/partitions.h" |
| 8 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 9 #include "wtf/StdLibExtras.h" | 10 #include "wtf/StdLibExtras.h" |
| 10 #include "wtf/allocator/Partitions.h" | |
| 11 | 11 |
| 12 namespace WTF { | 12 namespace WTF { |
| 13 | 13 |
| 14 // Classes that contain references to garbage-collected objects but aren't | 14 // Classes that contain references to garbage-collected objects but aren't |
| 15 // themselves garbaged allocated, have some extra macros available which | 15 // themselves garbaged allocated, have some extra macros available which |
| 16 // allows their use to be restricted to cases where the garbage collector | 16 // allows their use to be restricted to cases where the garbage collector |
| 17 // is able to discover their references. These macros will be useful for | 17 // is able to discover their references. These macros will be useful for |
| 18 // non-garbage-collected objects to avoid unintended allocations. | 18 // non-garbage-collected objects to avoid unintended allocations. |
| 19 // | 19 // |
| 20 // STACK_ALLOCATED(): Use if the object is only stack allocated. | 20 // STACK_ALLOCATED(): Use if the object is only stack allocated. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // ... | 94 // ... |
| 95 // }; | 95 // }; |
| 96 // | 96 // |
| 97 // struct Data { | 97 // struct Data { |
| 98 // USING_FAST_MALLOC(Data) | 98 // USING_FAST_MALLOC(Data) |
| 99 // public: | 99 // public: |
| 100 // ... | 100 // ... |
| 101 // }; | 101 // }; |
| 102 // | 102 // |
| 103 | 103 |
| 104 #define USING_FAST_MALLOC_INTERNAL(type, typeName) \ | 104 #define USING_FAST_MALLOC_INTERNAL(type, typeName) \ |
| 105 public: \ | 105 public: \ |
| 106 void* operator new(size_t, void* p) { return p; } \ | 106 void* operator new(size_t, void* p) { return p; } \ |
| 107 void* operator new[](size_t, void* p) { return p; } \ | 107 void* operator new[](size_t, void* p) { return p; } \ |
| 108 \ | 108 \ |
| 109 void* operator new(size_t size) { \ | 109 void* operator new(size_t size) { \ |
| 110 return ::WTF::Partitions::fastMalloc(size, typeName); \ | 110 return ::base::Partitions::fastMalloc(size, typeName); \ |
| 111 } \ | 111 } \ |
| 112 \ | 112 \ |
| 113 void operator delete(void* p) { ::WTF::Partitions::fastFree(p); } \ | 113 void operator delete(void* p) { ::base::Partitions::fastFree(p); } \ |
| 114 \ | 114 \ |
| 115 void* operator new[](size_t size) { \ | 115 void* operator new[](size_t size) { \ |
| 116 return ::WTF::Partitions::fastMalloc(size, typeName); \ | 116 return ::base::Partitions::fastMalloc(size, typeName); \ |
| 117 } \ | 117 } \ |
| 118 \ | 118 \ |
| 119 void operator delete[](void* p) { ::WTF::Partitions::fastFree(p); } \ | 119 void operator delete[](void* p) { ::base::Partitions::fastFree(p); } \ |
| 120 void* operator new(size_t, NotNullTag, void* location) { \ | 120 void* operator new(size_t, NotNullTag, void* location) { \ |
| 121 ASSERT(location); \ | 121 DCHECK(location); \ |
| 122 return location; \ | 122 return location; \ |
| 123 } \ | 123 } \ |
| 124 \ | 124 \ |
| 125 private: \ | 125 private: \ |
| 126 typedef int __thisIsHereToForceASemicolonAfterThisMacro | 126 typedef int __thisIsHereToForceASemicolonAfterThisMacro |
| 127 | 127 |
| 128 // Both of these macros enable fast malloc and provide type info to the heap | 128 // Both of these macros enable fast malloc and provide type info to the heap |
| 129 // profiler. The regular macro does not provide type info in official builds, | 129 // profiler. The regular macro does not provide type info in official builds, |
| 130 // to avoid bloating the binary with type name strings. The |WITH_TYPE_NAME| | 130 // to avoid bloating the binary with type name strings. The |WITH_TYPE_NAME| |
| 131 // variant provides type info unconditionally, so it should be used sparingly. | 131 // variant provides type info unconditionally, so it should be used sparingly. |
| 132 // Furthermore, the |WITH_TYPE_NAME| variant does not work if |type| is a | 132 // Furthermore, the |WITH_TYPE_NAME| variant does not work if |type| is a |
| 133 // template argument; |USING_FAST_MALLOC| does. | 133 // template argument; |USING_FAST_MALLOC| does. |
| 134 #define USING_FAST_MALLOC(type) \ | 134 #define USING_FAST_MALLOC(type) \ |
| 135 USING_FAST_MALLOC_INTERNAL(type, WTF_HEAP_PROFILER_TYPE_NAME(type)) | 135 USING_FAST_MALLOC_INTERNAL(type, WTF_HEAP_PROFILER_TYPE_NAME(type)) |
| 136 #define USING_FAST_MALLOC_WITH_TYPE_NAME(type) \ | 136 #define USING_FAST_MALLOC_WITH_TYPE_NAME(type) \ |
| 137 USING_FAST_MALLOC_INTERNAL(type, #type) | 137 USING_FAST_MALLOC_INTERNAL(type, #type) |
| 138 | 138 |
| 139 } // namespace WTF | 139 } // namespace WTF |
| 140 | 140 |
| 141 #endif /* WTF_Allocator_h */ | 141 #endif /* WTF_Allocator_h */ |
| OLD | NEW |