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

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: Non-Oilpan fixes 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 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<>. Remove when that
123 // transition type is (or its use is greatly reduced.)
haraken 2014/09/23 02:33:46 is => is gone
sof 2014/09/23 05:21:08 Thanks, done.
122 virtual void trace(Visitor*) { } 124 virtual void trace(Visitor*) { }
123 }; 125 };
124 126
125 template<typename T, bool isGarbageCollected = false> 127 template<typename T, bool isGarbageCollected = false>
126 class SupplementBase : public SupplementTracing<isGarbageCollected> { 128 class SupplementBase : public SupplementTracing<isGarbageCollected> {
127 public: 129 public:
128 #if ENABLE(SECURITY_ASSERT) 130 #if ENABLE(SECURITY_ASSERT)
129 virtual bool isRefCountedWrapper() const { return false; } 131 virtual bool isRefCountedWrapper() const { return false; }
130 #endif 132 #endif
131 133
132 static void provideTo(SupplementableBase<T, isGarbageCollected>& host, const char* key, typename SupplementableTraits<T, isGarbageCollected>::SupplementArgu mentType supplement) 134 static void provideTo(SupplementableBase<T, isGarbageCollected>& host, const char* key, typename SupplementableTraits<T, isGarbageCollected>::SupplementArgu mentType supplement)
133 { 135 {
134 host.provideSupplement(key, supplement); 136 host.provideSupplement(key, supplement);
135 } 137 }
136 138
137 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>& host, const char* key) 139 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>& host, const char* key)
138 { 140 {
139 return host.requireSupplement(key); 141 return host.requireSupplement(key);
140 } 142 }
141 143
142 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>* host, const char* key) 144 static SupplementBase<T, isGarbageCollected>* from(SupplementableBase<T, isG arbageCollected>* host, const char* key)
143 { 145 {
144 return host ? host->requireSupplement(key) : 0; 146 return host ? host->requireSupplement(key) : 0;
145 } 147 }
146 }; 148 };
147 149
150 template<typename T, bool isGarbageCollected>
151 class SupplementableTracing;
152
153 template<typename T>
154 class SupplementableTracing<T, true> : public GarbageCollectedMixin {
155 public:
156 virtual void trace(Visitor* visitor)
157 {
158 visitor->trace(m_supplements);
159 }
160
161 protected:
162 typedef HeapHashMap<const char*, Member<SupplementBase<T, true> >, PtrHash<c onst char*> > SupplementMap;
163 SupplementMap m_supplements;
164 };
165
166 template<typename T>
167 class SupplementableTracing<T, false> {
168 protected:
169 typedef HashMap<const char*, OwnPtr<SupplementBase<T, false> >, PtrHash<cons t char*> > SupplementMap;
170 SupplementMap m_supplements;
171 };
172
148 // Helper class for implementing Supplementable and HeapSupplementable. 173 // Helper class for implementing Supplementable and HeapSupplementable.
149 template<typename T, bool isGarbageCollected = false> 174 template<typename T, bool isGarbageCollected = false>
150 class SupplementableBase { 175 class SupplementableBase : public SupplementableTracing<T, isGarbageCollected> {
151 public: 176 public:
152 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement) 177 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement)
153 { 178 {
154 ASSERT(m_threadId == currentThread()); 179 ASSERT(m_threadId == currentThread());
155 ASSERT(!this->m_supplements.get(key)); 180 ASSERT(!this->m_supplements.get(key));
156 this->m_supplements.set(key, supplement); 181 this->m_supplements.set(key, supplement);
157 } 182 }
158 183
159 void removeSupplement(const char* key) 184 void removeSupplement(const char* key)
160 { 185 {
161 ASSERT(m_threadId == currentThread()); 186 ASSERT(m_threadId == currentThread());
162 this->m_supplements.remove(key); 187 this->m_supplements.remove(key);
163 } 188 }
164 189
165 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key) 190 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key)
166 { 191 {
167 ASSERT(m_threadId == currentThread()); 192 ASSERT(m_threadId == currentThread());
168 return this->m_supplements.get(key); 193 return this->m_supplements.get(key);
169 } 194 }
170 195
171 void reattachThread() 196 void reattachThread()
172 { 197 {
173 #if ENABLE(ASSERT) 198 #if ENABLE(ASSERT)
174 m_threadId = currentThread(); 199 m_threadId = currentThread();
175 #endif 200 #endif
176 } 201 }
177 202
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) 203 #if ENABLE(ASSERT)
190 protected: 204 protected:
191 SupplementableBase() : m_threadId(currentThread()) { } 205 SupplementableBase() : m_threadId(currentThread()) { }
192 206
193 private: 207 private:
194 ThreadIdentifier m_threadId; 208 ThreadIdentifier m_threadId;
195 #endif 209 #endif
196 }; 210 };
197 211
198 // This class is used to make an on-heap class supplementable. Its supplements
199 // must be HeapSupplement.
200 template<typename T> 212 template<typename T>
201 class HeapSupplement : public SupplementBase<T, true> { }; 213 class HeapSupplement : public SupplementBase<T, true> { };
202 214
203 // FIXME: Oilpan: Move GarbageCollectedMixin to SupplementableBase<T, true> once PersistentHeapSupplementable is removed again.
204 template<typename T> 215 template<typename T>
205 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su pplementableBase<T, true>, public GarbageCollectedMixin { 216 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 217
214 template<typename T> 218 template<typename T>
215 class Supplement : public SupplementBase<T, false> { }; 219 class Supplement : public SupplementBase<T, false> { };
216 220
217 // This class is used to make an off-heap class supplementable with off-heap
218 // supplements (Supplement).
219 template<typename T> 221 template<typename T>
220 class GC_PLUGIN_IGNORE("http://crbug.com/395036") Supplementable : public Supple mentableBase<T, false> { 222 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 223
231 template<typename T> 224 template<typename T>
232 struct ThreadingTrait<SupplementBase<T, true> > { 225 struct ThreadingTrait<SupplementBase<T, true> > {
233 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 226 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
234 }; 227 };
235 228
236 template<typename T> 229 template<typename T>
237 struct ThreadingTrait<SupplementableBase<T, true> > { 230 struct ThreadingTrait<SupplementableBase<T, true> > {
238 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 231 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
239 }; 232 };
240 233
241 } // namespace blink 234 } // namespace blink
242 235
243 #endif // Supplementable_h 236 #endif // Supplementable_h
OLDNEW
« Source/core/workers/WorkerClients.h ('K') | « Source/platform/RefCountedSupplement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698