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

Side by Side Diff: Source/platform/Supplementable.h

Issue 517043003: Move Frame to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Back out non-Oilpan experiment + tidy up by adding frame() ref accessors Created 6 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>& host, const char* key) 137 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>& host, const char* key)
138 { 138 {
139 return host.requireSupplement(key); 139 return host.requireSupplement(key);
140 } 140 }
141 141
142 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>* host, const char* key) 142 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>* host, const char* key)
143 { 143 {
144 return host ? host->requireSupplement(key) : 0; 144 return host ? host->requireSupplement(key) : 0;
145 } 145 }
146
147 // FIXME: Oilpan: Remove this callback once PersistentHeapSupplementable is removed again.
148 virtual void persistentHostHasBeenDestroyed() { }
149 }; 146 };
150 147
151 // Helper class for implementing Supplementable, HeapSupplementable, and 148 // Helper class for implementing Supplementable and HeapSupplementable.
152 // PersistentHeapSupplementable.
153 template<typename T, bool isGarbageCollected = false> 149 template<typename T, bool isGarbageCollected = false>
154 class SupplementableBase { 150 class SupplementableBase {
155 public: 151 public:
156 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement) 152 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement)
157 { 153 {
158 ASSERT(m_threadId == currentThread()); 154 ASSERT(m_threadId == currentThread());
159 ASSERT(!this->m_supplements.get(key)); 155 ASSERT(!this->m_supplements.get(key));
160 this->m_supplements.set(key, supplement); 156 this->m_supplements.set(key, supplement);
161 } 157 }
162 158
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 template<typename T> 204 template<typename T>
209 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su pplementableBase<T, true>, public GarbageCollectedMixin { 205 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su pplementableBase<T, true>, public GarbageCollectedMixin {
210 public: 206 public:
211 virtual void trace(Visitor* visitor) OVERRIDE 207 virtual void trace(Visitor* visitor) OVERRIDE
212 { 208 {
213 visitor->trace(this->m_supplements); 209 visitor->trace(this->m_supplements);
214 SupplementableBase<T, true>::trace(visitor); 210 SupplementableBase<T, true>::trace(visitor);
215 } 211 }
216 }; 212 };
217 213
218 // This class is used to make an off-heap class supplementable with supplements
219 // that are on-heap, aka. HeapSupplements.
220 template<typename T>
221 class GC_PLUGIN_IGNORE("http://crbug.com/395036") PersistentHeapSupplementable : public SupplementableBase<T, true> {
222 public:
223 PersistentHeapSupplementable() : m_root(this) { }
224 virtual ~PersistentHeapSupplementable()
225 {
226 typedef typename SupplementableTraits<T, true>::SupplementMap::iterator SupplementIterator;
227 for (SupplementIterator it = this->m_supplements.begin(); it != this->m_ supplements.end(); ++it)
228 it->value->persistentHostHasBeenDestroyed();
229 }
230
231 virtual void trace(Visitor* visitor)
232 {
233 visitor->trace(this->m_supplements);
234 SupplementableBase<T, true>::trace(visitor);
235 }
236
237 private:
238 class TraceDelegate : PersistentBase<ThreadLocalPersistents<AnyThread>, Trac eDelegate> {
239 public:
240 TraceDelegate(PersistentHeapSupplementable* owner) : m_owner(owner) { }
241 void trace(Visitor* visitor) { m_owner->trace(visitor); }
242 private:
243 PersistentHeapSupplementable* m_owner;
244 };
245
246 TraceDelegate m_root;
247 };
248
249 template<typename T> 214 template<typename T>
250 class Supplement : public SupplementBase<T, false> { }; 215 class Supplement : public SupplementBase<T, false> { };
251 216
252 // This class is used to make an off-heap class supplementable with off-heap 217 // This class is used to make an off-heap class supplementable with off-heap
253 // supplements (Supplement). 218 // supplements (Supplement).
254 template<typename T> 219 template<typename T>
255 class GC_PLUGIN_IGNORE("http://crbug.com/395036") Supplementable : public Supple mentableBase<T, false> { 220 class GC_PLUGIN_IGNORE("http://crbug.com/395036") Supplementable : public Supple mentableBase<T, false> {
256 public: 221 public:
257 virtual void trace(Visitor* visitor) 222 virtual void trace(Visitor* visitor)
258 { 223 {
259 // No tracing of off-heap supplements. We should not have any Supplement able 224 // No tracing of off-heap supplements. We should not have any Supplement able
260 // object on the heap. Either the object is HeapSupplementable or if it is 225 // object on the heap.
261 // off heap it should use PersistentHeapSupplementable to trace any on-h eap
262 // supplements.
263 COMPILE_ASSERT(!IsGarbageCollectedType<T>::value, GarbageCollectedObject MustBeHeapSupplementable); 226 COMPILE_ASSERT(!IsGarbageCollectedType<T>::value, GarbageCollectedObject MustBeHeapSupplementable);
264 SupplementableBase<T, false>::trace(visitor); 227 SupplementableBase<T, false>::trace(visitor);
265 } 228 }
266 }; 229 };
267 230
268 template<typename T> 231 template<typename T>
269 struct ThreadingTrait<SupplementBase<T, true> > { 232 struct ThreadingTrait<SupplementBase<T, true> > {
270 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 233 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
271 }; 234 };
272 235
273 template<typename T> 236 template<typename T>
274 struct ThreadingTrait<SupplementableBase<T, true> > { 237 struct ThreadingTrait<SupplementableBase<T, true> > {
275 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 238 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
276 }; 239 };
277 240
278 } // namespace blink 241 } // namespace blink
279 242
280 #endif // Supplementable_h 243 #endif // Supplementable_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698