OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // between objects that are in the managed heap. They are only | 294 // between objects that are in the managed heap. They are only |
295 // meant to point to managed heap objects from variables/members | 295 // meant to point to managed heap objects from variables/members |
296 // outside the managed heap. | 296 // outside the managed heap. |
297 // | 297 // |
298 // A Persistent is always a GC root from the point of view of | 298 // A Persistent is always a GC root from the point of view of |
299 // the garbage collector. | 299 // the garbage collector. |
300 // | 300 // |
301 // We have to construct and destruct Persistent with default RootsAccessor in | 301 // We have to construct and destruct Persistent with default RootsAccessor in |
302 // the same thread. | 302 // the same thread. |
303 template<typename T, typename RootsAccessor /* = ThreadLocalPersistents<Threadin
gTrait<T>::Affinity > */ > | 303 template<typename T, typename RootsAccessor /* = ThreadLocalPersistents<Threadin
gTrait<T>::Affinity > */ > |
304 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces
sor> > { | 304 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces
sor>> { |
305 public: | 305 public: |
306 Persistent() : m_raw(nullptr) { } | 306 Persistent() : m_raw(nullptr) { } |
307 | 307 |
308 Persistent(std::nullptr_t) : m_raw(nullptr) { } | 308 Persistent(std::nullptr_t) : m_raw(nullptr) { } |
309 | 309 |
310 Persistent(T* raw) : m_raw(raw) | 310 Persistent(T* raw) : m_raw(raw) |
311 { | 311 { |
312 ASSERT_IS_VALID_PERSISTENT_POINTER(m_raw); | 312 ASSERT_IS_VALID_PERSISTENT_POINTER(m_raw); |
313 recordBacktrace(); | 313 recordBacktrace(); |
314 } | 314 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 public: | 433 public: |
434 CrossThreadPersistent(T* raw) : Persistent<T, GlobalPersistents>(raw) { } | 434 CrossThreadPersistent(T* raw) : Persistent<T, GlobalPersistents>(raw) { } |
435 | 435 |
436 using Persistent<T, GlobalPersistents>::operator=; | 436 using Persistent<T, GlobalPersistents>::operator=; |
437 }; | 437 }; |
438 | 438 |
439 // FIXME: derive affinity based on the collection. | 439 // FIXME: derive affinity based on the collection. |
440 template<typename Collection, ThreadAffinity Affinity = AnyThread> | 440 template<typename Collection, ThreadAffinity Affinity = AnyThread> |
441 class PersistentHeapCollectionBase | 441 class PersistentHeapCollectionBase |
442 : public Collection | 442 : public Collection |
443 , public PersistentBase<ThreadLocalPersistents<Affinity>, PersistentHeapColl
ectionBase<Collection, Affinity> > { | 443 , public PersistentBase<ThreadLocalPersistents<Affinity>, PersistentHeapColl
ectionBase<Collection, Affinity>> { |
444 // We overload the various new and delete operators with using the WTF Defau
ltAllocator to ensure persistent | 444 // We overload the various new and delete operators with using the WTF Defau
ltAllocator to ensure persistent |
445 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in | 445 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in |
446 // DEFINE_STATIC_LOCAL et. al. | 446 // DEFINE_STATIC_LOCAL et. al. |
447 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator); | 447 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator); |
448 public: | 448 public: |
449 PersistentHeapCollectionBase() { } | 449 PersistentHeapCollectionBase() { } |
450 | 450 |
451 template<typename OtherCollection> | 451 template<typename OtherCollection> |
452 PersistentHeapCollectionBase(const OtherCollection& other) : Collection(othe
r) { } | 452 PersistentHeapCollectionBase(const OtherCollection& other) : Collection(othe
r) { } |
453 | 453 |
454 void trace(Visitor* visitor) | 454 void trace(Visitor* visitor) |
455 { | 455 { |
456 #if ENABLE(GC_PROFILE_MARKING) | 456 #if ENABLE(GC_PROFILE_MARKING) |
457 visitor->setHostInfo(this, "PersistentHeapCollectionBase"); | 457 visitor->setHostInfo(this, "PersistentHeapCollectionBase"); |
458 #endif | 458 #endif |
459 visitor->trace(*static_cast<Collection*>(this)); | 459 visitor->trace(*static_cast<Collection*>(this)); |
460 } | 460 } |
461 }; | 461 }; |
462 | 462 |
463 template< | 463 template< |
464 typename KeyArg, | 464 typename KeyArg, |
465 typename MappedArg, | 465 typename MappedArg, |
466 typename HashArg = typename DefaultHash<KeyArg>::Hash, | 466 typename HashArg = typename DefaultHash<KeyArg>::Hash, |
467 typename KeyTraitsArg = HashTraits<KeyArg>, | 467 typename KeyTraitsArg = HashTraits<KeyArg>, |
468 typename MappedTraitsArg = HashTraits<MappedArg> > | 468 typename MappedTraitsArg = HashTraits<MappedArg>> |
469 class PersistentHeapHashMap : public PersistentHeapCollectionBase<HeapHashMap<Ke
yArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> > { }; | 469 class PersistentHeapHashMap : public PersistentHeapCollectionBase<HeapHashMap<Ke
yArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>> { }; |
470 | 470 |
471 template< | 471 template< |
472 typename ValueArg, | 472 typename ValueArg, |
473 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 473 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
474 typename TraitsArg = HashTraits<ValueArg> > | 474 typename TraitsArg = HashTraits<ValueArg>> |
475 class PersistentHeapHashSet : public PersistentHeapCollectionBase<HeapHashSet<Va
lueArg, HashArg, TraitsArg> > { }; | 475 class PersistentHeapHashSet : public PersistentHeapCollectionBase<HeapHashSet<Va
lueArg, HashArg, TraitsArg>> { }; |
476 | 476 |
477 template< | 477 template< |
478 typename ValueArg, | 478 typename ValueArg, |
479 typename HashArg = typename DefaultHash<ValueArg>::Hash, | 479 typename HashArg = typename DefaultHash<ValueArg>::Hash, |
480 typename TraitsArg = HashTraits<ValueArg> > | 480 typename TraitsArg = HashTraits<ValueArg>> |
481 class PersistentHeapLinkedHashSet : public PersistentHeapCollectionBase<HeapLink
edHashSet<ValueArg, HashArg, TraitsArg> > { }; | 481 class PersistentHeapLinkedHashSet : public PersistentHeapCollectionBase<HeapLink
edHashSet<ValueArg, HashArg, TraitsArg>> { }; |
482 | 482 |
483 template< | 483 template< |
484 typename ValueArg, | 484 typename ValueArg, |
485 size_t inlineCapacity = 0, | 485 size_t inlineCapacity = 0, |
486 typename HashArg = typename DefaultHash<ValueArg>::Hash> | 486 typename HashArg = typename DefaultHash<ValueArg>::Hash> |
487 class PersistentHeapListHashSet : public PersistentHeapCollectionBase<HeapListHa
shSet<ValueArg, inlineCapacity, HashArg> > { }; | 487 class PersistentHeapListHashSet : public PersistentHeapCollectionBase<HeapListHa
shSet<ValueArg, inlineCapacity, HashArg>> { }; |
488 | 488 |
489 template<typename T, typename U, typename V> | 489 template<typename T, typename U, typename V> |
490 class PersistentHeapHashCountedSet : public PersistentHeapCollectionBase<HeapHas
hCountedSet<T, U, V> > { }; | 490 class PersistentHeapHashCountedSet : public PersistentHeapCollectionBase<HeapHas
hCountedSet<T, U, V>> { }; |
491 | 491 |
492 template<typename T, size_t inlineCapacity = 0> | 492 template<typename T, size_t inlineCapacity = 0> |
493 class PersistentHeapVector : public PersistentHeapCollectionBase<HeapVector<T, i
nlineCapacity> > { | 493 class PersistentHeapVector : public PersistentHeapCollectionBase<HeapVector<T, i
nlineCapacity>> { |
494 public: | 494 public: |
495 PersistentHeapVector() { } | 495 PersistentHeapVector() { } |
496 | 496 |
497 template<size_t otherCapacity> | 497 template<size_t otherCapacity> |
498 PersistentHeapVector(const HeapVector<T, otherCapacity>& other) | 498 PersistentHeapVector(const HeapVector<T, otherCapacity>& other) |
499 : PersistentHeapCollectionBase<HeapVector<T, inlineCapacity> >(other) | 499 : PersistentHeapCollectionBase<HeapVector<T, inlineCapacity>>(other) |
500 { | 500 { |
501 } | 501 } |
502 }; | 502 }; |
503 | 503 |
504 template<typename T, size_t inlineCapacity = 0> | 504 template<typename T, size_t inlineCapacity = 0> |
505 class PersistentHeapDeque : public PersistentHeapCollectionBase<HeapDeque<T, inl
ineCapacity> > { | 505 class PersistentHeapDeque : public PersistentHeapCollectionBase<HeapDeque<T, inl
ineCapacity>> { |
506 public: | 506 public: |
507 PersistentHeapDeque() { } | 507 PersistentHeapDeque() { } |
508 | 508 |
509 template<size_t otherCapacity> | 509 template<size_t otherCapacity> |
510 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other) | 510 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other) |
511 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity> >(other) | 511 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity>>(other) |
512 { | 512 { |
513 } | 513 } |
514 }; | 514 }; |
515 | 515 |
516 // Members are used in classes to contain strong pointers to other oilpan heap | 516 // Members are used in classes to contain strong pointers to other oilpan heap |
517 // allocated objects. | 517 // allocated objects. |
518 // All Member fields of a class must be traced in the class' trace method. | 518 // All Member fields of a class must be traced in the class' trace method. |
519 // During the mark phase of the GC all live objects are marked as live and | 519 // During the mark phase of the GC all live objects are marked as live and |
520 // all Member fields of a live object will be traced marked as live as well. | 520 // all Member fields of a live object will be traced marked as live as well. |
521 template<typename T> | 521 template<typename T> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // NeedsTracing<T>::value || IsWeakMember<T>::value. It should not need to test | 644 // NeedsTracing<T>::value || IsWeakMember<T>::value. It should not need to test |
645 // raw pointer types. To remove these tests, we may need support for | 645 // raw pointer types. To remove these tests, we may need support for |
646 // instantiating a template with a RawPtrOrMember'ish template. | 646 // instantiating a template with a RawPtrOrMember'ish template. |
647 template<typename T> | 647 template<typename T> |
648 struct TraceIfNeeded : public TraceIfEnabled<T, WTF::NeedsTracing<T>::value || b
link::IsGarbageCollectedType<typename RemoveHeapPointerWrapperTypes<typename WTF
::RemovePointer<T>::Type>::Type>::value> { }; | 648 struct TraceIfNeeded : public TraceIfEnabled<T, WTF::NeedsTracing<T>::value || b
link::IsGarbageCollectedType<typename RemoveHeapPointerWrapperTypes<typename WTF
::RemovePointer<T>::Type>::Type>::value> { }; |
649 | 649 |
650 // This trace trait for std::pair will null weak members if their referent is | 650 // This trace trait for std::pair will null weak members if their referent is |
651 // collected. If you have a collection that contain weakness it does not remove | 651 // collected. If you have a collection that contain weakness it does not remove |
652 // entries from the collection that contain nulled weak members. | 652 // entries from the collection that contain nulled weak members. |
653 template<typename T, typename U> | 653 template<typename T, typename U> |
654 class TraceTrait<std::pair<T, U> > { | 654 class TraceTrait<std::pair<T, U>> { |
655 public: | 655 public: |
656 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is
Weak<T>::value; | 656 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is
Weak<T>::value; |
657 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I
sWeak<U>::value; | 657 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I
sWeak<U>::value; |
658 static void trace(Visitor* visitor, std::pair<T, U>* pair) | 658 static void trace(Visitor* visitor, std::pair<T, U>* pair) |
659 { | 659 { |
660 TraceIfEnabled<T, firstNeedsTracing>::trace(visitor, &pair->first); | 660 TraceIfEnabled<T, firstNeedsTracing>::trace(visitor, &pair->first); |
661 TraceIfEnabled<U, secondNeedsTracing>::trace(visitor, &pair->second); | 661 TraceIfEnabled<U, secondNeedsTracing>::trace(visitor, &pair->second); |
662 } | 662 } |
663 }; | 663 }; |
664 | 664 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 static const bool value = TraceEagerlyTrait<T>::value; | 931 static const bool value = TraceEagerlyTrait<T>::value; |
932 }; | 932 }; |
933 | 933 |
934 template<typename T> | 934 template<typename T> |
935 class TraceEagerlyTrait<CrossThreadPersistent<T>> { | 935 class TraceEagerlyTrait<CrossThreadPersistent<T>> { |
936 public: | 936 public: |
937 static const bool value = TraceEagerlyTrait<T>::value; | 937 static const bool value = TraceEagerlyTrait<T>::value; |
938 }; | 938 }; |
939 | 939 |
940 template<typename T, typename U, typename V, typename W, typename X> | 940 template<typename T, typename U, typename V, typename W, typename X> |
941 class TraceEagerlyTrait<HeapHashMap<T, U, V, W, X> > { | 941 class TraceEagerlyTrait<HeapHashMap<T, U, V, W, X>> { |
942 public: | 942 public: |
943 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e || TraceEagerlyTrait<U>::value; | 943 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e || TraceEagerlyTrait<U>::value; |
944 }; | 944 }; |
945 | 945 |
946 template<typename T, typename U, typename V> | 946 template<typename T, typename U, typename V> |
947 class TraceEagerlyTrait<HeapHashSet<T, U, V> > { | 947 class TraceEagerlyTrait<HeapHashSet<T, U, V>> { |
948 public: | 948 public: |
949 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; | 949 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; |
950 }; | 950 }; |
951 | 951 |
952 template<typename T, typename U, typename V> | 952 template<typename T, typename U, typename V> |
953 class TraceEagerlyTrait<HeapLinkedHashSet<T, U, V> > { | 953 class TraceEagerlyTrait<HeapLinkedHashSet<T, U, V>> { |
954 public: | 954 public: |
955 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; | 955 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; |
956 }; | 956 }; |
957 | 957 |
958 template<typename T, size_t inlineCapacity, typename U> | 958 template<typename T, size_t inlineCapacity, typename U> |
959 class TraceEagerlyTrait<HeapListHashSet<T, inlineCapacity, U> > { | 959 class TraceEagerlyTrait<HeapListHashSet<T, inlineCapacity, U>> { |
960 public: | 960 public: |
961 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; | 961 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; |
962 }; | 962 }; |
963 | 963 |
964 template<typename T, size_t inlineCapacity> | 964 template<typename T, size_t inlineCapacity> |
965 class TraceEagerlyTrait<WTF::ListHashSetNode<T, HeapListHashSetAllocator<T, inli
neCapacity>>> { | 965 class TraceEagerlyTrait<WTF::ListHashSetNode<T, HeapListHashSetAllocator<T, inli
neCapacity>>> { |
966 public: | 966 public: |
967 static const bool value = false; | 967 static const bool value = false; |
968 }; | 968 }; |
969 | 969 |
970 template<typename T, size_t inlineCapacity> | 970 template<typename T, size_t inlineCapacity> |
971 class TraceEagerlyTrait<HeapVector<T, inlineCapacity> > { | 971 class TraceEagerlyTrait<HeapVector<T, inlineCapacity>> { |
972 public: | 972 public: |
973 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; | 973 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; |
974 }; | 974 }; |
975 | 975 |
976 template<typename T, typename U> | 976 template<typename T, typename U> |
977 class TraceEagerlyTrait<HeapVectorBacking<T, U>> { | 977 class TraceEagerlyTrait<HeapVectorBacking<T, U>> { |
978 public: | 978 public: |
979 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; | 979 static const bool value = MARKER_EAGER_TRACING || TraceEagerlyTrait<T>::valu
e; |
980 }; | 980 }; |
981 | 981 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 template<typename T> | 1181 template<typename T> |
1182 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { | 1182 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { |
1183 }; | 1183 }; |
1184 | 1184 |
1185 template<typename T> | 1185 template<typename T> |
1186 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1186 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
1187 | 1187 |
1188 } // namespace WTF | 1188 } // namespace WTF |
1189 | 1189 |
1190 #endif | 1190 #endif |
OLD | NEW |