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 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 669 |
670 template<typename T> | 670 template<typename T> |
671 class TraceTrait<OwnPtr<T> > { | 671 class TraceTrait<OwnPtr<T> > { |
672 public: | 672 public: |
673 static void trace(Visitor* visitor, OwnPtr<T>* ptr) | 673 static void trace(Visitor* visitor, OwnPtr<T>* ptr) |
674 { | 674 { |
675 TraceTrait<T>::trace(visitor, ptr->get()); | 675 TraceTrait<T>::trace(visitor, ptr->get()); |
676 } | 676 } |
677 }; | 677 }; |
678 | 678 |
679 template<bool needsTracing, typename T> | 679 template<typename T, bool needsTracing> |
680 struct StdPairHelper; | 680 struct TraceIfEnabled; |
681 | 681 |
682 template<typename T> | 682 template<typename T> |
683 struct StdPairHelper<false, T> { | 683 struct TraceIfEnabled<T, false> { |
684 static void trace(Visitor*, T*) { } | 684 static void trace(Visitor*, T*) { } |
685 }; | 685 }; |
686 | 686 |
687 template<typename T> | 687 template<typename T> |
688 struct StdPairHelper<true, T> { | 688 struct TraceIfEnabled<T, true> { |
689 static void trace(Visitor* visitor, T* t) | 689 static void trace(Visitor* visitor, T* t) |
690 { | 690 { |
691 visitor->trace(*t); | 691 visitor->trace(*t); |
692 } | 692 } |
693 }; | 693 }; |
694 | 694 |
| 695 template <typename T> struct RemoveHeapPointerWrapperTypes { |
| 696 typedef typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typename W
TF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type Type; |
| 697 }; |
| 698 |
| 699 template<typename T> |
| 700 struct TraceIfNeeded : public TraceIfEnabled<T, WebCore::IsGarbageCollectedType<
typename RemoveHeapPointerWrapperTypes<typename WTF::RemovePointer<T>::Type>::Ty
pe>::value> { }; |
| 701 |
695 // This trace trait for std::pair will null weak members if their referent is | 702 // This trace trait for std::pair will null weak members if their referent is |
696 // collected. If you have a collection that contain weakness it does not remove | 703 // collected. If you have a collection that contain weakness it does not remove |
697 // entries from the collection that contain nulled weak members. | 704 // entries from the collection that contain nulled weak members. |
698 template<typename T, typename U> | 705 template<typename T, typename U> |
699 class TraceTrait<std::pair<T, U> > { | 706 class TraceTrait<std::pair<T, U> > { |
700 public: | 707 public: |
701 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is
Weak<T>::value; | 708 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is
Weak<T>::value; |
702 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I
sWeak<U>::value; | 709 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I
sWeak<U>::value; |
703 static void trace(Visitor* visitor, std::pair<T, U>* pair) | 710 static void trace(Visitor* visitor, std::pair<T, U>* pair) |
704 { | 711 { |
705 StdPairHelper<firstNeedsTracing, T>::trace(visitor, &pair->first); | 712 TraceIfEnabled<T, firstNeedsTracing>::trace(visitor, &pair->first); |
706 StdPairHelper<secondNeedsTracing, U>::trace(visitor, &pair->second); | 713 TraceIfEnabled<U, secondNeedsTracing>::trace(visitor, &pair->second); |
707 } | 714 } |
708 }; | 715 }; |
709 | 716 |
710 // WeakMember is similar to Member in that it is used to point to other oilpan | 717 // WeakMember is similar to Member in that it is used to point to other oilpan |
711 // heap allocated objects. | 718 // heap allocated objects. |
712 // However instead of creating a strong pointer to the object, the WeakMember cr
eates | 719 // However instead of creating a strong pointer to the object, the WeakMember cr
eates |
713 // a weak pointer, which does not keep the pointee alive. Hence if all pointers
to | 720 // a weak pointer, which does not keep the pointee alive. Hence if all pointers
to |
714 // to a heap allocated object are weak the object will be garbage collected. At
the | 721 // to a heap allocated object are weak the object will be garbage collected. At
the |
715 // time of GC the weak pointers will automatically be set to null. | 722 // time of GC the weak pointers will automatically be set to null. |
716 template<typename T> | 723 template<typename T> |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa
rbageCollectedType<T>::value> { | 1197 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa
rbageCollectedType<T>::value> { |
1191 }; | 1198 }; |
1192 | 1199 |
1193 template<typename T> | 1200 template<typename T> |
1194 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, bli
nk::IsGarbageCollectedType<T>::value> { | 1201 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, bli
nk::IsGarbageCollectedType<T>::value> { |
1195 }; | 1202 }; |
1196 | 1203 |
1197 } // namespace WTF | 1204 } // namespace WTF |
1198 | 1205 |
1199 #endif | 1206 #endif |
OLD | NEW |