| 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 26 matching lines...) Expand all Loading... |
| 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/allocator/PartitionAlloc.h" | 40 #include "wtf/allocator/PartitionAlloc.h" |
| 41 #include "wtf/allocator/Partitions.h" | 41 #include "wtf/allocator/Partitions.h" |
| 42 | 42 |
| 43 #include <string.h> | 43 #include <string.h> |
| 44 | 44 |
| 45 namespace WTF { | 45 namespace WTF { |
| 46 | 46 |
| 47 class PartitionAllocatorDummyVisitor; | 47 class PartitionAllocatorDummyVisitor { |
| 48 DISALLOW_NEW(); |
| 49 }; |
| 48 | 50 |
| 49 class WTF_EXPORT PartitionAllocator { | 51 class WTF_EXPORT PartitionAllocator { |
| 50 public: | 52 public: |
| 51 typedef PartitionAllocatorDummyVisitor Visitor; | 53 typedef PartitionAllocatorDummyVisitor Visitor; |
| 52 static const bool isGarbageCollected = false; | 54 static const bool isGarbageCollected = false; |
| 53 | 55 |
| 54 template<typename T> | 56 template<typename T> |
| 55 static size_t quantizedSize(size_t count) | 57 static size_t quantizedSize(size_t count) |
| 56 { | 58 { |
| 57 RELEASE_ASSERT(count <= kGenericMaxDirectMapped / sizeof(T)); | 59 RELEASE_ASSERT(count <= kGenericMaxDirectMapped / sizeof(T)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 { | 119 { |
| 118 return malloc<void*, void>(bytes, WTF_HEAP_PROFILER_TYPE_NAME(T)); | 120 return malloc<void*, void>(bytes, WTF_HEAP_PROFILER_TYPE_NAME(T)); |
| 119 } | 121 } |
| 120 static void | 122 static void |
| 121 deleteArray(void* ptr) | 123 deleteArray(void* ptr) |
| 122 { | 124 { |
| 123 free(ptr); // Not the system free, the one from this class. | 125 free(ptr); // Not the system free, the one from this class. |
| 124 } | 126 } |
| 125 | 127 |
| 126 static bool isAllocationAllowed() { return true; } | 128 static bool isAllocationAllowed() { return true; } |
| 127 template<typename T> | |
| 128 static bool isHeapObjectAlive(T* object) | |
| 129 { | |
| 130 ASSERT_NOT_REACHED(); | |
| 131 return false; | |
| 132 } | |
| 133 | |
| 134 static void markNoTracing(...) | |
| 135 { | |
| 136 ASSERT_NOT_REACHED(); | |
| 137 } | |
| 138 | |
| 139 static void registerDelayedMarkNoTracing(...) | |
| 140 { | |
| 141 ASSERT_NOT_REACHED(); | |
| 142 } | |
| 143 | |
| 144 static void registerWeakMembers(...) | |
| 145 { | |
| 146 ASSERT_NOT_REACHED(); | |
| 147 } | |
| 148 | |
| 149 static void registerWeakTable(...) | |
| 150 { | |
| 151 ASSERT_NOT_REACHED(); | |
| 152 } | |
| 153 | |
| 154 #if ENABLE(ASSERT) | |
| 155 static bool weakTableRegistered(...) | |
| 156 { | |
| 157 ASSERT_NOT_REACHED(); | |
| 158 return false; | |
| 159 } | |
| 160 #endif | |
| 161 | |
| 162 template<typename T, typename Traits> | |
| 163 static void trace(...) | |
| 164 { | |
| 165 ASSERT_NOT_REACHED(); | |
| 166 } | |
| 167 | 129 |
| 168 template<typename T> | 130 template<typename T> |
| 169 struct OtherType { | 131 struct OtherType { |
| 170 typedef T* Type; | 132 typedef T* Type; |
| 171 }; | 133 }; |
| 172 | 134 |
| 173 template<typename T> | 135 template<typename T> |
| 174 static T& getOther(T* other) | 136 static T& getOther(T* other) |
| 175 { | 137 { |
| 176 return *other; | 138 return *other; |
| 177 } | 139 } |
| 178 | 140 |
| 179 static void enterGCForbiddenScope() { } | 141 static void enterGCForbiddenScope() { } |
| 180 static void leaveGCForbiddenScope() { } | 142 static void leaveGCForbiddenScope() { } |
| 181 | 143 |
| 182 private: | 144 private: |
| 183 static void* allocateBacking(size_t, const char* typeName); | 145 static void* allocateBacking(size_t, const char* typeName); |
| 184 }; | 146 }; |
| 185 | 147 |
| 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. | |
| 188 class PartitionAllocatorDummyVisitor { | |
| 189 DISALLOW_NEW(); | |
| 190 public: | |
| 191 template<typename T> inline bool isHeapObjectAlive(T obj) | |
| 192 { | |
| 193 ASSERT_NOT_REACHED(); | |
| 194 return false; | |
| 195 } | |
| 196 }; | |
| 197 | |
| 198 // Specializations for heap profiling, so type profiling of |char| is possible | 148 // Specializations for heap profiling, so type profiling of |char| is possible |
| 199 // even in official builds (because |char| makes up a large portion of the heap.
) | 149 // even in official builds (because |char| makes up a large portion of the heap.
) |
| 200 template <> WTF_EXPORT char* PartitionAllocator::allocateVectorBacking<char>(siz
e_t); | 150 template <> WTF_EXPORT char* PartitionAllocator::allocateVectorBacking<char>(siz
e_t); |
| 201 template <> WTF_EXPORT char* PartitionAllocator::allocateExpandedVectorBacking<c
har>(size_t); | 151 template <> WTF_EXPORT char* PartitionAllocator::allocateExpandedVectorBacking<c
har>(size_t); |
| 202 | 152 |
| 203 } // namespace WTF | 153 } // namespace WTF |
| 204 | 154 |
| 205 #define WTF_USE_ALLOCATOR(ClassName, Allocator) \ | 155 #define WTF_USE_ALLOCATOR(ClassName, Allocator) \ |
| 206 public: \ | 156 public: \ |
| 207 void* operator new(size_t size) \ | 157 void* operator new(size_t size) \ |
| 208 { \ | 158 { \ |
| 209 return Allocator::template malloc<void*, ClassName>(size, WTF_HEAP_PROFI
LER_TYPE_NAME(ClassName)); \ | 159 return Allocator::template malloc<void*, ClassName>(size, WTF_HEAP_PROFI
LER_TYPE_NAME(ClassName)); \ |
| 210 } \ | 160 } \ |
| 211 void operator delete(void* p) { Allocator::free(p); } \ | 161 void operator delete(void* p) { Allocator::free(p); } \ |
| 212 void* operator new[](size_t size) { return Allocator::template newArray<Clas
sName>(size); } \ | 162 void* operator new[](size_t size) { return Allocator::template newArray<Clas
sName>(size); } \ |
| 213 void operator delete[](void* p) { Allocator::deleteArray(p); } \ | 163 void operator delete[](void* p) { Allocator::deleteArray(p); } \ |
| 214 void* operator new(size_t, NotNullTag, void* location) \ | 164 void* operator new(size_t, NotNullTag, void* location) \ |
| 215 { \ | 165 { \ |
| 216 ASSERT(location); \ | 166 ASSERT(location); \ |
| 217 return location; \ | 167 return location; \ |
| 218 } \ | 168 } \ |
| 219 private: \ | 169 private: \ |
| 220 typedef int __thisIsHereToForceASemicolonAfterThisMacro | 170 typedef int __thisIsHereToForceASemicolonAfterThisMacro |
| 221 | 171 |
| 222 using WTF::PartitionAllocator; | 172 using WTF::PartitionAllocator; |
| 223 | 173 |
| 224 #endif // WTF_PartitionAllocator_h | 174 #endif // WTF_PartitionAllocator_h |
| OLD | NEW |