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

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

Issue 587393002: Oilpan: make Supplementable tracing more regular. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Improve dummy trace() comment 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
« no previous file with comments | « Source/platform/RefCountedSupplement.h ('k') | no next file » | 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) 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 template<typename T, bool isGarbageCollected> 94 template<typename T, bool isGarbageCollected>
95 class SupplementableBase; 95 class SupplementableBase;
96 96
97 template<typename T, bool isGarbageCollected> 97 template<typename T, bool isGarbageCollected>
98 struct SupplementableTraits; 98 struct SupplementableTraits;
99 99
100 template<typename T> 100 template<typename T>
101 struct SupplementableTraits<T, true> { 101 struct SupplementableTraits<T, true> {
102 typedef RawPtr<SupplementBase<T, true> > SupplementArgumentType; 102 typedef RawPtr<SupplementBase<T, true> > SupplementArgumentType;
103 typedef HeapHashMap<const char*, Member<SupplementBase<T, true> >, PtrHash<c onst char*> > SupplementMap;
104 }; 103 };
105 104
106 template<typename T> 105 template<typename T>
107 struct SupplementableTraits<T, false> { 106 struct SupplementableTraits<T, false> {
108 typedef PassOwnPtr<SupplementBase<T, false> > SupplementArgumentType; 107 typedef PassOwnPtr<SupplementBase<T, false> > SupplementArgumentType;
109 typedef HashMap<const char*, OwnPtr<SupplementBase<T, false> >, PtrHash<cons t char*> > SupplementMap;
110 }; 108 };
111 109
112 template<bool> 110 template<bool>
113 class SupplementTracing; 111 class SupplementTracing;
114 112
115 template<> 113 template<>
116 class SupplementTracing<true> : public GarbageCollectedMixin { }; 114 class SupplementTracing<true> : public GarbageCollectedMixin { };
117 115
118 template<> 116 template<>
119 class SupplementTracing<false> { 117 class SupplementTracing<false> {
120 public: 118 public:
121 virtual ~SupplementTracing() { } 119 virtual ~SupplementTracing() { }
120 // FIXME: Oilpan: this trace() method is only provided to minimize
121 // the use of ENABLE(OILPAN) for Supplements deriving from the
122 // transition type WillBeHeapSupplement<>.
123 //
124 // When that transition type is removed (or its use is substantially
125 // reduced), remove this dummy trace method also.
122 virtual void trace(Visitor*) { } 126 virtual void trace(Visitor*) { }
123 }; 127 };
124 128
125 template<typename T, bool isGarbageCollected = false> 129 template<typename T, bool isGarbageCollected = false>
126 class SupplementBase : public SupplementTracing<isGarbageCollected> { 130 class SupplementBase : public SupplementTracing<isGarbageCollected> {
127 public: 131 public:
128 #if ENABLE(SECURITY_ASSERT) 132 #if ENABLE(SECURITY_ASSERT)
129 virtual bool isRefCountedWrapper() const { return false; } 133 virtual bool isRefCountedWrapper() const { return false; }
130 #endif 134 #endif
131 135
132 static void provideTo(SupplementableBase<T, isGarbageCollected>& host, const char* key, typename SupplementableTraits<T, isGarbageCollected>::SupplementArgu mentType supplement) 136 static void provideTo(SupplementableBase<T, isGarbageCollected>& host, const char* key, typename SupplementableTraits<T, isGarbageCollected>::SupplementArgu mentType supplement)
133 { 137 {
134 host.provideSupplement(key, supplement); 138 host.provideSupplement(key, supplement);
135 } 139 }
136 140
137 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>& host, const char* key) 141 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>& host, const char* key)
138 { 142 {
139 return host.requireSupplement(key); 143 return host.requireSupplement(key);
140 } 144 }
141 145
142 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>* host, const char* key) 146 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>* host, const char* key)
143 { 147 {
144 return host ? host->requireSupplement(key) : 0; 148 return host ? host->requireSupplement(key) : 0;
145 } 149 }
146 }; 150 };
147 151
152 template<typename T, bool isGarbageCollected>
153 class SupplementableTracing;
154
155 template<typename T>
156 class SupplementableTracing<T, true> : public GarbageCollectedMixin {
157 public:
158 virtual void trace(Visitor* visitor)
159 {
160 visitor->trace(m_supplements);
161 }
162
163 protected:
164 typedef HeapHashMap<const char*, Member<SupplementBase<T, true> >, PtrHash<c onst char*> > SupplementMap;
165 SupplementMap m_supplements;
166 };
167
168 template<typename T>
169 class SupplementableTracing<T, false> {
170 protected:
171 typedef HashMap<const char*, OwnPtr<SupplementBase<T, false> >, PtrHash<cons t char*> > SupplementMap;
172 SupplementMap m_supplements;
173 };
174
148 // Helper class for implementing Supplementable and HeapSupplementable. 175 // Helper class for implementing Supplementable and HeapSupplementable.
149 template<typename T, bool isGarbageCollected = false> 176 template<typename T, bool isGarbageCollected = false>
150 class SupplementableBase { 177 class SupplementableBase : public SupplementableTracing<T, isGarbageCollected> {
151 public: 178 public:
152 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement) 179 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement)
153 { 180 {
154 ASSERT(m_threadId == currentThread()); 181 ASSERT(m_threadId == currentThread());
155 ASSERT(!this->m_supplements.get(key)); 182 ASSERT(!this->m_supplements.get(key));
156 this->m_supplements.set(key, supplement); 183 this->m_supplements.set(key, supplement);
157 } 184 }
158 185
159 void removeSupplement(const char* key) 186 void removeSupplement(const char* key)
160 { 187 {
161 ASSERT(m_threadId == currentThread()); 188 ASSERT(m_threadId == currentThread());
162 this->m_supplements.remove(key); 189 this->m_supplements.remove(key);
163 } 190 }
164 191
165 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key) 192 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key)
166 { 193 {
167 ASSERT(m_threadId == currentThread()); 194 ASSERT(m_threadId == currentThread());
168 return this->m_supplements.get(key); 195 return this->m_supplements.get(key);
169 } 196 }
170 197
171 void reattachThread() 198 void reattachThread()
172 { 199 {
173 #if ENABLE(ASSERT) 200 #if ENABLE(ASSERT)
174 m_threadId = currentThread(); 201 m_threadId = currentThread();
175 #endif 202 #endif
176 } 203 }
177 204
178 // We have a trace method in the SupplementableBase class to ensure we have
179 // the vtable at the first word of the object. However we don't trace the
180 // m_supplements here, but in the partially specialized template subclasses
181 // since we only want to trace it for garbage collected classes.
182 virtual void trace(Visitor*) { }
183
184 // FIXME: Oilpan: Make private and remove this ignore once PersistentHeapSup plementable is removed again.
185 protected:
186 GC_PLUGIN_IGNORE("")
187 typename SupplementableTraits<T, isGarbageCollected>::SupplementMap m_supple ments;
188
189 #if ENABLE(ASSERT) 205 #if ENABLE(ASSERT)
190 protected: 206 protected:
191 SupplementableBase() : m_threadId(currentThread()) { } 207 SupplementableBase() : m_threadId(currentThread()) { }
192 208
193 private: 209 private:
194 ThreadIdentifier m_threadId; 210 ThreadIdentifier m_threadId;
195 #endif 211 #endif
196 }; 212 };
197 213
198 // This class is used to make an on-heap class supplementable. Its supplements
199 // must be HeapSupplement.
200 template<typename T> 214 template<typename T>
201 class HeapSupplement : public SupplementBase<T, true> { }; 215 class HeapSupplement : public SupplementBase<T, true> { };
202 216
203 // FIXME: Oilpan: Move GarbageCollectedMixin to SupplementableBase<T, true> once PersistentHeapSupplementable is removed again.
204 template<typename T> 217 template<typename T>
205 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su pplementableBase<T, true>, public GarbageCollectedMixin { 218 class HeapSupplementable : public SupplementableBase<T, true> { };
206 public:
207 virtual void trace(Visitor* visitor) OVERRIDE
208 {
209 visitor->trace(this->m_supplements);
210 SupplementableBase<T, true>::trace(visitor);
211 }
212 };
213 219
214 template<typename T> 220 template<typename T>
215 class Supplement : public SupplementBase<T, false> { }; 221 class Supplement : public SupplementBase<T, false> { };
216 222
217 // This class is used to make an off-heap class supplementable with off-heap
218 // supplements (Supplement).
219 template<typename T> 223 template<typename T>
220 class GC_PLUGIN_IGNORE("http://crbug.com/395036") Supplementable : public Supple mentableBase<T, false> { 224 class Supplementable : public SupplementableBase<T, false> { };
221 public:
222 virtual void trace(Visitor* visitor)
223 {
224 // No tracing of off-heap supplements. We should not have any Supplement able
225 // object on the heap.
226 COMPILE_ASSERT(!IsGarbageCollectedType<T>::value, GarbageCollectedObject MustBeHeapSupplementable);
227 SupplementableBase<T, false>::trace(visitor);
228 }
229 };
230 225
231 template<typename T> 226 template<typename T>
232 struct ThreadingTrait<SupplementBase<T, true> > { 227 struct ThreadingTrait<SupplementBase<T, true> > {
233 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 228 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
234 }; 229 };
235 230
236 template<typename T> 231 template<typename T>
237 struct ThreadingTrait<SupplementableBase<T, true> > { 232 struct ThreadingTrait<SupplementableBase<T, true> > {
238 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 233 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
239 }; 234 };
240 235
241 } // namespace blink 236 } // namespace blink
242 237
243 #endif // Supplementable_h 238 #endif // Supplementable_h
OLDNEW
« no previous file with comments | « Source/platform/RefCountedSupplement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698