| 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 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 | 854 |
| 854 EnsureFillerObjectAtTop(); | 855 EnsureFillerObjectAtTop(); |
| 855 | 856 |
| 856 if (collector == SCAVENGER && !incremental_marking()->IsStopped()) { | 857 if (collector == SCAVENGER && !incremental_marking()->IsStopped()) { |
| 857 if (FLAG_trace_incremental_marking) { | 858 if (FLAG_trace_incremental_marking) { |
| 858 PrintF("[IncrementalMarking] Scavenge during marking.\n"); | 859 PrintF("[IncrementalMarking] Scavenge during marking.\n"); |
| 859 } | 860 } |
| 860 } | 861 } |
| 861 | 862 |
| 862 if (collector == MARK_COMPACTOR && | 863 if (collector == MARK_COMPACTOR && |
| 863 !mark_compact_collector()->abort_incremental_marking() && | 864 !mark_compact_collector()->incremental_marking_abort_requested() && |
| 864 !incremental_marking()->IsStopped() && | 865 !incremental_marking()->IsStopped() && |
| 865 !incremental_marking()->should_hurry() && | 866 !incremental_marking()->should_hurry() && |
| 866 FLAG_incremental_marking_steps) { | 867 FLAG_incremental_marking_steps) { |
| 867 // Make progress in incremental marking. | 868 // Make progress in incremental marking. |
| 868 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; | 869 const intptr_t kStepSizeWhenDelayedByScavenge = 1 * MB; |
| 869 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, | 870 incremental_marking()->Step(kStepSizeWhenDelayedByScavenge, |
| 870 IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 871 IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
| 871 if (!incremental_marking()->IsComplete() && | 872 if (!incremental_marking()->IsComplete() && |
| 872 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { | 873 !mark_compact_collector_.marking_deque_.IsEmpty() && !FLAG_gc_global) { |
| 873 if (FLAG_trace_incremental_marking) { | 874 if (FLAG_trace_incremental_marking) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 896 | 897 |
| 897 GarbageCollectionEpilogue(); | 898 GarbageCollectionEpilogue(); |
| 898 if (collector == MARK_COMPACTOR && FLAG_track_detached_contexts) { | 899 if (collector == MARK_COMPACTOR && FLAG_track_detached_contexts) { |
| 899 isolate()->CheckDetachedContextsAfterGC(); | 900 isolate()->CheckDetachedContextsAfterGC(); |
| 900 } | 901 } |
| 901 tracer()->Stop(collector); | 902 tracer()->Stop(collector); |
| 902 } | 903 } |
| 903 | 904 |
| 904 // Start incremental marking for the next cycle. The heap snapshot | 905 // Start incremental marking for the next cycle. The heap snapshot |
| 905 // generator needs incremental marking to stay off after it aborted. | 906 // generator needs incremental marking to stay off after it aborted. |
| 906 if (!mark_compact_collector()->abort_incremental_marking() && | 907 if (!mark_compact_collector()->incremental_marking_abort_requested() && |
| 907 WorthActivatingIncrementalMarking()) { | 908 incremental_marking()->IsStopped() && |
| 909 incremental_marking()->ShouldActivate()) { |
| 908 incremental_marking()->Start(); | 910 incremental_marking()->Start(); |
| 909 } | 911 } |
| 910 | 912 |
| 911 return next_gc_likely_to_collect_more; | 913 return next_gc_likely_to_collect_more; |
| 912 } | 914 } |
| 913 | 915 |
| 914 | 916 |
| 915 int Heap::NotifyContextDisposed(bool dependant_context) { | 917 int Heap::NotifyContextDisposed(bool dependant_context) { |
| 916 if (!dependant_context) { | 918 if (!dependant_context) { |
| 917 tracer()->ResetSurvivalEvents(); | 919 tracer()->ResetSurvivalEvents(); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 incremental_marking()->NotifyOfHighPromotionRate(); | 1156 incremental_marking()->NotifyOfHighPromotionRate(); |
| 1155 } | 1157 } |
| 1156 | 1158 |
| 1157 if (collector == MARK_COMPACTOR) { | 1159 if (collector == MARK_COMPACTOR) { |
| 1158 // Perform mark-sweep with optional compaction. | 1160 // Perform mark-sweep with optional compaction. |
| 1159 MarkCompact(); | 1161 MarkCompact(); |
| 1160 sweep_generation_++; | 1162 sweep_generation_++; |
| 1161 // Temporarily set the limit for case when PostGarbageCollectionProcessing | 1163 // Temporarily set the limit for case when PostGarbageCollectionProcessing |
| 1162 // allocates and triggers GC. The real limit is set at after | 1164 // allocates and triggers GC. The real limit is set at after |
| 1163 // PostGarbageCollectionProcessing. | 1165 // PostGarbageCollectionProcessing. |
| 1164 old_generation_allocation_limit_ = | 1166 SetOldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), 0, false); |
| 1165 OldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), 0); | |
| 1166 old_gen_exhausted_ = false; | 1167 old_gen_exhausted_ = false; |
| 1167 old_generation_size_configured_ = true; | 1168 old_generation_size_configured_ = true; |
| 1168 } else { | 1169 } else { |
| 1169 Scavenge(); | 1170 Scavenge(); |
| 1170 } | 1171 } |
| 1171 | 1172 |
| 1172 UpdateSurvivalStatistics(start_new_space_size); | 1173 UpdateSurvivalStatistics(start_new_space_size); |
| 1173 ConfigureInitialOldGenerationSize(); | 1174 ConfigureInitialOldGenerationSize(); |
| 1174 | 1175 |
| 1175 isolate_->counters()->objs_since_last_young()->Set(0); | 1176 isolate_->counters()->objs_since_last_young()->Set(0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1189 | 1190 |
| 1190 isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); | 1191 isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); |
| 1191 | 1192 |
| 1192 // Update relocatables. | 1193 // Update relocatables. |
| 1193 Relocatable::PostGarbageCollectionProcessing(isolate_); | 1194 Relocatable::PostGarbageCollectionProcessing(isolate_); |
| 1194 | 1195 |
| 1195 if (collector == MARK_COMPACTOR) { | 1196 if (collector == MARK_COMPACTOR) { |
| 1196 // Register the amount of external allocated memory. | 1197 // Register the amount of external allocated memory. |
| 1197 amount_of_external_allocated_memory_at_last_global_gc_ = | 1198 amount_of_external_allocated_memory_at_last_global_gc_ = |
| 1198 amount_of_external_allocated_memory_; | 1199 amount_of_external_allocated_memory_; |
| 1199 old_generation_allocation_limit_ = OldGenerationAllocationLimit( | 1200 SetOldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), |
| 1200 PromotedSpaceSizeOfObjects(), freed_global_handles); | 1201 freed_global_handles, true); |
| 1201 // We finished a marking cycle. We can uncommit the marking deque until | 1202 // We finished a marking cycle. We can uncommit the marking deque until |
| 1202 // we start marking again. | 1203 // we start marking again. |
| 1203 mark_compact_collector_.UncommitMarkingDeque(); | 1204 mark_compact_collector_.UncommitMarkingDeque(); |
| 1204 } | 1205 } |
| 1205 | 1206 |
| 1206 { | 1207 { |
| 1207 GCCallbacksScope scope(this); | 1208 GCCallbacksScope scope(this); |
| 1208 if (scope.CheckReenter()) { | 1209 if (scope.CheckReenter()) { |
| 1209 AllowHeapAllocation allow_allocation; | 1210 AllowHeapAllocation allow_allocation; |
| 1210 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); | 1211 GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL); |
| (...skipping 3356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4567 gc_idle_time_handler_.ShouldDoFinalIncrementalMarkCompact( | 4568 gc_idle_time_handler_.ShouldDoFinalIncrementalMarkCompact( |
| 4568 static_cast<size_t>(idle_time_in_ms), size_of_objects, | 4569 static_cast<size_t>(idle_time_in_ms), size_of_objects, |
| 4569 final_incremental_mark_compact_speed_in_bytes_per_ms))) { | 4570 final_incremental_mark_compact_speed_in_bytes_per_ms))) { |
| 4570 CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); | 4571 CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); |
| 4571 return true; | 4572 return true; |
| 4572 } | 4573 } |
| 4573 return false; | 4574 return false; |
| 4574 } | 4575 } |
| 4575 | 4576 |
| 4576 | 4577 |
| 4577 bool Heap::WorthActivatingIncrementalMarking() { | |
| 4578 return incremental_marking()->IsStopped() && | |
| 4579 incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull(); | |
| 4580 } | |
| 4581 | |
| 4582 | |
| 4583 static double MonotonicallyIncreasingTimeInMs() { | 4578 static double MonotonicallyIncreasingTimeInMs() { |
| 4584 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * | 4579 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * |
| 4585 static_cast<double>(base::Time::kMillisecondsPerSecond); | 4580 static_cast<double>(base::Time::kMillisecondsPerSecond); |
| 4586 } | 4581 } |
| 4587 | 4582 |
| 4588 | 4583 |
| 4589 bool Heap::IdleNotification(int idle_time_in_ms) { | 4584 bool Heap::IdleNotification(int idle_time_in_ms) { |
| 4590 return IdleNotification( | 4585 return IdleNotification( |
| 4591 V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + | 4586 V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + |
| 4592 (static_cast<double>(idle_time_in_ms) / | 4587 (static_cast<double>(idle_time_in_ms) / |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5224 | 5219 |
| 5225 int64_t Heap::PromotedExternalMemorySize() { | 5220 int64_t Heap::PromotedExternalMemorySize() { |
| 5226 if (amount_of_external_allocated_memory_ <= | 5221 if (amount_of_external_allocated_memory_ <= |
| 5227 amount_of_external_allocated_memory_at_last_global_gc_) | 5222 amount_of_external_allocated_memory_at_last_global_gc_) |
| 5228 return 0; | 5223 return 0; |
| 5229 return amount_of_external_allocated_memory_ - | 5224 return amount_of_external_allocated_memory_ - |
| 5230 amount_of_external_allocated_memory_at_last_global_gc_; | 5225 amount_of_external_allocated_memory_at_last_global_gc_; |
| 5231 } | 5226 } |
| 5232 | 5227 |
| 5233 | 5228 |
| 5234 intptr_t Heap::OldGenerationAllocationLimit(intptr_t old_gen_size, | 5229 void Heap::SetOldGenerationAllocationLimit(intptr_t old_gen_size, |
| 5235 int freed_global_handles) { | 5230 int freed_global_handles, |
| 5231 bool weak_callbacks_completed) { |
| 5236 const int kMaxHandles = 1000; | 5232 const int kMaxHandles = 1000; |
| 5237 const int kMinHandles = 100; | 5233 const int kMinHandles = 100; |
| 5238 double min_factor = 1.1; | 5234 double min_factor = 1.1; |
| 5239 double max_factor = 4; | 5235 double max_factor = 4; |
| 5240 // We set the old generation growing factor to 2 to grow the heap slower on | 5236 // We set the old generation growing factor to 2 to grow the heap slower on |
| 5241 // memory-constrained devices. | 5237 // memory-constrained devices. |
| 5242 if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) { | 5238 if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) { |
| 5243 max_factor = 2; | 5239 max_factor = 2; |
| 5244 } | 5240 } |
| 5245 // If there are many freed global handles, then the next full GC will | 5241 // If there are many freed global handles, then the next full GC will |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5259 (kMaxHandles - kMinHandles); | 5255 (kMaxHandles - kMinHandles); |
| 5260 } | 5256 } |
| 5261 | 5257 |
| 5262 if (FLAG_stress_compaction || | 5258 if (FLAG_stress_compaction || |
| 5263 mark_compact_collector()->reduce_memory_footprint_) { | 5259 mark_compact_collector()->reduce_memory_footprint_) { |
| 5264 factor = min_factor; | 5260 factor = min_factor; |
| 5265 } | 5261 } |
| 5266 | 5262 |
| 5267 intptr_t limit = static_cast<intptr_t>(old_gen_size * factor); | 5263 intptr_t limit = static_cast<intptr_t>(old_gen_size * factor); |
| 5268 limit = Max(limit, kMinimumOldGenerationAllocationLimit); | 5264 limit = Max(limit, kMinimumOldGenerationAllocationLimit); |
| 5269 limit += new_space_.Capacity(); | 5265 |
| 5270 intptr_t halfway_to_the_max = (old_gen_size + max_old_generation_size_) / 2; | 5266 old_generation_allocation_limit_ = limit + new_space_.Capacity(); |
| 5271 return Min(limit, halfway_to_the_max); | 5267 |
| 5268 // The committed memory limit is halfway from the current live object count |
| 5269 // to the max size. This means that if half of our allowed extra memory is |
| 5270 // currently taken by fragmentation we will immediately start another |
| 5271 // incremental GC. If there is no fragmentation, we will start incremental |
| 5272 // GC when we have committed half the allowed extra memory. This limit will |
| 5273 // be compared against the committed memory, ie including fragmentation. |
| 5274 intptr_t commit_limit_basis = old_gen_size; |
| 5275 if (FLAG_never_compact || !FLAG_compact_code_space) { |
| 5276 // No point in provoking GCs to get rid of fragmentation if we can't |
| 5277 // actually get rid of fragmentation. In this case set the limit higher. |
| 5278 commit_limit_basis = CommittedOldGenerationMemory(); |
| 5279 } |
| 5280 old_generation_committed_memory_limit_ = |
| 5281 old_gen_size / 2 + max_old_generation_size_ / 2; |
| 5282 |
| 5283 if (weak_callbacks_completed && FLAG_trace_gc) { |
| 5284 PrintPID("%8.0f ms: ", isolate()->time_millis_since_init()); |
| 5285 PrintF("Next GC at %.1f (%.1f) -> %.1f (%.1f)\n", old_gen_size * 1.0 / MB, |
| 5286 CommittedOldGenerationMemory() * 1.0 / MB, limit * 1.0 / MB, |
| 5287 old_generation_committed_memory_limit_ * 1.0 / MB); |
| 5288 } |
| 5272 } | 5289 } |
| 5273 | 5290 |
| 5274 | 5291 |
| 5275 void Heap::EnableInlineAllocation() { | 5292 void Heap::EnableInlineAllocation() { |
| 5276 if (!inline_allocation_disabled_) return; | 5293 if (!inline_allocation_disabled_) return; |
| 5277 inline_allocation_disabled_ = false; | 5294 inline_allocation_disabled_ = false; |
| 5278 | 5295 |
| 5279 // Update inline allocation limit for new space. | 5296 // Update inline allocation limit for new space. |
| 5280 new_space()->UpdateInlineAllocationLimit(0); | 5297 new_space()->UpdateInlineAllocationLimit(0); |
| 5281 } | 5298 } |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6390 static_cast<int>(object_sizes_last_time_[index])); | 6407 static_cast<int>(object_sizes_last_time_[index])); |
| 6391 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6408 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 6392 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6409 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 6393 | 6410 |
| 6394 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6411 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 6395 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6412 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 6396 ClearObjectStats(); | 6413 ClearObjectStats(); |
| 6397 } | 6414 } |
| 6398 } | 6415 } |
| 6399 } // namespace v8::internal | 6416 } // namespace v8::internal |
| OLD | NEW |