| 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 GCInfo_h | 5 #ifndef GCInfo_h |
| 6 #define GCInfo_h | 6 #define GCInfo_h |
| 7 | 7 |
| 8 #include "platform/heap/Visitor.h" | 8 #include "platform/heap/Visitor.h" |
| 9 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 10 #include "wtf/Atomics.h" | 10 #include "wtf/Atomics.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // encounter. | 146 // encounter. |
| 147 static const size_t maxIndex = 1 << 14; | 147 static const size_t maxIndex = 1 << 14; |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 static void resize(); | 150 static void resize(); |
| 151 | 151 |
| 152 static int s_gcInfoIndex; | 152 static int s_gcInfoIndex; |
| 153 static size_t s_gcInfoTableSize; | 153 static size_t s_gcInfoTableSize; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 // This macro should be used when returning a unique 14 bit integer | 156 // GCInfotAtBaseType should be used when returning a unique 14 bit integer |
| 157 // for a given gcInfo. | 157 // for a given gcInfo. |
| 158 #define RETURN_GCINFO_INDEX() \ | |
| 159 static size_t gcInfoIndex = 0; \ | |
| 160 ASSERT(s_gcInfoTable); \ | |
| 161 if (!acquireLoad(&gcInfoIndex)) \ | |
| 162 GCInfoTable::ensureGCInfoIndex(&gcInfo, &gcInfoIndex); \ | |
| 163 ASSERT(gcInfoIndex >= 1); \ | |
| 164 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); \ | |
| 165 return gcInfoIndex; | |
| 166 | |
| 167 template<typename T> | 158 template<typename T> |
| 168 struct GCInfoAtBase { | 159 struct GCInfoAtBaseType { |
| 169 static size_t index() | 160 static size_t index() |
| 170 { | 161 { |
| 171 static_assert(sizeof(T), "T must be fully defined"); | 162 static_assert(sizeof(T), "T must be fully defined"); |
| 172 static const GCInfo gcInfo = { | 163 static const GCInfo gcInfo = { |
| 173 TraceTrait<T>::trace, | 164 TraceTrait<T>::trace, |
| 174 FinalizerTrait<T>::finalize, | 165 FinalizerTrait<T>::finalize, |
| 175 FinalizerTrait<T>::nonTrivialFinalizer, | 166 FinalizerTrait<T>::nonTrivialFinalizer, |
| 176 WTF::IsPolymorphic<T>::value, | 167 WTF::IsPolymorphic<T>::value, |
| 177 #if ENABLE(GC_PROFILING) || ENABLE(DETAILED_MEMORY_INFRA) | 168 #if ENABLE(GC_PROFILING) || ENABLE(DETAILED_MEMORY_INFRA) |
| 178 TypenameStringTrait<T>::get | 169 TypenameStringTrait<T>::get |
| 179 #endif | 170 #endif |
| 180 }; | 171 }; |
| 181 RETURN_GCINFO_INDEX(); | 172 |
| 173 static size_t gcInfoIndex = 0; |
| 174 ASSERT(s_gcInfoTable); |
| 175 if (!acquireLoad(&gcInfoIndex)) |
| 176 GCInfoTable::ensureGCInfoIndex(&gcInfo, &gcInfoIndex); |
| 177 ASSERT(gcInfoIndex >= 1); |
| 178 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); |
| 179 return gcInfoIndex; |
| 182 } | 180 } |
| 183 }; | 181 }; |
| 184 | 182 |
| 185 template<typename T, bool = WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<
T>::Type, GarbageCollected>::value> struct GetGarbageCollectedBase; | 183 template<typename T, bool = WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<
T>::Type, GarbageCollected>::value> struct GetGarbageCollectedType; |
| 186 | 184 |
| 187 template<typename T> | 185 template<typename T> |
| 188 struct GetGarbageCollectedBase<T, true> { | 186 struct GetGarbageCollectedType<T, true> { |
| 189 typedef typename T::GarbageCollectedBase type; | 187 using type = typename T::GarbageCollectedType; |
| 190 }; | 188 }; |
| 191 | 189 |
| 192 template<typename T> | 190 template<typename T> |
| 193 struct GetGarbageCollectedBase<T, false> { | 191 struct GetGarbageCollectedType<T, false> { |
| 194 typedef T type; | 192 using type = T; |
| 195 }; | 193 }; |
| 196 | 194 |
| 197 template<typename T> | 195 template<typename T> |
| 198 struct GCInfoTrait { | 196 struct GCInfoTrait { |
| 199 static size_t index() | 197 static size_t index() |
| 200 { | 198 { |
| 201 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); | 199 return GCInfoAtBaseType<typename GetGarbageCollectedType<T>::type>::inde
x(); |
| 202 } | 200 } |
| 203 }; | 201 }; |
| 204 | 202 |
| 205 template<typename U> class GCInfoTrait<const U> : public GCInfoTrait<U> { }; | 203 template<typename U> class GCInfoTrait<const U> : public GCInfoTrait<U> { }; |
| 206 | 204 |
| 207 template<typename T, typename U, typename V, typename W, typename X> class HeapH
ashMap; | 205 template<typename T, typename U, typename V, typename W, typename X> class HeapH
ashMap; |
| 208 template<typename T, typename U, typename V> class HeapHashSet; | 206 template<typename T, typename U, typename V> class HeapHashSet; |
| 209 template<typename T, typename U, typename V> class HeapLinkedHashSet; | 207 template<typename T, typename U, typename V> class HeapLinkedHashSet; |
| 210 template<typename T, size_t inlineCapacity, typename U> class HeapListHashSet; | 208 template<typename T, size_t inlineCapacity, typename U> class HeapListHashSet; |
| 211 template<typename T, size_t inlineCapacity> class HeapVector; | 209 template<typename T, size_t inlineCapacity> class HeapVector; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 template<typename T, size_t inlineCapacity> | 221 template<typename T, size_t inlineCapacity> |
| 224 struct GCInfoTrait<HeapVector<T, inlineCapacity>> : public GCInfoTrait<Vector<T,
inlineCapacity, HeapAllocator>> { }; | 222 struct GCInfoTrait<HeapVector<T, inlineCapacity>> : public GCInfoTrait<Vector<T,
inlineCapacity, HeapAllocator>> { }; |
| 225 template<typename T, size_t inlineCapacity> | 223 template<typename T, size_t inlineCapacity> |
| 226 struct GCInfoTrait<HeapDeque<T, inlineCapacity>> : public GCInfoTrait<Deque<T, i
nlineCapacity, HeapAllocator>> { }; | 224 struct GCInfoTrait<HeapDeque<T, inlineCapacity>> : public GCInfoTrait<Deque<T, i
nlineCapacity, HeapAllocator>> { }; |
| 227 template<typename T, typename U, typename V> | 225 template<typename T, typename U, typename V> |
| 228 struct GCInfoTrait<HeapHashCountedSet<T, U, V>> : public GCInfoTrait<HashCounted
Set<T, U, V, HeapAllocator>> { }; | 226 struct GCInfoTrait<HeapHashCountedSet<T, U, V>> : public GCInfoTrait<HashCounted
Set<T, U, V, HeapAllocator>> { }; |
| 229 | 227 |
| 230 } // namespace blink | 228 } // namespace blink |
| 231 | 229 |
| 232 #endif | 230 #endif |
| OLD | NEW |