| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 { | 269 { |
| 264 OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::t
race(this, hashSet); | 270 OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::t
race(this, hashSet); |
| 265 } | 271 } |
| 266 | 272 |
| 267 template<typename T, size_t inlineCapacity, typename U> | 273 template<typename T, size_t inlineCapacity, typename U> |
| 268 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) | 274 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) |
| 269 { | 275 { |
| 270 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t
his, hashSet); | 276 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t
his, hashSet); |
| 271 } | 277 } |
| 272 | 278 |
| 279 template<typename T, typename U> |
| 280 void trace(const LinkedHashSet<T, U>& hashSet) |
| 281 { |
| 282 OffHeapCollectionTraceTrait<LinkedHashSet<T, U> >::trace(this, hashSet); |
| 283 } |
| 284 |
| 273 template<typename T, size_t N> | 285 template<typename T, size_t N> |
| 274 void trace(const Deque<T, N>& deque) | 286 void trace(const Deque<T, N>& deque) |
| 275 { | 287 { |
| 276 OffHeapCollectionTraceTrait<Deque<T, N> >::trace(this, deque); | 288 OffHeapCollectionTraceTrait<Deque<T, N> >::trace(this, deque); |
| 277 } | 289 } |
| 278 | 290 |
| 279 template<typename T, typename U, typename V, typename W, typename X> | 291 template<typename T, typename U, typename V, typename W, typename X> |
| 280 void trace(const HashMap<T, U, V, W, X, WTF::DefaultAllocator>& map) | 292 void trace(const HashMap<T, U, V, W, X, WTF::DefaultAllocator>& map) |
| 281 { | 293 { |
| 282 OffHeapCollectionTraceTrait<HashMap<T, U, V, W, X, WTF::DefaultAllocator
> >::trace(this, map); | 294 OffHeapCollectionTraceTrait<HashMap<T, U, V, W, X, WTF::DefaultAllocator
> >::trace(this, map); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D
efaultAllocator> > { | 422 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D
efaultAllocator> > { |
| 411 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe
t; | 423 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe
t; |
| 412 | 424 |
| 413 static void trace(Visitor* visitor, const HashSet& set) | 425 static void trace(Visitor* visitor, const HashSet& set) |
| 414 { | 426 { |
| 415 if (set.isEmpty()) | 427 if (set.isEmpty()) |
| 416 return; | 428 return; |
| 417 if (WTF::ShouldBeTraced<Traits>::value) { | 429 if (WTF::ShouldBeTraced<Traits>::value) { |
| 418 HashSet& iterSet = const_cast<HashSet&>(set); | 430 HashSet& iterSet = const_cast<HashSet&>(set); |
| 419 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) | 431 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) |
| 420 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value,
Traits::isWeak, false, T, Traits>::mark(visitor, *it); | 432 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value,
Traits::isWeak, WeakPointersActWeak, T, Traits>::mark(visitor, *it); |
| 421 } | 433 } |
| 422 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou
s0); | 434 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou
s0); |
| 423 } | 435 } |
| 424 }; | 436 }; |
| 425 | 437 |
| 426 template<typename T, size_t inlineCapacity, typename HashFunctions> | 438 template<typename T, size_t inlineCapacity, typename HashFunctions> |
| 427 struct OffHeapCollectionTraceTrait<WTF::ListHashSet<T, inlineCapacity, HashFunct
ions> > { | 439 struct OffHeapCollectionTraceTrait<WTF::ListHashSet<T, inlineCapacity, HashFunct
ions> > { |
| 428 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; | 440 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; |
| 429 | 441 |
| 430 static void trace(Visitor* visitor, const ListHashSet& set) | 442 static void trace(Visitor* visitor, const ListHashSet& set) |
| 431 { | 443 { |
| 432 if (set.isEmpty()) | 444 if (set.isEmpty()) |
| 433 return; | 445 return; |
| 434 ListHashSet& iterSet = const_cast<ListHashSet&>(set); | 446 ListHashSet& iterSet = const_cast<ListHashSet&>(set); |
| 435 for (typename ListHashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) | 447 for (typename ListHashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) |
| 436 visitor->trace(*it); | 448 visitor->trace(*it); |
| 437 } | 449 } |
| 438 }; | 450 }; |
| 439 | 451 |
| 452 template<typename T, typename HashFunctions> |
| 453 struct OffHeapCollectionTraceTrait<WTF::LinkedHashSet<T, HashFunctions> > { |
| 454 typedef WTF::LinkedHashSet<T, HashFunctions> LinkedHashSet; |
| 455 |
| 456 static void trace(Visitor* visitor, const LinkedHashSet& set) |
| 457 { |
| 458 if (set.isEmpty()) |
| 459 return; |
| 460 LinkedHashSet& iterSet = const_cast<LinkedHashSet&>(set); |
| 461 for (typename LinkedHashSet::iterator it = iterSet.begin(), end = iterSe
t.end(); it != end; ++it) |
| 462 visitor->trace(*it); |
| 463 } |
| 464 }; |
| 465 |
| 440 template<typename Key, typename Value, typename HashFunctions, typename KeyTrait
s, typename ValueTraits> | 466 template<typename Key, typename Value, typename HashFunctions, typename KeyTrait
s, typename ValueTraits> |
| 441 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
aits, ValueTraits, WTF::DefaultAllocator> > { | 467 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
aits, ValueTraits, WTF::DefaultAllocator> > { |
| 442 typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF:
:DefaultAllocator> HashMap; | 468 typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF:
:DefaultAllocator> HashMap; |
| 443 | 469 |
| 444 static void trace(Visitor* visitor, const HashMap& map) | 470 static void trace(Visitor* visitor, const HashMap& map) |
| 445 { | 471 { |
| 446 if (map.isEmpty()) | 472 if (map.isEmpty()) |
| 447 return; | 473 return; |
| 448 if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTr
aits>::value) { | 474 if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTr
aits>::value) { |
| 449 HashMap& iterMap = const_cast<HashMap&>(map); | 475 HashMap& iterMap = const_cast<HashMap&>(map); |
| 450 for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.
end(); it != end; ++it) { | 476 for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.
end(); it != end; ++it) { |
| 451 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::valu
e, KeyTraits::isWeak, false, Key, KeyTraits>::mark(visitor, it->key); | 477 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::valu
e, KeyTraits::isWeak, WeakPointersActWeak, Key, KeyTraits>::mark(visitor, it->ke
y); |
| 452 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::va
lue, ValueTraits::isWeak, false, Value, ValueTraits>::mark(visitor, it->value); | 478 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::va
lue, ValueTraits::isWeak, WeakPointersActWeak, Value, ValueTraits>::mark(visitor
, it->value); |
| 453 } | 479 } |
| 454 } | 480 } |
| 455 COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDange
rous1); | 481 COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDange
rous1); |
| 456 COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDan
gerous2); | 482 COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDan
gerous2); |
| 457 } | 483 } |
| 458 }; | 484 }; |
| 459 | 485 |
| 460 // We trace vectors by using the trace trait on each element, which means you | 486 // We trace vectors by using the trace trait on each element, which means you |
| 461 // can have vectors of general objects (not just pointers to objects) that can | 487 // can have vectors of general objects (not just pointers to objects) that can |
| 462 // be traced. | 488 // be traced. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 struct GCInfoTrait { | 656 struct GCInfoTrait { |
| 631 static const GCInfo* get() | 657 static const GCInfo* get() |
| 632 { | 658 { |
| 633 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 659 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
| 634 } | 660 } |
| 635 }; | 661 }; |
| 636 | 662 |
| 637 } | 663 } |
| 638 | 664 |
| 639 #endif | 665 #endif |
| OLD | NEW |