| Index: src/compiler.cc
|
| diff --git a/src/compiler.cc b/src/compiler.cc
|
| index 22cd4b0e541e6375216c96d4ef015d3b18e438e2..e72d3027307008df09314e2bacf3b50c6c41fe48 100644
|
| --- a/src/compiler.cc
|
| +++ b/src/compiler.cc
|
| @@ -346,7 +346,8 @@ bool ShouldUseIgnition(CompilationInfo* info) {
|
| return info->shared_info()->PassesFilter(FLAG_ignition_filter);
|
| }
|
|
|
| -CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) {
|
| +std::vector<std::unique_ptr<CompilationJob>> GetUnoptimizedCompilationJob(
|
| + CompilationInfo* info) {
|
| // Function should have been parsed and analyzed before creating a compilation
|
| // job.
|
| DCHECK_NOT_NULL(info->literal());
|
| @@ -356,40 +357,12 @@ CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) {
|
| if (ShouldUseIgnition(info)) {
|
| return interpreter::Interpreter::NewCompilationJob(info);
|
| } else {
|
| - return FullCodeGenerator::NewCompilationJob(info);
|
| - }
|
| -}
|
| -
|
| -bool GenerateUnoptimizedCode(CompilationInfo* info) {
|
| - if (FLAG_validate_asm && info->scope()->asm_module() &&
|
| - !info->shared_info()->is_asm_wasm_broken()) {
|
| - EnsureFeedbackMetadata(info);
|
| - MaybeHandle<FixedArray> wasm_data;
|
| - wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info());
|
| - if (!wasm_data.is_null()) {
|
| - info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
|
| - info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
|
| - return true;
|
| - }
|
| + std::unique_ptr<CompilationJob> job(
|
| + FullCodeGenerator::NewCompilationJob(info));
|
| + std::vector<std::unique_ptr<CompilationJob>> result;
|
| + result.push_back(std::move(job));
|
| + return result;
|
| }
|
| -
|
| - std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info));
|
| - if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false;
|
| - if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false;
|
| - if (job->FinalizeJob() != CompilationJob::SUCCEEDED) return false;
|
| - job->RecordUnoptimizedCompilationStats();
|
| - return true;
|
| -}
|
| -
|
| -bool CompileUnoptimizedCode(CompilationInfo* info) {
|
| - DCHECK(AllowCompilation::IsAllowed(info->isolate()));
|
| - if (!Compiler::Analyze(info->parse_info()) ||
|
| - !GenerateUnoptimizedCode(info)) {
|
| - Isolate* isolate = info->isolate();
|
| - if (!isolate->has_pending_exception()) isolate->StackOverflow();
|
| - return false;
|
| - }
|
| - return true;
|
| }
|
|
|
| void InstallSharedScopeInfo(CompilationInfo* info,
|
| @@ -431,6 +404,54 @@ void InstallUnoptimizedCode(CompilationInfo* info) {
|
| RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info);
|
| }
|
|
|
| +CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
|
| + CompilationJob::Status status = job->FinalizeJob();
|
| + if (status == CompilationJob::SUCCEEDED) {
|
| + DCHECK(!job->info()->shared_info()->is_compiled());
|
| + InstallUnoptimizedCode(job->info());
|
| + job->RecordUnoptimizedCompilationStats();
|
| + }
|
| + return status;
|
| +}
|
| +
|
| +bool GenerateUnoptimizedCode(CompilationInfo* info) {
|
| + if (FLAG_validate_asm && info->scope()->asm_module() &&
|
| + !info->shared_info()->is_asm_wasm_broken()) {
|
| + EnsureFeedbackMetadata(info);
|
| + MaybeHandle<FixedArray> wasm_data;
|
| + wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info());
|
| + if (!wasm_data.is_null()) {
|
| + info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
|
| + info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
|
| + return true;
|
| + }
|
| + }
|
| +
|
| + std::vector<std::unique_ptr<CompilationJob>> jobs(
|
| + GetUnoptimizedCompilationJob(info));
|
| + for (auto& job : jobs) {
|
| + if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false;
|
| + if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false;
|
| + if (FinalizeUnoptimizedCompilationJob(job.get()) !=
|
| + CompilationJob::SUCCEEDED) {
|
| + return false;
|
| + }
|
| + job.reset();
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +bool CompileUnoptimizedCode(CompilationInfo* info) {
|
| + DCHECK(AllowCompilation::IsAllowed(info->isolate()));
|
| + if (!Compiler::Analyze(info->parse_info()) ||
|
| + !GenerateUnoptimizedCode(info)) {
|
| + Isolate* isolate = info->isolate();
|
| + if (!isolate->has_pending_exception()) isolate->StackOverflow();
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) {
|
| VMState<COMPILER> state(info->isolate());
|
| PostponeInterruptsScope postpone(info->isolate());
|
| @@ -443,21 +464,9 @@ MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) {
|
| // Compile either unoptimized code or bytecode for the interpreter.
|
| if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
|
|
|
| - InstallUnoptimizedCode(info);
|
| -
|
| return info->code();
|
| }
|
|
|
| -CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
|
| - CompilationJob::Status status = job->FinalizeJob();
|
| - if (status == CompilationJob::SUCCEEDED) {
|
| - DCHECK(!job->info()->shared_info()->is_compiled());
|
| - InstallUnoptimizedCode(job->info());
|
| - job->RecordUnoptimizedCompilationStats();
|
| - }
|
| - return status;
|
| -}
|
| -
|
| MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
|
| Handle<JSFunction> function, BailoutId osr_ast_id) {
|
| Handle<SharedFunctionInfo> shared(function->shared());
|
| @@ -497,33 +506,6 @@ void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
|
| literals, info->osr_ast_id());
|
| }
|
|
|
| -bool Renumber(ParseInfo* parse_info) {
|
| - // Create a canonical handle scope if compiling ignition bytecode. This is
|
| - // required by the constant array builder to de-duplicate objects without
|
| - // dereferencing handles.
|
| - std::unique_ptr<CanonicalHandleScope> canonical;
|
| - if (FLAG_ignition) {
|
| - canonical.reset(new CanonicalHandleScope(parse_info->isolate()));
|
| - }
|
| -
|
| - if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
|
| - parse_info->literal())) {
|
| - return false;
|
| - }
|
| - Handle<SharedFunctionInfo> shared_info = parse_info->shared_info();
|
| - if (!shared_info.is_null()) {
|
| - FunctionLiteral* lit = parse_info->literal();
|
| - shared_info->set_ast_node_count(lit->ast_node_count());
|
| - if (lit->dont_optimize_reason() != kNoReason) {
|
| - shared_info->DisableOptimization(lit->dont_optimize_reason());
|
| - }
|
| - if (lit->flags() & AstProperties::kDontCrankshaft) {
|
| - shared_info->set_dont_crankshaft(true);
|
| - }
|
| - }
|
| - return true;
|
| -}
|
| -
|
| bool UseTurboFan(Handle<SharedFunctionInfo> shared) {
|
| bool optimization_disabled = shared->optimization_disabled();
|
| bool dont_crankshaft = shared->dont_crankshaft();
|
| @@ -1113,12 +1095,6 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
|
| return Handle<SharedFunctionInfo>::null();
|
| }
|
|
|
| - // Update the shared function info with the scope info.
|
| - InstallSharedScopeInfo(info, result);
|
| -
|
| - // Install compilation result on the shared function info
|
| - InstallSharedCompilationResult(info, result);
|
| -
|
| Handle<String> script_name =
|
| script->name()->IsString()
|
| ? Handle<String>(String::cast(script->name()))
|
| @@ -1160,6 +1136,33 @@ bool Compiler::ParseAndAnalyze(ParseInfo* info) {
|
| return true;
|
| }
|
|
|
| +bool Compiler::Renumber(ParseInfo* parse_info) {
|
| + // Create a canonical handle scope if compiling ignition bytecode. This is
|
| + // required by the constant array builder to de-duplicate objects without
|
| + // dereferencing handles.
|
| + std::unique_ptr<CanonicalHandleScope> canonical;
|
| + if (FLAG_ignition) {
|
| + canonical.reset(new CanonicalHandleScope(parse_info->isolate()));
|
| + }
|
| +
|
| + if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
|
| + parse_info->literal())) {
|
| + return false;
|
| + }
|
| + Handle<SharedFunctionInfo> shared_info = parse_info->shared_info();
|
| + if (!shared_info.is_null()) {
|
| + FunctionLiteral* lit = parse_info->literal();
|
| + shared_info->set_ast_node_count(lit->ast_node_count());
|
| + if (lit->dont_optimize_reason() != kNoReason) {
|
| + shared_info->DisableOptimization(lit->dont_optimize_reason());
|
| + }
|
| + if (lit->flags() & AstProperties::kDontCrankshaft) {
|
| + shared_info->set_dont_crankshaft(true);
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) {
|
| if (function->is_compiled()) return true;
|
| Isolate* isolate = function->GetIsolate();
|
| @@ -1703,16 +1706,16 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForStreamedScript(
|
| return result;
|
| }
|
|
|
| -
|
| Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
|
| FunctionLiteral* literal, Handle<Script> script,
|
| - CompilationInfo* outer_info) {
|
| + CompilationInfo* outer_info, ShouldCompile should_compile) {
|
| // Precondition: code has been parsed and scopes have been analyzed.
|
| Isolate* isolate = outer_info->isolate();
|
| MaybeHandle<SharedFunctionInfo> maybe_existing;
|
|
|
| // Find any previously allocated shared function info for the given literal.
|
| - if (outer_info->shared_info()->never_compiled()) {
|
| + if (outer_info->shared_info()->never_compiled() &&
|
| + should_compile == ShouldCompile::kIfNecessary) {
|
| // On the first compile, there are no existing shared function info for
|
| // inner functions yet, so do not try to find them. All bets are off for
|
| // live edit though.
|
| @@ -1734,6 +1737,8 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
|
| if (!outer_info->is_debug() || existing->HasDebugCode()) {
|
| return existing;
|
| }
|
| + } else if (should_compile == ShouldCompile::kNever) {
|
| + return existing;
|
| }
|
| }
|
|
|
| @@ -1763,7 +1768,8 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
|
| RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode);
|
| TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
|
|
|
| - if (!literal->ShouldEagerCompile()) {
|
| + if (!literal->ShouldEagerCompile() ||
|
| + should_compile == ShouldCompile::kNever) {
|
| info.SetCode(isolate->builtins()->CompileLazy());
|
| Scope* outer_scope = literal->scope()->GetOuterScopeWithContext();
|
| if (outer_scope) {
|
| @@ -1831,14 +1837,18 @@ MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function,
|
| return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame);
|
| }
|
|
|
| -CompilationJob* Compiler::PrepareUnoptimizedCompilationJob(
|
| - CompilationInfo* info) {
|
| +std::vector<std::unique_ptr<CompilationJob>>
|
| +Compiler::PrepareUnoptimizedCompilationJob(CompilationInfo* info) {
|
| VMState<COMPILER> state(info->isolate());
|
| - std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info));
|
| - if (job->PrepareJob() != CompilationJob::SUCCEEDED) {
|
| - return nullptr;
|
| + std::vector<std::unique_ptr<CompilationJob>> jobs(
|
| + GetUnoptimizedCompilationJob(info));
|
| + for (auto& job : jobs) {
|
| + if (job->PrepareJob() != CompilationJob::SUCCEEDED) {
|
| + std::vector<std::unique_ptr<CompilationJob>> result;
|
| + return result;
|
| + }
|
| }
|
| - return job.release();
|
| + return jobs;
|
| }
|
|
|
| bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) {
|
|
|