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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 class HeapObjectHeader; | 64 class HeapObjectHeader; |
65 template<typename T> class Member; | 65 template<typename T> class Member; |
66 template<typename T> class WeakMember; | 66 template<typename T> class WeakMember; |
67 class Visitor; | 67 class Visitor; |
68 | 68 |
69 enum ShouldWeakPointersBeMarkedStrongly { | 69 enum ShouldWeakPointersBeMarkedStrongly { |
70 WeakPointersActStrong, | 70 WeakPointersActStrong, |
71 WeakPointersActWeak | 71 WeakPointersActWeak |
72 }; | 72 }; |
73 | 73 |
74 template<bool needsTracing, bool isWeak, ShouldWeakPointersBeMarkedStrongly stro
ngify, typename T, typename Traits> struct CollectionBackingTraceTrait; | 74 template<bool needsTracing, WTF::WeakHandlingFlag weakHandlingFlag, ShouldWeakPo
intersBeMarkedStrongly strongify, typename T, typename Traits> struct Collection
BackingTraceTrait; |
75 | 75 |
76 // The TraceMethodDelegate is used to convert a trace method for type T to a Tra
ceCallback. | 76 // The TraceMethodDelegate is used to convert a trace method for type T to a Tra
ceCallback. |
77 // This allows us to pass a type's trace method as a parameter to the Persistent
Node | 77 // This allows us to pass a type's trace method as a parameter to the Persistent
Node |
78 // constructor. The PersistentNode constructor needs the specific trace method d
ue an issue | 78 // constructor. The PersistentNode constructor needs the specific trace method d
ue an issue |
79 // with the Windows compiler which instantiates even unused variables. This caus
es problems | 79 // with the Windows compiler which instantiates even unused variables. This caus
es problems |
80 // in header files where we have only forward declarations of classes. | 80 // in header files where we have only forward declarations of classes. |
81 template<typename T, void (T::*method)(Visitor*)> | 81 template<typename T, void (T::*method)(Visitor*)> |
82 struct TraceMethodDelegate { | 82 struct TraceMethodDelegate { |
83 static void trampoline(Visitor* visitor, void* self) { (reinterpret_cast<T*>
(self)->*method)(visitor); } | 83 static void trampoline(Visitor* visitor, void* self) { (reinterpret_cast<T*>
(self)->*method)(visitor); } |
84 }; | 84 }; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 template<typename T> | 232 template<typename T> |
233 void trace(const Member<T>& t) | 233 void trace(const Member<T>& t) |
234 { | 234 { |
235 t.verifyTypeIsGarbageCollected(); | 235 t.verifyTypeIsGarbageCollected(); |
236 mark(t.get()); | 236 mark(t.get()); |
237 } | 237 } |
238 | 238 |
239 // Fallback method used only when we need to trace raw pointers of T. | 239 // Fallback method used only when we need to trace raw pointers of T. |
240 // This is the case when a member is a union where we do not support members
. | 240 // This is the case when a member is a union where we do not support members
. |
241 template<typename T> | 241 template<typename T> |
| 242 void trace(const T* t) |
| 243 { |
| 244 mark(const_cast<T*>(t)); |
| 245 } |
| 246 |
| 247 template<typename T> |
242 void trace(T* t) | 248 void trace(T* t) |
243 { | 249 { |
244 mark(t); | 250 mark(t); |
245 } | 251 } |
246 | 252 |
247 // WeakMember version of the templated trace method. It doesn't keep | 253 // WeakMember version of the templated trace method. It doesn't keep |
248 // the traced thing alive, but will write null to the WeakMember later | 254 // the traced thing alive, but will write null to the WeakMember later |
249 // if the pointed-to object is dead. | 255 // if the pointed-to object is dead. It's lying for this to be const, |
| 256 // but the overloading resolver prioritizes constness too high when |
| 257 // picking the correct overload, so all these trace methods have to have |
| 258 // the same constness on their argument to allow the type to decide. |
250 template<typename T> | 259 template<typename T> |
251 void trace(const WeakMember<T>& t) | 260 void trace(const WeakMember<T>& t) |
252 { | 261 { |
253 registerWeakCell(t.cell()); | 262 registerWeakCell(const_cast<WeakMember<T>&>(t).cell()); |
254 } | 263 } |
255 | 264 |
256 // Fallback trace method for part objects to allow individual | 265 template<typename T> |
257 // trace methods to trace through a part object with | 266 void traceInCollection(T& t, ShouldWeakPointersBeMarkedStrongly strongify) |
258 // visitor->trace(m_partObject). | 267 { |
| 268 HashTraits<T>::traceInCollection(this, t, strongify); |
| 269 } |
| 270 |
| 271 // Fallback trace method for part objects to allow individual trace methods |
| 272 // to trace through a part object with visitor->trace(m_partObject). This |
| 273 // takes a const argument, because otherwise it will match too eagerly: a |
| 274 // non-const argument would match a non-const Vector<T>& argument better |
| 275 // than the specialization that takes const Vector<T>&. For a similar reason
, |
| 276 // the other specializations take a const argument even though they are |
| 277 // usually used with non-const arguments, otherwise this function would matc
h |
| 278 // too well. |
259 template<typename T> | 279 template<typename T> |
260 void trace(const T& t) | 280 void trace(const T& t) |
261 { | 281 { |
262 const_cast<T&>(t).trace(this); | 282 const_cast<T&>(t).trace(this); |
263 } | 283 } |
264 | 284 |
265 // The following trace methods are for off-heap collections. | 285 // The following trace methods are for off-heap collections. |
266 template<typename T, size_t inlineCapacity> | 286 template<typename T, size_t inlineCapacity> |
267 void trace(const Vector<T, inlineCapacity, WTF::DefaultAllocator>& vector) | 287 void trace(const Vector<T, inlineCapacity>& vector) |
268 { | 288 { |
269 OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAlloca
tor> >::trace(this, vector); | 289 OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAlloca
tor> >::trace(this, vector); |
270 } | 290 } |
271 | 291 |
272 template<typename T, typename U, typename V> | 292 template<typename T, typename U, typename V> |
273 void trace(const HashSet<T, U, V, WTF::DefaultAllocator>& hashSet) | 293 void trace(const HashSet<T, U, V>& hashSet) |
274 { | 294 { |
275 OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::t
race(this, hashSet); | 295 OffHeapCollectionTraceTrait<HashSet<T, U, V> >::trace(this, hashSet); |
276 } | 296 } |
277 | 297 |
278 template<typename T, size_t inlineCapacity, typename U> | 298 template<typename T, size_t inlineCapacity, typename U> |
279 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) | 299 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) |
280 { | 300 { |
281 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t
his, hashSet); | 301 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t
his, hashSet); |
282 } | 302 } |
283 | 303 |
284 template<typename T, typename U> | 304 template<typename T, typename U> |
285 void trace(const LinkedHashSet<T, U>& hashSet) | 305 void trace(const LinkedHashSet<T, U>& hashSet) |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 template<typename T, typename HashFunctions, typename Traits> | 481 template<typename T, typename HashFunctions, typename Traits> |
462 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D
efaultAllocator> > { | 482 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D
efaultAllocator> > { |
463 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe
t; | 483 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe
t; |
464 | 484 |
465 static void trace(Visitor* visitor, const HashSet& set) | 485 static void trace(Visitor* visitor, const HashSet& set) |
466 { | 486 { |
467 if (set.isEmpty()) | 487 if (set.isEmpty()) |
468 return; | 488 return; |
469 if (WTF::ShouldBeTraced<Traits>::value) { | 489 if (WTF::ShouldBeTraced<Traits>::value) { |
470 HashSet& iterSet = const_cast<HashSet&>(set); | 490 HashSet& iterSet = const_cast<HashSet&>(set); |
471 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) | 491 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.
end(); it != end; ++it) { |
472 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value,
Traits::isWeak, WeakPointersActWeak, T, Traits>::trace(visitor, *it); | 492 const T& t = *it; |
| 493 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value,
Traits::weakHandlingFlag, WeakPointersActWeak, T, Traits>::trace(visitor, const_
cast<T&>(t)); |
| 494 } |
473 } | 495 } |
474 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou
s0); | 496 COMPILE_ASSERT(Traits::weakHandlingFlag == WTF::NoWeakHandlingInCollecti
ons, WeakOffHeapCollectionsConsideredDangerous0); |
475 } | 497 } |
476 }; | 498 }; |
477 | 499 |
478 template<typename T, size_t inlineCapacity, typename HashFunctions> | 500 template<typename T, size_t inlineCapacity, typename HashFunctions> |
479 struct OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, HashFunctions>
> { | 501 struct OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, HashFunctions>
> { |
480 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; | 502 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; |
481 | 503 |
482 static void trace(Visitor* visitor, const ListHashSet& set) | 504 static void trace(Visitor* visitor, const ListHashSet& set) |
483 { | 505 { |
484 if (set.isEmpty()) | 506 if (set.isEmpty()) |
(...skipping 22 matching lines...) Expand all Loading... |
507 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
aits, ValueTraits, WTF::DefaultAllocator> > { | 529 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
aits, ValueTraits, WTF::DefaultAllocator> > { |
508 typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF:
:DefaultAllocator> HashMap; | 530 typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF:
:DefaultAllocator> HashMap; |
509 | 531 |
510 static void trace(Visitor* visitor, const HashMap& map) | 532 static void trace(Visitor* visitor, const HashMap& map) |
511 { | 533 { |
512 if (map.isEmpty()) | 534 if (map.isEmpty()) |
513 return; | 535 return; |
514 if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTr
aits>::value) { | 536 if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTr
aits>::value) { |
515 HashMap& iterMap = const_cast<HashMap&>(map); | 537 HashMap& iterMap = const_cast<HashMap&>(map); |
516 for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.
end(); it != end; ++it) { | 538 for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.
end(); it != end; ++it) { |
517 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::valu
e, KeyTraits::isWeak, WeakPointersActWeak, typename HashMap::KeyType, KeyTraits>
::trace(visitor, it->key); | 539 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::valu
e, KeyTraits::weakHandlingFlag, WeakPointersActWeak, typename HashMap::KeyType,
KeyTraits>::trace(visitor, it->key); |
518 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::va
lue, ValueTraits::isWeak, WeakPointersActWeak, typename HashMap::MappedType, Val
ueTraits>::trace(visitor, it->value); | 540 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::va
lue, ValueTraits::weakHandlingFlag, WeakPointersActWeak, typename HashMap::Mappe
dType, ValueTraits>::trace(visitor, it->value); |
519 } | 541 } |
520 } | 542 } |
521 COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDange
rous1); | 543 COMPILE_ASSERT(KeyTraits::weakHandlingFlag == WTF::NoWeakHandlingInColle
ctions, WeakOffHeapCollectionsConsideredDangerous1); |
522 COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDan
gerous2); | 544 COMPILE_ASSERT(ValueTraits::weakHandlingFlag == WTF::NoWeakHandlingInCol
lections, WeakOffHeapCollectionsConsideredDangerous2); |
523 } | 545 } |
524 }; | 546 }; |
525 | 547 |
526 // We trace vectors by using the trace trait on each element, which means you | 548 // We trace vectors by using the trace trait on each element, which means you |
527 // can have vectors of general objects (not just pointers to objects) that can | 549 // can have vectors of general objects (not just pointers to objects) that can |
528 // be traced. | 550 // be traced. |
529 template<typename T, size_t N> | 551 template<typename T, size_t N> |
530 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { | 552 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { |
531 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; | 553 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; |
532 | 554 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 struct GCInfoTrait { | 746 struct GCInfoTrait { |
725 static const GCInfo* get() | 747 static const GCInfo* get() |
726 { | 748 { |
727 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 749 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
728 } | 750 } |
729 }; | 751 }; |
730 | 752 |
731 } | 753 } |
732 | 754 |
733 #endif | 755 #endif |
OLD | NEW |