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

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: 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
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() { 3762 void MarkCompactCollector::MoveEvacuationCandidatesToEndOfPagesList() {
Hannes Payer (out of office) 2016/01/20 09:25:03 This logic is not needed anymore, since we have a
Michael Lippautz 2016/01/20 11:11:16 Done.
3764 int npages = evacuation_candidates_.length(); 3763 int npages = evacuation_candidates_.length();
3765 for (int i = 0; i < npages; i++) { 3764 for (int i = 0; i < npages; i++) {
3766 Page* p = evacuation_candidates_[i]; 3765 Page* p = evacuation_candidates_[i];
3767 if (!p->IsEvacuationCandidate()) continue; 3766 if (!p->IsEvacuationCandidate()) continue;
3768 p->Unlink(); 3767 p->Unlink();
3769 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); 3768 PagedSpace* space = static_cast<PagedSpace*>(p->owner());
3770 p->InsertAfter(space->LastPage()); 3769 p->InsertAfter(space->LastPage());
3771 } 3770 }
3772 } 3771 }
3773 3772
(...skipping 11 matching lines...) Expand all
3785 space->ReleasePage(p); 3784 space->ReleasePage(p);
3786 } 3785 }
3787 evacuation_candidates_.Rewind(0); 3786 evacuation_candidates_.Rewind(0);
3788 compacting_ = false; 3787 compacting_ = false;
3789 heap()->FilterStoreBufferEntriesOnAboutToBeFreedPages(); 3788 heap()->FilterStoreBufferEntriesOnAboutToBeFreedPages();
3790 heap()->FreeQueuedChunks(); 3789 heap()->FreeQueuedChunks();
3791 } 3790 }
3792 3791
3793 3792
3794 int MarkCompactCollector::SweepInParallel(PagedSpace* space, 3793 int MarkCompactCollector::SweepInParallel(PagedSpace* space,
3795 int required_freed_bytes) { 3794 int required_freed_bytes,
3795 int max_pages) {
3796 int max_freed = 0; 3796 int max_freed = 0;
3797 int max_freed_overall = 0; 3797 int max_freed_overall = 0;
3798 PageIterator it(space); 3798 int page_count = 0;
3799 while (it.has_next()) { 3799 for (Page* p : sweeping_list(space)) {
Hannes Payer (out of office) 2016/01/20 09:25:03 Since we have now a separate data structure, why d
Michael Lippautz 2016/01/20 11:11:16 Because removing items from a std::vector can be q
Hannes Payer (out of office) 2016/01/20 12:08:19 Why don't we use a priority_queue?
3800 Page* p = it.next();
3801 max_freed = SweepInParallel(p, space); 3800 max_freed = SweepInParallel(p, space);
3802 DCHECK(max_freed >= 0); 3801 DCHECK(max_freed >= 0);
3803 if (required_freed_bytes > 0 && max_freed >= required_freed_bytes) { 3802 if (required_freed_bytes > 0 && max_freed >= required_freed_bytes) {
3804 return max_freed; 3803 return max_freed;
3805 } 3804 }
3806 max_freed_overall = Max(max_freed, max_freed_overall); 3805 max_freed_overall = Max(max_freed, max_freed_overall);
3807 if (p == space->end_of_unswept_pages()) break; 3806 page_count++;
3807 if (max_pages > 0 && page_count >= max_pages) {
3808 break;
3809 }
3808 } 3810 }
3809 return max_freed_overall; 3811 return max_freed_overall;
3810 } 3812 }
3811 3813
3812 3814
3813 int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) { 3815 int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) {
3814 int max_freed = 0; 3816 int max_freed = 0;
3815 if (page->TryLock()) { 3817 if (page->TryLock()) {
3816 // If this page was already swept in the meantime, we can return here. 3818 // If this page was already swept in the meantime, we can return here.
3817 if (page->parallel_sweeping_state().Value() != 3819 if (page->parallel_sweeping_state().Value() !=
(...skipping 23 matching lines...) Expand all
3841 free_list->Concatenate(&private_free_list); 3843 free_list->Concatenate(&private_free_list);
3842 page->mutex()->Unlock(); 3844 page->mutex()->Unlock();
3843 } 3845 }
3844 return max_freed; 3846 return max_freed;
3845 } 3847 }
3846 3848
3847 3849
3848 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { 3850 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) {
3849 space->ClearStats(); 3851 space->ClearStats();
3850 3852
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); 3853 PageIterator it(space);
3856 3854
3857 int pages_swept = 0; 3855 int will_be_swept = 0;
3858 bool unused_page_present = false; 3856 bool unused_page_present = false;
3859 bool parallel_sweeping_active = false;
3860 3857
3861 while (it.has_next()) { 3858 while (it.has_next()) {
3862 Page* p = it.next(); 3859 Page* p = it.next();
3863 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone); 3860 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
3864 3861
3865 // Clear sweeping flags indicating that marking bits are still intact. 3862 // Clear sweeping flags indicating that marking bits are still intact.
3866 p->ClearWasSwept(); 3863 p->ClearWasSwept();
3867 3864
3868 if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION) || 3865 if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION) ||
3869 p->IsEvacuationCandidate()) { 3866 p->IsEvacuationCandidate()) {
(...skipping 17 matching lines...) Expand all
3887 if (unused_page_present) { 3884 if (unused_page_present) {
3888 if (FLAG_gc_verbose) { 3885 if (FLAG_gc_verbose) {
3889 PrintIsolate(isolate(), "sweeping: released page: %p", p); 3886 PrintIsolate(isolate(), "sweeping: released page: %p", p);
3890 } 3887 }
3891 space->ReleasePage(p); 3888 space->ReleasePage(p);
3892 continue; 3889 continue;
3893 } 3890 }
3894 unused_page_present = true; 3891 unused_page_present = true;
3895 } 3892 }
3896 3893
3897 if (!parallel_sweeping_active) { 3894 sweeping_list(space).push_back(p);
3898 if (FLAG_gc_verbose) { 3895 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending);
3899 PrintIsolate(isolate(), "sweeping: %p", p); 3896 int to_sweep = p->area_size() - p->LiveBytes();
3900 } 3897 space->accounting_stats_.ShrinkSpace(to_sweep);
3901 if (space->identity() == CODE_SPACE) { 3898 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 } 3899 }
3925 3900
3926 if (FLAG_gc_verbose) { 3901 if (FLAG_gc_verbose) {
3927 PrintIsolate(isolate(), "sweeping: space=%s pages_swept=%d", 3902 PrintIsolate(isolate(), "sweeping: space=%s initialized_for_sweeping=%d",
3928 AllocationSpaceName(space->identity()), pages_swept); 3903 AllocationSpaceName(space->identity()), will_be_swept);
3929 } 3904 }
3905 std::sort(sweeping_list(space).begin(), sweeping_list(space).end(),
3906 [](Page* a, Page* b) { return a->LiveBytes() < b->LiveBytes(); });
3930 } 3907 }
3931 3908
3932 3909
3933 void MarkCompactCollector::SweepSpaces() { 3910 void MarkCompactCollector::SweepSpaces() {
3934 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_SWEEP); 3911 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_SWEEP);
3935 double start_time = 0.0; 3912 double start_time = 0.0;
3936 if (FLAG_print_cumulative_gc_stat) { 3913 if (FLAG_print_cumulative_gc_stat) {
3937 start_time = heap_->MonotonicallyIncreasingTimeInMs(); 3914 start_time = heap_->MonotonicallyIncreasingTimeInMs();
3938 } 3915 }
3939 3916
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3973 heap()->FreeQueuedChunks(); 3950 heap()->FreeQueuedChunks();
3974 3951
3975 if (FLAG_print_cumulative_gc_stat) { 3952 if (FLAG_print_cumulative_gc_stat) {
3976 heap_->tracer()->AddSweepingTime(heap_->MonotonicallyIncreasingTimeInMs() - 3953 heap_->tracer()->AddSweepingTime(heap_->MonotonicallyIncreasingTimeInMs() -
3977 start_time); 3954 start_time);
3978 } 3955 }
3979 } 3956 }
3980 3957
3981 3958
3982 void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) { 3959 void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) {
3983 PageIterator it(space); 3960 for (Page* p : sweeping_list(space)) {
3984 while (it.has_next()) {
3985 Page* p = it.next();
3986 if (p->parallel_sweeping_state().Value() == 3961 if (p->parallel_sweeping_state().Value() ==
3987 MemoryChunk::kSweepingFinalize) { 3962 MemoryChunk::kSweepingFinalize) {
3988 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone); 3963 p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone);
3989 p->SetWasSwept(); 3964 p->SetWasSwept();
3990 } 3965 }
3991 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone); 3966 DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
3992 } 3967 }
3993 } 3968 }
3994 3969
3995 3970
3996 void MarkCompactCollector::ParallelSweepSpacesComplete() { 3971 void MarkCompactCollector::ParallelSweepSpacesComplete() {
3997 ParallelSweepSpaceComplete(heap()->old_space()); 3972 ParallelSweepSpaceComplete(heap()->old_space());
3998 ParallelSweepSpaceComplete(heap()->code_space()); 3973 ParallelSweepSpaceComplete(heap()->code_space());
3999 ParallelSweepSpaceComplete(heap()->map_space()); 3974 ParallelSweepSpaceComplete(heap()->map_space());
3975 sweeping_list(heap()->old_space()).clear();
3976 sweeping_list(heap()->code_space()).clear();
3977 sweeping_list(heap()->map_space()).clear();
4000 } 3978 }
4001 3979
4002 3980
4003 // TODO(1466) ReportDeleteIfNeeded is not called currently. 3981 // TODO(1466) ReportDeleteIfNeeded is not called currently.
4004 // Our profiling tools do not expect intersections between 3982 // Our profiling tools do not expect intersections between
4005 // code objects. We should either reenable it or change our tools. 3983 // code objects. We should either reenable it or change our tools.
4006 void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj, 3984 void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj,
4007 Isolate* isolate) { 3985 Isolate* isolate) {
4008 if (obj->IsCode()) { 3986 if (obj->IsCode()) {
4009 PROFILE(isolate, CodeDeleteEvent(obj->address())); 3987 PROFILE(isolate, CodeDeleteEvent(obj->address()));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4067 MarkBit mark_bit = Marking::MarkBitFrom(host); 4045 MarkBit mark_bit = Marking::MarkBitFrom(host);
4068 if (Marking::IsBlack(mark_bit)) { 4046 if (Marking::IsBlack(mark_bit)) {
4069 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); 4047 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host);
4070 RecordRelocSlot(&rinfo, target); 4048 RecordRelocSlot(&rinfo, target);
4071 } 4049 }
4072 } 4050 }
4073 } 4051 }
4074 4052
4075 } // namespace internal 4053 } // namespace internal
4076 } // namespace v8 4054 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/mark-compact-inl.h » ('j') | src/heap/spaces.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698