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 3723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3734 if ((required_freed_bytes) > 0 && (max_freed >= required_freed_bytes)) | 3734 if ((required_freed_bytes) > 0 && (max_freed >= required_freed_bytes)) |
3735 return max_freed; | 3735 return max_freed; |
3736 if ((max_pages > 0) && (pages_freed >= max_pages)) return max_freed; | 3736 if ((max_pages > 0) && (pages_freed >= max_pages)) return max_freed; |
3737 } | 3737 } |
3738 return max_freed; | 3738 return max_freed; |
3739 } | 3739 } |
3740 | 3740 |
3741 int MarkCompactCollector::Sweeper::ParallelSweepPage(Page* page, | 3741 int MarkCompactCollector::Sweeper::ParallelSweepPage(Page* page, |
3742 AllocationSpace identity) { | 3742 AllocationSpace identity) { |
3743 int max_freed = 0; | 3743 int max_freed = 0; |
3744 if (page->mutex()->TryLock()) { | 3744 { |
| 3745 base::LockGuard<base::Mutex> guard(page->mutex()); |
3745 // If this page was already swept in the meantime, we can return here. | 3746 // If this page was already swept in the meantime, we can return here. |
3746 if (page->concurrent_sweeping_state().Value() != Page::kSweepingPending) { | 3747 if (page->SweepingDone()) return 0; |
3747 page->mutex()->Unlock(); | 3748 DCHECK_EQ(Page::kSweepingPending, |
3748 return 0; | 3749 page->concurrent_sweeping_state().Value()); |
3749 } | |
3750 page->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); | 3750 page->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); |
3751 const Sweeper::FreeSpaceTreatmentMode free_space_mode = | 3751 const Sweeper::FreeSpaceTreatmentMode free_space_mode = |
3752 Heap::ShouldZapGarbage() ? ZAP_FREE_SPACE : IGNORE_FREE_SPACE; | 3752 Heap::ShouldZapGarbage() ? ZAP_FREE_SPACE : IGNORE_FREE_SPACE; |
3753 if (identity == NEW_SPACE) { | 3753 if (identity == NEW_SPACE) { |
3754 RawSweep(page, IGNORE_FREE_LIST, free_space_mode); | 3754 RawSweep(page, IGNORE_FREE_LIST, free_space_mode); |
3755 } else { | 3755 } else { |
3756 max_freed = RawSweep(page, REBUILD_FREE_LIST, free_space_mode); | 3756 max_freed = RawSweep(page, REBUILD_FREE_LIST, free_space_mode); |
3757 } | 3757 } |
| 3758 DCHECK(page->SweepingDone()); |
3758 | 3759 |
3759 // After finishing sweeping of a page we clean up its remembered set. | 3760 // After finishing sweeping of a page we clean up its remembered set. |
3760 if (page->typed_old_to_new_slots()) { | 3761 if (page->typed_old_to_new_slots()) { |
3761 page->typed_old_to_new_slots()->FreeToBeFreedChunks(); | 3762 page->typed_old_to_new_slots()->FreeToBeFreedChunks(); |
3762 } | 3763 } |
3763 if (page->old_to_new_slots()) { | 3764 if (page->old_to_new_slots()) { |
3764 page->old_to_new_slots()->FreeToBeFreedBuckets(); | 3765 page->old_to_new_slots()->FreeToBeFreedBuckets(); |
3765 } | 3766 } |
| 3767 } |
3766 | 3768 |
3767 { | 3769 { |
3768 base::LockGuard<base::Mutex> guard(&mutex_); | 3770 base::LockGuard<base::Mutex> guard(&mutex_); |
3769 swept_list_[identity].Add(page); | 3771 swept_list_[identity].Add(page); |
3770 } | |
3771 page->concurrent_sweeping_state().SetValue(Page::kSweepingDone); | |
3772 page->mutex()->Unlock(); | |
3773 } | 3772 } |
3774 return max_freed; | 3773 return max_freed; |
3775 } | 3774 } |
3776 | 3775 |
3777 void MarkCompactCollector::Sweeper::AddPage(AllocationSpace space, Page* page) { | 3776 void MarkCompactCollector::Sweeper::AddPage(AllocationSpace space, Page* page) { |
3778 DCHECK(!FLAG_concurrent_sweeping || !AreSweeperTasksRunning()); | 3777 DCHECK(!FLAG_concurrent_sweeping || !AreSweeperTasksRunning()); |
3779 PrepareToBeSweptPage(space, page); | 3778 PrepareToBeSweptPage(space, page); |
3780 sweeping_list_[space].push_back(page); | 3779 sweeping_list_[space].push_back(page); |
3781 } | 3780 } |
3782 | 3781 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3922 // The target is always in old space, we don't have to record the slot in | 3921 // The target is always in old space, we don't have to record the slot in |
3923 // the old-to-new remembered set. | 3922 // the old-to-new remembered set. |
3924 DCHECK(!heap()->InNewSpace(target)); | 3923 DCHECK(!heap()->InNewSpace(target)); |
3925 RecordRelocSlot(host, &rinfo, target); | 3924 RecordRelocSlot(host, &rinfo, target); |
3926 } | 3925 } |
3927 } | 3926 } |
3928 } | 3927 } |
3929 | 3928 |
3930 } // namespace internal | 3929 } // namespace internal |
3931 } // namespace v8 | 3930 } // namespace v8 |
OLD | NEW |