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 #include <climits> | 4 #include <climits> |
5 | 5 |
6 #include "src/v8.h" | 6 #include "src/v8.h" |
7 | 7 |
8 #include "src/heap/gc-idle-time-handler.h" | 8 #include "src/heap/gc-idle-time-handler.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 | |
14 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; | 13 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; |
15 | 14 |
16 | |
17 intptr_t GCIdleTimeHandler::EstimateMarkingStepSize( | 15 intptr_t GCIdleTimeHandler::EstimateMarkingStepSize( |
18 int idle_time_in_ms, intptr_t marking_speed_in_bytes_per_ms) { | 16 int idle_time_in_ms, intptr_t marking_speed_in_bytes_per_ms) { |
19 DCHECK(idle_time_in_ms > 0); | 17 DCHECK(idle_time_in_ms > 0); |
20 | 18 |
21 if (marking_speed_in_bytes_per_ms == 0) { | 19 if (marking_speed_in_bytes_per_ms == 0) { |
22 marking_speed_in_bytes_per_ms = | 20 marking_speed_in_bytes_per_ms = |
23 GCIdleTimeHandler::kInitialConservativeMarkingSpeed; | 21 GCIdleTimeHandler::kInitialConservativeMarkingSpeed; |
24 } | 22 } |
25 | 23 |
26 intptr_t marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms; | 24 intptr_t marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms; |
27 if (static_cast<intptr_t>(marking_step_size / idle_time_in_ms) != | 25 if (static_cast<intptr_t>(marking_step_size / idle_time_in_ms) != |
28 marking_speed_in_bytes_per_ms) { | 26 marking_speed_in_bytes_per_ms) { |
29 // 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. |
30 return INT_MAX; | 28 return INT_MAX; |
31 } | 29 } |
32 | 30 |
33 return static_cast<intptr_t>(marking_step_size * | 31 return static_cast<intptr_t>(marking_step_size * |
34 GCIdleTimeHandler::kConservativeTimeRatio); | 32 GCIdleTimeHandler::kConservativeTimeRatio); |
35 } | 33 } |
34 | |
35 | |
36 int GCIdleTimeHandler::EstimateMarkSweepTime( | |
37 intptr_t size_of_objects, intptr_t mark_sweep_speed_in_bytes_per_ms) { | |
38 const intptr_t kInitialConservativeMarkSweepSpeed = 2 * MB; | |
39 const intptr_t kMaxTimeInMs = 1000000; | |
40 if (mark_sweep_speed_in_bytes_per_ms == 0) { | |
41 mark_sweep_speed_in_bytes_per_ms = kInitialConservativeMarkSweepSpeed; | |
42 } | |
43 intptr_t result = size_of_objects / mark_sweep_speed_in_bytes_per_ms; | |
44 return static_cast<int>(Min(result, kMaxTimeInMs)); | |
45 } | |
46 | |
47 | |
48 GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms, | |
49 int contexts_disposed, | |
50 intptr_t size_of_objects, | |
51 bool incremental_marking_stopped, | |
52 GCTracer* gc_tracer) { | |
53 if (IsIdleRoundFinished()) { | |
54 if (EnoughGarbageSinceLastIdleRound() || contexts_disposed > 0) { | |
55 StartIdleRound(); | |
56 } else { | |
57 return GCIdleTimeAction::Nothing(); | |
58 } | |
59 } | |
60 if (incremental_marking_stopped) { | |
61 intptr_t speed = gc_tracer->MaxMarkSweepSpeedInBytesPerMillisecond(); | |
Hannes Payer (out of office)
2014/08/20 18:24:11
Why are we taking the maximum?
ulan
2014/08/21 08:45:19
Good catch, it should be either minimum or average
| |
62 if (idle_time_in_ms >= EstimateMarkSweepTime(size_of_objects, speed)) { | |
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 | |
65 // the code space. | |
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. | |
68 int remaining_mark_sweeps = | |
69 kMaxMarkSweepsInIdleRound - mark_sweeps_since_idle_round_started_; | |
70 if (contexts_disposed > 0 || remaining_mark_sweeps <= 2) { | |
71 return GCIdleTimeAction::FullGC(); | |
72 } | |
73 } | |
74 } | |
75 intptr_t speed = gc_tracer->IncrementalMarkingSpeedInBytesPerMillisecond(); | |
76 intptr_t step_size = EstimateMarkingStepSize(idle_time_in_ms, speed); | |
77 return GCIdleTimeAction::IncrementalMarking(step_size); | |
36 } | 78 } |
37 } | 79 } |
80 } | |
OLD | NEW |