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

Side by Side Diff: sky/engine/platform/heap/Heap.h

Issue 655083003: Remove GarbageCollectedFinalized (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « sky/engine/platform/heap/Handle.h ('k') | sky/engine/public/platform/WebPrivatePtr.h » ('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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 GlobalMarking, 102 GlobalMarking,
103 ThreadLocalMarking, 103 ThreadLocalMarking,
104 PostMarking, 104 PostMarking,
105 WeaknessProcessing, 105 WeaknessProcessing,
106 }; 106 };
107 107
108 class HeapStats; 108 class HeapStats;
109 class PageMemory; 109 class PageMemory;
110 template<ThreadAffinity affinity> class ThreadLocalPersistents; 110 template<ThreadAffinity affinity> class ThreadLocalPersistents;
111 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > > class Persistent; 111 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > > class Persistent;
112 template<typename T> class CrossThreadPersistent;
113 112
114 #if ENABLE(GC_PROFILE_HEAP) 113 #if ENABLE(GC_PROFILE_HEAP)
115 class TracedValue; 114 class TracedValue;
116 #endif 115 #endif
117 116
118 PLATFORM_EXPORT size_t osPageSize(); 117 PLATFORM_EXPORT size_t osPageSize();
119 118
120 // Blink heap pages are set up with a guard page before and after the 119 // Blink heap pages are set up with a guard page before and after the
121 // payload. 120 // payload.
122 inline size_t blinkPagePayloadSize() 121 inline size_t blinkPagePayloadSize()
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // 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
677 // very hard to forward declare. 676 // very hard to forward declare.
678 class HeapContainsCache : public HeapExtentCache<PositiveEntry> { 677 class HeapContainsCache : public HeapExtentCache<PositiveEntry> {
679 public: 678 public:
680 BaseHeapPage* lookup(Address); 679 BaseHeapPage* lookup(Address);
681 void addEntry(Address, BaseHeapPage*); 680 void addEntry(Address, BaseHeapPage*);
682 }; 681 };
683 682
684 class HeapDoesNotContainCache : public HeapExtentCache<NegativeEntry> { }; 683 class HeapDoesNotContainCache : public HeapExtentCache<NegativeEntry> { };
685 684
686 // FIXME: This is currently used by the WebAudio code.
687 // We should attempt to restructure the WebAudio code so that the main thread
688 // alone determines life-time and receives messages about life-time from the
689 // audio thread.
690 template<typename T>
691 class ThreadSafeRefCountedGarbageCollected : public GarbageCollectedFinalized<T> , public WTF::ThreadSafeRefCountedBase {
692 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedGarbageCollected);
693
694 public:
695 ThreadSafeRefCountedGarbageCollected()
696 {
697 makeKeepAlive();
698 }
699
700 // Override ref to deal with a case where a reference count goes up
701 // from 0 to 1. This can happen in the following scenario:
702 // (1) The reference count becomes 0, but on-stack pointers keep references to the object.
703 // (2) The on-stack pointer is assigned to a RefPtr. The reference count bec omes 1.
704 // In this case, we have to resurrect m_keepAlive.
705 void ref()
706 {
707 MutexLocker lock(m_mutex);
708 if (UNLIKELY(!refCount())) {
709 makeKeepAlive();
710 }
711 WTF::ThreadSafeRefCountedBase::ref();
712 }
713
714 // Override deref to deal with our own deallocation based on ref counting.
715 void deref()
716 {
717 MutexLocker lock(m_mutex);
718 if (derefBase()) {
719 ASSERT(m_keepAlive);
720 m_keepAlive.clear();
721 }
722 }
723
724 using GarbageCollectedFinalized<T>::operator new;
725 using GarbageCollectedFinalized<T>::operator delete;
726
727 protected:
728 ~ThreadSafeRefCountedGarbageCollected() { }
729
730 private:
731 void makeKeepAlive()
732 {
733 ASSERT(!m_keepAlive);
734 m_keepAlive = adoptPtr(new CrossThreadPersistent<T>(static_cast<T*>(this )));
735 }
736
737 OwnPtr<CrossThreadPersistent<T> > m_keepAlive;
738 mutable Mutex m_mutex;
739 };
740
741 template<typename DataType> 685 template<typename DataType>
742 class PagePool { 686 class PagePool {
743 protected: 687 protected:
744 PagePool(); 688 PagePool();
745 689
746 class PoolEntry { 690 class PoolEntry {
747 public: 691 public:
748 PoolEntry(DataType* data, PoolEntry* next) 692 PoolEntry(DataType* data, PoolEntry* next)
749 : data(data) 693 : data(data)
750 , next(next) 694 , next(next)
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 private: 1145 private:
1202 void enter() const 1146 void enter() const
1203 { 1147 {
1204 if (m_active) 1148 if (m_active)
1205 ThreadStateFor<Affinity>::state()->enterNoAllocationScope(); 1149 ThreadStateFor<Affinity>::state()->enterNoAllocationScope();
1206 } 1150 }
1207 1151
1208 bool m_active; 1152 bool m_active;
1209 }; 1153 };
1210 1154
1211 // Base class for objects allocated in the Blink garbage-collected
1212 // heap.
1213 //
1214 // Defines a 'new' operator that allocates the memory in the
1215 // heap. 'delete' should not be called on objects that inherit from
1216 // GarbageCollected.
1217 //
1218 // Instances of GarbageCollected will *NOT* get finalized. Their
1219 // destructor will not be called. Therefore, only classes that have
1220 // trivial destructors with no semantic meaning (including all their
1221 // subclasses) should inherit from GarbageCollected. If there are
1222 // non-trival destructors in a given class or any of its subclasses,
1223 // GarbageCollectedFinalized should be used which guarantees that the
1224 // destructor is called on an instance when the garbage collector
1225 // determines that it is no longer reachable.
1226 template<typename T>
1227 class GarbageCollected {
1228 WTF_MAKE_NONCOPYABLE(GarbageCollected);
1229
1230 // For now direct allocation of arrays on the heap is not allowed.
1231 void* operator new[](size_t size);
1232 void operator delete[](void* p);
1233 public:
1234 typedef T GarbageCollectedBase;
1235
1236 void* operator new(size_t size)
1237 {
1238 return Heap::allocate<T>(size);
1239 }
1240
1241 void operator delete(void* p)
1242 {
1243 ASSERT_NOT_REACHED();
1244 }
1245
1246 protected:
1247 GarbageCollected()
1248 {
1249 }
1250 };
1251
1252 // Base class for objects allocated in the Blink garbage-collected
1253 // heap.
1254 //
1255 // Defines a 'new' operator that allocates the memory in the
1256 // heap. 'delete' should not be called on objects that inherit from
1257 // GarbageCollected.
1258 //
1259 // Instances of GarbageCollectedFinalized will have their destructor
1260 // called when the garbage collector determines that the object is no
1261 // longer reachable.
1262 template<typename T>
1263 class GarbageCollectedFinalized : public GarbageCollected<T> {
1264 WTF_MAKE_NONCOPYABLE(GarbageCollectedFinalized);
1265
1266 protected:
1267 // finalizeGarbageCollectedObject is called when the object is
1268 // freed from the heap. By default finalization means calling the
1269 // destructor on the object. finalizeGarbageCollectedObject can be
1270 // overridden to support calling the destructor of a
1271 // subclass. This is useful for objects without vtables that
1272 // require explicit dispatching. The name is intentionally a bit
1273 // long to make name conflicts less likely.
1274 void finalizeGarbageCollectedObject()
1275 {
1276 static_cast<T*>(this)->~T();
1277 }
1278
1279 GarbageCollectedFinalized() { }
1280 ~GarbageCollectedFinalized() { }
1281
1282 template<typename U> friend struct HasFinalizer;
1283 template<typename U, bool> friend struct FinalizerTraitImpl;
1284 };
1285
1286 // Base class for objects that are in the Blink garbage-collected heap 1155 // Base class for objects that are in the Blink garbage-collected heap
1287 // and are still reference counted. 1156 // and are still reference counted.
1288 // 1157 //
1289 // This class should be used sparingly and only to gradually move 1158 // This class should be used sparingly and only to gradually move
1290 // objects from being reference counted to being managed by the blink 1159 // objects from being reference counted to being managed by the blink
1291 // garbage collector. 1160 // garbage collector.
1292 // 1161 //
1293 // While the current reference counting keeps one of these objects 1162 // While the current reference counting keeps one of these objects
1294 // alive it will have a Persistent handle to itself allocated so we 1163 // alive it will have a Persistent handle to itself allocated so we
1295 // will not reclaim the memory. When the reference count reaches 0 the 1164 // will not reclaim the memory. When the reference count reaches 0 the
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2408 }; 2277 };
2409 2278
2410 template<typename T> 2279 template<typename T>
2411 struct IfWeakMember<WeakMember<T> > { 2280 struct IfWeakMember<WeakMember<T> > {
2412 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } 2281 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); }
2413 }; 2282 };
2414 2283
2415 } 2284 }
2416 2285
2417 #endif // Heap_h 2286 #endif // Heap_h
OLDNEW
« no previous file with comments | « sky/engine/platform/heap/Handle.h ('k') | sky/engine/public/platform/WebPrivatePtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698