Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 } | 186 } |
| 187 | 187 |
| 188 template<typename U> | 188 template<typename U> |
| 189 U* as() const | 189 U* as() const |
| 190 { | 190 { |
| 191 return static_cast<U*>(m_raw); | 191 return static_cast<U*>(m_raw); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void trace(Visitor* visitor) { visitor->mark(m_raw); } | 194 void trace(Visitor* visitor) { visitor->mark(m_raw); } |
| 195 | 195 |
| 196 T* clear() | 196 T* release() |
|
haraken
2014/01/14 13:57:10
Just to confirm: The places where we want to call
Mads Ager (chromium)
2014/01/14 14:03:13
It seems to me that it should mostly be the case t
haraken
2014/01/14 14:23:15
If there are cases where we must not replace RefPt
| |
| 197 { | 197 { |
| 198 T* result = m_raw; | 198 T* result = m_raw; |
| 199 m_raw = 0; | 199 m_raw = 0; |
| 200 return result; | 200 return result; |
| 201 } | 201 } |
| 202 | 202 |
| 203 T& operator*() const { return *m_raw; } | 203 T& operator*() const { return *m_raw; } |
| 204 | 204 |
| 205 bool operator!() const { return !m_raw; } | 205 bool operator!() const { return !m_raw; } |
| 206 | 206 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 227 return *this; | 227 return *this; |
| 228 } | 228 } |
| 229 | 229 |
| 230 template<typename U> | 230 template<typename U> |
| 231 Persistent& operator=(const Member<U>& other) | 231 Persistent& operator=(const Member<U>& other) |
| 232 { | 232 { |
| 233 m_raw = other; | 233 m_raw = other; |
| 234 return *this; | 234 return *this; |
| 235 } | 235 } |
| 236 | 236 |
| 237 T* raw() const { return m_raw; } | 237 T* get() const { return m_raw; } |
| 238 | 238 |
| 239 private: | 239 private: |
| 240 T* m_raw; | 240 T* m_raw; |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 // Members are used in classes to contain strong pointers to other oilpan heap | 243 // Members are used in classes to contain strong pointers to other oilpan heap |
| 244 // allocated objects. | 244 // allocated objects. |
| 245 // All Member fields of a class must be traced in the class' trace method. | 245 // All Member fields of a class must be traced in the class' trace method. |
| 246 // During the mark phase of the GC all live objects are marked as live and | 246 // During the mark phase of the GC all live objects are marked as live and |
| 247 // all Member fields of a live object will be traced marked as live as well. | 247 // all Member fields of a live object will be traced marked as live as well. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 259 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); } | 259 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); } |
| 260 | 260 |
| 261 template<typename U> | 261 template<typename U> |
| 262 Member(const Persistent<U>& other) : m_raw(other) { } | 262 Member(const Persistent<U>& other) : m_raw(other) { } |
| 263 | 263 |
| 264 Member(const Member& other) : m_raw(other) { } | 264 Member(const Member& other) : m_raw(other) { } |
| 265 | 265 |
| 266 template<typename U> | 266 template<typename U> |
| 267 Member(const Member<U>& other) : m_raw(other) { } | 267 Member(const Member<U>& other) : m_raw(other) { } |
| 268 | 268 |
| 269 T* clear() | 269 T* release() |
|
haraken
2014/01/14 13:57:10
Ditto.
| |
| 270 { | 270 { |
| 271 T* result = m_raw; | 271 T* result = m_raw; |
| 272 m_raw = 0; | 272 m_raw = 0; |
| 273 return result; | 273 return result; |
| 274 } | 274 } |
| 275 | 275 |
| 276 template<typename U> | 276 template<typename U> |
| 277 U* as() const | 277 U* as() const |
| 278 { | 278 { |
| 279 return static_cast<U*>(m_raw); | 279 return static_cast<U*>(m_raw); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 314 |
| 315 template<typename U> | 315 template<typename U> |
| 316 Member& operator=(U* other) | 316 Member& operator=(U* other) |
| 317 { | 317 { |
| 318 m_raw = other; | 318 m_raw = other; |
| 319 return *this; | 319 return *this; |
| 320 } | 320 } |
| 321 | 321 |
| 322 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); } | 322 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); } |
| 323 | 323 |
| 324 T* get() const { return m_raw; } | |
| 325 | |
| 324 protected: | 326 protected: |
| 325 T* raw() const { return m_raw; } | |
| 326 | |
| 327 T* m_raw; | 327 T* m_raw; |
| 328 | 328 |
| 329 template<typename U> friend class Member; | 329 template<typename U> friend class Member; |
| 330 template<typename U> friend class Persistent; | 330 template<typename U> friend class Persistent; |
| 331 friend class Visitor; | 331 friend class Visitor; |
| 332 template<typename U> friend struct WTF::PtrHash; | 332 template<typename U> friend struct WTF::PtrHash; |
| 333 // FIXME: Uncomment when HeapObjectHash is moved. | 333 // FIXME: Uncomment when HeapObjectHash is moved. |
| 334 // friend struct HeapObjectHash<T>; | 334 // friend struct HeapObjectHash<T>; |
| 335 friend struct ObjectAliveTrait<Member<T> >; | 335 friend struct ObjectAliveTrait<Member<T> >; |
| 336 template<bool x, bool y, bool z, typename U, typename V> friend struct Colle ctionBackingTraceTrait; | 336 template<bool x, bool y, bool z, typename U, typename V> friend struct Colle ctionBackingTraceTrait; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 template<typename U> friend class WeakMember; | 408 template<typename U> friend class WeakMember; |
| 409 template<typename U> friend class Persistent; | 409 template<typename U> friend class Persistent; |
| 410 friend class Visitor; | 410 friend class Visitor; |
| 411 template<typename U> friend struct WTF::PtrHash; | 411 template<typename U> friend struct WTF::PtrHash; |
| 412 // FIXME: Uncomment when moving HeapObjectHash to trunk. | 412 // FIXME: Uncomment when moving HeapObjectHash to trunk. |
| 413 // friend struct HeapObjectHash<T>; | 413 // friend struct HeapObjectHash<T>; |
| 414 friend struct ObjectAliveTrait<WeakMember<T> >; | 414 friend struct ObjectAliveTrait<WeakMember<T> >; |
| 415 }; | 415 }; |
| 416 | 416 |
| 417 // Comparison operators between (Weak)Members and Persistents | 417 // Comparison operators between (Weak)Members and Persistents |
| 418 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.m_raw == b.m_raw; } | 418 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } |
| 419 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.m_raw != b.m_raw; } | 419 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } |
| 420 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.m_raw == b.m_raw; } | 420 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } |
| 421 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.m_raw != b.m_raw; } | 421 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } |
| 422 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.m_raw == b.m_raw; } | 422 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
| 423 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.m_raw != b.m_raw; } | 423 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } |
| 424 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.m_raw == b.m_raw; } | 424 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } |
| 425 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.m_raw != b.m_raw; } | 425 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } |
| 426 | 426 |
| 427 } // namespace WebCore | 427 } // namespace WebCore |
| 428 | 428 |
| 429 namespace WTF { | 429 namespace WTF { |
| 430 | 430 |
| 431 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas e<false, WebCore::Member<T> > { | 431 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas e<false, WebCore::Member<T> > { |
| 432 static const bool needsDestruction = false; | 432 static const bool needsDestruction = false; |
| 433 static const bool canInitializeWithMemset = true; | 433 static const bool canInitializeWithMemset = true; |
| 434 static const bool canMoveWithMemcpy = true; | 434 static const bool canMoveWithMemcpy = true; |
| 435 }; | 435 }; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 446 // the sake of the reference counting handles. When they are gone the two | 446 // the sake of the reference counting handles. When they are gone the two |
| 447 // types can be merged into PassInType. | 447 // types can be merged into PassInType. |
| 448 // FIXME: Implement proper const'ness for iterator types. Requires support | 448 // FIXME: Implement proper const'ness for iterator types. Requires support |
| 449 // in the marking Visitor. | 449 // in the marking Visitor. |
| 450 typedef T* PeekInType; | 450 typedef T* PeekInType; |
| 451 typedef T* PassInType; | 451 typedef T* PassInType; |
| 452 typedef T* IteratorGetType; | 452 typedef T* IteratorGetType; |
| 453 typedef T* IteratorConstGetType; | 453 typedef T* IteratorConstGetType; |
| 454 typedef T* IteratorReferenceType; | 454 typedef T* IteratorReferenceType; |
| 455 typedef T* IteratorConstReferenceType; | 455 typedef T* IteratorConstReferenceType; |
| 456 static IteratorConstGetType getToConstGetConversion(const WebCore::Member<T> * x) { return x->raw(); } | 456 static IteratorConstGetType getToConstGetConversion(const WebCore::Member<T> * x) { return x->get(); } |
| 457 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x; } | 457 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x; } |
| 458 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x; } | 458 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x; } |
| 459 // FIXME: Similarly, there is no need for a distinction between PeekOutType | 459 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
| 460 // and PassOutType without reference counting. | 460 // and PassOutType without reference counting. |
| 461 typedef T* PeekOutType; | 461 typedef T* PeekOutType; |
| 462 typedef T* PassOutType; | 462 typedef T* PassOutType; |
| 463 | 463 |
| 464 template<typename U> | 464 template<typename U> |
| 465 static void store(const U& value, WebCore::Member<T>& storage) { storage = v alue; } | 465 static void store(const U& value, WebCore::Member<T>& storage) { storage = v alue; } |
| 466 | 466 |
| 467 static PeekOutType peek(const WebCore::Member<T>& value) { return value; } | 467 static PeekOutType peek(const WebCore::Member<T>& value) { return value; } |
| 468 static PassOutType passOut(const WebCore::Member<T>& value) { return value; } | 468 static PassOutType passOut(const WebCore::Member<T>& value) { return value; } |
| 469 }; | 469 }; |
| 470 | 470 |
| 471 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHas hTraits<WebCore::WeakMember<T> > { | 471 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHas hTraits<WebCore::WeakMember<T> > { |
| 472 static const bool needsDestruction = false; | 472 static const bool needsDestruction = false; |
| 473 // FIXME: The distinction between PeekInType and PassInType is there for | 473 // FIXME: The distinction between PeekInType and PassInType is there for |
| 474 // the sake of the reference counting handles. When they are gone the two | 474 // the sake of the reference counting handles. When they are gone the two |
| 475 // types can be merged into PassInType. | 475 // types can be merged into PassInType. |
| 476 // FIXME: Implement proper const'ness for iterator types. Requires support | 476 // FIXME: Implement proper const'ness for iterator types. Requires support |
| 477 // in the marking Visitor. | 477 // in the marking Visitor. |
| 478 typedef T* PeekInType; | 478 typedef T* PeekInType; |
| 479 typedef T* PassInType; | 479 typedef T* PassInType; |
| 480 typedef T* IteratorGetType; | 480 typedef T* IteratorGetType; |
| 481 typedef T* IteratorConstGetType; | 481 typedef T* IteratorConstGetType; |
| 482 typedef T* IteratorReferenceType; | 482 typedef T* IteratorReferenceType; |
| 483 typedef T* IteratorConstReferenceType; | 483 typedef T* IteratorConstReferenceType; |
| 484 static IteratorConstGetType getToConstGetConversion(const WebCore::WeakMembe r<T>* x) { return x->raw(); } | 484 static IteratorConstGetType getToConstGetConversion(const WebCore::WeakMembe r<T>* x) { return x->get(); } |
| 485 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x; } | 485 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x; } |
| 486 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x; } | 486 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x; } |
| 487 // FIXME: Similarly, there is no need for a distinction between PeekOutType | 487 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
| 488 // and PassOutType without reference counting. | 488 // and PassOutType without reference counting. |
| 489 typedef T* PeekOutType; | 489 typedef T* PeekOutType; |
| 490 typedef T* PassOutType; | 490 typedef T* PassOutType; |
| 491 | 491 |
| 492 template<typename U> | 492 template<typename U> |
| 493 static void store(const U& value, WebCore::WeakMember<T>& storage) { storage = value; } | 493 static void store(const U& value, WebCore::WeakMember<T>& storage) { storage = value; } |
| 494 | 494 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 }; | 528 }; |
| 529 | 529 |
| 530 template<typename Key, typename Value, typename Extractor, typename Traits, type name KeyTraits> | 530 template<typename Key, typename Value, typename Extractor, typename Traits, type name KeyTraits> |
| 531 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr aits> > { | 531 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr aits> > { |
| 532 static const bool value = Traits::isWeak; | 532 static const bool value = Traits::isWeak; |
| 533 }; | 533 }; |
| 534 | 534 |
| 535 } // namespace WTF | 535 } // namespace WTF |
| 536 | 536 |
| 537 #endif | 537 #endif |
| OLD | NEW |