| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 162 // Helper class for implementing Supplementable, HeapSupplementable, and | |
| 163 // PersistentHeapSupplementable. | |
| 164 template<typename T, bool isGarbageCollected = false> | 162 template<typename T, bool isGarbageCollected = false> |
| 165 class SupplementableBase : public SupplementableTracing<T, isGarbageCollected> { | 163 class SupplementableBase : public SupplementableTracing<T, isGarbageCollected> { |
| 166 public: | 164 public: |
| 167 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) |
| 168 { | 166 { |
| 169 ASSERT(m_threadId == currentThread()); | 167 ASSERT(m_threadId == currentThread()); |
| 170 ASSERT(!this->m_supplements.get(key)); | 168 ASSERT(!this->m_supplements.get(key)); |
| 171 this->m_supplements.set(key, supplement); | 169 this->m_supplements.set(key, supplement); |
| 172 } | 170 } |
| 173 | 171 |
| 174 void removeSupplement(const char* key) | 172 void removeSupplement(const char* key) |
| 175 { | 173 { |
| 176 ASSERT(m_threadId == currentThread()); | 174 ASSERT(m_threadId == currentThread()); |
| 177 this->m_supplements.remove(key); | 175 this->m_supplements.remove(key); |
| 178 } | 176 } |
| 179 | 177 |
| 180 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key) | 178 SupplementBase<T, isGarbageCollected>* requireSupplement(const char* key) |
| 181 { | 179 { |
| 182 ASSERT(m_threadId == currentThread()); | 180 ASSERT(m_threadId == currentThread()); |
| 183 return this->m_supplements.get(key); | 181 return this->m_supplements.get(key); |
| 184 } | 182 } |
| 185 | 183 |
| 186 void reattachThread() | 184 void reattachThread() |
| 187 { | 185 { |
| 188 #if ENABLE(ASSERT) | 186 #if ENABLE(ASSERT) |
| 189 m_threadId = currentThread(); | 187 m_threadId = currentThread(); |
| 190 #endif | 188 #endif |
| 191 } | 189 } |
| 192 | 190 |
| 193 // We have a trace method in the SupplementableBase class to ensure we have | 191 virtual void trace(Visitor* visitor) { visitor->trace(m_supplements); } |
| 194 // the vtable at the first word of the object. However we don't trace the | |
| 195 // m_supplements here, but in the partially specialized template subclasses | |
| 196 // since we only want to trace it for garbage collected classes. | |
| 197 virtual void trace(Visitor*) { } | |
| 198 | 192 |
| 199 void willBeDestroyed() | 193 void willBeDestroyed() |
| 200 { | 194 { |
| 201 typedef typename SupplementableTraits<T, isGarbageCollected>::Supplement
Map::iterator SupplementIterator; | 195 typedef typename SupplementableTraits<T, isGarbageCollected>::Supplement
Map::iterator SupplementIterator; |
| 202 for (SupplementIterator it = m_supplements.begin(); it != m_supplements.
end(); ++it) | 196 for (SupplementIterator it = m_supplements.begin(); it != m_supplements.
end(); ++it) |
| 203 it->value->willBeDestroyed(); | 197 it->value->willBeDestroyed(); |
| 204 } | 198 } |
| 205 | 199 |
| 206 // FIXME: Oilpan: Make private and remove this ignore once PersistentHeapSup
plementable is removed again. | 200 // FIXME: Oilpan: Make private and remove this ignore once PersistentHeapSup
plementable is removed again. |
| 207 protected: | 201 protected: |
| 208 GC_PLUGIN_IGNORE("") | 202 GC_PLUGIN_IGNORE("") |
| 209 typename SupplementableTraits<T, isGarbageCollected>::SupplementMap m_supple
ments; | 203 typename SupplementableTraits<T, isGarbageCollected>::SupplementMap m_supple
ments; |
| 210 | 204 |
| 211 #if ENABLE(ASSERT) | 205 #if ENABLE(ASSERT) |
| 212 protected: | 206 protected: |
| 213 SupplementableBase() : m_threadId(currentThread()) { } | 207 SupplementableBase() : m_threadId(currentThread()) { } |
| 214 | 208 |
| 215 private: | 209 private: |
| 216 ThreadIdentifier m_threadId; | 210 ThreadIdentifier m_threadId; |
| 217 #endif | 211 #endif |
| 218 }; | 212 }; |
| 219 | 213 |
| 220 // This class is used to make an on-heap class supplementable. Its supplements | |
| 221 // must be HeapSupplement. | |
| 222 template<typename T> | 214 template<typename T> |
| 223 class HeapSupplement : public SupplementBase<T, true> { }; | 215 class HeapSupplement : public SupplementBase<T, true> { }; |
| 224 | 216 |
| 225 // FIXME: Oilpan: Move GarbageCollectedMixin to SupplementableBase<T, true> once
PersistentHeapSupplementable is removed again. | 217 // FIXME: Oilpan: Move GarbageCollectedMixin to SupplementableBase<T, true> once
PersistentHeapSupplementable is removed again. |
| 226 template<typename T> | 218 template<typename T> |
| 227 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su
pplementableBase<T, true>, public GarbageCollectedMixin { | 219 class GC_PLUGIN_IGNORE("http://crbug.com/395036") HeapSupplementable : public Su
pplementableBase<T, true>, public GarbageCollectedMixin { |
| 228 public: | 220 public: |
| 229 virtual void trace(Visitor* visitor) OVERRIDE | 221 virtual void trace(Visitor* visitor) { SupplementableBase<T, true>::trace(vi
sitor); } |
| 230 { | |
| 231 visitor->trace(this->m_supplements); | |
| 232 SupplementableBase<T, true>::trace(visitor); | |
| 233 } | |
| 234 }; | 222 }; |
| 235 | 223 |
| 236 // This class is used to make an off-heap class supplementable with supplements | |
| 237 // that are on-heap, aka. HeapSupplements. | |
| 238 template<typename T> | 224 template<typename T> |
| 239 class GC_PLUGIN_IGNORE("http://crbug.com/395036") PersistentHeapSupplementable :
public SupplementableBase<T, true> { | 225 class PersistentHeapSupplementable : public SupplementableBase<T, true> { |
| 240 public: | 226 public: |
| 241 PersistentHeapSupplementable() : m_root(this) { } | 227 PersistentHeapSupplementable() : m_root(this) { } |
| 242 virtual ~PersistentHeapSupplementable() | 228 virtual ~PersistentHeapSupplementable() |
| 243 { | 229 { |
| 244 typedef typename SupplementableTraits<T, true>::SupplementMap::iterator
SupplementIterator; | 230 typedef typename SupplementableTraits<T, true>::SupplementMap::iterator
SupplementIterator; |
| 245 for (SupplementIterator it = this->m_supplements.begin(); it != this->m_
supplements.end(); ++it) | 231 for (SupplementIterator it = this->m_supplements.begin(); it != this->m_
supplements.end(); ++it) |
| 246 it->value->persistentHostHasBeenDestroyed(); | 232 it->value->persistentHostHasBeenDestroyed(); |
| 247 } | 233 } |
| 248 | |
| 249 virtual void trace(Visitor* visitor) | |
| 250 { | |
| 251 visitor->trace(this->m_supplements); | |
| 252 SupplementableBase<T, true>::trace(visitor); | |
| 253 } | |
| 254 | |
| 255 private: | 234 private: |
| 256 class TraceDelegate : PersistentBase<ThreadLocalPersistents<AnyThread>, Trac
eDelegate> { | 235 class TraceDelegate : PersistentBase<ThreadLocalPersistents<AnyThread>, Trac
eDelegate> { |
| 257 public: | 236 public: |
| 258 TraceDelegate(PersistentHeapSupplementable* owner) : m_owner(owner) { } | 237 TraceDelegate(PersistentHeapSupplementable* owner) : m_owner(owner) { } |
| 259 void trace(Visitor* visitor) { m_owner->trace(visitor); } | 238 void trace(Visitor* visitor) { m_owner->trace(visitor); } |
| 260 private: | 239 private: |
| 261 PersistentHeapSupplementable* m_owner; | 240 PersistentHeapSupplementable* m_owner; |
| 262 }; | 241 }; |
| 263 | 242 |
| 264 TraceDelegate m_root; | 243 TraceDelegate m_root; |
| 265 }; | 244 }; |
| 266 | 245 |
| 267 template<typename T> | 246 template<typename T> |
| 268 class Supplement : public SupplementBase<T, false> { }; | 247 class Supplement : public SupplementBase<T, false> { }; |
| 269 | 248 |
| 270 // This class is used to make an off-heap class supplementable with off-heap | |
| 271 // supplements (Supplement). | |
| 272 template<typename T> | 249 template<typename T> |
| 273 class GC_PLUGIN_IGNORE("http://crbug.com/395036") Supplementable : public Supple
mentableBase<T, false> { | 250 class Supplementable : public SupplementableBase<T, false> { }; |
| 274 public: | |
| 275 virtual void trace(Visitor* visitor) | |
| 276 { | |
| 277 // No tracing of off-heap supplements. We should not have any Supplement
able | |
| 278 // object on the heap. Either the object is HeapSupplementable or if it
is | |
| 279 // off heap it should use PersistentHeapSupplementable to trace any on-h
eap | |
| 280 // supplements. | |
| 281 COMPILE_ASSERT(!IsGarbageCollectedType<T>::value, GarbageCollectedObject
MustBeHeapSupplementable); | |
| 282 SupplementableBase<T, false>::trace(visitor); | |
| 283 } | |
| 284 }; | |
| 285 | 251 |
| 286 template<typename T> | 252 template<typename T> |
| 287 struct ThreadingTrait<blink::SupplementBase<T, true> > { | 253 struct ThreadingTrait<blink::SupplementBase<T, true> > { |
| 288 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 254 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 289 }; | 255 }; |
| 290 | 256 |
| 291 template<typename T> | 257 template<typename T> |
| 292 struct ThreadingTrait<blink::SupplementableBase<T, true> > { | 258 struct ThreadingTrait<blink::SupplementableBase<T, true> > { |
| 293 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; | 259 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; |
| 294 }; | 260 }; |
| 295 | 261 |
| 296 } // namespace blink | 262 } // namespace blink |
| 297 | 263 |
| 298 #endif // Supplementable_h | 264 #endif // Supplementable_h |
| OLD | NEW |