OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 2767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 int size = map->instance_size(); | 2778 int size = map->instance_size(); |
2779 AllocationSpace space = | 2779 AllocationSpace space = |
2780 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE; | 2780 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_POINTER_SPACE; |
2781 Object* result = Heap::Allocate(map, space); | 2781 Object* result = Heap::Allocate(map, space); |
2782 if (result->IsFailure()) return result; | 2782 if (result->IsFailure()) return result; |
2783 Struct::cast(result)->InitializeBody(size); | 2783 Struct::cast(result)->InitializeBody(size); |
2784 return result; | 2784 return result; |
2785 } | 2785 } |
2786 | 2786 |
2787 | 2787 |
| 2788 bool Heap::IdleNotification() { |
| 2789 static const int kIdlesBeforeCollection = 7; |
| 2790 static int number_idle_notifications = 0; |
| 2791 static int last_gc_count = gc_count_; |
| 2792 |
| 2793 bool finished = false; |
| 2794 |
| 2795 if (last_gc_count == gc_count_) { |
| 2796 number_idle_notifications++; |
| 2797 } else { |
| 2798 number_idle_notifications = 0; |
| 2799 last_gc_count = gc_count_; |
| 2800 } |
| 2801 |
| 2802 if (number_idle_notifications >= kIdlesBeforeCollection) { |
| 2803 // The first time through we collect without forcing compaction. |
| 2804 // The second time through we force compaction and quit. |
| 2805 bool force_compaction = |
| 2806 number_idle_notifications > kIdlesBeforeCollection; |
| 2807 CollectAllGarbage(force_compaction); |
| 2808 last_gc_count = gc_count_; |
| 2809 if (force_compaction) { |
| 2810 number_idle_notifications = 0; |
| 2811 finished = true; |
| 2812 } |
| 2813 } |
| 2814 |
| 2815 // Uncommit unused memory in new space. |
| 2816 Heap::UncommitFromSpace(); |
| 2817 return finished; |
| 2818 } |
| 2819 |
| 2820 |
2788 #ifdef DEBUG | 2821 #ifdef DEBUG |
2789 | 2822 |
2790 void Heap::Print() { | 2823 void Heap::Print() { |
2791 if (!HasBeenSetup()) return; | 2824 if (!HasBeenSetup()) return; |
2792 Top::PrintStack(); | 2825 Top::PrintStack(); |
2793 AllSpaces spaces; | 2826 AllSpaces spaces; |
2794 while (Space* space = spaces.next()) space->Print(); | 2827 while (Space* space = spaces.next()) space->Print(); |
2795 } | 2828 } |
2796 | 2829 |
2797 | 2830 |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3926 #ifdef DEBUG | 3959 #ifdef DEBUG |
3927 bool Heap::GarbageCollectionGreedyCheck() { | 3960 bool Heap::GarbageCollectionGreedyCheck() { |
3928 ASSERT(FLAG_gc_greedy); | 3961 ASSERT(FLAG_gc_greedy); |
3929 if (Bootstrapper::IsActive()) return true; | 3962 if (Bootstrapper::IsActive()) return true; |
3930 if (disallow_allocation_failure()) return true; | 3963 if (disallow_allocation_failure()) return true; |
3931 return CollectGarbage(0, NEW_SPACE); | 3964 return CollectGarbage(0, NEW_SPACE); |
3932 } | 3965 } |
3933 #endif | 3966 #endif |
3934 | 3967 |
3935 } } // namespace v8::internal | 3968 } } // namespace v8::internal |
OLD | NEW |