OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/spaces.h" | 5 #include "src/heap/spaces.h" |
6 | 6 |
7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/full-codegen/full-codegen.h" | 9 #include "src/full-codegen/full-codegen.h" |
10 #include "src/heap/slot-set.h" | 10 #include "src/heap/slot-set.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if (page_mode_ == kOnePageOnly) return false; | 55 if (page_mode_ == kOnePageOnly) return false; |
56 Page* cur_page; | 56 Page* cur_page; |
57 if (cur_addr_ == NULL) { | 57 if (cur_addr_ == NULL) { |
58 cur_page = space_->anchor(); | 58 cur_page = space_->anchor(); |
59 } else { | 59 } else { |
60 cur_page = Page::FromAddress(cur_addr_ - 1); | 60 cur_page = Page::FromAddress(cur_addr_ - 1); |
61 DCHECK(cur_addr_ == cur_page->area_end()); | 61 DCHECK(cur_addr_ == cur_page->area_end()); |
62 } | 62 } |
63 cur_page = cur_page->next_page(); | 63 cur_page = cur_page->next_page(); |
64 if (cur_page == space_->anchor()) return false; | 64 if (cur_page == space_->anchor()) return false; |
65 cur_page->heap()->mark_compact_collector()->SweepOrWaitUntilSweepingCompleted( | 65 cur_page->heap() |
66 cur_page); | 66 ->mark_compact_collector() |
| 67 ->sweeper() |
| 68 .SweepOrWaitUntilSweepingCompleted(cur_page); |
67 cur_addr_ = cur_page->area_start(); | 69 cur_addr_ = cur_page->area_start(); |
68 cur_end_ = cur_page->area_end(); | 70 cur_end_ = cur_page->area_end(); |
69 DCHECK(cur_page->SweepingDone()); | 71 DCHECK(cur_page->SweepingDone()); |
70 return true; | 72 return true; |
71 } | 73 } |
72 | 74 |
73 PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap) | 75 PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap) |
74 : heap_(heap) { | 76 : heap_(heap) { |
75 AllSpaces spaces(heap_); | 77 AllSpaces spaces(heap_); |
76 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { | 78 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 } | 1050 } |
1049 | 1051 |
1050 void PagedSpace::RefillFreeList() { | 1052 void PagedSpace::RefillFreeList() { |
1051 // Any PagedSpace might invoke RefillFreeList. We filter all but our old | 1053 // Any PagedSpace might invoke RefillFreeList. We filter all but our old |
1052 // generation spaces out. | 1054 // generation spaces out. |
1053 if (identity() != OLD_SPACE && identity() != CODE_SPACE && | 1055 if (identity() != OLD_SPACE && identity() != CODE_SPACE && |
1054 identity() != MAP_SPACE) { | 1056 identity() != MAP_SPACE) { |
1055 return; | 1057 return; |
1056 } | 1058 } |
1057 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 1059 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
1058 List<Page*>* swept_pages = collector->swept_pages(identity()); | |
1059 intptr_t added = 0; | 1060 intptr_t added = 0; |
1060 { | 1061 { |
1061 base::LockGuard<base::Mutex> guard(collector->swept_pages_mutex()); | 1062 Page* p = nullptr; |
1062 for (int i = swept_pages->length() - 1; i >= 0; --i) { | 1063 while ((p = collector->sweeper().GetSweptPageSafe(this)) != nullptr) { |
1063 Page* p = (*swept_pages)[i]; | |
1064 // Only during compaction pages can actually change ownership. This is | 1064 // Only during compaction pages can actually change ownership. This is |
1065 // safe because there exists no other competing action on the page links | 1065 // safe because there exists no other competing action on the page links |
1066 // during compaction. | 1066 // during compaction. |
1067 if (is_local() && (p->owner() != this)) { | 1067 if (is_local() && (p->owner() != this)) { |
1068 if (added > kCompactionMemoryWanted) break; | |
1069 base::LockGuard<base::Mutex> guard( | 1068 base::LockGuard<base::Mutex> guard( |
1070 reinterpret_cast<PagedSpace*>(p->owner())->mutex()); | 1069 reinterpret_cast<PagedSpace*>(p->owner())->mutex()); |
1071 p->Unlink(); | 1070 p->Unlink(); |
1072 p->set_owner(this); | 1071 p->set_owner(this); |
1073 p->InsertAfter(anchor_.prev_page()); | 1072 p->InsertAfter(anchor_.prev_page()); |
1074 } | 1073 } |
1075 added += RelinkFreeListCategories(p); | 1074 added += RelinkFreeListCategories(p); |
1076 added += p->wasted_memory(); | 1075 added += p->wasted_memory(); |
1077 swept_pages->Remove(i); | 1076 if (is_local() && (added > kCompactionMemoryWanted)) break; |
1078 } | 1077 } |
1079 } | 1078 } |
1080 accounting_stats_.IncreaseCapacity(added); | 1079 accounting_stats_.IncreaseCapacity(added); |
1081 } | 1080 } |
1082 | 1081 |
1083 void PagedSpace::MergeCompactionSpace(CompactionSpace* other) { | 1082 void PagedSpace::MergeCompactionSpace(CompactionSpace* other) { |
1084 DCHECK(identity() == other->identity()); | 1083 DCHECK(identity() == other->identity()); |
1085 // Unmerged fields: | 1084 // Unmerged fields: |
1086 // area_size_ | 1085 // area_size_ |
1087 // anchor_ | 1086 // anchor_ |
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 if (collector->sweeping_in_progress()) { | 2615 if (collector->sweeping_in_progress()) { |
2617 // First try to refill the free-list, concurrent sweeper threads | 2616 // First try to refill the free-list, concurrent sweeper threads |
2618 // may have freed some objects in the meantime. | 2617 // may have freed some objects in the meantime. |
2619 RefillFreeList(); | 2618 RefillFreeList(); |
2620 | 2619 |
2621 // Retry the free list allocation. | 2620 // Retry the free list allocation. |
2622 HeapObject* object = free_list_.Allocate(size_in_bytes); | 2621 HeapObject* object = free_list_.Allocate(size_in_bytes); |
2623 if (object != NULL) return object; | 2622 if (object != NULL) return object; |
2624 | 2623 |
2625 // If sweeping is still in progress try to sweep pages on the main thread. | 2624 // If sweeping is still in progress try to sweep pages on the main thread. |
2626 int max_freed = collector->SweepInParallel(heap()->paged_space(identity()), | 2625 int max_freed = collector->sweeper().ParallelSweepSpace( |
2627 size_in_bytes, kMaxPagesToSweep); | 2626 identity(), size_in_bytes, kMaxPagesToSweep); |
2628 RefillFreeList(); | 2627 RefillFreeList(); |
2629 if (max_freed >= size_in_bytes) { | 2628 if (max_freed >= size_in_bytes) { |
2630 object = free_list_.Allocate(size_in_bytes); | 2629 object = free_list_.Allocate(size_in_bytes); |
2631 if (object != nullptr) return object; | 2630 if (object != nullptr) return object; |
2632 } | 2631 } |
2633 } | 2632 } |
2634 | 2633 |
2635 // Free list allocation failed and there is no next page. Fail if we have | 2634 // Free list allocation failed and there is no next page. Fail if we have |
2636 // hit the old generation size limit that should cause a garbage | 2635 // hit the old generation size limit that should cause a garbage |
2637 // collection. | 2636 // collection. |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3136 object->ShortPrint(); | 3135 object->ShortPrint(); |
3137 PrintF("\n"); | 3136 PrintF("\n"); |
3138 } | 3137 } |
3139 printf(" --------------------------------------\n"); | 3138 printf(" --------------------------------------\n"); |
3140 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3139 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3141 } | 3140 } |
3142 | 3141 |
3143 #endif // DEBUG | 3142 #endif // DEBUG |
3144 } // namespace internal | 3143 } // namespace internal |
3145 } // namespace v8 | 3144 } // namespace v8 |
OLD | NEW |