Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 template<typename T, bool> | 153 template<typename T, bool> |
| 154 class SupplementableTracing; | 154 class SupplementableTracing; |
| 155 | 155 |
| 156 template<typename T> | 156 template<typename T> |
| 157 class SupplementableTracing<T, true> { }; | 157 class SupplementableTracing<T, true> { }; |
| 158 | 158 |
| 159 template<typename T> | 159 template<typename T> |
| 160 class SupplementableTracing<T, false> { }; | 160 class SupplementableTracing<T, false> { }; |
| 161 | 161 |
|
Erik Corry
2014/07/22 09:37:51
Could we add a comment here a la:
// Helper class
wibling-chromium
2014/07/22 11:03:42
Done.
| |
| 162 template<typename T, bool isGarbageCollected = false> | 162 template<typename T, bool isGarbageCollected = false> |
| 163 class SupplementableBase : public SupplementableTracing<T, isGarbageCollected> { | 163 class SupplementableBase : public SupplementableTracing<T, isGarbageCollected> { |
| 164 public: | 164 public: |
| 165 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement) | 165 void provideSupplement(const char* key, typename SupplementableTraits<T, isG arbageCollected>::SupplementArgumentType supplement) |
| 166 { | 166 { |
| 167 ASSERT(m_threadId == currentThread()); | 167 ASSERT(m_threadId == currentThread()); |
| 168 ASSERT(!this->m_supplements.get(key)); | 168 ASSERT(!this->m_supplements.get(key)); |
| 169 this->m_supplements.set(key, supplement); | 169 this->m_supplements.set(key, supplement); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void removeSupplement(const char* key) | 172 void removeSupplement(const char* key) |
| 173 { | 173 { |
| 174 ASSERT(m_threadId == currentThread()); | 174 ASSERT(m_threadId == currentThread()); |
| 175 this->m_supplements.remove(key); | 175 this->m_supplements.remove(key); |
| 176 } | 176 } |
| 177 | 177 |
| 178 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key) | 178 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key) |
| 179 { | 179 { |
| 180 ASSERT(m_threadId == currentThread()); | 180 ASSERT(m_threadId == currentThread()); |
| 181 return this->m_supplements.get(key); | 181 return this->m_supplements.get(key); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void reattachThread() | 184 void reattachThread() |
| 185 { | 185 { |
| 186 #if ENABLE(ASSERT) | 186 #if ENABLE(ASSERT) |
| 187 m_threadId = currentThread(); | 187 m_threadId = currentThread(); |
| 188 #endif | 188 #endif |
| 189 } | 189 } |
|
Erik Corry
2014/07/22 09:37:51
I think this should have a virtual trace method to
wibling-chromium
2014/07/22 11:03:42
Done. It does require me to add back the GC_PLUGIN
| |
| 190 | 190 |
| 191 virtual void trace(Visitor* visitor) { visitor->trace(m_supplements); } | |
| 192 | |
| 193 void willBeDestroyed() | 191 void willBeDestroyed() |
| 194 { | 192 { |
| 195 typedef typename SupplementableTraits<T, isGarbageCollected>::Supplement Map::iterator SupplementIterator; | 193 typedef typename SupplementableTraits<T, isGarbageCollected>::Supplement Map::iterator SupplementIterator; |
| 196 for (SupplementIterator it = m_supplements.begin(); it != m_supplements. end(); ++it) | 194 for (SupplementIterator it = m_supplements.begin(); it != m_supplements. end(); ++it) |
| 197 it->value->willBeDestroyed(); | 195 it->value->willBeDestroyed(); |
| 198 } | 196 } |
| 199 | 197 |
| 200 // FIXME: Oilpan: Make private and remove this ignore once PersistentHeapSup plementable is removed again. | 198 // FIXME: Oilpan: Make private and remove this ignore once PersistentHeapSup plementable is removed again. |
| 201 protected: | 199 protected: |
| 202 GC_PLUGIN_IGNORE("") | 200 GC_PLUGIN_IGNORE("") |
| 203 typename SupplementableTraits<T, isGarbageCollected>::SupplementMap m_supple ments; | 201 typename SupplementableTraits<T, isGarbageCollected>::SupplementMap m_supple ments; |
| 204 | 202 |
| 205 #if ENABLE(ASSERT) | 203 #if ENABLE(ASSERT) |
| 206 protected: | 204 protected: |
| 207 SupplementableBase() : m_threadId(currentThread()) { } | 205 SupplementableBase() : m_threadId(currentThread()) { } |
| 208 | 206 |
| 209 private: | 207 private: |
| 210 ThreadIdentifier m_threadId; | 208 ThreadIdentifier m_threadId; |
| 211 #endif | 209 #endif |
| 212 }; | 210 }; |
| 213 | 211 |
| 214 template<typename T> | 212 template<typename T> |
| 215 class HeapSupplement : public SupplementBase<T, true> { }; | 213 class HeapSupplement : public SupplementBase<T, true> { }; |
| 216 | 214 |
| 217 // FIXME: Oilpan: Move GarbageCollectedMixin to SupplementableBase<T, true> once PersistentHeapSupplementable is removed again. | 215 // FIXME: Oilpan: Move GarbageCollectedMixin to SupplementableBase<T, true> once PersistentHeapSupplementable is removed again. |
| 218 template<typename T> | 216 template<typename T> |
| 219 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su pplementableBase<T, true>, public GarbageCollectedMixin { | 217 class HeapSupplementable : public SupplementableBase<T, true>, public GarbageCol lectedMixin { |
| 220 public: | 218 public: |
| 221 virtual void trace(Visitor* visitor) { SupplementableBase<T, true>::trace(vi sitor); } | 219 virtual void trace(Visitor* visitor) OVERRIDE { visitor->trace(this->m_suppl ements); } |
| 222 }; | 220 }; |
| 223 | 221 |
| 224 template<typename T> | 222 template<typename T> |
| 225 class PersistentHeapSupplementable : public SupplementableBase<T, true> { | 223 class PersistentHeapSupplementable : public SupplementableBase<T, true> { |
| 226 public: | 224 public: |
| 227 PersistentHeapSupplementable() : m_root(this) { } | 225 PersistentHeapSupplementable() : m_root(this) { } |
| 228 virtual ~PersistentHeapSupplementable() | 226 virtual ~PersistentHeapSupplementable() |
| 229 { | 227 { |
| 230 typedef typename SupplementableTraits<T, true>::SupplementMap::iterator SupplementIterator; | 228 typedef typename SupplementableTraits<T, true>::SupplementMap::iterator SupplementIterator; |
| 231 for (SupplementIterator it = this->m_supplements.begin(); it != this->m_ supplements.end(); ++it) | 229 for (SupplementIterator it = this->m_supplements.begin(); it != this->m_ supplements.end(); ++it) |
| 232 it->value->persistentHostHasBeenDestroyed(); | 230 it->value->persistentHostHasBeenDestroyed(); |
| 233 } | 231 } |
| 232 | |
| 233 virtual void trace(Visitor* visitor) { visitor->trace(this->m_supplements); } | |
| 234 | |
| 234 private: | 235 private: |
| 235 class TraceDelegate : PersistentBase<ThreadLocalPersistents<AnyThread>, Trac eDelegate> { | 236 class TraceDelegate : PersistentBase<ThreadLocalPersistents<AnyThread>, Trac eDelegate> { |
| 236 public: | 237 public: |
| 237 TraceDelegate(PersistentHeapSupplementable* owner) : m_owner(owner) { } | 238 TraceDelegate(PersistentHeapSupplementable* owner) : m_owner(owner) { } |
| 238 void trace(Visitor* visitor) { m_owner->trace(visitor); } | 239 void trace(Visitor* visitor) { m_owner->trace(visitor); } |
| 239 private: | 240 private: |
| 240 PersistentHeapSupplementable* m_owner; | 241 PersistentHeapSupplementable* m_owner; |
| 241 }; | 242 }; |
| 242 | 243 |
| 243 TraceDelegate m_root; | 244 TraceDelegate m_root; |
| 244 }; | 245 }; |
| 245 | 246 |
| 246 template<typename T> | 247 template<typename T> |
| 247 class Supplement : public SupplementBase<T, false> { }; | 248 class Supplement : public SupplementBase<T, false> { }; |
| 248 | 249 |
| 249 template<typename T> | 250 template<typename T> |
| 250 class Supplementable : public SupplementableBase<T, false> { }; | 251 class Supplementable : public SupplementableBase<T, false> { |
| 252 public: | |
| 253 virtual void trace(Visitor*) | |
| 254 { | |
| 255 // No tracing of off-heap supplements. We should not have any Supplement able | |
| 256 // object on the heap. Either the object is HeapSupplementable or if it is | |
| 257 // off heap it should use PersistentHeapSupplementable to trace any on-h eap | |
| 258 // supplements. | |
| 259 COMPILE_ASSERT(!IsGarbageCollectedType<T>::value, GarbageCollectedObject MustBeHeapSupplementable); | |
| 260 } | |
| 261 }; | |
| 251 | 262 |
| 252 template<typename T> | 263 template<typename T> |
| 253 struct ThreadingTrait<blink::SupplementBase<T, true> > { | 264 struct ThreadingTrait<blink::SupplementBase<T, true> > { |
| 254 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 265 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 255 }; | 266 }; |
| 256 | 267 |
| 257 template<typename T> | 268 template<typename T> |
| 258 struct ThreadingTrait<blink::SupplementableBase<T, true> > { | 269 struct ThreadingTrait<blink::SupplementableBase<T, true> > { |
| 259 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 270 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 260 }; | 271 }; |
| 261 | 272 |
| 262 } // namespace blink | 273 } // namespace blink |
| 263 | 274 |
| 264 #endif // Supplementable_h | 275 #endif // Supplementable_h |
| OLD | NEW |