From ce65e1059715dbcafef68b3d4097afc031eaa998 Mon Sep 17 00:00:00 2001 From: rmcilroy Date: Tue, 16 Aug 2016 08:06:32 -0700 Subject: [PATCH] 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} --- .../optimizing-compile-dispatcher.cc | 2 +- src/compiler.cc | 114 +++++++++--------- src/compiler.h | 86 +++++-------- src/compiler/pipeline.cc | 29 +++-- src/compiler/wasm-compiler.cc | 8 +- src/crankshaft/hydrogen.cc | 8 +- src/crankshaft/hydrogen.h | 6 +- src/crankshaft/lithium-codegen.h | 2 + src/interpreter/bytecode-generator.cc | 10 +- src/interpreter/bytecode-generator.h | 6 +- src/interpreter/interpreter.cc | 68 +++-------- test/cctest/wasm/wasm-run-utils.h | 4 +- 12 files changed, 144 insertions(+), 199 deletions(-) diff --git a/src/compiler-dispatcher/optimizing-compile-dispatcher.cc b/src/compiler-dispatcher/optimizing-compile-dispatcher.cc index be81047976..c7b2f31b46 100644 --- a/src/compiler-dispatcher/optimizing-compile-dispatcher.cc +++ b/src/compiler-dispatcher/optimizing-compile-dispatcher.cc @@ -107,7 +107,7 @@ void OptimizingCompileDispatcher::CompileNext(CompilationJob* job) { if (!job) return; // 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. // The function may have already been optimized by OSR. Simply continue. diff --git a/src/compiler.cc b/src/compiler.cc index 9e5e3916c9..54ea359c65 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -240,11 +240,11 @@ bool CompilationInfo::ExpectsJSReceiverAsReceiver() { // ---------------------------------------------------------------------------- // Implementation of CompilationJob -CompilationJob::Status CompilationJob::PrepareJob() { - DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); +CompilationJob::Status CompilationJob::CreateGraph() { DisallowJavascriptExecution no_js(isolate()); + DCHECK(info()->IsOptimizing()); - if (FLAG_trace_opt && info()->IsOptimizing()) { + if (FLAG_trace_opt) { OFStream os(stdout); os << "[compiling method " << Brief(*info()->closure()) << " using " << compiler_name_; @@ -253,69 +253,34 @@ CompilationJob::Status CompilationJob::PrepareJob() { } // Delegate to the underlying implementation. - DCHECK(state() == State::kReadyToPrepare); - ScopedTimer t(&time_taken_to_prepare_); - return UpdateState(PrepareJobImpl(), State::kReadyToExecute); + DCHECK_EQ(SUCCEEDED, last_status()); + ScopedTimer t(&time_taken_to_create_graph_); + return SetLastStatus(CreateGraphImpl()); } -CompilationJob::Status CompilationJob::ExecuteJob() { +CompilationJob::Status CompilationJob::OptimizeGraph() { DisallowHeapAllocation no_allocation; DisallowHandleAllocation no_handles; DisallowHandleDereference no_deref; DisallowCodeDependencyChange no_dependency_change; // Delegate to the underlying implementation. - DCHECK(state() == State::kReadyToExecute); - ScopedTimer t(&time_taken_to_execute_); - return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize); + DCHECK_EQ(SUCCEEDED, last_status()); + ScopedTimer t(&time_taken_to_optimize_); + return SetLastStatus(OptimizeGraphImpl()); } -CompilationJob::Status CompilationJob::FinalizeJob() { - DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); +CompilationJob::Status CompilationJob::GenerateCode() { DisallowCodeDependencyChange no_dependency_change; DisallowJavascriptExecution no_js(isolate()); DCHECK(!info()->dependencies()->HasAborted()); // Delegate to the underlying implementation. - DCHECK(state() == State::kReadyToFinalize); - ScopedTimer t(&time_taken_to_finalize_); - return UpdateState(FinalizeJobImpl(), State::kSucceeded); + DCHECK_EQ(SUCCEEDED, last_status()); + ScopedTimer t(&time_taken_to_codegen_); + return SetLastStatus(GenerateCodeImpl()); } -void CompilationJob::RecordOptimizationStats() { - DCHECK(info()->IsOptimizing()); - Handle 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 { @@ -335,7 +300,6 @@ void AddWeakObjectToCodeDependency(Isolate* isolate, Handle object, } // namespace -// static void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle code) { // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. Isolate* const isolate = code->GetIsolate(); @@ -376,6 +340,42 @@ void CompilationJob::RegisterWeakObjectsInOptimizedCode(Handle code) { code->set_can_have_weak_objects(true); } +void CompilationJob::RecordOptimizationStats() { + Handle 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. @@ -672,9 +672,9 @@ bool GetOptimizedCodeNow(CompilationJob* job) { TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); - if (job->PrepareJob() != CompilationJob::SUCCEEDED || - job->ExecuteJob() != CompilationJob::SUCCEEDED || - job->FinalizeJob() != CompilationJob::SUCCEEDED) { + if (job->CreateGraph() != CompilationJob::SUCCEEDED || + job->OptimizeGraph() != CompilationJob::SUCCEEDED || + job->GenerateCode() != CompilationJob::SUCCEEDED) { if (FLAG_trace_opt) { PrintF("[aborted optimizing "); info->closure()->ShortPrint(); @@ -735,7 +735,7 @@ bool GetOptimizedCodeLater(CompilationJob* job) { TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); - if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; + if (job->CreateGraph() != CompilationJob::SUCCEEDED) return false; isolate->optimizing_compile_dispatcher()->QueueForOptimization(job); if (FLAG_trace_concurrent_recompilation) { @@ -1907,12 +1907,12 @@ void Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { // Except when OSR already disabled optimization for some reason. // 3) The code may have already been invalidated due to dependency change. // 4) Code generation may have failed. - if (job->state() == CompilationJob::State::kReadyToFinalize) { + if (job->last_status() == CompilationJob::SUCCEEDED) { if (shared->optimization_disabled()) { job->RetryOptimization(kOptimizationDisabled); } else if (info->dependencies()->HasAborted()) { job->RetryOptimization(kBailedOutDueToDependencyChange); - } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { + } else if (job->GenerateCode() == CompilationJob::SUCCEEDED) { job->RecordOptimizationStats(); RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); if (shared->SearchOptimizedCodeMap(info->context()->native_context(), @@ -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) { PrintF("[aborted optimizing "); info->closure()->ShortPrint(); diff --git a/src/compiler.h b/src/compiler.h index fcbbd4e389..b8b3a0bfb4 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -537,86 +537,62 @@ class CompilationInfo final { // 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 // different threads and with different limitations: -// 1) PrepareJob: Runs on main thread. No major limitations. -// 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs. -// 3) FinalizeJob: Runs on main thread. No dependency changes. +// 1) CreateGraph: Runs on main thread. No major limitations. +// 2) OptimizeGraph: Runs concurrently. No heap allocation or handle derefs. +// 3) GenerateCode: Runs on main thread. No dependency changes. // -// Each of the three phases can either fail or succeed. The current state of -// the job can be checked using {state()}. +// Each of the three phases can either fail or succeed. Apart from their return +// 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 { public: - enum Status { SUCCEEDED, FAILED }; - enum class State { - 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) {} + explicit CompilationJob(CompilationInfo* info, const char* compiler_name) + : info_(info), compiler_name_(compiler_name), last_status_(SUCCEEDED) {} virtual ~CompilationJob() {} - // Prepare the compile job. Must be called on the main thread. - MUST_USE_RESULT Status PrepareJob(); + enum Status { FAILED, SUCCEEDED }; - // Executes the compile job. Can be called off the main thread. - MUST_USE_RESULT Status ExecuteJob(); + MUST_USE_RESULT Status CreateGraph(); + MUST_USE_RESULT Status OptimizeGraph(); + MUST_USE_RESULT Status GenerateCode(); - // Finalizes the compile job. Must be called on the main thread. - MUST_USE_RESULT Status FinalizeJob(); + Status last_status() const { return last_status_; } + 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) { - DCHECK(info_->IsOptimizing()); info_->RetryOptimization(reason); - state_ = State::kFailed; - return FAILED; + return SetLastStatus(FAILED); } - // Report a persistent failure, disable future optimization on the function. - // Should only be called on optimization compilation jobs. Status AbortOptimization(BailoutReason reason) { - DCHECK(info_->IsOptimizing()); info_->AbortOptimization(reason); - state_ = State::kFailed; - return FAILED; + return SetLastStatus(FAILED); } void RecordOptimizationStats(); - // Registers weak object to optimized code dependencies. - // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. - static void RegisterWeakObjectsInOptimizedCode(Handle code); - - State state() const { return state_; } - CompilationInfo* info() const { return info_; } - Isolate* isolate() const { return info()->isolate(); } - protected: + void RegisterWeakObjectsInOptimizedCode(Handle code); + // Overridden by the actual implementation. - virtual Status PrepareJobImpl() = 0; - virtual Status ExecuteJobImpl() = 0; - virtual Status FinalizeJobImpl() = 0; + virtual Status CreateGraphImpl() = 0; + virtual Status OptimizeGraphImpl() = 0; + virtual Status GenerateCodeImpl() = 0; private: CompilationInfo* info_; - base::TimeDelta time_taken_to_prepare_; - base::TimeDelta time_taken_to_execute_; - base::TimeDelta time_taken_to_finalize_; + base::TimeDelta time_taken_to_create_graph_; + base::TimeDelta time_taken_to_optimize_; + base::TimeDelta time_taken_to_codegen_; const char* compiler_name_; - State state_; + Status last_status_; - MUST_USE_RESULT Status UpdateState(Status status, State next_state) { - if (status == SUCCEEDED) { - state_ = next_state; - } else { - state_ = State::kFailed; - } - return status; + MUST_USE_RESULT Status SetLastStatus(Status status) { + last_status_ = status; + return last_status_; } }; diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index ed4e19bf13..20a0db9813 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -573,9 +573,9 @@ class PipelineCompilationJob final : public CompilationJob { linkage_(nullptr) {} protected: - Status PrepareJobImpl() final; - Status ExecuteJobImpl() final; - Status FinalizeJobImpl() final; + Status CreateGraphImpl() final; + Status OptimizeGraphImpl() final; + Status GenerateCodeImpl() final; private: Zone zone_; @@ -590,7 +590,7 @@ class PipelineCompilationJob final : public CompilationJob { DISALLOW_COPY_AND_ASSIGN(PipelineCompilationJob); }; -PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() { +PipelineCompilationJob::Status PipelineCompilationJob::CreateGraphImpl() { if (info()->shared_info()->asm_function()) { if (info()->osr_frame()) info()->MarkAsFrameSpecializing(); info()->MarkAsFunctionContextSpecializing(); @@ -633,12 +633,12 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() { return SUCCEEDED; } -PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl() { +PipelineCompilationJob::Status PipelineCompilationJob::OptimizeGraphImpl() { if (!pipeline_.OptimizeGraph(linkage_)) return FAILED; return SUCCEEDED; } -PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() { +PipelineCompilationJob::Status PipelineCompilationJob::GenerateCodeImpl() { Handle code = pipeline_.GenerateCode(linkage_); if (code.is_null()) { if (info()->bailout_reason() == kNoReason) { @@ -650,7 +650,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() { info()->SetCode(code); if (info()->is_deoptimization_enabled()) { info()->context()->native_context()->AddOptimizedCode(*code); - CompilationJob::RegisterWeakObjectsInOptimizedCode(code); + RegisterWeakObjectsInOptimizedCode(code); } return SUCCEEDED; } @@ -660,16 +660,16 @@ class PipelineWasmCompilationJob final : public CompilationJob { explicit PipelineWasmCompilationJob(CompilationInfo* info, Graph* graph, CallDescriptor* descriptor, SourcePositionTable* source_positions) - : CompilationJob(info, "TurboFan", State::kReadyToExecute), + : CompilationJob(info, "TurboFan"), zone_pool_(info->isolate()->allocator()), data_(&zone_pool_, info, graph, source_positions), pipeline_(&data_), linkage_(descriptor) {} protected: - Status PrepareJobImpl() final; - Status ExecuteJobImpl() final; - Status FinalizeJobImpl() final; + Status CreateGraphImpl() final; + Status OptimizeGraphImpl() final; + Status GenerateCodeImpl() final; private: ZonePool zone_pool_; @@ -679,13 +679,12 @@ class PipelineWasmCompilationJob final : public CompilationJob { }; PipelineWasmCompilationJob::Status -PipelineWasmCompilationJob::PrepareJobImpl() { - UNREACHABLE(); // Prepare should always be skipped for WasmCompilationJob. +PipelineWasmCompilationJob::CreateGraphImpl() { return SUCCEEDED; } PipelineWasmCompilationJob::Status -PipelineWasmCompilationJob::ExecuteJobImpl() { +PipelineWasmCompilationJob::OptimizeGraphImpl() { if (FLAG_trace_turbo) { TurboJsonFile json_of(info(), std::ios_base::trunc); json_of << "{\"function\":\"" << info()->GetDebugName().get() @@ -699,7 +698,7 @@ PipelineWasmCompilationJob::ExecuteJobImpl() { } PipelineWasmCompilationJob::Status -PipelineWasmCompilationJob::FinalizeJobImpl() { +PipelineWasmCompilationJob::GenerateCodeImpl() { pipeline_.GenerateCode(&linkage_); return SUCCEEDED; } diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index 41da92641b..b457efec4e 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -3165,7 +3165,11 @@ void WasmCompilationUnit::ExecuteCompilation() { } job_.reset(Pipeline::NewWasmCompilationJob(&info_, jsgraph_->graph(), 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(ahaas): The counters are not thread-safe at the moment. // isolate_->counters()->wasm_compile_function_peak_memory_bytes() @@ -3197,7 +3201,7 @@ Handle WasmCompilationUnit::FinishCompilation() { return Handle::null(); } - if (job_->FinalizeJob() != CompilationJob::SUCCEEDED) { + if (job_->GenerateCode() != CompilationJob::SUCCEEDED) { return Handle::null(); } base::ElapsedTimer compile_timer; diff --git a/src/crankshaft/hydrogen.cc b/src/crankshaft/hydrogen.cc index f2cf5098a7..ded0e99d91 100644 --- a/src/crankshaft/hydrogen.cc +++ b/src/crankshaft/hydrogen.cc @@ -114,7 +114,7 @@ class HOptimizedGraphBuilderWithPositions : public HOptimizedGraphBuilder { #undef DEF_VISIT }; -HCompilationJob::Status HCompilationJob::PrepareJobImpl() { +HCompilationJob::Status HCompilationJob::CreateGraphImpl() { if (!isolate()->use_crankshaft() || info()->shared_info()->dont_crankshaft()) { // Crankshaft is entirely disabled. @@ -203,7 +203,7 @@ HCompilationJob::Status HCompilationJob::PrepareJobImpl() { return SUCCEEDED; } -HCompilationJob::Status HCompilationJob::ExecuteJobImpl() { +HCompilationJob::Status HCompilationJob::OptimizeGraphImpl() { DCHECK(graph_ != NULL); BailoutReason bailout_reason = kNoReason; @@ -217,7 +217,7 @@ HCompilationJob::Status HCompilationJob::ExecuteJobImpl() { return FAILED; } -HCompilationJob::Status HCompilationJob::FinalizeJobImpl() { +HCompilationJob::Status HCompilationJob::GenerateCodeImpl() { DCHECK(chunk_ != NULL); DCHECK(graph_ != NULL); { @@ -233,7 +233,7 @@ HCompilationJob::Status HCompilationJob::FinalizeJobImpl() { } return FAILED; } - CompilationJob::RegisterWeakObjectsInOptimizedCode(optimized_code); + RegisterWeakObjectsInOptimizedCode(optimized_code); info()->SetCode(optimized_code); } // Add to the weak list of optimized code objects. diff --git a/src/crankshaft/hydrogen.h b/src/crankshaft/hydrogen.h index 492fa9522b..3ac2af6f60 100644 --- a/src/crankshaft/hydrogen.h +++ b/src/crankshaft/hydrogen.h @@ -44,9 +44,9 @@ class HCompilationJob final : public CompilationJob { chunk_(nullptr) {} protected: - virtual Status PrepareJobImpl(); - virtual Status ExecuteJobImpl(); - virtual Status FinalizeJobImpl(); + virtual Status CreateGraphImpl(); + virtual Status OptimizeGraphImpl(); + virtual Status GenerateCodeImpl(); private: Zone zone_; diff --git a/src/crankshaft/lithium-codegen.h b/src/crankshaft/lithium-codegen.h index fbf96924ee..c666e1b0af 100644 --- a/src/crankshaft/lithium-codegen.h +++ b/src/crankshaft/lithium-codegen.h @@ -54,6 +54,8 @@ class LCodeGenBase BASE_EMBEDDED { int GetNextEmittedBlock() const; + void RegisterWeakObjectsInOptimizedCode(Handle code); + void WriteTranslationFrame(LEnvironment* environment, Translation* translation); int DefineDeoptimizationLiteral(Handle literal); diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc index b5d085cc5f..cb133c365e 100644 --- a/src/interpreter/bytecode-generator.cc +++ b/src/interpreter/bytecode-generator.cc @@ -688,16 +688,20 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info) InitializeAstVisitor(isolate()->stack_guard()->real_climit()); } -Handle BytecodeGenerator::FinalizeBytecode() { +Handle BytecodeGenerator::MakeBytecode() { // Create an inner HandleScope to avoid unnecessarily canonicalizing handles // created as part of bytecode finalization. HandleScope scope(isolate()); - AllocateDeferredConstants(); + + GenerateBytecode(); + FinalizeBytecode(); + if (HasStackOverflow()) return Handle(); + return scope.CloseAndEscape(builder()->ToBytecodeArray()); } -void BytecodeGenerator::AllocateDeferredConstants() { +void BytecodeGenerator::FinalizeBytecode() { // Build global declaration pair arrays. for (GlobalDeclarationsBuilder* globals_builder : global_declarations_) { Handle declarations = diff --git a/src/interpreter/bytecode-generator.h b/src/interpreter/bytecode-generator.h index 3b6b2894ab..573ad673ef 100644 --- a/src/interpreter/bytecode-generator.h +++ b/src/interpreter/bytecode-generator.h @@ -24,8 +24,7 @@ class BytecodeGenerator final : public AstVisitor { public: explicit BytecodeGenerator(CompilationInfo* info); - void GenerateBytecode(); - Handle FinalizeBytecode(); + Handle MakeBytecode(); #define DECLARE_VISIT(type) void Visit##type(type* node); AST_NODE_LIST(DECLARE_VISIT) @@ -53,8 +52,9 @@ class BytecodeGenerator final : public AstVisitor { enum class TestFallthrough { kThen, kElse, kNone }; + void GenerateBytecode(); void GenerateBytecodeBody(); - void AllocateDeferredConstants(); + void FinalizeBytecode(); DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc index 6be5fae9c9..761199766e 100644 --- a/src/interpreter/interpreter.cc +++ b/src/interpreter/interpreter.cc @@ -30,23 +30,6 @@ typedef InterpreterAssembler::Arg Arg; #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) { memset(dispatch_table_, 0, sizeof(dispatch_table_)); } @@ -149,39 +132,6 @@ int Interpreter::InterruptBudget() { 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 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) { RuntimeCallTimerScope runtimeTimer(info->isolate(), &RuntimeCallStats::CompileIgnition); @@ -206,10 +156,20 @@ bool Interpreter::MakeBytecode(CompilationInfo* info) { } #endif // DEBUG - InterpreterCompilationJob job(info); - if (job.PrepareJob() != CompilationJob::SUCCEEDED) return false; - if (job.ExecuteJob() != CompilationJob::SUCCEEDED) return false; - return job.FinalizeJob() == CompilationJob::SUCCEEDED; + BytecodeGenerator generator(info); + Handle bytecodes = generator.MakeBytecode(); + + 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() { diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h index 0a11fedfd1..a9f70deadf 100644 --- a/test/cctest/wasm/wasm-run-utils.h +++ b/test/cctest/wasm/wasm-run-utils.h @@ -549,8 +549,8 @@ class WasmFunctionCompiler : public HandleAndZoneScope, Code::ComputeFlags(Code::WASM_FUNCTION)); std::unique_ptr job(Pipeline::NewWasmCompilationJob( &info, graph(), desc, &source_position_table_)); - if (job->ExecuteJob() != CompilationJob::SUCCEEDED || - job->FinalizeJob() != CompilationJob::SUCCEEDED) + if (job->OptimizeGraph() != CompilationJob::SUCCEEDED || + job->GenerateCode() != CompilationJob::SUCCEEDED) return Handle::null(); Handle code = info.code();