Commit 924ab19b authored by Thibaud Michaud's avatar Thibaud Michaud Committed by Commit Bot

Reland "[wasm] Compile JS to WASM wrappers asynchronously"

Revert reason should be fixed with this CL:
https://chromium-review.googlesource.com/c/v8/v8/+/1722554

The underlying problem was the isolate being accessed from the
background compilation thread. Other known places where the isolate was
used have also been fixed in these CLs:
https://chromium-review.googlesource.com/c/v8/v8/+/1722555
https://chromium-review.googlesource.com/c/v8/v8/+/1722559
https://chromium-review.googlesource.com/c/v8/v8/+/1722556

Original CL:
> Reland "[wasm] Compile JS to WASM wrappers asynchronously"
>
> Original CL had an issue with builtins being accessed through the
> isolate after the isolate died. See:
> https://ci.chromium.org/p/v8/builders/try.triggered/v8_win64_rel_ng_triggered/b8907837534672203296
>
> Initial upload is the original CL and the following patch sets will
> attempt to fix it.
>
> Original CL:
>
> > [wasm] Compile JS to WASM wrappers asynchronously
> >
> > R=mstarzinger@chromium.org, ahaas@chromium.org
> >
> > Bug: v8:9231
> > Change-Id: I9e18073bbe25bf8c9c5f9ace102316e6209d0459
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1669699
> > Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
> > Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#62672}
>
> R=​mstarzinger@chromium.org, ahaas@chromium.org
>
> Bug: v8:9231
> Change-Id: I1b01d5d2b9f728d6f6a90fe9b642f5ba3bf686eb
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1708485
> Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#62918}

R=mstarzinger@chromium.org

