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 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 2830 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
2831 if (collector->sweeping_in_progress()) { | 2831 if (collector->sweeping_in_progress()) { |
2832 collector->SweepAndRefill(this); | 2832 collector->SweepAndRefill(this); |
2833 return free_list_.Allocate(size_in_bytes); | 2833 return free_list_.Allocate(size_in_bytes); |
2834 } | 2834 } |
2835 return nullptr; | 2835 return nullptr; |
2836 } | 2836 } |
2837 | 2837 |
2838 | 2838 |
2839 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { | 2839 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
| 2840 const int kMaxPagesToSweep = 10; |
2840 // Allocation in this space has failed. | 2841 // Allocation in this space has failed. |
2841 | 2842 HeapObject* object = nullptr; |
2842 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 2843 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
2843 // Sweeping is still in progress. | 2844 // Sweeping is still in progress. |
2844 if (collector->sweeping_in_progress()) { | 2845 if (collector->sweeping_in_progress()) { |
2845 // First try to refill the free-list, concurrent sweeper threads | 2846 // First try to refill the free-list, concurrent sweeper threads |
2846 // may have freed some objects in the meantime. | 2847 // may have freed some objects in the meantime. |
2847 RefillFreeList(); | 2848 RefillFreeList(); |
| 2849 // Retry the free list allocation. |
| 2850 object = free_list_.Allocate(size_in_bytes); |
| 2851 if (object != nullptr) return object; |
2848 | 2852 |
2849 // Retry the free list allocation. | 2853 // If sweeping is still in progress and we are currently not compacting |
2850 HeapObject* object = free_list_.Allocate(size_in_bytes); | 2854 // try to sweep pages on the main thread. |
2851 if (object != NULL) return object; | 2855 collector->SweepInParallel(heap()->paged_space(identity()), size_in_bytes, |
2852 | 2856 kMaxPagesToSweep); |
2853 // If sweeping is still in progress try to sweep pages on the main thread. | |
2854 collector->SweepInParallel(heap()->paged_space(identity()), size_in_bytes); | |
2855 RefillFreeList(); | 2857 RefillFreeList(); |
2856 object = free_list_.Allocate(size_in_bytes); | 2858 object = free_list_.Allocate(size_in_bytes); |
2857 if (object != nullptr) return object; | 2859 if (object != nullptr) return object; |
2858 } | 2860 } |
2859 | 2861 |
2860 // Free list allocation failed and there is no next page. Fail if we have | 2862 // 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 | 2863 // hit the old generation size limit that should cause a garbage |
2862 // collection. | 2864 // collection. |
2863 if (!heap()->always_allocate() && | 2865 if (!heap()->always_allocate() && |
2864 heap()->OldGenerationAllocationLimitReached()) { | 2866 heap()->OldGenerationAllocationLimitReached()) { |
2865 // If sweeper threads are active, wait for them at that point and steal | 2867 // If sweeper threads are active, wait for them at that point and steal |
2866 // elements form their free-lists. | 2868 // elements form their free-lists. |
2867 HeapObject* object = SweepAndRetryAllocation(size_in_bytes); | 2869 return SweepAndRetryAllocation(size_in_bytes); |
2868 return object; | |
2869 } | 2870 } |
2870 | 2871 |
2871 // Try to expand the space and allocate in the new next page. | 2872 // Try to expand the space and allocate in the new next page. |
2872 if (Expand()) { | 2873 if (Expand()) { |
2873 DCHECK((CountTotalPages() > 1) || | 2874 DCHECK((CountTotalPages() > 1) || |
2874 (size_in_bytes <= free_list_.Available())); | 2875 (size_in_bytes <= free_list_.Available())); |
2875 return free_list_.Allocate(size_in_bytes); | 2876 return free_list_.Allocate(size_in_bytes); |
2876 } | 2877 } |
2877 | 2878 |
2878 // If sweeper threads are active, wait for them at that point and steal | 2879 // If sweeper threads are active, wait for them at that point and steal |
(...skipping 484 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 |