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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 : amount_of_external_allocated_memory_(0), | 59 : amount_of_external_allocated_memory_(0), |
60 amount_of_external_allocated_memory_at_last_global_gc_(0), | 60 amount_of_external_allocated_memory_at_last_global_gc_(0), |
61 isolate_(NULL), | 61 isolate_(NULL), |
62 code_range_size_(0), | 62 code_range_size_(0), |
63 // semispace_size_ should be a power of 2 and old_generation_size_ should | 63 // semispace_size_ should be a power of 2 and old_generation_size_ should |
64 // be a multiple of Page::kPageSize. | 64 // be a multiple of Page::kPageSize. |
65 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), | 65 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), |
66 max_semi_space_size_(8 * (kPointerSize / 4) * MB), | 66 max_semi_space_size_(8 * (kPointerSize / 4) * MB), |
67 initial_semispace_size_(Page::kPageSize), | 67 initial_semispace_size_(Page::kPageSize), |
68 target_semispace_size_(Page::kPageSize), | 68 target_semispace_size_(Page::kPageSize), |
69 max_old_generation_size_(700ul * (kPointerSize / 4) * MB), | 69 max_old_generation_size_(kDefaultMaxOldGenSize), |
70 initial_old_generation_size_(max_old_generation_size_ / | 70 initial_old_generation_size_(max_old_generation_size_ / |
71 kInitalOldGenerationLimitFactor), | 71 kInitalOldGenerationLimitFactor), |
72 old_generation_size_configured_(false), | 72 old_generation_size_configured_(false), |
73 max_executable_size_(256ul * (kPointerSize / 4) * MB), | 73 max_executable_size_(256ul * (kPointerSize / 4) * MB), |
74 // Variables set based on semispace_size_ and old_generation_size_ in | 74 // Variables set based on semispace_size_ and old_generation_size_ in |
75 // ConfigureHeap. | 75 // ConfigureHeap. |
76 // Will be 4 * reserved_semispace_size_ to ensure that young | 76 // Will be 4 * reserved_semispace_size_ to ensure that young |
77 // generation can be aligned to its size. | 77 // generation can be aligned to its size. |
78 maximum_committed_(0), | 78 maximum_committed_(0), |
79 survived_since_last_expansion_(0), | 79 survived_since_last_expansion_(0), |
(...skipping 16 matching lines...) Expand all Loading... |
96 raw_allocations_hash_(0), | 96 raw_allocations_hash_(0), |
97 dump_allocations_hash_countdown_(FLAG_dump_allocations_digest_at_alloc), | 97 dump_allocations_hash_countdown_(FLAG_dump_allocations_digest_at_alloc), |
98 ms_count_(0), | 98 ms_count_(0), |
99 gc_count_(0), | 99 gc_count_(0), |
100 remembered_unmapped_pages_index_(0), | 100 remembered_unmapped_pages_index_(0), |
101 unflattened_strings_length_(0), | 101 unflattened_strings_length_(0), |
102 #ifdef DEBUG | 102 #ifdef DEBUG |
103 allocation_timeout_(0), | 103 allocation_timeout_(0), |
104 #endif // DEBUG | 104 #endif // DEBUG |
105 old_generation_allocation_limit_(initial_old_generation_size_), | 105 old_generation_allocation_limit_(initial_old_generation_size_), |
| 106 old_generation_committed_memory_limit_(kDefaultMaxOldGenSize >> 1), |
106 old_gen_exhausted_(false), | 107 old_gen_exhausted_(false), |
107 inline_allocation_disabled_(false), | 108 inline_allocation_disabled_(false), |
108 store_buffer_rebuilder_(store_buffer()), | 109 store_buffer_rebuilder_(store_buffer()), |
109 hidden_string_(NULL), | 110 hidden_string_(NULL), |
110 gc_safe_size_of_old_object_(NULL), | 111 gc_safe_size_of_old_object_(NULL), |
111 total_regexp_code_generated_(0), | 112 total_regexp_code_generated_(0), |
112 tracer_(this), | 113 tracer_(this), |
113 high_survival_rate_period_length_(0), | 114 high_survival_rate_period_length_(0), |
114 promoted_objects_size_(0), | 115 promoted_objects_size_(0), |
115 promotion_ratio_(0), | 116 promotion_ratio_(0), |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 | 855 |
855 EnsureFillerObjectAtTop(); | 856 EnsureFillerObjectAtTop(); |
856 | 857 |
857 if (collector == SCAVENGER && !incremental_marking()->IsStopped()) { | 858 if (collector == SCAVENGER && !incremental_marking()->IsStopped()) { |
858 if (FLAG_trace_incremental_marking) { | 859 if (FLAG_trace_incremental_marking) { |
859 PrintF("[IncrementalMarking] Scavenge during marking.\n"); | 860 PrintF("[IncrementalMarking] Scavenge during marking.\n"); |
860 } | 861 } |
861 } | 862 } |
862 | 863 |
863 if (collector == MARK_COMPACTOR && | 864 if (collector == MARK_COMPACTOR && |
864 !mark_compact_collector()->abort_incremental_marking() && | 865 !mark_compact_collector()->incremental_marking_abort_requested() && |
865 !incremental_marking()->IsStopped() && | 866 !incremental_marking()->IsStopped() && |
866 !incremental_marking()->should_hurry() && | 867 !incremental_marking()->should_hurry() && |
867 FLAG_incremental_marking_steps) { | 868 FLAG_incremental_marking_steps) { |
868 // Make progress in incremental marking. | 869 // Make progress in incremental marking. |
869 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; | 870 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; |
870 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, | 871 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, |
871 IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 872 IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
872 if (!incremental_marking()->IsComplete() && | 873 if (!incremental_marking()->IsComplete() && |
873 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { | 874 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { |
874 if (FLAG_trace_incremental_marking) { | 875 if (FLAG_trace_incremental_marking) { |
(...skipping 22 matching lines...) Expand all Loading... |
897 | 898 |
898 GarbageCollectionEpilogue(); | 899 GarbageCollectionEpilogue(); |
899 if (collector == MARK_COMPACTOR && FLAG_track_detached_contexts) { | 900 if (collector == MARK_COMPACTOR && FLAG_track_detached_contexts) { |
900 isolate()->CheckDetachedContextsAfterGC(); | 901 isolate()->CheckDetachedContextsAfterGC(); |
901 } | 902 } |
902 tracer()->Stop(collector); | 903 tracer()->Stop(collector); |
903 } | 904 } |
904 | 905 |
905 // Start incremental marking for the next cycle. The heap snapshot | 906 // Start incremental marking for the next cycle. The heap snapshot |
906 // generator needs incremental marking to stay off after it aborted. | 907 // generator needs incremental marking to stay off after it aborted. |
907 if (!mark_compact_collector()->abort_incremental_marking() && | 908 if (!mark_compact_collector()->incremental_marking_abort_requested() && |
908 WorthActivatingIncrementalMarking()) { | 909 incremental_marking()->IsStopped() && |
| 910 incremental_marking()->ShouldActivate()) { |
909 incremental_marking()->Start(); | 911 incremental_marking()->Start(); |
910 } | 912 } |
911 | 913 |
912 return next_gc_likely_to_collect_more; | 914 return next_gc_likely_to_collect_more; |
913 } | 915 } |
914 | 916 |
915 | 917 |
916 int Heap::NotifyContextDisposed(bool dependant_context) { | 918 int Heap::NotifyContextDisposed(bool dependant_context) { |
917 if (!dependant_context) { | 919 if (!dependant_context) { |
918 tracer()->ResetSurvivalEvents(); | 920 tracer()->ResetSurvivalEvents(); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 incremental_marking()->NotifyOfHighPromotionRate(); | 1157 incremental_marking()->NotifyOfHighPromotionRate(); |
1156 } | 1158 } |
1157 | 1159 |
1158 if (collector == MARK_COMPACTOR) { | 1160 if (collector == MARK_COMPACTOR) { |
1159 // Perform mark-sweep with optional compaction. | 1161 // Perform mark-sweep with optional compaction. |
1160 MarkCompact(); | 1162 MarkCompact(); |
1161 sweep_generation_++; | 1163 sweep_generation_++; |
1162 // Temporarily set the limit for case when PostGarbageCollectionProcessing | 1164 // Temporarily set the limit for case when PostGarbageCollectionProcessing |
1163 // allocates and triggers GC. The real limit is set at after | 1165 // allocates and triggers GC. The real limit is set at after |
1164 // PostGarbageCollectionProcessing. | 1166 // PostGarbageCollectionProcessing. |
1165 old_generation_allocation_limit_ = | 1167 SetOldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), 0, false); |
1166 OldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), 0); | |
1167 old_gen_exhausted_ = false; | 1168 old_gen_exhausted_ = false; |
1168 old_generation_size_configured_ = true; | 1169 old_generation_size_configured_ = true; |
1169 } else { | 1170 } else { |
1170 Scavenge(); | 1171 Scavenge(); |
1171 } | 1172 } |
1172 | 1173 |
1173 UpdateSurvivalStatistics(start_new_space_size); | 1174 UpdateSurvivalStatistics(start_new_space_size); |
1174 ConfigureInitialOldGenerationSize(); | 1175 ConfigureInitialOldGenerationSize(); |
1175 | 1176 |
1176 isolate_->counters()->objs_since_last_young()->Set(0); | 1177 isolate_->counters()->objs_since_last_young()->Set(0); |
(...skipping 13 matching lines...) Expand all Loading... |
1190 | 1191 |
1191 isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); | 1192 isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); |
1192 | 1193 |
1193 // Update relocatables. | 1194 // Update relocatables. |
1194 Relocatable::PostGarbageCollectionProcessing(isolate_); | 1195 Relocatable::PostGarbageCollectionProcessing(isolate_); |
1195 | 1196 |
1196 if (collector == MARK_COMPACTOR) { | 1197 if (collector == MARK_COMPACTOR) { |
1197 // Register the amount of external allocated memory. | 1198 // Register the amount of external allocated memory. |
1198 amount_of_external_allocated_memory_at_last_global_gc_ = | 1199 amount_of_external_allocated_memory_at_last_global_gc_ = |
1199 amount_of_external_allocated_memory_; | 1200 amount_of_external_allocated_memory_; |
1200 old_generation_allocation_limit_ = OldGenerationAllocationLimit( | 1201 SetOldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), |
1201 PromotedSpaceSizeOfObjects(), freed_global_handles); | 1202 freed_global_handles, true); |
1202 // We finished a marking cycle. We can uncommit the marking deque until | 1203 // We finished a marking cycle. We can uncommit the marking deque until |
1203 // we start marking again. | 1204 // we start marking again. |
1204 mark_compact_collector_.UncommitMarkingDeque(); | 1205 mark_compact_collector_.UncommitMarkingDeque(); |
1205 } | 1206 } |
1206 | 1207 |
1207 { | 1208 { |
1208 GCCallbacksScope scope(this); | 1209 GCCallbacksScope scope(this); |
1209 if (scope.CheckReenter()) { | 1210 if (scope.CheckReenter()) { |
1210 AllowHeapAllocation allow_allocation; | 1211 AllowHeapAllocation allow_allocation; |
1211 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); | 1212 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); |
(...skipping 3389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4601 gc_idle_time_handler_.ShouldDoFinalIncrementalMarkCompact( | 4602 gc_idle_time_handler_.ShouldDoFinalIncrementalMarkCompact( |
4602 static_cast<size_t>(idle_time_in_ms), size_of_objects, | 4603 static_cast<size_t>(idle_time_in_ms), size_of_objects, |
4603 final_incremental_mark_compact_speed_in_bytes_per_ms))) { | 4604 final_incremental_mark_compact_speed_in_bytes_per_ms))) { |
4604 CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); | 4605 CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); |
4605 return true; | 4606 return true; |
4606 } | 4607 } |
4607 return false; | 4608 return false; |
4608 } | 4609 } |
4609 | 4610 |
4610 | 4611 |
4611 bool Heap::WorthActivatingIncrementalMarking() { | |
4612 return incremental_marking()->IsStopped() && | |
4613 incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull(); | |
4614 } | |
4615 | |
4616 | |
4617 static double MonotonicallyIncreasingTimeInMs() { | 4612 static double MonotonicallyIncreasingTimeInMs() { |
4618 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * | 4613 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * |
4619 static_cast<double>(base::Time::kMillisecondsPerSecond); | 4614 static_cast<double>(base::Time::kMillisecondsPerSecond); |
4620 } | 4615 } |
4621 | 4616 |
4622 | 4617 |
4623 bool Heap::IdleNotification(int idle_time_in_ms) { | 4618 bool Heap::IdleNotification(int idle_time_in_ms) { |
4624 return IdleNotification( | 4619 return IdleNotification( |
4625 V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + | 4620 V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + |
4626 (static_cast<double>(idle_time_in_ms) / | 4621 (static_cast<double>(idle_time_in_ms) / |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5251 | 5246 |
5252 int64_t Heap::PromotedExternalMemorySize() { | 5247 int64_t Heap::PromotedExternalMemorySize() { |
5253 if (amount_of_external_allocated_memory_ <= | 5248 if (amount_of_external_allocated_memory_ <= |
5254 amount_of_external_allocated_memory_at_last_global_gc_) | 5249 amount_of_external_allocated_memory_at_last_global_gc_) |
5255 return 0; | 5250 return 0; |
5256 return amount_of_external_allocated_memory_ - | 5251 return amount_of_external_allocated_memory_ - |
5257 amount_of_external_allocated_memory_at_last_global_gc_; | 5252 amount_of_external_allocated_memory_at_last_global_gc_; |
5258 } | 5253 } |
5259 | 5254 |
5260 | 5255 |
5261 intptr_t Heap::OldGenerationAllocationLimit(intptr_t old_gen_size, | 5256 void Heap::SetOldGenerationAllocationLimit(intptr_t old_gen_size, |
5262 int freed_global_handles) { | 5257 int freed_global_handles, |
| 5258 bool weak_callbacks_completed) { |
5263 const int kMaxHandles = 1000; | 5259 const int kMaxHandles = 1000; |
5264 const int kMinHandles = 100; | 5260 const int kMinHandles = 100; |
5265 double min_factor = 1.1; | 5261 double min_factor = 1.1; |
5266 double max_factor = 4; | 5262 double max_factor = 4; |
5267 // We set the old generation growing factor to 2 to grow the heap slower on | 5263 // We set the old generation growing factor to 2 to grow the heap slower on |
5268 // memory-constrained devices. | 5264 // memory-constrained devices. |
5269 if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) { | 5265 if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) { |
5270 max_factor = 2; | 5266 max_factor = 2; |
5271 } | 5267 } |
5272 // If there are many freed global handles, then the next full GC will | 5268 // If there are many freed global handles, then the next full GC will |
(...skipping 13 matching lines...) Expand all Loading... |
5286 (kMaxHandles - kMinHandles); | 5282 (kMaxHandles - kMinHandles); |
5287 } | 5283 } |
5288 | 5284 |
5289 if (FLAG_stress_compaction || | 5285 if (FLAG_stress_compaction || |
5290 mark_compact_collector()->reduce_memory_footprint_) { | 5286 mark_compact_collector()->reduce_memory_footprint_) { |
5291 factor = min_factor; | 5287 factor = min_factor; |
5292 } | 5288 } |
5293 | 5289 |
5294 intptr_t limit = static_cast<intptr_t>(old_gen_size * factor); | 5290 intptr_t limit = static_cast<intptr_t>(old_gen_size * factor); |
5295 limit = Max(limit, kMinimumOldGenerationAllocationLimit); | 5291 limit = Max(limit, kMinimumOldGenerationAllocationLimit); |
5296 limit += new_space_.Capacity(); | 5292 |
5297 intptr_t halfway_to_the_max = (old_gen_size + max_old_generation_size_) / 2; | 5293 old_generation_allocation_limit_ = limit + new_space_.Capacity(); |
5298 return Min(limit, halfway_to_the_max); | 5294 |
| 5295 // The committed memory limit is halfway from the current committed memory |
| 5296 // level to the max size. |
| 5297 old_generation_committed_memory_limit_ = |
| 5298 CommittedOldGenerationMemory() / 2 + max_old_generation_size_ / 2; |
| 5299 |
| 5300 if (weak_callbacks_completed && FLAG_trace_gc) { |
| 5301 PrintPID("%8.0f ms: ", isolate()->time_millis_since_init()); |
| 5302 PrintF("Next GC at %.1f (%.1f) -> %.1f (%.1f)\n", old_gen_size * 1.0 / MB, |
| 5303 CommittedOldGenerationMemory() * 1.0 / MB, limit * 1.0 / MB, |
| 5304 old_generation_committed_memory_limit_ * 1.0 / MB); |
| 5305 } |
5299 } | 5306 } |
5300 | 5307 |
5301 | 5308 |
5302 void Heap::EnableInlineAllocation() { | 5309 void Heap::EnableInlineAllocation() { |
5303 if (!inline_allocation_disabled_) return; | 5310 if (!inline_allocation_disabled_) return; |
5304 inline_allocation_disabled_ = false; | 5311 inline_allocation_disabled_ = false; |
5305 | 5312 |
5306 // Update inline allocation limit for new space. | 5313 // Update inline allocation limit for new space. |
5307 new_space()->UpdateInlineAllocationLimit(0); | 5314 new_space()->UpdateInlineAllocationLimit(0); |
5308 } | 5315 } |
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6435 static_cast<int>(object_sizes_last_time_[index])); | 6442 static_cast<int>(object_sizes_last_time_[index])); |
6436 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6443 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6437 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6444 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6438 | 6445 |
6439 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6446 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6440 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6447 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6441 ClearObjectStats(); | 6448 ClearObjectStats(); |
6442 } | 6449 } |
6443 } | 6450 } |
6444 } // namespace v8::internal | 6451 } // namespace v8::internal |
OLD | NEW |