| 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 28 matching lines...) Expand all Loading... |
| 39 #include "platform/heap/TraceTraits.h" | 39 #include "platform/heap/TraceTraits.h" |
| 40 #include "platform/heap/Visitor.h" | 40 #include "platform/heap/Visitor.h" |
| 41 #include "wtf/Functional.h" | 41 #include "wtf/Functional.h" |
| 42 #include "wtf/HashFunctions.h" | 42 #include "wtf/HashFunctions.h" |
| 43 #include "wtf/Locker.h" | 43 #include "wtf/Locker.h" |
| 44 #include "wtf/MainThread.h" | 44 #include "wtf/MainThread.h" |
| 45 #include "wtf/RawPtr.h" | 45 #include "wtf/RawPtr.h" |
| 46 #include "wtf/RefCounted.h" | 46 #include "wtf/RefCounted.h" |
| 47 #include "wtf/TypeTraits.h" | 47 #include "wtf/TypeTraits.h" |
| 48 | 48 |
| 49 #if defined(LEAK_SANITIZER) |
| 50 #include "wtf/LeakAnnotations.h" |
| 51 #endif |
| 52 |
| 49 namespace blink { | 53 namespace blink { |
| 50 | 54 |
| 51 enum WeaknessPersistentConfiguration { | 55 enum WeaknessPersistentConfiguration { |
| 52 NonWeakPersistentConfiguration, | 56 NonWeakPersistentConfiguration, |
| 53 WeakPersistentConfiguration | 57 WeakPersistentConfiguration |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 enum CrossThreadnessPersistentConfiguration { | 60 enum CrossThreadnessPersistentConfiguration { |
| 57 SingleThreadPersistentConfiguration, | 61 SingleThreadPersistentConfiguration, |
| 58 CrossThreadPersistentConfiguration | 62 CrossThreadPersistentConfiguration |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return *this; | 180 return *this; |
| 177 } | 181 } |
| 178 | 182 |
| 179 template<typename U> | 183 template<typename U> |
| 180 PersistentBase& operator=(const RawPtr<U>& other) | 184 PersistentBase& operator=(const RawPtr<U>& other) |
| 181 { | 185 { |
| 182 assign(other); | 186 assign(other); |
| 183 return *this; | 187 return *this; |
| 184 } | 188 } |
| 185 | 189 |
| 190 #if defined(LEAK_SANITIZER) |
| 191 PersistentBase* registerAsStaticReference() |
| 192 { |
| 193 if (m_persistentNode) { |
| 194 ASSERT(ThreadState::current()); |
| 195 ThreadState::current()->registerStaticPersistentNode(m_persistentNod
e); |
| 196 LEAK_SANITIZER_IGNORE_OBJECT(this); |
| 197 } |
| 198 return this; |
| 199 } |
| 200 #endif |
| 186 | 201 |
| 187 private: | 202 private: |
| 188 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 203 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 189 void assign(T* ptr) | 204 void assign(T* ptr) |
| 190 { | 205 { |
| 191 m_raw = ptr; | 206 m_raw = ptr; |
| 192 checkPointer(); | 207 checkPointer(); |
| 193 if (m_raw) { | 208 if (m_raw) { |
| 194 if (!m_persistentNode) | 209 if (!m_persistentNode) |
| 195 initialize(); | 210 initialize(); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 uninitialize(); | 553 uninitialize(); |
| 539 } | 554 } |
| 540 | 555 |
| 541 template<typename VisitorDispatcher> | 556 template<typename VisitorDispatcher> |
| 542 void trace(VisitorDispatcher visitor) | 557 void trace(VisitorDispatcher visitor) |
| 543 { | 558 { |
| 544 static_assert(sizeof(Collection), "Collection must be fully defined"); | 559 static_assert(sizeof(Collection), "Collection must be fully defined"); |
| 545 visitor->trace(*static_cast<Collection*>(this)); | 560 visitor->trace(*static_cast<Collection*>(this)); |
| 546 } | 561 } |
| 547 | 562 |
| 563 #if defined(LEAK_SANITIZER) |
| 564 PersistentHeapCollectionBase* registerAsStaticReference() |
| 565 { |
| 566 if (m_persistentNode) { |
| 567 ASSERT(ThreadState::current()); |
| 568 ThreadState::current()->registerStaticPersistentNode(m_persistentNod
e); |
| 569 LEAK_SANITIZER_IGNORE_OBJECT(this); |
| 570 } |
| 571 return this; |
| 572 } |
| 573 #endif |
| 574 |
| 548 private: | 575 private: |
| 576 |
| 549 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 577 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 550 void initialize() | 578 void initialize() |
| 551 { | 579 { |
| 552 // FIXME: Derive affinity based on the collection. | 580 // FIXME: Derive affinity based on the collection. |
| 553 ThreadState* state = ThreadState::current(); | 581 ThreadState* state = ThreadState::current(); |
| 554 ASSERT(state->checkThread()); | 582 ASSERT(state->checkThread()); |
| 555 m_persistentNode = state->persistentRegion()->allocatePersistentNode(thi
s, TraceMethodDelegate<PersistentHeapCollectionBase<Collection>, &PersistentHeap
CollectionBase<Collection>::trace>::trampoline); | 583 m_persistentNode = state->persistentRegion()->allocatePersistentNode(thi
s, TraceMethodDelegate<PersistentHeapCollectionBase<Collection>, &PersistentHeap
CollectionBase<Collection>::trace>::trampoline); |
| 556 #if ENABLE(ASSERT) | 584 #if ENABLE(ASSERT) |
| 557 m_state = state; | 585 m_state = state; |
| 558 #endif | 586 #endif |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 static_assert(isGarbageCollected, "T needs to be a garbage collected type.")
; | 1087 static_assert(isGarbageCollected, "T needs to be a garbage collected type.")
; |
| 1060 return ptr; | 1088 return ptr; |
| 1061 } | 1089 } |
| 1062 | 1090 |
| 1063 #define USING_FAST_MALLOC_WILL_BE_REMOVED(type) // do nothing when oilpan is ena
bled. | 1091 #define USING_FAST_MALLOC_WILL_BE_REMOVED(type) // do nothing when oilpan is ena
bled. |
| 1064 #define USING_FAST_MALLOC_WITH_TYPE_NAME_WILL_BE_REMOVED(type) | 1092 #define USING_FAST_MALLOC_WITH_TYPE_NAME_WILL_BE_REMOVED(type) |
| 1065 #define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing | 1093 #define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing |
| 1066 #define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing | 1094 #define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing |
| 1067 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing | 1095 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing |
| 1068 | 1096 |
| 1097 #if defined(LEAK_SANITIZER) |
| 1069 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ | 1098 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ |
| 1070 static type* name = (new Persistent<type>(arguments))->get(); | 1099 static type* name = *(new Persistent<type>(arguments))->registerAsStaticRefe
rence() |
| 1100 #else |
| 1101 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ |
| 1102 static type* name = *(new Persistent<type>(arguments)) |
| 1103 #endif |
| 1071 | 1104 |
| 1072 #else // !ENABLE(OILPAN) | 1105 #else // !ENABLE(OILPAN) |
| 1073 | 1106 |
| 1074 #define PassRefPtrWillBeRawPtr WTF::PassRefPtr | 1107 #define PassRefPtrWillBeRawPtr WTF::PassRefPtr |
| 1075 #define RefCountedWillBeGarbageCollected WTF::RefCounted | 1108 #define RefCountedWillBeGarbageCollected WTF::RefCounted |
| 1076 #define RefCountedWillBeGarbageCollectedFinalized WTF::RefCounted | 1109 #define RefCountedWillBeGarbageCollectedFinalized WTF::RefCounted |
| 1077 #define RefCountedWillBeRefCountedGarbageCollected WTF::RefCounted | 1110 #define RefCountedWillBeRefCountedGarbageCollected WTF::RefCounted |
| 1078 #define RefCountedGarbageCollectedWillBeGarbageCollectedFinalized blink::RefCoun
tedGarbageCollected | 1111 #define RefCountedGarbageCollectedWillBeGarbageCollectedFinalized blink::RefCoun
tedGarbageCollected |
| 1079 #define RefCountedWillBeNoBase WTF::RefCounted | 1112 #define RefCountedWillBeNoBase WTF::RefCounted |
| 1080 #define RefCountedGarbageCollectedWillBeNoBase blink::RefCountedGarbageCollected | 1113 #define RefCountedGarbageCollectedWillBeNoBase blink::RefCountedGarbageCollected |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 template<typename T> | 1292 template<typename T> |
| 1260 class AllowCrossThreadWeakPersistent { | 1293 class AllowCrossThreadWeakPersistent { |
| 1261 STACK_ALLOCATED(); | 1294 STACK_ALLOCATED(); |
| 1262 public: | 1295 public: |
| 1263 explicit AllowCrossThreadWeakPersistent(T* value) : m_value(value) { } | 1296 explicit AllowCrossThreadWeakPersistent(T* value) : m_value(value) { } |
| 1264 CrossThreadWeakPersistent<T> value() const { return m_value; } | 1297 CrossThreadWeakPersistent<T> value() const { return m_value; } |
| 1265 private: | 1298 private: |
| 1266 CrossThreadWeakPersistent<T> m_value; | 1299 CrossThreadWeakPersistent<T> m_value; |
| 1267 }; | 1300 }; |
| 1268 | 1301 |
| 1302 // LEAK_SANITIZER_DISABLED_SCOPE: all allocations made in the current scope |
| 1303 // will be exempted from LSan consideration. |
| 1304 // |
| 1305 // TODO(sof): move this to wtf/LeakAnnotations.h (LeakSanitizer.h?) once |
| 1306 // wtf/ can freely call upon Oilpan functionality. |
| 1307 #if defined(LEAK_SANITIZER) |
| 1308 class LeakSanitizerDisableScope { |
| 1309 STACK_ALLOCATED(); |
| 1310 WTF_MAKE_NONCOPYABLE(LeakSanitizerDisableScope); |
| 1311 public: |
| 1312 LeakSanitizerDisableScope() |
| 1313 { |
| 1314 __lsan_disable(); |
| 1315 if (ThreadState::current()) |
| 1316 ThreadState::current()->enterStaticReferenceRegistrationDisabledScop
e(); |
| 1317 } |
| 1318 |
| 1319 ~LeakSanitizerDisableScope() |
| 1320 { |
| 1321 __lsan_enable(); |
| 1322 if (ThreadState::current()) |
| 1323 ThreadState::current()->leaveStaticReferenceRegistrationDisabledScop
e(); |
| 1324 } |
| 1325 }; |
| 1326 #define LEAK_SANITIZER_DISABLED_SCOPE LeakSanitizerDisableScope lsanDisabledScop
e |
| 1327 #else |
| 1328 #define LEAK_SANITIZER_DISABLED_SCOPE |
| 1329 #endif |
| 1330 |
| 1269 } // namespace blink | 1331 } // namespace blink |
| 1270 | 1332 |
| 1271 namespace WTF { | 1333 namespace WTF { |
| 1272 | 1334 |
| 1273 template <typename T> struct VectorTraits<blink::Member<T>> : VectorTraitsBase<b
link::Member<T>> { | 1335 template <typename T> struct VectorTraits<blink::Member<T>> : VectorTraitsBase<b
link::Member<T>> { |
| 1274 static const bool needsDestruction = false; | 1336 static const bool needsDestruction = false; |
| 1275 static const bool canInitializeWithMemset = true; | 1337 static const bool canInitializeWithMemset = true; |
| 1276 static const bool canClearUnusedSlotsWithMemset = true; | 1338 static const bool canClearUnusedSlotsWithMemset = true; |
| 1277 static const bool canMoveWithMemcpy = true; | 1339 static const bool canMoveWithMemcpy = true; |
| 1278 }; | 1340 }; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. | 1569 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. |
| 1508 static T* unwrap(const StorageType& value) { return value.get(); } | 1570 static T* unwrap(const StorageType& value) { return value.get(); } |
| 1509 }; | 1571 }; |
| 1510 | 1572 |
| 1511 template<typename T> | 1573 template<typename T> |
| 1512 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1574 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
| 1513 | 1575 |
| 1514 } // namespace WTF | 1576 } // namespace WTF |
| 1515 | 1577 |
| 1516 #endif | 1578 #endif |
| OLD | NEW |