| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 private: | 189 private: |
| 190 PersistentAnchor() : PersistentNode(TraceMethodDelegate<PersistentAnchor, &P
ersistentAnchor::trace>::trampoline) | 190 PersistentAnchor() : PersistentNode(TraceMethodDelegate<PersistentAnchor, &P
ersistentAnchor::trace>::trampoline) |
| 191 { | 191 { |
| 192 m_next = this; | 192 m_next = this; |
| 193 m_prev = this; | 193 m_prev = this; |
| 194 } | 194 } |
| 195 | 195 |
| 196 friend class ThreadState; | 196 friend class ThreadState; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 template<typename T> | |
| 200 class CrossThreadPersistent; | |
| 201 | |
| 202 // Persistent handles are used to store pointers into the | 199 // Persistent handles are used to store pointers into the |
| 203 // managed heap. As long as the Persistent handle is alive | 200 // managed heap. As long as the Persistent handle is alive |
| 204 // the GC will keep the object pointed to alive. Persistent | 201 // the GC will keep the object pointed to alive. Persistent |
| 205 // handles can be stored in objects and they are not scoped. | 202 // handles can be stored in objects and they are not scoped. |
| 206 // Persistent handles must not be used to contain pointers | 203 // Persistent handles must not be used to contain pointers |
| 207 // between objects that are in the managed heap. They are only | 204 // between objects that are in the managed heap. They are only |
| 208 // meant to point to managed heap objects from variables/members | 205 // meant to point to managed heap objects from variables/members |
| 209 // outside the managed heap. | 206 // outside the managed heap. |
| 210 // | 207 // |
| 211 // A Persistent is always a GC root from the point of view of | 208 // A Persistent is always a GC root from the point of view of |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 Persistent& operator=(const RawPtr<U>& other) | 318 Persistent& operator=(const RawPtr<U>& other) |
| 322 { | 319 { |
| 323 m_raw = other; | 320 m_raw = other; |
| 324 recordBacktrace(); | 321 recordBacktrace(); |
| 325 return *this; | 322 return *this; |
| 326 } | 323 } |
| 327 | 324 |
| 328 T* get() const { return m_raw; } | 325 T* get() const { return m_raw; } |
| 329 | 326 |
| 330 private: | 327 private: |
| 331 #if ENABLE(GC_PROFILE_MARKING) | |
| 332 void recordBacktrace() | |
| 333 { | |
| 334 if (m_raw) | |
| 335 m_tracingName = Heap::createBacktraceString(); | |
| 336 } | |
| 337 | |
| 338 String m_tracingName; | |
| 339 #else | |
| 340 inline void recordBacktrace() const { } | 328 inline void recordBacktrace() const { } |
| 341 #endif | |
| 342 T* m_raw; | 329 T* m_raw; |
| 343 | |
| 344 friend class CrossThreadPersistent<T>; | |
| 345 }; | |
| 346 | |
| 347 // FIXME: derive affinity based on the collection. | |
| 348 template<typename Collection, ThreadAffinity Affinity = AnyThread> | |
| 349 class PersistentHeapCollectionBase | |
| 350 : public Collection | |
| 351 , public PersistentBase<ThreadLocalPersistents<Affinity>, PersistentHeapColl
ectionBase<Collection, Affinity> > { | |
| 352 // We overload the various new and delete operators with using the WTF Defau
ltAllocator to ensure persistent | |
| 353 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in | |
| 354 // DEFINE_STATIC_LOCAL et. al. | |
| 355 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator); | |
| 356 public: | |
| 357 PersistentHeapCollectionBase() { } | |
| 358 | |
| 359 template<typename OtherCollection> | |
| 360 PersistentHeapCollectionBase(const OtherCollection& other) : Collection(othe
r) { } | |
| 361 | |
| 362 void trace(Visitor* visitor) | |
| 363 { | |
| 364 #if ENABLE(GC_PROFILE_MARKING) | |
| 365 visitor->setHostInfo(this, "PersistentHeapCollectionBase"); | |
| 366 #endif | |
| 367 visitor->trace(*static_cast<Collection*>(this)); | |
| 368 } | |
| 369 }; | |
| 370 | |
| 371 template< | |
| 372 typename KeyArg, | |
| 373 typename MappedArg, | |
| 374 typename HashArg = typename DefaultHash<KeyArg>::Hash, | |
| 375 typename KeyTraitsArg = HashTraits<KeyArg>, | |
| 376 typename MappedTraitsArg = HashTraits<MappedArg> > | |
| 377 class PersistentHeapHashMap : public PersistentHeapCollectionBase<HeapHashMap<Ke
yArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> > { }; | |
| 378 | |
| 379 template< | |
| 380 typename ValueArg, | |
| 381 typename HashArg = typename DefaultHash<ValueArg>::Hash, | |
| 382 typename TraitsArg = HashTraits<ValueArg> > | |
| 383 class PersistentHeapHashSet : public PersistentHeapCollectionBase<HeapHashSet<Va
lueArg, HashArg, TraitsArg> > { }; | |
| 384 | |
| 385 template< | |
| 386 typename ValueArg, | |
| 387 typename HashArg = typename DefaultHash<ValueArg>::Hash, | |
| 388 typename TraitsArg = HashTraits<ValueArg> > | |
| 389 class PersistentHeapLinkedHashSet : public PersistentHeapCollectionBase<HeapLink
edHashSet<ValueArg, HashArg, TraitsArg> > { }; | |
| 390 | |
| 391 template< | |
| 392 typename ValueArg, | |
| 393 size_t inlineCapacity = 0, | |
| 394 typename HashArg = typename DefaultHash<ValueArg>::Hash> | |
| 395 class PersistentHeapListHashSet : public PersistentHeapCollectionBase<HeapListHa
shSet<ValueArg, inlineCapacity, HashArg> > { }; | |
| 396 | |
| 397 template<typename T, typename U, typename V> | |
| 398 class PersistentHeapHashCountedSet : public PersistentHeapCollectionBase<HeapHas
hCountedSet<T, U, V> > { }; | |
| 399 | |
| 400 template<typename T, size_t inlineCapacity = 0> | |
| 401 class PersistentHeapVector : public PersistentHeapCollectionBase<HeapVector<T, i
nlineCapacity> > { | |
| 402 public: | |
| 403 PersistentHeapVector() { } | |
| 404 | |
| 405 template<size_t otherCapacity> | |
| 406 PersistentHeapVector(const HeapVector<T, otherCapacity>& other) | |
| 407 : PersistentHeapCollectionBase<HeapVector<T, inlineCapacity> >(other) | |
| 408 { | |
| 409 } | |
| 410 }; | |
| 411 | |
| 412 template<typename T, size_t inlineCapacity = 0> | |
| 413 class PersistentHeapDeque : public PersistentHeapCollectionBase<HeapDeque<T, inl
ineCapacity> > { | |
| 414 public: | |
| 415 PersistentHeapDeque() { } | |
| 416 | |
| 417 template<size_t otherCapacity> | |
| 418 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other) | |
| 419 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity> >(other) | |
| 420 { | |
| 421 } | |
| 422 }; | 330 }; |
| 423 | 331 |
| 424 // Members are used in classes to contain strong pointers to other oilpan heap | 332 // Members are used in classes to contain strong pointers to other oilpan heap |
| 425 // allocated objects. | 333 // allocated objects. |
| 426 // All Member fields of a class must be traced in the class' trace method. | 334 // All Member fields of a class must be traced in the class' trace method. |
| 427 // During the mark phase of the GC all live objects are marked as live and | 335 // During the mark phase of the GC all live objects are marked as live and |
| 428 // all Member fields of a live object will be traced marked as live as well. | 336 // all Member fields of a live object will be traced marked as live as well. |
| 429 template<typename T> | 337 template<typename T> |
| 430 class Member { | 338 class Member { |
| 431 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Member); | 339 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Member); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 754 |
| 847 template<typename T> | 755 template<typename T> |
| 848 struct PointerParamStorageTraits<T*, false> { | 756 struct PointerParamStorageTraits<T*, false> { |
| 849 typedef T* StorageType; | 757 typedef T* StorageType; |
| 850 | 758 |
| 851 static StorageType wrap(T* value) { return value; } | 759 static StorageType wrap(T* value) { return value; } |
| 852 static T* unwrap(const StorageType& value) { return value; } | 760 static T* unwrap(const StorageType& value) { return value; } |
| 853 }; | 761 }; |
| 854 | 762 |
| 855 template<typename T> | 763 template<typename T> |
| 856 struct PointerParamStorageTraits<T*, true> { | |
| 857 typedef blink::CrossThreadPersistent<T> StorageType; | |
| 858 | |
| 859 static StorageType wrap(T* value) { return value; } | |
| 860 static T* unwrap(const StorageType& value) { return value.get(); } | |
| 861 }; | |
| 862 | |
| 863 template<typename T> | |
| 864 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> { | 764 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> { |
| 865 }; | 765 }; |
| 866 | 766 |
| 867 template<typename T> | 767 template<typename T> |
| 868 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal
se> { | 768 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal
se> { |
| 869 }; | 769 }; |
| 870 | 770 |
| 871 } // namespace WTF | 771 } // namespace WTF |
| 872 | 772 |
| 873 #endif | 773 #endif |
| OLD | NEW |