Commit 2b8cc34b authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[offthread] Resolve parallel tasks in off-thread merge

Parallel tasks have to be resolved to their SharedFunctionInfos on the
main thread, so do so for off-thread finalizations.

Bug: chromium:1011762
Change-Id: I1f0c510630b820cad191db614960ed734218bf0e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2110018
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67362}
parent 1aa51b49
...@@ -1041,14 +1041,13 @@ bool FailWithPendingExceptionAfterOffThreadFinalization( ...@@ -1041,14 +1041,13 @@ bool FailWithPendingExceptionAfterOffThreadFinalization(
return false; return false;
} }
void FinalizeScriptCompilation(Isolate* isolate, Handle<Script> script, void FinalizeScriptCompilation(
ParseInfo* parse_info) { Isolate* isolate, Handle<Script> script,
UnoptimizedCompileState::ParallelTasks* parallel_tasks) {
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
if (parallel_tasks) {
// Register any pending parallel tasks with the associated SFI. CompilerDispatcher* dispatcher = parallel_tasks->dispatcher();
if (parse_info->parallel_tasks()) { for (auto& it : *parallel_tasks) {
CompilerDispatcher* dispatcher = parse_info->parallel_tasks()->dispatcher();
for (auto& it : *parse_info->parallel_tasks()) {
FunctionLiteral* literal = it.first; FunctionLiteral* literal = it.first;
CompilerDispatcher::JobId job_id = it.second; CompilerDispatcher::JobId job_id = it.second;
MaybeHandle<SharedFunctionInfo> maybe_shared_for_task = MaybeHandle<SharedFunctionInfo> maybe_shared_for_task =
...@@ -1063,12 +1062,6 @@ void FinalizeScriptCompilation(Isolate* isolate, Handle<Script> script, ...@@ -1063,12 +1062,6 @@ void FinalizeScriptCompilation(Isolate* isolate, Handle<Script> script,
} }
} }
void FinalizeScriptCompilation(OffThreadIsolate* isolate, Handle<Script> script,
ParseInfo* parse_info) {
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
DCHECK(!parse_info->parallel_tasks());
}
template <typename LocalIsolate> template <typename LocalIsolate>
MaybeHandle<SharedFunctionInfo> FinalizeTopLevel( MaybeHandle<SharedFunctionInfo> FinalizeTopLevel(
ParseInfo* parse_info, Handle<Script> script, LocalIsolate* isolate, ParseInfo* parse_info, Handle<Script> script, LocalIsolate* isolate,
...@@ -1089,13 +1082,8 @@ MaybeHandle<SharedFunctionInfo> FinalizeTopLevel( ...@@ -1089,13 +1082,8 @@ MaybeHandle<SharedFunctionInfo> FinalizeTopLevel(
// Finalize compilation of the unoptimized bytecode or asm-js data. // Finalize compilation of the unoptimized bytecode or asm-js data.
if (!FinalizeUnoptimizedCode(parse_info, isolate, shared_info, if (!FinalizeUnoptimizedCode(parse_info, isolate, shared_info,
outer_function_job, inner_function_jobs)) { outer_function_job, inner_function_jobs)) {
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
return MaybeHandle<SharedFunctionInfo>(); return MaybeHandle<SharedFunctionInfo>();
} }
FinalizeScriptCompilation(isolate, script, parse_info);
return shared_info; return shared_info;
} }
...@@ -1139,7 +1127,7 @@ MaybeHandle<SharedFunctionInfo> CompileToplevel( ...@@ -1139,7 +1127,7 @@ MaybeHandle<SharedFunctionInfo> CompileToplevel(
return MaybeHandle<SharedFunctionInfo>(); return MaybeHandle<SharedFunctionInfo>();
} }
FinalizeScriptCompilation(isolate, script, parse_info); FinalizeScriptCompilation(isolate, script, parse_info->parallel_tasks());
return shared_info; return shared_info;
} }
...@@ -1357,8 +1345,9 @@ void BackgroundCompileTask::Run() { ...@@ -1357,8 +1345,9 @@ void BackgroundCompileTask::Run() {
Handle<SharedFunctionInfo> result; Handle<SharedFunctionInfo> result;
if (!maybe_result.ToHandle(&result)) { if (!maybe_result.ToHandle(&result)) {
compile_state_.pending_error_handler()->PrepareErrorsOffThread( DCHECK(compile_state_.pending_error_handler()->has_pending_error());
isolate, script, info_->ast_value_factory()); FailWithPendingException(isolate, script, info_.get(),
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
} }
outer_function_sfi_ = isolate->TransferHandle(maybe_result); outer_function_sfi_ = isolate->TransferHandle(maybe_result);
...@@ -2611,7 +2600,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript( ...@@ -2611,7 +2600,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
origin_options, NOT_NATIVES_CODE); origin_options, NOT_NATIVES_CODE);
if (maybe_result.is_null()) { if (maybe_result.is_null()) {
// Parsing has failed - report error messages. // Off-thread parse, compile or finalization has failed - report error
// messages.
FailWithPendingExceptionAfterOffThreadFinalization( FailWithPendingExceptionAfterOffThreadFinalization(
isolate, script, task->pending_error_handler()); isolate, script, task->pending_error_handler());
} else { } else {
...@@ -2639,6 +2629,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript( ...@@ -2639,6 +2629,8 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
} }
}); });
} }
FinalizeScriptCompilation(isolate, script, task->parallel_tasks());
} }
} else { } else {
ParseInfo* parse_info = task->info(); ParseInfo* parse_info = task->info();
...@@ -2652,21 +2644,20 @@ Compiler::GetSharedFunctionInfoForStreamedScript( ...@@ -2652,21 +2644,20 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
task->parser()->UpdateStatistics(isolate, script); task->parser()->UpdateStatistics(isolate, script);
task->parser()->HandleSourceURLComments(isolate, script); task->parser()->HandleSourceURLComments(isolate, script);
if (parse_info->literal() == nullptr || !task->outer_function_job()) { if (parse_info->literal() != nullptr && task->outer_function_job()) {
// Parsing has failed - report error messages. // Off-thread parse & compile has succeeded - finalize compilation.
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
} else {
// Parsing has succeeded - finalize compilation.
maybe_result = FinalizeTopLevel(parse_info, script, isolate, maybe_result = FinalizeTopLevel(parse_info, script, isolate,
task->outer_function_job(), task->outer_function_job(),
task->inner_function_jobs()); task->inner_function_jobs());
if (maybe_result.is_null()) { }
// Finalization failed - throw an exception.
FailWithPendingException( if (maybe_result.is_null()) {
isolate, script, parse_info, // Compilation failed - throw an exception.
Compiler::ClearExceptionFlag::KEEP_EXCEPTION); FailWithPendingException(isolate, script, parse_info,
} Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
} else {
FinalizeScriptCompilation(isolate, script,
parse_info->parallel_tasks());
} }
} }
......
...@@ -394,6 +394,9 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask { ...@@ -394,6 +394,9 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
PendingCompilationErrorHandler* pending_error_handler() { PendingCompilationErrorHandler* pending_error_handler() {
return compile_state_.pending_error_handler(); return compile_state_.pending_error_handler();
} }
UnoptimizedCompileState::ParallelTasks* parallel_tasks() {
return compile_state_.parallel_tasks();
}
MaybeHandle<SharedFunctionInfo> outer_function_sfi() { MaybeHandle<SharedFunctionInfo> outer_function_sfi() {
DCHECK_NOT_NULL(off_thread_isolate_); DCHECK_NOT_NULL(off_thread_isolate_);
return outer_function_sfi_.ToHandle(); return outer_function_sfi_.ToHandle();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment