OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2580 int remaining = | 2580 int remaining = |
2581 static_cast<int>(allocation_info_.limit() - allocation_info_.top()); | 2581 static_cast<int>(allocation_info_.limit() - allocation_info_.top()); |
2582 heap()->CreateFillerObjectAt(allocation_info_.top(), remaining); | 2582 heap()->CreateFillerObjectAt(allocation_info_.top(), remaining); |
2583 | 2583 |
2584 allocation_info_.set_top(NULL); | 2584 allocation_info_.set_top(NULL); |
2585 allocation_info_.set_limit(NULL); | 2585 allocation_info_.set_limit(NULL); |
2586 } | 2586 } |
2587 } | 2587 } |
2588 | 2588 |
2589 | 2589 |
2590 bool PagedSpace::EnsureSweeperProgress(intptr_t size_in_bytes) { | |
2591 MarkCompactCollector* collector = heap()->mark_compact_collector(); | |
2592 if (collector->AreSweeperThreadsActivated()) { | |
2593 if (collector->IsConcurrentSweepingInProgress()) { | |
2594 if (collector->RefillFreeLists(this) < size_in_bytes) { | |
2595 if (!collector->sequential_sweeping()) { | |
2596 collector->WaitUntilSweepingCompleted(); | |
2597 return true; | |
2598 } | |
2599 } | |
2600 return false; | |
2601 } | |
2602 } | |
2603 return true; | |
2604 } | |
2605 | |
2606 | |
2607 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { | 2590 HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
2608 // Allocation in this space has failed. | 2591 // Allocation in this space has failed. |
2609 | 2592 |
2610 // If there are unswept pages advance sweeping a bounded number of times | 2593 // If sweeper threads are active, try to re-fill the free-lists. |
2611 // until we find a size_in_bytes contiguous piece of memory | 2594 MarkCompactCollector* collector = heap()->mark_compact_collector(); |
2612 const int kMaxSweepingTries = 5; | 2595 if (collector->IsConcurrentSweepingInProgress()) { |
2613 bool sweeping_complete = false; | 2596 collector->RefillFreeList(this); |
2614 | |
2615 for (int i = 0; i < kMaxSweepingTries && !sweeping_complete; i++) { | |
2616 sweeping_complete = EnsureSweeperProgress(size_in_bytes); | |
2617 | 2597 |
2618 // Retry the free list allocation. | 2598 // Retry the free list allocation. |
2619 HeapObject* object = free_list_.Allocate(size_in_bytes); | 2599 HeapObject* object = free_list_.Allocate(size_in_bytes); |
2620 if (object != NULL) return object; | 2600 if (object != NULL) return object; |
2621 } | 2601 } |
2622 | 2602 |
2623 // Free list allocation failed and there is no next page. Fail if we have | 2603 // Free list allocation failed and there is no next page. Fail if we have |
2624 // hit the old generation size limit that should cause a garbage | 2604 // hit the old generation size limit that should cause a garbage |
2625 // collection. | 2605 // collection. |
2626 if (!heap()->always_allocate() && | 2606 if (!heap()->always_allocate() && |
2627 heap()->OldGenerationAllocationLimitReached()) { | 2607 heap()->OldGenerationAllocationLimitReached()) { |
2628 return NULL; | 2608 return NULL; |
2629 } | 2609 } |
2630 | 2610 |
2631 // Try to expand the space and allocate in the new next page. | 2611 // Try to expand the space and allocate in the new next page. |
2632 if (Expand()) { | 2612 if (Expand()) { |
2633 ASSERT(CountTotalPages() > 1 || size_in_bytes <= free_list_.available()); | 2613 ASSERT(CountTotalPages() > 1 || size_in_bytes <= free_list_.available()); |
2634 return free_list_.Allocate(size_in_bytes); | 2614 return free_list_.Allocate(size_in_bytes); |
2635 } | 2615 } |
2636 | 2616 |
2637 // Last ditch, sweep all the remaining pages to try to find space. | 2617 // If sweeper threads are active, wait for them at that point. |
2638 if (heap()->mark_compact_collector()->IsConcurrentSweepingInProgress()) { | 2618 if (collector->IsConcurrentSweepingInProgress()) { |
2639 heap()->mark_compact_collector()->WaitUntilSweepingCompleted(); | 2619 collector->WaitUntilSweepingCompleted(); |
2640 | 2620 |
2641 // Retry the free list allocation. | 2621 // After waiting for the sweeper threads, there may be new free-list |
| 2622 // entries. |
2642 HeapObject* object = free_list_.Allocate(size_in_bytes); | 2623 HeapObject* object = free_list_.Allocate(size_in_bytes); |
2643 if (object != NULL) return object; | 2624 if (object != NULL) return object; |
2644 } | 2625 } |
2645 | 2626 |
2646 // Finally, fail. | 2627 // Finally, fail. |
2647 return NULL; | 2628 return NULL; |
2648 } | 2629 } |
2649 | 2630 |
2650 | 2631 |
2651 #ifdef DEBUG | 2632 #ifdef DEBUG |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3154 object->ShortPrint(); | 3135 object->ShortPrint(); |
3155 PrintF("\n"); | 3136 PrintF("\n"); |
3156 } | 3137 } |
3157 printf(" --------------------------------------\n"); | 3138 printf(" --------------------------------------\n"); |
3158 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3139 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3159 } | 3140 } |
3160 | 3141 |
3161 #endif // DEBUG | 3142 #endif // DEBUG |
3162 | 3143 |
3163 } } // namespace v8::internal | 3144 } } // namespace v8::internal |
OLD | NEW |