| 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 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef Handle_h | 31 #ifndef Handle_h |
| 32 #define Handle_h | 32 #define Handle_h |
| 33 | 33 |
| 34 #include "heap/Heap.h" | 34 #include "heap/Heap.h" |
| 35 #include "heap/ThreadState.h" | 35 #include "heap/ThreadState.h" |
| 36 #include "heap/Visitor.h" | 36 #include "heap/Visitor.h" |
| 37 | 37 |
| 38 #include "wtf/Ptr.h" |
| 39 #include "wtf/RefCounted.h" |
| 40 |
| 38 namespace WebCore { | 41 namespace WebCore { |
| 39 | 42 |
| 40 template<typename T> class Member; | 43 template<typename T> class Member; |
| 41 | 44 |
| 42 class PersistentNode { | 45 class PersistentNode { |
| 43 public: | 46 public: |
| 44 explicit PersistentNode(TraceCallback trace) : m_trace(trace) { } | 47 explicit PersistentNode(TraceCallback trace) : m_trace(trace) { } |
| 45 | 48 |
| 46 virtual ~PersistentNode() { } | 49 virtual ~PersistentNode() { } |
| 47 | 50 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Persistent handles must not be used to contain pointers | 155 // Persistent handles must not be used to contain pointers |
| 153 // between objects that are in the managed heap. They are only | 156 // between objects that are in the managed heap. They are only |
| 154 // meant to point to managed heap objects from variables/members | 157 // meant to point to managed heap objects from variables/members |
| 155 // outside the managed heap. | 158 // outside the managed heap. |
| 156 // | 159 // |
| 157 // A Persistent is always a GC root from the point of view of | 160 // A Persistent is always a GC root from the point of view of |
| 158 // the garbage collector. | 161 // the garbage collector. |
| 159 template<typename T> | 162 template<typename T> |
| 160 class Persistent : public PersistentBase<ThreadingTrait<T>::Affinity, Persistent
<T> > { | 163 class Persistent : public PersistentBase<ThreadingTrait<T>::Affinity, Persistent
<T> > { |
| 161 public: | 164 public: |
| 165 #if ENABLE(OILPAN) |
| 166 typedef Persistent<T> FromRefPtr; |
| 167 #else |
| 168 typedef RefPtr<T> FromRefPtr; |
| 169 #endif |
| 170 |
| 162 Persistent() : m_raw(0) { } | 171 Persistent() : m_raw(0) { } |
| 163 | 172 |
| 164 Persistent(T* raw) : m_raw(raw) { } | 173 Persistent(T* raw) : m_raw(raw) { } |
| 165 | 174 |
| 166 Persistent(std::nullptr_t) : m_raw(0) { } | 175 Persistent(std::nullptr_t) : m_raw(0) { } |
| 167 | 176 |
| 168 Persistent(const Persistent& other) : m_raw(other) { } | 177 Persistent(const Persistent& other) : m_raw(other) { } |
| 169 | 178 |
| 170 template<typename U> | 179 template<typename U> |
| 171 Persistent(const Persistent<U>& other) : m_raw(other) { } | 180 Persistent(const Persistent<U>& other) : m_raw(other) { } |
| 172 | 181 |
| 173 template<typename U> | 182 template<typename U> |
| 174 Persistent(const Member<U>& other) : m_raw(other) { } | 183 Persistent(const Member<U>& other) : m_raw(other) { } |
| 175 | 184 |
| 176 template<typename U> | 185 template<typename U> |
| 186 Persistent(const Ptr<U>& other) : m_raw(other.get()) { } |
| 187 |
| 188 template<typename U> |
| 177 Persistent& operator=(U* other) | 189 Persistent& operator=(U* other) |
| 178 { | 190 { |
| 179 m_raw = other; | 191 m_raw = other; |
| 180 return *this; | 192 return *this; |
| 181 } | 193 } |
| 182 | 194 |
| 183 virtual ~Persistent() | 195 virtual ~Persistent() |
| 184 { | 196 { |
| 185 m_raw = 0; | 197 m_raw = 0; |
| 186 } | 198 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 198 T* result = m_raw; | 210 T* result = m_raw; |
| 199 m_raw = 0; | 211 m_raw = 0; |
| 200 return result; | 212 return result; |
| 201 } | 213 } |
| 202 | 214 |
| 203 T& operator*() const { return *m_raw; } | 215 T& operator*() const { return *m_raw; } |
| 204 | 216 |
| 205 bool operator!() const { return !m_raw; } | 217 bool operator!() const { return !m_raw; } |
| 206 | 218 |
| 207 operator T*() const { return m_raw; } | 219 operator T*() const { return m_raw; } |
| 220 operator Ptr<T>() const { return Ptr<T>(m_raw); } |
| 208 | 221 |
| 209 T* operator->() const { return *this; } | 222 T* operator->() const { return *this; } |
| 210 | 223 |
| 211 Persistent& operator=(std::nullptr_t) | 224 Persistent& operator=(std::nullptr_t) |
| 212 { | 225 { |
| 213 m_raw = 0; | 226 m_raw = 0; |
| 214 return *this; | 227 return *this; |
| 215 } | 228 } |
| 216 | 229 |
| 217 Persistent& operator=(const Persistent& other) | 230 Persistent& operator=(const Persistent& other) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 241 }; | 254 }; |
| 242 | 255 |
| 243 // Members are used in classes to contain strong pointers to other oilpan heap | 256 // Members are used in classes to contain strong pointers to other oilpan heap |
| 244 // allocated objects. | 257 // allocated objects. |
| 245 // All Member fields of a class must be traced in the class' trace method. | 258 // 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 | 259 // 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. | 260 // all Member fields of a live object will be traced marked as live as well. |
| 248 template<typename T> | 261 template<typename T> |
| 249 class Member { | 262 class Member { |
| 250 public: | 263 public: |
| 264 #if ENABLE(OILPAN) |
| 265 typedef Member<T> FromRefPtr; |
| 266 typedef Member<T> FromOwnPtr; |
| 267 #else |
| 268 typedef RefPtr<T> FromRefPtr; |
| 269 typedef OwnPtr<T> FromOwnPtr; |
| 270 #endif |
| 271 |
| 251 Member() : m_raw(0) { } | 272 Member() : m_raw(0) { } |
| 252 | 273 |
| 253 Member(T* raw) : m_raw(raw) { } | 274 Member(T* raw) : m_raw(raw) { } |
| 254 | 275 |
| 255 Member(std::nullptr_t) : m_raw(0) { } | 276 Member(std::nullptr_t) : m_raw(0) { } |
| 256 | 277 |
| 257 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) { } | 278 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) { } |
| 258 | 279 |
| 259 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(
-1); } | 280 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(
-1); } |
| 260 | 281 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 361 |
| 341 // WeakMember is similar to Member in that it is used to point to other oilpan | 362 // WeakMember is similar to Member in that it is used to point to other oilpan |
| 342 // heap allocated objects. | 363 // heap allocated objects. |
| 343 // However instead of creating a strong pointer to the object, the WeakMember cr
eates | 364 // However instead of creating a strong pointer to the object, the WeakMember cr
eates |
| 344 // a weak pointer, which does not keep the pointee alive. Hence if all pointers
to | 365 // a weak pointer, which does not keep the pointee alive. Hence if all pointers
to |
| 345 // to a heap allocated object are weak the object will be garbage collected. At
the | 366 // to a heap allocated object are weak the object will be garbage collected. At
the |
| 346 // time of GC the weak pointers will automatically be set to null. | 367 // time of GC the weak pointers will automatically be set to null. |
| 347 template<typename T> | 368 template<typename T> |
| 348 class WeakMember : public Member<T> { | 369 class WeakMember : public Member<T> { |
| 349 public: | 370 public: |
| 371 #if ENABLE(OILPAN) |
| 372 typedef WeakMember<T> FromPtr; |
| 373 #else |
| 374 typedef Ptr<T> FromPtr; |
| 375 #endif |
| 376 |
| 350 WeakMember() : Member<T>() { } | 377 WeakMember() : Member<T>() { } |
| 351 | 378 |
| 352 WeakMember(T* raw) : Member<T>(raw) { } | 379 WeakMember(T* raw) : Member<T>(raw) { } |
| 353 | 380 |
| 354 WeakMember(std::nullptr_t) : Member<T>(nullptr) { } | 381 WeakMember(std::nullptr_t) : Member<T>(nullptr) { } |
| 355 | 382 |
| 356 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } | 383 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } |
| 357 | 384 |
| 358 template<typename U> | 385 template<typename U> |
| 359 WeakMember(const Persistent<U>& other) : Member<T>(other) { } | 386 WeakMember(const Persistent<U>& other) : Member<T>(other) { } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // Comparison operators between (Weak)Members and Persistents | 424 // Comparison operators between (Weak)Members and Persistents |
| 398 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Member<U>& b) { return a.get() == b.get(); } | 425 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Member<U>& b) { return a.get() == b.get(); } |
| 399 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Member<U>& b) { return a.get() != b.get(); } | 426 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Member<U>& b) { return a.get() != b.get(); } |
| 400 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() == b.get(); } | 427 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() == b.get(); } |
| 401 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() != b.get(); } | 428 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons
t Persistent<U>& b) { return a.get() != b.get(); } |
| 402 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Member<U>& b) { return a.get() == b.get(); } | 429 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Member<U>& b) { return a.get() == b.get(); } |
| 403 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Member<U>& b) { return a.get() != b.get(); } | 430 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Member<U>& b) { return a.get() != b.get(); } |
| 404 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() == b.get(); } | 431 template<typename T, typename U> inline bool operator==(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() == b.get(); } |
| 405 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } | 432 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } |
| 406 | 433 |
| 434 #if ENABLE(OILPAN) |
| 435 template<typename T> |
| 436 typename Ptr<T>::FromPassRefPtr adoptRefWillBeNoop(T* ptr) |
| 437 { |
| 438 return Ptr<T>(ptr); |
| 439 } |
| 440 |
| 441 template<typename T> |
| 442 typename Ptr<T>::FromPassOwnPtr adoptPtrWillBeNoop(T* ptr) |
| 443 { |
| 444 return Ptr<T>(ptr); |
| 445 } |
| 446 #else |
| 447 template<typename T> |
| 448 typename Ptr<T>::FromPassRefPtr adoptRefWillBeNoop(T* ptr) |
| 449 { |
| 450 return adoptRef(ptr); |
| 451 } |
| 452 |
| 453 template<typename T> |
| 454 typename Ptr<T>::FromPassOwnPtr adoptPtrWillBeNoop(T* ptr) |
| 455 { |
| 456 return adoptPtr(ptr); |
| 457 } |
| 458 #endif |
| 459 |
| 407 } // namespace WebCore | 460 } // namespace WebCore |
| 408 | 461 |
| 409 namespace WTF { | 462 namespace WTF { |
| 410 | 463 |
| 411 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas
e<false, WebCore::Member<T> > { | 464 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas
e<false, WebCore::Member<T> > { |
| 412 static const bool needsDestruction = false; | 465 static const bool needsDestruction = false; |
| 413 static const bool canInitializeWithMemset = true; | 466 static const bool canInitializeWithMemset = true; |
| 414 static const bool canMoveWithMemcpy = true; | 467 static const bool canMoveWithMemcpy = true; |
| 415 }; | 468 }; |
| 416 | 469 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 }; | 561 }; |
| 509 | 562 |
| 510 template<typename Key, typename Value, typename Extractor, typename Traits, type
name KeyTraits> | 563 template<typename Key, typename Value, typename Extractor, typename Traits, type
name KeyTraits> |
| 511 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr
aits> > { | 564 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr
aits> > { |
| 512 static const bool value = Traits::isWeak; | 565 static const bool value = Traits::isWeak; |
| 513 }; | 566 }; |
| 514 | 567 |
| 515 } // namespace WTF | 568 } // namespace WTF |
| 516 | 569 |
| 517 #endif | 570 #endif |
| OLD | NEW |