| 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 HeapAllocator_h | 5 #ifndef HeapAllocator_h |
| 6 #define HeapAllocator_h | 6 #define HeapAllocator_h |
| 7 | 7 |
| 8 #include "platform/heap/Heap.h" | 8 #include "platform/heap/Heap.h" |
| 9 #include "platform/heap/Persistent.h" | 9 #include "platform/heap/Persistent.h" |
| 10 #include "platform/heap/TraceTraits.h" | 10 #include "platform/heap/TraceTraits.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 { | 142 { |
| 143 return ThreadHeap::isHeapObjectAlive(object); | 143 return ThreadHeap::isHeapObjectAlive(object); |
| 144 } | 144 } |
| 145 | 145 |
| 146 template<typename VisitorDispatcher> | 146 template<typename VisitorDispatcher> |
| 147 static void markNoTracing(VisitorDispatcher visitor, const void* t) { visito
r->markNoTracing(t); } | 147 static void markNoTracing(VisitorDispatcher visitor, const void* t) { visito
r->markNoTracing(t); } |
| 148 | 148 |
| 149 template<typename VisitorDispatcher, typename T, typename Traits> | 149 template<typename VisitorDispatcher, typename T, typename Traits> |
| 150 static void trace(VisitorDispatcher visitor, T& t) | 150 static void trace(VisitorDispatcher visitor, T& t) |
| 151 { | 151 { |
| 152 TraceCollectionIfEnabled<WTF::NeedsTracingTrait<Traits>::value, Traits::
weakHandlingFlag, WTF::WeakPointersActWeak, T, Traits>::trace(visitor, t); | 152 TraceCollectionIfEnabled<WTF::IsTraceableInCollectionTrait<Traits>::valu
e, Traits::weakHandlingFlag, WTF::WeakPointersActWeak, T, Traits>::trace(visitor
, t); |
| 153 } | 153 } |
| 154 | 154 |
| 155 template<typename VisitorDispatcher> | 155 template<typename VisitorDispatcher> |
| 156 static void registerDelayedMarkNoTracing(VisitorDispatcher visitor, const vo
id* object) | 156 static void registerDelayedMarkNoTracing(VisitorDispatcher visitor, const vo
id* object) |
| 157 { | 157 { |
| 158 visitor->registerDelayedMarkNoTracing(object); | 158 visitor->registerDelayedMarkNoTracing(object); |
| 159 } | 159 } |
| 160 | 160 |
| 161 template<typename VisitorDispatcher> | 161 template<typename VisitorDispatcher> |
| 162 static void registerWeakMembers(VisitorDispatcher visitor, const void* closu
re, const void* object, WeakCallback callback) | 162 static void registerWeakMembers(VisitorDispatcher visitor, const void* closu
re, const void* object, WeakCallback callback) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 template<typename VisitorDispatcher, typename Value> | 201 template<typename VisitorDispatcher, typename Value> |
| 202 static void traceListHashSetValue(VisitorDispatcher visitor, Value& value) | 202 static void traceListHashSetValue(VisitorDispatcher visitor, Value& value) |
| 203 { | 203 { |
| 204 // We use the default hash traits for the value in the node, because | 204 // We use the default hash traits for the value in the node, because |
| 205 // ListHashSet does not let you specify any specific ones. | 205 // ListHashSet does not let you specify any specific ones. |
| 206 // We don't allow ListHashSet of WeakMember, so we set that one false | 206 // We don't allow ListHashSet of WeakMember, so we set that one false |
| 207 // (there's an assert elsewhere), but we have to specify some value for the | 207 // (there's an assert elsewhere), but we have to specify some value for the |
| 208 // strongify template argument, so we specify WTF::WeakPointersActWeak, | 208 // strongify template argument, so we specify WTF::WeakPointersActWeak, |
| 209 // arbitrarily. | 209 // arbitrarily. |
| 210 TraceCollectionIfEnabled<WTF::NeedsTracingTrait<WTF::HashTraits<Value>>::val
ue, WTF::NoWeakHandlingInCollections, WTF::WeakPointersActWeak, Value, WTF::Hash
Traits<Value>>::trace(visitor, value); | 210 TraceCollectionIfEnabled<WTF::IsTraceableInCollectionTrait<WTF::HashTraits<V
alue>>::value, WTF::NoWeakHandlingInCollections, WTF::WeakPointersActWeak, Value
, WTF::HashTraits<Value>>::trace(visitor, value); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // The inline capacity is just a dummy template argument to match the off-heap | 213 // The inline capacity is just a dummy template argument to match the off-heap |
| 214 // allocator. | 214 // allocator. |
| 215 // This inherits from the static-only HeapAllocator trait class, but we do | 215 // This inherits from the static-only HeapAllocator trait class, but we do |
| 216 // declare pointers to instances. These pointers are always null, and no | 216 // declare pointers to instances. These pointers are always null, and no |
| 217 // objects are instantiated. | 217 // objects are instantiated. |
| 218 template<typename ValueArg, size_t inlineCapacity> | 218 template<typename ValueArg, size_t inlineCapacity> |
| 219 class HeapListHashSetAllocator : public HeapAllocator { | 219 class HeapListHashSetAllocator : public HeapAllocator { |
| 220 DISALLOW_NEW(); | 220 DISALLOW_NEW(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 307 } |
| 308 | 308 |
| 309 template< | 309 template< |
| 310 typename KeyArg, | 310 typename KeyArg, |
| 311 typename MappedArg, | 311 typename MappedArg, |
| 312 typename HashArg = typename DefaultHash<KeyArg>::Hash, | 312 typename HashArg = typename DefaultHash<KeyArg>::Hash, |
| 313 typename KeyTraitsArg = HashTraits<KeyArg>, | 313 typename KeyTraitsArg = HashTraits<KeyArg>, |
| 314 typename MappedTraitsArg = HashTraits<MappedArg>> | 314 typename MappedTraitsArg = HashTraits<MappedArg>> |
| 315 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map
pedTraitsArg, HeapAllocator> { | 315 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map
pedTraitsArg, HeapAllocator> { |
| 316 IS_GARBAGE_COLLECTED_TYPE(); | 316 IS_GARBAGE_COLLECTED_TYPE(); |
| 317 static_assert(WTF::IsWeak<KeyArg>::value || WTF::IsWeak<MappedArg>::value ||
WTF::NeedsTracing<KeyArg>::value || WTF::NeedsTracing<MappedArg>::value, "For h
ash maps without traceable elements, use HashMap<> instead of HeapHashMap<>"); | 317 static_assert(WTF::IsTraceable<KeyArg>::value || WTF::IsTraceable<MappedArg>
::value, "For hash maps without traceable elements, use HashMap<> instead of Hea
pHashMap<>"); |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 template< | 320 template< |
| 321 typename ValueArg, | 321 typename ValueArg, |
| 322 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 322 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
| 323 typename TraitsArg = HashTraits<ValueArg>> | 323 typename TraitsArg = HashTraits<ValueArg>> |
| 324 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>
{ | 324 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>
{ |
| 325 IS_GARBAGE_COLLECTED_TYPE(); | 325 IS_GARBAGE_COLLECTED_TYPE(); |
| 326 static_assert(WTF::IsWeak<ValueArg>::value || WTF::NeedsTracing<ValueArg>::v
alue, "For hash sets without traceable elements, use HashSet<> instead of HeapHa
shSet<>"); | 326 static_assert(WTF::IsTraceable<ValueArg>::value, "For hash sets without trac
eable elements, use HashSet<> instead of HeapHashSet<>"); |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 template< | 329 template< |
| 330 typename ValueArg, | 330 typename ValueArg, |
| 331 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 331 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
| 332 typename TraitsArg = HashTraits<ValueArg>> | 332 typename TraitsArg = HashTraits<ValueArg>> |
| 333 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea
pAllocator> { | 333 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea
pAllocator> { |
| 334 IS_GARBAGE_COLLECTED_TYPE(); | 334 IS_GARBAGE_COLLECTED_TYPE(); |
| 335 static_assert(WTF::IsWeak<ValueArg>::value || WTF::NeedsTracing<ValueArg>::v
alue, "For sets without traceable elements, use LinkedHashSet<> instead of HeapL
inkedHashSet<>"); | 335 static_assert(WTF::IsTraceable<ValueArg>::value, "For sets without traceable
elements, use LinkedHashSet<> instead of HeapLinkedHashSet<>"); |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 template< | 338 template< |
| 339 typename ValueArg, | 339 typename ValueArg, |
| 340 size_t inlineCapacity = 0, // The inlineCapacity is just a dummy to match Li
stHashSet (off-heap). | 340 size_t inlineCapacity = 0, // The inlineCapacity is just a dummy to match Li
stHashSet (off-heap). |
| 341 typename HashArg = typename DefaultHash<ValueArg>::Hash> | 341 typename HashArg = typename DefaultHash<ValueArg>::Hash> |
| 342 class HeapListHashSet : public ListHashSet<ValueArg, inlineCapacity, HashArg, He
apListHashSetAllocator<ValueArg, inlineCapacity>> { | 342 class HeapListHashSet : public ListHashSet<ValueArg, inlineCapacity, HashArg, He
apListHashSetAllocator<ValueArg, inlineCapacity>> { |
| 343 IS_GARBAGE_COLLECTED_TYPE(); | 343 IS_GARBAGE_COLLECTED_TYPE(); |
| 344 static_assert(WTF::IsWeak<ValueArg>::value || WTF::NeedsTracing<ValueArg>::v
alue, "For sets without traceable elements, use ListHashSet<> instead of HeapLis
tHashSet<>"); | 344 static_assert(WTF::IsTraceable<ValueArg>::value, "For sets without traceable
elements, use ListHashSet<> instead of HeapListHashSet<>"); |
| 345 }; | 345 }; |
| 346 | 346 |
| 347 template< | 347 template< |
| 348 typename Value, | 348 typename Value, |
| 349 typename HashFunctions = typename DefaultHash<Value>::Hash, | 349 typename HashFunctions = typename DefaultHash<Value>::Hash, |
| 350 typename Traits = HashTraits<Value>> | 350 typename Traits = HashTraits<Value>> |
| 351 class HeapHashCountedSet : public HashCountedSet<Value, HashFunctions, Traits, H
eapAllocator> { | 351 class HeapHashCountedSet : public HashCountedSet<Value, HashFunctions, Traits, H
eapAllocator> { |
| 352 IS_GARBAGE_COLLECTED_TYPE(); | 352 IS_GARBAGE_COLLECTED_TYPE(); |
| 353 static_assert(WTF::IsWeak<Value>::value || WTF::NeedsTracing<Value>::value,
"For counted sets without traceable elements, use HashCountedSet<> instead of He
apHashCountedSet<>"); | 353 static_assert(WTF::IsTraceable<Value>::value, "For counted sets without trac
eable elements, use HashCountedSet<> instead of HeapHashCountedSet<>"); |
| 354 }; | 354 }; |
| 355 | 355 |
| 356 template<typename T, size_t inlineCapacity = 0> | 356 template<typename T, size_t inlineCapacity = 0> |
| 357 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { | 357 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { |
| 358 IS_GARBAGE_COLLECTED_TYPE(); | 358 IS_GARBAGE_COLLECTED_TYPE(); |
| 359 public: | 359 public: |
| 360 HeapVector() | 360 HeapVector() |
| 361 { | 361 { |
| 362 static_assert(WTF::NeedsTracing<T>::value, "For vectors without traceabl
e elements, use Vector<> instead of HeapVector<>"); | 362 static_assert(WTF::IsTraceable<T>::value, "For vectors without traceable
elements, use Vector<> instead of HeapVector<>"); |
| 363 } | 363 } |
| 364 | 364 |
| 365 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>(
size) | 365 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>(
size) |
| 366 { | 366 { |
| 367 } | 367 } |
| 368 | 368 |
| 369 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca
tor>(size, val) | 369 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca
tor>(size, val) |
| 370 { | 370 { |
| 371 } | 371 } |
| 372 | 372 |
| 373 template<size_t otherCapacity> | 373 template<size_t otherCapacity> |
| 374 HeapVector(const HeapVector<T, otherCapacity>& other) | 374 HeapVector(const HeapVector<T, otherCapacity>& other) |
| 375 : Vector<T, inlineCapacity, HeapAllocator>(other) | 375 : Vector<T, inlineCapacity, HeapAllocator>(other) |
| 376 { | 376 { |
| 377 } | 377 } |
| 378 }; | 378 }; |
| 379 | 379 |
| 380 template<typename T, size_t inlineCapacity = 0> | 380 template<typename T, size_t inlineCapacity = 0> |
| 381 class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { | 381 class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { |
| 382 IS_GARBAGE_COLLECTED_TYPE(); | 382 IS_GARBAGE_COLLECTED_TYPE(); |
| 383 public: | 383 public: |
| 384 HeapDeque() | 384 HeapDeque() |
| 385 { | 385 { |
| 386 static_assert(WTF::NeedsTracing<T>::value, "For vectors without traceabl
e elements, use Deque<> instead of HeapDeque<>"); | 386 static_assert(WTF::IsTraceable<T>::value, "For vectors without traceable
elements, use Deque<> instead of HeapDeque<>"); |
| 387 } | 387 } |
| 388 | 388 |
| 389 explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(si
ze) | 389 explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(si
ze) |
| 390 { | 390 { |
| 391 } | 391 } |
| 392 | 392 |
| 393 HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocato
r>(size, val) | 393 HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocato
r>(size, val) |
| 394 { | 394 { |
| 395 } | 395 } |
| 396 | 396 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return *x; } | 554 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return *x; } |
| 555 using PeekOutType = T*; | 555 using PeekOutType = T*; |
| 556 | 556 |
| 557 template<typename U> | 557 template<typename U> |
| 558 static void store(const U& value, blink::UntracedMember<T>& storage) { stora
ge = value; } | 558 static void store(const U& value, blink::UntracedMember<T>& storage) { stora
ge = value; } |
| 559 | 559 |
| 560 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu
e; } | 560 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu
e; } |
| 561 }; | 561 }; |
| 562 | 562 |
| 563 template<typename T, size_t inlineCapacity> | 563 template<typename T, size_t inlineCapacity> |
| 564 struct NeedsTracing<ListHashSetNode<T, blink::HeapListHashSetAllocator<T, inline
Capacity>> *> { | 564 struct IsTraceable<ListHashSetNode<T, blink::HeapListHashSetAllocator<T, inlineC
apacity>> *> { |
| 565 STATIC_ONLY(NeedsTracing); | 565 STATIC_ONLY(IsTraceable); |
| 566 static_assert(sizeof(T), "T must be fully defined"); | 566 static_assert(sizeof(T), "T must be fully defined"); |
| 567 // All heap allocated node pointers need visiting to keep the nodes alive, | 567 // All heap allocated node pointers need visiting to keep the nodes alive, |
| 568 // regardless of whether they contain pointers to other heap allocated | 568 // regardless of whether they contain pointers to other heap allocated |
| 569 // objects. | 569 // objects. |
| 570 static const bool value = true; | 570 static const bool value = true; |
| 571 }; | 571 }; |
| 572 | 572 |
| 573 template<typename T, size_t inlineCapacity> | 573 template<typename T, size_t inlineCapacity> |
| 574 struct IsGarbageCollectedType<ListHashSetNode<T, blink::HeapListHashSetAllocator
<T, inlineCapacity>>> { | 574 struct IsGarbageCollectedType<ListHashSetNode<T, blink::HeapListHashSetAllocator
<T, inlineCapacity>>> { |
| 575 static const bool value = true; | 575 static const bool value = true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 599 static PeekOutType peek(const H& value) { return value; } | 599 static PeekOutType peek(const H& value) { return value; } |
| 600 }; | 600 }; |
| 601 | 601 |
| 602 template<typename T> struct HashTraits<blink::Persistent<T>> : HandleHashTraits<
T, blink::Persistent<T>> { }; | 602 template<typename T> struct HashTraits<blink::Persistent<T>> : HandleHashTraits<
T, blink::Persistent<T>> { }; |
| 603 | 603 |
| 604 template<typename T> struct HashTraits<blink::CrossThreadPersistent<T>> : Handle
HashTraits<T, blink::CrossThreadPersistent<T>> { }; | 604 template<typename T> struct HashTraits<blink::CrossThreadPersistent<T>> : Handle
HashTraits<T, blink::CrossThreadPersistent<T>> { }; |
| 605 | 605 |
| 606 } // namespace WTF | 606 } // namespace WTF |
| 607 | 607 |
| 608 #endif | 608 #endif |
| OLD | NEW |