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() |
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() |
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; | |
330 template<typename U> friend class Persistent; | |
331 friend class Visitor; | |
332 template<typename U> friend struct WTF::PtrHash; | |
333 // FIXME: Uncomment when HeapObjectHash is moved. | |
334 // friend struct HeapObjectHash<T>; | |
335 friend struct ObjectAliveTrait<Member<T> >; | |
336 template<bool x, bool y, bool z, typename U, typename V> friend struct Colle
ctionBackingTraceTrait; | 329 template<bool x, bool y, bool z, typename U, typename V> friend struct Colle
ctionBackingTraceTrait; |
337 template<typename U, typename V> friend bool operator==(const Member<U>&, co
nst Persistent<V>&); | |
338 template<typename U, typename V> friend bool operator!=(const Member<U>&, co
nst Persistent<V>&); | |
339 template<typename U, typename V> friend bool operator==(const Persistent<U>&
, const Member<V>&); | |
340 template<typename U, typename V> friend bool operator!=(const Persistent<U>&
, const Member<V>&); | |
341 template<typename U, typename V> friend bool operator==(const Member<U>&, co
nst Member<V>&); | |
342 template<typename U, typename V> friend bool operator!=(const Member<U>&, co
nst Member<V>&); | |
343 }; | 330 }; |
344 | 331 |
345 template<typename T> | 332 template<typename T> |
346 class TraceTrait<Member<T> > { | 333 class TraceTrait<Member<T> > { |
347 public: | 334 public: |
348 static void trace(Visitor* visitor, void* self) | 335 static void trace(Visitor* visitor, void* self) |
349 { | 336 { |
350 TraceTrait<T>::mark(visitor, *static_cast<Member<T>*>(self)); | 337 TraceTrait<T>::mark(visitor, *static_cast<Member<T>*>(self)); |
351 } | 338 } |
352 }; | 339 }; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 template<typename U> | 384 template<typename U> |
398 WeakMember& operator=(U* other) | 385 WeakMember& operator=(U* other) |
399 { | 386 { |
400 this->m_raw = other; | 387 this->m_raw = other; |
401 return *this; | 388 return *this; |
402 } | 389 } |
403 | 390 |
404 private: | 391 private: |
405 T** cell() const { return const_cast<T**>(&this->m_raw); } | 392 T** cell() const { return const_cast<T**>(&this->m_raw); } |
406 | 393 |
407 template<typename U> friend class Member; | |
408 template<typename U> friend class WeakMember; | |
409 template<typename U> friend class Persistent; | |
410 friend class Visitor; | 394 friend class Visitor; |
411 template<typename U> friend struct WTF::PtrHash; | |
412 // FIXME: Uncomment when moving HeapObjectHash to trunk. | |
413 // friend struct HeapObjectHash<T>; | |
414 friend struct ObjectAliveTrait<WeakMember<T> >; | |
415 }; | 395 }; |
416 | 396 |
417 // Comparison operators between (Weak)Members and Persistents | 397 // 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; } | 398 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; } | 399 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; } | 400 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; } | 401 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; } | 402 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; } | 403 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; } | 404 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; } | 405 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
const Persistent<U>& b) { return a.get() != b.get(); } |
426 | 406 |
427 } // namespace WebCore | 407 } // namespace WebCore |
428 | 408 |
429 namespace WTF { | 409 namespace WTF { |
430 | 410 |
431 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas
e<false, WebCore::Member<T> > { | 411 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas
e<false, WebCore::Member<T> > { |
432 static const bool needsDestruction = false; | 412 static const bool needsDestruction = false; |
433 static const bool canInitializeWithMemset = true; | 413 static const bool canInitializeWithMemset = true; |
434 static const bool canMoveWithMemcpy = true; | 414 static const bool canMoveWithMemcpy = true; |
435 }; | 415 }; |
(...skipping 10 matching lines...) Expand all Loading... |
446 // the sake of the reference counting handles. When they are gone the two | 426 // the sake of the reference counting handles. When they are gone the two |
447 // types can be merged into PassInType. | 427 // types can be merged into PassInType. |
448 // FIXME: Implement proper const'ness for iterator types. Requires support | 428 // FIXME: Implement proper const'ness for iterator types. Requires support |
449 // in the marking Visitor. | 429 // in the marking Visitor. |
450 typedef T* PeekInType; | 430 typedef T* PeekInType; |
451 typedef T* PassInType; | 431 typedef T* PassInType; |
452 typedef T* IteratorGetType; | 432 typedef T* IteratorGetType; |
453 typedef T* IteratorConstGetType; | 433 typedef T* IteratorConstGetType; |
454 typedef T* IteratorReferenceType; | 434 typedef T* IteratorReferenceType; |
455 typedef T* IteratorConstReferenceType; | 435 typedef T* IteratorConstReferenceType; |
456 static IteratorConstGetType getToConstGetConversion(const WebCore::Member<T>
* x) { return x->raw(); } | 436 static IteratorConstGetType getToConstGetConversion(const WebCore::Member<T>
* x) { return x->get(); } |
457 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn x; } | 437 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn x; } |
458 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return x; } | 438 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return x; } |
459 // FIXME: Similarly, there is no need for a distinction between PeekOutType | 439 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
460 // and PassOutType without reference counting. | 440 // and PassOutType without reference counting. |
461 typedef T* PeekOutType; | 441 typedef T* PeekOutType; |
462 typedef T* PassOutType; | 442 typedef T* PassOutType; |
463 | 443 |
464 template<typename U> | 444 template<typename U> |
465 static void store(const U& value, WebCore::Member<T>& storage) { storage = v
alue; } | 445 static void store(const U& value, WebCore::Member<T>& storage) { storage = v
alue; } |
466 | 446 |
467 static PeekOutType peek(const WebCore::Member<T>& value) { return value; } | 447 static PeekOutType peek(const WebCore::Member<T>& value) { return value; } |
468 static PassOutType passOut(const WebCore::Member<T>& value) { return value;
} | 448 static PassOutType passOut(const WebCore::Member<T>& value) { return value;
} |
469 }; | 449 }; |
470 | 450 |
471 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHas
hTraits<WebCore::WeakMember<T> > { | 451 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHas
hTraits<WebCore::WeakMember<T> > { |
472 static const bool needsDestruction = false; | 452 static const bool needsDestruction = false; |
473 // FIXME: The distinction between PeekInType and PassInType is there for | 453 // FIXME: The distinction between PeekInType and PassInType is there for |
474 // the sake of the reference counting handles. When they are gone the two | 454 // the sake of the reference counting handles. When they are gone the two |
475 // types can be merged into PassInType. | 455 // types can be merged into PassInType. |
476 // FIXME: Implement proper const'ness for iterator types. Requires support | 456 // FIXME: Implement proper const'ness for iterator types. Requires support |
477 // in the marking Visitor. | 457 // in the marking Visitor. |
478 typedef T* PeekInType; | 458 typedef T* PeekInType; |
479 typedef T* PassInType; | 459 typedef T* PassInType; |
480 typedef T* IteratorGetType; | 460 typedef T* IteratorGetType; |
481 typedef T* IteratorConstGetType; | 461 typedef T* IteratorConstGetType; |
482 typedef T* IteratorReferenceType; | 462 typedef T* IteratorReferenceType; |
483 typedef T* IteratorConstReferenceType; | 463 typedef T* IteratorConstReferenceType; |
484 static IteratorConstGetType getToConstGetConversion(const WebCore::WeakMembe
r<T>* x) { return x->raw(); } | 464 static IteratorConstGetType getToConstGetConversion(const WebCore::WeakMembe
r<T>* x) { return x->get(); } |
485 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn x; } | 465 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn x; } |
486 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return x; } | 466 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return x; } |
487 // FIXME: Similarly, there is no need for a distinction between PeekOutType | 467 // FIXME: Similarly, there is no need for a distinction between PeekOutType |
488 // and PassOutType without reference counting. | 468 // and PassOutType without reference counting. |
489 typedef T* PeekOutType; | 469 typedef T* PeekOutType; |
490 typedef T* PassOutType; | 470 typedef T* PassOutType; |
491 | 471 |
492 template<typename U> | 472 template<typename U> |
493 static void store(const U& value, WebCore::WeakMember<T>& storage) { storage
= value; } | 473 static void store(const U& value, WebCore::WeakMember<T>& storage) { storage
= value; } |
494 | 474 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 }; | 508 }; |
529 | 509 |
530 template<typename Key, typename Value, typename Extractor, typename Traits, type
name KeyTraits> | 510 template<typename Key, typename Value, typename Extractor, typename Traits, type
name KeyTraits> |
531 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr
aits> > { | 511 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr
aits> > { |
532 static const bool value = Traits::isWeak; | 512 static const bool value = Traits::isWeak; |
533 }; | 513 }; |
534 | 514 |
535 } // namespace WTF | 515 } // namespace WTF |
536 | 516 |
537 #endif | 517 #endif |
OLD | NEW |