Commit e0df158b authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[offthread] Fall-back to main-thread finalization for asm.js

asm-to-wasm doesn't support off-thread finalization, so disable it if an
asm compilation job is successfully executed. Note that in the future,
we could instead have a hybrid off-thread and main-thread finalization
for mixed JS and asm.js scripts, but for now that's probably
unncecessary.

Bug: chromium:1011762
Change-Id: I52c8f31fa13790e03ccf3196dbef471bca387bc5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2110017
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67364}
parent 9f43850f
......@@ -187,7 +187,8 @@ class AsmJsCompilationJob final : public UnoptimizedCompilationJob {
explicit AsmJsCompilationJob(ParseInfo* parse_info, FunctionLiteral* literal,
AccountingAllocator* allocator)
: UnoptimizedCompilationJob(parse_info->stack_limit(), parse_info,
&compilation_info_),
&compilation_info_,
CanOffThreadFinalize::kNo),
allocator_(allocator),
zone_(allocator, ZONE_NAME),
compilation_info_(&zone_, parse_info, literal),
......
......@@ -1274,6 +1274,20 @@ class OffThreadParseInfoScope {
DISALLOW_COPY_AND_ASSIGN(OffThreadParseInfoScope);
};
bool CanOffThreadFinalizeAllJobs(
UnoptimizedCompilationJob* outer_job,
const UnoptimizedCompilationJobList& inner_function_jobs) {
if (!outer_job->can_off_thread_finalize()) return false;
for (auto& job : inner_function_jobs) {
if (!job->can_off_thread_finalize()) {
return false;
}
}
return true;
}
} // namespace
void BackgroundCompileTask::Run() {
......@@ -1311,7 +1325,19 @@ void BackgroundCompileTask::Run() {
language_mode_ = info_->language_mode();
collected_source_positions_ = info_->flags().collect_source_positions();
if (!finalize_on_background_thread_) return;
// We don't currently support off-thread finalization for some jobs (namely,
// asm.js), so release the off-thread isolate and fall back to main-thread
// finalization.
// TODO(leszeks): Still finalize Ignition tasks on the background thread,
// and fallback to main-thread finalization for asm.js jobs only.
finalize_on_background_thread_ =
finalize_on_background_thread_ &&
CanOffThreadFinalizeAllJobs(outer_function_job(), *inner_function_jobs());
if (!finalize_on_background_thread_) {
off_thread_isolate_.reset();
return;
}
// ---
// At this point, off-thread compilation has completed and we are off-thread
......
......@@ -248,12 +248,17 @@ class V8_EXPORT_PRIVATE CompilationJob {
// Either of phases can either fail or succeed.
class UnoptimizedCompilationJob : public CompilationJob {
public:
enum class CanOffThreadFinalize : bool { kYes = true, kNo = false };
UnoptimizedCompilationJob(uintptr_t stack_limit, ParseInfo* parse_info,
UnoptimizedCompilationInfo* compilation_info)
UnoptimizedCompilationInfo* compilation_info,
CanOffThreadFinalize can_off_thread_finalize)
: CompilationJob(State::kReadyToExecute),
stack_limit_(stack_limit),
parse_info_(parse_info),
compilation_info_(compilation_info) {}
compilation_info_(compilation_info),
can_off_thread_finalize_(can_off_thread_finalize ==
CanOffThreadFinalize::kYes) {}
// Executes the compile job. Can be called on a background thread.
V8_WARN_UNUSED_RESULT Status ExecuteJob();
......@@ -278,6 +283,8 @@ class UnoptimizedCompilationJob : public CompilationJob {
uintptr_t stack_limit() const { return stack_limit_; }
bool can_off_thread_finalize() const { return can_off_thread_finalize_; }
protected:
// Overridden by the actual implementation.
virtual Status ExecuteJobImpl() = 0;
......@@ -292,6 +299,7 @@ class UnoptimizedCompilationJob : public CompilationJob {
UnoptimizedCompilationInfo* compilation_info_;
base::TimeDelta time_taken_to_execute_;
base::TimeDelta time_taken_to_finalize_;
bool can_off_thread_finalize_;
};
// A base class for optimized compilation jobs.
......
......@@ -149,7 +149,7 @@ InterpreterCompilationJob::InterpreterCompilationJob(
AccountingAllocator* allocator,
std::vector<FunctionLiteral*>* eager_inner_literals)
: UnoptimizedCompilationJob(parse_info->stack_limit(), parse_info,
&compilation_info_),
&compilation_info_, CanOffThreadFinalize::kYes),
zone_(allocator, ZONE_NAME),
compilation_info_(&zone_, parse_info, literal),
generator_(&compilation_info_, parse_info->ast_string_constants(),
......
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