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/slots-buffer.h" | 10 #include "src/heap/slots-buffer.h" |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == | 945 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == |
946 ObjectSpace::kObjectSpaceOldSpace); | 946 ObjectSpace::kObjectSpaceOldSpace); |
947 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == | 947 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == |
948 ObjectSpace::kObjectSpaceCodeSpace); | 948 ObjectSpace::kObjectSpaceCodeSpace); |
949 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == | 949 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == |
950 ObjectSpace::kObjectSpaceMapSpace); | 950 ObjectSpace::kObjectSpaceMapSpace); |
951 | 951 |
952 | 952 |
953 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, | 953 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, |
954 Executability executable) | 954 Executability executable) |
955 : Space(heap, space, executable), | 955 : Space(heap, space, executable), free_list_(this) { |
956 free_list_(this), | |
957 end_of_unswept_pages_(NULL) { | |
958 area_size_ = MemoryAllocator::PageAreaSize(space); | 956 area_size_ = MemoryAllocator::PageAreaSize(space); |
959 accounting_stats_.Clear(); | 957 accounting_stats_.Clear(); |
960 | 958 |
961 allocation_info_.Reset(nullptr, nullptr); | 959 allocation_info_.Reset(nullptr, nullptr); |
962 | 960 |
963 anchor_.InitializeAsAnchor(this); | 961 anchor_.InitializeAsAnchor(this); |
964 } | 962 } |
965 | 963 |
966 | 964 |
967 bool PagedSpace::SetUp() { return true; } | 965 bool PagedSpace::SetUp() { return true; } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 MoveOverFreeMemory(other); | 1100 MoveOverFreeMemory(other); |
1103 | 1101 |
1104 // Update and clear accounting statistics. | 1102 // Update and clear accounting statistics. |
1105 accounting_stats_.Merge(other->accounting_stats_); | 1103 accounting_stats_.Merge(other->accounting_stats_); |
1106 other->accounting_stats_.Clear(); | 1104 other->accounting_stats_.Clear(); |
1107 | 1105 |
1108 // The linear allocation area of {other} should be destroyed now. | 1106 // The linear allocation area of {other} should be destroyed now. |
1109 DCHECK(other->top() == nullptr); | 1107 DCHECK(other->top() == nullptr); |
1110 DCHECK(other->limit() == nullptr); | 1108 DCHECK(other->limit() == nullptr); |
1111 | 1109 |
1112 DCHECK(other->end_of_unswept_pages_ == nullptr); | |
1113 | |
1114 AccountCommitted(other->CommittedMemory()); | 1110 AccountCommitted(other->CommittedMemory()); |
1115 | 1111 |
1116 // Move over pages. | 1112 // Move over pages. |
1117 PageIterator it(other); | 1113 PageIterator it(other); |
1118 Page* p = nullptr; | 1114 Page* p = nullptr; |
1119 while (it.has_next()) { | 1115 while (it.has_next()) { |
1120 p = it.next(); | 1116 p = it.next(); |
1121 p->Unlink(); | 1117 p->Unlink(); |
1122 p->set_owner(this); | 1118 p->set_owner(this); |
1123 p->InsertAfter(anchor_.prev_page()); | 1119 p->InsertAfter(anchor_.prev_page()); |
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 2826 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
2831 if (collector->sweeping_in_progress()) { | 2827 if (collector->sweeping_in_progress()) { |
2832 collector->SweepAndRefill(this); | 2828 collector->SweepAndRefill(this); |
2833 return free_list_.Allocate(size_in_bytes); | 2829 return free_list_.Allocate(size_in_bytes); |
2834 } | 2830 } |
2835 return nullptr; | 2831 return nullptr; |
2836 } | 2832 } |
2837 | 2833 |
2838 | 2834 |
2839 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { | 2835 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
| 2836 const int kMaxPagesToSweep = 1; |
| 2837 |
2840 // Allocation in this space has failed. | 2838 // Allocation in this space has failed. |
2841 | 2839 |
2842 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 2840 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
2843 // Sweeping is still in progress. | 2841 // Sweeping is still in progress. |
2844 if (collector->sweeping_in_progress()) { | 2842 if (collector->sweeping_in_progress()) { |
2845 // First try to refill the free-list, concurrent sweeper threads | 2843 // First try to refill the free-list, concurrent sweeper threads |
2846 // may have freed some objects in the meantime. | 2844 // may have freed some objects in the meantime. |
2847 RefillFreeList(); | 2845 RefillFreeList(); |
2848 | 2846 |
2849 // Retry the free list allocation. | 2847 // Retry the free list allocation. |
2850 HeapObject* object = free_list_.Allocate(size_in_bytes); | 2848 HeapObject* object = free_list_.Allocate(size_in_bytes); |
2851 if (object != NULL) return object; | 2849 if (object != NULL) return object; |
2852 | 2850 |
2853 // If sweeping is still in progress try to sweep pages on the main thread. | 2851 // If sweeping is still in progress try to sweep pages on the main thread. |
2854 collector->SweepInParallel(heap()->paged_space(identity()), size_in_bytes); | 2852 int max_freed = collector->SweepInParallel(heap()->paged_space(identity()), |
| 2853 size_in_bytes, kMaxPagesToSweep); |
2855 RefillFreeList(); | 2854 RefillFreeList(); |
2856 object = free_list_.Allocate(size_in_bytes); | 2855 if (max_freed >= size_in_bytes) { |
2857 if (object != nullptr) return object; | 2856 object = free_list_.Allocate(size_in_bytes); |
| 2857 if (object != nullptr) return object; |
| 2858 } |
2858 } | 2859 } |
2859 | 2860 |
2860 // Free list allocation failed and there is no next page. Fail if we have | 2861 // Free list allocation failed and there is no next page. Fail if we have |
2861 // hit the old generation size limit that should cause a garbage | 2862 // hit the old generation size limit that should cause a garbage |
2862 // collection. | 2863 // collection. |
2863 if (!heap()->always_allocate() && | 2864 if (!heap()->always_allocate() && |
2864 heap()->OldGenerationAllocationLimitReached()) { | 2865 heap()->OldGenerationAllocationLimitReached()) { |
2865 // If sweeper threads are active, wait for them at that point and steal | 2866 // If sweeper threads are active, wait for them at that point and steal |
2866 // elements form their free-lists. | 2867 // elements form their free-lists. |
2867 HeapObject* object = SweepAndRetryAllocation(size_in_bytes); | 2868 HeapObject* object = SweepAndRetryAllocation(size_in_bytes); |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 object->ShortPrint(); | 3364 object->ShortPrint(); |
3364 PrintF("\n"); | 3365 PrintF("\n"); |
3365 } | 3366 } |
3366 printf(" --------------------------------------\n"); | 3367 printf(" --------------------------------------\n"); |
3367 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3368 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3368 } | 3369 } |
3369 | 3370 |
3370 #endif // DEBUG | 3371 #endif // DEBUG |
3371 } // namespace internal | 3372 } // namespace internal |
3372 } // namespace v8 | 3373 } // namespace v8 |
OLD | NEW |