| 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 = 1000; |
| 14 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; | 14 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; |
| 15 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7; | 15 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7; |
| 16 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5; | 16 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5; |
| 17 | 17 |
| 18 | 18 |
| 19 void GCIdleTimeAction::Print() { | 19 void GCIdleTimeAction::Print() { |
| 20 switch (type) { | 20 switch (type) { |
| 21 case DO_NOTHING: | 21 case DO_NOTHING: |
| 22 PrintF("no action"); | 22 PrintF("no action"); |
| 23 break; | 23 break; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, | 71 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, |
| 72 HeapState heap_state) { | 72 HeapState heap_state) { |
| 73 if (IsIdleRoundFinished()) { | 73 if (IsIdleRoundFinished()) { |
| 74 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { | 74 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { |
| 75 StartIdleRound(); | 75 StartIdleRound(); |
| 76 } else { | 76 } else { |
| 77 return GCIdleTimeAction::Nothing(); | 77 return GCIdleTimeAction::Nothing(); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 if (heap_state.incremental_marking_stopped) { | 80 if (heap_state.incremental_marking_stopped) { |
| 81 if (idle_time_in_ms >= EstimateMarkCompactTime( | 81 size_t estimated_time_in_ms = |
| 82 heap_state.size_of_objects, | 82 EstimateMarkCompactTime(heap_state.size_of_objects, |
| 83 heap_state.mark_compact_speed_in_bytes_per_ms)) { | 83 heap_state.mark_compact_speed_in_bytes_per_ms); |
| 84 if (idle_time_in_ms >= estimated_time_in_ms) { |
| 84 // If there are no more than two GCs left in this idle round and we are | 85 // If there are no more than two GCs left in this idle round and we are |
| 85 // allowed to do a full GC, then make those GCs full in order to compact | 86 // allowed to do a full GC, then make those GCs full in order to compact |
| 86 // the code space. | 87 // the code space. |
| 87 // TODO(ulan): Once we enable code compaction for incremental marking, we | 88 // TODO(ulan): Once we enable code compaction for incremental marking, we |
| 88 // can get rid of this special case and always start incremental marking. | 89 // can get rid of this special case and always start incremental marking. |
| 89 int remaining_mark_sweeps = | 90 int remaining_mark_sweeps = |
| 90 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | 91 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; |
| 91 if (heap_state.contexts_disposed > 0 || remaining_mark_sweeps <= 2 || | 92 if (heap_state.contexts_disposed > 0 || remaining_mark_sweeps <= 2 || |
| 92 !heap_state.can_start_incremental_marking) { | 93 !heap_state.can_start_incremental_marking) { |
| 93 return GCIdleTimeAction::FullGC(); | 94 return GCIdleTimeAction::FullGC(); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 if (!heap_state.can_start_incremental_marking) { | 97 if (!heap_state.can_start_incremental_marking) { |
| 97 return GCIdleTimeAction::Nothing(); | 98 return GCIdleTimeAction::Nothing(); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 // TODO(hpayer): Estimate finalize sweeping time. | 101 // TODO(hpayer): Estimate finalize sweeping time. |
| 101 if (heap_state.sweeping_in_progress && | 102 if (heap_state.sweeping_in_progress && |
| 102 idle_time_in_ms >= kMinTimeForFinalizeSweeping) { | 103 idle_time_in_ms >= kMinTimeForFinalizeSweeping) { |
| 103 return GCIdleTimeAction::FinalizeSweeping(); | 104 return GCIdleTimeAction::FinalizeSweeping(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 size_t step_size = EstimateMarkingStepSize( | 107 size_t step_size = EstimateMarkingStepSize( |
| 107 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 108 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 108 return GCIdleTimeAction::IncrementalMarking(step_size); | 109 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 } | 112 } |
| OLD | NEW |