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/TraceTraits.h" | 9 #include "platform/heap/TraceTraits.h" |
10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 template< | 311 template< |
312 typename KeyArg, | 312 typename KeyArg, |
313 typename MappedArg, | 313 typename MappedArg, |
314 typename HashArg = typename DefaultHash<KeyArg>::Hash, | 314 typename HashArg = typename DefaultHash<KeyArg>::Hash, |
315 typename KeyTraitsArg = HashTraits<KeyArg>, | 315 typename KeyTraitsArg = HashTraits<KeyArg>, |
316 typename MappedTraitsArg = HashTraits<MappedArg>> | 316 typename MappedTraitsArg = HashTraits<MappedArg>> |
317 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map
pedTraitsArg, HeapAllocator> { | 317 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map
pedTraitsArg, HeapAllocator> { |
318 IS_GARBAGE_COLLECTED_TYPE(); | 318 IS_GARBAGE_COLLECTED_TYPE(); |
| 319 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<>"); |
319 }; | 320 }; |
320 | 321 |
321 template< | 322 template< |
322 typename ValueArg, | 323 typename ValueArg, |
323 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 324 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
324 typename TraitsArg = HashTraits<ValueArg>> | 325 typename TraitsArg = HashTraits<ValueArg>> |
325 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>
{ | 326 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>
{ |
326 IS_GARBAGE_COLLECTED_TYPE(); | 327 IS_GARBAGE_COLLECTED_TYPE(); |
| 328 static_assert(WTF::IsWeak<ValueArg>::value || WTF::NeedsTracing<ValueArg>::v
alue, "For hash sets without traceable elements, use HashSet<> instead of HeapHa
shSet<>"); |
327 }; | 329 }; |
328 | 330 |
329 template< | 331 template< |
330 typename ValueArg, | 332 typename ValueArg, |
331 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 333 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
332 typename TraitsArg = HashTraits<ValueArg>> | 334 typename TraitsArg = HashTraits<ValueArg>> |
333 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea
pAllocator> { | 335 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea
pAllocator> { |
334 IS_GARBAGE_COLLECTED_TYPE(); | 336 IS_GARBAGE_COLLECTED_TYPE(); |
| 337 static_assert(WTF::IsWeak<ValueArg>::value || WTF::NeedsTracing<ValueArg>::v
alue, "For sets without traceable elements, use LinkedHashSet<> instead of HeapL
inkedHashSet<>"); |
335 }; | 338 }; |
336 | 339 |
337 template< | 340 template< |
338 typename ValueArg, | 341 typename ValueArg, |
339 size_t inlineCapacity = 0, // The inlineCapacity is just a dummy to match Li
stHashSet (off-heap). | 342 size_t inlineCapacity = 0, // The inlineCapacity is just a dummy to match Li
stHashSet (off-heap). |
340 typename HashArg = typename DefaultHash<ValueArg>::Hash> | 343 typename HashArg = typename DefaultHash<ValueArg>::Hash> |
341 class HeapListHashSet : public ListHashSet<ValueArg, inlineCapacity, HashArg, He
apListHashSetAllocator<ValueArg, inlineCapacity>> { | 344 class HeapListHashSet : public ListHashSet<ValueArg, inlineCapacity, HashArg, He
apListHashSetAllocator<ValueArg, inlineCapacity>> { |
342 IS_GARBAGE_COLLECTED_TYPE(); | 345 IS_GARBAGE_COLLECTED_TYPE(); |
| 346 static_assert(WTF::IsWeak<ValueArg>::value || WTF::NeedsTracing<ValueArg>::v
alue, "For sets without traceable elements, use ListHashSet<> instead of HeapLis
tHashSet<>"); |
343 }; | 347 }; |
344 | 348 |
345 template< | 349 template< |
346 typename Value, | 350 typename Value, |
347 typename HashFunctions = typename DefaultHash<Value>::Hash, | 351 typename HashFunctions = typename DefaultHash<Value>::Hash, |
348 typename Traits = HashTraits<Value>> | 352 typename Traits = HashTraits<Value>> |
349 class HeapHashCountedSet : public HashCountedSet<Value, HashFunctions, Traits, H
eapAllocator> { | 353 class HeapHashCountedSet : public HashCountedSet<Value, HashFunctions, Traits, H
eapAllocator> { |
350 IS_GARBAGE_COLLECTED_TYPE(); | 354 IS_GARBAGE_COLLECTED_TYPE(); |
| 355 static_assert(WTF::IsWeak<Value>::value || WTF::NeedsTracing<Value>::value,
"For counted sets without traceable elements, use HashCountedSet<> instead of He
apHashCountedSet<>"); |
351 }; | 356 }; |
352 | 357 |
353 template<typename T, size_t inlineCapacity = 0> | 358 template<typename T, size_t inlineCapacity = 0> |
354 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { | 359 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { |
355 IS_GARBAGE_COLLECTED_TYPE(); | 360 IS_GARBAGE_COLLECTED_TYPE(); |
356 public: | 361 public: |
357 HeapVector() { } | 362 HeapVector() |
| 363 { |
| 364 static_assert(WTF::NeedsTracing<T>::value, "For vectors without traceabl
e elements, use Vector<> instead of HeapVector<>"); |
| 365 } |
358 | 366 |
359 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>(
size) | 367 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>(
size) |
360 { | 368 { |
361 } | 369 } |
362 | 370 |
363 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca
tor>(size, val) | 371 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca
tor>(size, val) |
364 { | 372 { |
365 } | 373 } |
366 | 374 |
367 template<size_t otherCapacity> | 375 template<size_t otherCapacity> |
368 HeapVector(const HeapVector<T, otherCapacity>& other) | 376 HeapVector(const HeapVector<T, otherCapacity>& other) |
369 : Vector<T, inlineCapacity, HeapAllocator>(other) | 377 : Vector<T, inlineCapacity, HeapAllocator>(other) |
370 { | 378 { |
371 } | 379 } |
372 }; | 380 }; |
373 | 381 |
374 template<typename T, size_t inlineCapacity = 0> | 382 template<typename T, size_t inlineCapacity = 0> |
375 class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { | 383 class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { |
376 IS_GARBAGE_COLLECTED_TYPE(); | 384 IS_GARBAGE_COLLECTED_TYPE(); |
377 public: | 385 public: |
378 HeapDeque() { } | 386 HeapDeque() |
| 387 { |
| 388 static_assert(WTF::NeedsTracing<T>::value, "For vectors without traceabl
e elements, use Deque<> instead of HeapDeque<>"); |
| 389 } |
379 | 390 |
380 explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(si
ze) | 391 explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(si
ze) |
381 { | 392 { |
382 } | 393 } |
383 | 394 |
384 HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocato
r>(size, val) | 395 HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocato
r>(size, val) |
385 { | 396 { |
386 } | 397 } |
387 | 398 |
388 HeapDeque& operator=(const HeapDeque& other) | 399 HeapDeque& operator=(const HeapDeque& other) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 static_assert(sizeof(T), "T must be fully defined"); | 568 static_assert(sizeof(T), "T must be fully defined"); |
558 // All heap allocated node pointers need visiting to keep the nodes alive, | 569 // All heap allocated node pointers need visiting to keep the nodes alive, |
559 // regardless of whether they contain pointers to other heap allocated | 570 // regardless of whether they contain pointers to other heap allocated |
560 // objects. | 571 // objects. |
561 static const bool value = true; | 572 static const bool value = true; |
562 }; | 573 }; |
563 | 574 |
564 } // namespace WTF | 575 } // namespace WTF |
565 | 576 |
566 #endif | 577 #endif |
OLD | NEW |