Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: src/heap/mark-compact.cc

Issue 1596343004: [heap] Sort sweep pages list by free memory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adressed final comment Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/mark-compact-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3285 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 MemoryChunk::kSweepingDone); 3296 MemoryChunk::kSweepingDone);
3297 if (p->parallel_compaction_state().TrySetValue( 3297 if (p->parallel_compaction_state().TrySetValue(
3298 MemoryChunk::kCompactingDone, MemoryChunk::kCompactingInProgress)) { 3298 MemoryChunk::kCompactingDone, MemoryChunk::kCompactingInProgress)) {
3299 if (p->IsEvacuationCandidate()) { 3299 if (p->IsEvacuationCandidate()) {
3300 DCHECK_EQ(p->parallel_compaction_state().Value(), 3300 DCHECK_EQ(p->parallel_compaction_state().Value(),
3301 MemoryChunk::kCompactingInProgress); 3301 MemoryChunk::kCompactingInProgress);
3302 double start = heap()->MonotonicallyIncreasingTimeInMs(); 3302 double start = heap()->MonotonicallyIncreasingTimeInMs();
3303 intptr_t live_bytes = p->LiveBytes(); 3303 intptr_t live_bytes = p->LiveBytes();
3304 AlwaysAllocateScope always_allocate(isolate()); 3304 AlwaysAllocateScope always_allocate(isolate());
3305 if (VisitLiveObjects(p, &visitor, kClearMarkbits)) { 3305 if (VisitLiveObjects(p, &visitor, kClearMarkbits)) {
3306 p->ResetLiveBytes();
3307 p->parallel_compaction_state().SetValue( 3306 p->parallel_compaction_state().SetValue(
3308 MemoryChunk::kCompactingFinalize); 3307 MemoryChunk::kCompactingFinalize);
3309 compaction_spaces->ReportCompactionProgress( 3308 compaction_spaces->ReportCompactionProgress(
3310 heap()->MonotonicallyIncreasingTimeInMs() - start, live_bytes); 3309 heap()->MonotonicallyIncreasingTimeInMs() - start, live_bytes);
3311 } else { 3310 } else {
3312 p->parallel_compaction_state().SetValue( 3311 p->parallel_compaction_state().SetValue(
3313 MemoryChunk::kCompactingAborted); 3312 MemoryChunk::kCompactingAborted);
3314 } 3313 }
3315 } else { 3314 } else {
3316 // There could be popular pages in the list of evacuation candidates 3315 // There could be popular pages in the list of evacuation candidates
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3753 // Update pointers from external string table. 3752 // Update pointers from external string table.
3754 heap_->UpdateReferencesInExternalStringTable( 3753 heap_->UpdateReferencesInExternalStringTable(
3755 &UpdateReferenceInExternalStringTableEntry); 3754 &UpdateReferenceInExternalStringTableEntry);
3756 3755
3757 EvacuationWeakObjectRetainer evacuation_object_retainer; 3756 EvacuationWeakObjectRetainer evacuation_object_retainer;
3758 heap()->ProcessAllWeakReferences(&evacuation_object_retainer); 3757 heap()->ProcessAllWeakReferences(&evacuation_object_retainer);
3759 } 3758 }
3760 } 3759 }
3761 3760
3762 3761
3763 void MarkCompactCollector::MoveEvacuationCandidatesToEndOfPagesList() {
3764 int npages = evacuation_candidates_.length();
3765 for (int i = 0; i < npages; i++) {
3766 Page* p = evacuation_candidates_[i];
3767 if (!p->IsEvacuationCandidate()) continue;
3768 p->Unlink();
3769 PagedSpace* space = static_cast<PagedSpace*>(p->owner());
3770 p->InsertAfter(space->LastPage());
3771 }
3772 }
3773
3774
3775 void MarkCompactCollector::ReleaseEvacuationCandidates() { 3762 void MarkCompactCollector::ReleaseEvacuationCandidates() {
3776 int npages = evacuation_candidates_.length(); 3763 int npages = evacuation_candidates_.length();
3777 for (int i = 0; i < npages; i++) { 3764 for (int i = 0; i < npages; i++) {
3778 Page* p = evacuation_candidates_[i]; 3765 Page* p = evacuation_candidates_[i];
3779 if (!p->IsEvacuationCandidate()) continue; 3766 if (!p->IsEvacuationCandidate()) continue;
3780 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); 3767 PagedSpace* space = static_cast<PagedSpace*>(p->owner());
3781 space->Free(p->area_start(), p->area_size()); 3768 space->Free(p->area_start(), p->area_size());
3782 p->set_scan_on_scavenge(false); 3769 p->set_scan_on_scavenge(false);
3783 p->ResetLiveBytes(); 3770 p->ResetLiveBytes();
3784 CHECK(p->WasSwept()); 3771 CHECK(p->WasSwept());
3785 space->ReleasePage(p); 3772 space->ReleasePage(p);
3786 } 3773 }
3787 evacuation_candidates_.Rewind(0); 3774 evacuation_candidates_.Rewind(0);
3788 compacting_ = false; 3775 compacting_ = false;
3789 heap()->FilterStoreBufferEntriesOnAboutToBeFreedPages(); 3776 heap()->FilterStoreBufferEntriesOnAboutToBeFreedPages();
3790 heap()->FreeQueuedChunks(); 3777 heap()->FreeQueuedChunks();
3791 } 3778 }
3792 3779
3793 3780
3794 int MarkCompactCollector::SweepInParallel(PagedSpace* space, 3781 int MarkCompactCollector::SweepInParallel(PagedSpace* space,
3795 int required_freed_bytes) { 3782 int required_freed_bytes,
3783 int max_pages) {
3796 int max_freed = 0; 3784 int max_freed = 0;
3797 int max_freed_overall = 0; 3785 int max_freed_overall = 0;
3798 PageIterator it(space); 3786 int page_count = 0;
3799 while (it.has_next()) { 3787 for (Page* p : sweeping_list(space)) {
3800 Page* p = it.next();
3801 max_freed = SweepInParallel(p, space); 3788 max_freed = SweepInParallel(p, space);
3802 DCHECK(max_freed >= 0); 3789 DCHECK(max_freed >= 0);
3803 if (required_freed_bytes > 0 && max_freed >= required_freed_bytes) { 3790 if (required_freed_bytes > 0 && max_freed >= required_freed_bytes) {
3804 return max_freed; 3791 return max_freed;
3805 } 3792 }
3806 max_freed_overall = Max(max_freed, max_freed_overall); 3793 max_freed_overall = Max(max_freed, max_freed_overall);
3807 if (p == space->end_of_unswept_pages()) break; 3794 page_count++;
3795 if (max_pages > 0 && page_count >= max_pages) {
3796 break;
3797 }
3808 } 3798 }
3809 return max_freed_overall; 3799 return max_freed_overall;
3810 } 3800 }
3811 3801
3812 3802
3813 int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) { 3803 int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) {
3814 int max_freed = 0; 3804 int max_freed = 0;
3815 if (page->TryLock()) { 3805 if (page->TryLock()) {
3816 // If this page was already swept in the meantime, we can return here. 3806 // If this page was already swept in the meantime, we can return here.
3817 if (page->parallel_sweeping_state().Value() != 3807 if (page->parallel_sweeping_state().Value() !=
(...skipping 23 matching lines...) Expand all
3841 free_list->Concatenate(&private_free_list); 3831 free_list->Concatenate(&private_free_list);
3842 page->mutex()->Unlock(); 3832 page->mutex()->Unlock();
3843 } 3833 }
3844 return max_freed; 3834 return max_freed;
3845 } 3835 }
3846 3836
3847 3837
3848 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { 3838 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) {
3849 space->ClearStats(); 3839 space->ClearStats();
3850 3840
3851 // We defensively initialize end_of_unswept_pages_ here with the first page
3852 // of the pages list.
3853 space->set_end_of_unswept_pages(space->FirstPage());
3854
3855 PageIterator it(space); 3841 PageIterator it(space);
3856 3842
3857 int pages_swept = 0; 3843 int will_be_swept = 0;
3858 bool unused_page_present = false; 3844 bool unused_page_present = false;
3859 bool parallel_sweeping_active = false;
3860 3845
3861 while (it.has_next()) { 3846 while (it.has_next()) {
3862 Page* p = it.next(); 3847 Page* p = it.next();
3863 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone); 3848 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
3864 3849
3865 // Clear sweeping flags indicating that marking bits are still intact. 3850 // Clear sweeping flags indicating that marking bits are still intact.
3866 p->ClearWasSwept(); 3851 p->ClearWasSwept();
3867 3852
3868 if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION) || 3853 if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION) ||
3869 p->IsEvacuationCandidate()) { 3854 p->IsEvacuationCandidate()) {
(...skipping 17 matching lines...) Expand all
3887 if (unused_page_present) { 3872 if (unused_page_present) {
3888 if (FLAG_gc_verbose) { 3873 if (FLAG_gc_verbose) {
3889 PrintIsolate(isolate(), "sweeping: released page: %p", p); 3874 PrintIsolate(isolate(), "sweeping: released page: %p", p);
3890 } 3875 }
3891 space->ReleasePage(p); 3876 space->ReleasePage(p);
3892 continue; 3877 continue;
3893 } 3878 }
3894 unused_page_present = true; 3879 unused_page_present = true;
3895 } 3880 }
3896 3881
3897 if (!parallel_sweeping_active) { 3882 sweeping_list(space).push_back(p);
3898 if (FLAG_gc_verbose) { 3883 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending);
3899 PrintIsolate(isolate(), "sweeping: %p", p); 3884 int to_sweep = p->area_size() - p->LiveBytes();
3900 } 3885 space->accounting_stats_.ShrinkSpace(to_sweep);
3901 if (space->identity() == CODE_SPACE) { 3886 will_be_swept++;
3902 if (FLAG_zap_code_space) {
3903 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
3904 ZAP_FREE_SPACE>(space, NULL, p, NULL);
3905 } else {
3906 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
3907 IGNORE_FREE_SPACE>(space, NULL, p, NULL);
3908 }
3909 } else {
3910 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST,
3911 IGNORE_FREE_SPACE>(space, NULL, p, NULL);
3912 }
3913 pages_swept++;
3914 parallel_sweeping_active = true;
3915 } else {
3916 if (FLAG_gc_verbose) {
3917 PrintIsolate(isolate(), "sweeping: initialized for parallel: %p", p);
3918 }
3919 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending);
3920 int to_sweep = p->area_size() - p->LiveBytes();
3921 space->accounting_stats_.ShrinkSpace(to_sweep);
3922 }
3923 space->set_end_of_unswept_pages(p);
3924 } 3887 }
3925 3888
3926 if (FLAG_gc_verbose) { 3889 if (FLAG_gc_verbose) {
3927 PrintIsolate(isolate(), "sweeping: space=%s pages_swept=%d", 3890 PrintIsolate(isolate(), "sweeping: space=%s initialized_for_sweeping=%d",
3928 AllocationSpaceName(space->identity()), pages_swept); 3891 AllocationSpaceName(space->identity()), will_be_swept);
3929 } 3892 }
3893 std::sort(sweeping_list(space).begin(), sweeping_list(space).end(),
3894 [](Page* a, Page* b) { return a->LiveBytes() < b->LiveBytes(); });
3930 } 3895 }
3931 3896
3932 3897
3933 void MarkCompactCollector::SweepSpaces() { 3898 void MarkCompactCollector::SweepSpaces() {
3934 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_SWEEP); 3899 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_SWEEP);
3935 double start_time = 0.0; 3900 double start_time = 0.0;
3936 if (FLAG_print_cumulative_gc_stat) { 3901 if (FLAG_print_cumulative_gc_stat) {
3937 start_time = heap_->MonotonicallyIncreasingTimeInMs(); 3902 start_time = heap_->MonotonicallyIncreasingTimeInMs();
3938 } 3903 }
3939 3904
3940 #ifdef DEBUG 3905 #ifdef DEBUG
3941 state_ = SWEEP_SPACES; 3906 state_ = SWEEP_SPACES;
3942 #endif 3907 #endif
3943 3908
3944 MoveEvacuationCandidatesToEndOfPagesList();
3945
3946 { 3909 {
3947 sweeping_in_progress_ = true; 3910 sweeping_in_progress_ = true;
3948 { 3911 {
3949 GCTracer::Scope sweep_scope(heap()->tracer(), 3912 GCTracer::Scope sweep_scope(heap()->tracer(),
3950 GCTracer::Scope::MC_SWEEP_OLD); 3913 GCTracer::Scope::MC_SWEEP_OLD);
3951 StartSweepSpace(heap()->old_space()); 3914 StartSweepSpace(heap()->old_space());
3952 } 3915 }
3953 { 3916 {
3954 GCTracer::Scope sweep_scope(heap()->tracer(), 3917 GCTracer::Scope sweep_scope(heap()->tracer(),
3955 GCTracer::Scope::MC_SWEEP_CODE); 3918 GCTracer::Scope::MC_SWEEP_CODE);
(...skipping 17 matching lines...) Expand all
3973 heap()->FreeQueuedChunks(); 3936 heap()->FreeQueuedChunks();
3974 3937
3975 if (FLAG_print_cumulative_gc_stat) { 3938 if (FLAG_print_cumulative_gc_stat) {
3976 heap_->tracer()->AddSweepingTime(heap_->MonotonicallyIncreasingTimeInMs() - 3939 heap_->tracer()->AddSweepingTime(heap_->MonotonicallyIncreasingTimeInMs() -
3977 start_time); 3940 start_time);
3978 } 3941 }
3979 } 3942 }
3980 3943
3981 3944
3982 void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) { 3945 void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) {
3983 PageIterator it(space); 3946 for (Page* p : sweeping_list(space)) {
3984 while (it.has_next()) {
3985 Page* p = it.next();
3986 if (p->parallel_sweeping_state().Value() == 3947 if (p->parallel_sweeping_state().Value() ==
3987 MemoryChunk::kSweepingFinalize) { 3948 MemoryChunk::kSweepingFinalize) {
3988 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone); 3949 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone);
3989 p->SetWasSwept(); 3950 p->SetWasSwept();
3990 } 3951 }
3991 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone); 3952 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
3992 } 3953 }
3993 } 3954 }
3994 3955
3995 3956
3996 void MarkCompactCollector::ParallelSweepSpacesComplete() { 3957 void MarkCompactCollector::ParallelSweepSpacesComplete() {
3997 ParallelSweepSpaceComplete(heap()->old_space()); 3958 ParallelSweepSpaceComplete(heap()->old_space());
3998 ParallelSweepSpaceComplete(heap()->code_space()); 3959 ParallelSweepSpaceComplete(heap()->code_space());
3999 ParallelSweepSpaceComplete(heap()->map_space()); 3960 ParallelSweepSpaceComplete(heap()->map_space());
3961 sweeping_list(heap()->old_space()).clear();
3962 sweeping_list(heap()->code_space()).clear();
3963 sweeping_list(heap()->map_space()).clear();
4000 } 3964 }
4001 3965
4002 3966
4003 // TODO(1466) ReportDeleteIfNeeded is not called currently. 3967 // TODO(1466) ReportDeleteIfNeeded is not called currently.
4004 // Our profiling tools do not expect intersections between 3968 // Our profiling tools do not expect intersections between
4005 // code objects. We should either reenable it or change our tools. 3969 // code objects. We should either reenable it or change our tools.
4006 void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj, 3970 void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj,
4007 Isolate* isolate) { 3971 Isolate* isolate) {
4008 if (obj->IsCode()) { 3972 if (obj->IsCode()) {
4009 PROFILE(isolate, CodeDeleteEvent(obj->address())); 3973 PROFILE(isolate, CodeDeleteEvent(obj->address()));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4067 MarkBit mark_bit = Marking::MarkBitFrom(host); 4031 MarkBit mark_bit = Marking::MarkBitFrom(host);
4068 if (Marking::IsBlack(mark_bit)) { 4032 if (Marking::IsBlack(mark_bit)) {
4069 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); 4033 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host);
4070 RecordRelocSlot(&rinfo, target); 4034 RecordRelocSlot(&rinfo, target);
4071 } 4035 }
4072 } 4036 }
4073 } 4037 }
4074 4038
4075 } // namespace internal 4039 } // namespace internal
4076 } // namespace v8 4040 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/mark-compact-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698