OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/heap/objects-visiting.h" | 7 #include "src/heap/objects-visiting.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 bool stop_after_young) { | 195 bool stop_after_young) { |
196 Object* undefined = heap->undefined_value(); | 196 Object* undefined = heap->undefined_value(); |
197 Object* head = undefined; | 197 Object* head = undefined; |
198 T* tail = NULL; | 198 T* tail = NULL; |
199 MarkCompactCollector* collector = heap->mark_compact_collector(); | 199 MarkCompactCollector* collector = heap->mark_compact_collector(); |
200 bool record_slots = MustRecordSlots(heap); | 200 bool record_slots = MustRecordSlots(heap); |
201 | 201 |
202 while (list != undefined) { | 202 while (list != undefined) { |
203 // Check whether to keep the candidate in the list. | 203 // Check whether to keep the candidate in the list. |
204 T* candidate = reinterpret_cast<T*>(list); | 204 T* candidate = reinterpret_cast<T*>(list); |
205 T* original_candidate = candidate; | |
206 | 205 |
207 Object* retained = retainer->RetainAs(list); | 206 Object* retained = retainer->RetainAs(list); |
208 if (retained != NULL) { | 207 if (retained != NULL) { |
209 if (head == undefined) { | 208 if (head == undefined) { |
210 // First element in the list. | 209 // First element in the list. |
211 head = retained; | 210 head = retained; |
212 } else { | 211 } else { |
213 // Subsequent elements in the list. | 212 // Subsequent elements in the list. |
214 DCHECK(tail != NULL); | 213 DCHECK(tail != NULL); |
215 WeakListVisitor<T>::SetWeakNext(tail, retained); | 214 WeakListVisitor<T>::SetWeakNext(tail, retained); |
216 if (record_slots) { | 215 if (record_slots) { |
217 Object** next_slot = | 216 Object** next_slot = |
218 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset()); | 217 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset()); |
219 collector->RecordSlot(next_slot, next_slot, retained); | 218 collector->RecordSlot(next_slot, next_slot, retained); |
220 } | 219 } |
221 } | 220 } |
222 // Retained object is new tail. | 221 // Retained object is new tail. |
223 DCHECK(!retained->IsUndefined()); | 222 DCHECK(!retained->IsUndefined()); |
224 candidate = reinterpret_cast<T*>(retained); | 223 candidate = reinterpret_cast<T*>(retained); |
225 tail = candidate; | 224 tail = candidate; |
226 | 225 |
227 // tail is a live object, visit it. | 226 // tail is a live object, visit it. |
228 WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer); | 227 WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer); |
229 | 228 |
230 // The list of weak objects is usually order. It starts with objects | |
231 // recently allocated in the young generation followed by objects | |
232 // allocated in the old generation. When a migration failure happened, | |
233 // the list is not ordered until the next GC that has no migration | |
234 // failure. | |
235 // For young generation collections we just have to visit until the last | |
236 // young generation objects. | |
237 if (stop_after_young && !heap->migration_failure() && | |
238 !heap->previous_migration_failure() && | |
239 !heap->InNewSpace(original_candidate)) { | |
240 return head; | |
241 } | |
242 } else { | 229 } else { |
243 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); | 230 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); |
244 } | 231 } |
245 | 232 |
246 // Move to next element in the list. | 233 // Move to next element in the list. |
247 list = WeakListVisitor<T>::WeakNext(candidate); | 234 list = WeakListVisitor<T>::WeakNext(candidate); |
248 } | 235 } |
249 | 236 |
250 // Terminate the list if there is one or more elements. | 237 // Terminate the list if there is one or more elements. |
251 if (tail != NULL) { | 238 if (tail != NULL) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 464 |
478 template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list, | 465 template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list, |
479 WeakObjectRetainer* retainer, | 466 WeakObjectRetainer* retainer, |
480 bool stop_after_young); | 467 bool stop_after_young); |
481 | 468 |
482 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, | 469 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, |
483 WeakObjectRetainer* retainer, | 470 WeakObjectRetainer* retainer, |
484 bool stop_after_young); | 471 bool stop_after_young); |
485 } | 472 } |
486 } // namespace v8::internal | 473 } // namespace v8::internal |
OLD | NEW |