From 984e6aed3e8c597e8985ea53225f142257037a68 Mon Sep 17 00:00:00 2001 From: ulan Date: Tue, 8 Nov 2016 05:47:16 -0800 Subject: [PATCH] [heap] Remove js call rate heuristic from memory reducer. This is an experiment to check whether the heuristics is still useful. BUG= Review-Url: https://codereview.chromium.org/2482163002 Cr-Commit-Position: refs/heads/master@{#40833} --- src/api.cc | 1 - src/heap/memory-reducer.cc | 20 +++----------------- src/heap/memory-reducer.h | 3 --- src/isolate.cc | 1 - src/isolate.h | 9 --------- test/cctest/heap/test-heap.cc | 24 ------------------------ 6 files changed, 3 insertions(+), 55 deletions(-) diff --git a/src/api.cc b/src/api.cc index a46f0233f3..d3a180cee9 100644 --- a/src/api.cc +++ b/src/api.cc @@ -198,7 +198,6 @@ class CallDepthScope { : isolate_(isolate), context_(context), escaped_(false) { // TODO(dcarney): remove this when blink stops crashing. DCHECK(!isolate_->external_caught_exception()); - isolate_->IncrementJsCallsFromApiCounter(); isolate_->handle_scope_implementer()->IncrementCallDepth(); if (!context.IsEmpty()) { i::Handle env = Utils::OpenHandle(*context); diff --git a/src/heap/memory-reducer.cc b/src/heap/memory-reducer.cc index 22d0b48266..2aed4c714a 100644 --- a/src/heap/memory-reducer.cc +++ b/src/heap/memory-reducer.cc @@ -24,19 +24,16 @@ MemoryReducer::TimerTask::TimerTask(MemoryReducer* memory_reducer) void MemoryReducer::TimerTask::RunInternal() { - const double kJsCallsPerMsThreshold = 0.5; Heap* heap = memory_reducer_->heap(); Event event; double time_ms = heap->MonotonicallyIncreasingTimeInMs(); heap->tracer()->SampleAllocation(time_ms, heap->NewSpaceAllocationCounter(), heap->OldGenerationAllocationCounter()); - double js_call_rate = memory_reducer_->SampleAndGetJsCallsPerMs(time_ms); bool low_allocation_rate = heap->HasLowAllocationRate(); - bool is_idle = js_call_rate < kJsCallsPerMsThreshold && low_allocation_rate; bool optimize_for_memory = heap->ShouldOptimizeForMemoryUsage(); if (FLAG_trace_gc_verbose) { heap->isolate()->PrintWithTimestamp( - "Memory reducer: call rate %.3lf, %s, %s\n", js_call_rate, + "Memory reducer: %s, %s\n", low_allocation_rate ? "low alloc" : "high alloc", optimize_for_memory ? "background" : "foreground"); } @@ -45,7 +42,8 @@ void MemoryReducer::TimerTask::RunInternal() { // The memory reducer will start incremental markig if // 1) mutator is likely idle: js call rate is low and allocation rate is low. // 2) mutator is in background: optimize for memory flag is set. - event.should_start_incremental_gc = is_idle || optimize_for_memory; + event.should_start_incremental_gc = + low_allocation_rate || optimize_for_memory; event.can_start_incremental_gc = heap->incremental_marking()->IsStopped() && (heap->incremental_marking()->CanBeActivated() || optimize_for_memory); @@ -53,16 +51,6 @@ void MemoryReducer::TimerTask::RunInternal() { } -double MemoryReducer::SampleAndGetJsCallsPerMs(double time_ms) { - unsigned int counter = heap()->isolate()->js_calls_from_api_counter(); - unsigned int call_delta = counter - js_calls_counter_; - double time_delta_ms = time_ms - js_calls_sample_time_ms_; - js_calls_counter_ = counter; - js_calls_sample_time_ms_ = time_ms; - return time_delta_ms > 0 ? call_delta / time_delta_ms : 0; -} - - void MemoryReducer::NotifyTimer(const Event& event) { DCHECK_EQ(kTimer, event.type); DCHECK_EQ(kWait, state_.action); @@ -196,8 +184,6 @@ MemoryReducer::State MemoryReducer::Step(const State& state, void MemoryReducer::ScheduleTimer(double time_ms, double delay_ms) { DCHECK(delay_ms > 0); - // Record the time and the js call counter. - SampleAndGetJsCallsPerMs(time_ms); // Leave some room for precision error in task scheduler. const double kSlackMs = 100; v8::Isolate* isolate = reinterpret_cast(heap()->isolate()); diff --git a/src/heap/memory-reducer.h b/src/heap/memory-reducer.h index 4745001b6c..0421987a3c 100644 --- a/src/heap/memory-reducer.h +++ b/src/heap/memory-reducer.h @@ -149,9 +149,6 @@ class V8_EXPORT_PRIVATE MemoryReducer { static bool WatchdogGC(const State& state, const Event& event); - // Returns the rate of JS calls initiated from the API. - double SampleAndGetJsCallsPerMs(double time_ms); - Heap* heap_; State state_; unsigned int js_calls_counter_; diff --git a/src/isolate.cc b/src/isolate.cc index 995b2628be..528c27efe8 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -2120,7 +2120,6 @@ Isolate::Isolate(bool enable_serializer) optimizing_compile_dispatcher_(NULL), stress_deopt_count_(0), next_optimization_id_(0), - js_calls_from_api_counter_(0), #if TRACE_MAPS next_unique_sfi_id_(0), #endif diff --git a/src/isolate.h b/src/isolate.h index 157c3f9021..22888fc7f2 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -1073,12 +1073,6 @@ class Isolate { return id; } - void IncrementJsCallsFromApiCounter() { ++js_calls_from_api_counter_; } - - unsigned int js_calls_from_api_counter() { - return js_calls_from_api_counter_; - } - // Get (and lazily initialize) the registry for per-isolate symbols. Handle GetSymbolRegistry(); @@ -1416,9 +1410,6 @@ class Isolate { int next_optimization_id_; - // Counts javascript calls from the API. Wraps around on overflow. - unsigned int js_calls_from_api_counter_; - #if TRACE_MAPS int next_unique_sfi_id_; #endif diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc index d7dec934e7..e8b8209c0c 100644 --- a/test/cctest/heap/test-heap.cc +++ b/test/cctest/heap/test-heap.cc @@ -6408,30 +6408,6 @@ TEST(Regress519319) { } -HEAP_TEST(TestMemoryReducerSampleJsCalls) { - CcTest::InitializeVM(); - v8::HandleScope scope(CcTest::isolate()); - Heap* heap = CcTest::heap(); - Isolate* isolate = CcTest::i_isolate(); - MemoryReducer* memory_reducer = heap->memory_reducer_; - memory_reducer->SampleAndGetJsCallsPerMs(0); - isolate->IncrementJsCallsFromApiCounter(); - isolate->IncrementJsCallsFromApiCounter(); - isolate->IncrementJsCallsFromApiCounter(); - double calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(1); - CheckDoubleEquals(3, calls_per_ms); - - calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(2); - CheckDoubleEquals(0, calls_per_ms); - - isolate->IncrementJsCallsFromApiCounter(); - isolate->IncrementJsCallsFromApiCounter(); - isolate->IncrementJsCallsFromApiCounter(); - isolate->IncrementJsCallsFromApiCounter(); - calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); - CheckDoubleEquals(2, calls_per_ms); -} - HEAP_TEST(Regress587004) { FLAG_concurrent_sweeping = false; #ifdef VERIFY_HEAP