From 292a4b04c93db0e221ed73b91a2758ba2b8e59d6 Mon Sep 17 00:00:00 2001 From: hpayer Date: Wed, 20 May 2015 06:07:57 -0700 Subject: [PATCH] Move code around in IdleNotification. BUG= Review URL: https://codereview.chromium.org/1149593002 Cr-Commit-Position: refs/heads/master@{#28513} --- src/heap/heap.cc | 117 ++++++++++++++++++++++++++++++++++--------------------- src/heap/heap.h | 12 ++++++ 2 files changed, 84 insertions(+), 45 deletions(-) diff --git a/src/heap/heap.cc b/src/heap/heap.cc index e66ae93..62c3821 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -4587,35 +4587,7 @@ bool Heap::TryFinalizeIdleIncrementalMarking( } -double Heap::MonotonicallyIncreasingTimeInMs() { - return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * - static_cast(base::Time::kMillisecondsPerSecond); -} - - -bool Heap::IdleNotification(int idle_time_in_ms) { - return IdleNotification( - V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + - (static_cast(idle_time_in_ms) / - static_cast(base::Time::kMillisecondsPerSecond))); -} - - -bool Heap::IdleNotification(double deadline_in_seconds) { - CHECK(HasBeenSetUp()); // http://crbug.com/425035 - double deadline_in_ms = - deadline_in_seconds * - static_cast(base::Time::kMillisecondsPerSecond); - HistogramTimerScope idle_notification_scope( - isolate_->counters()->gc_idle_notification()); - double start_ms = MonotonicallyIncreasingTimeInMs(); - double idle_time_in_ms = deadline_in_ms - start_ms; - bool is_long_idle_notification = - static_cast(idle_time_in_ms) > - GCIdleTimeHandler::kMaxFrameRenderingIdleTime; - - static const double kLastGCTimeTreshold = 1000; - +GCIdleTimeHandler::HeapState Heap::ComputeHeapState(bool reduce_memory) { GCIdleTimeHandler::HeapState heap_state; heap_state.contexts_disposed = contexts_disposed_; heap_state.contexts_disposal_rate = @@ -4624,8 +4596,7 @@ bool Heap::IdleNotification(double deadline_in_seconds) { heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); // TODO(ulan): Start incremental marking only for large heaps. intptr_t limit = old_generation_allocation_limit_; - if (is_long_idle_notification && - (start_ms - last_gc_time_ > kLastGCTimeTreshold)) { + if (reduce_memory) { limit = idle_old_generation_allocation_limit_; } @@ -4651,21 +4622,14 @@ bool Heap::IdleNotification(double deadline_in_seconds) { heap_state.new_space_allocation_throughput_in_bytes_per_ms = static_cast( tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); + return heap_state; +} - GCIdleTimeAction action = - gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state); - - isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample( - static_cast(idle_time_in_ms)); - if (is_long_idle_notification) { - int committed_memory = static_cast(CommittedMemory() / KB); - int used_memory = static_cast(heap_state.size_of_objects / KB); - isolate()->counters()->aggregated_memory_heap_committed()->AddSample( - start_ms, committed_memory); - isolate()->counters()->aggregated_memory_heap_used()->AddSample( - start_ms, used_memory); - } +bool Heap::PerformIdleTimeAction(GCIdleTimeAction action, + GCIdleTimeHandler::HeapState heap_state, + double deadline_in_ms, + bool is_long_idle_notification) { bool result = false; switch (action.type) { case DONE: @@ -4724,11 +4688,33 @@ bool Heap::IdleNotification(double deadline_in_seconds) { new_space_.Shrink(); UncommitFromSpace(); } + return result; +} + +void Heap::IdleNotificationEpilogue(GCIdleTimeAction action, + GCIdleTimeHandler::HeapState heap_state, + double start_ms, double deadline_in_ms, + bool is_long_idle_notification) { + double idle_time_in_ms = deadline_in_ms - start_ms; double current_time = MonotonicallyIncreasingTimeInMs(); last_idle_notification_time_ = current_time; double deadline_difference = deadline_in_ms - current_time; + contexts_disposed_ = 0; + + isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample( + static_cast(idle_time_in_ms)); + + if (is_long_idle_notification) { + int committed_memory = static_cast(CommittedMemory() / KB); + int used_memory = static_cast(heap_state.size_of_objects / KB); + isolate()->counters()->aggregated_memory_heap_committed()->AddSample( + start_ms, committed_memory); + isolate()->counters()->aggregated_memory_heap_used()->AddSample( + start_ms, used_memory); + } + if (deadline_difference >= 0) { if (action.type != DONE && action.type != DO_NOTHING) { isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( @@ -4756,8 +4742,49 @@ bool Heap::IdleNotification(double deadline_in_seconds) { } PrintF("\n"); } +} - contexts_disposed_ = 0; + +double Heap::MonotonicallyIncreasingTimeInMs() { + return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * + static_cast(base::Time::kMillisecondsPerSecond); +} + + +bool Heap::IdleNotification(int idle_time_in_ms) { + return IdleNotification( + V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + + (static_cast(idle_time_in_ms) / + static_cast(base::Time::kMillisecondsPerSecond))); +} + + +bool Heap::IdleNotification(double deadline_in_seconds) { + CHECK(HasBeenSetUp()); + static const double kLastGCTimeTreshold = 1000; + double deadline_in_ms = + deadline_in_seconds * + static_cast(base::Time::kMillisecondsPerSecond); + HistogramTimerScope idle_notification_scope( + isolate_->counters()->gc_idle_notification()); + double start_ms = MonotonicallyIncreasingTimeInMs(); + double idle_time_in_ms = deadline_in_ms - start_ms; + bool is_long_idle_notification = + static_cast(idle_time_in_ms) > + GCIdleTimeHandler::kMaxFrameRenderingIdleTime; + bool has_low_gc_activity = (start_ms - last_gc_time_) > kLastGCTimeTreshold; + + GCIdleTimeHandler::HeapState heap_state = + ComputeHeapState(is_long_idle_notification && has_low_gc_activity); + + GCIdleTimeAction action = + gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state); + + bool result = PerformIdleTimeAction(action, heap_state, deadline_in_ms, + is_long_idle_notification); + + IdleNotificationEpilogue(action, heap_state, start_ms, deadline_in_ms, + is_long_idle_notification); return result; } diff --git a/src/heap/heap.h b/src/heap/heap.h index f460b55..4535bbb 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -2118,6 +2118,18 @@ class Heap { double idle_time_in_ms, size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); + GCIdleTimeHandler::HeapState ComputeHeapState(bool reduce_memory); + + bool PerformIdleTimeAction(GCIdleTimeAction action, + GCIdleTimeHandler::HeapState heap_state, + double deadline_in_ms, + bool is_long_idle_notification); + + void IdleNotificationEpilogue(GCIdleTimeAction action, + GCIdleTimeHandler::HeapState heap_state, + double start_ms, double deadline_in_ms, + bool is_long_idle_notification); + void ClearObjectStats(bool clear_last_time_stats = false); inline void UpdateAllocationsHash(HeapObject* object); -- 2.7.4