Chromium Code Reviews| 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 | 7 |
| 7 namespace v8 { | 8 namespace v8 { |
| 8 namespace internal { | 9 namespace internal { |
| 9 | 10 |
| 10 | |
| 11 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; | 11 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; |
| 12 | 12 |
| 13 | 13 |
| 14 size_t GCIdleTimeHandler::EstimateMarkingStepSize( | 14 size_t GCIdleTimeHandler::EstimateMarkingStepSize( |
| 15 size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms) { | 15 size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms) { |
| 16 DCHECK(idle_time_in_ms > 0); | 16 DCHECK(idle_time_in_ms > 0); |
| 17 | 17 |
| 18 if (marking_speed_in_bytes_per_ms == 0) { | 18 if (marking_speed_in_bytes_per_ms == 0) { |
| 19 marking_speed_in_bytes_per_ms = | 19 marking_speed_in_bytes_per_ms = |
| 20 GCIdleTimeHandler::kInitialConservativeMarkingSpeed; | 20 GCIdleTimeHandler::kInitialConservativeMarkingSpeed; |
| 21 } | 21 } |
| 22 | 22 |
| 23 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; |
| 24 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) { |
| 25 // 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. |
| 26 return GCIdleTimeHandler::kMaximumMarkingStepSize; | 26 return GCIdleTimeHandler::kMaximumMarkingStepSize; |
| 27 } | 27 } |
| 28 | 28 |
| 29 if (marking_step_size > kMaximumMarkingStepSize) | 29 if (marking_step_size > kMaximumMarkingStepSize) |
| 30 return kMaximumMarkingStepSize; | 30 return kMaximumMarkingStepSize; |
| 31 | 31 |
| 32 return static_cast<size_t>(marking_step_size * | 32 return static_cast<size_t>(marking_step_size * |
| 33 GCIdleTimeHandler::kConservativeTimeRatio); | 33 GCIdleTimeHandler::kConservativeTimeRatio); |
| 34 } | 34 } |
| 35 | |
| 36 | |
| 37 int GCIdleTimeHandler::EstimateMarkSweepTime( | |
| 38 intptr_t size_of_objects, intptr_t mark_sweep_speed_in_bytes_per_ms) { | |
|
Hannes Payer (out of office)
2014/08/21 09:47:53
Can we make the parameters size_t, c.f. EstimateMa
ulan
2014/08/21 11:44:00
Done.
| |
| 39 const intptr_t kInitialConservativeMarkSweepSpeed = 2 * MB; | |
| 40 const int kMaxTimeInMs = 1000000; | |
|
Hannes Payer (out of office)
2014/08/21 09:47:53
I think these constant should be in GCIdleTImeHand
ulan
2014/08/21 11:44:00
Done.
| |
| 41 if (mark_sweep_speed_in_bytes_per_ms == 0) { | |
| 42 mark_sweep_speed_in_bytes_per_ms = kInitialConservativeMarkSweepSpeed; | |
| 43 } | |
| 44 intptr_t result = size_of_objects / mark_sweep_speed_in_bytes_per_ms; | |
| 45 if (result > kMaxTimeInMs) return kMaxTimeInMs; | |
| 46 return static_cast<int>(result); | |
| 47 } | |
| 48 | |
| 49 | |
| 50 GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms, | |
| 51 int contexts_disposed, | |
| 52 intptr_t size_of_objects, | |
| 53 bool incremental_marking_stopped, | |
| 54 GCTracer* gc_tracer) { | |
| 55 if (IsIdleRoundFinished()) { | |
| 56 if (EnoughGarbageSinceLastIdleRound() || contexts_disposed > 0) { | |
| 57 StartIdleRound(); | |
| 58 } else { | |
| 59 return GCIdleTimeAction::Nothing(); | |
| 60 } | |
| 61 } | |
| 62 if (incremental_marking_stopped) { | |
| 63 intptr_t speed = gc_tracer->MarkCompactSpeedInBytesPerMillisecond(); | |
| 64 if (idle_time_in_ms >= EstimateMarkSweepTime(size_of_objects, speed)) { | |
| 65 // If there are no more than two GCs left in this idle round and we are | |
| 66 // allowed to do a full GC, then make those GCs full in order to compact | |
| 67 // the code space. | |
| 68 // TODO(ulan): Once we enable code compaction for incremental marking, we | |
| 69 // can get rid of this special case and always start incremental marking. | |
| 70 int remaining_mark_sweeps = | |
| 71 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | |
| 72 if (contexts_disposed > 0 || remaining_mark_sweeps <= 2) { | |
| 73 return GCIdleTimeAction::FullGC(); | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 intptr_t speed = gc_tracer->IncrementalMarkingSpeedInBytesPerMillisecond(); | |
| 78 intptr_t step_size = EstimateMarkingStepSize(idle_time_in_ms, speed); | |
| 79 return GCIdleTimeAction::IncrementalMarking(step_size); | |
| 35 } | 80 } |
| 36 } | 81 } |
| 82 } | |
| OLD | NEW |