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

Side by Side Diff: third_party/WebKit/Source/platform/heap/MarkingVisitorImpl.h

Issue 2619493003: Replace ASSERTs in platform/heap/ with DCHECKs
Patch Set: temp Created 3 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MarkingVisitorImpl_h 5 #ifndef MarkingVisitorImpl_h
6 #define MarkingVisitorImpl_h 6 #define MarkingVisitorImpl_h
7 7
8 #include "platform/heap/Heap.h" 8 #include "platform/heap/Heap.h"
9 #include "platform/heap/ThreadState.h" 9 #include "platform/heap/ThreadState.h"
10 #include "platform/heap/Visitor.h" 10 #include "platform/heap/Visitor.h"
11 #include "wtf/Allocator.h" 11 #include "wtf/Allocator.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 template <typename Derived> 15 template <typename Derived>
16 class MarkingVisitorImpl { 16 class MarkingVisitorImpl {
17 USING_FAST_MALLOC(MarkingVisitorImpl); 17 USING_FAST_MALLOC(MarkingVisitorImpl);
18 18
19 protected: 19 protected:
20 inline void markHeader(HeapObjectHeader* header, 20 inline void markHeader(HeapObjectHeader* header,
21 const void* objectPointer, 21 const void* objectPointer,
22 TraceCallback callback) { 22 TraceCallback callback) {
23 ASSERT(header); 23 DCHECK(header);
24 ASSERT(objectPointer); 24 DCHECK(objectPointer);
25 if (!toDerived()->shouldMarkObject(objectPointer)) 25 if (!toDerived()->shouldMarkObject(objectPointer))
26 return; 26 return;
27 27
28 // If you hit this ASSERT, it means that there is a dangling pointer 28 // If you hit this DCHECK, it means that there is a dangling pointer
29 // from a live thread heap to a dead thread heap. We must eliminate 29 // from a live thread heap to a dead thread heap. We must eliminate
30 // the dangling pointer. 30 // the dangling pointer.
31 // Release builds don't have the ASSERT, but it is OK because 31 // Release builds don't have the DCHECK, but it is OK because
32 // release builds will crash in the following header->isMarked() 32 // release builds will crash in the following header->isMarked()
33 // because all the entries of the orphaned arenas are zapped. 33 // because all the entries of the orphaned arenas are zapped.
34 ASSERT(!pageFromObject(objectPointer)->orphaned()); 34 DCHECK(!pageFromObject(objectPointer)->orphaned());
35 35
36 if (header->isMarked()) 36 if (header->isMarked())
37 return; 37 return;
38 38
39 ASSERT(ThreadState::current()->isInGC()); 39 DCHECK(ThreadState::current()->isInGC());
40 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); 40 DCHECK(toDerived()->getMarkingMode() != Visitor::WeakProcessing);
41 41
42 // A GC should only mark the objects that belong in its heap. 42 // A GC should only mark the objects that belong in its heap.
43 DCHECK(&pageFromObject(objectPointer)->arena()->getThreadState()->heap() == 43 DCHECK(&pageFromObject(objectPointer)->arena()->getThreadState()->heap() ==
44 &toDerived()->heap()); 44 &toDerived()->heap());
45 45
46 header->mark(); 46 header->mark();
47 47
48 if (callback) 48 if (callback)
49 toDerived()->heap().pushTraceCallback(const_cast<void*>(objectPointer), 49 toDerived()->heap().pushTraceCallback(const_cast<void*>(objectPointer),
50 callback); 50 callback);
51 } 51 }
52 52
53 inline void mark(const void* objectPointer, TraceCallback callback) { 53 inline void mark(const void* objectPointer, TraceCallback callback) {
54 if (!objectPointer) 54 if (!objectPointer)
55 return; 55 return;
56 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); 56 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer);
57 markHeader(header, header->payload(), callback); 57 markHeader(header, header->payload(), callback);
58 } 58 }
59 59
60 inline void registerDelayedMarkNoTracing(const void* objectPointer) { 60 inline void registerDelayedMarkNoTracing(const void* objectPointer) {
61 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); 61 DCHECK(toDerived()->getMarkingMode() != Visitor::WeakProcessing);
62 toDerived()->heap().pushPostMarkingCallback( 62 toDerived()->heap().pushPostMarkingCallback(
63 const_cast<void*>(objectPointer), &markNoTracingCallback); 63 const_cast<void*>(objectPointer), &markNoTracingCallback);
64 } 64 }
65 65
66 inline void registerWeakMembers(const void* closure, 66 inline void registerWeakMembers(const void* closure,
67 const void* objectPointer, 67 const void* objectPointer,
68 WeakCallback callback) { 68 WeakCallback callback) {
69 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); 69 DCHECK(toDerived()->getMarkingMode() != Visitor::WeakProcessing);
70 // We don't want to run weak processings when taking a snapshot. 70 // We don't want to run weak processings when taking a snapshot.
71 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) 71 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking)
72 return; 72 return;
73 toDerived()->heap().pushThreadLocalWeakCallback( 73 toDerived()->heap().pushThreadLocalWeakCallback(
74 const_cast<void*>(closure), const_cast<void*>(objectPointer), callback); 74 const_cast<void*>(closure), const_cast<void*>(objectPointer), callback);
75 } 75 }
76 76
77 inline void registerWeakTable(const void* closure, 77 inline void registerWeakTable(const void* closure,
78 EphemeronCallback iterationCallback, 78 EphemeronCallback iterationCallback,
79 EphemeronCallback iterationDoneCallback) { 79 EphemeronCallback iterationDoneCallback) {
80 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); 80 DCHECK(toDerived()->getMarkingMode() != Visitor::WeakProcessing);
81 toDerived()->heap().registerWeakTable( 81 toDerived()->heap().registerWeakTable(
82 const_cast<void*>(closure), iterationCallback, iterationDoneCallback); 82 const_cast<void*>(closure), iterationCallback, iterationDoneCallback);
83 } 83 }
84 84
85 #if ENABLE(ASSERT) 85 #if DCHECK_IS_ON()
86 inline bool weakTableRegistered(const void* closure) { 86 inline bool weakTableRegistered(const void* closure) {
87 return toDerived()->heap().weakTableRegistered(closure); 87 return toDerived()->heap().weakTableRegistered(closure);
88 } 88 }
89 #endif 89 #endif
90 90
91 inline void registerMovingObjectReference(MovableReference* slot) { 91 inline void registerMovingObjectReference(MovableReference* slot) {
92 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction) 92 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction)
93 return; 93 return;
94 toDerived()->heap().registerMovingObjectReference(slot); 94 toDerived()->heap().registerMovingObjectReference(slot);
95 } 95 }
96 96
97 inline void registerMovingObjectCallback(MovableReference reference, 97 inline void registerMovingObjectCallback(MovableReference reference,
98 MovingObjectCallback callback, 98 MovingObjectCallback callback,
99 void* callbackData) { 99 void* callbackData) {
100 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction) 100 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction)
101 return; 101 return;
102 toDerived()->heap().registerMovingObjectCallback(reference, callback, 102 toDerived()->heap().registerMovingObjectCallback(reference, callback,
103 callbackData); 103 callbackData);
104 } 104 }
105 105
106 inline bool ensureMarked(const void* objectPointer) { 106 inline bool ensureMarked(const void* objectPointer) {
107 if (!objectPointer) 107 if (!objectPointer)
108 return false; 108 return false;
109 if (!toDerived()->shouldMarkObject(objectPointer)) 109 if (!toDerived()->shouldMarkObject(objectPointer))
110 return false; 110 return false;
111 #if ENABLE(ASSERT) 111 #if DCHECK_IS_ON()
112 if (HeapObjectHeader::fromPayload(objectPointer)->isMarked()) 112 if (HeapObjectHeader::fromPayload(objectPointer)->isMarked())
113 return false; 113 return false;
114 114
115 toDerived()->markNoTracing(objectPointer); 115 toDerived()->markNoTracing(objectPointer);
116 #else 116 #else
117 // Inline what the above markNoTracing() call expands to, 117 // Inline what the above markNoTracing() call expands to,
118 // so as to make sure that we do get all the benefits. 118 // so as to make sure that we do get all the benefits.
119 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); 119 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer);
120 if (header->isMarked()) 120 if (header->isMarked())
121 return false; 121 return false;
122 header->mark(); 122 header->mark();
123 #endif 123 #endif
124 return true; 124 return true;
125 } 125 }
126 126
127 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) { 127 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) {
128 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); 128 DCHECK(toDerived()->getMarkingMode() != Visitor::WeakProcessing);
129 // We don't want to run weak processings when taking a snapshot. 129 // We don't want to run weak processings when taking a snapshot.
130 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) 130 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking)
131 return; 131 return;
132 toDerived()->heap().pushGlobalWeakCallback(cell, callback); 132 toDerived()->heap().pushGlobalWeakCallback(cell, callback);
133 } 133 }
134 134
135 Derived* toDerived() { return static_cast<Derived*>(this); } 135 Derived* toDerived() { return static_cast<Derived*>(this); }
136 136
137 private: 137 private:
138 static void markNoTracingCallback(Visitor* visitor, void* object) { 138 static void markNoTracingCallback(Visitor* visitor, void* object) {
139 visitor->markNoTracing(object); 139 visitor->markNoTracing(object);
140 } 140 }
141 }; 141 };
142 142
143 } // namespace blink 143 } // namespace blink
144 144
145 #endif 145 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698