| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/gc-idle-time-handler.h" | 5 #include "src/heap/gc-idle-time-handler.h" |
| 6 #include "src/heap/gc-tracer.h" | 6 #include "src/heap/gc-tracer.h" |
| 7 #include "src/utils.h" | 7 #include "src/utils.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 | 11 |
| 12 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; | 12 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; |
| 13 const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000000; | 13 const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000000; |
| 14 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; |
| 14 | 15 |
| 15 | 16 |
| 16 size_t GCIdleTimeHandler::EstimateMarkingStepSize( | 17 size_t GCIdleTimeHandler::EstimateMarkingStepSize( |
| 17 size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms) { | 18 size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms) { |
| 18 DCHECK(idle_time_in_ms > 0); | 19 DCHECK(idle_time_in_ms > 0); |
| 19 | 20 |
| 20 if (marking_speed_in_bytes_per_ms == 0) { | 21 if (marking_speed_in_bytes_per_ms == 0) { |
| 21 marking_speed_in_bytes_per_ms = kInitialConservativeMarkingSpeed; | 22 marking_speed_in_bytes_per_ms = kInitialConservativeMarkingSpeed; |
| 22 } | 23 } |
| 23 | 24 |
| 24 size_t marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms; | 25 size_t marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms; |
| 25 if (marking_step_size / marking_speed_in_bytes_per_ms != idle_time_in_ms) { | 26 if (marking_step_size / marking_speed_in_bytes_per_ms != idle_time_in_ms) { |
| 26 // In the case of an overflow we return maximum marking step size. | 27 // In the case of an overflow we return maximum marking step size. |
| 27 return kMaximumMarkingStepSize; | 28 return kMaximumMarkingStepSize; |
| 28 } | 29 } |
| 29 | 30 |
| 30 if (marking_step_size > kMaximumMarkingStepSize) | 31 if (marking_step_size > kMaximumMarkingStepSize) |
| 31 return kMaximumMarkingStepSize; | 32 return kMaximumMarkingStepSize; |
| 32 | 33 |
| 33 return static_cast<size_t>(marking_step_size * | 34 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); |
| 34 GCIdleTimeHandler::kConservativeTimeRatio); | |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 size_t GCIdleTimeHandler::EstimateMarkCompactTime( | 38 size_t GCIdleTimeHandler::EstimateMarkCompactTime( |
| 39 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { | 39 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { |
| 40 if (mark_compact_speed_in_bytes_per_ms == 0) { | 40 if (mark_compact_speed_in_bytes_per_ms == 0) { |
| 41 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; | 41 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; |
| 42 } | 42 } |
| 43 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; | 43 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; |
| 44 return Min(result, kMaxMarkCompactTimeInMs); | 44 return Min(result, kMaxMarkCompactTimeInMs); |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms, | 48 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, |
| 49 HeapState heap_state, | 49 HeapState heap_state, |
| 50 GCTracer* gc_tracer) { | 50 GCTracer* gc_tracer) { |
| 51 if (IsIdleRoundFinished()) { | 51 if (IsIdleRoundFinished()) { |
| 52 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { | 52 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { |
| 53 StartIdleRound(); | 53 StartIdleRound(); |
| 54 } else { | 54 } else { |
| 55 return GCIdleTimeAction::Nothing(); | 55 return GCIdleTimeAction::Nothing(); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 if (heap_state.incremental_marking_stopped) { | 58 if (heap_state.incremental_marking_stopped) { |
| 59 size_t speed = | 59 size_t speed = |
| 60 static_cast<size_t>(gc_tracer->MarkCompactSpeedInBytesPerMillisecond()); | 60 static_cast<size_t>(gc_tracer->MarkCompactSpeedInBytesPerMillisecond()); |
| 61 if (idle_time_in_ms >= static_cast<int>(EstimateMarkCompactTime( | 61 if (idle_time_in_ms >= |
| 62 heap_state.size_of_objects, speed))) { | 62 EstimateMarkCompactTime(heap_state.size_of_objects, speed)) { |
| 63 // If there are no more than two GCs left in this idle round and we are | 63 // If there are no more than two GCs left in this idle round and we are |
| 64 // allowed to do a full GC, then make those GCs full in order to compact | 64 // allowed to do a full GC, then make those GCs full in order to compact |
| 65 // the code space. | 65 // the code space. |
| 66 // TODO(ulan): Once we enable code compaction for incremental marking, we | 66 // TODO(ulan): Once we enable code compaction for incremental marking, we |
| 67 // can get rid of this special case and always start incremental marking. | 67 // can get rid of this special case and always start incremental marking. |
| 68 int remaining_mark_sweeps = | 68 int remaining_mark_sweeps = |
| 69 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | 69 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; |
| 70 if (heap_state.contexts_disposed > 0 || remaining_mark_sweeps <= 2 || | 70 if (heap_state.contexts_disposed > 0 || remaining_mark_sweeps <= 2 || |
| 71 !heap_state.can_start_incremental_marking) { | 71 !heap_state.can_start_incremental_marking) { |
| 72 return GCIdleTimeAction::FullGC(); | 72 return GCIdleTimeAction::FullGC(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 if (!heap_state.can_start_incremental_marking) { | 75 if (!heap_state.can_start_incremental_marking) { |
| 76 return GCIdleTimeAction::Nothing(); | 76 return GCIdleTimeAction::Nothing(); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 // TODO(hpayer): Estimate finalize sweeping time. |
| 80 if (heap_state.sweeping_in_progress && |
| 81 idle_time_in_ms >= kMinTimeForFinalizeSweeping) { |
| 82 return GCIdleTimeAction::FinalizeSweeping(); |
| 83 } |
| 84 |
| 79 intptr_t speed = gc_tracer->IncrementalMarkingSpeedInBytesPerMillisecond(); | 85 intptr_t speed = gc_tracer->IncrementalMarkingSpeedInBytesPerMillisecond(); |
| 80 size_t step_size = | 86 size_t step_size = |
| 81 static_cast<size_t>(EstimateMarkingStepSize(idle_time_in_ms, speed)); | 87 static_cast<size_t>(EstimateMarkingStepSize(idle_time_in_ms, speed)); |
| 82 return GCIdleTimeAction::IncrementalMarking(step_size); | 88 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 83 } | 89 } |
| 84 } | 90 } |
| 85 } | 91 } |
| OLD | NEW |