Commit 231b3e15 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Move code generation fully to background task.

This moves the entire code generation phase (including code emission
into the native module) into the background task. The code manager is
fully thread safe by now and there are no Isolate-bound steps anymore.

R=clemensh@chromium.org
BUG=v8:7921

Change-Id: Ie3e8565e126bfdb58bf472291a1f9fbebe7b5431
Reviewed-on: https://chromium-review.googlesource.com/1128743Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54324}
parent f659efb1
......@@ -1053,18 +1053,10 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
pipeline_.ComputeScheduledGraph();
if (!pipeline_.SelectInstructions(&linkage_)) return FAILED;
pipeline_.AssembleCode(&linkage_);
return SUCCEEDED;
}
size_t PipelineWasmCompilationJob::AllocatedMemory() const {
return pipeline_.data_->zone_stats()->GetCurrentAllocatedBytes();
}
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
Isolate* isolate) {
CodeGenerator* code_generator = pipeline_.data_->code_generator();
CodeDesc code_desc;
code_generator->tasm()->GetCode(isolate, &code_desc);
code_generator->tasm()->GetCode(nullptr, &code_desc);
wasm::WasmCode* code = native_module_->AddCode(
data_.wasm_function_index(), code_desc,
......@@ -1074,15 +1066,13 @@ PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
data_.wasm_compilation_data()->GetProtectedInstructions(),
code_generator->GetSourcePositionTable(), wasm::WasmCode::kTurbofan);
if (!code) return FAILED;
if (data_.info()->trace_turbo_json_enabled()) {
TurboJsonFile json_of(data_.info(), std::ios_base::app);
json_of << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\"";
#ifdef ENABLE_DISASSEMBLER
std::stringstream disassembler_stream;
Disassembler::Decode(
isolate, &disassembler_stream, code->instructions().start(),
nullptr, &disassembler_stream, code->instructions().start(),
code->instructions().start() + code->safepoint_table_offset(),
CodeReference(code));
for (auto const c : disassembler_stream.str()) {
......@@ -1098,6 +1088,16 @@ PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
return SUCCEEDED;
}
size_t PipelineWasmCompilationJob::AllocatedMemory() const {
return pipeline_.data_->zone_stats()->GetCurrentAllocatedBytes();
}
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
Isolate* isolate) {
UNREACHABLE(); // Finalize should always be skipped for WasmCompilationJob.
return SUCCEEDED;
}
template <typename Phase>
void PipelineImpl::Run() {
PipelineRunScope scope(this->data_, Phase::phase_name());
......
......@@ -5246,22 +5246,6 @@ wasm::WasmCode* TurbofanWasmCompilationUnit::FinishCompilation(
return nullptr;
}
base::ElapsedTimer codegen_timer;
if (FLAG_trace_wasm_decode_time) {
codegen_timer.Start();
}
if (job_->FinalizeJob(wasm_unit_->isolate_) != CompilationJob::SUCCEEDED) {
return nullptr;
}
if (FLAG_trace_wasm_decode_time) {
double codegen_ms = codegen_timer.Elapsed().InMillisecondsF();
PrintF("wasm-code-generation ok: %u bytes, %0.3f ms code generation\n",
static_cast<unsigned>(wasm_unit_->func_body_.end -
wasm_unit_->func_body_.start),
codegen_ms);
}
return job_->compilation_info()->wasm_code();
}
......
......@@ -725,6 +725,7 @@ void NativeModule::DisableTrapHandler() {
NativeModule::~NativeModule() {
TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this));
compilation_state_.reset(); // Cancels tasks, needs to be done first.
wasm_code_manager_->FreeNativeModule(this);
}
......
......@@ -387,15 +387,19 @@ class V8_EXPORT_PRIVATE NativeModule final {
// Jump table used to easily redirect wasm function calls.
WasmCode* jump_table_ = nullptr;
// The compilation state keeps track of compilation tasks for this module.
// Note that its destructor blocks until all tasks are finished/aborted and
// hence needs to be destructed first when this native module dies.
std::unique_ptr<CompilationState, CompilationStateDeleter> compilation_state_;
// This mutex protects concurrent calls to {AddCode} and {AddCodeCopy}.
mutable base::Mutex allocation_mutex_;
DisjointAllocationPool free_code_space_;
DisjointAllocationPool allocated_code_space_;
std::list<VirtualMemory> owned_code_space_;
WasmCodeManager* wasm_code_manager_;
// This mutex protects concurrent calls to {AddCode} and {AddCodeCopy}.
mutable base::Mutex allocation_mutex_;
size_t committed_code_space_ = 0;
int modification_scope_depth_ = 0;
bool can_request_more_memory_;
......
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