| 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 #include "wtf/Functional.h" | 12 #include "wtf/Functional.h" |
| 13 #include "wtf/HashFunctions.h" | 13 #include "wtf/HashFunctions.h" |
| 14 #include "wtf/Locker.h" | 14 #include "wtf/Locker.h" |
| 15 #include "wtf/TypeTraits.h" | 15 #include "wtf/TypeTraits.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 template <typename Derived> | 19 template <typename Derived, bool PerThreadHeapEnabled> |
| 20 struct HeapAccessor { |
| 21 static ThreadHeap* heap(Derived* visitor); |
| 22 }; |
| 23 |
| 24 template<typename Derived> |
| 25 struct HeapAccessor<Derived, true> { |
| 26 static ThreadHeap* heap(Derived* visitor) |
| 27 { |
| 28 return &visitor->heap(); |
| 29 } |
| 30 }; |
| 31 |
| 32 template<typename Derived> |
| 33 struct HeapAccessor<Derived, false> { |
| 34 static ThreadHeap* heap(Derived* visitor) |
| 35 { |
| 36 return ThreadHeap::mainThreadHeap(); |
| 37 } |
| 38 }; |
| 39 |
| 40 template <typename Derived, bool PerThreadHeapEnabled> |
| 20 class MarkingVisitorImpl { | 41 class MarkingVisitorImpl { |
| 21 USING_FAST_MALLOC(MarkingVisitorImpl); | 42 USING_FAST_MALLOC(MarkingVisitorImpl); |
| 22 protected: | 43 protected: |
| 23 inline void markHeader(HeapObjectHeader* header, const void* objectPointer,
TraceCallback callback) | 44 inline void markHeader(HeapObjectHeader* header, const void* objectPointer,
TraceCallback callback) |
| 24 { | 45 { |
| 25 ASSERT(header); | 46 ASSERT(header); |
| 26 ASSERT(objectPointer); | 47 ASSERT(objectPointer); |
| 27 if (!toDerived()->shouldMarkObject(objectPointer)) | 48 if (!toDerived()->shouldMarkObject(objectPointer)) |
| 28 return; | 49 return; |
| 29 | 50 |
| 30 // If you hit this ASSERT, it means that there is a dangling pointer | 51 // If you hit this ASSERT, it means that there is a dangling pointer |
| 31 // from a live thread heap to a dead thread heap. We must eliminate | 52 // from a live thread heap to a dead thread heap. We must eliminate |
| 32 // the dangling pointer. | 53 // the dangling pointer. |
| 33 // Release builds don't have the ASSERT, but it is OK because | 54 // Release builds don't have the ASSERT, but it is OK because |
| 34 // release builds will crash in the following header->isMarked() | 55 // release builds will crash in the following header->isMarked() |
| 35 // because all the entries of the orphaned arenas are zapped. | 56 // because all the entries of the orphaned arenas are zapped. |
| 36 ASSERT(!pageFromObject(objectPointer)->orphaned()); | 57 ASSERT(!pageFromObject(objectPointer)->orphaned()); |
| 37 | 58 |
| 38 if (header->isMarked()) | 59 if (header->isMarked()) |
| 39 return; | 60 return; |
| 40 | 61 |
| 41 ASSERT(ThreadState::current()->isInGC()); | 62 ASSERT(ThreadState::current()->isInGC()); |
| 42 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 63 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); |
| 43 | 64 |
| 44 header->mark(); | 65 header->mark(); |
| 45 | 66 |
| 46 if (callback) | 67 if (callback) |
| 47 ThreadHeap::mainThreadHeap()->pushTraceCallback(const_cast<void*>(ob
jectPointer), callback); | 68 getThreadHeap()->pushTraceCallback(const_cast<void*>(objectPointer),
callback); |
| 48 } | 69 } |
| 49 | 70 |
| 50 inline void mark(const void* objectPointer, TraceCallback callback) | 71 inline void mark(const void* objectPointer, TraceCallback callback) |
| 51 { | 72 { |
| 52 if (!objectPointer) | 73 if (!objectPointer) |
| 53 return; | 74 return; |
| 54 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); | 75 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); |
| 55 markHeader(header, header->payload(), callback); | 76 markHeader(header, header->payload(), callback); |
| 56 } | 77 } |
| 57 | 78 |
| 58 inline void registerDelayedMarkNoTracing(const void* objectPointer) | 79 inline void registerDelayedMarkNoTracing(const void* objectPointer) |
| 59 { | 80 { |
| 60 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 81 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); |
| 61 ThreadHeap::mainThreadHeap()->pushPostMarkingCallback(const_cast<void*>(
objectPointer), &markNoTracingCallback); | 82 getThreadHeap()->pushPostMarkingCallback(const_cast<void*>(objectPointer
), &markNoTracingCallback); |
| 62 } | 83 } |
| 63 | 84 |
| 64 inline void registerWeakMembers(const void* closure, const void* objectPoint
er, WeakCallback callback) | 85 inline void registerWeakMembers(const void* closure, const void* objectPoint
er, WeakCallback callback) |
| 65 { | 86 { |
| 66 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 87 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); |
| 67 // We don't want to run weak processings when taking a snapshot. | 88 // We don't want to run weak processings when taking a snapshot. |
| 68 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) | 89 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) |
| 69 return; | 90 return; |
| 70 ThreadHeap::mainThreadHeap()->pushThreadLocalWeakCallback(const_cast<voi
d*>(closure), const_cast<void*>(objectPointer), callback); | 91 getThreadHeap()->pushThreadLocalWeakCallback(const_cast<void*>(closure),
const_cast<void*>(objectPointer), callback); |
| 71 } | 92 } |
| 72 | 93 |
| 73 inline void registerWeakTable(const void* closure, EphemeronCallback iterati
onCallback, EphemeronCallback iterationDoneCallback) | 94 inline void registerWeakTable(const void* closure, EphemeronCallback iterati
onCallback, EphemeronCallback iterationDoneCallback) |
| 74 { | 95 { |
| 75 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 96 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); |
| 76 ThreadHeap::mainThreadHeap()->registerWeakTable(const_cast<void*>(closur
e), iterationCallback, iterationDoneCallback); | 97 getThreadHeap()->registerWeakTable(const_cast<void*>(closure), iteration
Callback, iterationDoneCallback); |
| 77 } | 98 } |
| 78 | 99 |
| 79 #if ENABLE(ASSERT) | 100 #if ENABLE(ASSERT) |
| 80 inline bool weakTableRegistered(const void* closure) | 101 inline bool weakTableRegistered(const void* closure) |
| 81 { | 102 { |
| 82 return ThreadHeap::mainThreadHeap()->weakTableRegistered(closure); | 103 return getThreadHeap()->weakTableRegistered(closure); |
| 83 } | 104 } |
| 84 #endif | 105 #endif |
| 85 | 106 |
| 86 inline bool ensureMarked(const void* objectPointer) | 107 inline bool ensureMarked(const void* objectPointer) |
| 87 { | 108 { |
| 88 if (!objectPointer) | 109 if (!objectPointer) |
| 89 return false; | 110 return false; |
| 90 if (!toDerived()->shouldMarkObject(objectPointer)) | 111 if (!toDerived()->shouldMarkObject(objectPointer)) |
| 91 return false; | 112 return false; |
| 92 #if ENABLE(ASSERT) | 113 #if ENABLE(ASSERT) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 header->mark(); | 124 header->mark(); |
| 104 #endif | 125 #endif |
| 105 return true; | 126 return true; |
| 106 } | 127 } |
| 107 | 128 |
| 108 Derived* toDerived() | 129 Derived* toDerived() |
| 109 { | 130 { |
| 110 return static_cast<Derived*>(this); | 131 return static_cast<Derived*>(this); |
| 111 } | 132 } |
| 112 | 133 |
| 134 ThreadHeap* getThreadHeap() |
| 135 { |
| 136 return HeapAccessor<Derived, PerThreadHeapEnabled>::heap(toDerived()); |
| 137 } |
| 138 |
| 113 protected: | 139 protected: |
| 114 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) | 140 inline void registerWeakCellWithCallback(void** cell, WeakCallback callback) |
| 115 { | 141 { |
| 116 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); | 142 ASSERT(toDerived()->getMarkingMode() != Visitor::WeakProcessing); |
| 117 // We don't want to run weak processings when taking a snapshot. | 143 // We don't want to run weak processings when taking a snapshot. |
| 118 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) | 144 if (toDerived()->getMarkingMode() == Visitor::SnapshotMarking) |
| 119 return; | 145 return; |
| 120 ThreadHeap::mainThreadHeap()->pushGlobalWeakCallback(cell, callback); | 146 getThreadHeap()->pushGlobalWeakCallback(cell, callback); |
| 121 } | 147 } |
| 122 | 148 |
| 123 private: | 149 private: |
| 124 static void markNoTracingCallback(Visitor* visitor, void* object) | 150 static void markNoTracingCallback(Visitor* visitor, void* object) |
| 125 { | 151 { |
| 126 visitor->markNoTracing(object); | 152 visitor->markNoTracing(object); |
| 127 } | 153 } |
| 128 }; | 154 }; |
| 129 | 155 |
| 130 } // namespace blink | 156 } // namespace blink |
| 131 | 157 |
| 132 #endif | 158 #endif |
| OLD | NEW |