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