Skip to content

Commit

Permalink
Merged: Squashed multiple commits.
Browse files Browse the repository at this point in the history
Merged: [runtime] Create unoptimized data even if compilation is aborted
(cherry picked from commit 0e07abe)

Merged: [class] Export SharedFunctionInfo::CreateAndSetUncompiledData
(cherry picked from commit 1b55293)

Bug: chromium:1441254
Change-Id: I3c78d3972295c147d79d3734a4869c9b36f19433
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4603931
Auto-Submit: Igor Sheludko <[email protected]>
Reviewed-by: Jakob Kummerow <[email protected]>
Cr-Commit-Position: refs/branch-heads/11.5@{v8#10}
Cr-Branched-From: 0c4044b-refs/heads/11.5.150@{#1}
Cr-Branched-From: b71d303-refs/heads/main@{#87781}
  • Loading branch information
isheludko authored and jakobkummerow committed Jun 9, 2023
1 parent 6cdd546 commit 8459fe6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/codegen/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ bool IterativelyExecuteAndFinalizeUnoptimizedCompilationJobs(
std::vector<FunctionLiteral*> 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();
Expand All @@ -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);

Expand All @@ -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.
Expand All @@ -881,7 +897,7 @@ bool IterativelyExecuteAndFinalizeUnoptimizedCompilationJobs(
parse_info->pending_error_handler()->PrepareWarnings(isolate);
}

return true;
return compilation_succeeded;
}

bool FinalizeDeferredUnoptimizedCompilationJobs(
Expand Down
17 changes: 16 additions & 1 deletion src/objects/shared-function-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,15 @@ void SharedFunctionInfo::InitFromFunctionLiteral(

raw_sfi.UpdateExpectedNofPropertiesFromEstimate(lit);
}
CreateAndSetUncompiledData(isolate, shared_info, lit);
}

template <typename IsolateT>
void SharedFunctionInfo::CreateAndSetUncompiledData(
IsolateT* isolate, Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit) {
DCHECK(!shared_info->HasUncompiledData());
Handle<UncompiledData> data;

ProducedPreparseData* scope_data = lit->produced_preparse_data();
if (scope_data != nullptr) {
Handle<PreparseData> preparse_data = scope_data->Serialize(isolate);
Expand Down Expand Up @@ -611,6 +617,15 @@ template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo::
LocalIsolate* isolate, Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit, bool is_toplevel);

template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo::
CreateAndSetUncompiledData<Isolate>(Isolate* isolate,
Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit);
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo::
CreateAndSetUncompiledData<LocalIsolate>(
LocalIsolate* isolate, Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit);

uint16_t SharedFunctionInfo::get_property_estimate_from_literal(
FunctionLiteral* literal) {
int estimate = literal->expected_property_count();
Expand Down
5 changes: 5 additions & 0 deletions src/objects/shared-function-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ class SharedFunctionInfo
Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit, bool is_toplevel);

template <typename IsolateT>
static void CreateAndSetUncompiledData(IsolateT* isolate,
Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit);

// Updates the expected number of properties based on estimate from parser.
void UpdateExpectedNofPropertiesFromEstimate(FunctionLiteral* literal);
void UpdateAndFinalizeExpectedNofPropertiesFromEstimate(
Expand Down

0 comments on commit 8459fe6

Please sign in to comment.