From 8459fe6ec0eb9ac169240e7b9323860eb285af0b Mon Sep 17 00:00:00 2001 From: Igor Sheludko Date: Fri, 9 Jun 2023 16:37:15 +0200 Subject: [PATCH] Merged: Squashed multiple commits. Merged: [runtime] Create unoptimized data even if compilation is aborted (cherry picked from commit 0e07abe6ae3828b12d2555abae45ac78f165d061) Merged: [class] Export SharedFunctionInfo::CreateAndSetUncompiledData (cherry picked from commit 1b55293a7140eb9310638621987c6d90dc00a80f) Bug: chromium:1441254 Change-Id: I3c78d3972295c147d79d3734a4869c9b36f19433 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4603931 Auto-Submit: Igor Sheludko Reviewed-by: Jakob Kummerow Cr-Commit-Position: refs/branch-heads/11.5@{#10} Cr-Branched-From: 0c4044b7336787781646e48b2f98f0c7d1b400a5-refs/heads/11.5.150@{#1} Cr-Branched-From: b71d3038a7d99c79e1c21239e8ae07da5fc8c90b-refs/heads/main@{#87781} --- src/codegen/compiler.cc | 22 +++++++++++++++++++--- src/objects/shared-function-info.cc | 17 ++++++++++++++++- src/objects/shared-function-info.h | 5 +++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/codegen/compiler.cc b/src/codegen/compiler.cc index 34b9a492c4ee..a7c79f78b423 100644 --- a/src/codegen/compiler.cc +++ b/src/codegen/compiler.cc @@ -817,6 +817,7 @@ bool IterativelyExecuteAndFinalizeUnoptimizedCompilationJobs( std::vector functions_to_compile; functions_to_compile.push_back(parse_info->literal()); + bool compilation_succeeded = true; bool is_first = true; while (!functions_to_compile.empty()) { FunctionLiteral* literal = functions_to_compile.back(); @@ -841,7 +842,19 @@ bool IterativelyExecuteAndFinalizeUnoptimizedCompilationJobs( allocator, &functions_to_compile, isolate->AsLocalIsolate()); - if (!job) return false; + if (!job) { + // Compilation failed presumably because of stack overflow, make sure + // the shared function info contains uncompiled data for the next + // compilation attempts. + if (!shared_info->HasUncompiledData()) { + SharedFunctionInfo::CreateAndSetUncompiledData(isolate, shared_info, + literal); + } + compilation_succeeded = false; + // Proceed finalizing other functions in case they don't have uncompiled + // data. + continue; + } UpdateSharedFunctionFlagsAfterCompilation(literal, *shared_info); @@ -859,7 +872,10 @@ bool IterativelyExecuteAndFinalizeUnoptimizedCompilationJobs( break; case CompilationJob::FAILED: - return false; + compilation_succeeded = false; + // Proceed finalizing other functions in case they don't have uncompiled + // data. + continue; case CompilationJob::RETRY_ON_MAIN_THREAD: // This should not happen on the main thread. @@ -881,7 +897,7 @@ bool IterativelyExecuteAndFinalizeUnoptimizedCompilationJobs( parse_info->pending_error_handler()->PrepareWarnings(isolate); } - return true; + return compilation_succeeded; } bool FinalizeDeferredUnoptimizedCompilationJobs( diff --git a/src/objects/shared-function-info.cc b/src/objects/shared-function-info.cc index 05a98c9807ef..3fea3706e74c 100644 --- a/src/objects/shared-function-info.cc +++ b/src/objects/shared-function-info.cc @@ -571,9 +571,15 @@ void SharedFunctionInfo::InitFromFunctionLiteral( raw_sfi.UpdateExpectedNofPropertiesFromEstimate(lit); } + CreateAndSetUncompiledData(isolate, shared_info, lit); +} +template +void SharedFunctionInfo::CreateAndSetUncompiledData( + IsolateT* isolate, Handle shared_info, + FunctionLiteral* lit) { + DCHECK(!shared_info->HasUncompiledData()); Handle data; - ProducedPreparseData* scope_data = lit->produced_preparse_data(); if (scope_data != nullptr) { Handle preparse_data = scope_data->Serialize(isolate); @@ -611,6 +617,15 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo:: LocalIsolate* isolate, Handle shared_info, FunctionLiteral* lit, bool is_toplevel); +template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo:: + CreateAndSetUncompiledData(Isolate* isolate, + Handle shared_info, + FunctionLiteral* lit); +template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo:: + CreateAndSetUncompiledData( + LocalIsolate* isolate, Handle shared_info, + FunctionLiteral* lit); + uint16_t SharedFunctionInfo::get_property_estimate_from_literal( FunctionLiteral* literal) { int estimate = literal->expected_property_count(); diff --git a/src/objects/shared-function-info.h b/src/objects/shared-function-info.h index 5336c3e22332..b7044459272f 100644 --- a/src/objects/shared-function-info.h +++ b/src/objects/shared-function-info.h @@ -603,6 +603,11 @@ class SharedFunctionInfo Handle shared_info, FunctionLiteral* lit, bool is_toplevel); + template + static void CreateAndSetUncompiledData(IsolateT* isolate, + Handle shared_info, + FunctionLiteral* lit); + // Updates the expected number of properties based on estimate from parser. void UpdateExpectedNofPropertiesFromEstimate(FunctionLiteral* literal); void UpdateAndFinalizeExpectedNofPropertiesFromEstimate(