Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: Source/heap/Handle.h

Issue 170603003: Use nullptr_t for RefPtr, PassRefPtr and RawPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/xml/parser/XMLDocumentParser.cpp ('k') | Source/heap/HeapTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // handles can be stored in objects and they are not scoped. 202 // handles can be stored in objects and they are not scoped.
203 // Persistent handles must not be used to contain pointers 203 // Persistent handles must not be used to contain pointers
204 // between objects that are in the managed heap. They are only 204 // between objects that are in the managed heap. They are only
205 // meant to point to managed heap objects from variables/members 205 // meant to point to managed heap objects from variables/members
206 // outside the managed heap. 206 // outside the managed heap.
207 // 207 //
208 // A Persistent is always a GC root from the point of view of 208 // A Persistent is always a GC root from the point of view of
209 // the garbage collector. 209 // the garbage collector.
210 template<typename T, typename RootsAccessor /* = ThreadLocalPersistents<Threadin gTrait<T>::Affinity > */ > 210 template<typename T, typename RootsAccessor /* = ThreadLocalPersistents<Threadin gTrait<T>::Affinity > */ >
211 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces sor> > { 211 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces sor> > {
212 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Persistent);
213 WTF_DISALLOW_ZERO_ASSIGNMENT(Persistent);
212 public: 214 public:
213 Persistent() : m_raw(0) { } 215 Persistent() : m_raw(0) { }
216 Persistent(std::nullptr_t) : m_raw(0) { }
214 217
215 Persistent(T* raw) : m_raw(raw) { } 218 Persistent(T* raw) : m_raw(raw) { }
216 219
217 Persistent(const Persistent& other) : m_raw(other) { } 220 Persistent(const Persistent& other) : m_raw(other) { }
218 221
219 template<typename U> 222 template<typename U>
220 Persistent(const Persistent<U, RootsAccessor>& other) : m_raw(other) { } 223 Persistent(const Persistent<U, RootsAccessor>& other) : m_raw(other) { }
221 224
222 template<typename U> 225 template<typename U>
223 Persistent(const Member<U>& other) : m_raw(other) { } 226 Persistent(const Member<U>& other) : m_raw(other) { }
224 227
225 template<typename U> 228 template<typename U>
226 Persistent(const RawPtr<U>& other) : m_raw(other.get()) { } 229 Persistent(const RawPtr<U>& other) : m_raw(other.get()) { }
227 230
228 template<typename U> 231 template<typename U>
229 Persistent& operator=(U* other) 232 Persistent& operator=(U* other)
230 { 233 {
231 m_raw = other; 234 m_raw = other;
232 return *this; 235 return *this;
233 } 236 }
237
238 Persistent& operator=(std::nullptr_t)
239 {
240 m_raw = 0;
241 return *this;
242 }
243
234 void clear() { m_raw = 0; } 244 void clear() { m_raw = 0; }
235 245
236 virtual ~Persistent() 246 virtual ~Persistent()
237 { 247 {
238 m_raw = 0; 248 m_raw = 0;
239 } 249 }
240 250
241 template<typename U> 251 template<typename U>
242 U* as() const 252 U* as() const
243 { 253 {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 template<typename T, size_t inlineCapacity = 0> 333 template<typename T, size_t inlineCapacity = 0>
324 class PersistentHeapVector : public PersistentHeapCollectionBase<HeapVector<T, i nlineCapacity> > { }; 334 class PersistentHeapVector : public PersistentHeapCollectionBase<HeapVector<T, i nlineCapacity> > { };
325 335
326 // Members are used in classes to contain strong pointers to other oilpan heap 336 // Members are used in classes to contain strong pointers to other oilpan heap
327 // allocated objects. 337 // allocated objects.
328 // All Member fields of a class must be traced in the class' trace method. 338 // All Member fields of a class must be traced in the class' trace method.
329 // During the mark phase of the GC all live objects are marked as live and 339 // During the mark phase of the GC all live objects are marked as live and
330 // all Member fields of a live object will be traced marked as live as well. 340 // all Member fields of a live object will be traced marked as live as well.
331 template<typename T> 341 template<typename T>
332 class Member { 342 class Member {
343 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Member);
344 WTF_DISALLOW_ZERO_ASSIGNMENT(Member);
333 public: 345 public:
334 Member() : m_raw(0) { } 346 Member() : m_raw(0) { }
347 Member(std::nullptr_t) : m_raw(0) { }
335 348
336 Member(T* raw) : m_raw(raw) { } 349 Member(T* raw) : m_raw(raw) { }
337 350
338 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) { } 351 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) { }
339 352
340 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); } 353 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); }
341 354
342 template<typename U> 355 template<typename U>
343 Member(const Persistent<U>& other) : m_raw(other) { } 356 Member(const Persistent<U>& other) : m_raw(other) { }
344 357
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return *this; 402 return *this;
390 } 403 }
391 404
392 template<typename U> 405 template<typename U>
393 Member& operator=(RawPtr<U> other) 406 Member& operator=(RawPtr<U> other)
394 { 407 {
395 m_raw = other; 408 m_raw = other;
396 return *this; 409 return *this;
397 } 410 }
398 411
412 Member& operator=(std::nullptr_t)
413 {
414 m_raw = 0;
415 return *this;
416 }
417
399 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); } 418 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); }
400 419
401 T* get() const { return m_raw; } 420 T* get() const { return m_raw; }
402 421
403 void clear() { m_raw = 0; } 422 void clear() { m_raw = 0; }
404 423
405 protected: 424 protected:
406 T* m_raw; 425 T* m_raw;
407 426
408 template<bool x, bool y, bool z, typename U, typename V> friend struct Colle ctionBackingTraceTrait; 427 template<bool x, bool y, bool z, typename U, typename V> friend struct Colle ctionBackingTraceTrait;
(...skipping 20 matching lines...) Expand all
429 }; 448 };
430 449
431 // WeakMember is similar to Member in that it is used to point to other oilpan 450 // WeakMember is similar to Member in that it is used to point to other oilpan
432 // heap allocated objects. 451 // heap allocated objects.
433 // However instead of creating a strong pointer to the object, the WeakMember cr eates 452 // However instead of creating a strong pointer to the object, the WeakMember cr eates
434 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to 453 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to
435 // to a heap allocated object are weak the object will be garbage collected. At the 454 // to a heap allocated object are weak the object will be garbage collected. At the
436 // time of GC the weak pointers will automatically be set to null. 455 // time of GC the weak pointers will automatically be set to null.
437 template<typename T> 456 template<typename T>
438 class WeakMember : public Member<T> { 457 class WeakMember : public Member<T> {
458 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(WeakMember);
459 WTF_DISALLOW_ZERO_ASSIGNMENT(WeakMember);
439 public: 460 public:
440 WeakMember() : Member<T>() { } 461 WeakMember() : Member<T>() { }
462 WeakMember(std::nullptr_t) : Member<T>(nullptr) { }
441 463
442 WeakMember(T* raw) : Member<T>(raw) { } 464 WeakMember(T* raw) : Member<T>(raw) { }
443 465
444 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } 466 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { }
445 467
446 template<typename U> 468 template<typename U>
447 WeakMember(const Persistent<U>& other) : Member<T>(other) { } 469 WeakMember(const Persistent<U>& other) : Member<T>(other) { }
448 470
449 template<typename U> 471 template<typename U>
450 WeakMember(const Member<U>& other) : Member<T>(other) { } 472 WeakMember(const Member<U>& other) : Member<T>(other) { }
(...skipping 19 matching lines...) Expand all
470 return *this; 492 return *this;
471 } 493 }
472 494
473 template<typename U> 495 template<typename U>
474 WeakMember& operator=(const RawPtr<U>& other) 496 WeakMember& operator=(const RawPtr<U>& other)
475 { 497 {
476 this->m_raw = other; 498 this->m_raw = other;
477 return *this; 499 return *this;
478 } 500 }
479 501
502 WeakMember& operator=(std::nullptr_t)
503 {
504 this->m_raw = 0;
505 return *this;
506 }
507
480 private: 508 private:
481 T** cell() const { return const_cast<T**>(&this->m_raw); } 509 T** cell() const { return const_cast<T**>(&this->m_raw); }
482 510
483 friend class Visitor; 511 friend class Visitor;
484 }; 512 };
485 513
486 // Comparison operators between (Weak)Members and Persistents 514 // Comparison operators between (Weak)Members and Persistents
487 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } 515 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); }
488 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } 516 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); }
489 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } 517 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 static const bool canMoveWithMemcpy = true; 641 static const bool canMoveWithMemcpy = true;
614 }; 642 };
615 643
616 template<typename T> struct HashTraits<WebCore::Member<T> > : SimpleClassHashTra its<WebCore::Member<T> > { 644 template<typename T> struct HashTraits<WebCore::Member<T> > : SimpleClassHashTra its<WebCore::Member<T> > {
617 static const bool needsDestruction = false; 645 static const bool needsDestruction = false;
618 // FIXME: The distinction between PeekInType and PassInType is there for 646 // FIXME: The distinction between PeekInType and PassInType is there for
619 // the sake of the reference counting handles. When they are gone the two 647 // the sake of the reference counting handles. When they are gone the two
620 // types can be merged into PassInType. 648 // types can be merged into PassInType.
621 // FIXME: Implement proper const'ness for iterator types. Requires support 649 // FIXME: Implement proper const'ness for iterator types. Requires support
622 // in the marking Visitor. 650 // in the marking Visitor.
623 typedef T* PeekInType; 651 typedef RawPtr<T> PeekInType;
624 typedef T* PassInType; 652 typedef RawPtr<T> PassInType;
625 typedef WebCore::Member<T>* IteratorGetType; 653 typedef WebCore::Member<T>* IteratorGetType;
626 typedef const WebCore::Member<T>* IteratorConstGetType; 654 typedef const WebCore::Member<T>* IteratorConstGetType;
627 typedef T* IteratorReferenceType; 655 typedef T* IteratorReferenceType;
628 typedef T* IteratorConstReferenceType; 656 typedef T* IteratorConstReferenceType;
629 static IteratorConstGetType getToConstGetConversion(const WebCore::Member<T> * x) { return x->get(); } 657 static IteratorConstGetType getToConstGetConversion(const WebCore::Member<T> * x) { return x->get(); }
630 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x->get(); } 658 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x->get(); }
631 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x->get(); } 659 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x->get(); }
632 // FIXME: Similarly, there is no need for a distinction between PeekOutType 660 // FIXME: Similarly, there is no need for a distinction between PeekOutType
633 // and PassOutType without reference counting. 661 // and PassOutType without reference counting.
634 typedef T* PeekOutType; 662 typedef T* PeekOutType;
635 typedef T* PassOutType; 663 typedef T* PassOutType;
636 664
637 template<typename U> 665 template<typename U>
638 static void store(const U& value, WebCore::Member<T>& storage) { storage = v alue; } 666 static void store(const U& value, WebCore::Member<T>& storage) { storage = v alue; }
639 667
640 static PeekOutType peek(const WebCore::Member<T>& value) { return value; } 668 static PeekOutType peek(const WebCore::Member<T>& value) { return value; }
641 static PassOutType passOut(const WebCore::Member<T>& value) { return value; } 669 static PassOutType passOut(const WebCore::Member<T>& value) { return value; }
642 }; 670 };
643 671
644 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHas hTraits<WebCore::WeakMember<T> > { 672 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHas hTraits<WebCore::WeakMember<T> > {
645 static const bool needsDestruction = false; 673 static const bool needsDestruction = false;
646 // FIXME: The distinction between PeekInType and PassInType is there for 674 // FIXME: The distinction between PeekInType and PassInType is there for
647 // the sake of the reference counting handles. When they are gone the two 675 // the sake of the reference counting handles. When they are gone the two
648 // types can be merged into PassInType. 676 // types can be merged into PassInType.
649 // FIXME: Implement proper const'ness for iterator types. Requires support 677 // FIXME: Implement proper const'ness for iterator types. Requires support
650 // in the marking Visitor. 678 // in the marking Visitor.
651 typedef T* PeekInType; 679 typedef RawPtr<T> PeekInType;
652 typedef T* PassInType; 680 typedef RawPtr<T> PassInType;
653 typedef WebCore::WeakMember<T>* IteratorGetType; 681 typedef WebCore::WeakMember<T>* IteratorGetType;
654 typedef const WebCore::WeakMember<T>* IteratorConstGetType; 682 typedef const WebCore::WeakMember<T>* IteratorConstGetType;
655 typedef T* IteratorReferenceType; 683 typedef T* IteratorReferenceType;
656 typedef T* IteratorConstReferenceType; 684 typedef T* IteratorConstReferenceType;
657 static IteratorConstGetType getToConstGetConversion(const WebCore::WeakMembe r<T>* x) { return x->get(); } 685 static IteratorConstGetType getToConstGetConversion(const WebCore::WeakMembe r<T>* x) { return x->get(); }
658 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x->get(); } 686 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x->get(); }
659 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x->get(); } 687 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x->get(); }
660 // FIXME: Similarly, there is no need for a distinction between PeekOutType 688 // FIXME: Similarly, there is no need for a distinction between PeekOutType
661 // and PassOutType without reference counting. 689 // and PassOutType without reference counting.
662 typedef T* PeekOutType; 690 typedef T* PeekOutType;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 }; 749 };
722 750
723 template<typename T> inline T* getPtr(const WebCore::Member<T>& p) 751 template<typename T> inline T* getPtr(const WebCore::Member<T>& p)
724 { 752 {
725 return p.get(); 753 return p.get();
726 } 754 }
727 755
728 } // namespace WTF 756 } // namespace WTF
729 757
730 #endif 758 #endif
OLDNEW
« no previous file with comments | « Source/core/xml/parser/XMLDocumentParser.cpp ('k') | Source/heap/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698