OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 VisitorImpl_h | 5 #ifndef VisitorImpl_h |
6 #define VisitorImpl_h | 6 #define VisitorImpl_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 inline void Visitor::markHeader(HeapObjectHeader* header, | 15 inline void Visitor::markHeader(HeapObjectHeader* header, |
16 const void* objectPointer, | 16 const void* objectPointer, |
17 TraceCallback callback) { | 17 TraceCallback callback) { |
18 DCHECK(header); | 18 DCHECK(header); |
19 DCHECK(objectPointer); | 19 DCHECK(objectPointer); |
20 | 20 |
21 if (header->isMarked()) | 21 if (header->isMarked()) |
22 return; | 22 return; |
23 | 23 |
24 DCHECK(ThreadState::current()->isInGC()); | 24 DCHECK(ThreadState::current()->isInGC()); |
25 DCHECK(getMarkingMode() != VisitorMarkingMode::WeakProcessing); | 25 DCHECK(getMarkingMode() != WeakProcessing); |
26 | 26 |
27 // A GC should only mark the objects that belong in its heap. | 27 // A GC should only mark the objects that belong in its heap. |
28 DCHECK(&pageFromObject(objectPointer)->arena()->getThreadState()->heap() == | 28 DCHECK(&pageFromObject(objectPointer)->arena()->getThreadState()->heap() == |
29 &heap()); | 29 &heap()); |
30 | 30 |
31 header->mark(); | 31 header->mark(); |
32 | 32 |
33 if (callback) | 33 if (callback) |
34 heap().pushTraceCallback(const_cast<void*>(objectPointer), callback); | 34 heap().pushTraceCallback(const_cast<void*>(objectPointer), callback); |
35 } | 35 } |
36 | 36 |
37 inline void Visitor::markHeader(HeapObjectHeader* header, | 37 inline void Visitor::markHeader(HeapObjectHeader* header, |
38 TraceCallback callback) { | 38 TraceCallback callback) { |
39 markHeader(header, header->payload(), callback); | 39 markHeader(header, header->payload(), callback); |
40 } | 40 } |
41 | 41 |
42 inline void Visitor::mark(const void* objectPointer, TraceCallback callback) { | 42 inline void Visitor::mark(const void* objectPointer, TraceCallback callback) { |
43 if (!objectPointer) | 43 if (!objectPointer) |
44 return; | 44 return; |
45 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); | 45 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); |
46 markHeader(header, header->payload(), callback); | 46 markHeader(header, header->payload(), callback); |
47 } | 47 } |
48 | 48 |
49 inline void Visitor::markHeaderNoTracing(HeapObjectHeader* header) { | 49 inline void Visitor::markHeaderNoTracing(HeapObjectHeader* header) { |
50 markHeader(header, header->payload(), reinterpret_cast<TraceCallback>(0)); | 50 markHeader(header, header->payload(), reinterpret_cast<TraceCallback>(0)); |
51 } | 51 } |
52 | 52 |
53 inline void Visitor::registerDelayedMarkNoTracing(const void* objectPointer) { | 53 inline void Visitor::registerDelayedMarkNoTracing(const void* objectPointer) { |
54 DCHECK(getMarkingMode() != VisitorMarkingMode::WeakProcessing); | 54 DCHECK(getMarkingMode() != WeakProcessing); |
55 heap().pushPostMarkingCallback(const_cast<void*>(objectPointer), | 55 heap().pushPostMarkingCallback(const_cast<void*>(objectPointer), |
56 &markNoTracingCallback); | 56 &markNoTracingCallback); |
57 } | 57 } |
58 | 58 |
59 inline void Visitor::registerWeakMembers(const void* closure, | 59 inline void Visitor::registerWeakMembers(const void* closure, |
60 const void* objectPointer, | 60 const void* objectPointer, |
61 WeakCallback callback) { | 61 WeakCallback callback) { |
62 DCHECK(getMarkingMode() != VisitorMarkingMode::WeakProcessing); | 62 DCHECK(getMarkingMode() != WeakProcessing); |
63 // We don't want to run weak processings when taking a snapshot. | 63 // We don't want to run weak processings when taking a snapshot. |
64 if (getMarkingMode() == VisitorMarkingMode::SnapshotMarking) | 64 if (getMarkingMode() == SnapshotMarking) |
65 return; | 65 return; |
66 heap().pushThreadLocalWeakCallback( | 66 heap().pushThreadLocalWeakCallback( |
67 const_cast<void*>(closure), const_cast<void*>(objectPointer), callback); | 67 const_cast<void*>(closure), const_cast<void*>(objectPointer), callback); |
68 } | 68 } |
69 | 69 |
70 inline void Visitor::registerWeakTable( | 70 inline void Visitor::registerWeakTable( |
71 const void* closure, | 71 const void* closure, |
72 EphemeronCallback iterationCallback, | 72 EphemeronCallback iterationCallback, |
73 EphemeronCallback iterationDoneCallback) { | 73 EphemeronCallback iterationDoneCallback) { |
74 DCHECK(getMarkingMode() != VisitorMarkingMode::WeakProcessing); | 74 DCHECK(getMarkingMode() != WeakProcessing); |
75 heap().registerWeakTable(const_cast<void*>(closure), iterationCallback, | 75 heap().registerWeakTable(const_cast<void*>(closure), iterationCallback, |
76 iterationDoneCallback); | 76 iterationDoneCallback); |
77 } | 77 } |
78 | 78 |
79 #if DCHECK_IS_ON() | 79 #if DCHECK_IS_ON() |
80 inline bool Visitor::weakTableRegistered(const void* closure) { | 80 inline bool Visitor::weakTableRegistered(const void* closure) { |
81 return heap().weakTableRegistered(closure); | 81 return heap().weakTableRegistered(closure); |
82 } | 82 } |
83 #endif | 83 #endif |
84 | 84 |
85 inline bool Visitor::ensureMarked(const void* objectPointer) { | 85 inline bool Visitor::ensureMarked(const void* objectPointer) { |
86 if (!objectPointer) | 86 if (!objectPointer) |
87 return false; | 87 return false; |
88 | 88 |
89 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); | 89 HeapObjectHeader* header = HeapObjectHeader::fromPayload(objectPointer); |
90 if (header->isMarked()) | 90 if (header->isMarked()) |
91 return false; | 91 return false; |
92 #if DCHECK_IS_ON() | 92 #if DCHECK_IS_ON() |
93 markNoTracing(objectPointer); | 93 markNoTracing(objectPointer); |
94 #else | 94 #else |
95 // Inline what the above markNoTracing() call expands to, | 95 // Inline what the above markNoTracing() call expands to, |
96 // so as to make sure that we do get all the benefits (asserts excepted.) | 96 // so as to make sure that we do get all the benefits (asserts excepted.) |
97 header->mark(); | 97 header->mark(); |
98 #endif | 98 #endif |
99 return true; | 99 return true; |
100 } | 100 } |
101 | 101 |
102 inline void Visitor::registerWeakCellWithCallback(void** cell, | 102 inline void Visitor::registerWeakCellWithCallback(void** cell, |
103 WeakCallback callback) { | 103 WeakCallback callback) { |
104 DCHECK(getMarkingMode() != VisitorMarkingMode::WeakProcessing); | 104 DCHECK(getMarkingMode() != WeakProcessing); |
105 // We don't want to run weak processings when taking a snapshot. | 105 // We don't want to run weak processings when taking a snapshot. |
106 if (getMarkingMode() == VisitorMarkingMode::SnapshotMarking) | 106 if (getMarkingMode() == SnapshotMarking) |
107 return; | 107 return; |
108 heap().pushGlobalWeakCallback(cell, callback); | 108 heap().pushGlobalWeakCallback(cell, callback); |
109 } | 109 } |
110 | 110 |
111 inline void Visitor::registerBackingStoreReference(void* slot) { | 111 inline void Visitor::registerBackingStoreReference(void* slot) { |
112 if (getMarkingMode() != VisitorMarkingMode::GlobalMarkingWithCompaction) | 112 if (getMarkingMode() != GlobalMarkingWithCompaction) |
113 return; | 113 return; |
114 heap().registerMovingObjectReference( | 114 heap().registerMovingObjectReference( |
115 reinterpret_cast<MovableReference*>(slot)); | 115 reinterpret_cast<MovableReference*>(slot)); |
116 } | 116 } |
117 | 117 |
118 inline void Visitor::registerBackingStoreCallback(void* backingStore, | 118 inline void Visitor::registerBackingStoreCallback(void* backingStore, |
119 MovingObjectCallback callback, | 119 MovingObjectCallback callback, |
120 void* callbackData) { | 120 void* callbackData) { |
121 if (getMarkingMode() != VisitorMarkingMode::GlobalMarkingWithCompaction) | 121 if (getMarkingMode() != GlobalMarkingWithCompaction) |
122 return; | 122 return; |
123 heap().registerMovingObjectCallback( | 123 heap().registerMovingObjectCallback( |
124 reinterpret_cast<MovableReference>(backingStore), callback, callbackData); | 124 reinterpret_cast<MovableReference>(backingStore), callback, callbackData); |
125 } | 125 } |
126 | 126 |
127 } // namespace blink | 127 } // namespace blink |
128 | 128 |
129 #endif | 129 #endif |
OLD | NEW |