| 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/full-codegen.h" | 7 #include "src/full-codegen.h" |
| 8 #include "src/macro-assembler.h" | 8 #include "src/macro-assembler.h" |
| 9 #include "src/mark-compact.h" | 9 #include "src/mark-compact.h" |
| 10 #include "src/msan.h" | 10 #include "src/msan.h" |
| (...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 int remaining = | 2570 int remaining = |
| 2571 static_cast<int>(allocation_info_.limit() - allocation_info_.top()); | 2571 static_cast<int>(allocation_info_.limit() - allocation_info_.top()); |
| 2572 heap()->CreateFillerObjectAt(allocation_info_.top(), remaining); | 2572 heap()->CreateFillerObjectAt(allocation_info_.top(), remaining); |
| 2573 | 2573 |
| 2574 allocation_info_.set_top(NULL); | 2574 allocation_info_.set_top(NULL); |
| 2575 allocation_info_.set_limit(NULL); | 2575 allocation_info_.set_limit(NULL); |
| 2576 } | 2576 } |
| 2577 } | 2577 } |
| 2578 | 2578 |
| 2579 | 2579 |
| 2580 HeapObject* PagedSpace::WaitForSweeperThreadsAndRetryAllocation( |
| 2581 int size_in_bytes) { |
| 2582 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
| 2583 |
| 2584 // If sweeper threads are still running, wait for them. |
| 2585 if (collector->IsConcurrentSweepingInProgress()) { |
| 2586 collector->WaitUntilSweepingCompleted(); |
| 2587 |
| 2588 // After waiting for the sweeper threads, there may be new free-list |
| 2589 // entries. |
| 2590 return free_list_.Allocate(size_in_bytes); |
| 2591 } |
| 2592 return NULL; |
| 2593 } |
| 2594 |
| 2595 |
| 2580 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { | 2596 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
| 2581 // Allocation in this space has failed. | 2597 // Allocation in this space has failed. |
| 2582 | 2598 |
| 2583 // If sweeper threads are active, try to re-fill the free-lists. | 2599 // If sweeper threads are active, try to re-fill the free-lists. |
| 2584 MarkCompactCollector* collector = heap()->mark_compact_collector(); | 2600 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
| 2585 if (collector->IsConcurrentSweepingInProgress()) { | 2601 if (collector->IsConcurrentSweepingInProgress()) { |
| 2586 collector->RefillFreeList(this); | 2602 collector->RefillFreeList(this); |
| 2587 | 2603 |
| 2588 // Retry the free list allocation. | 2604 // Retry the free list allocation. |
| 2589 HeapObject* object = free_list_.Allocate(size_in_bytes); | 2605 HeapObject* object = free_list_.Allocate(size_in_bytes); |
| 2590 if (object != NULL) return object; | 2606 if (object != NULL) return object; |
| 2591 } | 2607 } |
| 2592 | 2608 |
| 2593 // Free list allocation failed and there is no next page. Fail if we have | 2609 // Free list allocation failed and there is no next page. Fail if we have |
| 2594 // hit the old generation size limit that should cause a garbage | 2610 // hit the old generation size limit that should cause a garbage |
| 2595 // collection. | 2611 // collection. |
| 2596 if (!heap()->always_allocate() && | 2612 if (!heap()->always_allocate() |
| 2597 heap()->OldGenerationAllocationLimitReached()) { | 2613 && heap()->OldGenerationAllocationLimitReached()) { |
| 2598 // If sweeper threads are active, wait for them at that point. | 2614 // If sweeper threads are active, wait for them at that point and steal |
| 2599 if (collector->IsConcurrentSweepingInProgress()) { | 2615 // elements form their free-lists. |
| 2600 collector->WaitUntilSweepingCompleted(); | 2616 HeapObject* object = WaitForSweeperThreadsAndRetryAllocation(size_in_bytes); |
| 2601 | 2617 if (object != NULL) return object; |
| 2602 // After waiting for the sweeper threads, there may be new free-list | |
| 2603 // entries. | |
| 2604 HeapObject* object = free_list_.Allocate(size_in_bytes); | |
| 2605 if (object != NULL) return object; | |
| 2606 } | |
| 2607 | |
| 2608 return NULL; | |
| 2609 } | 2618 } |
| 2610 | 2619 |
| 2611 // Try to expand the space and allocate in the new next page. | 2620 // Try to expand the space and allocate in the new next page. |
| 2612 if (Expand()) { | 2621 if (Expand()) { |
| 2613 ASSERT(CountTotalPages() > 1 || size_in_bytes <= free_list_.available()); | 2622 ASSERT(CountTotalPages() > 1 || size_in_bytes <= free_list_.available()); |
| 2614 return free_list_.Allocate(size_in_bytes); | 2623 return free_list_.Allocate(size_in_bytes); |
| 2615 } | 2624 } |
| 2616 | 2625 |
| 2617 // Finally, fail. | 2626 // If sweeper threads are active, wait for them at that point and steal |
| 2618 return NULL; | 2627 // elements form their free-lists. Allocation may still fail their which |
| 2628 // would indicate that there is not enough memory for the given allocation. |
| 2629 return WaitForSweeperThreadsAndRetryAllocation(size_in_bytes); |
| 2619 } | 2630 } |
| 2620 | 2631 |
| 2621 | 2632 |
| 2622 #ifdef DEBUG | 2633 #ifdef DEBUG |
| 2623 void PagedSpace::ReportCodeStatistics(Isolate* isolate) { | 2634 void PagedSpace::ReportCodeStatistics(Isolate* isolate) { |
| 2624 CommentStatistic* comments_statistics = | 2635 CommentStatistic* comments_statistics = |
| 2625 isolate->paged_space_comments_statistics(); | 2636 isolate->paged_space_comments_statistics(); |
| 2626 ReportCodeKindStatistics(isolate->code_kind_statistics()); | 2637 ReportCodeKindStatistics(isolate->code_kind_statistics()); |
| 2627 PrintF("Code comment statistics (\" [ comment-txt : size/ " | 2638 PrintF("Code comment statistics (\" [ comment-txt : size/ " |
| 2628 "count (average)\"):\n"); | 2639 "count (average)\"):\n"); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3125 object->ShortPrint(); | 3136 object->ShortPrint(); |
| 3126 PrintF("\n"); | 3137 PrintF("\n"); |
| 3127 } | 3138 } |
| 3128 printf(" --------------------------------------\n"); | 3139 printf(" --------------------------------------\n"); |
| 3129 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3140 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3130 } | 3141 } |
| 3131 | 3142 |
| 3132 #endif // DEBUG | 3143 #endif // DEBUG |
| 3133 | 3144 |
| 3134 } } // namespace v8::internal | 3145 } } // namespace v8::internal |
| OLD | NEW |