Commit ce65e105 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

Revert of [Interpreter] Introduce InterpreterCompilationJob (patchset #7...

Revert of [Interpreter] Introduce InterpreterCompilationJob (patchset #7 id:140001 of https://codereview.chromium.org/2240463002/ )

Reason for revert:
Failing on Win64 bot:
https://build.chromium.org/p/client.v8/builders/V8%20Win64/builds/12061/steps/Check/logs/regress-635429

Original issue's description:
> [Interpreter] Introduce InterpreterCompilationJob
>
> Adds InterpreterCompilationJob as a sub-class of
> CompilationJob, to enable off-thread bytecode
> generation. Currently only used in
> Interpreter::MakeBytecode.
>
> As part of this change, CompilationJob is modified
> to make it less specific to optimized compilation,
> renaming the phases as follows:
>  - CreateGraph -> PrepareJob
>  - OptimizeGraph -> ExecuteJob
>  - GenerateCode -> FinalizeJob
>
> RegisterWeakObjectsInOptimizedCode is also moved out
> of CompilationJob and instead becomes a static function
> on Compiler.
>
> BUG=v8:5203
>
> Committed: https://crrev.com/1fb6a7e697e8bc5b4af51647553741f966e00cdc
> Cr-Commit-Position: refs/heads/master@{#38662}

TBR=mstarzinger@chromium.org,jkummerow@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203

Review-Url: https://codereview.chromium.org/2249153002
Cr-Commit-Position: refs/heads/master@{#38663}
parent 1fb6a7e6
...@@ -107,7 +107,7 @@ void OptimizingCompileDispatcher::CompileNext(CompilationJob* job) { ...@@ -107,7 +107,7 @@ void OptimizingCompileDispatcher::CompileNext(CompilationJob* job) {
if (!job) return; if (!job) return;
// The function may have already been optimized by OSR. Simply continue. // The function may have already been optimized by OSR. Simply continue.
CompilationJob::Status status = job->ExecuteJob(); CompilationJob::Status status = job->OptimizeGraph();
USE(status); // Prevent an unused-variable error. USE(status); // Prevent an unused-variable error.
// The function may have already been optimized by OSR. Simply continue. // The function may have already been optimized by OSR. Simply continue.
......
...@@ -240,11 +240,11 @@ bool CompilationInfo::ExpectsJSReceiverAsReceiver() { ...@@ -240,11 +240,11 @@ bool CompilationInfo::ExpectsJSReceiverAsReceiver() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of CompilationJob // Implementation of CompilationJob
CompilationJob::Status CompilationJob::PrepareJob() { CompilationJob::Status CompilationJob::CreateGraph() {
DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id()));
DisallowJavascriptExecution no_js(isolate()); DisallowJavascriptExecution no_js(isolate());
DCHECK(info()->IsOptimizing());
if (FLAG_trace_opt && info()->IsOptimizing()) { if (FLAG_trace_opt) {
OFStream os(stdout); OFStream os(stdout);
os << "[compiling method " << Brief(*info()->closure()) << " using " os << "[compiling method " << Brief(*info()->closure()) << " using "
<< compiler_name_; << compiler_name_;
...@@ -253,69 +253,34 @@ CompilationJob::Status CompilationJob::PrepareJob() { ...@@ -253,69 +253,34 @@ CompilationJob::Status CompilationJob::PrepareJob() {
} }
// Delegate to the underlying implementation. // Delegate to the underlying implementation.
DCHECK(state() == State::kReadyToPrepare); DCHECK_EQ(SUCCEEDED, last_status());
ScopedTimer t(&time_taken_to_prepare_); ScopedTimer t(&time_taken_to_create_graph_);
return UpdateState(PrepareJobImpl(), State::kReadyToExecute); return SetLastStatus(CreateGraphImpl());
} }
CompilationJob::Status CompilationJob::ExecuteJob() { CompilationJob::Status CompilationJob::OptimizeGraph() {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
DisallowHandleAllocation no_handles; DisallowHandleAllocation no_handles;
DisallowHandleDereference no_deref; DisallowHandleDereference no_deref;
DisallowCodeDependencyChange no_dependency_change; DisallowCodeDependencyChange no_dependency_change;
// Delegate to the underlying implementation. // Delegate to the underlying implementation.
DCHECK(state() == State::kReadyToExecute); DCHECK_EQ(SUCCEEDED, last_status());
ScopedTimer t(&time_taken_to_execute_); ScopedTimer t(&time_taken_to_optimize_);
return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize); return SetLastStatus(OptimizeGraphImpl());
} }
CompilationJob::Status CompilationJob::FinalizeJob() { CompilationJob::Status CompilationJob::GenerateCode() {
DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id()));
DisallowCodeDependencyChange no_dependency_change; DisallowCodeDependencyChange no_dependency_change;
DisallowJavascriptExecution no_js(isolate()); DisallowJavascriptExecution no_js(isolate());
DCHECK(!info()->dependencies()->HasAborted()); DCHECK(!info()->dependencies()->HasAborted());
// Delegate to the underlying implementation. // Delegate to the underlying implementation.
DCHECK(state() == State::kReadyToFinalize); DCHECK_EQ(SUCCEEDED, last_status());
ScopedTimer t(&time_taken_to_finalize_); ScopedTimer t(&time_taken_to_codegen_);
return UpdateState(FinalizeJobImpl(), State::kSucceeded); return SetLastStatus(GenerateCodeImpl());
} }
void CompilationJob::RecordOptimizationStats() {
DCHECK(info()->IsOptimizing());
Handle<JSFunction> function = info()->closure();
if (!function->IsOptimized()) {
// Concurrent recompilation and OSR may race. Increment only once.
int opt_count = function->shared()->opt_count();
function->shared()->set_opt_count(opt_count + 1);
}
double ms_creategraph = time_taken_to_prepare_.InMillisecondsF();
double ms_optimize = time_taken_to_execute_.InMillisecondsF();
double ms_codegen = time_taken_to_finalize_.InMillisecondsF();
if (FLAG_trace_opt) {
PrintF("[optimizing ");
function->ShortPrint();
PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize,
ms_codegen);
}
if (FLAG_trace_opt_stats) {
static double compilation_time = 0.0;
static int compiled_functions = 0;
static int code_size = 0;
compilation_time += (ms_creategraph + ms_optimize + ms_codegen);
compiled_functions++;
code_size += function->shared()->SourceSize();
PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
compiled_functions, code_size, compilation_time);
}
if (FLAG_hydrogen_stats) {
isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_prepare_,
time_taken_to_execute_,
time_taken_to_finalize_);
}
}
namespace { namespace {
...@@ -335,7 +300,6 @@ void AddWeakObjectToCodeDependency(Isolate* isolate, Handle<HeapObject> object, ...@@ -335,7 +300,6 @@ void AddWeakObjectToCodeDependency(Isolate* isolate, Handle<HeapObject> object,
} // namespace } // namespace
// static
void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) { void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
// TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies.
Isolate* const isolate = code->GetIsolate(); Isolate* const isolate = code->GetIsolate();
...@@ -376,6 +340,42 @@ void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) { ...@@ -376,6 +340,42 @@ void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
code->set_can_have_weak_objects(true); code->set_can_have_weak_objects(true);
} }
void CompilationJob::RecordOptimizationStats() {
Handle<JSFunction> function = info()->closure();
if (!function->IsOptimized()) {
// Concurrent recompilation and OSR may race. Increment only once.
int opt_count = function->shared()->opt_count();
function->shared()->set_opt_count(opt_count + 1);
}
double ms_creategraph = time_taken_to_create_graph_.InMillisecondsF();
double ms_optimize = time_taken_to_optimize_.InMillisecondsF();
double ms_codegen = time_taken_to_codegen_.InMillisecondsF();
if (FLAG_trace_opt) {
PrintF("[optimizing ");
function->ShortPrint();
PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize,
ms_codegen);
}
if (FLAG_trace_opt_stats) {
static double compilation_time = 0.0;
static int compiled_functions = 0;
static int code_size = 0;
compilation_time += (ms_creategraph + ms_optimize + ms_codegen);
compiled_functions++;
code_size += function->shared()->SourceSize();
PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
compiled_functions,
code_size,
compilation_time);
}
if (FLAG_hydrogen_stats) {
isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_create_graph_,
time_taken_to_optimize_,
time_taken_to_codegen_);
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Local helper methods that make up the compilation pipeline. // Local helper methods that make up the compilation pipeline.
...@@ -672,9 +672,9 @@ bool GetOptimizedCodeNow(CompilationJob* job) { ...@@ -672,9 +672,9 @@ bool GetOptimizedCodeNow(CompilationJob* job) {
TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); isolate, &tracing::TraceEventStatsTable::RecompileSynchronous);
if (job->PrepareJob() != CompilationJob::SUCCEEDED || if (job->CreateGraph() != CompilationJob::SUCCEEDED ||
job->ExecuteJob() != CompilationJob::SUCCEEDED || job->OptimizeGraph() != CompilationJob::SUCCEEDED ||
job->FinalizeJob() != CompilationJob::SUCCEEDED) { job->GenerateCode() != CompilationJob::SUCCEEDED) {
if (FLAG_trace_opt) { if (FLAG_trace_opt) {
PrintF("[aborted optimizing "); PrintF("[aborted optimizing ");
info->closure()->ShortPrint(); info->closure()->ShortPrint();
...@@ -735,7 +735,7 @@ bool GetOptimizedCodeLater(CompilationJob* job) { ...@@ -735,7 +735,7 @@ bool GetOptimizedCodeLater(CompilationJob* job) {
TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); isolate, &tracing::TraceEventStatsTable::RecompileSynchronous);
if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; if (job->CreateGraph() != CompilationJob::SUCCEEDED) return false;
isolate->optimizing_compile_dispatcher()->QueueForOptimization(job); isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
if (FLAG_trace_concurrent_recompilation) { if (FLAG_trace_concurrent_recompilation) {
...@@ -1907,12 +1907,12 @@ void Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { ...@@ -1907,12 +1907,12 @@ void Compiler::FinalizeCompilationJob(CompilationJob* raw_job) {
// Except when OSR already disabled optimization for some reason. // Except when OSR already disabled optimization for some reason.
// 3) The code may have already been invalidated due to dependency change. // 3) The code may have already been invalidated due to dependency change.
// 4) Code generation may have failed. // 4) Code generation may have failed.
if (job->state() == CompilationJob::State::kReadyToFinalize) { if (job->last_status() == CompilationJob::SUCCEEDED) {
if (shared->optimization_disabled()) { if (shared->optimization_disabled()) {
job->RetryOptimization(kOptimizationDisabled); job->RetryOptimization(kOptimizationDisabled);
} else if (info->dependencies()->HasAborted()) { } else if (info->dependencies()->HasAborted()) {
job->RetryOptimization(kBailedOutDueToDependencyChange); job->RetryOptimization(kBailedOutDueToDependencyChange);
} else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { } else if (job->GenerateCode() == CompilationJob::SUCCEEDED) {
job->RecordOptimizationStats(); job->RecordOptimizationStats();
RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info);
if (shared->SearchOptimizedCodeMap(info->context()->native_context(), if (shared->SearchOptimizedCodeMap(info->context()->native_context(),
...@@ -1929,7 +1929,7 @@ void Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { ...@@ -1929,7 +1929,7 @@ void Compiler::FinalizeCompilationJob(CompilationJob* raw_job) {
} }
} }
DCHECK(job->state() == CompilationJob::State::kFailed); DCHECK(job->last_status() != CompilationJob::SUCCEEDED);
if (FLAG_trace_opt) { if (FLAG_trace_opt) {
PrintF("[aborted optimizing "); PrintF("[aborted optimizing ");
info->closure()->ShortPrint(); info->closure()->ShortPrint();
......
...@@ -537,86 +537,62 @@ class CompilationInfo final { ...@@ -537,86 +537,62 @@ class CompilationInfo final {
// A base class for compilation jobs intended to run concurrent to the main // A base class for compilation jobs intended to run concurrent to the main
// thread. The job is split into three phases which are called in sequence on // thread. The job is split into three phases which are called in sequence on
// different threads and with different limitations: // different threads and with different limitations:
// 1) PrepareJob: Runs on main thread. No major limitations. // 1) CreateGraph: Runs on main thread. No major limitations.
// 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs. // 2) OptimizeGraph: Runs concurrently. No heap allocation or handle derefs.
// 3) FinalizeJob: Runs on main thread. No dependency changes. // 3) GenerateCode: Runs on main thread. No dependency changes.
// //
// Each of the three phases can either fail or succeed. The current state of // Each of the three phases can either fail or succeed. Apart from their return
// the job can be checked using {state()}. // value, the status of the phase last run can be checked using {last_status()}
// as well. When failing we distinguish between the following levels:
// a) AbortOptimization: Persistent failure, disable future optimization.
// b) RetryOptimzation: Transient failure, try again next time.
class CompilationJob { class CompilationJob {
public: public:
enum Status { SUCCEEDED, FAILED }; explicit CompilationJob(CompilationInfo* info, const char* compiler_name)
enum class State { : info_(info), compiler_name_(compiler_name), last_status_(SUCCEEDED) {}
kReadyToPrepare,
kReadyToExecute,
kReadyToFinalize,
kSucceeded,
kFailed,
};
explicit CompilationJob(CompilationInfo* info, const char* compiler_name,
State initial_state = State::kReadyToPrepare)
: info_(info), compiler_name_(compiler_name), state_(initial_state) {}
virtual ~CompilationJob() {} virtual ~CompilationJob() {}
// Prepare the compile job. Must be called on the main thread. enum Status { FAILED, SUCCEEDED };
MUST_USE_RESULT Status PrepareJob();
// Executes the compile job. Can be called off the main thread. MUST_USE_RESULT Status CreateGraph();
MUST_USE_RESULT Status ExecuteJob(); MUST_USE_RESULT Status OptimizeGraph();
MUST_USE_RESULT Status GenerateCode();
// Finalizes the compile job. Must be called on the main thread. Status last_status() const { return last_status_; }
MUST_USE_RESULT Status FinalizeJob(); CompilationInfo* info() const { return info_; }
Isolate* isolate() const { return info()->isolate(); }
// Report a transient failure, try again next time. Should only be called on
// optimization compilation jobs.
Status RetryOptimization(BailoutReason reason) { Status RetryOptimization(BailoutReason reason) {
DCHECK(info_->IsOptimizing());
info_->RetryOptimization(reason); info_->RetryOptimization(reason);
state_ = State::kFailed; return SetLastStatus(FAILED);
return FAILED;
} }
// Report a persistent failure, disable future optimization on the function.
// Should only be called on optimization compilation jobs.
Status AbortOptimization(BailoutReason reason) { Status AbortOptimization(BailoutReason reason) {
DCHECK(info_->IsOptimizing());
info_->AbortOptimization(reason); info_->AbortOptimization(reason);
state_ = State::kFailed; return SetLastStatus(FAILED);
return FAILED;
} }
void RecordOptimizationStats(); void RecordOptimizationStats();
// Registers weak object to optimized code dependencies.
// TODO(turbofan): Move this to pipeline.cc once Crankshaft dies.
static void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
State state() const { return state_; }
CompilationInfo* info() const { return info_; }
Isolate* isolate() const { return info()->isolate(); }
protected: protected:
void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
// Overridden by the actual implementation. // Overridden by the actual implementation.
virtual Status PrepareJobImpl() = 0; virtual Status CreateGraphImpl() = 0;
virtual Status ExecuteJobImpl() = 0; virtual Status OptimizeGraphImpl() = 0;
virtual Status FinalizeJobImpl() = 0; virtual Status GenerateCodeImpl() = 0;
private: private:
CompilationInfo* info_; CompilationInfo* info_;
base::TimeDelta time_taken_to_prepare_; base::TimeDelta time_taken_to_create_graph_;
base::TimeDelta time_taken_to_execute_; base::TimeDelta time_taken_to_optimize_;
base::TimeDelta time_taken_to_finalize_; base::TimeDelta time_taken_to_codegen_;
const char* compiler_name_; const char* compiler_name_;
State state_; Status last_status_;
MUST_USE_RESULT Status UpdateState(Status status, State next_state) { MUST_USE_RESULT Status SetLastStatus(Status status) {
if (status == SUCCEEDED) { last_status_ = status;
state_ = next_state; return last_status_;
} else {
state_ = State::kFailed;
}
return status;
} }
}; };
......
...@@ -573,9 +573,9 @@ class PipelineCompilationJob final : public CompilationJob { ...@@ -573,9 +573,9 @@ class PipelineCompilationJob final : public CompilationJob {
linkage_(nullptr) {} linkage_(nullptr) {}
protected: protected:
Status PrepareJobImpl() final; Status CreateGraphImpl() final;
Status ExecuteJobImpl() final; Status OptimizeGraphImpl() final;
Status FinalizeJobImpl() final; Status GenerateCodeImpl() final;
private: private:
Zone zone_; Zone zone_;
...@@ -590,7 +590,7 @@ class PipelineCompilationJob final : public CompilationJob { ...@@ -590,7 +590,7 @@ class PipelineCompilationJob final : public CompilationJob {
DISALLOW_COPY_AND_ASSIGN(PipelineCompilationJob); DISALLOW_COPY_AND_ASSIGN(PipelineCompilationJob);
}; };
PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() { PipelineCompilationJob::Status PipelineCompilationJob::CreateGraphImpl() {
if (info()->shared_info()->asm_function()) { if (info()->shared_info()->asm_function()) {
if (info()->osr_frame()) info()->MarkAsFrameSpecializing(); if (info()->osr_frame()) info()->MarkAsFrameSpecializing();
info()->MarkAsFunctionContextSpecializing(); info()->MarkAsFunctionContextSpecializing();
...@@ -633,12 +633,12 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() { ...@@ -633,12 +633,12 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() {
return SUCCEEDED; return SUCCEEDED;
} }
PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl() { PipelineCompilationJob::Status PipelineCompilationJob::OptimizeGraphImpl() {
if (!pipeline_.OptimizeGraph(linkage_)) return FAILED; if (!pipeline_.OptimizeGraph(linkage_)) return FAILED;
return SUCCEEDED; return SUCCEEDED;
} }
PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() { PipelineCompilationJob::Status PipelineCompilationJob::GenerateCodeImpl() {
Handle<Code> code = pipeline_.GenerateCode(linkage_); Handle<Code> code = pipeline_.GenerateCode(linkage_);
if (code.is_null()) { if (code.is_null()) {
if (info()->bailout_reason() == kNoReason) { if (info()->bailout_reason() == kNoReason) {
...@@ -650,7 +650,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() { ...@@ -650,7 +650,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() {
info()->SetCode(code); info()->SetCode(code);
if (info()->is_deoptimization_enabled()) { if (info()->is_deoptimization_enabled()) {
info()->context()->native_context()->AddOptimizedCode(*code); info()->context()->native_context()->AddOptimizedCode(*code);
CompilationJob::RegisterWeakObjectsInOptimizedCode(code); RegisterWeakObjectsInOptimizedCode(code);
} }
return SUCCEEDED; return SUCCEEDED;
} }
...@@ -660,16 +660,16 @@ class PipelineWasmCompilationJob final : public CompilationJob { ...@@ -660,16 +660,16 @@ class PipelineWasmCompilationJob final : public CompilationJob {
explicit PipelineWasmCompilationJob(CompilationInfo* info, Graph* graph, explicit PipelineWasmCompilationJob(CompilationInfo* info, Graph* graph,
CallDescriptor* descriptor, CallDescriptor* descriptor,
SourcePositionTable* source_positions) SourcePositionTable* source_positions)
: CompilationJob(info, "TurboFan", State::kReadyToExecute), : CompilationJob(info, "TurboFan"),
zone_pool_(info->isolate()->allocator()), zone_pool_(info->isolate()->allocator()),
data_(&zone_pool_, info, graph, source_positions), data_(&zone_pool_, info, graph, source_positions),
pipeline_(&data_), pipeline_(&data_),
linkage_(descriptor) {} linkage_(descriptor) {}
protected: protected:
Status PrepareJobImpl() final; Status CreateGraphImpl() final;
Status ExecuteJobImpl() final; Status OptimizeGraphImpl() final;
Status FinalizeJobImpl() final; Status GenerateCodeImpl() final;
private: private:
ZonePool zone_pool_; ZonePool zone_pool_;
...@@ -679,13 +679,12 @@ class PipelineWasmCompilationJob final : public CompilationJob { ...@@ -679,13 +679,12 @@ class PipelineWasmCompilationJob final : public CompilationJob {
}; };
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::Status
PipelineWasmCompilationJob::PrepareJobImpl() { PipelineWasmCompilationJob::CreateGraphImpl() {
UNREACHABLE(); // Prepare should always be skipped for WasmCompilationJob.
return SUCCEEDED; return SUCCEEDED;
} }
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::Status
PipelineWasmCompilationJob::ExecuteJobImpl() { PipelineWasmCompilationJob::OptimizeGraphImpl() {
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
TurboJsonFile json_of(info(), std::ios_base::trunc); TurboJsonFile json_of(info(), std::ios_base::trunc);
json_of << "{\"function\":\"" << info()->GetDebugName().get() json_of << "{\"function\":\"" << info()->GetDebugName().get()
...@@ -699,7 +698,7 @@ PipelineWasmCompilationJob::ExecuteJobImpl() { ...@@ -699,7 +698,7 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
} }
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::Status
PipelineWasmCompilationJob::FinalizeJobImpl() { PipelineWasmCompilationJob::GenerateCodeImpl() {
pipeline_.GenerateCode(&linkage_); pipeline_.GenerateCode(&linkage_);
return SUCCEEDED; return SUCCEEDED;
} }
......
...@@ -3165,7 +3165,11 @@ void WasmCompilationUnit::ExecuteCompilation() { ...@@ -3165,7 +3165,11 @@ void WasmCompilationUnit::ExecuteCompilation() {
} }
job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_->graph(), job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_->graph(),
descriptor, source_positions)); descriptor, source_positions));
ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED;
// The function name {OptimizeGraph()} is misleading but necessary because we
// want to use the CompilationJob interface. A better name would be
// ScheduleGraphAndSelectInstructions.
ok_ = job_->OptimizeGraph() == CompilationJob::SUCCEEDED;
// TODO(bradnelson): Improve histogram handling of size_t. // TODO(bradnelson): Improve histogram handling of size_t.
// TODO(ahaas): The counters are not thread-safe at the moment. // TODO(ahaas): The counters are not thread-safe at the moment.
// isolate_->counters()->wasm_compile_function_peak_memory_bytes() // isolate_->counters()->wasm_compile_function_peak_memory_bytes()
...@@ -3197,7 +3201,7 @@ Handle<Code> WasmCompilationUnit::FinishCompilation() { ...@@ -3197,7 +3201,7 @@ Handle<Code> WasmCompilationUnit::FinishCompilation() {
return Handle<Code>::null(); return Handle<Code>::null();
} }
if (job_->FinalizeJob() != CompilationJob::SUCCEEDED) { if (job_->GenerateCode() != CompilationJob::SUCCEEDED) {
return Handle<Code>::null(); return Handle<Code>::null();
} }
base::ElapsedTimer compile_timer; base::ElapsedTimer compile_timer;
......
...@@ -114,7 +114,7 @@ class HOptimizedGraphBuilderWithPositions : public HOptimizedGraphBuilder { ...@@ -114,7 +114,7 @@ class HOptimizedGraphBuilderWithPositions : public HOptimizedGraphBuilder {
#undef DEF_VISIT #undef DEF_VISIT
}; };
HCompilationJob::Status HCompilationJob::PrepareJobImpl() { HCompilationJob::Status HCompilationJob::CreateGraphImpl() {
if (!isolate()->use_crankshaft() || if (!isolate()->use_crankshaft() ||
info()->shared_info()->dont_crankshaft()) { info()->shared_info()->dont_crankshaft()) {
// Crankshaft is entirely disabled. // Crankshaft is entirely disabled.
...@@ -203,7 +203,7 @@ HCompilationJob::Status HCompilationJob::PrepareJobImpl() { ...@@ -203,7 +203,7 @@ HCompilationJob::Status HCompilationJob::PrepareJobImpl() {
return SUCCEEDED; return SUCCEEDED;
} }
HCompilationJob::Status HCompilationJob::ExecuteJobImpl() { HCompilationJob::Status HCompilationJob::OptimizeGraphImpl() {
DCHECK(graph_ != NULL); DCHECK(graph_ != NULL);
BailoutReason bailout_reason = kNoReason; BailoutReason bailout_reason = kNoReason;
...@@ -217,7 +217,7 @@ HCompilationJob::Status HCompilationJob::ExecuteJobImpl() { ...@@ -217,7 +217,7 @@ HCompilationJob::Status HCompilationJob::ExecuteJobImpl() {
return FAILED; return FAILED;
} }
HCompilationJob::Status HCompilationJob::FinalizeJobImpl() { HCompilationJob::Status HCompilationJob::GenerateCodeImpl() {
DCHECK(chunk_ != NULL); DCHECK(chunk_ != NULL);
DCHECK(graph_ != NULL); DCHECK(graph_ != NULL);
{ {
...@@ -233,7 +233,7 @@ HCompilationJob::Status HCompilationJob::FinalizeJobImpl() { ...@@ -233,7 +233,7 @@ HCompilationJob::Status HCompilationJob::FinalizeJobImpl() {
} }
return FAILED; return FAILED;
} }
CompilationJob::RegisterWeakObjectsInOptimizedCode(optimized_code); RegisterWeakObjectsInOptimizedCode(optimized_code);
info()->SetCode(optimized_code); info()->SetCode(optimized_code);
} }
// Add to the weak list of optimized code objects. // Add to the weak list of optimized code objects.
......
...@@ -44,9 +44,9 @@ class HCompilationJob final : public CompilationJob { ...@@ -44,9 +44,9 @@ class HCompilationJob final : public CompilationJob {
chunk_(nullptr) {} chunk_(nullptr) {}
protected: protected:
virtual Status PrepareJobImpl(); virtual Status CreateGraphImpl();
virtual Status ExecuteJobImpl(); virtual Status OptimizeGraphImpl();
virtual Status FinalizeJobImpl(); virtual Status GenerateCodeImpl();
private: private:
Zone zone_; Zone zone_;
......
...@@ -54,6 +54,8 @@ class LCodeGenBase BASE_EMBEDDED { ...@@ -54,6 +54,8 @@ class LCodeGenBase BASE_EMBEDDED {
int GetNextEmittedBlock() const; int GetNextEmittedBlock() const;
void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
void WriteTranslationFrame(LEnvironment* environment, void WriteTranslationFrame(LEnvironment* environment,
Translation* translation); Translation* translation);
int DefineDeoptimizationLiteral(Handle<Object> literal); int DefineDeoptimizationLiteral(Handle<Object> literal);
......
...@@ -688,16 +688,20 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info) ...@@ -688,16 +688,20 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
InitializeAstVisitor(isolate()->stack_guard()->real_climit()); InitializeAstVisitor(isolate()->stack_guard()->real_climit());
} }
Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode() { Handle<BytecodeArray> BytecodeGenerator::MakeBytecode() {
// Create an inner HandleScope to avoid unnecessarily canonicalizing handles // Create an inner HandleScope to avoid unnecessarily canonicalizing handles
// created as part of bytecode finalization. // created as part of bytecode finalization.
HandleScope scope(isolate()); HandleScope scope(isolate());
AllocateDeferredConstants();
GenerateBytecode();
FinalizeBytecode();
if (HasStackOverflow()) return Handle<BytecodeArray>(); if (HasStackOverflow()) return Handle<BytecodeArray>();
return scope.CloseAndEscape(builder()->ToBytecodeArray()); return scope.CloseAndEscape(builder()->ToBytecodeArray());
} }
void BytecodeGenerator::AllocateDeferredConstants() { void BytecodeGenerator::FinalizeBytecode() {
// Build global declaration pair arrays. // Build global declaration pair arrays.
for (GlobalDeclarationsBuilder* globals_builder : global_declarations_) { for (GlobalDeclarationsBuilder* globals_builder : global_declarations_) {
Handle<FixedArray> declarations = Handle<FixedArray> declarations =
......
...@@ -24,8 +24,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { ...@@ -24,8 +24,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
public: public:
explicit BytecodeGenerator(CompilationInfo* info); explicit BytecodeGenerator(CompilationInfo* info);
void GenerateBytecode(); Handle<BytecodeArray> MakeBytecode();
Handle<BytecodeArray> FinalizeBytecode();
#define DECLARE_VISIT(type) void Visit##type(type* node); #define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
...@@ -53,8 +52,9 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { ...@@ -53,8 +52,9 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
enum class TestFallthrough { kThen, kElse, kNone }; enum class TestFallthrough { kThen, kElse, kNone };
void GenerateBytecode();
void GenerateBytecodeBody(); void GenerateBytecodeBody();
void AllocateDeferredConstants(); void FinalizeBytecode();
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
......
...@@ -30,23 +30,6 @@ typedef InterpreterAssembler::Arg Arg; ...@@ -30,23 +30,6 @@ typedef InterpreterAssembler::Arg Arg;
#define __ assembler-> #define __ assembler->
class InterpreterCompilationJob final : public CompilationJob {
public:
explicit InterpreterCompilationJob(CompilationInfo* info);
protected:
Status PrepareJobImpl() final;
Status ExecuteJobImpl() final;
Status FinalizeJobImpl() final;
private:
BytecodeGenerator* generator() { return &generator_; }
BytecodeGenerator generator_;
DISALLOW_COPY_AND_ASSIGN(InterpreterCompilationJob);
};
Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) { Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) {
memset(dispatch_table_, 0, sizeof(dispatch_table_)); memset(dispatch_table_, 0, sizeof(dispatch_table_));
} }
...@@ -149,39 +132,6 @@ int Interpreter::InterruptBudget() { ...@@ -149,39 +132,6 @@ int Interpreter::InterruptBudget() {
return FLAG_interrupt_budget * kCodeSizeMultiplier; return FLAG_interrupt_budget * kCodeSizeMultiplier;
} }
InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info)
: CompilationJob(info, "Ignition"), generator_(info) {}
InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() {
return SUCCEEDED;
}
InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() {
generator()->GenerateBytecode();
if (generator()->HasStackOverflow()) {
return FAILED;
}
return SUCCEEDED;
}
InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() {
Handle<BytecodeArray> bytecodes = generator()->FinalizeBytecode();
if (generator()->HasStackOverflow()) {
return FAILED;
}
if (FLAG_print_bytecode) {
OFStream os(stdout);
bytecodes->Print(os);
os << std::flush;
}
info()->SetBytecodeArray(bytecodes);
info()->SetCode(info()->isolate()->builtins()->InterpreterEntryTrampoline());
return SUCCEEDED;
}
bool Interpreter::MakeBytecode(CompilationInfo* info) { bool Interpreter::MakeBytecode(CompilationInfo* info) {
RuntimeCallTimerScope runtimeTimer(info->isolate(), RuntimeCallTimerScope runtimeTimer(info->isolate(),
&RuntimeCallStats::CompileIgnition); &RuntimeCallStats::CompileIgnition);
...@@ -206,10 +156,20 @@ bool Interpreter::MakeBytecode(CompilationInfo* info) { ...@@ -206,10 +156,20 @@ bool Interpreter::MakeBytecode(CompilationInfo* info) {
} }
#endif // DEBUG #endif // DEBUG
InterpreterCompilationJob job(info); BytecodeGenerator generator(info);
if (job.PrepareJob() != CompilationJob::SUCCEEDED) return false; Handle<BytecodeArray> bytecodes = generator.MakeBytecode();
if (job.ExecuteJob() != CompilationJob::SUCCEEDED) return false;
return job.FinalizeJob() == CompilationJob::SUCCEEDED; if (generator.HasStackOverflow()) return false;
if (FLAG_print_bytecode) {
OFStream os(stdout);
bytecodes->Print(os);
os << std::flush;
}
info->SetBytecodeArray(bytecodes);
info->SetCode(info->isolate()->builtins()->InterpreterEntryTrampoline());
return true;
} }
bool Interpreter::IsDispatchTableInitialized() { bool Interpreter::IsDispatchTableInitialized() {
......
...@@ -549,8 +549,8 @@ class WasmFunctionCompiler : public HandleAndZoneScope, ...@@ -549,8 +549,8 @@ class WasmFunctionCompiler : public HandleAndZoneScope,
Code::ComputeFlags(Code::WASM_FUNCTION)); Code::ComputeFlags(Code::WASM_FUNCTION));
std::unique_ptr<CompilationJob> job(Pipeline::NewWasmCompilationJob( std::unique_ptr<CompilationJob> job(Pipeline::NewWasmCompilationJob(
&info, graph(), desc, &source_position_table_)); &info, graph(), desc, &source_position_table_));
if (job->ExecuteJob() != CompilationJob::SUCCEEDED || if (job->OptimizeGraph() != CompilationJob::SUCCEEDED ||
job->FinalizeJob() != CompilationJob::SUCCEEDED) job->GenerateCode() != CompilationJob::SUCCEEDED)
return Handle<Code>::null(); return Handle<Code>::null();
Handle<Code> code = info.code(); Handle<Code> code = info.code();
......
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