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

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

Issue 614373007: Oilpan: Remove adoptRefCountedGarbageCollected (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 private: 615 private:
616 static const int numberOfEntriesLog2 = 12; 616 static const int numberOfEntriesLog2 = 12;
617 static const int numberOfEntries = 1 << numberOfEntriesLog2; 617 static const int numberOfEntries = 1 << numberOfEntriesLog2;
618 618
619 static size_t hash(Address); 619 static size_t hash(Address);
620 620
621 WTF::OwnPtr<Address[]> m_entries; 621 WTF::OwnPtr<Address[]> m_entries;
622 bool m_hasEntries; 622 bool m_hasEntries;
623 }; 623 };
624 624
625 // FIXME: This is currently used by the WebAudio code.
626 // We should attempt to restructure the WebAudio code so that the main thread
627 // alone determines life-time and receives messages about life-time from the
628 // audio thread.
629 template<typename T>
630 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T> , public WTF::ThreadSafeRefCountedBase {
631 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected);
632
633 public:
634 ThreadSafeRefCountedGarbageCollected()
635 {
636 makeKeepAlive();
637 }
638
639 // Override ref to deal with a case where a reference count goes up
640 // from 0 to 1. This can happen in the following scenario:
641 // (1) The reference count becomes 0, but on-stack pointers keep references to the object.
642 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec omes 1.
643 // In this case, we have to resurrect m_keepAlive.
644 void ref()
645 {
646 MutexLocker lock(m_mutex);
647 if (UNLIKELY(!refCount())) {
648 makeKeepAlive();
649 }
650 WTF::ThreadSafeRefCountedBase::ref();
651 }
652
653 // Override deref to deal with our own deallocation based on ref counting.
654 void deref()
655 {
656 MutexLocker lock(m_mutex);
657 if (derefBase()) {
658 ASSERT(m_keepAlive);
659 m_keepAlive.clear();
660 }
661 }
662
663 using GarbageCollectedFinalized<T>::operator new;
664 using GarbageCollectedFinalized<T>::operator delete;
665
666 protected:
667 ~ThreadSafeRefCountedGarbageCollected() { }
668
669 private:
670 void makeKeepAlive()
671 {
672 ASSERT(!m_keepAlive);
673 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this )));
674 }
675
676 OwnPtr<CrossThreadPersistent<T> > m_keepAlive;
677 mutable Mutex m_mutex;
678 };
679
680 template<typename DataType> 625 template<typename DataType>
681 class PagePool { 626 class PagePool {
682 protected: 627 protected:
683 PagePool(); 628 PagePool();
684 629
685 class PoolEntry { 630 class PoolEntry {
686 public: 631 public:
687 PoolEntry(DataType* data, PoolEntry* next) 632 PoolEntry(DataType* data, PoolEntry* next)
688 : data(data) 633 : data(data)
689 , next(next) 634 , next(next)
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 // persistent handle will be deleted. When the garbage collector 1132 // persistent handle will be deleted. When the garbage collector
1188 // determines that there are no other references to the object it will 1133 // determines that there are no other references to the object it will
1189 // be reclaimed and the destructor of the reclaimed object will be 1134 // be reclaimed and the destructor of the reclaimed object will be
1190 // called at that time. 1135 // called at that time.
1191 template<typename T> 1136 template<typename T>
1192 class RefCountedGarbageCollected : public GarbageCollectedFinalized<T> { 1137 class RefCountedGarbageCollected : public GarbageCollectedFinalized<T> {
1193 WTF_MAKE_NONCOPYABLE(RefCountedGarbageCollected); 1138 WTF_MAKE_NONCOPYABLE(RefCountedGarbageCollected);
1194 1139
1195 public: 1140 public:
1196 RefCountedGarbageCollected() 1141 RefCountedGarbageCollected()
1197 : m_refCount(1) 1142 : m_refCount(0)
1198 { 1143 {
1199 makeKeepAlive();
1200 } 1144 }
1201 1145
1202 // Implement method to increase reference count for use with 1146 // Implement method to increase reference count for use with
1203 // RefPtrs. 1147 // RefPtrs.
1204 // 1148 //
1205 // In contrast to the normal WTF::RefCounted, the reference count 1149 // In contrast to the normal WTF::RefCounted, the reference count
1206 // can reach 0 and increase again. This happens in the following 1150 // can reach 0 and increase again. This happens in the following
1207 // scenario: 1151 // scenario:
1208 // 1152 //
1209 // (1) The reference count becomes 0, but members, persistents, or 1153 // (1) The reference count becomes 0, but members, persistents, or
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 void makeKeepAlive() 1195 void makeKeepAlive()
1252 { 1196 {
1253 ASSERT(!m_keepAlive); 1197 ASSERT(!m_keepAlive);
1254 m_keepAlive = new Persistent<T>(static_cast<T*>(this)); 1198 m_keepAlive = new Persistent<T>(static_cast<T*>(this));
1255 } 1199 }
1256 1200
1257 int m_refCount; 1201 int m_refCount;
1258 Persistent<T>* m_keepAlive; 1202 Persistent<T>* m_keepAlive;
1259 }; 1203 };
1260 1204
1261 template<typename T>
1262 T* adoptRefCountedGarbageCollected(T* ptr)
1263 {
1264 ASSERT(ptr->hasOneRef());
1265 ptr->deref();
1266 WTF::adopted(ptr);
1267 return ptr;
1268 }
1269
1270 // Classes that contain heap references but aren't themselves heap 1205 // Classes that contain heap references but aren't themselves heap
1271 // allocated, have some extra macros available which allows their use 1206 // allocated, have some extra macros available which allows their use
1272 // to be restricted to cases where the garbage collector is able 1207 // to be restricted to cases where the garbage collector is able
1273 // to discover their heap references. 1208 // to discover their heap references.
1274 // 1209 //
1275 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects 1210 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects
1276 // should be in Members but you do not need the trace method as they are on 1211 // should be in Members but you do not need the trace method as they are on
1277 // the stack. (Down the line these might turn in to raw pointers, but for 1212 // the stack. (Down the line these might turn in to raw pointers, but for
1278 // now Members indicates that we have thought about them and explicitly 1213 // now Members indicates that we have thought about them and explicitly
1279 // taken care of them.) 1214 // taken care of them.)
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 }; 2385 };
2451 2386
2452 template<typename T> 2387 template<typename T>
2453 struct IfWeakMember<WeakMember<T> > { 2388 struct IfWeakMember<WeakMember<T> > {
2454 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } 2389 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); }
2455 }; 2390 };
2456 2391
2457 } 2392 }
2458 2393
2459 #endif // Heap_h 2394 #endif // Heap_h
OLDNEW
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698