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

Side by Side Diff: Source/platform/heap/Handle.h

Issue 365653002: Oilpan: move 2D Canvas and WebGL objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Have Nullable<T>::trace() use TraceIfNeeded<>. Created 6 years, 5 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 /* 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 658
659 template<typename T> 659 template<typename T>
660 class TraceTrait<OwnPtr<T> > { 660 class TraceTrait<OwnPtr<T> > {
661 public: 661 public:
662 static void trace(Visitor* visitor, OwnPtr<T>* ptr) 662 static void trace(Visitor* visitor, OwnPtr<T>* ptr)
663 { 663 {
664 TraceTrait<T>::trace(visitor, ptr->get()); 664 TraceTrait<T>::trace(visitor, ptr->get());
665 } 665 }
666 }; 666 };
667 667
668 template<bool needsTracing, typename T> 668 template<typename T, bool needsTracing>
669 struct StdPairHelper; 669 struct TraceIfEnabled;
670 670
671 template<typename T> 671 template<typename T>
672 struct StdPairHelper<false, T> { 672 struct TraceIfEnabled<T, false> {
673 static void trace(Visitor*, T*) { } 673 static void trace(Visitor*, T*) { }
674 }; 674 };
675 675
676 template<typename T> 676 template<typename T>
677 struct StdPairHelper<true, T> { 677 struct TraceIfEnabled<T, true> {
678 static void trace(Visitor* visitor, T* t) 678 static void trace(Visitor* visitor, T* t)
679 { 679 {
680 visitor->trace(*t); 680 visitor->trace(*t);
681 } 681 }
682 }; 682 };
683 683
684 template <typename T> struct RemoveHeapPointerWrapperTypes {
685 typedef typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typename W TF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type Type;
686 };
687
688 template<typename T>
689 struct TraceIfNeeded : public TraceIfEnabled<T, WebCore::IsGarbageCollectedType< typename RemoveHeapPointerWrapperTypes<typename WTF::RemovePointer<T>::Type>::Ty pe>::value> { };
690
684 // This trace trait for std::pair will null weak members if their referent is 691 // This trace trait for std::pair will null weak members if their referent is
685 // collected. If you have a collection that contain weakness it does not remove 692 // collected. If you have a collection that contain weakness it does not remove
686 // entries from the collection that contain nulled weak members. 693 // entries from the collection that contain nulled weak members.
687 template<typename T, typename U> 694 template<typename T, typename U>
688 class TraceTrait<std::pair<T, U> > { 695 class TraceTrait<std::pair<T, U> > {
689 public: 696 public:
690 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is Weak<T>::value; 697 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is Weak<T>::value;
691 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I sWeak<U>::value; 698 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I sWeak<U>::value;
692 static void trace(Visitor* visitor, std::pair<T, U>* pair) 699 static void trace(Visitor* visitor, std::pair<T, U>* pair)
693 { 700 {
694 StdPairHelper<firstNeedsTracing, T>::trace(visitor, &pair->first); 701 TraceIfEnabled<T, firstNeedsTracing>::trace(visitor, &pair->first);
695 StdPairHelper<secondNeedsTracing, U>::trace(visitor, &pair->second); 702 TraceIfEnabled<U, secondNeedsTracing>::trace(visitor, &pair->second);
696 } 703 }
697 }; 704 };
698 705
699 // WeakMember is similar to Member in that it is used to point to other oilpan 706 // WeakMember is similar to Member in that it is used to point to other oilpan
700 // heap allocated objects. 707 // heap allocated objects.
701 // However instead of creating a strong pointer to the object, the WeakMember cr eates 708 // However instead of creating a strong pointer to the object, the WeakMember cr eates
702 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to 709 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to
703 // to a heap allocated object are weak the object will be garbage collected. At the 710 // to a heap allocated object are weak the object will be garbage collected. At the
704 // time of GC the weak pointers will automatically be set to null. 711 // time of GC the weak pointers will automatically be set to null.
705 template<typename T> 712 template<typename T>
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, WebCore::Is GarbageCollectedType<T>::value> { 1181 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, WebCore::Is GarbageCollectedType<T>::value> {
1175 }; 1182 };
1176 1183
1177 template<typename T> 1184 template<typename T>
1178 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, Web Core::IsGarbageCollectedType<T>::value> { 1185 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, Web Core::IsGarbageCollectedType<T>::value> {
1179 }; 1186 };
1180 1187
1181 } // namespace WTF 1188 } // namespace WTF
1182 1189
1183 #endif 1190 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698