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

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
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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // Normally these would be typedefs instead of subclasses, but that makes them 675 // Normally these would be typedefs instead of subclasses, but that makes them
676 // very hard to forward declare. 676 // very hard to forward declare.
677 class HeapContainsCache : public HeapExtentCache<PositiveEntry> { 677 class HeapContainsCache : public HeapExtentCache<PositiveEntry> {
678 public: 678 public:
679 BaseHeapPage* lookup(Address); 679 BaseHeapPage* lookup(Address);
680 void addEntry(Address, BaseHeapPage*); 680 void addEntry(Address, BaseHeapPage*);
681 }; 681 };
682 682
683 class HeapDoesNotContainCache : public HeapExtentCache<NegativeEntry> { }; 683 class HeapDoesNotContainCache : public HeapExtentCache<NegativeEntry> { };
684 684
685 // FIXME: This is currently used by the WebAudio code.
686 // We should attempt to restructure the WebAudio code so that the main thread
687 // alone determines life-time and receives messages about life-time from the
688 // audio thread.
689 template<typename T>
690 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T> , public WTF::ThreadSafeRefCountedBase {
691 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected);
692
693 public:
694 ThreadSafeRefCountedGarbageCollected()
695 {
696 makeKeepAlive();
697 }
698
699 // Override ref to deal with a case where a reference count goes up
700 // from 0 to 1. This can happen in the following scenario:
701 // (1) The reference count becomes 0, but on-stack pointers keep references to the object.
702 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec omes 1.
703 // In this case, we have to resurrect m_keepAlive.
704 void ref()
705 {
706 MutexLocker lock(m_mutex);
707 if (UNLIKELY(!refCount())) {
708 makeKeepAlive();
709 }
710 WTF::ThreadSafeRefCountedBase::ref();
711 }
712
713 // Override deref to deal with our own deallocation based on ref counting.
714 void deref()
715 {
716 MutexLocker lock(m_mutex);
717 if (derefBase()) {
718 ASSERT(m_keepAlive);
719 m_keepAlive.clear();
720 }
721 }
722
723 using GarbageCollectedFinalized<T>::operator new;
724 using GarbageCollectedFinalized<T>::operator delete;
725
726 protected:
727 ~ThreadSafeRefCountedGarbageCollected() { }
728
729 private:
730 void makeKeepAlive()
731 {
732 ASSERT(!m_keepAlive);
733 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this )));
734 }
735
736 OwnPtr<CrossThreadPersistent<T> > m_keepAlive;
737 mutable Mutex m_mutex;
738 };
739
740 template<typename DataType> 685 template<typename DataType>
741 class PagePool { 686 class PagePool {
742 protected: 687 protected:
743 PagePool(); 688 PagePool();
744 689
745 class PoolEntry { 690 class PoolEntry {
746 public: 691 public:
747 PoolEntry(DataType* data, PoolEntry* next) 692 PoolEntry(DataType* data, PoolEntry* next)
748 : data(data) 693 : data(data)
749 , next(next) 694 , next(next)
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 // persistent handle will be deleted. When the garbage collector 1170 // persistent handle will be deleted. When the garbage collector
1226 // determines that there are no other references to the object it will 1171 // determines that there are no other references to the object it will
1227 // be reclaimed and the destructor of the reclaimed object will be 1172 // be reclaimed and the destructor of the reclaimed object will be
1228 // called at that time. 1173 // called at that time.
1229 template<typename T> 1174 template<typename T>
1230 class RefCountedGarbageCollected : public GarbageCollectedFinalized<T> { 1175 class RefCountedGarbageCollected : public GarbageCollectedFinalized<T> {
1231 WTF_MAKE_NONCOPYABLE(RefCountedGarbageCollected); 1176 WTF_MAKE_NONCOPYABLE(RefCountedGarbageCollected);
1232 1177
1233 public: 1178 public:
1234 RefCountedGarbageCollected() 1179 RefCountedGarbageCollected()
1235 : m_refCount(1) 1180 : m_refCount(0)
1236 { 1181 {
1237 makeKeepAlive();
1238 } 1182 }
1239 1183
1240 // Implement method to increase reference count for use with 1184 // Implement method to increase reference count for use with
1241 // RefPtrs. 1185 // RefPtrs.
1242 // 1186 //
1243 // In contrast to the normal WTF::RefCounted, the reference count 1187 // In contrast to the normal WTF::RefCounted, the reference count
1244 // can reach 0 and increase again. This happens in the following 1188 // can reach 0 and increase again. This happens in the following
1245 // scenario: 1189 // scenario:
1246 // 1190 //
1247 // (1) The reference count becomes 0, but members, persistents, or 1191 // (1) The reference count becomes 0, but members, persistents, or
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 void makeKeepAlive() 1233 void makeKeepAlive()
1290 { 1234 {
1291 ASSERT(!m_keepAlive); 1235 ASSERT(!m_keepAlive);
1292 m_keepAlive = new Persistent<T>(static_cast<T*>(this)); 1236 m_keepAlive = new Persistent<T>(static_cast<T*>(this));
1293 } 1237 }
1294 1238
1295 int m_refCount; 1239 int m_refCount;
1296 Persistent<T>* m_keepAlive; 1240 Persistent<T>* m_keepAlive;
1297 }; 1241 };
1298 1242
1299 template<typename T>
1300 T* adoptRefCountedGarbageCollected(T* ptr)
1301 {
1302 ASSERT(ptr->hasOneRef());
1303 ptr->deref();
1304 WTF::adopted(ptr);
1305 return ptr;
1306 }
1307
1308 // Classes that contain heap references but aren't themselves heap 1243 // Classes that contain heap references but aren't themselves heap
1309 // allocated, have some extra macros available which allows their use 1244 // allocated, have some extra macros available which allows their use
1310 // to be restricted to cases where the garbage collector is able 1245 // to be restricted to cases where the garbage collector is able
1311 // to discover their heap references. 1246 // to discover their heap references.
1312 // 1247 //
1313 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects 1248 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects
1314 // should be in Members but you do not need the trace method as they are on 1249 // should be in Members but you do not need the trace method as they are on
1315 // the stack. (Down the line these might turn in to raw pointers, but for 1250 // the stack. (Down the line these might turn in to raw pointers, but for
1316 // now Members indicates that we have thought about them and explicitly 1251 // now Members indicates that we have thought about them and explicitly
1317 // taken care of them.) 1252 // taken care of them.)
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2488 }; 2423 };
2489 2424
2490 template<typename T> 2425 template<typename T>
2491 struct IfWeakMember<WeakMember<T> > { 2426 struct IfWeakMember<WeakMember<T> > {
2492 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } 2427 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); }
2493 }; 2428 };
2494 2429
2495 } 2430 }
2496 2431
2497 #endif // Heap_h 2432 #endif // Heap_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698