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/heap/heap.h" | 5 #include "src/heap/heap.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/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 } | 801 } |
802 | 802 |
803 | 803 |
804 void Heap::ScheduleIdleScavengeIfNeeded(int bytes_allocated) { | 804 void Heap::ScheduleIdleScavengeIfNeeded(int bytes_allocated) { |
805 scavenge_job_->ScheduleIdleTaskIfNeeded(this, bytes_allocated); | 805 scavenge_job_->ScheduleIdleTaskIfNeeded(this, bytes_allocated); |
806 } | 806 } |
807 | 807 |
808 | 808 |
809 void Heap::FinalizeIncrementalMarking(const char* gc_reason) { | 809 void Heap::FinalizeIncrementalMarking(const char* gc_reason) { |
810 if (FLAG_trace_incremental_marking) { | 810 if (FLAG_trace_incremental_marking) { |
811 PrintF("[IncrementalMarking] (%s).\n", gc_reason); | 811 isolate()->PrintWithTimestamp("[IncrementalMarking] (%s).\n", gc_reason); |
812 } | 812 } |
813 | 813 |
814 HistogramTimerScope incremental_marking_scope( | 814 HistogramTimerScope incremental_marking_scope( |
815 isolate()->counters()->gc_incremental_marking_finalize()); | 815 isolate()->counters()->gc_incremental_marking_finalize()); |
816 TRACE_EVENT0("v8", "V8.GCIncrementalMarkingFinalize"); | 816 TRACE_EVENT0("v8", "V8.GCIncrementalMarkingFinalize"); |
817 TRACE_GC(tracer(), GCTracer::Scope::MC_INCREMENTAL_FINALIZE); | 817 TRACE_GC(tracer(), GCTracer::Scope::MC_INCREMENTAL_FINALIZE); |
818 | 818 |
819 { | 819 { |
820 GCCallbacksScope scope(this); | 820 GCCallbacksScope scope(this); |
821 if (scope.CheckReenter()) { | 821 if (scope.CheckReenter()) { |
(...skipping 3252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4074 } | 4074 } |
4075 | 4075 |
4076 | 4076 |
4077 double Heap::YoungGenerationMutatorUtilization() { | 4077 double Heap::YoungGenerationMutatorUtilization() { |
4078 double mutator_speed = static_cast<double>( | 4078 double mutator_speed = static_cast<double>( |
4079 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); | 4079 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); |
4080 double gc_speed = | 4080 double gc_speed = |
4081 tracer()->ScavengeSpeedInBytesPerMillisecond(kForSurvivedObjects); | 4081 tracer()->ScavengeSpeedInBytesPerMillisecond(kForSurvivedObjects); |
4082 double result = ComputeMutatorUtilization(mutator_speed, gc_speed); | 4082 double result = ComputeMutatorUtilization(mutator_speed, gc_speed); |
4083 if (FLAG_trace_mutator_utilization) { | 4083 if (FLAG_trace_mutator_utilization) { |
4084 PrintIsolate(isolate(), | 4084 isolate()->PrintWithTimestamp( |
4085 "Young generation mutator utilization = %.3f (" | 4085 "Young generation mutator utilization = %.3f (" |
4086 "mutator_speed=%.f, gc_speed=%.f)\n", | 4086 "mutator_speed=%.f, gc_speed=%.f)\n", |
4087 result, mutator_speed, gc_speed); | 4087 result, mutator_speed, gc_speed); |
4088 } | 4088 } |
4089 return result; | 4089 return result; |
4090 } | 4090 } |
4091 | 4091 |
4092 | 4092 |
4093 double Heap::OldGenerationMutatorUtilization() { | 4093 double Heap::OldGenerationMutatorUtilization() { |
4094 double mutator_speed = static_cast<double>( | 4094 double mutator_speed = static_cast<double>( |
4095 tracer()->OldGenerationAllocationThroughputInBytesPerMillisecond()); | 4095 tracer()->OldGenerationAllocationThroughputInBytesPerMillisecond()); |
4096 double gc_speed = static_cast<double>( | 4096 double gc_speed = static_cast<double>( |
4097 tracer()->CombinedMarkCompactSpeedInBytesPerMillisecond()); | 4097 tracer()->CombinedMarkCompactSpeedInBytesPerMillisecond()); |
4098 double result = ComputeMutatorUtilization(mutator_speed, gc_speed); | 4098 double result = ComputeMutatorUtilization(mutator_speed, gc_speed); |
4099 if (FLAG_trace_mutator_utilization) { | 4099 if (FLAG_trace_mutator_utilization) { |
4100 PrintIsolate(isolate(), | 4100 isolate()->PrintWithTimestamp( |
4101 "Old generation mutator utilization = %.3f (" | 4101 "Old generation mutator utilization = %.3f (" |
4102 "mutator_speed=%.f, gc_speed=%.f)\n", | 4102 "mutator_speed=%.f, gc_speed=%.f)\n", |
4103 result, mutator_speed, gc_speed); | 4103 result, mutator_speed, gc_speed); |
4104 } | 4104 } |
4105 return result; | 4105 return result; |
4106 } | 4106 } |
4107 | 4107 |
4108 | 4108 |
4109 bool Heap::HasLowYoungGenerationAllocationRate() { | 4109 bool Heap::HasLowYoungGenerationAllocationRate() { |
4110 const double high_mutator_utilization = 0.993; | 4110 const double high_mutator_utilization = 0.993; |
4111 return YoungGenerationMutatorUtilization() > high_mutator_utilization; | 4111 return YoungGenerationMutatorUtilization() > high_mutator_utilization; |
4112 } | 4112 } |
4113 | 4113 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4321 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( | 4321 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( |
4322 static_cast<int>(deadline_difference)); | 4322 static_cast<int>(deadline_difference)); |
4323 } | 4323 } |
4324 } else { | 4324 } else { |
4325 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample( | 4325 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample( |
4326 static_cast<int>(-deadline_difference)); | 4326 static_cast<int>(-deadline_difference)); |
4327 } | 4327 } |
4328 | 4328 |
4329 if ((FLAG_trace_idle_notification && action.type > DO_NOTHING) || | 4329 if ((FLAG_trace_idle_notification && action.type > DO_NOTHING) || |
4330 FLAG_trace_idle_notification_verbose) { | 4330 FLAG_trace_idle_notification_verbose) { |
4331 PrintIsolate(isolate_, "%8.0f ms: ", isolate()->time_millis_since_init()); | 4331 isolate_->PrintWithTimestamp( |
4332 PrintF( | |
4333 "Idle notification: requested idle time %.2f ms, used idle time %.2f " | 4332 "Idle notification: requested idle time %.2f ms, used idle time %.2f " |
4334 "ms, deadline usage %.2f ms [", | 4333 "ms, deadline usage %.2f ms [", |
4335 idle_time_in_ms, idle_time_in_ms - deadline_difference, | 4334 idle_time_in_ms, idle_time_in_ms - deadline_difference, |
4336 deadline_difference); | 4335 deadline_difference); |
4337 action.Print(); | 4336 action.Print(); |
4338 PrintF("]"); | 4337 PrintF("]"); |
4339 if (FLAG_trace_idle_notification_verbose) { | 4338 if (FLAG_trace_idle_notification_verbose) { |
4340 PrintF("["); | 4339 PrintF("["); |
4341 heap_state.Print(); | 4340 heap_state.Print(); |
4342 PrintF("]"); | 4341 PrintF("]"); |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5188 return Min(limit, halfway_to_the_max); | 5187 return Min(limit, halfway_to_the_max); |
5189 } | 5188 } |
5190 | 5189 |
5191 | 5190 |
5192 void Heap::SetOldGenerationAllocationLimit(intptr_t old_gen_size, | 5191 void Heap::SetOldGenerationAllocationLimit(intptr_t old_gen_size, |
5193 double gc_speed, | 5192 double gc_speed, |
5194 double mutator_speed) { | 5193 double mutator_speed) { |
5195 double factor = HeapGrowingFactor(gc_speed, mutator_speed); | 5194 double factor = HeapGrowingFactor(gc_speed, mutator_speed); |
5196 | 5195 |
5197 if (FLAG_trace_gc_verbose) { | 5196 if (FLAG_trace_gc_verbose) { |
5198 PrintIsolate(isolate_, | 5197 isolate_->PrintWithTimestamp( |
5199 "Heap growing factor %.1f based on mu=%.3f, speed_ratio=%.f " | 5198 "Heap growing factor %.1f based on mu=%.3f, speed_ratio=%.f " |
5200 "(gc=%.f, mutator=%.f)\n", | 5199 "(gc=%.f, mutator=%.f)\n", |
5201 factor, kTargetMutatorUtilization, gc_speed / mutator_speed, | 5200 factor, kTargetMutatorUtilization, gc_speed / mutator_speed, gc_speed, |
5202 gc_speed, mutator_speed); | 5201 mutator_speed); |
5203 } | 5202 } |
5204 | 5203 |
5205 if (IsMemoryConstrainedDevice()) { | 5204 if (IsMemoryConstrainedDevice()) { |
5206 factor = Min(factor, kMaxHeapGrowingFactorMemoryConstrained); | 5205 factor = Min(factor, kMaxHeapGrowingFactorMemoryConstrained); |
5207 } | 5206 } |
5208 | 5207 |
5209 if (memory_reducer_->ShouldGrowHeapSlowly() || | 5208 if (memory_reducer_->ShouldGrowHeapSlowly() || |
5210 ShouldOptimizeForMemoryUsage()) { | 5209 ShouldOptimizeForMemoryUsage()) { |
5211 factor = Min(factor, kConservativeHeapGrowingFactor); | 5210 factor = Min(factor, kConservativeHeapGrowingFactor); |
5212 } | 5211 } |
5213 | 5212 |
5214 if (FLAG_stress_compaction || ShouldReduceMemory()) { | 5213 if (FLAG_stress_compaction || ShouldReduceMemory()) { |
5215 factor = kMinHeapGrowingFactor; | 5214 factor = kMinHeapGrowingFactor; |
5216 } | 5215 } |
5217 | 5216 |
5218 if (FLAG_heap_growing_percent > 0) { | 5217 if (FLAG_heap_growing_percent > 0) { |
5219 factor = 1.0 + FLAG_heap_growing_percent / 100.0; | 5218 factor = 1.0 + FLAG_heap_growing_percent / 100.0; |
5220 } | 5219 } |
5221 | 5220 |
5222 old_generation_allocation_limit_ = | 5221 old_generation_allocation_limit_ = |
5223 CalculateOldGenerationAllocationLimit(factor, old_gen_size); | 5222 CalculateOldGenerationAllocationLimit(factor, old_gen_size); |
5224 | 5223 |
5225 if (FLAG_trace_gc_verbose) { | 5224 if (FLAG_trace_gc_verbose) { |
5226 PrintIsolate(isolate_, "Grow: old size: %" V8PRIdPTR | 5225 isolate_->PrintWithTimestamp("Grow: old size: %" V8PRIdPTR |
5227 " KB, new limit: %" V8PRIdPTR " KB (%.1f)\n", | 5226 " KB, new limit: %" V8PRIdPTR " KB (%.1f)\n", |
5228 old_gen_size / KB, old_generation_allocation_limit_ / KB, | 5227 old_gen_size / KB, |
5229 factor); | 5228 old_generation_allocation_limit_ / KB, factor); |
5230 } | 5229 } |
5231 } | 5230 } |
5232 | 5231 |
5233 | 5232 |
5234 void Heap::DampenOldGenerationAllocationLimit(intptr_t old_gen_size, | 5233 void Heap::DampenOldGenerationAllocationLimit(intptr_t old_gen_size, |
5235 double gc_speed, | 5234 double gc_speed, |
5236 double mutator_speed) { | 5235 double mutator_speed) { |
5237 double factor = HeapGrowingFactor(gc_speed, mutator_speed); | 5236 double factor = HeapGrowingFactor(gc_speed, mutator_speed); |
5238 intptr_t limit = CalculateOldGenerationAllocationLimit(factor, old_gen_size); | 5237 intptr_t limit = CalculateOldGenerationAllocationLimit(factor, old_gen_size); |
5239 if (limit < old_generation_allocation_limit_) { | 5238 if (limit < old_generation_allocation_limit_) { |
5240 if (FLAG_trace_gc_verbose) { | 5239 if (FLAG_trace_gc_verbose) { |
5241 PrintIsolate(isolate_, | 5240 isolate_->PrintWithTimestamp( |
5242 "Dampen: old size: %" V8PRIdPTR " KB, old limit: %" V8PRIdPTR | 5241 "Dampen: old size: %" V8PRIdPTR " KB, old limit: %" V8PRIdPTR |
5243 " KB, " | 5242 " KB, " |
5244 "new limit: %" V8PRIdPTR " KB (%.1f)\n", | 5243 "new limit: %" V8PRIdPTR " KB (%.1f)\n", |
5245 old_gen_size / KB, old_generation_allocation_limit_ / KB, | 5244 old_gen_size / KB, old_generation_allocation_limit_ / KB, limit / KB, |
5246 limit / KB, factor); | 5245 factor); |
5247 } | 5246 } |
5248 old_generation_allocation_limit_ = limit; | 5247 old_generation_allocation_limit_ = limit; |
5249 } | 5248 } |
5250 } | 5249 } |
5251 | 5250 |
5252 | 5251 |
5253 void Heap::EnableInlineAllocation() { | 5252 void Heap::EnableInlineAllocation() { |
5254 if (!inline_allocation_disabled_) return; | 5253 if (!inline_allocation_disabled_) return; |
5255 inline_allocation_disabled_ = false; | 5254 inline_allocation_disabled_ = false; |
5256 | 5255 |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6500 } | 6499 } |
6501 | 6500 |
6502 | 6501 |
6503 // static | 6502 // static |
6504 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6503 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6505 return StaticVisitorBase::GetVisitorId(map); | 6504 return StaticVisitorBase::GetVisitorId(map); |
6506 } | 6505 } |
6507 | 6506 |
6508 } // namespace internal | 6507 } // namespace internal |
6509 } // namespace v8 | 6508 } // namespace v8 |
OLD | NEW |