Index: src/heap/heap.cc |
diff --git a/src/heap/heap.cc b/src/heap/heap.cc |
index fd08c8292f812c8c3084fb699eb9f65dcc98b4a7..40ff03f49c9b98c5ce61bc4fff8161ead6d09426 100644 |
--- a/src/heap/heap.cc |
+++ b/src/heap/heap.cc |
@@ -4259,7 +4259,26 @@ void Heap::MakeHeapIterable() { |
} |
-void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) { |
+intptr_t Heap::EstimateMarkingStepSize(int idle_time_in_ms) { |
+ // We have to make sure that we finish the IdleNotification before |
+ // idle_time_in_ms. Hence, we conservatively prune our workload estimate. |
+ const double kConservativeTimeRatio = 0.9; |
+ // If we haven't recorded any incremental marking events yet, we carefully |
+ // mark with a conservative lower bound for the marking speed. |
+ const intptr_t kMarkingSpeedInBytesLowerBound = 100 * KB; |
+ intptr_t marking_speed_in_bytes_per_millisecond = |
+ tracer_.IncrementalMarkingSpeedInBytesPerMillisecond(); |
+ if (marking_speed_in_bytes_per_millisecond == 0) { |
+ marking_speed_in_bytes_per_millisecond = kMarkingSpeedInBytesLowerBound; |
+ } |
+ return static_cast<intptr_t>(marking_speed_in_bytes_per_millisecond * |
ulan
2014/08/18 12:32:13
Potential integer overflow here, maybe use marking
Hannes Payer (out of office)
2014/08/19 15:24:04
Good catch.
|
+ kConservativeTimeRatio * idle_time_in_ms); |
+} |
+ |
+ |
+void Heap::AdvanceIdleIncrementalMarking(int idle_time_in_ms) { |
+ intptr_t step_size = EstimateMarkingStepSize(idle_time_in_ms); |
+ |
incremental_marking()->Step(step_size, |
IncrementalMarking::NO_GC_VIA_STACK_GUARD, true); |
@@ -4282,36 +4301,27 @@ void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) { |
} |
-bool Heap::IdleNotification(int hint) { |
+bool Heap::IdleNotification(int idle_time_in_ms) { |
// If incremental marking is off, we do not perform idle notification. |
if (!FLAG_incremental_marking) return true; |
- // Hints greater than this value indicate that |
- // the embedder is requesting a lot of GC work. |
- const int kMaxHint = 1000; |
- const int kMinHintForIncrementalMarking = 10; |
// Minimal hint that allows to do full GC. |
const int kMinHintForFullGC = 100; |
- intptr_t size_factor = Min(Max(hint, 20), kMaxHint) / 4; |
- // The size factor is in range [5..250]. The numbers here are chosen from |
- // experiments. If you changes them, make sure to test with |
- // chrome/performance_ui_tests --gtest_filter="GeneralMixMemoryTest.* |
- intptr_t step_size = size_factor * IncrementalMarking::kAllocatedThreshold; |
- |
- isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample(hint); |
+ isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample( |
+ idle_time_in_ms); |
HistogramTimerScope idle_notification_scope( |
isolate_->counters()->gc_idle_notification()); |
if (contexts_disposed_ > 0) { |
contexts_disposed_ = 0; |
int mark_sweep_time = Min(TimeMarkSweepWouldTakeInMs(), 1000); |
- if (hint >= mark_sweep_time && !FLAG_expose_gc && |
+ if (idle_time_in_ms >= mark_sweep_time && !FLAG_expose_gc && |
incremental_marking()->IsStopped()) { |
HistogramTimerScope scope(isolate_->counters()->gc_context()); |
CollectAllGarbage(kReduceMemoryFootprintMask, |
"idle notification: contexts disposed"); |
} else { |
- AdvanceIdleIncrementalMarking(step_size); |
+ AdvanceIdleIncrementalMarking(idle_time_in_ms); |
} |
// After context disposal there is likely a lot of garbage remaining, reset |
@@ -4346,17 +4356,16 @@ bool Heap::IdleNotification(int hint) { |
// the code space. |
// TODO(ulan): Once we enable code compaction for incremental marking, |
// we can get rid of this special case and always start incremental marking. |
- if (remaining_mark_sweeps <= 2 && hint >= kMinHintForFullGC) { |
+ if (remaining_mark_sweeps <= 2 && idle_time_in_ms >= kMinHintForFullGC) { |
CollectAllGarbage(kReduceMemoryFootprintMask, |
"idle notification: finalize idle round"); |
mark_sweeps_since_idle_round_started_++; |
- } else if (hint > kMinHintForIncrementalMarking) { |
+ } else { |
incremental_marking()->Start(); |
} |
} |
- if (!incremental_marking()->IsStopped() && |
- hint > kMinHintForIncrementalMarking) { |
- AdvanceIdleIncrementalMarking(step_size); |
+ if (!incremental_marking()->IsStopped()) { |
+ AdvanceIdleIncrementalMarking(idle_time_in_ms); |
} |
if (mark_sweeps_since_idle_round_started_ >= kMaxMarkSweepsInIdleRound) { |
@@ -4366,7 +4375,7 @@ bool Heap::IdleNotification(int hint) { |
// If the IdleNotifcation is called with a large hint we will wait for |
// the sweepter threads here. |
- if (hint >= kMinHintForFullGC && |
+ if (idle_time_in_ms >= kMinHintForFullGC && |
mark_compact_collector()->sweeping_in_progress()) { |
mark_compact_collector()->EnsureSweepingCompleted(); |
} |