OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 622 |
623 // Code that should be executed after the garbage collection proper. | 623 // Code that should be executed after the garbage collection proper. |
624 static void PostGarbageCollectionProcessing(); | 624 static void PostGarbageCollectionProcessing(); |
625 | 625 |
626 // Performs garbage collection operation. | 626 // Performs garbage collection operation. |
627 // Returns whether required_space bytes are available after the collection. | 627 // Returns whether required_space bytes are available after the collection. |
628 static bool CollectGarbage(int required_space, AllocationSpace space); | 628 static bool CollectGarbage(int required_space, AllocationSpace space); |
629 | 629 |
630 // Performs a full garbage collection. Force compaction if the | 630 // Performs a full garbage collection. Force compaction if the |
631 // parameter is true. | 631 // parameter is true. |
632 static void CollectAllGarbage(bool force_compaction = false); | 632 static void CollectAllGarbage(bool force_compaction); |
633 | 633 |
634 // Performs a full garbage collection if a context has been disposed | 634 // Performs a full garbage collection if a context has been disposed |
635 // since the last time the check was performed. | 635 // since the last time the check was performed. |
636 static void CollectAllGarbageIfContextDisposed(); | 636 static void CollectAllGarbageIfContextDisposed(); |
637 | 637 |
638 // Notify the heap that a context has been disposed. | 638 // Notify the heap that a context has been disposed. |
639 static void NotifyContextDisposed(); | 639 static void NotifyContextDisposed(); |
640 | 640 |
641 // Utility to invoke the scavenger. This is needed in test code to | 641 // Utility to invoke the scavenger. This is needed in test code to |
642 // ensure correct callback for weak global handles. | 642 // ensure correct callback for weak global handles. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 > old_gen_promotion_limit_; | 832 > old_gen_promotion_limit_; |
833 } | 833 } |
834 | 834 |
835 // True if we have reached the allocation limit in the old generation that | 835 // True if we have reached the allocation limit in the old generation that |
836 // should artificially cause a GC right now. | 836 // should artificially cause a GC right now. |
837 static bool OldGenerationAllocationLimitReached() { | 837 static bool OldGenerationAllocationLimitReached() { |
838 return (PromotedSpaceSize() + PromotedExternalMemorySize()) | 838 return (PromotedSpaceSize() + PromotedExternalMemorySize()) |
839 > old_gen_allocation_limit_; | 839 > old_gen_allocation_limit_; |
840 } | 840 } |
841 | 841 |
| 842 // Can be called when the embedding application is idle. |
| 843 static bool IdleNotification() { |
| 844 static const int kIdlesBeforeCollection = 7; |
| 845 static int number_idle_notifications = 0; |
| 846 static int last_gc_count = gc_count_; |
| 847 |
| 848 bool finished = false; |
| 849 |
| 850 if (last_gc_count == gc_count_) { |
| 851 number_idle_notifications++; |
| 852 } else { |
| 853 number_idle_notifications = 0; |
| 854 last_gc_count = gc_count_; |
| 855 } |
| 856 |
| 857 if (number_idle_notifications >= kIdlesBeforeCollection) { |
| 858 bool force_compaction = true; |
| 859 CollectAllGarbage(force_compaction); |
| 860 number_idle_notifications = 0; |
| 861 finished = true; |
| 862 } |
| 863 |
| 864 // Uncommit unused memory in new space. |
| 865 Heap::UncommitFromSpace(); |
| 866 return finished; |
| 867 } |
| 868 |
842 private: | 869 private: |
843 static int semispace_size_; | 870 static int semispace_size_; |
844 static int initial_semispace_size_; | 871 static int initial_semispace_size_; |
845 static int young_generation_size_; | 872 static int young_generation_size_; |
846 static int old_generation_size_; | 873 static int old_generation_size_; |
847 | 874 |
848 // For keeping track of how much data has survived | 875 // For keeping track of how much data has survived |
849 // scavenge since last new space expansion. | 876 // scavenge since last new space expansion. |
850 static int survived_since_last_expansion_; | 877 static int survived_since_last_expansion_; |
851 | 878 |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 int marked_count_; | 1520 int marked_count_; |
1494 | 1521 |
1495 // The count from the end of the previous full GC. Will be zero if there | 1522 // The count from the end of the previous full GC. Will be zero if there |
1496 // was no previous full GC. | 1523 // was no previous full GC. |
1497 int previous_marked_count_; | 1524 int previous_marked_count_; |
1498 }; | 1525 }; |
1499 | 1526 |
1500 } } // namespace v8::internal | 1527 } } // namespace v8::internal |
1501 | 1528 |
1502 #endif // V8_HEAP_H_ | 1529 #endif // V8_HEAP_H_ |
OLD | NEW |