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

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

Issue 1397073002: [Oilpan] Create UnsafePtr to store on-heap pointers in Vector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Work for nits Created 5 years, 2 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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 a pointer to an on-heap object that is not traced for some
873 // reason. Please don't use this unless you understand what you're doing.
874 // Basically, all pointers to on-heap objects must be stored in either of
875 // Persistent, Member or WeakMember. It is not allowed to leave raw pointers to
876 // on-heap objects. However, there can be scenarios where you have to use raw
877 // pointers for some reason, and in that case you can use UntracedMember. Of
878 // course, it must be guaranteed that the pointing on-heap object is kept alive
879 // while the raw pointer is pointing to the object.
880 template<typename T>
881 class UntracedMember final : public Member<T> {
882 public:
883 UntracedMember() : Member<T>() { }
884
885 UntracedMember(std::nullptr_t) : Member<T>(nullptr) { }
886
887 UntracedMember(T* raw) : Member<T>(raw) { }
888
889 template<typename U>
890 UntracedMember(const RawPtr<U>& other) : Member<T>(other) { }
891
892 template<typename U>
893 UntracedMember(const Persistent<U>& other) : Member<T>(other) { }
894
895 template<typename U>
896 UntracedMember(const Member<U>& other) : Member<T>(other) { }
897
898 UntracedMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { }
899
900 template<typename U>
901 UntracedMember& operator=(const Persistent<U>& other)
902 {
903 this->m_raw = other;
904 this->checkPointer();
905 return *this;
906 }
907
908 template<typename U>
909 UntracedMember& operator=(const Member<U>& other)
910 {
911 this->m_raw = other;
912 this->checkPointer();
913 return *this;
914 }
915
916 template<typename U>
917 UntracedMember& operator=(U* other)
918 {
919 this->m_raw = other;
920 this->checkPointer();
921 return *this;
922 }
923
924 template<typename U>
925 UntracedMember& operator=(const RawPtr<U>& other)
926 {
927 this->m_raw = other;
928 this->checkPointer();
929 return *this;
930 }
931
932 UntracedMember& operator=(std::nullptr_t)
933 {
934 this->m_raw = nullptr;
935 return *this;
936 }
937 };
938
939 // 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(); } 940 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(); } 941 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); }
942 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
943 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
944
875 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } 945 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(); } 946 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(); } 947 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(); } 948 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 949
882 template<typename T> 950 template<typename T>
883 class DummyBase { 951 class DummyBase {
884 public: 952 public:
885 DummyBase() { } 953 DummyBase() { }
886 ~DummyBase() { } 954 ~DummyBase() { }
887 }; 955 };
888 956
889 // CPP-defined type names for the transition period where we want to 957 // CPP-defined type names for the transition period where we want to
890 // support both reference counting and garbage collection based on a 958 // support both reference counting and garbage collection based on a
(...skipping 27 matching lines...) Expand all
918 #define RefPtrWillBePersistent blink::Persistent 986 #define RefPtrWillBePersistent blink::Persistent
919 #define RefPtrWillBeRawPtr WTF::RawPtr 987 #define RefPtrWillBeRawPtr WTF::RawPtr
920 #define RefPtrWillBeMember blink::Member 988 #define RefPtrWillBeMember blink::Member
921 #define RefPtrWillBeWeakMember blink::WeakMember 989 #define RefPtrWillBeWeakMember blink::WeakMember
922 #define RefPtrWillBeWeakPersistent blink::WeakPersistent 990 #define RefPtrWillBeWeakPersistent blink::WeakPersistent
923 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent 991 #define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent
924 #define RawPtrWillBeMember blink::Member 992 #define RawPtrWillBeMember blink::Member
925 #define RawPtrWillBePersistent blink::Persistent 993 #define RawPtrWillBePersistent blink::Persistent
926 #define RawPtrWillBeWeakMember blink::WeakMember 994 #define RawPtrWillBeWeakMember blink::WeakMember
927 #define RawPtrWillBeWeakPersistent blink::WeakPersistent 995 #define RawPtrWillBeWeakPersistent blink::WeakPersistent
996 #define RawPtrWillBeUntracedMember blink::UntracedMember
928 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent 997 #define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent
929 #define OwnPtrWillBeMember blink::Member 998 #define OwnPtrWillBeMember blink::Member
930 #define OwnPtrWillBePersistent blink::Persistent 999 #define OwnPtrWillBePersistent blink::Persistent
931 #define OwnPtrWillBeRawPtr WTF::RawPtr 1000 #define OwnPtrWillBeRawPtr WTF::RawPtr
932 #define PassOwnPtrWillBeRawPtr WTF::RawPtr 1001 #define PassOwnPtrWillBeRawPtr WTF::RawPtr
933 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent 1002 #define WeakPtrWillBeCrossThreadWeakPersistent blink::CrossThreadWeakPersistent
934 #define WeakPtrWillBeMember blink::Member 1003 #define WeakPtrWillBeMember blink::Member
935 #define WeakPtrWillBeRawPtr WTF::RawPtr 1004 #define WeakPtrWillBeRawPtr WTF::RawPtr
936 #define WeakPtrWillBeWeakMember blink::WeakMember 1005 #define WeakPtrWillBeWeakMember blink::WeakMember
937 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent 1006 #define WeakPtrWillBeWeakPersistent blink::WeakPersistent
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 #define RefPtrWillBePersistent WTF::RefPtr 1070 #define RefPtrWillBePersistent WTF::RefPtr
1002 #define RefPtrWillBeRawPtr WTF::RefPtr 1071 #define RefPtrWillBeRawPtr WTF::RefPtr
1003 #define RefPtrWillBeMember WTF::RefPtr 1072 #define RefPtrWillBeMember WTF::RefPtr
1004 #define RefPtrWillBeWeakMember WTF::RefPtr 1073 #define RefPtrWillBeWeakMember WTF::RefPtr
1005 #define RefPtrWillBeWeakPersistent WTF::RefPtr 1074 #define RefPtrWillBeWeakPersistent WTF::RefPtr
1006 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr 1075 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr
1007 #define RawPtrWillBeMember WTF::RawPtr 1076 #define RawPtrWillBeMember WTF::RawPtr
1008 #define RawPtrWillBePersistent WTF::RawPtr 1077 #define RawPtrWillBePersistent WTF::RawPtr
1009 #define RawPtrWillBeWeakMember WTF::RawPtr 1078 #define RawPtrWillBeWeakMember WTF::RawPtr
1010 #define RawPtrWillBeWeakPersistent WTF::RawPtr 1079 #define RawPtrWillBeWeakPersistent WTF::RawPtr
1080 #define RawPtrWillBeUntracedMember WTF::RawPtr
1011 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr 1081 #define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr
1012 #define OwnPtrWillBeMember WTF::OwnPtr 1082 #define OwnPtrWillBeMember WTF::OwnPtr
1013 #define OwnPtrWillBePersistent WTF::OwnPtr 1083 #define OwnPtrWillBePersistent WTF::OwnPtr
1014 #define OwnPtrWillBeRawPtr WTF::OwnPtr 1084 #define OwnPtrWillBeRawPtr WTF::OwnPtr
1015 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr 1085 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr
1016 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr 1086 #define WeakPtrWillBeCrossThreadWeakPersistent WTF::WeakPtr
1017 #define WeakPtrWillBeMember WTF::WeakPtr 1087 #define WeakPtrWillBeMember WTF::WeakPtr
1018 #define WeakPtrWillBeRawPtr WTF::WeakPtr 1088 #define WeakPtrWillBeRawPtr WTF::WeakPtr
1019 #define WeakPtrWillBeWeakMember WTF::WeakPtr 1089 #define WeakPtrWillBeWeakMember WTF::WeakPtr
1020 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr 1090 #define WeakPtrWillBeWeakPersistent WTF::WeakPtr
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 static const bool canMoveWithMemcpy = true; 1261 static const bool canMoveWithMemcpy = true;
1192 }; 1262 };
1193 1263
1194 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa se<blink::WeakMember<T>> { 1264 template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa se<blink::WeakMember<T>> {
1195 static const bool needsDestruction = false; 1265 static const bool needsDestruction = false;
1196 static const bool canInitializeWithMemset = true; 1266 static const bool canInitializeWithMemset = true;
1197 static const bool canClearUnusedSlotsWithMemset = true; 1267 static const bool canClearUnusedSlotsWithMemset = true;
1198 static const bool canMoveWithMemcpy = true; 1268 static const bool canMoveWithMemcpy = true;
1199 }; 1269 };
1200 1270
1271 template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTrai tsBase<blink::UntracedMember<T>> {
1272 static const bool needsDestruction = false;
1273 static const bool canInitializeWithMemset = true;
1274 static const bool canClearUnusedSlotsWithMemset = true;
1275 static const bool canMoveWithMemcpy = true;
1276 };
1277
1201 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> { 1278 template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTrait sBase<blink::HeapVector<T, 0>> {
1202 static const bool needsDestruction = false; 1279 static const bool needsDestruction = false;
1203 static const bool canInitializeWithMemset = true; 1280 static const bool canInitializeWithMemset = true;
1204 static const bool canClearUnusedSlotsWithMemset = true; 1281 static const bool canClearUnusedSlotsWithMemset = true;
1205 static const bool canMoveWithMemcpy = true; 1282 static const bool canMoveWithMemcpy = true;
1206 }; 1283 };
1207 1284
1208 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> { 1285 template <typename T> struct VectorTraits<blink::HeapDeque<T, 0>> : VectorTraits Base<blink::HeapDeque<T, 0>> {
1209 static const bool needsDestruction = false; 1286 static const bool needsDestruction = false;
1210 static const bool canInitializeWithMemset = true; 1287 static const bool canInitializeWithMemset = true;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify) 1359 static bool traceInCollection(VisitorDispatcher visitor, blink::WeakMember<T >& weakMember, ShouldWeakPointersBeMarkedStrongly strongify)
1283 { 1360 {
1284 if (strongify == WeakPointersActStrong) { 1361 if (strongify == WeakPointersActStrong) {
1285 visitor->trace(weakMember.get()); // Strongified visit. 1362 visitor->trace(weakMember.get()); // Strongified visit.
1286 return false; 1363 return false;
1287 } 1364 }
1288 return !blink::Heap::isHeapObjectAlive(weakMember); 1365 return !blink::Heap::isHeapObjectAlive(weakMember);
1289 } 1366 }
1290 }; 1367 };
1291 1368
1369 template<typename T> struct HashTraits<blink::UntracedMember<T>> : SimpleClassHa shTraits<blink::UntracedMember<T>> {
1370 static const bool needsDestruction = false;
1371 // FIXME: The distinction between PeekInType and PassInType is there for
1372 // the sake of the reference counting handles. When they are gone the two
1373 // types can be merged into PassInType.
1374 // FIXME: Implement proper const'ness for iterator types.
1375 using PeekInType = RawPtr<T>;
1376 using PassInType = RawPtr<T>;
1377 using IteratorGetType = blink::UntracedMember<T>*;
1378 using IteratorConstGetType = const blink::UntracedMember<T>*;
1379 using IteratorReferenceType = blink::UntracedMember<T>&;
1380 using IteratorConstReferenceType = const blink::UntracedMember<T>&;
1381 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
1382 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; }
1383 // FIXME: Similarly, there is no need for a distinction between PeekOutType
1384 // and PassOutType without reference counting.
1385 using PeekOutType = T*;
1386 using PassOutType = T*;
1387
1388 template<typename U>
1389 static void store(const U& value, blink::UntracedMember<T>& storage) { stora ge = value; }
1390
1391 static PeekOutType peek(const blink::UntracedMember<T>& value) { return valu e; }
1392 static PassOutType passOut(const blink::UntracedMember<T>& value) { return v alue; }
1393 };
1394
1292 template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> { 1395 template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> {
1293 template<typename U> 1396 template<typename U>
1294 static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); } 1397 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; } 1398 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; } 1399 static bool equal(const blink::Member<T>& a, T* b) { return a == b; }
1297 template<typename U, typename V> 1400 template<typename U, typename V>
1298 static bool equal(const U& a, const V& b) { return a == b; } 1401 static bool equal(const U& a, const V& b) { return a == b; }
1299 }; 1402 };
1300 1403
1301 template<typename T> struct PtrHash<blink::WeakMember<T>> : PtrHash<blink::Membe r<T>> { 1404 template<typename T> struct PtrHash<blink::WeakMember<T>> : PtrHash<blink::Membe r<T>> {
1302 }; 1405 };
1303 1406
1407 template<typename T> struct PtrHash<blink::UntracedMember<T>> : PtrHash<blink::M ember<T>> {
1408 };
1409
1304 // PtrHash is the default hash for hash tables with members. 1410 // PtrHash is the default hash for hash tables with members.
1305 template<typename T> struct DefaultHash<blink::Member<T>> { 1411 template<typename T> struct DefaultHash<blink::Member<T>> {
1306 using Hash = PtrHash<blink::Member<T>>; 1412 using Hash = PtrHash<blink::Member<T>>;
1307 }; 1413 };
1308 1414
1309 template<typename T> struct DefaultHash<blink::WeakMember<T>> { 1415 template<typename T> struct DefaultHash<blink::WeakMember<T>> {
1310 using Hash = PtrHash<blink::WeakMember<T>>; 1416 using Hash = PtrHash<blink::WeakMember<T>>;
1311 }; 1417 };
1312 1418
1419 template<typename T> struct DefaultHash<blink::UntracedMember<T>> {
1420 using Hash = PtrHash<blink::UntracedMember<T>>;
1421 };
1422
1313 template<typename T> 1423 template<typename T>
1314 struct NeedsTracing<blink::Member<T>> { 1424 struct NeedsTracing<blink::Member<T>> {
1315 static const bool value = true; 1425 static const bool value = true;
1316 }; 1426 };
1317 1427
1318 template<typename T> 1428 template<typename T>
1319 struct IsWeak<blink::WeakMember<T>> { 1429 struct IsWeak<blink::WeakMember<T>> {
1320 static const bool value = true; 1430 static const bool value = true;
1321 }; 1431 };
1322 1432
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. 1491 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent.
1382 static T* unwrap(const StorageType& value) { return value.get(); } 1492 static T* unwrap(const StorageType& value) { return value.get(); }
1383 }; 1493 };
1384 1494
1385 template<typename T> 1495 template<typename T>
1386 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1496 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1387 1497
1388 } // namespace WTF 1498 } // namespace WTF
1389 1499
1390 #endif 1500 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/LocalFrame.cpp ('k') | third_party/WebKit/Source/platform/heap/Heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698