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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 this->m_raw = nullptr; | 862 this->m_raw = nullptr; |
863 return *this; | 863 return *this; |
864 } | 864 } |
865 | 865 |
866 private: | 866 private: |
867 T** cell() const { return const_cast<T**>(&this->m_raw); } | 867 T** cell() const { return const_cast<T**>(&this->m_raw); } |
868 | 868 |
869 template<typename Derived> friend class VisitorHelper; | 869 template<typename Derived> friend class VisitorHelper; |
870 }; | 870 }; |
871 | 871 |
872 // Comparison operators between (Weak)Members and Persistents | 872 // UntracedMember is actually a raw pointer. |
873 // It is allowed to store a pointer to an object on oilpan heap, | |
874 // and it is also allowed to store UntracedMember in off heap collections. | |
875 // UntracedMember does not keep the pointee object alive, so if you use | |
876 // UntracedMember, you must guarantee that the pointee object is alive in | |
877 // some reason. | |
haraken
2015/10/15 05:26:08
// UntracedMember is a pointer to an on-heap objec
peria
2015/10/15 06:03:43
Done.
Thank you for this description.
| |
878 template<typename T> | |
879 class UntracedMember : public Member<T> { | |
haraken
2015/10/15 05:26:08
Add final.
peria
2015/10/15 06:03:43
Done.
| |
880 public: | |
881 UntracedMember() : Member<T>() { } | |
882 | |
883 UntracedMember(std::nullptr_t) : Member<T>(nullptr) { } | |
884 | |
885 UntracedMember(T* raw) : Member<T>(raw) { } | |
886 | |
887 template<typename U> | |
888 UntracedMember(const RawPtr<U>& other) : Member<T>(other) { } | |
889 | |
890 template<typename U> | |
891 UntracedMember(const Persistent<U>& other) : Member<T>(other) { } | |
892 | |
893 template<typename U> | |
894 UntracedMember(const Member<U>& other) : Member<T>(other) { } | |
895 | |
896 UntracedMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } | |
haraken
2015/10/15 05:26:08
Also implement operator=, just like WeakMember's o
peria
2015/10/15 06:03:43
Done.
| |
897 }; | |
898 | |
899 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. | |
873 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } | 900 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } |
874 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } | 901 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } |
902 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } | |
903 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } | |
904 | |
875 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } | 905 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } |
876 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } | 906 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } |
877 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } | 907 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
878 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } | 908 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } |
879 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } | |
880 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } | |
881 | 909 |
882 template<typename T> | 910 template<typename T> |
883 class DummyBase { | 911 class DummyBase { |
884 public: | 912 public: |
885 DummyBase() { } | 913 DummyBase() { } |
886 ~DummyBase() { } | 914 ~DummyBase() { } |
887 }; | 915 }; |
888 | 916 |
889 // CPP-defined type names for the transition period where we want to | 917 // CPP-defined type names for the transition period where we want to |
890 // support both reference counting and garbage collection based on a | 918 // support both reference counting and garbage collection based on a |
(...skipping 27 matching lines...) Expand all Loading... | |
918 #define RefPtrWillBePersistent blink::Persistent | 946 #define RefPtrWillBePersistent blink::Persistent |
919 #define RefPtrWillBeRawPtr WTF::RawPtr | 947 #define RefPtrWillBeRawPtr WTF::RawPtr |
920 #define RefPtrWillBeMember blink::Member | 948 #define RefPtrWillBeMember blink::Member |
921 #define RefPtrWillBeWeakMember blink::WeakMember | 949 #define RefPtrWillBeWeakMember blink::WeakMember |
922 #define RefPtrWillBeWeakPersistent blink::WeakPersistent | 950 #define RefPtrWillBeWeakPersistent blink::WeakPersistent |
923 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent | 951 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
924 #define RawPtrWillBeMember blink::Member | 952 #define RawPtrWillBeMember blink::Member |
925 #define RawPtrWillBePersistent blink::Persistent | 953 #define RawPtrWillBePersistent blink::Persistent |
926 #define RawPtrWillBeWeakMember blink::WeakMember | 954 #define RawPtrWillBeWeakMember blink::WeakMember |
927 #define RawPtrWillBeWeakPersistent blink::WeakPersistent | 955 #define RawPtrWillBeWeakPersistent blink::WeakPersistent |
956 #define RawPtrWillBeUntracedMember blink::UntracedMember | |
928 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent | 957 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
929 #define OwnPtrWillBeMember blink::Member | 958 #define OwnPtrWillBeMember blink::Member |
930 #define OwnPtrWillBePersistent blink::Persistent | 959 #define OwnPtrWillBePersistent blink::Persistent |
931 #define OwnPtrWillBeRawPtr WTF::RawPtr | 960 #define OwnPtrWillBeRawPtr WTF::RawPtr |
932 #define PassOwnPtrWillBeRawPtr WTF::RawPtr | 961 #define PassOwnPtrWillBeRawPtr WTF::RawPtr |
933 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent | 962 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent |
934 #define WeakPtrWillBeMember blink::Member | 963 #define WeakPtrWillBeMember blink::Member |
935 #define WeakPtrWillBeRawPtr WTF::RawPtr | 964 #define WeakPtrWillBeRawPtr WTF::RawPtr |
936 #define WeakPtrWillBeWeakMember blink::WeakMember | 965 #define WeakPtrWillBeWeakMember blink::WeakMember |
937 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent | 966 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 #define RefPtrWillBePersistent WTF::RefPtr | 1030 #define RefPtrWillBePersistent WTF::RefPtr |
1002 #define RefPtrWillBeRawPtr WTF::RefPtr | 1031 #define RefPtrWillBeRawPtr WTF::RefPtr |
1003 #define RefPtrWillBeMember WTF::RefPtr | 1032 #define RefPtrWillBeMember WTF::RefPtr |
1004 #define RefPtrWillBeWeakMember WTF::RefPtr | 1033 #define RefPtrWillBeWeakMember WTF::RefPtr |
1005 #define RefPtrWillBeWeakPersistent WTF::RefPtr | 1034 #define RefPtrWillBeWeakPersistent WTF::RefPtr |
1006 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr | 1035 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr |
1007 #define RawPtrWillBeMember WTF::RawPtr | 1036 #define RawPtrWillBeMember WTF::RawPtr |
1008 #define RawPtrWillBePersistent WTF::RawPtr | 1037 #define RawPtrWillBePersistent WTF::RawPtr |
1009 #define RawPtrWillBeWeakMember WTF::RawPtr | 1038 #define RawPtrWillBeWeakMember WTF::RawPtr |
1010 #define RawPtrWillBeWeakPersistent WTF::RawPtr | 1039 #define RawPtrWillBeWeakPersistent WTF::RawPtr |
1040 #define RawPtrWillBeUntracedMember WTF::RawPtr | |
1011 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr | 1041 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr |
1012 #define OwnPtrWillBeMember WTF::OwnPtr | 1042 #define OwnPtrWillBeMember WTF::OwnPtr |
1013 #define OwnPtrWillBePersistent WTF::OwnPtr | 1043 #define OwnPtrWillBePersistent WTF::OwnPtr |
1014 #define OwnPtrWillBeRawPtr WTF::OwnPtr | 1044 #define OwnPtrWillBeRawPtr WTF::OwnPtr |
1015 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr | 1045 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr |
1016 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr | 1046 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr |
1017 #define WeakPtrWillBeMember WTF::WeakPtr | 1047 #define WeakPtrWillBeMember WTF::WeakPtr |
1018 #define WeakPtrWillBeRawPtr WTF::WeakPtr | 1048 #define WeakPtrWillBeRawPtr WTF::WeakPtr |
1019 #define WeakPtrWillBeWeakMember WTF::WeakPtr | 1049 #define WeakPtrWillBeWeakMember WTF::WeakPtr |
1020 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr | 1050 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 static const bool canMoveWithMemcpy = true; | 1221 static const bool canMoveWithMemcpy = true; |
1192 }; | 1222 }; |
1193 | 1223 |
1194 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa se<blink::WeakMember<T>> { | 1224 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa se<blink::WeakMember<T>> { |
1195 static const bool needsDestruction = false; | 1225 static const bool needsDestruction = false; |
1196 static const bool canInitializeWithMemset = true; | 1226 static const bool canInitializeWithMemset = true; |
1197 static const bool canClearUnusedSlotsWithMemset = true; | 1227 static const bool canClearUnusedSlotsWithMemset = true; |
1198 static const bool canMoveWithMemcpy = true; | 1228 static const bool canMoveWithMemcpy = true; |
1199 }; | 1229 }; |
1200 | 1230 |
1231 template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTrai tsBase<blink::UntracedMember<T>> { | |
1232 static const bool needsDestruction = false; | |
1233 static const bool canInitializeWithMemset = true; | |
1234 static const bool canClearUnusedSlotsWithMemset = true; | |
1235 static const bool canMoveWithMemcpy = true; | |
1236 }; | |
1237 | |
1201 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> { | 1238 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> { |
1202 static const bool needsDestruction = false; | 1239 static const bool needsDestruction = false; |
1203 static const bool canInitializeWithMemset = true; | 1240 static const bool canInitializeWithMemset = true; |
1204 static const bool canClearUnusedSlotsWithMemset = true; | 1241 static const bool canClearUnusedSlotsWithMemset = true; |
1205 static const bool canMoveWithMemcpy = true; | 1242 static const bool canMoveWithMemcpy = true; |
1206 }; | 1243 }; |
1207 | 1244 |
1208 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> { | 1245 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> { |
1209 static const bool needsDestruction = false; | 1246 static const bool needsDestruction = false; |
1210 static const bool canInitializeWithMemset = true; | 1247 static const bool canInitializeWithMemset = true; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1282 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) | 1319 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) |
1283 { | 1320 { |
1284 if (strongify == WeakPointersActStrong) { | 1321 if (strongify == WeakPointersActStrong) { |
1285 visitor->trace(weakMember.get()); // Strongified visit. | 1322 visitor->trace(weakMember.get()); // Strongified visit. |
1286 return false; | 1323 return false; |
1287 } | 1324 } |
1288 return !blink::Heap::isHeapObjectAlive(weakMember); | 1325 return !blink::Heap::isHeapObjectAlive(weakMember); |
1289 } | 1326 } |
1290 }; | 1327 }; |
1291 | 1328 |
1329 template<typename T> struct HashTraits<blink::UntracedMember<T>> : SimpleClassHa shTraits<blink::UntracedMember<T>> { | |
1330 static const bool needsDestruction = false; | |
1331 // FIXME: The distinction between PeekInType and PassInType is there for | |
1332 // the sake of the reference counting handles. When they are gone the two | |
1333 // types can be merged into PassInType. | |
1334 // FIXME: Implement proper const'ness for iterator types. | |
1335 using PeekInType = RawPtr<T>; | |
1336 using PassInType = RawPtr<T>; | |
1337 using IteratorGetType = blink::UntracedMember<T>*; | |
1338 using IteratorConstGetType = const blink::UntracedMember<T>*; | |
1339 using IteratorReferenceType = blink::UntracedMember<T>&; | |
1340 using IteratorConstReferenceType = const blink::UntracedMember<T>&; | |
1341 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; } | |
1342 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; } | |
1343 // FIXME: Similarly, there is no need for a distinction between PeekOutType | |
1344 // and PassOutType without reference counting. | |
1345 using PeekOutType = T*; | |
1346 using PassOutType = T*; | |
1347 | |
1348 template<typename U> | |
1349 static void store(const U& value, blink::UntracedMember<T>& storage) { stora ge = value; } | |
1350 | |
1351 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu e; } | |
1352 static PassOutType passOut(const blink::UntracedMember<T>& value) { return v alue; } | |
1353 }; | |
1354 | |
1292 template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> { | 1355 template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> { |
1293 template<typename U> | 1356 template<typename U> |
1294 static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); } | 1357 static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); } |
1295 static bool equal(T* a, const blink::Member<T>& b) { return a == b; } | 1358 static bool equal(T* a, const blink::Member<T>& b) { return a == b; } |
1296 static bool equal(const blink::Member<T>& a, T* b) { return a == b; } | 1359 static bool equal(const blink::Member<T>& a, T* b) { return a == b; } |
1297 template<typename U, typename V> | 1360 template<typename U, typename V> |
1298 static bool equal(const U& a, const V& b) { return a == b; } | 1361 static bool equal(const U& a, const V& b) { return a == b; } |
1299 }; | 1362 }; |
1300 | 1363 |
1301 template<typename T> struct PtrHash<blink::WeakMember<T>> : PtrHash<blink::Membe r<T>> { | 1364 template<typename T> struct PtrHash<blink::WeakMember<T>> : PtrHash<blink::Membe r<T>> { |
1302 }; | 1365 }; |
1303 | 1366 |
1367 template<typename T> struct PtrHash<blink::UntracedMember<T>> : PtrHash<blink::M ember<T>> { | |
1368 }; | |
1369 | |
1304 // PtrHash is the default hash for hash tables with members. | 1370 // PtrHash is the default hash for hash tables with members. |
1305 template<typename T> struct DefaultHash<blink::Member<T>> { | 1371 template<typename T> struct DefaultHash<blink::Member<T>> { |
1306 using Hash = PtrHash<blink::Member<T>>; | 1372 using Hash = PtrHash<blink::Member<T>>; |
1307 }; | 1373 }; |
1308 | 1374 |
1309 template<typename T> struct DefaultHash<blink::WeakMember<T>> { | 1375 template<typename T> struct DefaultHash<blink::WeakMember<T>> { |
1310 using Hash = PtrHash<blink::WeakMember<T>>; | 1376 using Hash = PtrHash<blink::WeakMember<T>>; |
1311 }; | 1377 }; |
1312 | 1378 |
1379 template<typename T> struct DefaultHash<blink::UntracedMember<T>> { | |
1380 using Hash = PtrHash<blink::UntracedMember<T>>; | |
1381 }; | |
1382 | |
1313 template<typename T> | 1383 template<typename T> |
1314 struct NeedsTracing<blink::Member<T>> { | 1384 struct NeedsTracing<blink::Member<T>> { |
1315 static const bool value = true; | 1385 static const bool value = true; |
1316 }; | 1386 }; |
1317 | 1387 |
1318 template<typename T> | 1388 template<typename T> |
1319 struct IsWeak<blink::WeakMember<T>> { | 1389 struct IsWeak<blink::WeakMember<T>> { |
1320 static const bool value = true; | 1390 static const bool value = true; |
1321 }; | 1391 }; |
1322 | 1392 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. | 1451 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. |
1382 static T* unwrap(const StorageType& value) { return value.get(); } | 1452 static T* unwrap(const StorageType& value) { return value.get(); } |
1383 }; | 1453 }; |
1384 | 1454 |
1385 template<typename T> | 1455 template<typename T> |
1386 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1456 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
1387 | 1457 |
1388 } // namespace WTF | 1458 } // namespace WTF |
1389 | 1459 |
1390 #endif | 1460 #endif |
OLD | NEW |