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(