| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 21 matching lines...) Expand all Loading... |
| 32 #define Visitor_h | 32 #define Visitor_h |
| 33 | 33 |
| 34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
| 35 #include "platform/heap/ThreadState.h" | 35 #include "platform/heap/ThreadState.h" |
| 36 #include "wtf/Assertions.h" | 36 #include "wtf/Assertions.h" |
| 37 #include "wtf/Deque.h" | 37 #include "wtf/Deque.h" |
| 38 #include "wtf/Forward.h" | 38 #include "wtf/Forward.h" |
| 39 #include "wtf/HashMap.h" | 39 #include "wtf/HashMap.h" |
| 40 #include "wtf/HashSet.h" | 40 #include "wtf/HashSet.h" |
| 41 #include "wtf/HashTraits.h" | 41 #include "wtf/HashTraits.h" |
| 42 #include "wtf/LinkedHashSet.h" |
| 42 #include "wtf/ListHashSet.h" | 43 #include "wtf/ListHashSet.h" |
| 43 #include "wtf/OwnPtr.h" | 44 #include "wtf/OwnPtr.h" |
| 44 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
| 45 #include "wtf/TypeTraits.h" | 46 #include "wtf/TypeTraits.h" |
| 46 | 47 |
| 47 #ifndef NDEBUG | 48 #ifndef NDEBUG |
| 48 #define DEBUG_ONLY(x) x | 49 #define DEBUG_ONLY(x) x |
| 49 #else | 50 #else |
| 50 #define DEBUG_ONLY(x) | 51 #define DEBUG_ONLY(x) |
| 51 #endif | 52 #endif |
| 52 | 53 |
| 53 namespace WebCore { | 54 namespace WebCore { |
| 54 | 55 |
| 55 class FinalizedHeapObjectHeader; | 56 class FinalizedHeapObjectHeader; |
| 56 template<typename T> class GarbageCollectedFinalized; | 57 template<typename T> class GarbageCollectedFinalized; |
| 57 class HeapObjectHeader; | 58 class HeapObjectHeader; |
| 58 template<typename T> class Member; | 59 template<typename T> class Member; |
| 59 template<typename T> class WeakMember; | 60 template<typename T> class WeakMember; |
| 60 class Visitor; | 61 class Visitor; |
| 61 | 62 |
| 62 template<bool needsTracing, bool isWeak, bool markWeakMembersStrongly, typename
T, typename Traits> struct CollectionBackingTraceTrait; | 63 enum ShouldWeakPointersBeMarkedStrongly { |
| 64 WeakPointersActStrong, |
| 65 WeakPointersActWeak |
| 66 }; |
| 67 |
| 68 template<bool needsTracing, bool isWeak, ShouldWeakPointersBeMarkedStrongly stro
ngify, typename T, typename Traits> struct CollectionBackingTraceTrait; |
| 63 | 69 |
| 64 // The TraceMethodDelegate is used to convert a trace method for type T to a Tra
ceCallback. | 70 // The TraceMethodDelegate is used to convert a trace method for type T to a Tra
ceCallback. |
| 65 // This allows us to pass a type's trace method as a parameter to the Persistent
Node | 71 // This allows us to pass a type's trace method as a parameter to the Persistent
Node |
| 66 // constructor. The PersistentNode constructor needs the specific trace method d
ue an issue | 72 // constructor. The PersistentNode constructor needs the specific trace method d
ue an issue |
| 67 // with the Windows compiler which instantiates even unused variables. This caus
es problems | 73 // with the Windows compiler which instantiates even unused variables. This caus
es problems |
| 68 // in header files where we have only forward declarations of classes. | 74 // in header files where we have only forward declarations of classes. |
| 69 template<typename T, void (T::*method)(Visitor*)> | 75 template<typename T, void (T::*method)(Visitor*)> |
| 70 struct TraceMethodDelegate { | 76 struct TraceMethodDelegate { |
| 71 static void trampoline(Visitor* visitor, void* self) { (reinterpret_cast<T*>
(self)->*method)(visitor); } | 77 static void trampoline(Visitor* visitor, void* self) { (reinterpret_cast<T*>
(self)->*method)(visitor); } |
| 72 }; | 78 }; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 { | 261 { |
| 256 OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::t
race(this, hashSet); | 262 OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::t
race(this, hashSet); |
| 257 } | 263 } |
| 258 | 264 |
| 259 template<typename T, size_t inlineCapacity, typename U> | 265 template<typename T, size_t inlineCapacity, typename U> |
| 260 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) | 266 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) |
| 261 { | 267 { |
| 262 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t
his, hashSet); | 268 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t
his, hashSet); |
| 263 } | 269 } |
| 264 | 270 |
| 271 template<typename T, typename U> |
| 272 void trace(const LinkedHashSet<T, U>& hashSet) |
| 273 { |
| 274 OffHeapCollectionTraceTrait<LinkedHashSet<T, U> >::trace(this, hashSet); |
| 275 } |
| 276 |
| 265 template<typename T, size_t N> | 277 template<typename T, size_t N> |
| 266 void trace(const Deque<T, N>& deque) | 278 void trace(const Deque<T, N>& deque) |
| 267 { | 279 { |
| 268 OffHeapCollectionTraceTrait<Deque<T, N> >::trace(this, deque); | 280 OffHeapCollectionTraceTrait<Deque<T, N> >::trace(this, deque); |
| 269 } | 281 } |
| 270 | 282 |
| 271 template<typename T, typename U, typename V, typename W, typename X> | 283 template<typename T, typename U, typename V, typename W, typename X> |
| 272 void trace(const HashMap<T, U, V, W, X, WTF::DefaultAllocator>& map) | 284 void trace(const HashMap<T, U, V, W, X, WTF::DefaultAllocator>& map) |
| 273 { | 285 { |
| 274 OffHeapCollectionTraceTrait<HashMap<T, U, V, W, X, WTF::DefaultAllocator
> >::trace(this, map); | 286 OffHeapCollectionTraceTrait<HashMap<T, U, V, W, X, WTF::DefaultAllocator
> >::trace(this, map); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D
efaultAllocator> > { | 412 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D
efaultAllocator> > { |
| 401 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe
t; | 413 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe
t; |
| 402 | 414 |
| 403 static void trace(Visitor* visitor, const HashSet& set) | 415 static void trace(Visitor* visitor, const HashSet& set) |
| 404 { | 416 { |
| 405 if (set.isEmpty()) | 417 if (set.isEmpty()) |
| 406 return; | 418 return; |
| 407 if (WTF::ShouldBeTraced<Traits>::value) { | 419 if (WTF::ShouldBeTraced<Traits>::value) { |
| 408 HashSet& iterSet = const_cast<HashSet&>(set); | 420 HashSet& iterSet = const_cast<HashSet&>(set); |
| 409 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) | 421 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) |
| 410 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value,
Traits::isWeak, false, T, Traits>::mark(visitor, *it); | 422 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value,
Traits::isWeak, WeakPointersActWeak, T, Traits>::mark(visitor, *it); |
| 411 } | 423 } |
| 412 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou
s0); | 424 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou
s0); |
| 413 } | 425 } |
| 414 }; | 426 }; |
| 415 | 427 |
| 416 template<typename T, size_t inlineCapacity, typename HashFunctions> | 428 template<typename T, size_t inlineCapacity, typename HashFunctions> |
| 417 struct OffHeapCollectionTraceTrait<WTF::ListHashSet<T, inlineCapacity, HashFunct
ions> > { | 429 struct OffHeapCollectionTraceTrait<WTF::ListHashSet<T, inlineCapacity, HashFunct
ions> > { |
| 418 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; | 430 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; |
| 419 | 431 |
| 420 static void trace(Visitor* visitor, const ListHashSet& set) | 432 static void trace(Visitor* visitor, const ListHashSet& set) |
| 421 { | 433 { |
| 422 if (set.isEmpty()) | 434 if (set.isEmpty()) |
| 423 return; | 435 return; |
| 424 ListHashSet& iterSet = const_cast<ListHashSet&>(set); | 436 ListHashSet& iterSet = const_cast<ListHashSet&>(set); |
| 425 for (typename ListHashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) | 437 for (typename ListHashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) |
| 426 visitor->trace(*it); | 438 visitor->trace(*it); |
| 427 } | 439 } |
| 428 }; | 440 }; |
| 429 | 441 |
| 442 template<typename T, typename HashFunctions> |
| 443 struct OffHeapCollectionTraceTrait<WTF::LinkedHashSet<T, HashFunctions> > { |
| 444 typedef WTF::LinkedHashSet<T, HashFunctions> LinkedHashSet; |
| 445 |
| 446 static void trace(Visitor* visitor, const LinkedHashSet& set) |
| 447 { |
| 448 if (set.isEmpty()) |
| 449 return; |
| 450 LinkedHashSet& iterSet = const_cast<LinkedHashSet&>(set); |
| 451 for (typename LinkedHashSet::iterator it = iterSet.begin(), end = iterSe
t.end(); it != end; ++it) |
| 452 visitor->trace(*it); |
| 453 } |
| 454 }; |
| 455 |
| 430 template<typename Key, typename Value, typename HashFunctions, typename KeyTrait
s, typename ValueTraits> | 456 template<typename Key, typename Value, typename HashFunctions, typename KeyTrait
s, typename ValueTraits> |
| 431 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
aits, ValueTraits, WTF::DefaultAllocator> > { | 457 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
aits, ValueTraits, WTF::DefaultAllocator> > { |
| 432 typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF:
:DefaultAllocator> HashMap; | 458 typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF:
:DefaultAllocator> HashMap; |
| 433 | 459 |
| 434 static void trace(Visitor* visitor, const HashMap& map) | 460 static void trace(Visitor* visitor, const HashMap& map) |
| 435 { | 461 { |
| 436 if (map.isEmpty()) | 462 if (map.isEmpty()) |
| 437 return; | 463 return; |
| 438 if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTr
aits>::value) { | 464 if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTr
aits>::value) { |
| 439 HashMap& iterMap = const_cast<HashMap&>(map); | 465 HashMap& iterMap = const_cast<HashMap&>(map); |
| 440 for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.
end(); it != end; ++it) { | 466 for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.
end(); it != end; ++it) { |
| 441 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::valu
e, KeyTraits::isWeak, false, Key, KeyTraits>::mark(visitor, it->key); | 467 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::valu
e, KeyTraits::isWeak, WeakPointersActWeak, Key, KeyTraits>::mark(visitor, it->ke
y); |
| 442 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::va
lue, ValueTraits::isWeak, false, Value, ValueTraits>::mark(visitor, it->value); | 468 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::va
lue, ValueTraits::isWeak, WeakPointersActWeak, Value, ValueTraits>::mark(visitor
, it->value); |
| 443 } | 469 } |
| 444 } | 470 } |
| 445 COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDange
rous1); | 471 COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDange
rous1); |
| 446 COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDan
gerous2); | 472 COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDan
gerous2); |
| 447 } | 473 } |
| 448 }; | 474 }; |
| 449 | 475 |
| 450 // We trace vectors by using the trace trait on each element, which means you | 476 // We trace vectors by using the trace trait on each element, which means you |
| 451 // can have vectors of general objects (not just pointers to objects) that can | 477 // can have vectors of general objects (not just pointers to objects) that can |
| 452 // be traced. | 478 // be traced. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 struct GCInfoTrait { | 645 struct GCInfoTrait { |
| 620 static const GCInfo* get() | 646 static const GCInfo* get() |
| 621 { | 647 { |
| 622 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 648 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
| 623 } | 649 } |
| 624 }; | 650 }; |
| 625 | 651 |
| 626 } | 652 } |
| 627 | 653 |
| 628 #endif | 654 #endif |
| OLD | NEW |