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