| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WTF_DefaultAllocator_h | 31 #ifndef WTF_PartitionAllocator_h |
| 32 #define WTF_DefaultAllocator_h | 32 #define WTF_PartitionAllocator_h |
| 33 | 33 |
| 34 // This is the allocator that is used for allocations that are not on the | 34 // This is the allocator that is used for allocations that are not on the |
| 35 // traced, garbage collected heap. It uses FastMalloc for collections, | 35 // traced, garbage collected heap. It uses FastMalloc for collections, |
| 36 // but uses the partition allocator for the backing store of the collections. | 36 // but uses the partition allocator for the backing store of the collections. |
| 37 | 37 |
| 38 #include "wtf/Allocator.h" | 38 #include "wtf/Allocator.h" |
| 39 #include "wtf/Assertions.h" | 39 #include "wtf/Assertions.h" |
| 40 #include "wtf/PartitionAlloc.h" | 40 #include "wtf/PartitionAlloc.h" |
| 41 #include "wtf/Partitions.h" | 41 #include "wtf/Partitions.h" |
| 42 | 42 |
| 43 #include <string.h> | 43 #include <string.h> |
| 44 | 44 |
| 45 namespace WTF { | 45 namespace WTF { |
| 46 | 46 |
| 47 class DefaultAllocatorDummyVisitor; | 47 class PartitionAllocatorDummyVisitor; |
| 48 | 48 |
| 49 class WTF_EXPORT DefaultAllocator { | 49 class WTF_EXPORT PartitionAllocator { |
| 50 public: | 50 public: |
| 51 typedef DefaultAllocatorDummyVisitor Visitor; | 51 typedef PartitionAllocatorDummyVisitor Visitor; |
| 52 static const bool isGarbageCollected = false; | 52 static const bool isGarbageCollected = false; |
| 53 | 53 |
| 54 template<typename T> | 54 template<typename T> |
| 55 static size_t quantizedSize(size_t count) | 55 static size_t quantizedSize(size_t count) |
| 56 { | 56 { |
| 57 RELEASE_ASSERT(count <= kGenericMaxDirectMapped / sizeof(T)); | 57 RELEASE_ASSERT(count <= kGenericMaxDirectMapped / sizeof(T)); |
| 58 return partitionAllocActualSize(Partitions::bufferPartition(), count * s
izeof(T)); | 58 return partitionAllocActualSize(Partitions::bufferPartition(), count * s
izeof(T)); |
| 59 } | 59 } |
| 60 template <typename T> | 60 template <typename T> |
| 61 static T* allocateVectorBacking(size_t size) | 61 static T* allocateVectorBacking(size_t size) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 static void enterGCForbiddenScope() { } | 179 static void enterGCForbiddenScope() { } |
| 180 static void leaveGCForbiddenScope() { } | 180 static void leaveGCForbiddenScope() { } |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 static void* allocateBacking(size_t); | 183 static void* allocateBacking(size_t); |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 // The Windows compiler seems to be very eager to instantiate things it won't | 186 // The Windows compiler seems to be very eager to instantiate things it won't |
| 187 // need, so unless we have this class we get compile errors. | 187 // need, so unless we have this class we get compile errors. |
| 188 class DefaultAllocatorDummyVisitor { | 188 class PartitionAllocatorDummyVisitor { |
| 189 public: | 189 public: |
| 190 template<typename T> inline bool isHeapObjectAlive(T obj) | 190 template<typename T> inline bool isHeapObjectAlive(T obj) |
| 191 { | 191 { |
| 192 ASSERT_NOT_REACHED(); | 192 ASSERT_NOT_REACHED(); |
| 193 return false; | 193 return false; |
| 194 } | 194 } |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 } // namespace WTF | 197 } // namespace WTF |
| 198 | 198 |
| 199 #define WTF_USE_ALLOCATOR(ClassName, Allocator) \ | 199 #define WTF_USE_ALLOCATOR(ClassName, Allocator) \ |
| 200 public: \ | 200 public: \ |
| 201 void* operator new(size_t size) \ | 201 void* operator new(size_t size) \ |
| 202 { \ | 202 { \ |
| 203 return Allocator::template malloc<void*, ClassName>(size); \ | 203 return Allocator::template malloc<void*, ClassName>(size); \ |
| 204 } \ | 204 } \ |
| 205 void operator delete(void* p) { Allocator::free(p); } \ | 205 void operator delete(void* p) { Allocator::free(p); } \ |
| 206 void* operator new[](size_t size) { return Allocator::template newArray<Clas
sName>(size); } \ | 206 void* operator new[](size_t size) { return Allocator::template newArray<Clas
sName>(size); } \ |
| 207 void operator delete[](void* p) { Allocator::deleteArray(p); } \ | 207 void operator delete[](void* p) { Allocator::deleteArray(p); } \ |
| 208 void* operator new(size_t, NotNullTag, void* location) \ | 208 void* operator new(size_t, NotNullTag, void* location) \ |
| 209 { \ | 209 { \ |
| 210 ASSERT(location); \ | 210 ASSERT(location); \ |
| 211 return location; \ | 211 return location; \ |
| 212 } \ | 212 } \ |
| 213 private: \ | 213 private: \ |
| 214 typedef int __thisIsHereToForceASemicolonAfterThisMacro | 214 typedef int __thisIsHereToForceASemicolonAfterThisMacro |
| 215 | 215 |
| 216 using WTF::DefaultAllocator; | 216 using WTF::PartitionAllocator; |
| 217 | 217 |
| 218 #endif // WTF_DefaultAllocator_h | 218 #endif // WTF_PartitionAllocator_h |
| OLD | NEW |