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/mark-compact.h" | 5 #include "src/heap/mark-compact.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/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 // marking cycle. We did not collect any slots. | 865 // marking cycle. We did not collect any slots. |
866 if (!FLAG_never_compact && !was_marked_incrementally_) { | 866 if (!FLAG_never_compact && !was_marked_incrementally_) { |
867 StartCompaction(NON_INCREMENTAL_COMPACTION); | 867 StartCompaction(NON_INCREMENTAL_COMPACTION); |
868 } | 868 } |
869 | 869 |
870 PagedSpaces spaces(heap()); | 870 PagedSpaces spaces(heap()); |
871 for (PagedSpace* space = spaces.next(); space != NULL; | 871 for (PagedSpace* space = spaces.next(); space != NULL; |
872 space = spaces.next()) { | 872 space = spaces.next()) { |
873 space->PrepareForMarkCompact(); | 873 space->PrepareForMarkCompact(); |
874 } | 874 } |
875 heap()->account_amount_of_external_allocated_freed_memory(); | |
876 | 875 |
877 #ifdef VERIFY_HEAP | 876 #ifdef VERIFY_HEAP |
878 if (!was_marked_incrementally_ && FLAG_verify_heap) { | 877 if (!was_marked_incrementally_ && FLAG_verify_heap) { |
879 VerifyMarkbitsAreClean(); | 878 VerifyMarkbitsAreClean(); |
880 } | 879 } |
881 #endif | 880 #endif |
882 } | 881 } |
883 | 882 |
884 | 883 |
885 void MarkCompactCollector::Finish() { | 884 void MarkCompactCollector::Finish() { |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 local_pretenuring_feedback_(local_pretenuring_feedback) {} | 1743 local_pretenuring_feedback_(local_pretenuring_feedback) {} |
1745 | 1744 |
1746 inline bool Visit(HeapObject* object) override { | 1745 inline bool Visit(HeapObject* object) override { |
1747 heap_->UpdateAllocationSite<Heap::kCached>(object, | 1746 heap_->UpdateAllocationSite<Heap::kCached>(object, |
1748 local_pretenuring_feedback_); | 1747 local_pretenuring_feedback_); |
1749 int size = object->Size(); | 1748 int size = object->Size(); |
1750 HeapObject* target_object = nullptr; | 1749 HeapObject* target_object = nullptr; |
1751 if (heap_->ShouldBePromoted<DEFAULT_PROMOTION>(object->address(), size) && | 1750 if (heap_->ShouldBePromoted<DEFAULT_PROMOTION>(object->address(), size) && |
1752 TryEvacuateObject(compaction_spaces_->Get(OLD_SPACE), object, | 1751 TryEvacuateObject(compaction_spaces_->Get(OLD_SPACE), object, |
1753 &target_object)) { | 1752 &target_object)) { |
| 1753 // If we end up needing more special cases, we should factor this out. |
| 1754 if (V8_UNLIKELY(target_object->IsJSArrayBuffer())) { |
| 1755 heap_->array_buffer_tracker()->Promote( |
| 1756 JSArrayBuffer::cast(target_object)); |
| 1757 } |
1754 promoted_size_ += size; | 1758 promoted_size_ += size; |
1755 return true; | 1759 return true; |
1756 } | 1760 } |
1757 HeapObject* target = nullptr; | 1761 HeapObject* target = nullptr; |
1758 AllocationSpace space = AllocateTargetObject(object, &target); | 1762 AllocationSpace space = AllocateTargetObject(object, &target); |
1759 MigrateObject(HeapObject::cast(target), object, size, space); | 1763 MigrateObject(HeapObject::cast(target), object, size, space); |
| 1764 if (V8_UNLIKELY(target->IsJSArrayBuffer())) { |
| 1765 heap_->array_buffer_tracker()->MarkLive(JSArrayBuffer::cast(target)); |
| 1766 } |
1760 semispace_copied_size_ += size; | 1767 semispace_copied_size_ += size; |
1761 return true; | 1768 return true; |
1762 } | 1769 } |
1763 | 1770 |
1764 intptr_t promoted_size() { return promoted_size_; } | 1771 intptr_t promoted_size() { return promoted_size_; } |
1765 intptr_t semispace_copied_size() { return semispace_copied_size_; } | 1772 intptr_t semispace_copied_size() { return semispace_copied_size_; } |
1766 | 1773 |
1767 private: | 1774 private: |
1768 enum NewSpaceAllocationMode { | 1775 enum NewSpaceAllocationMode { |
1769 kNonstickyBailoutOldSpace, | 1776 kNonstickyBailoutOldSpace, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 : heap_(heap), promoted_size_(0) {} | 1881 : heap_(heap), promoted_size_(0) {} |
1875 | 1882 |
1876 static void TryMoveToOldSpace(Page* page, PagedSpace* owner) { | 1883 static void TryMoveToOldSpace(Page* page, PagedSpace* owner) { |
1877 if (page->heap()->new_space()->ReplaceWithEmptyPage(page)) { | 1884 if (page->heap()->new_space()->ReplaceWithEmptyPage(page)) { |
1878 Page* new_page = Page::ConvertNewToOld(page, owner); | 1885 Page* new_page = Page::ConvertNewToOld(page, owner); |
1879 new_page->SetFlag(Page::PAGE_NEW_OLD_PROMOTION); | 1886 new_page->SetFlag(Page::PAGE_NEW_OLD_PROMOTION); |
1880 } | 1887 } |
1881 } | 1888 } |
1882 | 1889 |
1883 inline bool Visit(HeapObject* object) { | 1890 inline bool Visit(HeapObject* object) { |
| 1891 if (V8_UNLIKELY(object->IsJSArrayBuffer())) { |
| 1892 object->GetHeap()->array_buffer_tracker()->Promote( |
| 1893 JSArrayBuffer::cast(object)); |
| 1894 } |
1884 RecordMigratedSlotVisitor visitor(heap_->mark_compact_collector()); | 1895 RecordMigratedSlotVisitor visitor(heap_->mark_compact_collector()); |
1885 object->IterateBodyFast(&visitor); | 1896 object->IterateBodyFast(&visitor); |
1886 promoted_size_ += object->Size(); | 1897 promoted_size_ += object->Size(); |
1887 return true; | 1898 return true; |
1888 } | 1899 } |
1889 | 1900 |
1890 intptr_t promoted_size() { return promoted_size_; } | 1901 intptr_t promoted_size() { return promoted_size_; } |
1891 | 1902 |
1892 private: | 1903 private: |
1893 Heap* heap_; | 1904 Heap* heap_; |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3132 } | 3143 } |
3133 return success; | 3144 return success; |
3134 } | 3145 } |
3135 | 3146 |
3136 bool MarkCompactCollector::Evacuator::EvacuatePage(Page* page) { | 3147 bool MarkCompactCollector::Evacuator::EvacuatePage(Page* page) { |
3137 bool result = false; | 3148 bool result = false; |
3138 DCHECK(page->SweepingDone()); | 3149 DCHECK(page->SweepingDone()); |
3139 switch (ComputeEvacuationMode(page)) { | 3150 switch (ComputeEvacuationMode(page)) { |
3140 case kObjectsNewToOld: | 3151 case kObjectsNewToOld: |
3141 result = EvacuateSinglePage<kClearMarkbits>(page, &new_space_visitor_); | 3152 result = EvacuateSinglePage<kClearMarkbits>(page, &new_space_visitor_); |
3142 ArrayBufferTracker::ProcessBuffers( | |
3143 page, ArrayBufferTracker::kUpdateForwardedRemoveOthers); | |
3144 DCHECK(result); | 3153 DCHECK(result); |
3145 USE(result); | 3154 USE(result); |
3146 break; | 3155 break; |
3147 case kPageNewToOld: | 3156 case kPageNewToOld: |
3148 result = EvacuateSinglePage<kKeepMarking>(page, &new_space_page_visitor); | 3157 result = EvacuateSinglePage<kKeepMarking>(page, &new_space_page_visitor); |
3149 // ArrayBufferTracker will be updated during sweeping. | |
3150 DCHECK(result); | 3158 DCHECK(result); |
3151 USE(result); | 3159 USE(result); |
3152 break; | 3160 break; |
3153 case kObjectsOldToOld: | 3161 case kObjectsOldToOld: |
3154 result = EvacuateSinglePage<kClearMarkbits>(page, &old_space_visitor_); | 3162 result = EvacuateSinglePage<kClearMarkbits>(page, &old_space_visitor_); |
3155 if (!result) { | 3163 if (!result) { |
3156 // Aborted compaction page. We have to record slots here, since we might | 3164 // Aborted compaction page. We have to record slots here, since we might |
3157 // not have recorded them in first place. | 3165 // not have recorded them in first place. |
3158 // Note: We mark the page as aborted here to be able to record slots | 3166 // Note: We mark the page as aborted here to be able to record slots |
3159 // for code objects in |RecordMigratedSlotVisitor|. | 3167 // for code objects in |RecordMigratedSlotVisitor|. |
3160 page->SetFlag(Page::COMPACTION_WAS_ABORTED); | 3168 page->SetFlag(Page::COMPACTION_WAS_ABORTED); |
3161 EvacuateRecordOnlyVisitor record_visitor(collector_->heap()); | 3169 EvacuateRecordOnlyVisitor record_visitor(collector_->heap()); |
3162 result = EvacuateSinglePage<kKeepMarking>(page, &record_visitor); | 3170 result = EvacuateSinglePage<kKeepMarking>(page, &record_visitor); |
3163 ArrayBufferTracker::ProcessBuffers( | |
3164 page, ArrayBufferTracker::kUpdateForwardedKeepOthers); | |
3165 DCHECK(result); | 3171 DCHECK(result); |
3166 USE(result); | 3172 USE(result); |
3167 // We need to return failure here to indicate that we want this page | 3173 // We need to return failure here to indicate that we want this page |
3168 // added to the sweeper. | 3174 // added to the sweeper. |
3169 return false; | 3175 return false; |
3170 } | 3176 } |
3171 ArrayBufferTracker::ProcessBuffers( | |
3172 page, ArrayBufferTracker::kUpdateForwardedRemoveOthers); | |
3173 | |
3174 break; | 3177 break; |
3175 default: | 3178 default: |
3176 UNREACHABLE(); | 3179 UNREACHABLE(); |
3177 } | 3180 } |
3178 return result; | 3181 return result; |
3179 } | 3182 } |
3180 | 3183 |
3181 void MarkCompactCollector::Evacuator::Finalize() { | 3184 void MarkCompactCollector::Evacuator::Finalize() { |
3182 heap()->old_space()->MergeCompactionSpace(compaction_spaces_.Get(OLD_SPACE)); | 3185 heap()->old_space()->MergeCompactionSpace(compaction_spaces_.Get(OLD_SPACE)); |
3183 heap()->code_space()->MergeCompactionSpace( | 3186 heap()->code_space()->MergeCompactionSpace( |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3343 MarkCompactCollector::Sweeper::FreeSpaceTreatmentMode free_space_mode> | 3346 MarkCompactCollector::Sweeper::FreeSpaceTreatmentMode free_space_mode> |
3344 int MarkCompactCollector::Sweeper::RawSweep(PagedSpace* space, Page* p, | 3347 int MarkCompactCollector::Sweeper::RawSweep(PagedSpace* space, Page* p, |
3345 ObjectVisitor* v) { | 3348 ObjectVisitor* v) { |
3346 DCHECK(!p->IsEvacuationCandidate() && !p->SweepingDone()); | 3349 DCHECK(!p->IsEvacuationCandidate() && !p->SweepingDone()); |
3347 DCHECK(!p->IsFlagSet(Page::BLACK_PAGE)); | 3350 DCHECK(!p->IsFlagSet(Page::BLACK_PAGE)); |
3348 DCHECK_EQ(skip_list_mode == REBUILD_SKIP_LIST, | 3351 DCHECK_EQ(skip_list_mode == REBUILD_SKIP_LIST, |
3349 space->identity() == CODE_SPACE); | 3352 space->identity() == CODE_SPACE); |
3350 DCHECK((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST)); | 3353 DCHECK((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST)); |
3351 DCHECK(parallelism == SWEEP_ON_MAIN_THREAD || sweeping_mode == SWEEP_ONLY); | 3354 DCHECK(parallelism == SWEEP_ON_MAIN_THREAD || sweeping_mode == SWEEP_ONLY); |
3352 | 3355 |
3353 // Before we sweep objects on the page, we free dead array buffers which | |
3354 // requires valid mark bits. | |
3355 ArrayBufferTracker::FreeDead(p); | |
3356 | |
3357 Address free_start = p->area_start(); | 3356 Address free_start = p->area_start(); |
3358 DCHECK(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0); | 3357 DCHECK(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0); |
3359 | 3358 |
3360 // If we use the skip list for code space pages, we have to lock the skip | 3359 // If we use the skip list for code space pages, we have to lock the skip |
3361 // list because it could be accessed concurrently by the runtime or the | 3360 // list because it could be accessed concurrently by the runtime or the |
3362 // deoptimizer. | 3361 // deoptimizer. |
3363 SkipList* skip_list = p->skip_list(); | 3362 SkipList* skip_list = p->skip_list(); |
3364 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list) { | 3363 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list) { |
3365 skip_list->Clear(); | 3364 skip_list->Clear(); |
3366 } | 3365 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3546 // because root iteration traverses the stack and might have to find | 3545 // because root iteration traverses the stack and might have to find |
3547 // code objects from non-updated pc pointing into evacuation candidate. | 3546 // code objects from non-updated pc pointing into evacuation candidate. |
3548 SkipList* list = p->skip_list(); | 3547 SkipList* list = p->skip_list(); |
3549 if (list != NULL) list->Clear(); | 3548 if (list != NULL) list->Clear(); |
3550 if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) { | 3549 if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) { |
3551 sweeper().AddLatePage(p->owner()->identity(), p); | 3550 sweeper().AddLatePage(p->owner()->identity(), p); |
3552 p->ClearFlag(Page::COMPACTION_WAS_ABORTED); | 3551 p->ClearFlag(Page::COMPACTION_WAS_ABORTED); |
3553 } | 3552 } |
3554 } | 3553 } |
3555 | 3554 |
| 3555 // EvacuateNewSpaceAndCandidates iterates over new space objects and for |
| 3556 // ArrayBuffers either re-registers them as live or promotes them. This is |
| 3557 // needed to properly free them. |
| 3558 heap()->array_buffer_tracker()->FreeDead(false); |
| 3559 |
3556 // Deallocate evacuated candidate pages. | 3560 // Deallocate evacuated candidate pages. |
3557 ReleaseEvacuationCandidates(); | 3561 ReleaseEvacuationCandidates(); |
3558 } | 3562 } |
3559 | 3563 |
3560 #ifdef VERIFY_HEAP | 3564 #ifdef VERIFY_HEAP |
3561 if (FLAG_verify_heap && !sweeper().sweeping_in_progress()) { | 3565 if (FLAG_verify_heap && !sweeper().sweeping_in_progress()) { |
3562 VerifyEvacuation(heap()); | 3566 VerifyEvacuation(heap()); |
3563 } | 3567 } |
3564 #endif | 3568 #endif |
3565 } | 3569 } |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3971 MarkBit mark_bit = Marking::MarkBitFrom(host); | 3975 MarkBit mark_bit = Marking::MarkBitFrom(host); |
3972 if (Marking::IsBlack(mark_bit)) { | 3976 if (Marking::IsBlack(mark_bit)) { |
3973 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 3977 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
3974 RecordRelocSlot(host, &rinfo, target); | 3978 RecordRelocSlot(host, &rinfo, target); |
3975 } | 3979 } |
3976 } | 3980 } |
3977 } | 3981 } |
3978 | 3982 |
3979 } // namespace internal | 3983 } // namespace internal |
3980 } // namespace v8 | 3984 } // namespace v8 |
OLD | NEW |