| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
| (...skipping 2660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2671 } | 2671 } |
| 2672 heap()->set_encountered_weak_collections(Smi::FromInt(0)); | 2672 heap()->set_encountered_weak_collections(Smi::FromInt(0)); |
| 2673 } | 2673 } |
| 2674 | 2674 |
| 2675 | 2675 |
| 2676 void MarkCompactCollector::ProcessAndClearWeakCells() { | 2676 void MarkCompactCollector::ProcessAndClearWeakCells() { |
| 2677 HeapObject* undefined = heap()->undefined_value(); | 2677 HeapObject* undefined = heap()->undefined_value(); |
| 2678 Object* weak_cell_obj = heap()->encountered_weak_cells(); | 2678 Object* weak_cell_obj = heap()->encountered_weak_cells(); |
| 2679 while (weak_cell_obj != Smi::FromInt(0)) { | 2679 while (weak_cell_obj != Smi::FromInt(0)) { |
| 2680 WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj); | 2680 WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj); |
| 2681 // We do not insert cleared weak cells into the list, so the value | 2681 // Raw read avoids read barrier. |
| 2682 // cannot be a Smi here. | 2682 Object* value = weak_cell->ValueNoReadBarrier(); |
| 2683 HeapObject* value = HeapObject::cast(weak_cell->value()); | 2683 if (value != Smi::FromInt(0)) { |
| 2684 if (!MarkCompactCollector::IsMarked(value)) { | 2684 HeapObject* heap_value = HeapObject::cast(value); |
| 2685 weak_cell->clear(); | 2685 // TODO(erikcorry): Also check whether the cell has been used. |
| 2686 } else { | 2686 if (!MarkCompactCollector::IsMarked(heap_value)) { |
| 2687 Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset); | 2687 weak_cell->clear(); |
| 2688 heap()->mark_compact_collector()->RecordSlot(slot, slot, value); | 2688 } else { |
| 2689 Object** slot = HeapObject::RawField( |
| 2690 weak_cell, WeakCell::kValueOffsetDontForgetTheReadBarrier); |
| 2691 heap()->mark_compact_collector()->RecordSlot(slot, slot, value); |
| 2692 } |
| 2693 // Tag for the next round of GC. |
| 2694 *HeapObject::RawField(weak_cell, HeapObject::kMapOffset) = |
| 2695 heap()->unused_weak_cell_map(); |
| 2689 } | 2696 } |
| 2690 weak_cell_obj = weak_cell->next(); | 2697 weak_cell_obj = weak_cell->next(); |
| 2691 weak_cell->set_next(undefined, SKIP_WRITE_BARRIER); | 2698 weak_cell->set_next(undefined, SKIP_WRITE_BARRIER); |
| 2692 } | 2699 } |
| 2693 heap()->set_encountered_weak_cells(Smi::FromInt(0)); | 2700 heap()->set_encountered_weak_cells(Smi::FromInt(0)); |
| 2694 } | 2701 } |
| 2695 | 2702 |
| 2696 | 2703 |
| 2697 void MarkCompactCollector::AbortWeakCells() { | 2704 void MarkCompactCollector::AbortWeakCells() { |
| 2698 Object* undefined = heap()->undefined_value(); | 2705 Object* undefined = heap()->undefined_value(); |
| (...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4406 SlotsBuffer* buffer = *buffer_address; | 4413 SlotsBuffer* buffer = *buffer_address; |
| 4407 while (buffer != NULL) { | 4414 while (buffer != NULL) { |
| 4408 SlotsBuffer* next_buffer = buffer->next(); | 4415 SlotsBuffer* next_buffer = buffer->next(); |
| 4409 DeallocateBuffer(buffer); | 4416 DeallocateBuffer(buffer); |
| 4410 buffer = next_buffer; | 4417 buffer = next_buffer; |
| 4411 } | 4418 } |
| 4412 *buffer_address = NULL; | 4419 *buffer_address = NULL; |
| 4413 } | 4420 } |
| 4414 } | 4421 } |
| 4415 } // namespace v8::internal | 4422 } // namespace v8::internal |
| OLD | NEW |