| 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" |
| 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 ASSERT(header); |
| 24 ASSERT(objectPointer); | 24 ASSERT(objectPointer); |
| 25 if (!toDerived()->shouldMarkObject(objectPointer)) | |
| 26 return; | |
| 27 | 25 |
| 28 // If you hit this ASSERT, it means that there is a dangling pointer | 26 // If you hit this ASSERT, it means that there is a dangling pointer |
| 29 // from a live thread heap to a dead thread heap. We must eliminate | 27 // from a live thread heap to a dead thread heap. We must eliminate |
| 30 // the dangling pointer. | 28 // the dangling pointer. |
| 31 // 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 |
| 32 // release builds will crash in the following header->isMarked() | 30 // release builds will crash in the following header->isMarked() |
| 33 // because all the entries of the orphaned arenas are zapped. | 31 // because all the entries of the orphaned arenas are zapped. |
| 34 ASSERT(!pageFromObject(objectPointer)->orphaned()); | 32 ASSERT(!pageFromObject(objectPointer)->orphaned()); |
| 35 | 33 |
| 36 if (header->isMarked()) | 34 if (header->isMarked()) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void* callbackData) { | 97 void* callbackData) { |
| 100 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction) | 98 if (toDerived()->getMarkingMode() != Visitor::GlobalMarkingWithCompaction) |
| 101 return; | 99 return; |
| 102 toDerived()->heap().registerMovingObjectCallback(reference, callback, | 100 toDerived()->heap().registerMovingObjectCallback(reference, callback, |
| 103 callbackData); | 101 callbackData); |
| 104 } | 102 } |
| 105 | 103 |
| 106 inline bool ensureMarked(const void* objectPointer) { | 104 inline bool ensureMarked(const void* objectPointer) { |
| 107 if (!objectPointer) | 105 if (!objectPointer) |
| 108 return false; | 106 return false; |
| 109 if (!toDerived()->shouldMarkObject(objectPointer)) | 107 |
| 108 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); |
| 109 if (header->isMarked()) |
| 110 return false; | 110 return false; |
| 111 #if ENABLE(ASSERT) | 111 #if ENABLE(ASSERT) |
| 112 if (HeapObjectHeader::fromPayload(objectPointer)->isMarked()) | |
| 113 return false; | |
| 114 | |
| 115 toDerived()->markNoTracing(objectPointer); | 112 toDerived()->markNoTracing(objectPointer); |
| 116 #else | 113 #else |
| 117 // Inline what the above markNoTracing() call expands to, | 114 // Inline what the above markNoTracing() call expands to, |
| 118 // so as to make sure that we do get all the benefits. | 115 // so as to make sure that we do get all the benefits (asserts excepted.) |
| 119 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); | |
| 120 if (header->isMarked()) | |
| 121 return false; | |
| 122 header->mark(); | 116 header->mark(); |
| 123 #endif | 117 #endif |
| 124 return true; | 118 return true; |
| 125 } | 119 } |
| 126 | 120 |
| 127 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) { | 121 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) { |
| 128 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 122 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); |
| 129 // We don't want to run weak processings when taking a snapshot. | 123 // We don't want to run weak processings when taking a snapshot. |
| 130 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) | 124 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) |
| 131 return; | 125 return; |
| 132 toDerived()->heap().pushGlobalWeakCallback(cell, callback); | 126 toDerived()->heap().pushGlobalWeakCallback(cell, callback); |
| 133 } | 127 } |
| 134 | 128 |
| 135 Derived* toDerived() { return static_cast<Derived*>(this); } | 129 Derived* toDerived() { return static_cast<Derived*>(this); } |
| 136 | 130 |
| 137 private: | 131 private: |
| 138 static void markNoTracingCallback(Visitor* visitor, void* object) { | 132 static void markNoTracingCallback(Visitor* visitor, void* object) { |
| 139 visitor->markNoTracing(object); | 133 visitor->markNoTracing(object); |
| 140 } | 134 } |
| 141 }; | 135 }; |
| 142 | 136 |
| 143 } // namespace blink | 137 } // namespace blink |
| 144 | 138 |
| 145 #endif | 139 #endif |
| OLD | NEW |