Bug: v8:9231, v8:9554
Change-Id: I40443e7228eb26d6669e826e96073b20fa038c15
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1725619Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62985}
parent 743ce772
...@@ -289,13 +289,7 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, ...@@ -289,13 +289,7 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
} else if (target_is_isolate_independent_builtin && } else if (target_is_isolate_independent_builtin &&
options().inline_offheap_trampolines) { options().inline_offheap_trampolines) {
// Inline the trampoline. // Inline the trampoline.
RecordCommentForOffHeapTrampoline(builtin_index); CallBuiltin(builtin_index);
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
// Use ip directly instead of using UseScratchRegisterScope, as we do not
// preserve scratch registers across calls.
mov(ip, Operand(entry, RelocInfo::OFF_HEAP_TARGET));
Call(ip, cond);
return; return;
} }
...@@ -323,6 +317,18 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) { ...@@ -323,6 +317,18 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) {
Call(builtin_index); Call(builtin_index);
} }
void TurboAssembler::CallBuiltin(int builtin_index, Condition cond) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
DCHECK(FLAG_embedded_builtins);
RecordCommentForOffHeapTrampoline(builtin_index);
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
// Use ip directly instead of using UseScratchRegisterScope, as we do not
// preserve scratch registers across calls.
mov(ip, Operand(entry, RelocInfo::OFF_HEAP_TARGET));
Call(ip, cond);
}
void TurboAssembler::LoadCodeObjectEntry(Register destination, void TurboAssembler::LoadCodeObjectEntry(Register destination,
Register code_object) { Register code_object) {
// Code objects are called differently depending on whether we are generating // Code objects are called differently depending on whether we are generating
...@@ -1832,6 +1838,8 @@ void TurboAssembler::TruncateDoubleToI(Isolate* isolate, Zone* zone, ...@@ -1832,6 +1838,8 @@ void TurboAssembler::TruncateDoubleToI(Isolate* isolate, Zone* zone,
if (stub_mode == StubCallMode::kCallWasmRuntimeStub) { if (stub_mode == StubCallMode::kCallWasmRuntimeStub) {
Call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL); Call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL);
} else if (options().inline_offheap_trampolines) {
CallBuiltin(Builtins::kDoubleToI);
} else { } else {
Call(BUILTIN_CODE(isolate, DoubleToI), RelocInfo::CODE_TARGET); Call(BUILTIN_CODE(isolate, DoubleToI), RelocInfo::CODE_TARGET);
} }
......
...@@ -304,6 +304,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase { ...@@ -304,6 +304,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// register. // register.
void LoadEntryFromBuiltinIndex(Register builtin_index); void LoadEntryFromBuiltinIndex(Register builtin_index);
void CallBuiltinByIndex(Register builtin_index) override; void CallBuiltinByIndex(Register builtin_index) override;
void CallBuiltin(int builtin_index, Condition cond = al);
void LoadCodeObjectEntry(Register destination, Register code_object) override; void LoadCodeObjectEntry(Register destination, Register code_object) override;
void CallCodeObject(Register code_object) override; void CallCodeObject(Register code_object) override;
......
...@@ -1900,14 +1900,7 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode) { ...@@ -1900,14 +1900,7 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode) {
if (isolate()->builtins()->IsBuiltinHandle(code, &builtin_index) && if (isolate()->builtins()->IsBuiltinHandle(code, &builtin_index) &&
Builtins::IsIsolateIndependent(builtin_index)) { Builtins::IsIsolateIndependent(builtin_index)) {
// Inline the trampoline. // Inline the trampoline.
RecordCommentForOffHeapTrampoline(builtin_index); CallBuiltin(builtin_index);
CHECK_NE(builtin_index, Builtins::kNoBuiltinId);
UseScratchRegisterScope temps(this);
Register scratch = temps.AcquireX();
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
Ldr(scratch, Operand(entry, RelocInfo::OFF_HEAP_TARGET));
Call(scratch);
return; return;
} }
} }
...@@ -1951,6 +1944,19 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) { ...@@ -1951,6 +1944,19 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) {
Call(builtin_index); Call(builtin_index);
} }
void TurboAssembler::CallBuiltin(int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
DCHECK(FLAG_embedded_builtins);
RecordCommentForOffHeapTrampoline(builtin_index);
CHECK_NE(builtin_index, Builtins::kNoBuiltinId);
UseScratchRegisterScope temps(this);
Register scratch = temps.AcquireX();
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
Ldr(scratch, Operand(entry, RelocInfo::OFF_HEAP_TARGET));
Call(scratch);
}
void TurboAssembler::LoadCodeObjectEntry(Register destination, void TurboAssembler::LoadCodeObjectEntry(Register destination,
Register code_object) { Register code_object) {
// Code objects are called differently depending on whether we are generating // Code objects are called differently depending on whether we are generating
...@@ -2374,6 +2380,8 @@ void TurboAssembler::TruncateDoubleToI(Isolate* isolate, Zone* zone, ...@@ -2374,6 +2380,8 @@ void TurboAssembler::TruncateDoubleToI(Isolate* isolate, Zone* zone,
// DoubleToI preserves any registers it needs to clobber. // DoubleToI preserves any registers it needs to clobber.
if (stub_mode == StubCallMode::kCallWasmRuntimeStub) { if (stub_mode == StubCallMode::kCallWasmRuntimeStub) {
Call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL); Call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL);
} else if (options().inline_offheap_trampolines) {
CallBuiltin(Builtins::kDoubleToI);
} else { } else {
Call(BUILTIN_CODE(isolate, DoubleToI), RelocInfo::CODE_TARGET); Call(BUILTIN_CODE(isolate, DoubleToI), RelocInfo::CODE_TARGET);
} }
......
...@@ -896,6 +896,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase { ...@@ -896,6 +896,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// register. // register.
void LoadEntryFromBuiltinIndex(Register builtin_index); void LoadEntryFromBuiltinIndex(Register builtin_index);
void CallBuiltinByIndex(Register builtin_index) override; void CallBuiltinByIndex(Register builtin_index) override;
void CallBuiltin(int builtin_index);
void LoadCodeObjectEntry(Register destination, Register code_object) override; void LoadCodeObjectEntry(Register destination, Register code_object) override;
void CallCodeObject(Register code_object) override; void CallCodeObject(Register code_object) override;
......
...@@ -1875,11 +1875,7 @@ void TurboAssembler::Call(Handle<Code> code_object, RelocInfo::Mode rmode) { ...@@ -1875,11 +1875,7 @@ void TurboAssembler::Call(Handle<Code> code_object, RelocInfo::Mode rmode) {
if (isolate()->builtins()->IsBuiltinHandle(code_object, &builtin_index) && if (isolate()->builtins()->IsBuiltinHandle(code_object, &builtin_index) &&
Builtins::IsIsolateIndependent(builtin_index)) { Builtins::IsIsolateIndependent(builtin_index)) {
// Inline the trampoline. // Inline the trampoline.
RecordCommentForOffHeapTrampoline(builtin_index); CallBuiltin(builtin_index);
CHECK_NE(builtin_index, Builtins::kNoBuiltinId);
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
call(entry, RelocInfo::OFF_HEAP_TARGET);
return; return;
} }
} }
...@@ -1907,6 +1903,16 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) { ...@@ -1907,6 +1903,16 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) {
call(builtin_index); call(builtin_index);
} }
void TurboAssembler::CallBuiltin(int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
DCHECK(FLAG_embedded_builtins);
RecordCommentForOffHeapTrampoline(builtin_index);
CHECK_NE(builtin_index, Builtins::kNoBuiltinId);
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
call(entry, RelocInfo::OFF_HEAP_TARGET);
}
void TurboAssembler::LoadCodeObjectEntry(Register destination, void TurboAssembler::LoadCodeObjectEntry(Register destination,
Register code_object) { Register code_object) {
// Code objects are called differently depending on whether we are generating // Code objects are called differently depending on whether we are generating
......
...@@ -91,6 +91,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase { ...@@ -91,6 +91,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// register. // register.
void LoadEntryFromBuiltinIndex(Register builtin_index); void LoadEntryFromBuiltinIndex(Register builtin_index);
void CallBuiltinByIndex(Register builtin_index) override; void CallBuiltinByIndex(Register builtin_index) override;
void CallBuiltin(int builtin_index);
void LoadCodeObjectEntry(Register destination, Register code_object) override; void LoadCodeObjectEntry(Register destination, Register code_object) override;
void CallCodeObject(Register code_object) override; void CallCodeObject(Register code_object) override;
......
...@@ -1594,12 +1594,7 @@ void TurboAssembler::Call(Handle<Code> code_object, RelocInfo::Mode rmode) { ...@@ -1594,12 +1594,7 @@ void TurboAssembler::Call(Handle<Code> code_object, RelocInfo::Mode rmode) {
if (isolate()->builtins()->IsBuiltinHandle(code_object, &builtin_index) && if (isolate()->builtins()->IsBuiltinHandle(code_object, &builtin_index) &&
Builtins::IsIsolateIndependent(builtin_index)) { Builtins::IsIsolateIndependent(builtin_index)) {
// Inline the trampoline. // Inline the trampoline.
RecordCommentForOffHeapTrampoline(builtin_index); CallBuiltin(builtin_index);
CHECK_NE(builtin_index, Builtins::kNoBuiltinId);
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
Move(kScratchRegister, entry, RelocInfo::OFF_HEAP_TARGET);
call(kScratchRegister);
return; return;
} }
} }
...@@ -1634,6 +1629,17 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) { ...@@ -1634,6 +1629,17 @@ void TurboAssembler::CallBuiltinByIndex(Register builtin_index) {
Call(EntryFromBuiltinIndexAsOperand(builtin_index)); Call(EntryFromBuiltinIndexAsOperand(builtin_index));
} }
void TurboAssembler::CallBuiltin(int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
DCHECK(FLAG_embedded_builtins);
RecordCommentForOffHeapTrampoline(builtin_index);
CHECK_NE(builtin_index, Builtins::kNoBuiltinId);
EmbeddedData d = EmbeddedData::FromBlob();
Address entry = d.InstructionStartOfBuiltin(builtin_index);
Move(kScratchRegister, entry, RelocInfo::OFF_HEAP_TARGET);
call(kScratchRegister);
}
void TurboAssembler::LoadCodeObjectEntry(Register destination, void TurboAssembler::LoadCodeObjectEntry(Register destination,
Register code_object) { Register code_object) {
// Code objects are called differently depending on whether we are generating // Code objects are called differently depending on whether we are generating
......
...@@ -344,6 +344,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase { ...@@ -344,6 +344,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
Operand EntryFromBuiltinIndexAsOperand(Register builtin_index); Operand EntryFromBuiltinIndexAsOperand(Register builtin_index);
void CallBuiltinByIndex(Register builtin_index) override; void CallBuiltinByIndex(Register builtin_index) override;
void CallBuiltin(int builtin_index);
void LoadCodeObjectEntry(Register destination, Register code_object) override; void LoadCodeObjectEntry(Register destination, Register code_object) override;
void CallCodeObject(Register code_object) override; void CallCodeObject(Register code_object) override;
......
...@@ -91,6 +91,7 @@ CodeGenerator::CodeGenerator( ...@@ -91,6 +91,7 @@ CodeGenerator::CodeGenerator(
code_kind == Code::WASM_TO_CAPI_FUNCTION || code_kind == Code::WASM_TO_CAPI_FUNCTION ||
code_kind == Code::WASM_TO_JS_FUNCTION || code_kind == Code::WASM_TO_JS_FUNCTION ||
code_kind == Code::WASM_INTERPRETER_ENTRY || code_kind == Code::WASM_INTERPRETER_ENTRY ||
code_kind == Code::JS_TO_WASM_FUNCTION ||
(Builtins::IsBuiltinId(builtin_index) && (Builtins::IsBuiltinId(builtin_index) &&
Builtins::IsWasmRuntimeStub(builtin_index))) { Builtins::IsWasmRuntimeStub(builtin_index))) {
tasm_.set_abort_hard(true); tasm_.set_abort_hard(true);
......
...@@ -256,6 +256,8 @@ class OutOfLineTruncateDoubleToI final : public OutOfLineCode { ...@@ -256,6 +256,8 @@ class OutOfLineTruncateDoubleToI final : public OutOfLineCode {
// Just encode the stub index. This will be patched when the code // Just encode the stub index. This will be patched when the code
// is added to the native module and copied into wasm code space. // is added to the native module and copied into wasm code space.
__ wasm_call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL); __ wasm_call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL);
} else if (tasm()->options().inline_offheap_trampolines) {
__ CallBuiltin(Builtins::kDoubleToI);
} else { } else {
__ Call(BUILTIN_CODE(isolate_, DoubleToI), RelocInfo::CODE_TARGET); __ Call(BUILTIN_CODE(isolate_, DoubleToI), RelocInfo::CODE_TARGET);
} }
......
...@@ -210,6 +210,10 @@ class OutOfLineTruncateDoubleToI final : public OutOfLineCode { ...@@ -210,6 +210,10 @@ class OutOfLineTruncateDoubleToI final : public OutOfLineCode {
// Just encode the stub index. This will be patched when the code // Just encode the stub index. This will be patched when the code
// is added to the native module and copied into wasm code space. // is added to the native module and copied into wasm code space.
__ near_call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL); __ near_call(wasm::WasmCode::kDoubleToI, RelocInfo::WASM_STUB_CALL);
} else if (tasm()->options().inline_offheap_trampolines) {
// With embedded builtins we do not need the isolate here. This allows
// the call to be generated asynchronously.
__ CallBuiltin(Builtins::kDoubleToI);
} else { } else {
__ Call(BUILTIN_CODE(isolate_, DoubleToI), RelocInfo::CODE_TARGET); __ Call(BUILTIN_CODE(isolate_, DoubleToI), RelocInfo::CODE_TARGET);
} }
......
...@@ -110,6 +110,9 @@ class PipelineData { ...@@ -110,6 +110,9 @@ class PipelineData {
may_have_unverifiable_graph_(false), may_have_unverifiable_graph_(false),
zone_stats_(zone_stats), zone_stats_(zone_stats),
pipeline_statistics_(pipeline_statistics), pipeline_statistics_(pipeline_statistics),
roots_relative_addressing_enabled_(
!isolate->serializer_enabled() &&
!isolate->IsGeneratingEmbeddedBuiltins()),
graph_zone_scope_(zone_stats_, ZONE_NAME), graph_zone_scope_(zone_stats_, ZONE_NAME),
graph_zone_(graph_zone_scope_.zone()), graph_zone_(graph_zone_scope_.zone()),
instruction_zone_scope_(zone_stats_, ZONE_NAME), instruction_zone_scope_(zone_stats_, ZONE_NAME),
...@@ -173,12 +176,12 @@ class PipelineData { ...@@ -173,12 +176,12 @@ class PipelineData {
// For CodeStubAssembler and machine graph testing entry point. // For CodeStubAssembler and machine graph testing entry point.
PipelineData(ZoneStats* zone_stats, OptimizedCompilationInfo* info, PipelineData(ZoneStats* zone_stats, OptimizedCompilationInfo* info,
Isolate* isolate, Graph* graph, Schedule* schedule, Isolate* isolate, AccountingAllocator* allocator, Graph* graph,
SourcePositionTable* source_positions, Schedule* schedule, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, JumpOptimizationInfo* jump_opt, NodeOriginTable* node_origins, JumpOptimizationInfo* jump_opt,
const AssemblerOptions& assembler_options) const AssemblerOptions& assembler_options)
: isolate_(isolate), : isolate_(isolate),
allocator_(isolate->allocator()), allocator_(allocator),
info_(info), info_(info),
debug_name_(info_->GetDebugName()), debug_name_(info_->GetDebugName()),
zone_stats_(zone_stats), zone_stats_(zone_stats),
...@@ -451,6 +454,10 @@ class PipelineData { ...@@ -451,6 +454,10 @@ class PipelineData {
const char* debug_name() const { return debug_name_.get(); } const char* debug_name() const { return debug_name_.get(); }
bool roots_relative_addressing_enabled() {
return roots_relative_addressing_enabled_;
}
private: private:
Isolate* const isolate_; Isolate* const isolate_;
wasm::WasmEngine* const wasm_engine_ = nullptr; wasm::WasmEngine* const wasm_engine_ = nullptr;
...@@ -468,6 +475,7 @@ class PipelineData { ...@@ -468,6 +475,7 @@ class PipelineData {
CodeGenerator* code_generator_ = nullptr; CodeGenerator* code_generator_ = nullptr;
Typer* typer_ = nullptr; Typer* typer_ = nullptr;
Typer::Flags typer_flags_ = Typer::kNoFlags; Typer::Flags typer_flags_ = Typer::kNoFlags;
bool roots_relative_addressing_enabled_ = false;
// All objects in the following group of fields are allocated in graph_zone_. // All objects in the following group of fields are allocated in graph_zone_.
// They are all set to nullptr when the graph_zone_ is destroyed. // They are all set to nullptr when the graph_zone_ is destroyed.
...@@ -1046,7 +1054,8 @@ void PipelineCompilationJob::RegisterWeakObjectsInOptimizedCode( ...@@ -1046,7 +1054,8 @@ void PipelineCompilationJob::RegisterWeakObjectsInOptimizedCode(
class WasmHeapStubCompilationJob final : public OptimizedCompilationJob { class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
public: public:
WasmHeapStubCompilationJob(Isolate* isolate, CallDescriptor* call_descriptor, WasmHeapStubCompilationJob(Isolate* isolate, wasm::WasmEngine* wasm_engine,
CallDescriptor* call_descriptor,
std::unique_ptr<Zone> zone, Graph* graph, std::unique_ptr<Zone> zone, Graph* graph,
Code::Kind kind, Code::Kind kind,
std::unique_ptr<char[]> debug_name, std::unique_ptr<char[]> debug_name,
...@@ -1055,16 +1064,19 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob { ...@@ -1055,16 +1064,19 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
// Note that the OptimizedCompilationInfo is not initialized at the time // Note that the OptimizedCompilationInfo is not initialized at the time
// we pass it to the CompilationJob constructor, but it is not // we pass it to the CompilationJob constructor, but it is not
// dereferenced there. // dereferenced there.
: OptimizedCompilationJob(&info_, "TurboFan"), : OptimizedCompilationJob(&info_, "TurboFan",
CompilationJob::State::kReadyToExecute),
debug_name_(std::move(debug_name)), debug_name_(std::move(debug_name)),
info_(CStrVector(debug_name_.get()), graph->zone(), kind), info_(CStrVector(debug_name_.get()), graph->zone(), kind),
call_descriptor_(call_descriptor), call_descriptor_(call_descriptor),
zone_stats_(zone->allocator()), zone_stats_(zone->allocator()),
zone_(std::move(zone)), zone_(std::move(zone)),
graph_(graph), graph_(graph),
data_(&zone_stats_, &info_, isolate, graph_, nullptr, source_positions, data_(&zone_stats_, &info_, isolate, wasm_engine->allocator(), graph_,
nullptr, source_positions,
new (zone_.get()) NodeOriginTable(graph_), nullptr, options), new (zone_.get()) NodeOriginTable(graph_), nullptr, options),
pipeline_(&data_) {} pipeline_(&data_),
wasm_engine_(wasm_engine) {}
~WasmHeapStubCompilationJob() = default; ~WasmHeapStubCompilationJob() = default;
...@@ -1082,30 +1094,33 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob { ...@@ -1082,30 +1094,33 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
Graph* graph_; Graph* graph_;
PipelineData data_; PipelineData data_;
PipelineImpl pipeline_; PipelineImpl pipeline_;
wasm::WasmEngine* wasm_engine_;
DISALLOW_COPY_AND_ASSIGN(WasmHeapStubCompilationJob); DISALLOW_COPY_AND_ASSIGN(WasmHeapStubCompilationJob);
}; };
// static // static
std::unique_ptr<OptimizedCompilationJob> std::unique_ptr<OptimizedCompilationJob>
Pipeline::NewWasmHeapStubCompilationJob(Isolate* isolate, Pipeline::NewWasmHeapStubCompilationJob(
CallDescriptor* call_descriptor, Isolate* isolate, wasm::WasmEngine* wasm_engine,
std::unique_ptr<Zone> zone, CallDescriptor* call_descriptor, std::unique_ptr<Zone> zone, Graph* graph,
Graph* graph, Code::Kind kind, Code::Kind kind, std::unique_ptr<char[]> debug_name,
std::unique_ptr<char[]> debug_name, const AssemblerOptions& options, SourcePositionTable* source_positions) {
const AssemblerOptions& options,
SourcePositionTable* source_positions) {
return base::make_unique<WasmHeapStubCompilationJob>( return base::make_unique<WasmHeapStubCompilationJob>(
isolate, call_descriptor, std::move(zone), graph, kind, isolate, wasm_engine, call_descriptor, std::move(zone), graph, kind,
std::move(debug_name), options, source_positions); std::move(debug_name), options, source_positions);
} }
CompilationJob::Status WasmHeapStubCompilationJob::PrepareJobImpl( CompilationJob::Status WasmHeapStubCompilationJob::PrepareJobImpl(
Isolate* isolate) { Isolate* isolate) {
UNREACHABLE();
}
CompilationJob::Status WasmHeapStubCompilationJob::ExecuteJobImpl() {
std::unique_ptr<PipelineStatistics> pipeline_statistics; std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) { if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(new PipelineStatistics( pipeline_statistics.reset(new PipelineStatistics(
&info_, isolate->GetTurboStatistics(), &zone_stats_)); &info_, wasm_engine_->GetOrCreateTurboStatistics(), &zone_stats_));
pipeline_statistics->BeginPhaseKind("V8.WasmStubCodegen"); pipeline_statistics->BeginPhaseKind("V8.WasmStubCodegen");
} }
if (info_.trace_turbo_json_enabled() || info_.trace_turbo_graph_enabled()) { if (info_.trace_turbo_json_enabled() || info_.trace_turbo_graph_enabled()) {
...@@ -1127,10 +1142,6 @@ CompilationJob::Status WasmHeapStubCompilationJob::PrepareJobImpl( ...@@ -1127,10 +1142,6 @@ CompilationJob::Status WasmHeapStubCompilationJob::PrepareJobImpl(
<< "\", \"source\":\"\",\n\"phases\":["; << "\", \"source\":\"\",\n\"phases\":[";
} }
pipeline_.RunPrintAndVerify("V8.WasmMachineCode", true); pipeline_.RunPrintAndVerify("V8.WasmMachineCode", true);
return CompilationJob::SUCCEEDED;
}
CompilationJob::Status WasmHeapStubCompilationJob::ExecuteJobImpl() {
pipeline_.ComputeScheduledGraph(); pipeline_.ComputeScheduledGraph();
if (pipeline_.SelectInstructionsAndAssemble(call_descriptor_)) { if (pipeline_.SelectInstructionsAndAssemble(call_descriptor_)) {
return CompilationJob::SUCCEEDED; return CompilationJob::SUCCEEDED;
...@@ -1853,10 +1864,9 @@ struct InstructionSelectionPhase { ...@@ -1853,10 +1864,9 @@ struct InstructionSelectionPhase {
FLAG_turbo_instruction_scheduling FLAG_turbo_instruction_scheduling
? InstructionSelector::kEnableScheduling ? InstructionSelector::kEnableScheduling
: InstructionSelector::kDisableScheduling, : InstructionSelector::kDisableScheduling,
!data->isolate() || data->isolate()->serializer_enabled() || data->roots_relative_addressing_enabled()
data->isolate()->IsGeneratingEmbeddedBuiltins() ? InstructionSelector::kEnableRootsRelativeAddressing
? InstructionSelector::kDisableRootsRelativeAddressing : InstructionSelector::kDisableRootsRelativeAddressing,
: InstructionSelector::kEnableRootsRelativeAddressing,
data->info()->GetPoisoningMitigationLevel(), data->info()->GetPoisoningMitigationLevel(),
data->info()->trace_turbo_json_enabled() data->info()->trace_turbo_json_enabled()
? InstructionSelector::kEnableTraceTurboJson ? InstructionSelector::kEnableTraceTurboJson
...@@ -2353,8 +2363,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub( ...@@ -2353,8 +2363,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub(
JumpOptimizationInfo jump_opt; JumpOptimizationInfo jump_opt;
bool should_optimize_jumps = bool should_optimize_jumps =
isolate->serializer_enabled() && FLAG_turbo_rewrite_far_jumps; isolate->serializer_enabled() && FLAG_turbo_rewrite_far_jumps;
PipelineData data(&zone_stats, &info, isolate, graph, nullptr, PipelineData data(&zone_stats, &info, isolate, isolate->allocator(), graph,
source_positions, &node_origins, nullptr, source_positions, &node_origins,
should_optimize_jumps ? &jump_opt : nullptr, options); should_optimize_jumps ? &jump_opt : nullptr, options);
data.set_verify_graph(FLAG_verify_csa); data.set_verify_graph(FLAG_verify_csa);
std::unique_ptr<PipelineStatistics> pipeline_statistics; std::unique_ptr<PipelineStatistics> pipeline_statistics;
...@@ -2399,10 +2409,10 @@ MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub( ...@@ -2399,10 +2409,10 @@ MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub(
// First run code generation on a copy of the pipeline, in order to be able to // First run code generation on a copy of the pipeline, in order to be able to
// repeat it for jump optimization. The first run has to happen on a temporary // repeat it for jump optimization. The first run has to happen on a temporary
// pipeline to avoid deletion of zones on the main pipeline. // pipeline to avoid deletion of zones on the main pipeline.
PipelineData second_data(&zone_stats, &info, isolate, data.graph(), PipelineData second_data(&zone_stats, &info, isolate, isolate->allocator(),
data.schedule(), data.source_positions(), data.graph(), data.schedule(),
data.node_origins(), data.jump_optimization_info(), data.source_positions(), data.node_origins(),
options); data.jump_optimization_info(), options);
second_data.set_verify_graph(FLAG_verify_csa); second_data.set_verify_graph(FLAG_verify_csa);
PipelineImpl second_pipeline(&second_data); PipelineImpl second_pipeline(&second_data);
second_pipeline.SelectInstructionsAndAssemble(call_descriptor); second_pipeline.SelectInstructionsAndAssemble(call_descriptor);
...@@ -2548,8 +2558,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting( ...@@ -2548,8 +2558,8 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
// Construct a pipeline for scheduling and code generation. // Construct a pipeline for scheduling and code generation.
ZoneStats zone_stats(isolate->allocator()); ZoneStats zone_stats(isolate->allocator());
NodeOriginTable* node_positions = new (info->zone()) NodeOriginTable(graph); NodeOriginTable* node_positions = new (info->zone()) NodeOriginTable(graph);
PipelineData data(&zone_stats, info, isolate, graph, schedule, nullptr, PipelineData data(&zone_stats, info, isolate, isolate->allocator(), graph,
node_positions, nullptr, options); schedule, nullptr, node_positions, nullptr, options);
std::unique_ptr<PipelineStatistics> pipeline_statistics; std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) { if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(new PipelineStatistics( pipeline_statistics.reset(new PipelineStatistics(
......
...@@ -61,9 +61,10 @@ class Pipeline : public AllStatic { ...@@ -61,9 +61,10 @@ class Pipeline : public AllStatic {
// Returns a new compilation job for a wasm heap stub. // Returns a new compilation job for a wasm heap stub.
static std::unique_ptr<OptimizedCompilationJob> NewWasmHeapStubCompilationJob( static std::unique_ptr<OptimizedCompilationJob> NewWasmHeapStubCompilationJob(
Isolate* isolate, CallDescriptor* call_descriptor, Isolate* isolate, wasm::WasmEngine* wasm_engine,
std::unique_ptr<Zone> zone, Graph* graph, Code::Kind kind, CallDescriptor* call_descriptor, std::unique_ptr<Zone> zone, Graph* graph,
std::unique_ptr<char[]> debug_name, const AssemblerOptions& options, Code::Kind kind, std::unique_ptr<char[]> debug_name,
const AssemblerOptions& options,
SourcePositionTable* source_positions = nullptr); SourcePositionTable* source_positions = nullptr);
// Run the pipeline on a machine graph and generate code. // Run the pipeline on a machine graph and generate code.
......
...@@ -6204,8 +6204,8 @@ std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob( ...@@ -6204,8 +6204,8 @@ std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
zone.get(), false, params + 1, CallDescriptor::kNoFlags); zone.get(), false, params + 1, CallDescriptor::kNoFlags);
return Pipeline::NewWasmHeapStubCompilationJob( return Pipeline::NewWasmHeapStubCompilationJob(
isolate, incoming, std::move(zone), graph, Code::JS_TO_WASM_FUNCTION, isolate, wasm_engine, incoming, std::move(zone), graph,
std::move(debug_name), WasmAssemblerOptions()); Code::JS_TO_WASM_FUNCTION, std::move(debug_name), WasmAssemblerOptions());
} }
std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall( std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
...@@ -6624,11 +6624,11 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate, ...@@ -6624,11 +6624,11 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate,
// Run the compilation job synchronously. // Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob( Pipeline::NewWasmHeapStubCompilationJob(
isolate, incoming, std::move(zone), graph, Code::JS_TO_JS_FUNCTION, isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
std::move(debug_name), AssemblerOptions::Default(isolate))); Code::JS_TO_JS_FUNCTION, std::move(debug_name),
AssemblerOptions::Default(isolate)));
if (job->PrepareJob(isolate) == CompilationJob::FAILED || if (job->ExecuteJob() == CompilationJob::FAILED ||
job->ExecuteJob() == CompilationJob::FAILED ||
job->FinalizeJob(isolate) == CompilationJob::FAILED) { job->FinalizeJob(isolate) == CompilationJob::FAILED) {
return {}; return {};
} }
...@@ -6680,11 +6680,11 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) { ...@@ -6680,11 +6680,11 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
// Run the compilation job synchronously. // Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob( Pipeline::NewWasmHeapStubCompilationJob(
isolate, incoming, std::move(zone), graph, Code::C_WASM_ENTRY, isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
std::move(debug_name), AssemblerOptions::Default(isolate))); Code::C_WASM_ENTRY, std::move(debug_name),
AssemblerOptions::Default(isolate)));
if (job->PrepareJob(isolate) == CompilationJob::FAILED || if (job->ExecuteJob() == CompilationJob::FAILED ||
job->ExecuteJob() == CompilationJob::FAILED ||
job->FinalizeJob(isolate) == CompilationJob::FAILED) { job->FinalizeJob(isolate) == CompilationJob::FAILED) {
return {}; return {};
} }
......
...@@ -265,19 +265,15 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate, ...@@ -265,19 +265,15 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
JSToWasmWrapperCompilationUnit::JSToWasmWrapperCompilationUnit( JSToWasmWrapperCompilationUnit::JSToWasmWrapperCompilationUnit(
Isolate* isolate, WasmEngine* wasm_engine, FunctionSig* sig, bool is_import, Isolate* isolate, WasmEngine* wasm_engine, FunctionSig* sig, bool is_import,
const WasmFeatures& enabled_features) const WasmFeatures& enabled_features)
: job_(compiler::NewJSToWasmCompilationJob(isolate, wasm_engine, sig, : is_import_(is_import),
sig_(sig),
job_(compiler::NewJSToWasmCompilationJob(isolate, wasm_engine, sig,
is_import, enabled_features)) {} is_import, enabled_features)) {}
JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit() = default; JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit() = default;
void JSToWasmWrapperCompilationUnit::Prepare(Isolate* isolate) {
CompilationJob::Status status = job_->PrepareJob(isolate);
CHECK_EQ(status, CompilationJob::SUCCEEDED);
}
void JSToWasmWrapperCompilationUnit::Execute() { void JSToWasmWrapperCompilationUnit::Execute() {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), "CompileJSToWasmWrapper"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), "CompileJSToWasmWrapper");
DCHECK_EQ(job_->state(), CompilationJob::State::kReadyToExecute);
CompilationJob::Status status = job_->ExecuteJob(); CompilationJob::Status status = job_->ExecuteJob();
CHECK_EQ(status, CompilationJob::SUCCEEDED); CHECK_EQ(status, CompilationJob::SUCCEEDED);
} }
...@@ -300,7 +296,6 @@ Handle<Code> JSToWasmWrapperCompilationUnit::CompileJSToWasmWrapper( ...@@ -300,7 +296,6 @@ Handle<Code> JSToWasmWrapperCompilationUnit::CompileJSToWasmWrapper(
WasmFeatures enabled_features = WasmFeaturesFromIsolate(isolate); WasmFeatures enabled_features = WasmFeaturesFromIsolate(isolate);
JSToWasmWrapperCompilationUnit unit(isolate, isolate->wasm_engine(), sig, JSToWasmWrapperCompilationUnit unit(isolate, isolate->wasm_engine(), sig,
is_import, enabled_features); is_import, enabled_features);
unit.Prepare(isolate);
unit.Execute(); unit.Execute();
return unit.Finalize(isolate); return unit.Finalize(isolate);
} }
......
...@@ -113,15 +113,19 @@ class V8_EXPORT_PRIVATE JSToWasmWrapperCompilationUnit final { ...@@ -113,15 +113,19 @@ class V8_EXPORT_PRIVATE JSToWasmWrapperCompilationUnit final {
const WasmFeatures& enabled_features); const WasmFeatures& enabled_features);
~JSToWasmWrapperCompilationUnit(); ~JSToWasmWrapperCompilationUnit();
void Prepare(Isolate* isolate);
void Execute(); void Execute();
Handle<Code> Finalize(Isolate* isolate); Handle<Code> Finalize(Isolate* isolate);
bool is_import() const { return is_import_; }
FunctionSig* sig() const { return sig_; }
// Run a compilation unit synchronously. // Run a compilation unit synchronously.
static Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, FunctionSig* sig, static Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, FunctionSig* sig,
bool is_import); bool is_import);
private: private:
bool is_import_;
FunctionSig* sig_;
std::unique_ptr<OptimizedCompilationJob> job_; std::unique_ptr<OptimizedCompilationJob> job_;
}; };
......
This diff is collapsed.
...@@ -153,8 +153,6 @@ class AsyncCompileJob { ...@@ -153,8 +153,6 @@ class AsyncCompileJob {
void AsyncCompileSucceeded(Handle<WasmModuleObject> result); void AsyncCompileSucceeded(Handle<WasmModuleObject> result);
void CompileWrappers();
void FinishModule(); void FinishModule();
void StartForegroundTask(); void StartForegroundTask();
......
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