Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: Source/platform/heap/Visitor.h

Issue 319593004: Oilpan:Allow custom handling of classes that contain weak pointers that are embedded in collections. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Feedback from Haraken Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Remove this once we remove WeakPtrWillBeMember. 361 // Remove this once we remove WeakPtrWillBeMember.
342 template<typename T> 362 template<typename T>
343 void trace(const WeakPtr<T>&) 363 void trace(const WeakPtr<T>&)
344 { 364 {
345 #if ENABLE(OILPAN) 365 #if ENABLE(OILPAN)
346 // WeakPtrs should never be traced. 366 // WeakPtrs should never be traced.
347 ASSERT_NOT_REACHED(); 367 ASSERT_NOT_REACHED();
348 #endif 368 #endif
349 } 369 }
350 370
371 template<typename T>
372 void trace(WeakPtr<T>&)
Mads Ager (chromium) 2014/06/06 09:59:17 Where do you need this? This doesn't really look l
Erik Corry 2014/06/10 11:21:18 Removed.
373 {
374 #if ENABLE(OILPAN)
375 // WeakPtrs should never be traced.
376 ASSERT_NOT_REACHED();
377 #endif
378 }
379
351 // This method marks an object and adds it to the set of objects 380 // This method marks an object and adds it to the set of objects
352 // that should have their trace method called. Since not all 381 // that should have their trace method called. Since not all
353 // objects have vtables we have to have the callback as an 382 // objects have vtables we have to have the callback as an
354 // explicit argument, but we can use the templated one-argument 383 // explicit argument, but we can use the templated one-argument
355 // mark method above to automatically provide the callback 384 // mark method above to automatically provide the callback
356 // function. 385 // function.
357 virtual void mark(const void*, TraceCallback) = 0; 386 virtual void mark(const void*, TraceCallback) = 0;
358 virtual void markNoTracing(const void* pointer) { mark(pointer, reinterpret_ cast<TraceCallback>(0)); } 387 virtual void markNoTracing(const void* pointer) { mark(pointer, reinterpret_ cast<TraceCallback>(0)); }
359 388
360 // Used to mark objects during conservative scanning. 389 // Used to mark objects during conservative scanning.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 template<typename T, typename HashFunctions, typename Traits> 490 template<typename T, typename HashFunctions, typename Traits>
462 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D efaultAllocator> > { 491 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D efaultAllocator> > {
463 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe t; 492 typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSe t;
464 493
465 static void trace(Visitor* visitor, const HashSet& set) 494 static void trace(Visitor* visitor, const HashSet& set)
466 { 495 {
467 if (set.isEmpty()) 496 if (set.isEmpty())
468 return; 497 return;
469 if (WTF::ShouldBeTraced<Traits>::value) { 498 if (WTF::ShouldBeTraced<Traits>::value) {
470 HashSet& iterSet = const_cast<HashSet&>(set); 499 HashSet& iterSet = const_cast<HashSet&>(set);
471 for (typename HashSet::iterator it = iterSet.begin(), end = iterSet. end(); it != end; ++it) 500 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); 501 const T& t = *it;
502 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits::isWeak, WeakPointersActWeak, T, Traits>::trace(visitor, const_cast<T&>(t ));
503 }
473 } 504 }
474 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou s0); 505 COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerou s0);
475 } 506 }
476 }; 507 };
477 508
478 template<typename T, size_t inlineCapacity, typename HashFunctions> 509 template<typename T, size_t inlineCapacity, typename HashFunctions>
479 struct OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, HashFunctions> > { 510 struct OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, HashFunctions> > {
480 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet; 511 typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet;
481 512
482 static void trace(Visitor* visitor, const ListHashSet& set) 513 static void trace(Visitor* visitor, const ListHashSet& set)
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 struct GCInfoTrait { 755 struct GCInfoTrait {
725 static const GCInfo* get() 756 static const GCInfo* get()
726 { 757 {
727 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); 758 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get();
728 } 759 }
729 }; 760 };
730 761
731 } 762 }
732 763
733 #endif 764 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698