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 "wtf/Assertions.h" | 8 #include "wtf/Assertions.h" |
9 #include "wtf/StdLibExtras.h" | 9 #include "wtf/StdLibExtras.h" |
10 #include "wtf/allocator/Partitions.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. |
21 // Garbage-collected objects should be in Members but you do not need the | 21 // Garbage-collected objects should be in Members but you do not need the |
22 // trace method as they are on the stack. (Down the line these might turn | 22 // trace method as they are on the stack. (Down the line these might turn |
23 // in to raw pointers, but for now Members indicate that we have thought | 23 // in to raw pointers, but for now Members indicate that we have thought |
24 // about them and explicitly taken care of them.) | 24 // about them and explicitly taken care of them.) |
25 // | 25 // |
26 // DISALLOW_NEW(): Cannot be allocated with new operators but can be a | 26 // DISALLOW_NEW(): Cannot be allocated with new operators but can be a |
27 // part of object. If it has Members you need a trace method and the containing | 27 // part of object. If it has Members you need a trace method and the containing |
28 // object needs to call that trace method. | 28 // object needs to call that trace method. |
29 // | 29 // |
30 // DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(): Allows only placement new operator. Thi
s | 30 // DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(): Allows only placement new operator. This |
31 // disallows general allocation of this object but allows to put the object as a | 31 // disallows general allocation of this object but allows to put the object as a |
32 // value object in collections. If these have Members you need to have a trace | 32 // value object in collections. If these have Members you need to have a trace |
33 // method. That trace method will be called automatically by the on-heap | 33 // method. That trace method will be called automatically by the on-heap |
34 // collections. | 34 // collections. |
35 // | 35 // |
36 #define DISALLOW_NEW() \ | 36 #define DISALLOW_NEW() \ |
37 private: \ | 37 private: \ |
38 void* operator new(size_t) = delete; \ | 38 void* operator new(size_t) = delete; \ |
39 void* operator new(size_t, NotNullTag, void*) = delete; \ | 39 void* operator new(size_t, NotNullTag, void*) = delete; \ |
40 void* operator new(size_t, void*) = delete; \ | 40 void* operator new(size_t, void*) = delete; \ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 __attribute__((annotate("blink_stack_allocated"))) void* operator new( \ | 75 __attribute__((annotate("blink_stack_allocated"))) void* operator new( \ |
76 size_t) = delete; \ | 76 size_t) = delete; \ |
77 void* operator new(size_t, NotNullTag, void*) = delete; \ | 77 void* operator new(size_t, NotNullTag, void*) = delete; \ |
78 void* operator new(size_t, void*) = delete; \ | 78 void* operator new(size_t, void*) = delete; \ |
79 \ | 79 \ |
80 public: | 80 public: |
81 #else | 81 #else |
82 #define STACK_ALLOCATED() DISALLOW_NEW() | 82 #define STACK_ALLOCATED() DISALLOW_NEW() |
83 #endif | 83 #endif |
84 | 84 |
85 // Provides customizable overrides of fastMalloc/fastFree and operator new/delet
e | 85 // Provides customizable overrides of fastMalloc/fastFree and operator |
| 86 // new/delete |
86 // | 87 // |
87 // Provided functionality: | 88 // Provided functionality: |
88 // Macro: USING_FAST_MALLOC | 89 // Macro: USING_FAST_MALLOC |
89 // | 90 // |
90 // Example usage: | 91 // Example usage: |
91 // class Widget { | 92 // class Widget { |
92 // USING_FAST_MALLOC(Widget) | 93 // USING_FAST_MALLOC(Widget) |
93 // ... | 94 // ... |
94 // }; | 95 // }; |
95 // | 96 // |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Furthermore, the |WITH_TYPE_NAME| variant does not work if |type| is a | 133 // Furthermore, the |WITH_TYPE_NAME| variant does not work if |type| is a |
133 // template argument; |USING_FAST_MALLOC| does. | 134 // template argument; |USING_FAST_MALLOC| does. |
134 #define USING_FAST_MALLOC(type) \ | 135 #define USING_FAST_MALLOC(type) \ |
135 USING_FAST_MALLOC_INTERNAL(type, WTF_HEAP_PROFILER_TYPE_NAME(type)) | 136 USING_FAST_MALLOC_INTERNAL(type, WTF_HEAP_PROFILER_TYPE_NAME(type)) |
136 #define USING_FAST_MALLOC_WITH_TYPE_NAME(type) \ | 137 #define USING_FAST_MALLOC_WITH_TYPE_NAME(type) \ |
137 USING_FAST_MALLOC_INTERNAL(type, #type) | 138 USING_FAST_MALLOC_INTERNAL(type, #type) |
138 | 139 |
139 } // namespace WTF | 140 } // namespace WTF |
140 | 141 |
141 #endif /* WTF_Allocator_h */ | 142 #endif /* WTF_Allocator_h */ |
OLD | NEW |