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

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

Issue 1166623002: Oilpan: Remove a visitor parameter from isHeapObjectAlive (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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/platform/heap/TraceTraits.h ('k') | Source/web/WebFrame.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) 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 template <typename VisitorDispatcher> \ 134 template <typename VisitorDispatcher> \
135 inline void traceAfterDispatchImpl(VisitorDispatcher visitor) 135 inline void traceAfterDispatchImpl(VisitorDispatcher visitor)
136 136
137 #define EMPTY_MACRO_ARGUMENT 137 #define EMPTY_MACRO_ARGUMENT
138 138
139 #define DECLARE_TRACE() DECLARE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) 139 #define DECLARE_TRACE() DECLARE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT)
140 #define DECLARE_VIRTUAL_TRACE() DECLARE_TRACE_IMPL(virtual) 140 #define DECLARE_VIRTUAL_TRACE() DECLARE_TRACE_IMPL(virtual)
141 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) 141 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT)
142 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) 142 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual)
143 143
144 template<typename T, bool = WTF::IsSubclassOfTemplate<typename WTF::RemoveConst< T>::Type, GarbageCollected>::value> class NeedsAdjustAndMark;
145
146 template<typename T>
147 class NeedsAdjustAndMark<T, true> {
148 static_assert(sizeof(T), "T must be fully defined");
149 public:
150 static const bool value = false;
151 };
152 template <typename T> const bool NeedsAdjustAndMark<T, true>::value;
153
154 template<typename T>
155 class NeedsAdjustAndMark<T, false> {
156 static_assert(sizeof(T), "T must be fully defined");
157 public:
158 static const bool value = IsGarbageCollectedMixin<typename WTF::RemoveConst< T>::Type>::value;
159 };
160 template <typename T> const bool NeedsAdjustAndMark<T, false>::value;
161
162 template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait ;
163
164 template<typename T>
165 class ObjectAliveTrait<T, false> {
166 public:
167 template<typename VisitorDispatcher>
168 static bool isHeapObjectAlive(VisitorDispatcher visitor, T* obj)
169 {
170 static_assert(sizeof(T), "T must be fully defined");
171 return visitor->isMarked(obj);
172 }
173 };
174
175 template<typename T>
176 class ObjectAliveTrait<T, true> {
177 public:
178 template<typename VisitorDispatcher>
179 static bool isHeapObjectAlive(VisitorDispatcher visitor, T* obj)
180 {
181 static_assert(sizeof(T), "T must be fully defined");
182 return obj->isHeapObjectAlive(visitor);
183 }
184 };
185
186 // VisitorHelper contains common implementation of Visitor helper methods. 144 // VisitorHelper contains common implementation of Visitor helper methods.
187 // 145 //
188 // VisitorHelper avoids virtual methods by using CRTP. 146 // VisitorHelper avoids virtual methods by using CRTP.
189 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern 147 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern
190 template<typename Derived> 148 template<typename Derived>
191 class VisitorHelper { 149 class VisitorHelper {
192 public: 150 public:
193 // One-argument templated mark method. This uses the static type of 151 // One-argument templated mark method. This uses the static type of
194 // the argument to get the TraceTrait. By default, the mark method 152 // the argument to get the TraceTrait. By default, the mark method
195 // of the TraceTrait just calls the virtual two-argument mark method on this 153 // of the TraceTrait just calls the virtual two-argument mark method on this
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 template<typename T, void (T::*method)(Visitor*)> 304 template<typename T, void (T::*method)(Visitor*)>
347 void registerWeakMembers(const T* obj) 305 void registerWeakMembers(const T* obj)
348 { 306 {
349 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); 307 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline);
350 } 308 }
351 void registerWeakMembers(const void* object, WeakCallback callback) 309 void registerWeakMembers(const void* object, WeakCallback callback)
352 { 310 {
353 Derived::fromHelper(this)->registerWeakMembers(object, object, callback) ; 311 Derived::fromHelper(this)->registerWeakMembers(object, object, callback) ;
354 } 312 }
355 313
356 template<typename T> inline bool isHeapObjectAlive(T* obj)
357 {
358 static_assert(sizeof(T), "T must be fully defined");
359 // The strongification of collections relies on the fact that once a
360 // collection has been strongified, there is no way that it can contain
361 // non-live entries, so no entries will be removed. Since you can't set
362 // the mark bit on a null pointer, that means that null pointers are
363 // always 'alive'.
364 if (!obj)
365 return true;
366 return ObjectAliveTrait<T>::isHeapObjectAlive(Derived::fromHelper(this), obj);
367 }
368 template<typename T> inline bool isHeapObjectAlive(const Member<T>& member)
369 {
370 return isHeapObjectAlive(member.get());
371 }
372 template<typename T> inline bool isHeapObjectAlive(const WeakMember<T>& memb er)
373 {
374 return isHeapObjectAlive(member.get());
375 }
376 template<typename T> inline bool isHeapObjectAlive(const RawPtr<T>& ptr)
377 {
378 return isHeapObjectAlive(ptr.get());
379 }
380
381 private: 314 private:
382 template <typename T> 315 template<typename T>
383 static void handleWeakCell(Visitor* self, void* obj); 316 static void handleWeakCell(Visitor* self, void* object);
384 }; 317 };
385 318
386 // Visitor is used to traverse the Blink object graph. Used for the 319 // Visitor is used to traverse the Blink object graph. Used for the
387 // marking phase of the mark-sweep garbage collector. 320 // marking phase of the mark-sweep garbage collector.
388 // 321 //
389 // Pointers are marked and pushed on the marking stack by calling the 322 // Pointers are marked and pushed on the marking stack by calling the
390 // |mark| method with the pointer as an argument. 323 // |mark| method with the pointer as an argument.
391 // 324 //
392 // Pointers within objects are traced by calling the |trace| methods 325 // Pointers within objects are traced by calling the |trace| methods
393 // with the object as an argument. Tracing objects will mark all of the 326 // with the object as an argument. Tracing objects will mark all of the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // the weak callback. Since other threads have been resumed the 378 // the weak callback. Since other threads have been resumed the
446 // mark bits are not valid for objects from other threads. 379 // mark bits are not valid for objects from other threads.
447 virtual void registerWeakMembers(const void*, const void*, WeakCallback) = 0 ; 380 virtual void registerWeakMembers(const void*, const void*, WeakCallback) = 0 ;
448 using VisitorHelper<Visitor>::registerWeakMembers; 381 using VisitorHelper<Visitor>::registerWeakMembers;
449 382
450 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0; 383 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0;
451 #if ENABLE(ASSERT) 384 #if ENABLE(ASSERT)
452 virtual bool weakTableRegistered(const void*) = 0; 385 virtual bool weakTableRegistered(const void*) = 0;
453 #endif 386 #endif
454 387
455 virtual bool isMarked(const void*) = 0;
456 virtual bool ensureMarked(const void*) = 0; 388 virtual bool ensureMarked(const void*) = 0;
457 389
458 #if ENABLE(GC_PROFILING) 390 #if ENABLE(GC_PROFILING)
459 void setHostInfo(void* object, const String& name) 391 void setHostInfo(void* object, const String& name)
460 { 392 {
461 m_hostObject = object; 393 m_hostObject = object;
462 m_hostName = name; 394 m_hostName = name;
463 } 395 }
464 #endif 396 #endif
465 397
(...skipping 15 matching lines...) Expand all
481 #if ENABLE(ASSERT) 413 #if ENABLE(ASSERT)
482 virtual void checkMarkingAllowed() { } 414 virtual void checkMarkingAllowed() { }
483 #endif 415 #endif
484 416
485 private: 417 private:
486 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); } 418 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); }
487 419
488 bool m_isGlobalMarkingVisitor; 420 bool m_isGlobalMarkingVisitor;
489 }; 421 };
490 422
491 template <typename Derived>
492 template <typename T>
493 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* obj)
494 {
495 T** cell = reinterpret_cast<T**>(obj);
496 if (*cell && !self->isHeapObjectAlive(*cell))
497 *cell = nullptr;
498 }
499
500 #if ENABLE(GC_PROFILING) 423 #if ENABLE(GC_PROFILING)
501 template<typename T> 424 template<typename T>
502 struct TypenameStringTrait { 425 struct TypenameStringTrait {
503 static const String& get() 426 static const String& get()
504 { 427 {
505 DEFINE_STATIC_LOCAL(String, typenameString, (WTF::extractTypeNameFromFun ctionName(WTF::extractNameFunction<T>()))); 428 DEFINE_STATIC_LOCAL(String, typenameString, (WTF::extractTypeNameFromFun ctionName(WTF::extractNameFunction<T>())));
506 return typenameString; 429 return typenameString;
507 } 430 }
508 }; 431 };
509 #endif 432 #endif
510 433
511 } // namespace blink 434 } // namespace blink
512 435
513 #endif // Visitor_h 436 #endif // Visitor_h
OLDNEW
« no previous file with comments | « Source/platform/heap/TraceTraits.h ('k') | Source/web/WebFrame.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698