From 9f73df5910906b3f48c2d6f351bdc971fd54170c Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Wed, 22 Mar 2017 18:04:26 -0700 Subject: [PATCH] deps: cherry-pick 22858cb from V8 upstream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: Only flush not yet started and finished compile jobs from gc We shouldn't block during GC for arbitrarily long intervals. BUG=chromium:686153,chromium:642532 R=verwaest@chromium.org,hpayer@chromium.org Review-Url: https://codereview.chromium.org/2658313002 Cr-Commit-Position: refs/heads/master@{#42761} PR-URL: https://github.com/nodejs/node/pull/11998 Reviewed-By: Ben Noordhuis Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- .../optimizing-compile-dispatcher.cc | 18 +++++++++++++++++- .../optimizing-compile-dispatcher.h | 4 +++- deps/v8/src/debug/debug.cc | 3 ++- deps/v8/src/heap/heap.cc | 9 ++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.cc b/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.cc index 75c50eec7d069c..11695063848721 100644 --- a/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.cc +++ b/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.cc @@ -134,7 +134,23 @@ void OptimizingCompileDispatcher::FlushOutputQueue(bool restore_function_code) { } } -void OptimizingCompileDispatcher::Flush() { +void OptimizingCompileDispatcher::Flush(BlockingBehavior blocking_behavior) { + if (FLAG_block_concurrent_recompilation) Unblock(); + if (blocking_behavior == BlockingBehavior::kDontBlock) { + base::LockGuard access_input_queue_(&input_queue_mutex_); + while (input_queue_length_ > 0) { + CompilationJob* job = input_queue_[InputQueueIndex(0)]; + DCHECK_NOT_NULL(job); + input_queue_shift_ = InputQueueIndex(1); + input_queue_length_--; + DisposeCompilationJob(job, true); + } + FlushOutputQueue(true); + if (FLAG_trace_concurrent_recompilation) { + PrintF(" ** Flushed concurrent recompilation queues (not blocking).\n"); + } + return; + } base::Release_Store(&mode_, static_cast(FLUSH)); if (FLAG_block_concurrent_recompilation) Unblock(); { diff --git a/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.h b/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.h index 8c032ab3202c67..7e081615174236 100644 --- a/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.h +++ b/deps/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.h @@ -22,6 +22,8 @@ class SharedFunctionInfo; class OptimizingCompileDispatcher { public: + enum class BlockingBehavior { kBlock, kDontBlock }; + explicit OptimizingCompileDispatcher(Isolate* isolate) : isolate_(isolate), input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), @@ -38,7 +40,7 @@ class OptimizingCompileDispatcher { void Run(); void Stop(); - void Flush(); + void Flush(BlockingBehavior blocking_behavior); void QueueForOptimization(CompilationJob* job); void Unblock(); void InstallOptimizedFunctions(); diff --git a/deps/v8/src/debug/debug.cc b/deps/v8/src/debug/debug.cc index e93dd3566196f4..bf7f4399a258a1 100644 --- a/deps/v8/src/debug/debug.cc +++ b/deps/v8/src/debug/debug.cc @@ -1264,7 +1264,8 @@ bool Debug::PrepareFunctionForBreakPoints(Handle shared) { DCHECK(shared->is_compiled()); if (isolate_->concurrent_recompilation_enabled()) { - isolate_->optimizing_compile_dispatcher()->Flush(); + isolate_->optimizing_compile_dispatcher()->Flush( + OptimizingCompileDispatcher::BlockingBehavior::kBlock); } List > functions; diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index d823232ac72614..a849345349115b 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -862,7 +862,8 @@ void Heap::CollectAllAvailableGarbage(GarbageCollectionReason gc_reason) { if (isolate()->concurrent_recompilation_enabled()) { // The optimizing compiler may be unnecessarily holding on to memory. DisallowHeapAllocation no_recursive_gc; - isolate()->optimizing_compile_dispatcher()->Flush(); + isolate()->optimizing_compile_dispatcher()->Flush( + OptimizingCompileDispatcher::BlockingBehavior::kDontBlock); } isolate()->ClearSerializerData(); set_current_gc_flags(kMakeHeapIterableMask | kReduceMemoryFootprintMask); @@ -1056,7 +1057,8 @@ int Heap::NotifyContextDisposed(bool dependant_context) { } if (isolate()->concurrent_recompilation_enabled()) { // Flush the queued recompilation tasks. - isolate()->optimizing_compile_dispatcher()->Flush(); + isolate()->optimizing_compile_dispatcher()->Flush( + OptimizingCompileDispatcher::BlockingBehavior::kDontBlock); } AgeInlineCaches(); number_of_disposed_maps_ = retained_maps()->Length(); @@ -4457,7 +4459,8 @@ void Heap::CheckMemoryPressure() { if (isolate()->concurrent_recompilation_enabled()) { // The optimizing compiler may be unnecessarily holding on to memory. DisallowHeapAllocation no_recursive_gc; - isolate()->optimizing_compile_dispatcher()->Flush(); + isolate()->optimizing_compile_dispatcher()->Flush( + OptimizingCompileDispatcher::BlockingBehavior::kDontBlock); } } if (memory_pressure_level_.Value() == MemoryPressureLevel::kCritical) {