OLD | NEW |
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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // the dangling pointer. | 28 // the dangling pointer. |
29 // Release builds don't have the ASSERT, but it is OK because | 29 // Release builds don't have the ASSERT, but it is OK because |
30 // release builds will crash in the following header->isMarked() | 30 // release builds will crash in the following header->isMarked() |
31 // because all the entries of the orphaned arenas are zapped. | 31 // because all the entries of the orphaned arenas are zapped. |
32 ASSERT(!pageFromObject(objectPointer)->orphaned()); | 32 ASSERT(!pageFromObject(objectPointer)->orphaned()); |
33 | 33 |
34 if (header->isMarked()) | 34 if (header->isMarked()) |
35 return; | 35 return; |
36 | 36 |
37 ASSERT(ThreadState::current()->isInGC()); | 37 ASSERT(ThreadState::current()->isInGC()); |
38 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 38 DCHECK(toDerived()->getMarkingMode() != VisitorMarkingMode::WeakProcessing); |
39 | 39 |
40 // A GC should only mark the objects that belong in its heap. | 40 // A GC should only mark the objects that belong in its heap. |
41 DCHECK(&pageFromObject(objectPointer)->arena()->getThreadState()->heap() == | 41 DCHECK(&pageFromObject(objectPointer)->arena()->getThreadState()->heap() == |
42 &toDerived()->heap()); | 42 &toDerived()->heap()); |
43 | 43 |
44 header->mark(); | 44 header->mark(); |
45 | 45 |
46 if (callback) | 46 if (callback) |
47 toDerived()->heap().pushTraceCallback(const_cast<void*>(objectPointer), | 47 toDerived()->heap().pushTraceCallback(const_cast<void*>(objectPointer), |
48 callback); | 48 callback); |
49 } | 49 } |
50 | 50 |
51 inline void mark(const void* objectPointer, TraceCallback callback) { | 51 inline void mark(const void* objectPointer, TraceCallback callback) { |
52 if (!objectPointer) | 52 if (!objectPointer) |
53 return; | 53 return; |
54 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); | 54 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); |
55 markHeader(header, header->payload(), callback); | 55 markHeader(header, header->payload(), callback); |
56 } | 56 } |
57 | 57 |
58 inline void registerDelayedMarkNoTracing(const void* objectPointer) { | 58 inline void registerDelayedMarkNoTracing(const void* objectPointer) { |
59 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 59 DCHECK(toDerived()->getMarkingMode() != VisitorMarkingMode::WeakProcessing); |
60 toDerived()->heap().pushPostMarkingCallback( | 60 toDerived()->heap().pushPostMarkingCallback( |
61 const_cast<void*>(objectPointer), &markNoTracingCallback); | 61 const_cast<void*>(objectPointer), &markNoTracingCallback); |
62 } | 62 } |
63 | 63 |
64 inline void registerWeakMembers(const void* closure, | 64 inline void registerWeakMembers(const void* closure, |
65 const void* objectPointer, | 65 const void* objectPointer, |
66 WeakCallback callback) { | 66 WeakCallback callback) { |
67 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 67 DCHECK(toDerived()->getMarkingMode() != VisitorMarkingMode::WeakProcessing); |
68 // We don't want to run weak processings when taking a snapshot. | 68 // We don't want to run weak processings when taking a snapshot. |
69 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) | 69 if (toDerived()->getMarkingMode() == VisitorMarkingMode::SnapshotMarking) |
70 return; | 70 return; |
71 toDerived()->heap().pushThreadLocalWeakCallback( | 71 toDerived()->heap().pushThreadLocalWeakCallback( |
72 const_cast<void*>(closure), const_cast<void*>(objectPointer), callback); | 72 const_cast<void*>(closure), const_cast<void*>(objectPointer), callback); |
73 } | 73 } |
74 | 74 |
75 inline void registerWeakTable(const void* closure, | 75 inline void registerWeakTable(const void* closure, |
76 EphemeronCallback iterationCallback, | 76 EphemeronCallback iterationCallback, |
77 EphemeronCallback iterationDoneCallback) { | 77 EphemeronCallback iterationDoneCallback) { |
78 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 78 DCHECK(toDerived()->getMarkingMode() != VisitorMarkingMode::WeakProcessing); |
79 toDerived()->heap().registerWeakTable( | 79 toDerived()->heap().registerWeakTable( |
80 const_cast<void*>(closure), iterationCallback, iterationDoneCallback); | 80 const_cast<void*>(closure), iterationCallback, iterationDoneCallback); |
81 } | 81 } |
82 | 82 |
83 #if ENABLE(ASSERT) | 83 #if ENABLE(ASSERT) |
84 inline bool weakTableRegistered(const void* closure) { | 84 inline bool weakTableRegistered(const void* closure) { |
85 return toDerived()->heap().weakTableRegistered(closure); | 85 return toDerived()->heap().weakTableRegistered(closure); |
86 } | 86 } |
87 #endif | 87 #endif |
88 | 88 |
89 inline void registerMovingObjectReference(MovableReference* slot) { | 89 inline void registerMovingObjectReference(MovableReference* slot) { |
90 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction) | 90 if (toDerived()->getMarkingMode() != |
| 91 VisitorMarkingMode::GlobalMarkingWithCompaction) |
91 return; | 92 return; |
92 toDerived()->heap().registerMovingObjectReference(slot); | 93 toDerived()->heap().registerMovingObjectReference(slot); |
93 } | 94 } |
94 | 95 |
95 inline void registerMovingObjectCallback(MovableReference reference, | 96 inline void registerMovingObjectCallback(MovableReference reference, |
96 MovingObjectCallback callback, | 97 MovingObjectCallback callback, |
97 void* callbackData) { | 98 void* callbackData) { |
98 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction) | 99 if (toDerived()->getMarkingMode() != |
| 100 VisitorMarkingMode::GlobalMarkingWithCompaction) |
99 return; | 101 return; |
100 toDerived()->heap().registerMovingObjectCallback(reference, callback, | 102 toDerived()->heap().registerMovingObjectCallback(reference, callback, |
101 callbackData); | 103 callbackData); |
102 } | 104 } |
103 | 105 |
104 inline bool ensureMarked(const void* objectPointer) { | 106 inline bool ensureMarked(const void* objectPointer) { |
105 if (!objectPointer) | 107 if (!objectPointer) |
106 return false; | 108 return false; |
107 | 109 |
108 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); | 110 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); |
109 if (header->isMarked()) | 111 if (header->isMarked()) |
110 return false; | 112 return false; |
111 #if ENABLE(ASSERT) | 113 #if ENABLE(ASSERT) |
112 toDerived()->markNoTracing(objectPointer); | 114 toDerived()->markNoTracing(objectPointer); |
113 #else | 115 #else |
114 // Inline what the above markNoTracing() call expands to, | 116 // Inline what the above markNoTracing() call expands to, |
115 // so as to make sure that we do get all the benefits (asserts excepted.) | 117 // so as to make sure that we do get all the benefits (asserts excepted.) |
116 header->mark(); | 118 header->mark(); |
117 #endif | 119 #endif |
118 return true; | 120 return true; |
119 } | 121 } |
120 | 122 |
121 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) { | 123 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) { |
122 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 124 DCHECK(toDerived()->getMarkingMode() != VisitorMarkingMode::WeakProcessing); |
123 // We don't want to run weak processings when taking a snapshot. | 125 // We don't want to run weak processings when taking a snapshot. |
124 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) | 126 if (toDerived()->getMarkingMode() == VisitorMarkingMode::SnapshotMarking) |
125 return; | 127 return; |
126 toDerived()->heap().pushGlobalWeakCallback(cell, callback); | 128 toDerived()->heap().pushGlobalWeakCallback(cell, callback); |
127 } | 129 } |
128 | 130 |
129 Derived* toDerived() { return static_cast<Derived*>(this); } | 131 Derived* toDerived() { return static_cast<Derived*>(this); } |
130 | 132 |
131 private: | 133 private: |
132 static void markNoTracingCallback(Visitor* visitor, void* object) { | 134 static void markNoTracingCallback(Visitor* visitor, void* object) { |
133 visitor->markNoTracing(object); | 135 visitor->markNoTracing(object); |
134 } | 136 } |
135 }; | 137 }; |
136 | 138 |
137 } // namespace blink | 139 } // namespace blink |
138 | 140 |
139 #endif | 141 #endif |
OLD | NEW |