Commit 44ca9863 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

Revert "[wasm] Move code generation fully to background task."

This reverts commit 231b3e15.

Reason for revert: Flakes in inspector/debugger/wasm-stack

Original change's description:
> [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/1128743
> Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#54324}

TBR=mstarzinger@chromium.org,clemensh@chromium.org

Change-Id: Ice5d80425cebd3921d9683d06f70d5173f663e42
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7921
Reviewed-on: https://chromium-review.googlesource.com/1129059Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54326}
parent 916925f3
......@@ -1053,10 +1053,18 @@ 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(nullptr, &code_desc);
code_generator->tasm()->GetCode(isolate, &code_desc);
wasm::WasmCode* code = native_module_->AddCode(
data_.wasm_function_index(), code_desc,
......@@ -1066,13 +1074,15 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
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(
nullptr, &disassembler_stream, code->instructions().start(),
isolate, &disassembler_stream, code->instructions().start(),
code->instructions().start() + code->safepoint_table_offset(),
CodeReference(code));
for (auto const c : disassembler_stream.str()) {
......@@ -1088,16 +1098,6 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
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());
......
......@@ -5258,6 +5258,22 @@ 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,7 +725,6 @@ 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,19 +387,15 @@ 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