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 3795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3806 return page; | 3806 return page; |
3807 } | 3807 } |
3808 | 3808 |
3809 void MarkCompactCollector::Sweeper::AddSweepingPageSafe(AllocationSpace space, | 3809 void MarkCompactCollector::Sweeper::AddSweepingPageSafe(AllocationSpace space, |
3810 Page* page) { | 3810 Page* page) { |
3811 base::LockGuard<base::Mutex> guard(&mutex_); | 3811 base::LockGuard<base::Mutex> guard(&mutex_); |
3812 sweeping_list_[space].push_back(page); | 3812 sweeping_list_[space].push_back(page); |
3813 } | 3813 } |
3814 | 3814 |
3815 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { | 3815 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { |
| 3816 Address space_top = space->top(); |
3816 space->ClearStats(); | 3817 space->ClearStats(); |
3817 | 3818 |
3818 PageIterator it(space); | 3819 PageIterator it(space); |
3819 | 3820 |
3820 int will_be_swept = 0; | 3821 int will_be_swept = 0; |
3821 bool unused_page_present = false; | 3822 bool unused_page_present = false; |
3822 | 3823 |
3823 while (it.has_next()) { | 3824 while (it.has_next()) { |
3824 Page* p = it.next(); | 3825 Page* p = it.next(); |
3825 DCHECK(p->SweepingDone()); | 3826 DCHECK(p->SweepingDone()); |
3826 | 3827 |
3827 if (p->IsEvacuationCandidate()) { | 3828 if (p->IsEvacuationCandidate()) { |
3828 // Will be processed in EvacuateNewSpaceAndCandidates. | 3829 // Will be processed in EvacuateNewSpaceAndCandidates. |
3829 DCHECK(evacuation_candidates_.length() > 0); | 3830 DCHECK(evacuation_candidates_.length() > 0); |
3830 continue; | 3831 continue; |
3831 } | 3832 } |
3832 | 3833 |
3833 // We can not sweep black pages, since all mark bits are set for these | 3834 // We can not sweep black pages, since all mark bits are set for these |
3834 // pages. | 3835 // pages. |
3835 if (p->IsFlagSet(Page::BLACK_PAGE)) { | 3836 if (p->IsFlagSet(Page::BLACK_PAGE)) { |
3836 Bitmap::Clear(p); | 3837 Bitmap::Clear(p); |
3837 p->concurrent_sweeping_state().SetValue(Page::kSweepingDone); | 3838 p->concurrent_sweeping_state().SetValue(Page::kSweepingDone); |
3838 p->ClearFlag(Page::BLACK_PAGE); | 3839 p->ClearFlag(Page::BLACK_PAGE); |
3839 // TODO(hpayer): Free unused memory of last black page. | 3840 // Area above the high watermark is free. |
| 3841 Address free_start = p->HighWaterMark(); |
| 3842 // Check if the space top was in this page, which means that the |
| 3843 // high watermark is not up-to-date. |
| 3844 if (free_start < space_top && space_top <= p->area_end()) { |
| 3845 free_start = space_top; |
| 3846 } |
| 3847 int size = static_cast<int>(p->area_end() - free_start); |
| 3848 space->Free(free_start, size); |
3840 continue; | 3849 continue; |
3841 } | 3850 } |
3842 | 3851 |
3843 if (p->IsFlagSet(Page::NEVER_ALLOCATE_ON_PAGE)) { | 3852 if (p->IsFlagSet(Page::NEVER_ALLOCATE_ON_PAGE)) { |
3844 // We need to sweep the page to get it into an iterable state again. Note | 3853 // We need to sweep the page to get it into an iterable state again. Note |
3845 // that this adds unusable memory into the free list that is later on | 3854 // that this adds unusable memory into the free list that is later on |
3846 // (in the free list) dropped again. Since we only use the flag for | 3855 // (in the free list) dropped again. Since we only use the flag for |
3847 // testing this is fine. | 3856 // testing this is fine. |
3848 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); | 3857 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); |
3849 Sweeper::RawSweep<Sweeper::SWEEP_ONLY, Sweeper::SWEEP_ON_MAIN_THREAD, | 3858 Sweeper::RawSweep<Sweeper::SWEEP_ONLY, Sweeper::SWEEP_ON_MAIN_THREAD, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3943 MarkBit mark_bit = Marking::MarkBitFrom(host); | 3952 MarkBit mark_bit = Marking::MarkBitFrom(host); |
3944 if (Marking::IsBlack(mark_bit)) { | 3953 if (Marking::IsBlack(mark_bit)) { |
3945 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 3954 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
3946 RecordRelocSlot(host, &rinfo, target); | 3955 RecordRelocSlot(host, &rinfo, target); |
3947 } | 3956 } |
3948 } | 3957 } |
3949 } | 3958 } |
3950 | 3959 |
3951 } // namespace internal | 3960 } // namespace internal |
3952 } // namespace v8 | 3961 } // namespace v8 |
OLD | NEW |