Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapAllocator.h

Issue 2007283002: Allow CrossThreadPersistent in collections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/TraceTraits.h" 10 #include "platform/heap/TraceTraits.h"
10 #include "wtf/Allocator.h" 11 #include "wtf/Allocator.h"
11 #include "wtf/Assertions.h" 12 #include "wtf/Assertions.h"
12 #include "wtf/Deque.h" 13 #include "wtf/Deque.h"
13 #include "wtf/HashCountedSet.h" 14 #include "wtf/HashCountedSet.h"
14 #include "wtf/HashMap.h" 15 #include "wtf/HashMap.h"
15 #include "wtf/HashSet.h" 16 #include "wtf/HashSet.h"
16 #include "wtf/HashTable.h" 17 #include "wtf/HashTable.h"
17 #include "wtf/LinkedHashSet.h" 18 #include "wtf/LinkedHashSet.h"
18 #include "wtf/ListHashSet.h" 19 #include "wtf/ListHashSet.h"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 }; 416 };
416 417
417 template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTrai tsBase<blink::UntracedMember<T>> { 418 template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTrai tsBase<blink::UntracedMember<T>> {
418 STATIC_ONLY(VectorTraits); 419 STATIC_ONLY(VectorTraits);
419 static const bool needsDestruction = false; 420 static const bool needsDestruction = false;
420 static const bool canInitializeWithMemset = true; 421 static const bool canInitializeWithMemset = true;
421 static const bool canClearUnusedSlotsWithMemset = true; 422 static const bool canClearUnusedSlotsWithMemset = true;
422 static const bool canMoveWithMemcpy = true; 423 static const bool canMoveWithMemcpy = true;
423 }; 424 };
424 425
426 template <typename T, blink::WeaknessPersistentConfiguration weaknessConfigurati on, blink::CrossThreadnessPersistentConfiguration crossThreadnessConfiguration>
427 struct VectorTraits<blink::PersistentBase<T, weaknessConfiguration, crossThreadn essConfiguration>>
428 : VectorTraitsBase<blink::PersistentBase<T, weaknessConfiguration, crossThre adnessConfiguration>> {
429 STATIC_ONLY(VectorTraits);
430 static const bool needsDestruction = true;
431 static const bool canInitializeWithMemset = true;
432 static const bool canClearUnusedSlotsWithMemset = false;
433 static const bool canMoveWithMemcpy = true;
434 };
435
425 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> { 436 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> {
426 STATIC_ONLY(VectorTraits); 437 STATIC_ONLY(VectorTraits);
427 static const bool needsDestruction = false; 438 static const bool needsDestruction = false;
428 static const bool canInitializeWithMemset = true; 439 static const bool canInitializeWithMemset = true;
429 static const bool canClearUnusedSlotsWithMemset = true; 440 static const bool canClearUnusedSlotsWithMemset = true;
430 static const bool canMoveWithMemcpy = true; 441 static const bool canMoveWithMemcpy = true;
431 }; 442 };
432 443
433 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> { 444 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> {
434 STATIC_ONLY(VectorTraits); 445 STATIC_ONLY(VectorTraits);
(...skipping 12 matching lines...) Expand all
447 }; 458 };
448 459
449 template <typename T, size_t inlineCapacity> struct VectorTraits<blink::HeapDequ e<T, inlineCapacity>> : VectorTraitsBase<blink::HeapDeque<T, inlineCapacity>> { 460 template <typename T, size_t inlineCapacity> struct VectorTraits<blink::HeapDequ e<T, inlineCapacity>> : VectorTraitsBase<blink::HeapDeque<T, inlineCapacity>> {
450 STATIC_ONLY(VectorTraits); 461 STATIC_ONLY(VectorTraits);
451 static const bool needsDestruction = VectorTraits<T>::needsDestruction; 462 static const bool needsDestruction = VectorTraits<T>::needsDestruction;
452 static const bool canInitializeWithMemset = VectorTraits<T>::canInitializeWi thMemset; 463 static const bool canInitializeWithMemset = VectorTraits<T>::canInitializeWi thMemset;
453 static const bool canClearUnusedSlotsWithMemset = VectorTraits<T>::canClearU nusedSlotsWithMemset; 464 static const bool canClearUnusedSlotsWithMemset = VectorTraits<T>::canClearU nusedSlotsWithMemset;
454 static const bool canMoveWithMemcpy = VectorTraits<T>::canMoveWithMemcpy; 465 static const bool canMoveWithMemcpy = VectorTraits<T>::canMoveWithMemcpy;
455 }; 466 };
456 467
457 template<typename T> struct HashTraits<blink::Member<T>> : SimpleClassHashTraits <blink::Member<T>> { 468 template<typename T, typename H> struct HandleHashTraits : SimpleClassHashTraits <H> {
458 STATIC_ONLY(HashTraits); 469 STATIC_ONLY(HandleHashTraits);
459 // FIXME: The distinction between PeekInType and PassInType is there for 470 // TODO: The distinction between PeekInType and PassInType is there for
460 // the sake of the reference counting handles. When they are gone the two 471 // the sake of the reference counting handles. When they are gone the two
461 // types can be merged into PassInType. 472 // types can be merged into PassInType.
462 // FIXME: Implement proper const'ness for iterator types. Requires support 473 // TODO: Implement proper const'ness for iterator types. Requires support
463 // in the marking Visitor. 474 // in the marking Visitor.
464 using PeekInType = T*; 475 using PeekInType = T*;
465 using PassInType = T*; 476 using PassInType = T*;
466 using IteratorGetType = blink::Member<T>*; 477 using IteratorGetType = H*;
467 using IteratorConstGetType = const blink::Member<T>*; 478 using IteratorConstGetType = const H*;
468 using IteratorReferenceType = blink::Member<T>&; 479 using IteratorReferenceType = H&;
469 using IteratorConstReferenceType = const blink::Member<T>&; 480 using IteratorConstReferenceType = const H&;
470 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; } 481 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
471 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; } 482 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; }
472 483
473 using PeekOutType = T*; 484 using PeekOutType = T*;
474 485
475 template<typename U> 486 template<typename U>
476 static void store(const U& value, blink::Member<T>& storage) { storage = val ue; } 487 static void store(const U& value, H& storage) { storage = value; }
477 488
478 static PeekOutType peek(const blink::Member<T>& value) { return value; } 489 static PeekOutType peek(const H& value) { return value; }
479 }; 490 };
480 491
481 template<typename T> struct HashTraits<blink::WeakMember<T>> : SimpleClassHashTr aits<blink::WeakMember<T>> { 492 template<typename T> struct HashTraits<blink::Member<T>> : HandleHashTraits<T, b link::Member<T>> { };
493
494 template<typename T> struct HashTraits<blink::WeakMember<T>> : HandleHashTraits< T, blink::WeakMember<T>> {
482 STATIC_ONLY(HashTraits); 495 STATIC_ONLY(HashTraits);
483 static const bool needsDestruction = false; 496 static const bool needsDestruction = false;
484 // FIXME: The distinction between PeekInType and PassInType is there for
485 // the sake of the reference counting handles. When they are gone the two
486 // types can be merged into PassInType.
487 // FIXME: Implement proper const'ness for iterator types. Requires support
488 // in the marking Visitor.
489 using PeekInType = T*;
490 using PassInType = T*;
491 using IteratorGetType = blink::WeakMember<T>*;
492 using IteratorConstGetType = const blink::WeakMember<T>*;
493 using IteratorReferenceType = blink::WeakMember<T>&;
494 using IteratorConstReferenceType = const blink::WeakMember<T>&;
495 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
496 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; }
497
498 using PeekOutType = T*;
499
500 template<typename U>
501 static void store(const U& value, blink::WeakMember<T>& storage) { storage = value; }
502
503 static PeekOutType peek(const blink::WeakMember<T>& value) { return value; }
504 497
505 template<typename VisitorDispatcher> 498 template<typename VisitorDispatcher>
506 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) 499 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify)
507 { 500 {
508 if (strongify == WeakPointersActStrong) { 501 if (strongify == WeakPointersActStrong) {
509 visitor->trace(weakMember.get()); // Strongified visit. 502 visitor->trace(weakMember.get()); // Strongified visit.
510 return false; 503 return false;
511 } 504 }
512 return !blink::ThreadHeap::isHeapObjectAlive(weakMember); 505 return !blink::ThreadHeap::isHeapObjectAlive(weakMember);
513 } 506 }
514 }; 507 };
515 508
516 template<typename T> struct HashTraits<blink::UntracedMember<T>> : SimpleClassHa shTraits<blink::UntracedMember<T>> { 509 template<typename T> struct HashTraits<blink::UntracedMember<T>> : HandleHashTra its<T, blink::UntracedMember<T>> {
517 STATIC_ONLY(HashTraits); 510 STATIC_ONLY(HashTraits);
518 static const bool needsDestruction = false; 511 static const bool needsDestruction = false;
519 // FIXME: The distinction between PeekInType and PassInType is there for
520 // the sake of the reference counting handles. When they are gone the two
521 // types can be merged into PassInType.
522 // FIXME: Implement proper const'ness for iterator types.
523 using PeekInType = T*;
524 using PassInType = T*;
525 using IteratorGetType = blink::UntracedMember<T>*;
526 using IteratorConstGetType = const blink::UntracedMember<T>*;
527 using IteratorReferenceType = blink::UntracedMember<T>&;
528 using IteratorConstReferenceType = const blink::UntracedMember<T>&;
529 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
530 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; }
531 using PeekOutType = T*;
532
533 template<typename U>
534 static void store(const U& value, blink::UntracedMember<T>& storage) { stora ge = value; }
535
536 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu e; }
537 }; 512 };
538 513
539 template<typename T, size_t inlineCapacity> 514 template<typename T, size_t inlineCapacity>
540 struct NeedsTracing<ListHashSetNode<T, blink::HeapListHashSetAllocator<T, inline Capacity>> *> { 515 struct NeedsTracing<ListHashSetNode<T, blink::HeapListHashSetAllocator<T, inline Capacity>> *> {
541 STATIC_ONLY(NeedsTracing); 516 STATIC_ONLY(NeedsTracing);
542 static_assert(sizeof(T), "T must be fully defined"); 517 static_assert(sizeof(T), "T must be fully defined");
543 // All heap allocated node pointers need visiting to keep the nodes alive, 518 // All heap allocated node pointers need visiting to keep the nodes alive,
544 // regardless of whether they contain pointers to other heap allocated 519 // regardless of whether they contain pointers to other heap allocated
545 // objects. 520 // objects.
546 static const bool value = true; 521 static const bool value = true;
547 }; 522 };
548 523
549 template<typename T, size_t inlineCapacity> 524 template<typename T, size_t inlineCapacity>
550 struct IsGarbageCollectedType<ListHashSetNode<T, blink::HeapListHashSetAllocator <T, inlineCapacity>>> { 525 struct IsGarbageCollectedType<ListHashSetNode<T, blink::HeapListHashSetAllocator <T, inlineCapacity>>> {
551 static const bool value = true; 526 static const bool value = true;
552 }; 527 };
553 528
529 template<typename T> struct HashTraits<blink::Persistent<T>> : HandleHashTraits< T, blink::Persistent<T>> { };
530
531 template<typename T> struct HashTraits<blink::CrossThreadPersistent<T>> : Handle HashTraits<T, blink::CrossThreadPersistent<T>> { };
532
554 } // namespace WTF 533 } // namespace WTF
555 534
556 #endif 535 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698