Chromium Code Reviews| Index: src/heap/objects-visiting.cc |
| diff --git a/src/heap/objects-visiting.cc b/src/heap/objects-visiting.cc |
| index 7b2e2d9a388939440e0aac0bb5c3263fedc4676f..ec649edcdf62e1103eebbe8416480b36a84ff21d 100644 |
| --- a/src/heap/objects-visiting.cc |
| +++ b/src/heap/objects-visiting.cc |
| @@ -191,15 +191,19 @@ struct WeakListVisitor; |
| template <class T> |
| -Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer) { |
| +Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer, |
| + bool stop_after_young) { |
| Object* undefined = heap->undefined_value(); |
| Object* head = undefined; |
| T* tail = NULL; |
| MarkCompactCollector* collector = heap->mark_compact_collector(); |
| bool record_slots = MustRecordSlots(heap); |
| + |
| while (list != undefined) { |
| // Check whether to keep the candidate in the list. |
| T* candidate = reinterpret_cast<T*>(list); |
| + T* original_candidate = candidate; |
| + |
| Object* retained = retainer->RetainAs(list); |
| if (retained != NULL) { |
| if (head == undefined) { |
| @@ -220,9 +224,19 @@ Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer) { |
| candidate = reinterpret_cast<T*>(retained); |
| tail = candidate; |
| - |
| // tail is a live object, visit it. |
| WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer); |
| + |
| + // The list of weak objects is usually order. It starts with objects |
| + // recently allocated in the young generation followed by objects |
| + // allocated in the old generation. When a promotion failure happens, |
| + // the list is not ordered until the next GC. |
| + // For young generation collections we just have to visit until the last |
| + // young generation objects. |
| + if (stop_after_young && !heap->promotion_failure() && |
| + !heap->InNewSpace(original_candidate)) { |
|
ulan
2015/02/06 14:36:46
Let's DCHECK that the remaining objects are in old
Hannes Payer (out of office)
2015/02/10 14:41:30
I moved the DCHECK to the call site. The invariant
|
| + return head; |
| + } |
| } else { |
| WeakListVisitor<T>::VisitPhantomObject(heap, candidate); |
| } |
| @@ -316,7 +330,8 @@ struct WeakListVisitor<Context> { |
| static void DoWeakList(Heap* heap, Context* context, |
| WeakObjectRetainer* retainer, int index) { |
| // Visit the weak list, removing dead intermediate elements. |
| - Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer); |
| + Object* list_head = |
| + VisitWeakList<T>(heap, context->get(index), retainer, false); |
| // Update the list head. |
| context->set(index, list_head, UPDATE_WRITE_BARRIER); |
| @@ -368,7 +383,7 @@ struct WeakListVisitor<JSArrayBuffer> { |
| static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, |
| WeakObjectRetainer* retainer) { |
| Object* typed_array_obj = VisitWeakList<JSArrayBufferView>( |
| - heap, array_buffer->weak_first_view(), retainer); |
| + heap, array_buffer->weak_first_view(), retainer, false); |
| array_buffer->set_weak_first_view(typed_array_obj); |
| if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) { |
| Object** slot = HeapObject::RawField(array_buffer, |
| @@ -399,23 +414,18 @@ struct WeakListVisitor<AllocationSite> { |
| }; |
| -template Object* VisitWeakList<Code>(Heap* heap, Object* list, |
| - WeakObjectRetainer* retainer); |
| - |
| - |
| -template Object* VisitWeakList<JSFunction>(Heap* heap, Object* list, |
| - WeakObjectRetainer* retainer); |
| - |
| - |
| template Object* VisitWeakList<Context>(Heap* heap, Object* list, |
| - WeakObjectRetainer* retainer); |
| + WeakObjectRetainer* retainer, |
| + bool stop_after_young); |
| template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, |
| - WeakObjectRetainer* retainer); |
| + WeakObjectRetainer* retainer, |
| + bool stop_after_young); |
| template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, |
| - WeakObjectRetainer* retainer); |
| + WeakObjectRetainer* retainer, |
| + bool stop_after_young); |
| } |
| } // namespace v8::internal |