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