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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/base/platform/platform.h" | 7 #include "src/base/platform/platform.h" |
8 #include "src/full-codegen.h" | 8 #include "src/full-codegen.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/mark-compact.h" | 10 #include "src/mark-compact.h" |
(...skipping 2563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2574 int remaining = | 2574 int remaining = |
2575 static_cast<int>(allocation_info_.limit() - allocation_info_.top()); | 2575 static_cast<int>(allocation_info_.limit() - allocation_info_.top()); |
2576 heap()->CreateFillerObjectAt(allocation_info_.top(), remaining); | 2576 heap()->CreateFillerObjectAt(allocation_info_.top(), remaining); |
2577 | 2577 |
2578 allocation_info_.set_top(NULL); | 2578 allocation_info_.set_top(NULL); |
2579 allocation_info_.set_limit(NULL); | 2579 allocation_info_.set_limit(NULL); |
2580 } | 2580 } |
2581 } | 2581 } |
2582 | 2582 |
2583 | 2583 |
2584 HeapObject* PagedSpace::WaitForSweeperThreadsAndRetryAllocation( | 2584 HeapObject* PagedSpace::EnsureSweepingProgress( |
2585 int size_in_bytes) { | 2585 int size_in_bytes) { |
2586 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 2586 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
2587 | 2587 |
2588 // If sweeper threads are still running, wait for them. | |
2589 if (collector->IsConcurrentSweepingInProgress(this)) { | 2588 if (collector->IsConcurrentSweepingInProgress(this)) { |
| 2589 // If sweeping is still in progress try to sweep pages on the main thread. |
| 2590 int free_chunk = |
| 2591 collector->SweepInParallel(this, size_in_bytes); |
| 2592 if (free_chunk >= size_in_bytes) { |
| 2593 HeapObject* object = free_list_.Allocate(size_in_bytes); |
| 2594 // We should be able to allocate an object here since we just freed that |
| 2595 // much memory. |
| 2596 ASSERT(object != NULL); |
| 2597 if (object != NULL) return object; |
| 2598 } |
| 2599 |
| 2600 // Wait for the sweeper threads here and complete the sweeping phase. |
2590 collector->WaitUntilSweepingCompleted(); | 2601 collector->WaitUntilSweepingCompleted(); |
2591 | 2602 |
2592 // After waiting for the sweeper threads, there may be new free-list | 2603 // After waiting for the sweeper threads, there may be new free-list |
2593 // entries. | 2604 // entries. |
2594 return free_list_.Allocate(size_in_bytes); | 2605 return free_list_.Allocate(size_in_bytes); |
2595 } | 2606 } |
2596 return NULL; | 2607 return NULL; |
2597 } | 2608 } |
2598 | 2609 |
2599 | 2610 |
(...skipping 10 matching lines...) Expand all Loading... |
2610 if (object != NULL) return object; | 2621 if (object != NULL) return object; |
2611 } | 2622 } |
2612 | 2623 |
2613 // Free list allocation failed and there is no next page. Fail if we have | 2624 // Free list allocation failed and there is no next page. Fail if we have |
2614 // hit the old generation size limit that should cause a garbage | 2625 // hit the old generation size limit that should cause a garbage |
2615 // collection. | 2626 // collection. |
2616 if (!heap()->always_allocate() | 2627 if (!heap()->always_allocate() |
2617 && heap()->OldGenerationAllocationLimitReached()) { | 2628 && heap()->OldGenerationAllocationLimitReached()) { |
2618 // If sweeper threads are active, wait for them at that point and steal | 2629 // If sweeper threads are active, wait for them at that point and steal |
2619 // elements form their free-lists. | 2630 // elements form their free-lists. |
2620 HeapObject* object = WaitForSweeperThreadsAndRetryAllocation(size_in_bytes); | 2631 HeapObject* object = EnsureSweepingProgress(size_in_bytes); |
2621 if (object != NULL) return object; | 2632 if (object != NULL) return object; |
2622 } | 2633 } |
2623 | 2634 |
2624 // Try to expand the space and allocate in the new next page. | 2635 // Try to expand the space and allocate in the new next page. |
2625 if (Expand()) { | 2636 if (Expand()) { |
2626 ASSERT(CountTotalPages() > 1 || size_in_bytes <= free_list_.available()); | 2637 ASSERT(CountTotalPages() > 1 || size_in_bytes <= free_list_.available()); |
2627 return free_list_.Allocate(size_in_bytes); | 2638 return free_list_.Allocate(size_in_bytes); |
2628 } | 2639 } |
2629 | 2640 |
2630 // If sweeper threads are active, wait for them at that point and steal | 2641 // If sweeper threads are active, wait for them at that point and steal |
2631 // elements form their free-lists. Allocation may still fail their which | 2642 // elements form their free-lists. Allocation may still fail their which |
2632 // would indicate that there is not enough memory for the given allocation. | 2643 // would indicate that there is not enough memory for the given allocation. |
2633 return WaitForSweeperThreadsAndRetryAllocation(size_in_bytes); | 2644 return EnsureSweepingProgress(size_in_bytes); |
2634 } | 2645 } |
2635 | 2646 |
2636 | 2647 |
2637 #ifdef DEBUG | 2648 #ifdef DEBUG |
2638 void PagedSpace::ReportCodeStatistics(Isolate* isolate) { | 2649 void PagedSpace::ReportCodeStatistics(Isolate* isolate) { |
2639 CommentStatistic* comments_statistics = | 2650 CommentStatistic* comments_statistics = |
2640 isolate->paged_space_comments_statistics(); | 2651 isolate->paged_space_comments_statistics(); |
2641 ReportCodeKindStatistics(isolate->code_kind_statistics()); | 2652 ReportCodeKindStatistics(isolate->code_kind_statistics()); |
2642 PrintF("Code comment statistics (\" [ comment-txt : size/ " | 2653 PrintF("Code comment statistics (\" [ comment-txt : size/ " |
2643 "count (average)\"):\n"); | 2654 "count (average)\"):\n"); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3141 object->ShortPrint(); | 3152 object->ShortPrint(); |
3142 PrintF("\n"); | 3153 PrintF("\n"); |
3143 } | 3154 } |
3144 printf(" --------------------------------------\n"); | 3155 printf(" --------------------------------------\n"); |
3145 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3156 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3146 } | 3157 } |
3147 | 3158 |
3148 #endif // DEBUG | 3159 #endif // DEBUG |
3149 | 3160 |
3150 } } // namespace v8::internal | 3161 } } // namespace v8::internal |
OLD | NEW |