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

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

Issue 397733004: Allow assertions to be enabled in Blink Release builds. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed config.gni. Minor cleanups. Created 6 years, 5 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "wtf/LinkedHashSet.h" 44 #include "wtf/LinkedHashSet.h"
45 #include "wtf/ListHashSet.h" 45 #include "wtf/ListHashSet.h"
46 #include "wtf/OwnPtr.h" 46 #include "wtf/OwnPtr.h"
47 #include "wtf/RefPtr.h" 47 #include "wtf/RefPtr.h"
48 #include "wtf/TypeTraits.h" 48 #include "wtf/TypeTraits.h"
49 #include "wtf/WeakPtr.h" 49 #include "wtf/WeakPtr.h"
50 #if ENABLE(GC_TRACING) 50 #if ENABLE(GC_TRACING)
51 #include "wtf/text/WTFString.h" 51 #include "wtf/text/WTFString.h"
52 #endif 52 #endif
53 53
54 #ifndef NDEBUG 54 #if ENABLE(ASSERT)
55 #define DEBUG_ONLY(x) x 55 #define DEBUG_ONLY(x) x
56 #else 56 #else
57 #define DEBUG_ONLY(x) 57 #define DEBUG_ONLY(x)
58 #endif 58 #endif
59 59
60 namespace WebCore { 60 namespace WebCore {
61 61
62 class FinalizedHeapObjectHeader; 62 class FinalizedHeapObjectHeader;
63 template<typename T> class GarbageCollectedFinalized; 63 template<typename T> class GarbageCollectedFinalized;
64 class HeapObjectHeader; 64 class HeapObjectHeader;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 static void trace(Visitor* visitor, void* self) 170 static void trace(Visitor* visitor, void* self)
171 { 171 {
172 static_cast<T*>(self)->trace(visitor); 172 static_cast<T*>(self)->trace(visitor);
173 } 173 }
174 174
175 static void mark(Visitor* visitor, const T* t) 175 static void mark(Visitor* visitor, const T* t)
176 { 176 {
177 DefaultTraceTrait<T>::mark(visitor, t); 177 DefaultTraceTrait<T>::mark(visitor, t);
178 } 178 }
179 179
180 #ifndef NDEBUG 180 #if ENABLE(ASSERT)
181 static void checkGCInfo(Visitor* visitor, const T* t) 181 static void checkGCInfo(Visitor* visitor, const T* t)
182 { 182 {
183 DefaultTraceTrait<T>::checkGCInfo(visitor, t); 183 DefaultTraceTrait<T>::checkGCInfo(visitor, t);
184 } 184 }
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>
(...skipping 19 matching lines...) Expand all
210 210
211 // One-argument templated mark method. This uses the static type of 211 // One-argument templated mark method. This uses the static type of
212 // the argument to get the TraceTrait. By default, the mark method 212 // the argument to get the TraceTrait. By default, the mark method
213 // of the TraceTrait just calls the virtual two-argument mark method on this 213 // of the TraceTrait just calls the virtual two-argument mark method on this
214 // visitor, where the second argument is the static trace method of the trai t. 214 // visitor, where the second argument is the static trace method of the trai t.
215 template<typename T> 215 template<typename T>
216 void mark(T* t) 216 void mark(T* t)
217 { 217 {
218 if (!t) 218 if (!t)
219 return; 219 return;
220 #ifndef NDEBUG 220 #if ENABLE(ASSERT)
221 TraceTrait<T>::checkGCInfo(this, t); 221 TraceTrait<T>::checkGCInfo(this, t);
222 #endif 222 #endif
223 TraceTrait<T>::mark(this, t); 223 TraceTrait<T>::mark(this, t);
224 } 224 }
225 225
226 // Member version of the one-argument templated trace method. 226 // Member version of the one-argument templated trace method.
227 template<typename T> 227 template<typename T>
228 void trace(const Member<T>& t) 228 void trace(const Member<T>& t)
229 { 229 {
230 t.verifyTypeIsGarbageCollected(); 230 t.verifyTypeIsGarbageCollected();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // In contrast to registerWeakMembers, the weak cell callbacks are 385 // In contrast to registerWeakMembers, the weak cell callbacks are
386 // run on the thread performing garbage collection. Therefore, all 386 // run on the thread performing garbage collection. Therefore, all
387 // threads are stopped during weak cell callbacks. 387 // threads are stopped during weak cell callbacks.
388 template<typename T> 388 template<typename T>
389 void registerWeakCell(T** cell) 389 void registerWeakCell(T** cell)
390 { 390 {
391 registerWeakCell(reinterpret_cast<void**>(cell), &handleWeakCell<T>); 391 registerWeakCell(reinterpret_cast<void**>(cell), &handleWeakCell<T>);
392 } 392 }
393 393
394 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0; 394 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0;
395 #ifndef NDEBUG 395 #if ENABLE(ASSERT)
396 virtual bool weakTableRegistered(const void*) = 0; 396 virtual bool weakTableRegistered(const void*) = 0;
397 #endif 397 #endif
398 398
399 virtual bool isMarked(const void*) = 0; 399 virtual bool isMarked(const void*) = 0;
400 400
401 template<typename T> inline bool isAlive(T* obj) 401 template<typename T> inline bool isAlive(T* obj)
402 { 402 {
403 // Check that we actually know the definition of T when tracing. 403 // Check that we actually know the definition of T when tracing.
404 COMPILE_ASSERT(sizeof(T), WeNeedToKnowTheDefinitionOfTheTypeWeAreTracing ); 404 COMPILE_ASSERT(sizeof(T), WeNeedToKnowTheDefinitionOfTheTypeWeAreTracing );
405 return !!obj && ObjectAliveTrait<T>::isAlive(this, obj); 405 return !!obj && ObjectAliveTrait<T>::isAlive(this, obj);
406 } 406 }
407 template<typename T> inline bool isAlive(const Member<T>& member) 407 template<typename T> inline bool isAlive(const Member<T>& member)
408 { 408 {
409 return isAlive(member.get()); 409 return isAlive(member.get());
410 } 410 }
411 template<typename T> inline bool isAlive(RawPtr<T> ptr) 411 template<typename T> inline bool isAlive(RawPtr<T> ptr)
412 { 412 {
413 return isAlive(ptr.get()); 413 return isAlive(ptr.get());
414 } 414 }
415 415
416 #ifndef NDEBUG 416 #if ENABLE(ASSERT)
417 void checkGCInfo(const void*, const GCInfo*); 417 void checkGCInfo(const void*, const GCInfo*);
418 #endif 418 #endif
419 419
420 // Macro to declare methods needed for each typed heap. 420 // Macro to declare methods needed for each typed heap.
421 #define DECLARE_VISITOR_METHODS(Type) \ 421 #define DECLARE_VISITOR_METHODS(Type) \
422 DEBUG_ONLY(void checkGCInfo(const Type*, const GCInfo*);) \ 422 DEBUG_ONLY(void checkGCInfo(const Type*, const GCInfo*);) \
423 virtual void mark(const Type*, TraceCallback) = 0; \ 423 virtual void mark(const Type*, TraceCallback) = 0; \
424 virtual bool isMarked(const Type*) = 0; 424 virtual bool isMarked(const Type*) = 0;
425 425
426 FOR_EACH_TYPED_HEAP(DECLARE_VISITOR_METHODS) 426 FOR_EACH_TYPED_HEAP(DECLARE_VISITOR_METHODS)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 public: 574 public:
575 static void mark(Visitor* visitor, const T* t) 575 static void mark(Visitor* visitor, const T* t)
576 { 576 {
577 // Default mark method of the trait just calls the two-argument mark 577 // Default mark method of the trait just calls the two-argument mark
578 // method on the visitor. The second argument is the static trace method 578 // method on the visitor. The second argument is the static trace method
579 // of the trait, which by default calls the instance method 579 // of the trait, which by default calls the instance method
580 // trace(Visitor*) on the object. 580 // trace(Visitor*) on the object.
581 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); 581 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace);
582 } 582 }
583 583
584 #ifndef NDEBUG 584 #if ENABLE(ASSERT)
585 static void checkGCInfo(Visitor* visitor, const T* t) 585 static void checkGCInfo(Visitor* visitor, const T* t)
586 { 586 {
587 visitor->checkGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get()); 587 visitor->checkGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get());
588 } 588 }
589 #endif 589 #endif
590 }; 590 };
591 591
592 template<typename T> 592 template<typename T>
593 class DefaultTraceTrait<T, true> { 593 class DefaultTraceTrait<T, true> {
594 public: 594 public:
595 static void mark(Visitor* visitor, const T* self) 595 static void mark(Visitor* visitor, const T* self)
596 { 596 {
597 if (self) 597 if (self)
598 self->adjustAndMark(visitor); 598 self->adjustAndMark(visitor);
599 } 599 }
600 600
601 #ifndef NDEBUG 601 #if ENABLE(ASSERT)
602 static void checkGCInfo(Visitor*, const T*) { } 602 static void checkGCInfo(Visitor*, const T*) { }
603 #endif 603 #endif
604 }; 604 };
605 605
606 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAli veTrait; 606 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAli veTrait;
607 607
608 template<typename T> 608 template<typename T>
609 class DefaultObjectAliveTrait<T, false> { 609 class DefaultObjectAliveTrait<T, false> {
610 public: 610 public:
611 static bool isAlive(Visitor* visitor, T* obj) 611 static bool isAlive(Visitor* visitor, T* obj)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 struct GCInfoTrait { 720 struct GCInfoTrait {
721 static const GCInfo* get() 721 static const GCInfo* get()
722 { 722 {
723 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); 723 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get();
724 } 724 }
725 }; 725 };
726 726
727 } 727 }
728 728
729 #endif 729 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698