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/Assertions.h" | 10 #include "wtf/Assertions.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 template<size_t otherCapacity> | 387 template<size_t otherCapacity> |
388 HeapDeque(const HeapDeque<T, otherCapacity>& other) | 388 HeapDeque(const HeapDeque<T, otherCapacity>& other) |
389 : Deque<T, inlineCapacity, HeapAllocator>(other) | 389 : Deque<T, inlineCapacity, HeapAllocator>(other) |
390 { | 390 { |
391 } | 391 } |
392 }; | 392 }; |
393 | 393 |
394 } // namespace blink | 394 } // namespace blink |
395 | 395 |
| 396 namespace WTF { |
| 397 |
| 398 template <typename T> struct VectorTraits<blink::Member<T>> : VectorTraitsBase<b
link::Member<T>> { |
| 399 static const bool needsDestruction = false; |
| 400 static const bool canInitializeWithMemset = true; |
| 401 static const bool canClearUnusedSlotsWithMemset = true; |
| 402 static const bool canMoveWithMemcpy = true; |
| 403 }; |
| 404 |
| 405 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa
se<blink::WeakMember<T>> { |
| 406 static const bool needsDestruction = false; |
| 407 static const bool canInitializeWithMemset = true; |
| 408 static const bool canClearUnusedSlotsWithMemset = true; |
| 409 static const bool canMoveWithMemcpy = true; |
| 410 }; |
| 411 |
| 412 template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTrai
tsBase<blink::UntracedMember<T>> { |
| 413 static const bool needsDestruction = false; |
| 414 static const bool canInitializeWithMemset = true; |
| 415 static const bool canClearUnusedSlotsWithMemset = true; |
| 416 static const bool canMoveWithMemcpy = true; |
| 417 }; |
| 418 |
| 419 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait
sBase<blink::HeapVector<T, 0>> { |
| 420 static const bool needsDestruction = false; |
| 421 static const bool canInitializeWithMemset = true; |
| 422 static const bool canClearUnusedSlotsWithMemset = true; |
| 423 static const bool canMoveWithMemcpy = true; |
| 424 }; |
| 425 |
| 426 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits
Base<blink::HeapDeque<T, 0>> { |
| 427 static const bool needsDestruction = false; |
| 428 static const bool canInitializeWithMemset = true; |
| 429 static const bool canClearUnusedSlotsWithMemset = true; |
| 430 static const bool canMoveWithMemcpy = true; |
| 431 }; |
| 432 |
| 433 template <typename T, size_t inlineCapacity> struct VectorTraits<blink::HeapVect
or<T, inlineCapacity>> : VectorTraitsBase<blink::HeapVector<T, inlineCapacity>>
{ |
| 434 static const bool needsDestruction = VectorTraits<T>::needsDestruction; |
| 435 static const bool canInitializeWithMemset = VectorTraits<T>::canInitializeWi
thMemset; |
| 436 static const bool canClearUnusedSlotsWithMemset = VectorTraits<T>::canClearU
nusedSlotsWithMemset; |
| 437 static const bool canMoveWithMemcpy = VectorTraits<T>::canMoveWithMemcpy; |
| 438 }; |
| 439 |
| 440 template <typename T, size_t inlineCapacity> struct VectorTraits<blink::HeapDequ
e<T, inlineCapacity>> : VectorTraitsBase<blink::HeapDeque<T, inlineCapacity>> { |
| 441 static const bool needsDestruction = VectorTraits<T>::needsDestruction; |
| 442 static const bool canInitializeWithMemset = VectorTraits<T>::canInitializeWi
thMemset; |
| 443 static const bool canClearUnusedSlotsWithMemset = VectorTraits<T>::canClearU
nusedSlotsWithMemset; |
| 444 static const bool canMoveWithMemcpy = VectorTraits<T>::canMoveWithMemcpy; |
| 445 }; |
| 446 |
| 447 template<typename T> struct HashTraits<blink::Member<T>> : SimpleClassHashTraits
<blink::Member<T>> { |
| 448 // FIXME: The distinction between PeekInType and PassInType is there for |
| 449 // the sake of the reference counting handles. When they are gone the two |
| 450 // types can be merged into PassInType. |
| 451 // FIXME: Implement proper const'ness for iterator types. Requires support |
| 452 // in the marking Visitor. |
| 453 using PeekInType = RawPtr<T>; |
| 454 using PassInType = RawPtr<T>; |
| 455 using IteratorGetType = blink::Member<T>*; |
| 456 using IteratorConstGetType = const blink::Member<T>*; |
| 457 using IteratorReferenceType = blink::Member<T>&; |
| 458 using IteratorConstReferenceType = const blink::Member<T>&; |
| 459 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn *x; } |
| 460 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return *x; } |
| 461 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
| 462 // and PassOutType without reference counting. |
| 463 using PeekOutType = T*; |
| 464 using PassOutType = T*; |
| 465 |
| 466 template<typename U> |
| 467 static void store(const U& value, blink::Member<T>& storage) { storage = val
ue; } |
| 468 |
| 469 static PeekOutType peek(const blink::Member<T>& value) { return value; } |
| 470 static PassOutType passOut(const blink::Member<T>& value) { return value; } |
| 471 }; |
| 472 |
| 473 template<typename T> struct HashTraits<blink::WeakMember<T>> : SimpleClassHashTr
aits<blink::WeakMember<T>> { |
| 474 static const bool needsDestruction = false; |
| 475 // FIXME: The distinction between PeekInType and PassInType is there for |
| 476 // the sake of the reference counting handles. When they are gone the two |
| 477 // types can be merged into PassInType. |
| 478 // FIXME: Implement proper const'ness for iterator types. Requires support |
| 479 // in the marking Visitor. |
| 480 using PeekInType = RawPtr<T>; |
| 481 using PassInType = RawPtr<T>; |
| 482 using IteratorGetType = blink::WeakMember<T>*; |
| 483 using IteratorConstGetType = const blink::WeakMember<T>*; |
| 484 using IteratorReferenceType = blink::WeakMember<T>&; |
| 485 using IteratorConstReferenceType = const blink::WeakMember<T>&; |
| 486 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn *x; } |
| 487 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return *x; } |
| 488 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
| 489 // and PassOutType without reference counting. |
| 490 using PeekOutType = T*; |
| 491 using PassOutType = T*; |
| 492 |
| 493 template<typename U> |
| 494 static void store(const U& value, blink::WeakMember<T>& storage) { storage =
value; } |
| 495 |
| 496 static PeekOutType peek(const blink::WeakMember<T>& value) { return value; } |
| 497 static PassOutType passOut(const blink::WeakMember<T>& value) { return value
; } |
| 498 |
| 499 template<typename VisitorDispatcher> |
| 500 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T
>& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) |
| 501 { |
| 502 if (strongify == WeakPointersActStrong) { |
| 503 visitor->trace(weakMember.get()); // Strongified visit. |
| 504 return false; |
| 505 } |
| 506 return !blink::Heap::isHeapObjectAlive(weakMember); |
| 507 } |
| 508 }; |
| 509 |
| 510 template<typename T> struct HashTraits<blink::UntracedMember<T>> : SimpleClassHa
shTraits<blink::UntracedMember<T>> { |
| 511 static const bool needsDestruction = false; |
| 512 // FIXME: The distinction between PeekInType and PassInType is there for |
| 513 // the sake of the reference counting handles. When they are gone the two |
| 514 // types can be merged into PassInType. |
| 515 // FIXME: Implement proper const'ness for iterator types. |
| 516 using PeekInType = RawPtr<T>; |
| 517 using PassInType = RawPtr<T>; |
| 518 using IteratorGetType = blink::UntracedMember<T>*; |
| 519 using IteratorConstGetType = const blink::UntracedMember<T>*; |
| 520 using IteratorReferenceType = blink::UntracedMember<T>&; |
| 521 using IteratorConstReferenceType = const blink::UntracedMember<T>&; |
| 522 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn *x; } |
| 523 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return *x; } |
| 524 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
| 525 // and PassOutType without reference counting. |
| 526 using PeekOutType = T*; |
| 527 using PassOutType = T*; |
| 528 |
| 529 template<typename U> |
| 530 static void store(const U& value, blink::UntracedMember<T>& storage) { stora
ge = value; } |
| 531 |
| 532 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu
e; } |
| 533 static PassOutType passOut(const blink::UntracedMember<T>& value) { return v
alue; } |
| 534 }; |
| 535 |
| 536 template<typename T, size_t inlineCapacity> |
| 537 struct NeedsTracing<ListHashSetNode<T, blink::HeapListHashSetAllocator<T, inline
Capacity>> *> { |
| 538 static_assert(sizeof(T), "T must be fully defined"); |
| 539 // All heap allocated node pointers need visiting to keep the nodes alive, |
| 540 // regardless of whether they contain pointers to other heap allocated |
| 541 // objects. |
| 542 static const bool value = true; |
| 543 }; |
| 544 |
| 545 } // namespace WTF |
| 546 |
396 #endif | 547 #endif |
OLD | NEW |