Commit c4081d25 authored by yangguo's avatar yangguo Committed by Commit bot

Revert of Remove support for thread-based recompilation (patchset #1 id:1 of...

Revert of Remove support for thread-based recompilation (patchset #1 id:1 of https://codereview.chromium.org/966653002/)

Reason for revert:
speculative revert due to gc-stress timeouts.

Original issue's description:
> Remove support for thread-based recompilation
>
> BUG=v8:3608
> R=yangguo@chromium.org
> LOG=y
>
> Committed: https://crrev.com/ed5db223a19dfe126af012e894582251aa3635d7
> Cr-Commit-Position: refs/heads/master@{#27619}

TBR=jochen@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
BUG=v8:3608
LOG=N

Review URL: https://codereview.chromium.org/1063383004

Cr-Commit-Position: refs/heads/master@{#27654}
parent a54f22d4
......@@ -892,8 +892,8 @@ source_set("v8_base") {
"src/objects-printer.cc",
"src/objects.cc",
"src/objects.h",
"src/optimizing-compile-dispatcher.cc",
"src/optimizing-compile-dispatcher.h",
"src/optimizing-compiler-thread.cc",
"src/optimizing-compiler-thread.h",
"src/ostreams.cc",
"src/ostreams.h",
"src/parser.cc",
......
......@@ -819,7 +819,7 @@ static bool GetOptimizedCodeNow(CompilationInfo* info) {
static bool GetOptimizedCodeLater(CompilationInfo* info) {
Isolate* isolate = info->isolate();
if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) {
if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) {
if (FLAG_trace_concurrent_recompilation) {
PrintF(" ** Compilation queue full, will retry optimizing ");
info->closure()->ShortPrint();
......@@ -840,7 +840,7 @@ static bool GetOptimizedCodeLater(CompilationInfo* info) {
OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info);
OptimizedCompileJob::Status status = job->CreateGraph();
if (status != OptimizedCompileJob::SUCCEEDED) return false;
isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
isolate->optimizing_compiler_thread()->QueueForOptimization(job);
if (FLAG_trace_concurrent_recompilation) {
PrintF(" ** Queued ");
......
......@@ -372,10 +372,12 @@ class CompilationInfo {
}
void AbortDueToDependencyChange() {
DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate()));
aborted_due_to_dependency_change_ = true;
}
bool HasAbortedDueToDependencyChange() const {
DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate()));
return aborted_due_to_dependency_change_;
}
......
......@@ -11,7 +11,7 @@
#include "src/circular-queue.h"
#include "src/compiler.h"
#include "src/sampler.h"
#include "src/unbound-queue-inl.h"
#include "src/unbound-queue.h"
namespace v8 {
namespace internal {
......
......@@ -1842,7 +1842,7 @@ void Debug::PrepareForBreakPoints() {
// functions as debugging does not work with optimized code.
if (!has_break_points_) {
if (isolate_->concurrent_recompilation_enabled()) {
isolate_->optimizing_compile_dispatcher()->Flush();
isolate_->optimizing_compiler_thread()->Flush();
}
Deoptimizer::DeoptimizeAll(isolate_);
......
......@@ -677,7 +677,7 @@ Object* StackGuard::HandleInterrupts() {
if (CheckAndClearInterrupt(INSTALL_CODE)) {
DCHECK(isolate_->concurrent_recompilation_enabled());
isolate_->optimizing_compile_dispatcher()->InstallOptimizedFunctions();
isolate_->optimizing_compiler_thread()->InstallOptimizedFunctions();
}
if (CheckAndClearInterrupt(API_INTERRUPT)) {
......
......@@ -363,6 +363,9 @@ DEFINE_BOOL(optimize_for_in, true, "optimize functions containing for-in loops")
DEFINE_BOOL(concurrent_recompilation, true,
"optimizing hot functions asynchronously on a separate thread")
DEFINE_BOOL(job_based_recompilation, true,
"post tasks to v8::Platform instead of using a thread for "
"concurrent recompilation")
DEFINE_BOOL(trace_concurrent_recompilation, false,
"track concurrent recompilation")
DEFINE_INT(concurrent_recompilation_queue_length, 8,
......
......@@ -441,7 +441,7 @@ void Heap::GarbageCollectionPrologue() {
store_buffer()->GCPrologue();
if (isolate()->concurrent_osr_enabled()) {
isolate()->optimizing_compile_dispatcher()->AgeBufferedOsrJobs();
isolate()->optimizing_compiler_thread()->AgeBufferedOsrJobs();
}
if (new_space_.IsAtMaximumCapacity()) {
......@@ -784,7 +784,7 @@ void Heap::CollectAllAvailableGarbage(const char* 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_compiler_thread()->Flush();
}
isolate()->ClearSerializerData();
mark_compact_collector()->SetFlags(kMakeHeapIterableMask |
......@@ -902,7 +902,7 @@ int Heap::NotifyContextDisposed(bool dependant_context) {
}
if (isolate()->concurrent_recompilation_enabled()) {
// Flush the queued recompilation tasks.
isolate()->optimizing_compile_dispatcher()->Flush();
isolate()->optimizing_compiler_thread()->Flush();
}
AgeInlineCaches();
set_retained_maps(ArrayList::cast(empty_fixed_array()));
......
......@@ -3473,6 +3473,7 @@ HBasicBlock* HGraph::CreateBasicBlock() {
void HGraph::FinalizeUniqueness() {
DisallowHeapAllocation no_gc;
DCHECK(!OptimizingCompilerThread::IsOptimizerThread(isolate()));
for (int i = 0; i < blocks()->length(); ++i) {
for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) {
it.Current()->FinalizeUniqueness();
......
......@@ -1736,7 +1736,7 @@ Isolate::Isolate(bool enable_serializer)
heap_profiler_(NULL),
function_entry_hook_(NULL),
deferred_handles_head_(NULL),
optimizing_compile_dispatcher_(NULL),
optimizing_compiler_thread_(NULL),
stress_deopt_count_(0),
next_optimization_id_(0),
#if TRACE_MAPS
......@@ -1833,9 +1833,9 @@ void Isolate::Deinit() {
FreeThreadResources();
if (concurrent_recompilation_enabled()) {
optimizing_compile_dispatcher_->Stop();
delete optimizing_compile_dispatcher_;
optimizing_compile_dispatcher_ = NULL;
optimizing_compiler_thread_->Stop();
delete optimizing_compiler_thread_;
optimizing_compiler_thread_ = NULL;
}
if (heap_.mark_compact_collector()->sweeping_in_progress()) {
......@@ -2133,8 +2133,9 @@ bool Isolate::Init(Deserializer* des) {
if (FLAG_trace_hydrogen || FLAG_trace_hydrogen_stubs) {
PrintF("Concurrent recompilation has been disabled for tracing.\n");
} else if (OptimizingCompileDispatcher::Enabled(max_available_threads_)) {
optimizing_compile_dispatcher_ = new OptimizingCompileDispatcher(this);
} else if (OptimizingCompilerThread::Enabled(max_available_threads_)) {
optimizing_compiler_thread_ = new OptimizingCompilerThread(this);
optimizing_compiler_thread_->Start();
}
// Initialize runtime profiler before deserialization, because collections may
......
......@@ -19,7 +19,7 @@
#include "src/handles.h"
#include "src/hashmap.h"
#include "src/heap/heap.h"
#include "src/optimizing-compile-dispatcher.h"
#include "src/optimizing-compiler-thread.h"
#include "src/regexp-stack.h"
#include "src/runtime/runtime.h"
#include "src/runtime-profiler.h"
......@@ -1028,20 +1028,20 @@ class Isolate {
bool concurrent_recompilation_enabled() {
// Thread is only available with flag enabled.
DCHECK(optimizing_compile_dispatcher_ == NULL ||
DCHECK(optimizing_compiler_thread_ == NULL ||
FLAG_concurrent_recompilation);
return optimizing_compile_dispatcher_ != NULL;
return optimizing_compiler_thread_ != NULL;
}
bool concurrent_osr_enabled() const {
// Thread is only available with flag enabled.
DCHECK(optimizing_compile_dispatcher_ == NULL ||
DCHECK(optimizing_compiler_thread_ == NULL ||
FLAG_concurrent_recompilation);
return optimizing_compile_dispatcher_ != NULL && FLAG_concurrent_osr;
return optimizing_compiler_thread_ != NULL && FLAG_concurrent_osr;
}
OptimizingCompileDispatcher* optimizing_compile_dispatcher() {
return optimizing_compile_dispatcher_;
OptimizingCompilerThread* optimizing_compiler_thread() {
return optimizing_compiler_thread_;
}
int id() const { return static_cast<int>(id_); }
......@@ -1329,7 +1329,7 @@ class Isolate {
#endif
DeferredHandles* deferred_handles_head_;
OptimizingCompileDispatcher* optimizing_compile_dispatcher_;
OptimizingCompilerThread* optimizing_compiler_thread_;
// Counts deopt points if deopt_every_n_times is enabled.
unsigned int stress_deopt_count_;
......@@ -1350,7 +1350,7 @@ class Isolate {
friend class ExecutionAccess;
friend class HandleScopeImplementer;
friend class OptimizingCompileDispatcher;
friend class OptimizingCompilerThread;
friend class SweeperThread;
friend class ThreadManager;
friend class Simulator;
......
......@@ -9706,7 +9706,7 @@ void JSFunction::AttemptConcurrentOptimization() {
return;
}
if (isolate->concurrent_osr_enabled() &&
isolate->optimizing_compile_dispatcher()->IsQueuedForOSR(this)) {
isolate->optimizing_compiler_thread()->IsQueuedForOSR(this)) {
// Do not attempt regular recompilation if we already queued this for OSR.
// TODO(yangguo): This is necessary so that we don't install optimized
// code on a function that is already optimized, since OSR and regular
......
......@@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OPTIMIZING_COMPILE_DISPATCHER_H_
#define V8_OPTIMIZING_COMPILE_DISPATCHER_H_
#include <queue>
#ifndef V8_OPTIMIZING_COMPILER_THREAD_H_
#define V8_OPTIMIZING_COMPILER_THREAD_H_
#include "src/base/atomicops.h"
#include "src/base/platform/condition-variable.h"
#include "src/base/platform/mutex.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/flags.h"
#include "src/list.h"
#include "src/unbound-queue-inl.h"
namespace v8 {
namespace internal {
......@@ -21,10 +21,16 @@ class HOptimizedGraphBuilder;
class OptimizedCompileJob;
class SharedFunctionInfo;
class OptimizingCompileDispatcher {
class OptimizingCompilerThread : public base::Thread {
public:
explicit OptimizingCompileDispatcher(Isolate* isolate)
: isolate_(isolate),
explicit OptimizingCompilerThread(Isolate* isolate)
: Thread(Options("OptimizingCompilerThread")),
#ifdef DEBUG
thread_id_(0),
#endif
isolate_(isolate),
stop_semaphore_(0),
input_queue_semaphore_(0),
input_queue_capacity_(FLAG_concurrent_recompilation_queue_length),
input_queue_length_(0),
input_queue_shift_(0),
......@@ -34,8 +40,11 @@ class OptimizingCompileDispatcher {
osr_attempts_(0),
blocked_jobs_(0),
ref_count_(0),
tracing_enabled_(FLAG_trace_concurrent_recompilation),
job_based_recompilation_(FLAG_job_based_recompilation),
recompilation_delay_(FLAG_concurrent_recompilation_delay) {
base::NoBarrier_Store(&mode_, static_cast<base::AtomicWord>(COMPILE));
base::NoBarrier_Store(&stop_thread_,
static_cast<base::AtomicWord>(CONTINUE));
input_queue_ = NewArray<OptimizedCompileJob*>(input_queue_capacity_);
if (FLAG_concurrent_osr) {
// Allocate and mark OSR buffer slots as empty.
......@@ -44,7 +53,7 @@ class OptimizingCompileDispatcher {
}
}
~OptimizingCompileDispatcher();
~OptimizingCompilerThread();
void Run();
void Stop();
......@@ -74,11 +83,17 @@ class OptimizingCompileDispatcher {
return (FLAG_concurrent_recompilation && max_available > 1);
}
#ifdef DEBUG
static bool IsOptimizerThread(Isolate* isolate);
bool IsOptimizerThread();
#endif
private:
class CompileTask;
enum ModeFlag { COMPILE, FLUSH };
enum StopFlag { CONTINUE, STOP, FLUSH };
void FlushInputQueue(bool restore_function_code);
void FlushOutputQueue(bool restore_function_code);
void FlushOsrBuffer(bool restore_function_code);
void CompileNext(OptimizedCompileJob* job);
......@@ -95,7 +110,14 @@ class OptimizingCompileDispatcher {
return result;
}
#ifdef DEBUG
int thread_id_;
base::Mutex thread_id_mutex_;
#endif
Isolate* isolate_;
base::Semaphore stop_semaphore_;
base::Semaphore input_queue_semaphore_;
// Circular queue of incoming recompilation tasks (including OSR).
OptimizedCompileJob** input_queue_;
......@@ -105,7 +127,7 @@ class OptimizingCompileDispatcher {
base::Mutex input_queue_mutex_;
// Queue of recompilation tasks ready to be installed (excluding OSR).
std::queue<OptimizedCompileJob*> output_queue_;
UnboundQueue<OptimizedCompileJob*> output_queue_;
// Used for job based recompilation which has multiple producers on
// different threads.
base::Mutex output_queue_mutex_;
......@@ -115,7 +137,9 @@ class OptimizingCompileDispatcher {
int osr_buffer_capacity_;
int osr_buffer_cursor_;
volatile base::AtomicWord mode_;
volatile base::AtomicWord stop_thread_;
base::TimeDelta time_spent_compiling_;
base::TimeDelta time_spent_total_;
int osr_hits_;
int osr_attempts_;
......@@ -126,14 +150,17 @@ class OptimizingCompileDispatcher {
base::Mutex ref_count_mutex_;
base::ConditionVariable ref_count_zero_;
// Copy of FLAG_concurrent_recompilation_delay that will be used from the
// background thread.
// Copies of FLAG_trace_concurrent_recompilation,
// FLAG_concurrent_recompilation_delay and
// FLAG_job_based_recompilation that will be used from the background thread.
//
// Since flags might get modified while the background thread is running, it
// is not safe to access them directly.
bool tracing_enabled_;
bool job_based_recompilation_;
int recompilation_delay_;
};
}
} // namespace v8::internal
#endif // V8_OPTIMIZING_COMPILE_DISPATCHER_H_
} } // namespace v8::internal
#endif // V8_OPTIMIZING_COMPILER_THREAD_H_
......@@ -232,8 +232,7 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
// Gate the OSR entry with a stack check.
BackEdgeTable::AddStackCheck(caller_code, pc_offset);
// Poll already queued compilation jobs.
OptimizingCompileDispatcher* thread =
isolate->optimizing_compile_dispatcher();
OptimizingCompilerThread* thread = isolate->optimizing_compiler_thread();
if (thread->IsQueuedForOSR(function, ast_id)) {
if (FLAG_trace_osr) {
PrintF("[OSR - Still waiting for queued: ");
......@@ -325,7 +324,7 @@ RUNTIME_FUNCTION(Runtime_TryInstallOptimizedCode) {
return isolate->StackOverflow();
}
isolate->optimizing_compile_dispatcher()->InstallOptimizedFunctions();
isolate->optimizing_compiler_thread()->InstallOptimizedFunctions();
return (function->IsOptimized()) ? function->code()
: function->shared()->code();
}
......
......@@ -175,7 +175,7 @@ RUNTIME_FUNCTION(Runtime_GetOptimizationStatus) {
if (isolate->concurrent_recompilation_enabled() &&
sync_with_compiler_thread) {
while (function->IsInOptimizationQueue()) {
isolate->optimizing_compile_dispatcher()->InstallOptimizedFunctions();
isolate->optimizing_compiler_thread()->InstallOptimizedFunctions();
base::OS::Sleep(50);
}
}
......@@ -200,7 +200,7 @@ RUNTIME_FUNCTION(Runtime_UnblockConcurrentRecompilation) {
DCHECK(args.length() == 0);
RUNTIME_ASSERT(FLAG_block_concurrent_recompilation);
RUNTIME_ASSERT(isolate->concurrent_recompilation_enabled());
isolate->optimizing_compile_dispatcher()->Unblock();
isolate->optimizing_compiler_thread()->Unblock();
return isolate->heap()->undefined_value();
}
......
......@@ -780,8 +780,8 @@
'../../src/objects-printer.cc',
'../../src/objects.cc',
'../../src/objects.h',
'../../src/optimizing-compile-dispatcher.cc',
'../../src/optimizing-compile-dispatcher.h',
'../../src/optimizing-compiler-thread.cc',
'../../src/optimizing-compiler-thread.h',
'../../src/ostreams.cc',
'../../src/ostreams.h',
'../../src/parser.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment