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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 } | 229 } |
230 | 230 |
231 // Member version of the one-argument templated trace method. | 231 // Member version of the one-argument templated trace method. |
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 template<typename T> | |
240 void trace(Member<T>& t) | |
haraken
2014/06/06 08:03:02
Just help me understand: Why do we have both const
Erik Corry
2014/06/06 08:47:35
We have to have a const and non-const version for
| |
241 { | |
242 t.verifyTypeIsGarbageCollected(); | |
243 mark(t.get()); | |
244 } | |
245 | |
239 // Fallback method used only when we need to trace raw pointers of T. | 246 // 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 . | 247 // This is the case when a member is a union where we do not support members . |
241 template<typename T> | 248 template<typename T> |
249 void trace(const T* t) | |
250 { | |
251 mark(const_cast<T*>(t)); | |
252 } | |
253 | |
254 template<typename T> | |
242 void trace(T* t) | 255 void trace(T* t) |
243 { | 256 { |
244 mark(t); | 257 mark(t); |
245 } | 258 } |
246 | 259 |
247 // WeakMember version of the templated trace method. It doesn't keep | 260 // WeakMember version of the templated trace method. It doesn't keep |
248 // the traced thing alive, but will write null to the WeakMember later | 261 // the traced thing alive, but will write null to the WeakMember later |
249 // if the pointed-to object is dead. | 262 // if the pointed-to object is dead. It's lying for this to be const, |
263 // but the overloading resolver prioritizes constness too high when | |
264 // picking the correct overload, so all these trace methods have to have | |
265 // the same constness on their argument to allow the type to decide. | |
haraken
2014/06/06 08:03:02
I agree that we need a const version of trace(cons
Erik Corry
2014/06/06 08:47:35
If you have only const methods to choose between t
| |
250 template<typename T> | 266 template<typename T> |
251 void trace(const WeakMember<T>& t) | 267 void trace(const WeakMember<T>& t) |
252 { | 268 { |
253 registerWeakCell(t.cell()); | 269 registerWeakCell(const_cast<WeakMember<T>&>(t).cell()); |
254 } | 270 } |
255 | 271 |
256 // Fallback trace method for part objects to allow individual | 272 template<typename T> |
257 // trace methods to trace through a part object with | 273 void traceInCollection(T& t, ShouldWeakPointersBeMarkedStrongly strongify) |
258 // visitor->trace(m_partObject). | 274 { |
275 HashTraits<T>::traceInCollection(this, t, strongify); | |
276 } | |
277 | |
278 // Fallback trace method for part objects to allow individual trace methods | |
279 // to trace through a part object with visitor->trace(m_partObject). This | |
280 // takes a const argument, because otherwise it will match too eagerly: a | |
281 // non-const argument would match a non-const Vector<T>& argument better | |
282 // than the specialization that takes const Vector<T>&. For a similar reason , | |
283 // the other specializations take a const argument even though they are | |
284 // usually used with non-const arguments, otherwise this function would matc h | |
285 // too well. | |
259 template<typename T> | 286 template<typename T> |
260 void trace(const T& t) | 287 void trace(const T& t) |
261 { | 288 { |
262 const_cast<T&>(t).trace(this); | 289 const_cast<T&>(t).trace(this); |
263 } | 290 } |
264 | 291 |
265 // The following trace methods are for off-heap collections. | 292 // The following trace methods are for off-heap collections. |
266 template<typename T, size_t inlineCapacity> | 293 template<typename T, size_t inlineCapacity> |
267 void trace(const Vector<T, inlineCapacity, WTF::DefaultAllocator>& vector) | 294 void trace(const Vector<T, inlineCapacity>& vector) |
268 { | 295 { |
269 OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAlloca tor> >::trace(this, vector); | 296 OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAlloca tor> >::trace(this, vector); |
270 } | 297 } |
271 | 298 |
272 template<typename T, typename U, typename V> | 299 template<typename T, typename U, typename V> |
273 void trace(const HashSet<T, U, V, WTF::DefaultAllocator>& hashSet) | 300 void trace(const HashSet<T, U, V>& hashSet) |
274 { | 301 { |
275 OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::t race(this, hashSet); | 302 OffHeapCollectionTraceTrait<HashSet<T, U, V> >::trace(this, hashSet); |
276 } | 303 } |
277 | 304 |
278 template<typename T, size_t inlineCapacity, typename U> | 305 template<typename T, size_t inlineCapacity, typename U> |
279 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) | 306 void trace(const ListHashSet<T, inlineCapacity, U>& hashSet) |
280 { | 307 { |
281 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t his, hashSet); | 308 OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(t his, hashSet); |
282 } | 309 } |
283 | 310 |
284 template<typename T, typename U> | 311 template<typename T, typename U> |
285 void trace(const LinkedHashSet<T, U>& hashSet) | 312 void trace(const LinkedHashSet<T, U>& hashSet) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 // Remove this once we remove WeakPtrWillBeMember. | 368 // Remove this once we remove WeakPtrWillBeMember. |
342 template<typename T> | 369 template<typename T> |
343 void trace(const WeakPtr<T>&) | 370 void trace(const WeakPtr<T>&) |
344 { | 371 { |
345 #if ENABLE(OILPAN) | 372 #if ENABLE(OILPAN) |
346 // WeakPtrs should never be traced. | 373 // WeakPtrs should never be traced. |
347 ASSERT_NOT_REACHED(); | 374 ASSERT_NOT_REACHED(); |
348 #endif | 375 #endif |
349 } | 376 } |
350 | 377 |
378 template<typename T> | |
379 void trace(WeakPtr<T>&) | |
380 { | |
381 #if ENABLE(OILPAN) | |
382 // WeakPtrs should never be traced. | |
383 ASSERT_NOT_REACHED(); | |
384 #endif | |
385 } | |
386 | |
351 // This method marks an object and adds it to the set of objects | 387 // This method marks an object and adds it to the set of objects |
352 // that should have their trace method called. Since not all | 388 // that should have their trace method called. Since not all |
353 // objects have vtables we have to have the callback as an | 389 // objects have vtables we have to have the callback as an |
354 // explicit argument, but we can use the templated one-argument | 390 // explicit argument, but we can use the templated one-argument |
355 // mark method above to automatically provide the callback | 391 // mark method above to automatically provide the callback |
356 // function. | 392 // function. |
357 virtual void mark(const void*, TraceCallback) = 0; | 393 virtual void mark(const void*, TraceCallback) = 0; |
358 virtual void markNoTracing(const void* pointer) { mark(pointer, reinterpret_ cast<TraceCallback>(0)); } | 394 virtual void markNoTracing(const void* pointer) { mark(pointer, reinterpret_ cast<TraceCallback>(0)); } |
359 | 395 |
360 // Used to mark objects during conservative scanning. | 396 // Used to mark objects during conservative scanning. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 template<typename T, typename HashFunctions, typename Traits> | 497 template<typename T, typename HashFunctions, typename Traits> |
462 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D efaultAllocator> > { | 498 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D efaultAllocator> > { |
463 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe t; | 499 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe t; |
464 | 500 |
465 static void trace(Visitor* visitor, const HashSet& set) | 501 static void trace(Visitor* visitor, const HashSet& set) |
466 { | 502 { |
467 if (set.isEmpty()) | 503 if (set.isEmpty()) |
468 return; | 504 return; |
469 if (WTF::ShouldBeTraced<Traits>::value) { | 505 if (WTF::ShouldBeTraced<Traits>::value) { |
470 HashSet& iterSet = const_cast<HashSet&>(set); | 506 HashSet& iterSet = const_cast<HashSet&>(set); |
471 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet. end(); it != end; ++it) | 507 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); | 508 const T& t = *it; |
509 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits::isWeak, WeakPointersActWeak, T, Traits>::trace(visitor, const_cast<T&>(t )); | |
510 } | |
473 } | 511 } |
474 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou s0); | 512 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou s0); |
475 } | 513 } |
476 }; | 514 }; |
477 | 515 |
478 template<typename T, size_t inlineCapacity, typename HashFunctions> | 516 template<typename T, size_t inlineCapacity, typename HashFunctions> |
479 struct OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, HashFunctions> > { | 517 struct OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, HashFunctions> > { |
480 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; | 518 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; |
481 | 519 |
482 static void trace(Visitor* visitor, const ListHashSet& set) | 520 static void trace(Visitor* visitor, const ListHashSet& set) |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 struct GCInfoTrait { | 762 struct GCInfoTrait { |
725 static const GCInfo* get() | 763 static const GCInfo* get() |
726 { | 764 { |
727 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 765 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
728 } | 766 } |
729 }; | 767 }; |
730 | 768 |
731 } | 769 } |
732 | 770 |
733 #endif | 771 #endif |
OLD | NEW |