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