OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 #include "src/heap/incremental-marking.h" | 5 #include "src/heap/incremental-marking.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/compilation-cache.h" | 8 #include "src/compilation-cache.h" |
9 #include "src/conversions.h" | 9 #include "src/conversions.h" |
10 #include "src/heap/gc-idle-time-handler.h" | 10 #include "src/heap/gc-idle-time-handler.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 void IncrementalMarking::RecordWriteIntoCodeSlow(Code* host, RelocInfo* rinfo, | 135 void IncrementalMarking::RecordWriteIntoCodeSlow(Code* host, RelocInfo* rinfo, |
136 Object* value) { | 136 Object* value) { |
137 if (BaseRecordWrite(host, value)) { | 137 if (BaseRecordWrite(host, value)) { |
138 // Object is not going to be rescanned. We need to record the slot. | 138 // Object is not going to be rescanned. We need to record the slot. |
139 heap_->mark_compact_collector()->RecordRelocSlot(host, rinfo, value); | 139 heap_->mark_compact_collector()->RecordRelocSlot(host, rinfo, value); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 void IncrementalMarking::RecordWrites(HeapObject* obj) { | |
145 if (IsMarking()) { | |
146 MarkBit obj_bit = Marking::MarkBitFrom(obj); | |
147 if (Marking::IsBlack(obj_bit)) { | |
148 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); | |
149 if (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR)) { | |
150 chunk->set_progress_bar(0); | |
151 } | |
152 BlackToGreyAndUnshift(obj, obj_bit); | |
153 RestartIfNotMarking(); | |
154 } | |
155 } | |
156 } | |
157 | |
158 | |
159 void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj, | |
160 MarkBit mark_bit) { | |
161 DCHECK(Marking::MarkBitFrom(obj) == mark_bit); | |
162 DCHECK(obj->Size() >= 2 * kPointerSize); | |
163 DCHECK(IsMarking()); | |
164 Marking::BlackToGrey(mark_bit); | |
165 int obj_size = obj->Size(); | |
166 MemoryChunk::IncrementLiveBytesFromGC(obj, -obj_size); | |
167 bytes_scanned_ -= obj_size; | |
168 int64_t old_bytes_rescanned = bytes_rescanned_; | |
169 bytes_rescanned_ = old_bytes_rescanned + obj_size; | |
170 if ((bytes_rescanned_ >> 20) != (old_bytes_rescanned >> 20)) { | |
171 if (bytes_rescanned_ > 2 * heap_->PromotedSpaceSizeOfObjects()) { | |
172 // If we have queued twice the heap size for rescanning then we are | |
173 // going around in circles, scanning the same objects again and again | |
174 // as the program mutates the heap faster than we can incrementally | |
175 // trace it. In this case we switch to non-incremental marking in | |
176 // order to finish off this marking phase. | |
177 if (FLAG_trace_incremental_marking) { | |
178 PrintIsolate( | |
179 heap()->isolate(), | |
180 "Hurrying incremental marking because of lack of progress\n"); | |
181 } | |
182 marking_speed_ = kMaxMarkingSpeed; | |
183 } | |
184 } | |
185 | |
186 heap_->mark_compact_collector()->marking_deque()->Unshift(obj); | |
187 } | |
188 | |
189 | |
190 void IncrementalMarking::WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit) { | 144 void IncrementalMarking::WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit) { |
191 Marking::WhiteToGrey(mark_bit); | 145 Marking::WhiteToGrey(mark_bit); |
192 heap_->mark_compact_collector()->marking_deque()->Push(obj); | 146 heap_->mark_compact_collector()->marking_deque()->Push(obj); |
193 } | 147 } |
194 | 148 |
195 | 149 |
196 static void MarkObjectGreyDoNotEnqueue(Object* obj) { | 150 static void MarkObjectGreyDoNotEnqueue(Object* obj) { |
197 if (obj->IsHeapObject()) { | 151 if (obj->IsHeapObject()) { |
198 HeapObject* heap_obj = HeapObject::cast(obj); | 152 HeapObject* heap_obj = HeapObject::cast(obj); |
199 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj)); | 153 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj)); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 if (Marking::IsWhite(mark_bit)) { | 270 if (Marking::IsWhite(mark_bit)) { |
317 Marking::MarkBlack(mark_bit); | 271 Marking::MarkBlack(mark_bit); |
318 MemoryChunk::IncrementLiveBytesFromGC(heap_object, heap_object->Size()); | 272 MemoryChunk::IncrementLiveBytesFromGC(heap_object, heap_object->Size()); |
319 return true; | 273 return true; |
320 } | 274 } |
321 return false; | 275 return false; |
322 } | 276 } |
323 }; | 277 }; |
324 | 278 |
325 void IncrementalMarking::IterateBlackObject(HeapObject* object) { | 279 void IncrementalMarking::IterateBlackObject(HeapObject* object) { |
326 if (black_allocation() && | 280 if (IsMarking() && Marking::IsBlack(Marking::MarkBitFrom(object))) { |
327 Page::FromAddress(object->address())->IsFlagSet(Page::BLACK_PAGE)) { | |
328 IncrementalMarkingMarkingVisitor::IterateBody(object->map(), object); | 281 IncrementalMarkingMarkingVisitor::IterateBody(object->map(), object); |
329 } | 282 } |
330 } | 283 } |
331 | 284 |
332 class IncrementalMarkingRootMarkingVisitor : public ObjectVisitor { | 285 class IncrementalMarkingRootMarkingVisitor : public ObjectVisitor { |
333 public: | 286 public: |
334 explicit IncrementalMarkingRootMarkingVisitor( | 287 explicit IncrementalMarkingRootMarkingVisitor( |
335 IncrementalMarking* incremental_marking) | 288 IncrementalMarking* incremental_marking) |
336 : heap_(incremental_marking->heap()) {} | 289 : heap_(incremental_marking->heap()) {} |
337 | 290 |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { | 1246 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { |
1294 idle_marking_delay_counter_++; | 1247 idle_marking_delay_counter_++; |
1295 } | 1248 } |
1296 | 1249 |
1297 | 1250 |
1298 void IncrementalMarking::ClearIdleMarkingDelayCounter() { | 1251 void IncrementalMarking::ClearIdleMarkingDelayCounter() { |
1299 idle_marking_delay_counter_ = 0; | 1252 idle_marking_delay_counter_ = 0; |
1300 } | 1253 } |
1301 } // namespace internal | 1254 } // namespace internal |
1302 } // namespace v8 | 1255 } // namespace v8 |
OLD | NEW |