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

Side by Side Diff: Source/platform/heap/Visitor.h

Issue 633463002: Rename ObjectAliveTrait::isAlive() to isHeapObjectAlive(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | no next file » | 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 #endif 185 #endif
186 }; 186 };
187 187
188 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { }; 188 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { };
189 189
190 template<typename Collection> 190 template<typename Collection>
191 struct OffHeapCollectionTraceTrait; 191 struct OffHeapCollectionTraceTrait;
192 192
193 template<typename T> 193 template<typename T>
194 struct ObjectAliveTrait { 194 struct ObjectAliveTrait {
195 static bool isAlive(Visitor*, T*); 195 static bool isHeapObjectAlive(Visitor*, T*);
196 }; 196 };
197 197
198 // Visitor is used to traverse the Blink object graph. Used for the 198 // Visitor is used to traverse the Blink object graph. Used for the
199 // marking phase of the mark-sweep garbage collector. 199 // marking phase of the mark-sweep garbage collector.
200 // 200 //
201 // Pointers are marked and pushed on the marking stack by calling the 201 // Pointers are marked and pushed on the marking stack by calling the
202 // |mark| method with the pointer as an argument. 202 // |mark| method with the pointer as an argument.
203 // 203 //
204 // Pointers within objects are traced by calling the |trace| methods 204 // Pointers within objects are traced by calling the |trace| methods
205 // with the object as an argument. Tracing objects will mark all of the 205 // with the object as an argument. Tracing objects will mark all of the
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 { 399 {
400 // Check that we actually know the definition of T when tracing. 400 // Check that we actually know the definition of T when tracing.
401 COMPILE_ASSERT(sizeof(T), WeNeedToKnowTheDefinitionOfTheTypeWeAreTracing ); 401 COMPILE_ASSERT(sizeof(T), WeNeedToKnowTheDefinitionOfTheTypeWeAreTracing );
402 // The strongification of collections relies on the fact that once a 402 // The strongification of collections relies on the fact that once a
403 // collection has been strongified, there is no way that it can contain 403 // collection has been strongified, there is no way that it can contain
404 // non-live entries, so no entries will be removed. Since you can't set 404 // non-live entries, so no entries will be removed. Since you can't set
405 // the mark bit on a null pointer, that means that null pointers are 405 // the mark bit on a null pointer, that means that null pointers are
406 // always 'alive'. 406 // always 'alive'.
407 if (!obj) 407 if (!obj)
408 return true; 408 return true;
409 return ObjectAliveTrait<T>::isAlive(this, obj); 409 return ObjectAliveTrait<T>::isHeapObjectAlive(this, obj);
410 } 410 }
411 template<typename T> inline bool isAlive(const Member<T>& member) 411 template<typename T> inline bool isAlive(const Member<T>& member)
412 { 412 {
413 return isAlive(member.get()); 413 return isAlive(member.get());
414 } 414 }
415 template<typename T> inline bool isAlive(RawPtr<T> ptr) 415 template<typename T> inline bool isAlive(RawPtr<T> ptr)
416 { 416 {
417 return isAlive(ptr.get()); 417 return isAlive(ptr.get());
418 } 418 }
419 419
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 #if ENABLE(ASSERT) 535 #if ENABLE(ASSERT)
536 static void checkGCInfo(Visitor*, const T*) { } 536 static void checkGCInfo(Visitor*, const T*) { }
537 #endif 537 #endif
538 }; 538 };
539 539
540 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAli veTrait; 540 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAli veTrait;
541 541
542 template<typename T> 542 template<typename T>
543 class DefaultObjectAliveTrait<T, false> { 543 class DefaultObjectAliveTrait<T, false> {
544 public: 544 public:
545 static bool isAlive(Visitor* visitor, T* obj) 545 static bool isHeapObjectAlive(Visitor* visitor, T* obj)
546 { 546 {
547 return visitor->isMarked(obj); 547 return visitor->isMarked(obj);
548 } 548 }
549 }; 549 };
550 550
551 template<typename T> 551 template<typename T>
552 class DefaultObjectAliveTrait<T, true> { 552 class DefaultObjectAliveTrait<T, true> {
553 public: 553 public:
554 static bool isAlive(Visitor* visitor, T* obj) 554 static bool isHeapObjectAlive(Visitor* visitor, T* obj)
555 { 555 {
556 return obj->isAlive(visitor); 556 return obj->isHeapObjectAlive(visitor);
557 } 557 }
558 }; 558 };
559 559
560 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T* obj) 560 template<typename T> bool ObjectAliveTrait<T>::isHeapObjectAlive(Visitor* visito r, T* obj)
561 { 561 {
562 return DefaultObjectAliveTrait<T>::isAlive(visitor, obj); 562 return DefaultObjectAliveTrait<T>::isHeapObjectAlive(visitor, obj);
563 } 563 }
564 564
565 // The GarbageCollectedMixin interface and helper macro 565 // The GarbageCollectedMixin interface and helper macro
566 // USING_GARBAGE_COLLECTED_MIXIN can be used to automatically define 566 // USING_GARBAGE_COLLECTED_MIXIN can be used to automatically define
567 // TraceTrait/ObjectAliveTrait on non-leftmost deriving classes 567 // TraceTrait/ObjectAliveTrait on non-leftmost deriving classes
568 // which need to be garbage collected. 568 // which need to be garbage collected.
569 // 569 //
570 // Consider the following case: 570 // Consider the following case:
571 // class B {}; 571 // class B {};
572 // class A : public GarbageCollected, public B {}; 572 // class A : public GarbageCollected, public B {};
573 // 573 //
574 // We can't correctly handle "Member<B> p = &a" as we can't compute addr of 574 // We can't correctly handle "Member<B> p = &a" as we can't compute addr of
575 // object header statically. This can be solved by using GarbageCollectedMixin: 575 // object header statically. This can be solved by using GarbageCollectedMixin:
576 // class B : public GarbageCollectedMixin {}; 576 // class B : public GarbageCollectedMixin {};
577 // class A : public GarbageCollected, public B { 577 // class A : public GarbageCollected, public B {
578 // USING_GARBAGE_COLLECTED_MIXIN(A) 578 // USING_GARBAGE_COLLECTED_MIXIN(A)
579 // }; 579 // };
580 // 580 //
581 // With the helper, as long as we are using Member<B>, TypeTrait<B> will 581 // With the helper, as long as we are using Member<B>, TypeTrait<B> will
582 // dispatch adjustAndMark dynamically to find collect addr of the object header. 582 // dispatch adjustAndMark dynamically to find collect addr of the object header.
583 // Note that this is only enabled for Member<B>. For Member<A> which we can 583 // Note that this is only enabled for Member<B>. For Member<A> which we can
584 // compute the object header addr statically, this dynamic dispatch is not used. 584 // compute the object header addr statically, this dynamic dispatch is not used.
585 585
586 class PLATFORM_EXPORT GarbageCollectedMixin { 586 class PLATFORM_EXPORT GarbageCollectedMixin {
587 public: 587 public:
588 virtual void adjustAndMark(Visitor*) const { }; 588 virtual void adjustAndMark(Visitor*) const { };
589 virtual bool isAlive(Visitor*) const { return true; }; 589 virtual bool isHeapObjectAlive(Visitor*) const { return true; };
590 virtual void trace(Visitor*) { } 590 virtual void trace(Visitor*) { }
591 }; 591 };
592 592
593 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \ 593 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \
594 public: \ 594 public: \
595 virtual void adjustAndMark(blink::Visitor* visitor) const OVERRIDE \ 595 virtual void adjustAndMark(blink::Visitor* visitor) const OVERRIDE \
596 { \ 596 { \
597 typedef WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<TYPE>::Type, blink::GarbageCollected> IsSubclassOfGarbageCollected; \ 597 typedef WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<TYPE>::Type, blink::GarbageCollected> IsSubclassOfGarbageCollected; \
598 COMPILE_ASSERT(IsSubclassOfGarbageCollected::value, OnlyGarbageCollected ObjectsCanHaveGarbageCollectedMixins); \ 598 COMPILE_ASSERT(IsSubclassOfGarbageCollected::value, OnlyGarbageCollected ObjectsCanHaveGarbageCollectedMixins); \
599 visitor->mark(static_cast<const TYPE*>(this), &blink::TraceTrait<TYPE>:: trace); \ 599 visitor->mark(static_cast<const TYPE*>(this), &blink::TraceTrait<TYPE>:: trace); \
600 } \ 600 } \
601 virtual bool isAlive(blink::Visitor* visitor) const OVERRIDE \ 601 virtual bool isHeapObjectAlive(blink::Visitor* visitor) const OVERRIDE \
602 { \ 602 { \
603 return visitor->isAlive(this); \ 603 return visitor->isAlive(this); \
604 } \ 604 } \
605 private: 605 private:
606 606
607 #if ENABLE(OILPAN) 607 #if ENABLE(OILPAN)
608 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) USING_GARBAGE_COLLECTED_MIXI N(TYPE) 608 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) USING_GARBAGE_COLLECTED_MIXI N(TYPE)
609 #else 609 #else
610 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) 610 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE)
611 #endif 611 #endif
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 struct GCInfoTrait { 655 struct GCInfoTrait {
656 static const GCInfo* get() 656 static const GCInfo* get()
657 { 657 {
658 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); 658 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get();
659 } 659 }
660 }; 660 };
661 661
662 } 662 }
663 663
664 #endif 664 #endif
OLDNEW
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698