| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 allocations_count_(0), | 89 allocations_count_(0), |
| 90 raw_allocations_hash_(0), | 90 raw_allocations_hash_(0), |
| 91 dump_allocations_hash_countdown_(FLAG_dump_allocations_digest_at_alloc), | 91 dump_allocations_hash_countdown_(FLAG_dump_allocations_digest_at_alloc), |
| 92 ms_count_(0), | 92 ms_count_(0), |
| 93 gc_count_(0), | 93 gc_count_(0), |
| 94 remembered_unmapped_pages_index_(0), | 94 remembered_unmapped_pages_index_(0), |
| 95 unflattened_strings_length_(0), | 95 unflattened_strings_length_(0), |
| 96 #ifdef DEBUG | 96 #ifdef DEBUG |
| 97 allocation_timeout_(0), | 97 allocation_timeout_(0), |
| 98 #endif // DEBUG | 98 #endif // DEBUG |
| 99 flush_eagerly_(false), |
| 99 old_generation_allocation_limit_(kMinimumOldGenerationAllocationLimit), | 100 old_generation_allocation_limit_(kMinimumOldGenerationAllocationLimit), |
| 100 old_gen_exhausted_(false), | 101 old_gen_exhausted_(false), |
| 101 inline_allocation_disabled_(false), | 102 inline_allocation_disabled_(false), |
| 102 store_buffer_rebuilder_(store_buffer()), | 103 store_buffer_rebuilder_(store_buffer()), |
| 103 hidden_string_(NULL), | 104 hidden_string_(NULL), |
| 104 gc_safe_size_of_old_object_(NULL), | 105 gc_safe_size_of_old_object_(NULL), |
| 105 total_regexp_code_generated_(0), | 106 total_regexp_code_generated_(0), |
| 106 tracer_(this), | 107 tracer_(this), |
| 107 high_survival_rate_period_length_(0), | 108 high_survival_rate_period_length_(0), |
| 108 promoted_objects_size_(0), | 109 promoted_objects_size_(0), |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 const v8::GCCallbackFlags gc_callback_flags) { | 730 const v8::GCCallbackFlags gc_callback_flags) { |
| 730 // Since we are ignoring the return value, the exact choice of space does | 731 // Since we are ignoring the return value, the exact choice of space does |
| 731 // not matter, so long as we do not specify NEW_SPACE, which would not | 732 // not matter, so long as we do not specify NEW_SPACE, which would not |
| 732 // cause a full GC. | 733 // cause a full GC. |
| 733 mark_compact_collector_.SetFlags(flags); | 734 mark_compact_collector_.SetFlags(flags); |
| 734 CollectGarbage(OLD_POINTER_SPACE, gc_reason, gc_callback_flags); | 735 CollectGarbage(OLD_POINTER_SPACE, gc_reason, gc_callback_flags); |
| 735 mark_compact_collector_.SetFlags(kNoGCFlags); | 736 mark_compact_collector_.SetFlags(kNoGCFlags); |
| 736 } | 737 } |
| 737 | 738 |
| 738 | 739 |
| 739 void Heap::CollectAllAvailableGarbage(const char* gc_reason) { | 740 void Heap::CollectAllAvailableGarbage(const char* gc_reason, int max_attempts) { |
| 740 // Since we are ignoring the return value, the exact choice of space does | 741 // Since we are ignoring the return value, the exact choice of space does |
| 741 // not matter, so long as we do not specify NEW_SPACE, which would not | 742 // not matter, so long as we do not specify NEW_SPACE, which would not |
| 742 // cause a full GC. | 743 // cause a full GC. |
| 743 // Major GC would invoke weak handle callbacks on weakly reachable | 744 // Major GC would invoke weak handle callbacks on weakly reachable |
| 744 // handles, but won't collect weakly reachable objects until next | 745 // handles, but won't collect weakly reachable objects until next |
| 745 // major GC. Therefore if we collect aggressively and weak handle callback | 746 // major GC. Therefore if we collect aggressively and weak handle callback |
| 746 // has been invoked, we rerun major GC to release objects which become | 747 // has been invoked, we rerun major GC to release objects which become |
| 747 // garbage. | 748 // garbage. |
| 748 // Note: as weak callbacks can execute arbitrary code, we cannot | 749 // Note: as weak callbacks can execute arbitrary code, we cannot |
| 749 // hope that eventually there will be no weak callbacks invocations. | 750 // hope that eventually there will be no weak callbacks invocations. |
| 750 // Therefore stop recollecting after several attempts. | 751 // Therefore stop recollecting after several attempts. |
| 751 if (isolate()->concurrent_recompilation_enabled()) { | 752 if (isolate()->concurrent_recompilation_enabled()) { |
| 752 // The optimizing compiler may be unnecessarily holding on to memory. | 753 // The optimizing compiler may be unnecessarily holding on to memory. |
| 753 DisallowHeapAllocation no_recursive_gc; | 754 DisallowHeapAllocation no_recursive_gc; |
| 754 isolate()->optimizing_compiler_thread()->Flush(); | 755 isolate()->optimizing_compiler_thread()->Flush(); |
| 755 } | 756 } |
| 756 mark_compact_collector()->SetFlags(kMakeHeapIterableMask | | 757 mark_compact_collector()->SetFlags(kMakeHeapIterableMask | |
| 757 kReduceMemoryFootprintMask); | 758 kReduceMemoryFootprintMask); |
| 758 isolate_->compilation_cache()->Clear(); | 759 isolate_->compilation_cache()->Clear(); |
| 759 const int kMaxNumberOfAttempts = 7; | |
| 760 const int kMinNumberOfAttempts = 2; | 760 const int kMinNumberOfAttempts = 2; |
| 761 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { | 761 FlushEagerly flush_eagerly_scope(this); |
| 762 for (int attempt = 0; attempt < max_attempts; attempt++) { |
| 762 if (!CollectGarbage(MARK_COMPACTOR, gc_reason, NULL) && | 763 if (!CollectGarbage(MARK_COMPACTOR, gc_reason, NULL) && |
| 763 attempt + 1 >= kMinNumberOfAttempts) { | 764 attempt + 1 >= kMinNumberOfAttempts) { |
| 764 break; | 765 break; |
| 765 } | 766 } |
| 766 } | 767 } |
| 767 mark_compact_collector()->SetFlags(kNoGCFlags); | 768 mark_compact_collector()->SetFlags(kNoGCFlags); |
| 768 new_space_.Shrink(); | 769 new_space_.Shrink(); |
| 769 UncommitFromSpace(); | 770 UncommitFromSpace(); |
| 770 incremental_marking()->UncommitMarkingDeque(); | 771 incremental_marking()->UncommitMarkingDeque(); |
| 771 } | 772 } |
| (...skipping 5467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6239 static_cast<int>(object_sizes_last_time_[index])); | 6240 static_cast<int>(object_sizes_last_time_[index])); |
| 6240 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6241 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 6241 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6242 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 6242 | 6243 |
| 6243 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6244 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 6244 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6245 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 6245 ClearObjectStats(); | 6246 ClearObjectStats(); |
| 6246 } | 6247 } |
| 6247 } | 6248 } |
| 6248 } // namespace v8::internal | 6249 } // namespace v8::internal |
| OLD | NEW |