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

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
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 template<typename T, void (T::*method)(Visitor*)> 296 template<typename T, void (T::*method)(Visitor*)>
339 void registerWeakMembers(const T* obj) 297 void registerWeakMembers(const T* obj)
340 { 298 {
341 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); 299 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline);
342 } 300 }
343 void registerWeakMembers(const void* object, WeakCallback callback) 301 void registerWeakMembers(const void* object, WeakCallback callback)
344 { 302 {
345 Derived::fromHelper(this)->registerWeakMembers(object, object, callback) ; 303 Derived::fromHelper(this)->registerWeakMembers(object, object, callback) ;
346 } 304 }
347 305
348 template<typename T> inline bool isHeapObjectAlive(T* obj)
349 {
350 static_assert(sizeof(T), "T must be fully defined");
351 // The strongification of collections relies on the fact that once a
352 // collection has been strongified, there is no way that it can contain
353 // non-live entries, so no entries will be removed. Since you can't set
354 // the mark bit on a null pointer, that means that null pointers are
355 // always 'alive'.
356 if (!obj)
357 return true;
358 return ObjectAliveTrait<T>::isHeapObjectAlive(Derived::fromHelper(this), obj);
359 }
360 template<typename T> inline bool isHeapObjectAlive(const Member<T>& member)
361 {
362 return isHeapObjectAlive(member.get());
363 }
364 template<typename T> inline bool isHeapObjectAlive(const WeakMember<T>& memb er)
365 {
366 return isHeapObjectAlive(member.get());
367 }
368 template<typename T> inline bool isHeapObjectAlive(const RawPtr<T>& ptr)
369 {
370 return isHeapObjectAlive(ptr.get());
371 }
372
373 private: 306 private:
374 template <typename T> 307 template<typename T>
375 static void handleWeakCell(Visitor* self, void* obj); 308 static void handleWeakCell(Visitor* self, void* object);
376 }; 309 };
377 310
378 // Visitor is used to traverse the Blink object graph. Used for the 311 // Visitor is used to traverse the Blink object graph. Used for the
379 // marking phase of the mark-sweep garbage collector. 312 // marking phase of the mark-sweep garbage collector.
380 // 313 //
381 // Pointers are marked and pushed on the marking stack by calling the 314 // Pointers are marked and pushed on the marking stack by calling the
382 // |mark| method with the pointer as an argument. 315 // |mark| method with the pointer as an argument.
383 // 316 //
384 // Pointers within objects are traced by calling the |trace| methods 317 // Pointers within objects are traced by calling the |trace| methods
385 // with the object as an argument. Tracing objects will mark all of the 318 // 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
437 // the weak callback. Since other threads have been resumed the 370 // the weak callback. Since other threads have been resumed the
438 // mark bits are not valid for objects from other threads. 371 // mark bits are not valid for objects from other threads.
439 virtual void registerWeakMembers(const void*, const void*, WeakCallback) = 0 ; 372 virtual void registerWeakMembers(const void*, const void*, WeakCallback) = 0 ;
440 using VisitorHelper<Visitor>::registerWeakMembers; 373 using VisitorHelper<Visitor>::registerWeakMembers;
441 374
442 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0; 375 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0;
443 #if ENABLE(ASSERT) 376 #if ENABLE(ASSERT)
444 virtual bool weakTableRegistered(const void*) = 0; 377 virtual bool weakTableRegistered(const void*) = 0;
445 #endif 378 #endif
446 379
447 virtual bool isMarked(const void*) = 0;
448 virtual bool ensureMarked(const void*) = 0; 380 virtual bool ensureMarked(const void*) = 0;
449 381
450 #if ENABLE(GC_PROFILING) 382 #if ENABLE(GC_PROFILING)
451 void setHostInfo(void* object, const String& name) 383 void setHostInfo(void* object, const String& name)
452 { 384 {
453 m_hostObject = object; 385 m_hostObject = object;
454 m_hostName = name; 386 m_hostName = name;
455 } 387 }
456 #endif 388 #endif
457 389
(...skipping 15 matching lines...) Expand all
473 #if ENABLE(ASSERT) 405 #if ENABLE(ASSERT)
474 virtual void checkMarkingAllowed() { } 406 virtual void checkMarkingAllowed() { }
475 #endif 407 #endif
476 408
477 private: 409 private:
478 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); } 410 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); }
479 411
480 bool m_isGlobalMarkingVisitor; 412 bool m_isGlobalMarkingVisitor;
481 }; 413 };
482 414
483 template <typename Derived>
484 template <typename T>
485 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* obj)
486 {
487 T** cell = reinterpret_cast<T**>(obj);
488 if (*cell && !self->isHeapObjectAlive(*cell))
489 *cell = nullptr;
490 }
491
492 #if ENABLE(GC_PROFILING) 415 #if ENABLE(GC_PROFILING)
493 template<typename T> 416 template<typename T>
494 struct TypenameStringTrait { 417 struct TypenameStringTrait {
495 static const String& get() 418 static const String& get()
496 { 419 {
497 DEFINE_STATIC_LOCAL(String, typenameString, (WTF::extractTypeNameFromFun ctionName(WTF::extractNameFunction<T>()))); 420 DEFINE_STATIC_LOCAL(String, typenameString, (WTF::extractTypeNameFromFun ctionName(WTF::extractNameFunction<T>())));
498 return typenameString; 421 return typenameString;
499 } 422 }
500 }; 423 };
501 #endif 424 #endif
502 425
503 } // namespace blink 426 } // namespace blink
504 427
505 #endif // Visitor_h 428 #endif // Visitor_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698