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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 heap->mark_compact_collector()->is_compacting(); | 185 heap->mark_compact_collector()->is_compacting(); |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 template <class T> | 189 template <class T> |
190 struct WeakListVisitor; | 190 struct WeakListVisitor; |
191 | 191 |
192 | 192 |
193 template <class T> | 193 template <class T> |
194 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer, | 194 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer, |
195 bool stop_after_young) { | 195 bool stop_after_young, Object** list_tail) { |
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 | 205 |
(...skipping 24 matching lines...) Expand all Loading... |
230 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); | 230 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); |
231 } | 231 } |
232 | 232 |
233 // Move to next element in the list. | 233 // Move to next element in the list. |
234 list = WeakListVisitor<T>::WeakNext(candidate); | 234 list = WeakListVisitor<T>::WeakNext(candidate); |
235 } | 235 } |
236 | 236 |
237 // Terminate the list if there is one or more elements. | 237 // Terminate the list if there is one or more elements. |
238 if (tail != NULL) { | 238 if (tail != NULL) { |
239 WeakListVisitor<T>::SetWeakNext(tail, undefined); | 239 WeakListVisitor<T>::SetWeakNext(tail, undefined); |
| 240 if (list_tail) *list_tail = tail; |
240 } | 241 } |
241 return head; | 242 return head; |
242 } | 243 } |
243 | 244 |
244 | 245 |
245 Object* VisitNewArrayBufferViewsWeakList(Heap* heap, Object* list, | 246 Object* VisitNewArrayBufferViewsWeakList(Heap* heap, Object* list, |
246 WeakObjectRetainer* retainer) { | 247 WeakObjectRetainer* retainer) { |
247 Object* undefined = heap->undefined_value(); | 248 Object* undefined = heap->undefined_value(); |
248 Object* previous = undefined; | 249 Object* previous = undefined; |
249 Object* head = undefined; | 250 Object* head = undefined; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST); | 364 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST); |
364 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST); | 365 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST); |
365 } | 366 } |
366 } | 367 } |
367 | 368 |
368 template <class T> | 369 template <class T> |
369 static void DoWeakList(Heap* heap, Context* context, | 370 static void DoWeakList(Heap* heap, Context* context, |
370 WeakObjectRetainer* retainer, int index) { | 371 WeakObjectRetainer* retainer, int index) { |
371 // Visit the weak list, removing dead intermediate elements. | 372 // Visit the weak list, removing dead intermediate elements. |
372 Object* list_head = | 373 Object* list_head = |
373 VisitWeakList<T>(heap, context->get(index), retainer, false); | 374 VisitWeakList<T>(heap, context->get(index), retainer, false, NULL); |
374 | 375 |
375 // Update the list head. | 376 // Update the list head. |
376 context->set(index, list_head, UPDATE_WRITE_BARRIER); | 377 context->set(index, list_head, UPDATE_WRITE_BARRIER); |
377 | 378 |
378 if (MustRecordSlots(heap)) { | 379 if (MustRecordSlots(heap)) { |
379 // Record the updated slot if necessary. | 380 // Record the updated slot if necessary. |
380 Object** head_slot = | 381 Object** head_slot = |
381 HeapObject::RawField(context, FixedArray::SizeFor(index)); | 382 HeapObject::RawField(context, FixedArray::SizeFor(index)); |
382 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot, | 383 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot, |
383 list_head); | 384 list_head); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 obj->set_weak_next(next); | 416 obj->set_weak_next(next); |
416 } | 417 } |
417 | 418 |
418 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } | 419 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } |
419 | 420 |
420 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } | 421 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } |
421 | 422 |
422 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, | 423 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, |
423 WeakObjectRetainer* retainer) { | 424 WeakObjectRetainer* retainer) { |
424 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>( | 425 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>( |
425 heap, array_buffer->weak_first_view(), retainer, false); | 426 heap, array_buffer->weak_first_view(), retainer, false, NULL); |
426 array_buffer->set_weak_first_view(typed_array_obj); | 427 array_buffer->set_weak_first_view(typed_array_obj); |
427 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) { | 428 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) { |
428 Object** slot = HeapObject::RawField(array_buffer, | 429 Object** slot = HeapObject::RawField(array_buffer, |
429 JSArrayBuffer::kWeakFirstViewOffset); | 430 JSArrayBuffer::kWeakFirstViewOffset); |
430 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); | 431 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); |
431 } | 432 } |
432 } | 433 } |
433 | 434 |
434 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { | 435 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { |
435 Runtime::FreeArrayBuffer(heap->isolate(), phantom); | 436 Runtime::FreeArrayBuffer(heap->isolate(), phantom); |
(...skipping 12 matching lines...) Expand all Loading... |
448 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; } | 449 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; } |
449 | 450 |
450 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {} | 451 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {} |
451 | 452 |
452 static void VisitPhantomObject(Heap*, AllocationSite*) {} | 453 static void VisitPhantomObject(Heap*, AllocationSite*) {} |
453 }; | 454 }; |
454 | 455 |
455 | 456 |
456 template Object* VisitWeakList<Context>(Heap* heap, Object* list, | 457 template Object* VisitWeakList<Context>(Heap* heap, Object* list, |
457 WeakObjectRetainer* retainer, | 458 WeakObjectRetainer* retainer, |
458 bool stop_after_young); | 459 bool stop_after_young, |
| 460 Object** list_tail); |
459 | 461 |
460 | 462 |
461 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, | 463 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, |
462 WeakObjectRetainer* retainer, | 464 WeakObjectRetainer* retainer, |
463 bool stop_after_young); | 465 bool stop_after_young, |
| 466 Object** list_tail); |
464 | 467 |
465 template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list, | 468 template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list, |
466 WeakObjectRetainer* retainer, | 469 WeakObjectRetainer* retainer, |
467 bool stop_after_young); | 470 bool stop_after_young, |
| 471 Object** list_tail); |
468 | 472 |
469 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, | 473 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, |
470 WeakObjectRetainer* retainer, | 474 WeakObjectRetainer* retainer, |
471 bool stop_after_young); | 475 bool stop_after_young, |
| 476 Object** list_tail); |
472 } | 477 } |
473 } // namespace v8::internal | 478 } // namespace v8::internal |
OLD | NEW |