| 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/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 collector, gc_callback_flags); | 1347 collector, gc_callback_flags); |
| 1348 } | 1348 } |
| 1349 gc_post_processing_depth_--; | 1349 gc_post_processing_depth_--; |
| 1350 | 1350 |
| 1351 isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); | 1351 isolate_->eternal_handles()->PostGarbageCollectionProcessing(this); |
| 1352 | 1352 |
| 1353 // Update relocatables. | 1353 // Update relocatables. |
| 1354 Relocatable::PostGarbageCollectionProcessing(isolate_); | 1354 Relocatable::PostGarbageCollectionProcessing(isolate_); |
| 1355 | 1355 |
| 1356 double gc_speed = tracer()->CombinedMarkCompactSpeedInBytesPerMillisecond(); | 1356 double gc_speed = tracer()->CombinedMarkCompactSpeedInBytesPerMillisecond(); |
| 1357 double mutator_speed = static_cast<double>( | 1357 double mutator_speed = |
| 1358 tracer() | 1358 tracer()->CurrentOldGenerationAllocationThroughputInBytesPerMillisecond(); |
| 1359 ->CurrentOldGenerationAllocationThroughputInBytesPerMillisecond()); | |
| 1360 intptr_t old_gen_size = PromotedSpaceSizeOfObjects(); | 1359 intptr_t old_gen_size = PromotedSpaceSizeOfObjects(); |
| 1361 if (collector == MARK_COMPACTOR) { | 1360 if (collector == MARK_COMPACTOR) { |
| 1362 // Register the amount of external allocated memory. | 1361 // Register the amount of external allocated memory. |
| 1363 amount_of_external_allocated_memory_at_last_global_gc_ = | 1362 amount_of_external_allocated_memory_at_last_global_gc_ = |
| 1364 amount_of_external_allocated_memory_; | 1363 amount_of_external_allocated_memory_; |
| 1365 SetOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); | 1364 SetOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); |
| 1366 } else if (HasLowYoungGenerationAllocationRate() && | 1365 } else if (HasLowYoungGenerationAllocationRate() && |
| 1367 old_generation_size_configured_) { | 1366 old_generation_size_configured_) { |
| 1368 DampenOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); | 1367 DampenOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); |
| 1369 } | 1368 } |
| (...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4128 // mutator_utilization = (1 / mutator_speed) / | 4127 // mutator_utilization = (1 / mutator_speed) / |
| 4129 // (1 / mutator_speed + 1 / gc_speed) | 4128 // (1 / mutator_speed + 1 / gc_speed) |
| 4130 // mutator_utilization = gc_speed / (mutator_speed + gc_speed) | 4129 // mutator_utilization = gc_speed / (mutator_speed + gc_speed) |
| 4131 return gc_speed / (mutator_speed + gc_speed); | 4130 return gc_speed / (mutator_speed + gc_speed); |
| 4132 } | 4131 } |
| 4133 | 4132 |
| 4134 | 4133 |
| 4135 double Heap::YoungGenerationMutatorUtilization() { | 4134 double Heap::YoungGenerationMutatorUtilization() { |
| 4136 double mutator_speed = static_cast<double>( | 4135 double mutator_speed = static_cast<double>( |
| 4137 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); | 4136 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); |
| 4138 double gc_speed = static_cast<double>( | 4137 double gc_speed = |
| 4139 tracer()->ScavengeSpeedInBytesPerMillisecond(kForSurvivedObjects)); | 4138 tracer()->ScavengeSpeedInBytesPerMillisecond(kForSurvivedObjects); |
| 4140 double result = ComputeMutatorUtilization(mutator_speed, gc_speed); | 4139 double result = ComputeMutatorUtilization(mutator_speed, gc_speed); |
| 4141 if (FLAG_trace_mutator_utilization) { | 4140 if (FLAG_trace_mutator_utilization) { |
| 4142 PrintIsolate(isolate(), | 4141 PrintIsolate(isolate(), |
| 4143 "Young generation mutator utilization = %.3f (" | 4142 "Young generation mutator utilization = %.3f (" |
| 4144 "mutator_speed=%.f, gc_speed=%.f)\n", | 4143 "mutator_speed=%.f, gc_speed=%.f)\n", |
| 4145 result, mutator_speed, gc_speed); | 4144 result, mutator_speed, gc_speed); |
| 4146 } | 4145 } |
| 4147 return result; | 4146 return result; |
| 4148 } | 4147 } |
| 4149 | 4148 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4208 event.time_ms = MonotonicallyIncreasingTimeInMs(); | 4207 event.time_ms = MonotonicallyIncreasingTimeInMs(); |
| 4209 memory_reducer_->NotifyPossibleGarbage(event); | 4208 memory_reducer_->NotifyPossibleGarbage(event); |
| 4210 } | 4209 } |
| 4211 optimize_for_memory_usage_ = true; | 4210 optimize_for_memory_usage_ = true; |
| 4212 } | 4211 } |
| 4213 | 4212 |
| 4214 void Heap::ReduceNewSpaceSize() { | 4213 void Heap::ReduceNewSpaceSize() { |
| 4215 // TODO(ulan): Unify this constant with the similar constant in | 4214 // TODO(ulan): Unify this constant with the similar constant in |
| 4216 // GCIdleTimeHandler once the change is merged to 4.5. | 4215 // GCIdleTimeHandler once the change is merged to 4.5. |
| 4217 static const size_t kLowAllocationThroughput = 1000; | 4216 static const size_t kLowAllocationThroughput = 1000; |
| 4218 const size_t allocation_throughput = | 4217 const double allocation_throughput = |
| 4219 tracer()->CurrentAllocationThroughputInBytesPerMillisecond(); | 4218 tracer()->CurrentAllocationThroughputInBytesPerMillisecond(); |
| 4220 | 4219 |
| 4221 if (FLAG_predictable) return; | 4220 if (FLAG_predictable) return; |
| 4222 | 4221 |
| 4223 if (ShouldReduceMemory() || | 4222 if (ShouldReduceMemory() || |
| 4224 ((allocation_throughput != 0) && | 4223 ((allocation_throughput != 0) && |
| 4225 (allocation_throughput < kLowAllocationThroughput))) { | 4224 (allocation_throughput < kLowAllocationThroughput))) { |
| 4226 new_space_.Shrink(); | 4225 new_space_.Shrink(); |
| 4227 UncommitFromSpace(); | 4226 UncommitFromSpace(); |
| 4228 } | 4227 } |
| 4229 } | 4228 } |
| 4230 | 4229 |
| 4231 | 4230 |
| 4232 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { | 4231 void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) { |
| 4233 if (incremental_marking()->IsMarking() && | 4232 if (incremental_marking()->IsMarking() && |
| 4234 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || | 4233 (incremental_marking()->IsReadyToOverApproximateWeakClosure() || |
| 4235 (!incremental_marking()->finalize_marking_completed() && | 4234 (!incremental_marking()->finalize_marking_completed() && |
| 4236 mark_compact_collector()->marking_deque()->IsEmpty()))) { | 4235 mark_compact_collector()->marking_deque()->IsEmpty()))) { |
| 4237 FinalizeIncrementalMarking(comment); | 4236 FinalizeIncrementalMarking(comment); |
| 4238 } else if (incremental_marking()->IsComplete() || | 4237 } else if (incremental_marking()->IsComplete() || |
| 4239 (mark_compact_collector()->marking_deque()->IsEmpty())) { | 4238 (mark_compact_collector()->marking_deque()->IsEmpty())) { |
| 4240 CollectAllGarbage(current_gc_flags_, comment); | 4239 CollectAllGarbage(current_gc_flags_, comment); |
| 4241 } | 4240 } |
| 4242 } | 4241 } |
| 4243 | 4242 |
| 4244 | 4243 |
| 4245 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { | 4244 bool Heap::TryFinalizeIdleIncrementalMarking(double idle_time_in_ms) { |
| 4246 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); | 4245 size_t size_of_objects = static_cast<size_t>(SizeOfObjects()); |
| 4247 size_t final_incremental_mark_compact_speed_in_bytes_per_ms = | 4246 double final_incremental_mark_compact_speed_in_bytes_per_ms = |
| 4248 static_cast<size_t>( | 4247 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond(); |
| 4249 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); | |
| 4250 if (incremental_marking()->IsReadyToOverApproximateWeakClosure() || | 4248 if (incremental_marking()->IsReadyToOverApproximateWeakClosure() || |
| 4251 (!incremental_marking()->finalize_marking_completed() && | 4249 (!incremental_marking()->finalize_marking_completed() && |
| 4252 mark_compact_collector()->marking_deque()->IsEmpty() && | 4250 mark_compact_collector()->marking_deque()->IsEmpty() && |
| 4253 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( | 4251 gc_idle_time_handler_->ShouldDoOverApproximateWeakClosure( |
| 4254 static_cast<size_t>(idle_time_in_ms)))) { | 4252 idle_time_in_ms))) { |
| 4255 FinalizeIncrementalMarking( | 4253 FinalizeIncrementalMarking( |
| 4256 "Idle notification: finalize incremental marking"); | 4254 "Idle notification: finalize incremental marking"); |
| 4257 return true; | 4255 return true; |
| 4258 } else if (incremental_marking()->IsComplete() || | 4256 } else if (incremental_marking()->IsComplete() || |
| 4259 (mark_compact_collector()->marking_deque()->IsEmpty() && | 4257 (mark_compact_collector()->marking_deque()->IsEmpty() && |
| 4260 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( | 4258 gc_idle_time_handler_->ShouldDoFinalIncrementalMarkCompact( |
| 4261 static_cast<size_t>(idle_time_in_ms), size_of_objects, | 4259 idle_time_in_ms, size_of_objects, |
| 4262 final_incremental_mark_compact_speed_in_bytes_per_ms))) { | 4260 final_incremental_mark_compact_speed_in_bytes_per_ms))) { |
| 4263 CollectAllGarbage(current_gc_flags_, | 4261 CollectAllGarbage(current_gc_flags_, |
| 4264 "idle notification: finalize incremental marking"); | 4262 "idle notification: finalize incremental marking"); |
| 4265 return true; | 4263 return true; |
| 4266 } | 4264 } |
| 4267 return false; | 4265 return false; |
| 4268 } | 4266 } |
| 4269 | 4267 |
| 4270 void Heap::RegisterReservationsForBlackAllocation(Reservation* reservations) { | 4268 void Heap::RegisterReservationsForBlackAllocation(Reservation* reservations) { |
| 4271 // TODO(hpayer): We do not have to iterate reservations on black objects | 4269 // TODO(hpayer): We do not have to iterate reservations on black objects |
| (...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6473 } | 6471 } |
| 6474 | 6472 |
| 6475 | 6473 |
| 6476 // static | 6474 // static |
| 6477 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6475 int Heap::GetStaticVisitorIdForMap(Map* map) { |
| 6478 return StaticVisitorBase::GetVisitorId(map); | 6476 return StaticVisitorBase::GetVisitorId(map); |
| 6479 } | 6477 } |
| 6480 | 6478 |
| 6481 } // namespace internal | 6479 } // namespace internal |
| 6482 } // namespace v8 | 6480 } // namespace v8 |
| OLD | NEW |