[wasm] Pass and store fewer wasm engine pointers
There is exactly one WasmEngine per process, hence we do not need to store or pass a pointer to it. We just use {GetWasmEngine} (which just reads a global variable) whenever we need it. R=jkummerow@chromium.org Bug: v8:11879 Change-Id: I7e0e86e326f4cafe5a894af0ff6d35803c0340a9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972725 Commit-Queue: Clemens Backes <clemensb@chromium.org> Reviewed-by: Maya Lekova <mslekova@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#75266}
This commit is contained in:
parent
fa3cd68a3f
commit
089221ef96
@ -1037,9 +1037,8 @@ PipelineStatistics* CreatePipelineStatistics(Handle<Script> script,
|
|||||||
|
|
||||||
#if V8_ENABLE_WEBASSEMBLY
|
#if V8_ENABLE_WEBASSEMBLY
|
||||||
PipelineStatistics* CreatePipelineStatistics(
|
PipelineStatistics* CreatePipelineStatistics(
|
||||||
wasm::WasmEngine* wasm_engine, wasm::FunctionBody function_body,
|
wasm::FunctionBody function_body, const wasm::WasmModule* wasm_module,
|
||||||
const wasm::WasmModule* wasm_module, OptimizedCompilationInfo* info,
|
OptimizedCompilationInfo* info, ZoneStats* zone_stats) {
|
||||||
ZoneStats* zone_stats) {
|
|
||||||
PipelineStatistics* pipeline_statistics = nullptr;
|
PipelineStatistics* pipeline_statistics = nullptr;
|
||||||
|
|
||||||
bool tracing_enabled;
|
bool tracing_enabled;
|
||||||
@ -1047,7 +1046,7 @@ PipelineStatistics* CreatePipelineStatistics(
|
|||||||
TRACE_DISABLED_BY_DEFAULT("v8.wasm.turbofan"), &tracing_enabled);
|
TRACE_DISABLED_BY_DEFAULT("v8.wasm.turbofan"), &tracing_enabled);
|
||||||
if (tracing_enabled || FLAG_turbo_stats_wasm) {
|
if (tracing_enabled || FLAG_turbo_stats_wasm) {
|
||||||
pipeline_statistics = new PipelineStatistics(
|
pipeline_statistics = new PipelineStatistics(
|
||||||
info, wasm_engine->GetOrCreateTurboStatistics(), zone_stats);
|
info, wasm::GetWasmEngine()->GetOrCreateTurboStatistics(), zone_stats);
|
||||||
pipeline_statistics->BeginPhaseKind("V8.WasmInitializing");
|
pipeline_statistics->BeginPhaseKind("V8.WasmInitializing");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2549,8 +2548,7 @@ struct VerifyGraphPhase {
|
|||||||
#if V8_ENABLE_WEBASSEMBLY
|
#if V8_ENABLE_WEBASSEMBLY
|
||||||
class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
|
class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
|
||||||
public:
|
public:
|
||||||
WasmHeapStubCompilationJob(Isolate* isolate, wasm::WasmEngine* wasm_engine,
|
WasmHeapStubCompilationJob(Isolate* isolate, CallDescriptor* call_descriptor,
|
||||||
CallDescriptor* call_descriptor,
|
|
||||||
std::unique_ptr<Zone> zone, Graph* graph,
|
std::unique_ptr<Zone> zone, Graph* graph,
|
||||||
CodeKind kind, std::unique_ptr<char[]> debug_name,
|
CodeKind kind, std::unique_ptr<char[]> debug_name,
|
||||||
const AssemblerOptions& options,
|
const AssemblerOptions& options,
|
||||||
@ -2566,11 +2564,10 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
|
|||||||
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, wasm_engine->allocator(), graph_,
|
data_(&zone_stats_, &info_, isolate, wasm::GetWasmEngine()->allocator(),
|
||||||
nullptr, nullptr, source_positions,
|
graph_, nullptr, nullptr, source_positions,
|
||||||
zone_->New<NodeOriginTable>(graph_), nullptr, options, nullptr),
|
zone_->New<NodeOriginTable>(graph_), nullptr, options, nullptr),
|
||||||
pipeline_(&data_),
|
pipeline_(&data_) {}
|
||||||
wasm_engine_(wasm_engine) {}
|
|
||||||
|
|
||||||
WasmHeapStubCompilationJob(const WasmHeapStubCompilationJob&) = delete;
|
WasmHeapStubCompilationJob(const WasmHeapStubCompilationJob&) = delete;
|
||||||
WasmHeapStubCompilationJob& operator=(const WasmHeapStubCompilationJob&) =
|
WasmHeapStubCompilationJob& operator=(const WasmHeapStubCompilationJob&) =
|
||||||
@ -2591,18 +2588,19 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
|
|||||||
Graph* graph_;
|
Graph* graph_;
|
||||||
PipelineData data_;
|
PipelineData data_;
|
||||||
PipelineImpl pipeline_;
|
PipelineImpl pipeline_;
|
||||||
wasm::WasmEngine* wasm_engine_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::unique_ptr<OptimizedCompilationJob>
|
std::unique_ptr<OptimizedCompilationJob>
|
||||||
Pipeline::NewWasmHeapStubCompilationJob(
|
Pipeline::NewWasmHeapStubCompilationJob(Isolate* isolate,
|
||||||
Isolate* isolate, wasm::WasmEngine* wasm_engine,
|
CallDescriptor* call_descriptor,
|
||||||
CallDescriptor* call_descriptor, std::unique_ptr<Zone> zone, Graph* graph,
|
std::unique_ptr<Zone> zone,
|
||||||
CodeKind kind, std::unique_ptr<char[]> debug_name,
|
Graph* graph, CodeKind kind,
|
||||||
const AssemblerOptions& options, SourcePositionTable* source_positions) {
|
std::unique_ptr<char[]> debug_name,
|
||||||
|
const AssemblerOptions& options,
|
||||||
|
SourcePositionTable* source_positions) {
|
||||||
return std::make_unique<WasmHeapStubCompilationJob>(
|
return std::make_unique<WasmHeapStubCompilationJob>(
|
||||||
isolate, wasm_engine, call_descriptor, std::move(zone), graph, kind,
|
isolate, call_descriptor, std::move(zone), graph, kind,
|
||||||
std::move(debug_name), options, source_positions);
|
std::move(debug_name), options, source_positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2616,7 +2614,8 @@ 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_, wasm_engine_->GetOrCreateTurboStatistics(), &zone_stats_));
|
&info_, wasm::GetWasmEngine()->GetOrCreateTurboStatistics(),
|
||||||
|
&zone_stats_));
|
||||||
pipeline_statistics->BeginPhaseKind("V8.WasmStubCodegen");
|
pipeline_statistics->BeginPhaseKind("V8.WasmStubCodegen");
|
||||||
}
|
}
|
||||||
if (info_.trace_turbo_json() || info_.trace_turbo_graph()) {
|
if (info_.trace_turbo_json() || info_.trace_turbo_graph()) {
|
||||||
@ -3138,13 +3137,14 @@ std::ostream& operator<<(std::ostream& out, const BlockStartsAsJSON& s) {
|
|||||||
#if V8_ENABLE_WEBASSEMBLY
|
#if V8_ENABLE_WEBASSEMBLY
|
||||||
// static
|
// static
|
||||||
wasm::WasmCompilationResult Pipeline::GenerateCodeForWasmNativeStub(
|
wasm::WasmCompilationResult Pipeline::GenerateCodeForWasmNativeStub(
|
||||||
wasm::WasmEngine* wasm_engine, CallDescriptor* call_descriptor,
|
CallDescriptor* call_descriptor, MachineGraph* mcgraph, CodeKind kind,
|
||||||
MachineGraph* mcgraph, CodeKind kind, int wasm_kind, const char* debug_name,
|
int wasm_kind, const char* debug_name, const AssemblerOptions& options,
|
||||||
const AssemblerOptions& options, SourcePositionTable* source_positions) {
|
SourcePositionTable* source_positions) {
|
||||||
Graph* graph = mcgraph->graph();
|
Graph* graph = mcgraph->graph();
|
||||||
OptimizedCompilationInfo info(base::CStrVector(debug_name), graph->zone(),
|
OptimizedCompilationInfo info(base::CStrVector(debug_name), graph->zone(),
|
||||||
kind);
|
kind);
|
||||||
// Construct a pipeline for scheduling and code generation.
|
// Construct a pipeline for scheduling and code generation.
|
||||||
|
wasm::WasmEngine* wasm_engine = wasm::GetWasmEngine();
|
||||||
ZoneStats zone_stats(wasm_engine->allocator());
|
ZoneStats zone_stats(wasm_engine->allocator());
|
||||||
NodeOriginTable* node_positions = graph->zone()->New<NodeOriginTable>(graph);
|
NodeOriginTable* node_positions = graph->zone()->New<NodeOriginTable>(graph);
|
||||||
// {instruction_buffer} must live longer than {PipelineData}, since
|
// {instruction_buffer} must live longer than {PipelineData}, since
|
||||||
@ -3241,15 +3241,15 @@ wasm::WasmCompilationResult Pipeline::GenerateCodeForWasmNativeStub(
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
void Pipeline::GenerateCodeForWasmFunction(
|
void Pipeline::GenerateCodeForWasmFunction(
|
||||||
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
|
OptimizedCompilationInfo* info, MachineGraph* mcgraph,
|
||||||
MachineGraph* mcgraph, CallDescriptor* call_descriptor,
|
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
|
||||||
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
|
NodeOriginTable* node_origins, wasm::FunctionBody function_body,
|
||||||
wasm::FunctionBody function_body, const wasm::WasmModule* module,
|
const wasm::WasmModule* module, int function_index,
|
||||||
int function_index, std::vector<compiler::WasmLoopInfo>* loop_info) {
|
std::vector<compiler::WasmLoopInfo>* loop_info) {
|
||||||
|
auto* wasm_engine = wasm::GetWasmEngine();
|
||||||
ZoneStats zone_stats(wasm_engine->allocator());
|
ZoneStats zone_stats(wasm_engine->allocator());
|
||||||
std::unique_ptr<PipelineStatistics> pipeline_statistics(
|
std::unique_ptr<PipelineStatistics> pipeline_statistics(
|
||||||
CreatePipelineStatistics(wasm_engine, function_body, module, info,
|
CreatePipelineStatistics(function_body, module, info, &zone_stats));
|
||||||
&zone_stats));
|
|
||||||
// {instruction_buffer} must live longer than {PipelineData}, since
|
// {instruction_buffer} must live longer than {PipelineData}, since
|
||||||
// {PipelineData} will reference the {instruction_buffer} via the
|
// {PipelineData} will reference the {instruction_buffer} via the
|
||||||
// {AssemblerBuffer} of the {Assembler} contained in the {CodeGenerator}.
|
// {AssemblerBuffer} of the {Assembler} contained in the {CodeGenerator}.
|
||||||
|
@ -54,25 +54,24 @@ class Pipeline : public AllStatic {
|
|||||||
|
|
||||||
// Run the pipeline for the WebAssembly compilation info.
|
// Run the pipeline for the WebAssembly compilation info.
|
||||||
static void GenerateCodeForWasmFunction(
|
static void GenerateCodeForWasmFunction(
|
||||||
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
|
OptimizedCompilationInfo* info, MachineGraph* mcgraph,
|
||||||
MachineGraph* mcgraph, CallDescriptor* call_descriptor,
|
CallDescriptor* call_descriptor, SourcePositionTable* source_positions,
|
||||||
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
|
NodeOriginTable* node_origins, wasm::FunctionBody function_body,
|
||||||
wasm::FunctionBody function_body, const wasm::WasmModule* module,
|
const wasm::WasmModule* module, int function_index,
|
||||||
int function_index, std::vector<compiler::WasmLoopInfo>* loop_infos);
|
std::vector<compiler::WasmLoopInfo>* loop_infos);
|
||||||
|
|
||||||
// Run the pipeline on a machine graph and generate code.
|
// Run the pipeline on a machine graph and generate code.
|
||||||
static wasm::WasmCompilationResult GenerateCodeForWasmNativeStub(
|
static wasm::WasmCompilationResult GenerateCodeForWasmNativeStub(
|
||||||
wasm::WasmEngine* wasm_engine, CallDescriptor* call_descriptor,
|
CallDescriptor* call_descriptor, MachineGraph* mcgraph, CodeKind kind,
|
||||||
MachineGraph* mcgraph, CodeKind kind, int wasm_kind,
|
int wasm_kind, const char* debug_name,
|
||||||
const char* debug_name, const AssemblerOptions& assembler_options,
|
const AssemblerOptions& assembler_options,
|
||||||
SourcePositionTable* source_positions = nullptr);
|
SourcePositionTable* source_positions = nullptr);
|
||||||
|
|
||||||
// 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, wasm::WasmEngine* wasm_engine,
|
Isolate* isolate, CallDescriptor* call_descriptor,
|
||||||
CallDescriptor* call_descriptor, std::unique_ptr<Zone> zone, Graph* graph,
|
std::unique_ptr<Zone> zone, Graph* graph, CodeKind kind,
|
||||||
CodeKind kind, std::unique_ptr<char[]> debug_name,
|
std::unique_ptr<char[]> debug_name, const AssemblerOptions& options,
|
||||||
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.
|
||||||
|
@ -7287,14 +7287,14 @@ void BuildInlinedJSToWasmWrapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
|
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
|
||||||
Isolate* isolate, wasm::WasmEngine* wasm_engine,
|
Isolate* isolate, const wasm::FunctionSig* sig,
|
||||||
const wasm::FunctionSig* sig, const wasm::WasmModule* module,
|
const wasm::WasmModule* module, bool is_import,
|
||||||
bool is_import, const wasm::WasmFeatures& enabled_features) {
|
const wasm::WasmFeatures& enabled_features) {
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Create the Graph.
|
// Create the Graph.
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::unique_ptr<Zone> zone = std::make_unique<Zone>(
|
std::unique_ptr<Zone> zone = std::make_unique<Zone>(
|
||||||
wasm_engine->allocator(), ZONE_NAME, kCompressGraphZone);
|
wasm::GetWasmEngine()->allocator(), ZONE_NAME, kCompressGraphZone);
|
||||||
Graph* graph = zone->New<Graph>(zone.get());
|
Graph* graph = zone->New<Graph>(zone.get());
|
||||||
CommonOperatorBuilder* common = zone->New<CommonOperatorBuilder>(zone.get());
|
CommonOperatorBuilder* common = zone->New<CommonOperatorBuilder>(zone.get());
|
||||||
MachineOperatorBuilder* machine = zone->New<MachineOperatorBuilder>(
|
MachineOperatorBuilder* machine = zone->New<MachineOperatorBuilder>(
|
||||||
@ -7318,9 +7318,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, wasm_engine, incoming, std::move(zone), graph,
|
isolate, incoming, std::move(zone), graph, CodeKind::JS_TO_WASM_FUNCTION,
|
||||||
CodeKind::JS_TO_WASM_FUNCTION, std::move(debug_name),
|
std::move(debug_name), WasmAssemblerOptions());
|
||||||
WasmAssemblerOptions());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
|
std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
|
||||||
@ -7487,14 +7486,13 @@ wasm::WasmOpcode GetMathIntrinsicOpcode(WasmImportCallKind kind,
|
|||||||
}
|
}
|
||||||
|
|
||||||
wasm::WasmCompilationResult CompileWasmMathIntrinsic(
|
wasm::WasmCompilationResult CompileWasmMathIntrinsic(
|
||||||
wasm::WasmEngine* wasm_engine, WasmImportCallKind kind,
|
WasmImportCallKind kind, const wasm::FunctionSig* sig) {
|
||||||
const wasm::FunctionSig* sig) {
|
|
||||||
DCHECK_EQ(1, sig->return_count());
|
DCHECK_EQ(1, sig->return_count());
|
||||||
|
|
||||||
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
||||||
"wasm.CompileWasmMathIntrinsic");
|
"wasm.CompileWasmMathIntrinsic");
|
||||||
|
|
||||||
Zone zone(wasm_engine->allocator(), ZONE_NAME, kCompressGraphZone);
|
Zone zone(wasm::GetWasmEngine()->allocator(), ZONE_NAME, kCompressGraphZone);
|
||||||
|
|
||||||
// Compile a Wasm function with a single bytecode and let TurboFan
|
// Compile a Wasm function with a single bytecode and let TurboFan
|
||||||
// generate either inlined machine code or a call to a helper.
|
// generate either inlined machine code or a call to a helper.
|
||||||
@ -7541,7 +7539,7 @@ wasm::WasmCompilationResult CompileWasmMathIntrinsic(
|
|||||||
}
|
}
|
||||||
|
|
||||||
wasm::WasmCompilationResult result = Pipeline::GenerateCodeForWasmNativeStub(
|
wasm::WasmCompilationResult result = Pipeline::GenerateCodeForWasmNativeStub(
|
||||||
wasm_engine, call_descriptor, mcgraph, CodeKind::WASM_FUNCTION,
|
call_descriptor, mcgraph, CodeKind::WASM_FUNCTION,
|
||||||
wasm::WasmCode::kFunction, debug_name, WasmStubAssemblerOptions(),
|
wasm::WasmCode::kFunction, debug_name, WasmStubAssemblerOptions(),
|
||||||
source_positions);
|
source_positions);
|
||||||
return result;
|
return result;
|
||||||
@ -7550,9 +7548,8 @@ wasm::WasmCompilationResult CompileWasmMathIntrinsic(
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
||||||
wasm::WasmEngine* wasm_engine, wasm::CompilationEnv* env,
|
wasm::CompilationEnv* env, WasmImportCallKind kind,
|
||||||
WasmImportCallKind kind, const wasm::FunctionSig* sig,
|
const wasm::FunctionSig* sig, bool source_positions, int expected_arity) {
|
||||||
bool source_positions, int expected_arity) {
|
|
||||||
DCHECK_NE(WasmImportCallKind::kLinkError, kind);
|
DCHECK_NE(WasmImportCallKind::kLinkError, kind);
|
||||||
DCHECK_NE(WasmImportCallKind::kWasmToWasm, kind);
|
DCHECK_NE(WasmImportCallKind::kWasmToWasm, kind);
|
||||||
|
|
||||||
@ -7560,7 +7557,7 @@ wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
|||||||
if (FLAG_wasm_math_intrinsics &&
|
if (FLAG_wasm_math_intrinsics &&
|
||||||
kind >= WasmImportCallKind::kFirstMathIntrinsic &&
|
kind >= WasmImportCallKind::kFirstMathIntrinsic &&
|
||||||
kind <= WasmImportCallKind::kLastMathIntrinsic) {
|
kind <= WasmImportCallKind::kLastMathIntrinsic) {
|
||||||
return CompileWasmMathIntrinsic(wasm_engine, kind, sig);
|
return CompileWasmMathIntrinsic(kind, sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
||||||
@ -7568,7 +7565,7 @@ wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Create the Graph
|
// Create the Graph
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Zone zone(wasm_engine->allocator(), ZONE_NAME, kCompressGraphZone);
|
Zone zone(wasm::GetWasmEngine()->allocator(), ZONE_NAME, kCompressGraphZone);
|
||||||
Graph* graph = zone.New<Graph>(&zone);
|
Graph* graph = zone.New<Graph>(&zone);
|
||||||
CommonOperatorBuilder* common = zone.New<CommonOperatorBuilder>(&zone);
|
CommonOperatorBuilder* common = zone.New<CommonOperatorBuilder>(&zone);
|
||||||
MachineOperatorBuilder* machine = zone.New<MachineOperatorBuilder>(
|
MachineOperatorBuilder* machine = zone.New<MachineOperatorBuilder>(
|
||||||
@ -7601,20 +7598,19 @@ wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
|||||||
incoming = GetI32WasmCallDescriptor(&zone, incoming);
|
incoming = GetI32WasmCallDescriptor(&zone, incoming);
|
||||||
}
|
}
|
||||||
wasm::WasmCompilationResult result = Pipeline::GenerateCodeForWasmNativeStub(
|
wasm::WasmCompilationResult result = Pipeline::GenerateCodeForWasmNativeStub(
|
||||||
wasm_engine, incoming, mcgraph, CodeKind::WASM_TO_JS_FUNCTION,
|
incoming, mcgraph, CodeKind::WASM_TO_JS_FUNCTION,
|
||||||
wasm::WasmCode::kWasmToJsWrapper, func_name, WasmStubAssemblerOptions(),
|
wasm::WasmCode::kWasmToJsWrapper, func_name, WasmStubAssemblerOptions(),
|
||||||
source_position_table);
|
source_position_table);
|
||||||
result.kind = wasm::WasmCompilationResult::kWasmToJsWrapper;
|
result.kind = wasm::WasmCompilationResult::kWasmToJsWrapper;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::WasmEngine* wasm_engine,
|
wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::NativeModule* native_module,
|
||||||
wasm::NativeModule* native_module,
|
|
||||||
const wasm::FunctionSig* sig) {
|
const wasm::FunctionSig* sig) {
|
||||||
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
||||||
"wasm.CompileWasmCapiFunction");
|
"wasm.CompileWasmCapiFunction");
|
||||||
|
|
||||||
Zone zone(wasm_engine->allocator(), ZONE_NAME, kCompressGraphZone);
|
Zone zone(wasm::GetWasmEngine()->allocator(), ZONE_NAME, kCompressGraphZone);
|
||||||
|
|
||||||
// TODO(jkummerow): Extract common code into helper method.
|
// TODO(jkummerow): Extract common code into helper method.
|
||||||
SourcePositionTable* source_positions = nullptr;
|
SourcePositionTable* source_positions = nullptr;
|
||||||
@ -7646,7 +7642,7 @@ wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::WasmEngine* wasm_engine,
|
|||||||
|
|
||||||
const char* debug_name = "WasmCapiCall";
|
const char* debug_name = "WasmCapiCall";
|
||||||
wasm::WasmCompilationResult result = Pipeline::GenerateCodeForWasmNativeStub(
|
wasm::WasmCompilationResult result = Pipeline::GenerateCodeForWasmNativeStub(
|
||||||
wasm_engine, call_descriptor, mcgraph, CodeKind::WASM_TO_CAPI_FUNCTION,
|
call_descriptor, mcgraph, CodeKind::WASM_TO_CAPI_FUNCTION,
|
||||||
wasm::WasmCode::kWasmToCapiWrapper, debug_name,
|
wasm::WasmCode::kWasmToCapiWrapper, debug_name,
|
||||||
WasmStubAssemblerOptions(), source_positions);
|
WasmStubAssemblerOptions(), source_positions);
|
||||||
std::unique_ptr<wasm::WasmCode> wasm_code = native_module->AddCode(
|
std::unique_ptr<wasm::WasmCode> wasm_code = native_module->AddCode(
|
||||||
@ -7695,7 +7691,7 @@ MaybeHandle<Code> CompileWasmToJSWrapper(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, wasm::GetWasmEngine(), incoming, std::move(zone), graph,
|
isolate, incoming, std::move(zone), graph,
|
||||||
CodeKind::WASM_TO_JS_FUNCTION, std::move(name_buffer),
|
CodeKind::WASM_TO_JS_FUNCTION, std::move(name_buffer),
|
||||||
AssemblerOptions::Default(isolate)));
|
AssemblerOptions::Default(isolate)));
|
||||||
|
|
||||||
@ -7742,7 +7738,7 @@ 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, wasm::GetWasmEngine(), incoming, std::move(zone), graph,
|
isolate, incoming, std::move(zone), graph,
|
||||||
CodeKind::JS_TO_JS_FUNCTION, std::move(name_buffer),
|
CodeKind::JS_TO_JS_FUNCTION, std::move(name_buffer),
|
||||||
AssemblerOptions::Default(isolate)));
|
AssemblerOptions::Default(isolate)));
|
||||||
|
|
||||||
@ -7797,9 +7793,8 @@ Handle<CodeT> CompileCWasmEntry(Isolate* isolate, const 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, wasm::GetWasmEngine(), incoming, std::move(zone), graph,
|
isolate, incoming, std::move(zone), graph, CodeKind::C_WASM_ENTRY,
|
||||||
CodeKind::C_WASM_ENTRY, std::move(name_buffer),
|
std::move(name_buffer), AssemblerOptions::Default(isolate)));
|
||||||
AssemblerOptions::Default(isolate)));
|
|
||||||
|
|
||||||
CHECK_NE(job->ExecuteJob(isolate->counters()->runtime_call_stats(), nullptr),
|
CHECK_NE(job->ExecuteJob(isolate->counters()->runtime_call_stats(), nullptr),
|
||||||
CompilationJob::FAILED);
|
CompilationJob::FAILED);
|
||||||
@ -7814,8 +7809,7 @@ Handle<CodeT> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig,
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool BuildGraphForWasmFunction(AccountingAllocator* allocator,
|
bool BuildGraphForWasmFunction(wasm::CompilationEnv* env,
|
||||||
wasm::CompilationEnv* env,
|
|
||||||
const wasm::FunctionBody& func_body,
|
const wasm::FunctionBody& func_body,
|
||||||
int func_index, wasm::WasmFeatures* detected,
|
int func_index, wasm::WasmFeatures* detected,
|
||||||
MachineGraph* mcgraph,
|
MachineGraph* mcgraph,
|
||||||
@ -7825,6 +7819,7 @@ bool BuildGraphForWasmFunction(AccountingAllocator* allocator,
|
|||||||
// Create a TF graph during decoding.
|
// Create a TF graph during decoding.
|
||||||
WasmGraphBuilder builder(env, mcgraph->zone(), mcgraph, func_body.sig,
|
WasmGraphBuilder builder(env, mcgraph->zone(), mcgraph, func_body.sig,
|
||||||
source_positions);
|
source_positions);
|
||||||
|
auto* allocator = wasm::GetWasmEngine()->allocator();
|
||||||
wasm::VoidResult graph_construction_result = wasm::BuildTFGraph(
|
wasm::VoidResult graph_construction_result = wasm::BuildTFGraph(
|
||||||
allocator, env->enabled_features, env->module, &builder, detected,
|
allocator, env->enabled_features, env->module, &builder, detected,
|
||||||
func_body, loop_infos, node_origins, func_index);
|
func_body, loop_infos, node_origins, func_index);
|
||||||
@ -7864,13 +7859,12 @@ base::Vector<const char> GetDebugName(Zone* zone, int index) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
|
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
|
||||||
wasm::WasmEngine* wasm_engine, wasm::CompilationEnv* env,
|
wasm::CompilationEnv* env, const wasm::FunctionBody& func_body,
|
||||||
const wasm::FunctionBody& func_body, int func_index, Counters* counters,
|
int func_index, Counters* counters, wasm::WasmFeatures* detected) {
|
||||||
wasm::WasmFeatures* detected) {
|
|
||||||
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
||||||
"wasm.CompileTopTier", "func_index", func_index, "body_size",
|
"wasm.CompileTopTier", "func_index", func_index, "body_size",
|
||||||
func_body.end - func_body.start);
|
func_body.end - func_body.start);
|
||||||
Zone zone(wasm_engine->allocator(), ZONE_NAME, kCompressGraphZone);
|
Zone zone(wasm::GetWasmEngine()->allocator(), ZONE_NAME, kCompressGraphZone);
|
||||||
MachineGraph* mcgraph = zone.New<MachineGraph>(
|
MachineGraph* mcgraph = zone.New<MachineGraph>(
|
||||||
zone.New<Graph>(&zone), zone.New<CommonOperatorBuilder>(&zone),
|
zone.New<Graph>(&zone), zone.New<CommonOperatorBuilder>(&zone),
|
||||||
zone.New<MachineOperatorBuilder>(
|
zone.New<MachineOperatorBuilder>(
|
||||||
@ -7897,9 +7891,8 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
|
|||||||
|
|
||||||
std::vector<WasmLoopInfo> loop_infos;
|
std::vector<WasmLoopInfo> loop_infos;
|
||||||
|
|
||||||
if (!BuildGraphForWasmFunction(wasm_engine->allocator(), env, func_body,
|
if (!BuildGraphForWasmFunction(env, func_body, func_index, detected, mcgraph,
|
||||||
func_index, detected, mcgraph, &loop_infos,
|
&loop_infos, node_origins, source_positions)) {
|
||||||
node_origins, source_positions)) {
|
|
||||||
return wasm::WasmCompilationResult{};
|
return wasm::WasmCompilationResult{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7918,8 +7911,8 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pipeline::GenerateCodeForWasmFunction(
|
Pipeline::GenerateCodeForWasmFunction(
|
||||||
&info, wasm_engine, mcgraph, call_descriptor, source_positions,
|
&info, mcgraph, call_descriptor, source_positions, node_origins,
|
||||||
node_origins, func_body, env->module, func_index, &loop_infos);
|
func_body, env->module, func_index, &loop_infos);
|
||||||
|
|
||||||
if (counters) {
|
if (counters) {
|
||||||
counters->wasm_compile_function_peak_memory_bytes()->AddSample(
|
counters->wasm_compile_function_peak_memory_bytes()->AddSample(
|
||||||
|
@ -59,8 +59,8 @@ enum class LoadTransformationKind : uint8_t;
|
|||||||
namespace compiler {
|
namespace compiler {
|
||||||
|
|
||||||
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
|
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
|
||||||
wasm::WasmEngine*, wasm::CompilationEnv*, const wasm::FunctionBody&,
|
wasm::CompilationEnv*, const wasm::FunctionBody&, int func_index, Counters*,
|
||||||
int func_index, Counters*, wasm::WasmFeatures* detected);
|
wasm::WasmFeatures* detected);
|
||||||
|
|
||||||
// Calls to Wasm imports are handled in several different ways, depending on the
|
// Calls to Wasm imports are handled in several different ways, depending on the
|
||||||
// type of the target function/callable and whether the signature matches the
|
// type of the target function/callable and whether the signature matches the
|
||||||
@ -116,19 +116,18 @@ ResolveWasmImportCall(Handle<JSReceiver> callable, const wasm::FunctionSig* sig,
|
|||||||
|
|
||||||
// Compiles an import call wrapper, which allows Wasm to call imports.
|
// Compiles an import call wrapper, which allows Wasm to call imports.
|
||||||
V8_EXPORT_PRIVATE wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
V8_EXPORT_PRIVATE wasm::WasmCompilationResult CompileWasmImportCallWrapper(
|
||||||
wasm::WasmEngine*, wasm::CompilationEnv* env, WasmImportCallKind,
|
wasm::CompilationEnv* env, WasmImportCallKind, const wasm::FunctionSig*,
|
||||||
const wasm::FunctionSig*, bool source_positions, int expected_arity);
|
bool source_positions, int expected_arity);
|
||||||
|
|
||||||
// Compiles a host call wrapper, which allows Wasm to call host functions.
|
// Compiles a host call wrapper, which allows Wasm to call host functions.
|
||||||
wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::WasmEngine*,
|
wasm::WasmCode* CompileWasmCapiCallWrapper(wasm::NativeModule*,
|
||||||
wasm::NativeModule*,
|
|
||||||
const wasm::FunctionSig*);
|
const wasm::FunctionSig*);
|
||||||
|
|
||||||
// Returns an OptimizedCompilationJob object for a JS to Wasm wrapper.
|
// Returns an OptimizedCompilationJob object for a JS to Wasm wrapper.
|
||||||
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
|
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
|
||||||
Isolate* isolate, wasm::WasmEngine* wasm_engine,
|
Isolate* isolate, const wasm::FunctionSig* sig,
|
||||||
const wasm::FunctionSig* sig, const wasm::WasmModule* module,
|
const wasm::WasmModule* module, bool is_import,
|
||||||
bool is_import, const wasm::WasmFeatures& enabled_features);
|
const wasm::WasmFeatures& enabled_features);
|
||||||
|
|
||||||
MaybeHandle<Code> CompileWasmToJSWrapper(Isolate* isolate,
|
MaybeHandle<Code> CompileWasmToJSWrapper(Isolate* isolate,
|
||||||
const wasm::FunctionSig* sig,
|
const wasm::FunctionSig* sig,
|
||||||
|
@ -6184,9 +6184,8 @@ constexpr base::EnumSet<ValueKind> LiftoffCompiler::kExternRefSupported;
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
WasmCompilationResult ExecuteLiftoffCompilation(
|
WasmCompilationResult ExecuteLiftoffCompilation(
|
||||||
AccountingAllocator* allocator, CompilationEnv* env,
|
CompilationEnv* env, const FunctionBody& func_body, int func_index,
|
||||||
const FunctionBody& func_body, int func_index, ForDebugging for_debugging,
|
ForDebugging for_debugging, Counters* counters, WasmFeatures* detected,
|
||||||
Counters* counters, WasmFeatures* detected,
|
|
||||||
base::Vector<const int> breakpoints,
|
base::Vector<const int> breakpoints,
|
||||||
std::unique_ptr<DebugSideTable>* debug_sidetable, int dead_breakpoint,
|
std::unique_ptr<DebugSideTable>* debug_sidetable, int dead_breakpoint,
|
||||||
int* max_steps) {
|
int* max_steps) {
|
||||||
@ -6195,7 +6194,7 @@ WasmCompilationResult ExecuteLiftoffCompilation(
|
|||||||
"wasm.CompileBaseline", "funcIndex", func_index, "bodySize",
|
"wasm.CompileBaseline", "funcIndex", func_index, "bodySize",
|
||||||
func_body_size);
|
func_body_size);
|
||||||
|
|
||||||
Zone zone(allocator, "LiftoffCompilationZone");
|
Zone zone(GetWasmEngine()->allocator(), "LiftoffCompilationZone");
|
||||||
auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, func_body.sig);
|
auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, func_body.sig);
|
||||||
size_t code_size_estimate =
|
size_t code_size_estimate =
|
||||||
WasmCodeManager::EstimateLiftoffCodeSize(func_body_size);
|
WasmCodeManager::EstimateLiftoffCodeSize(func_body_size);
|
||||||
|
@ -54,8 +54,8 @@ enum LiftoffBailoutReason : int8_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
V8_EXPORT_PRIVATE WasmCompilationResult ExecuteLiftoffCompilation(
|
V8_EXPORT_PRIVATE WasmCompilationResult ExecuteLiftoffCompilation(
|
||||||
AccountingAllocator*, CompilationEnv*, const FunctionBody&, int func_index,
|
CompilationEnv*, const FunctionBody&, int func_index, ForDebugging,
|
||||||
ForDebugging, Counters*, WasmFeatures* detected_features,
|
Counters*, WasmFeatures* detected_features,
|
||||||
base::Vector<const int> breakpoints = {},
|
base::Vector<const int> breakpoints = {},
|
||||||
std::unique_ptr<DebugSideTable>* = nullptr, int dead_breakpoint = 0,
|
std::unique_ptr<DebugSideTable>* = nullptr, int dead_breakpoint = 0,
|
||||||
int* max_steps = nullptr);
|
int* max_steps = nullptr);
|
||||||
|
@ -112,7 +112,7 @@ class V8_EXPORT_PRIVATE CompilationState {
|
|||||||
|
|
||||||
~CompilationState();
|
~CompilationState();
|
||||||
|
|
||||||
void InitCompileJob(WasmEngine*);
|
void InitCompileJob();
|
||||||
|
|
||||||
void CancelCompilation();
|
void CancelCompilation();
|
||||||
|
|
||||||
|
@ -121,15 +121,14 @@ ExecutionTier WasmCompilationUnit::GetBaselineExecutionTier(
|
|||||||
}
|
}
|
||||||
|
|
||||||
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
|
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
|
||||||
WasmEngine* engine, CompilationEnv* env,
|
CompilationEnv* env, const WireBytesStorage* wire_bytes_storage,
|
||||||
const WireBytesStorage* wire_bytes_storage, Counters* counters,
|
Counters* counters, WasmFeatures* detected) {
|
||||||
WasmFeatures* detected) {
|
|
||||||
WasmCompilationResult result;
|
WasmCompilationResult result;
|
||||||
if (func_index_ < static_cast<int>(env->module->num_imported_functions)) {
|
if (func_index_ < static_cast<int>(env->module->num_imported_functions)) {
|
||||||
result = ExecuteImportWrapperCompilation(engine, env);
|
result = ExecuteImportWrapperCompilation(env);
|
||||||
} else {
|
} else {
|
||||||
result = ExecuteFunctionCompilation(engine, env, wire_bytes_storage,
|
result =
|
||||||
counters, detected);
|
ExecuteFunctionCompilation(env, wire_bytes_storage, counters, detected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.succeeded() && counters) {
|
if (result.succeeded() && counters) {
|
||||||
@ -145,22 +144,21 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
WasmCompilationResult WasmCompilationUnit::ExecuteImportWrapperCompilation(
|
WasmCompilationResult WasmCompilationUnit::ExecuteImportWrapperCompilation(
|
||||||
WasmEngine* engine, CompilationEnv* env) {
|
CompilationEnv* env) {
|
||||||
const FunctionSig* sig = env->module->functions[func_index_].sig;
|
const FunctionSig* sig = env->module->functions[func_index_].sig;
|
||||||
// Assume the wrapper is going to be a JS function with matching arity at
|
// Assume the wrapper is going to be a JS function with matching arity at
|
||||||
// instantiation time.
|
// instantiation time.
|
||||||
auto kind = compiler::kDefaultImportCallKind;
|
auto kind = compiler::kDefaultImportCallKind;
|
||||||
bool source_positions = is_asmjs_module(env->module);
|
bool source_positions = is_asmjs_module(env->module);
|
||||||
WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
|
WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
|
||||||
engine, env, kind, sig, source_positions,
|
env, kind, sig, source_positions,
|
||||||
static_cast<int>(sig->parameter_count()));
|
static_cast<int>(sig->parameter_count()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmCompilationResult WasmCompilationUnit::ExecuteFunctionCompilation(
|
WasmCompilationResult WasmCompilationUnit::ExecuteFunctionCompilation(
|
||||||
WasmEngine* wasm_engine, CompilationEnv* env,
|
CompilationEnv* env, const WireBytesStorage* wire_bytes_storage,
|
||||||
const WireBytesStorage* wire_bytes_storage, Counters* counters,
|
Counters* counters, WasmFeatures* detected) {
|
||||||
WasmFeatures* detected) {
|
|
||||||
auto* func = &env->module->functions[func_index_];
|
auto* func = &env->module->functions[func_index_];
|
||||||
base::Vector<const uint8_t> code = wire_bytes_storage->GetCode(func->code);
|
base::Vector<const uint8_t> code = wire_bytes_storage->GetCode(func->code);
|
||||||
wasm::FunctionBody func_body{func->sig, func->code.offset(), code.begin(),
|
wasm::FunctionBody func_body{func->sig, func->code.offset(), code.begin(),
|
||||||
@ -198,15 +196,14 @@ WasmCompilationResult WasmCompilationUnit::ExecuteFunctionCompilation(
|
|||||||
if (V8_LIKELY(func_index_ >= 32 || (FLAG_wasm_debug_mask_for_testing &
|
if (V8_LIKELY(func_index_ >= 32 || (FLAG_wasm_debug_mask_for_testing &
|
||||||
(1 << func_index_)) == 0)) {
|
(1 << func_index_)) == 0)) {
|
||||||
result = ExecuteLiftoffCompilation(
|
result = ExecuteLiftoffCompilation(
|
||||||
wasm_engine->allocator(), env, func_body, func_index_,
|
env, func_body, func_index_, for_debugging_, counters, detected);
|
||||||
for_debugging_, counters, detected);
|
|
||||||
} else {
|
} else {
|
||||||
// We don't use the debug side table, we only pass it to cover
|
// We don't use the debug side table, we only pass it to cover
|
||||||
// different code paths in Liftoff for testing.
|
// different code paths in Liftoff for testing.
|
||||||
std::unique_ptr<DebugSideTable> debug_sidetable;
|
std::unique_ptr<DebugSideTable> debug_sidetable;
|
||||||
result = ExecuteLiftoffCompilation(
|
result = ExecuteLiftoffCompilation(env, func_body, func_index_,
|
||||||
wasm_engine->allocator(), env, func_body, func_index_,
|
kForDebugging, counters, detected,
|
||||||
kForDebugging, counters, detected, {}, &debug_sidetable);
|
{}, &debug_sidetable);
|
||||||
}
|
}
|
||||||
if (result.succeeded()) break;
|
if (result.succeeded()) break;
|
||||||
}
|
}
|
||||||
@ -218,7 +215,7 @@ WasmCompilationResult WasmCompilationUnit::ExecuteFunctionCompilation(
|
|||||||
|
|
||||||
case ExecutionTier::kTurbofan:
|
case ExecutionTier::kTurbofan:
|
||||||
result = compiler::ExecuteTurbofanWasmCompilation(
|
result = compiler::ExecuteTurbofanWasmCompilation(
|
||||||
wasm_engine, env, func_body, func_index_, counters, detected);
|
env, func_body, func_index_, counters, detected);
|
||||||
result.for_debugging = for_debugging_;
|
result.for_debugging = for_debugging_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -266,8 +263,7 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
|
|||||||
WasmCompilationUnit unit(function->func_index, tier, kNoDebugging);
|
WasmCompilationUnit unit(function->func_index, tier, kNoDebugging);
|
||||||
CompilationEnv env = native_module->CreateCompilationEnv();
|
CompilationEnv env = native_module->CreateCompilationEnv();
|
||||||
WasmCompilationResult result = unit.ExecuteCompilation(
|
WasmCompilationResult result = unit.ExecuteCompilation(
|
||||||
GetWasmEngine(), &env,
|
&env, native_module->compilation_state()->GetWireBytesStorage().get(),
|
||||||
native_module->compilation_state()->GetWireBytesStorage().get(),
|
|
||||||
isolate->counters(), detected);
|
isolate->counters(), detected);
|
||||||
if (result.succeeded()) {
|
if (result.succeeded()) {
|
||||||
WasmCodeRefScope code_ref_scope;
|
WasmCodeRefScope code_ref_scope;
|
||||||
@ -303,18 +299,18 @@ bool UseGenericWrapper(const FunctionSig* sig) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
JSToWasmWrapperCompilationUnit::JSToWasmWrapperCompilationUnit(
|
JSToWasmWrapperCompilationUnit::JSToWasmWrapperCompilationUnit(
|
||||||
Isolate* isolate, WasmEngine* wasm_engine, const FunctionSig* sig,
|
Isolate* isolate, const FunctionSig* sig, const WasmModule* module,
|
||||||
const WasmModule* module, bool is_import,
|
bool is_import, const WasmFeatures& enabled_features,
|
||||||
const WasmFeatures& enabled_features, AllowGeneric allow_generic)
|
AllowGeneric allow_generic)
|
||||||
: isolate_(isolate),
|
: isolate_(isolate),
|
||||||
is_import_(is_import),
|
is_import_(is_import),
|
||||||
sig_(sig),
|
sig_(sig),
|
||||||
use_generic_wrapper_(allow_generic && UseGenericWrapper(sig) &&
|
use_generic_wrapper_(allow_generic && UseGenericWrapper(sig) &&
|
||||||
!is_import),
|
!is_import),
|
||||||
job_(use_generic_wrapper_ ? nullptr
|
job_(use_generic_wrapper_
|
||||||
: compiler::NewJSToWasmCompilationJob(
|
? nullptr
|
||||||
isolate, wasm_engine, sig, module,
|
: compiler::NewJSToWasmCompilationJob(
|
||||||
is_import, enabled_features)) {}
|
isolate, sig, module, is_import, enabled_features)) {}
|
||||||
|
|
||||||
JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit() = default;
|
JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit() = default;
|
||||||
|
|
||||||
@ -349,9 +345,8 @@ Handle<Code> JSToWasmWrapperCompilationUnit::CompileJSToWasmWrapper(
|
|||||||
bool is_import) {
|
bool is_import) {
|
||||||
// Run the compilation unit synchronously.
|
// Run the compilation unit synchronously.
|
||||||
WasmFeatures enabled_features = WasmFeatures::FromIsolate(isolate);
|
WasmFeatures enabled_features = WasmFeatures::FromIsolate(isolate);
|
||||||
JSToWasmWrapperCompilationUnit unit(isolate, GetWasmEngine(), sig, module,
|
JSToWasmWrapperCompilationUnit unit(isolate, sig, module, is_import,
|
||||||
is_import, enabled_features,
|
enabled_features, kAllowGeneric);
|
||||||
kAllowGeneric);
|
|
||||||
unit.Execute();
|
unit.Execute();
|
||||||
return unit.Finalize();
|
return unit.Finalize();
|
||||||
}
|
}
|
||||||
@ -362,9 +357,8 @@ Handle<Code> JSToWasmWrapperCompilationUnit::CompileSpecificJSToWasmWrapper(
|
|||||||
// Run the compilation unit synchronously.
|
// Run the compilation unit synchronously.
|
||||||
const bool is_import = false;
|
const bool is_import = false;
|
||||||
WasmFeatures enabled_features = WasmFeatures::FromIsolate(isolate);
|
WasmFeatures enabled_features = WasmFeatures::FromIsolate(isolate);
|
||||||
JSToWasmWrapperCompilationUnit unit(isolate, GetWasmEngine(), sig, module,
|
JSToWasmWrapperCompilationUnit unit(isolate, sig, module, is_import,
|
||||||
is_import, enabled_features,
|
enabled_features, kDontAllowGeneric);
|
||||||
kDontAllowGeneric);
|
|
||||||
unit.Execute();
|
unit.Execute();
|
||||||
return unit.Finalize();
|
return unit.Finalize();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
|
|||||||
WasmCompilationUnit(int index, ExecutionTier tier, ForDebugging for_debugging)
|
WasmCompilationUnit(int index, ExecutionTier tier, ForDebugging for_debugging)
|
||||||
: func_index_(index), tier_(tier), for_debugging_(for_debugging) {}
|
: func_index_(index), tier_(tier), for_debugging_(for_debugging) {}
|
||||||
|
|
||||||
WasmCompilationResult ExecuteCompilation(WasmEngine*, CompilationEnv*,
|
WasmCompilationResult ExecuteCompilation(CompilationEnv*,
|
||||||
const WireBytesStorage*, Counters*,
|
const WireBytesStorage*, Counters*,
|
||||||
WasmFeatures* detected);
|
WasmFeatures* detected);
|
||||||
|
|
||||||
@ -96,13 +96,12 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
|
|||||||
ExecutionTier);
|
ExecutionTier);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WasmCompilationResult ExecuteFunctionCompilation(WasmEngine*, CompilationEnv*,
|
WasmCompilationResult ExecuteFunctionCompilation(CompilationEnv*,
|
||||||
const WireBytesStorage*,
|
const WireBytesStorage*,
|
||||||
Counters*,
|
Counters*,
|
||||||
WasmFeatures* detected);
|
WasmFeatures* detected);
|
||||||
|
|
||||||
WasmCompilationResult ExecuteImportWrapperCompilation(WasmEngine*,
|
WasmCompilationResult ExecuteImportWrapperCompilation(CompilationEnv*);
|
||||||
CompilationEnv*);
|
|
||||||
|
|
||||||
int func_index_;
|
int func_index_;
|
||||||
ExecutionTier tier_;
|
ExecutionTier tier_;
|
||||||
@ -120,8 +119,7 @@ class V8_EXPORT_PRIVATE JSToWasmWrapperCompilationUnit final {
|
|||||||
// and return the builtin (generic) wrapper, when available.
|
// and return the builtin (generic) wrapper, when available.
|
||||||
enum AllowGeneric : bool { kAllowGeneric = true, kDontAllowGeneric = false };
|
enum AllowGeneric : bool { kAllowGeneric = true, kDontAllowGeneric = false };
|
||||||
|
|
||||||
JSToWasmWrapperCompilationUnit(Isolate* isolate, WasmEngine* wasm_engine,
|
JSToWasmWrapperCompilationUnit(Isolate* isolate, const FunctionSig* sig,
|
||||||
const FunctionSig* sig,
|
|
||||||
const wasm::WasmModule* module, bool is_import,
|
const wasm::WasmModule* module, bool is_import,
|
||||||
const WasmFeatures& enabled_features,
|
const WasmFeatures& enabled_features,
|
||||||
AllowGeneric allow_generic);
|
AllowGeneric allow_generic);
|
||||||
|
@ -535,7 +535,7 @@ class CompilationStateImpl {
|
|||||||
|
|
||||||
// Call right after the constructor, after the {compilation_state_} field in
|
// Call right after the constructor, after the {compilation_state_} field in
|
||||||
// the {NativeModule} has been initialized.
|
// the {NativeModule} has been initialized.
|
||||||
void InitCompileJob(WasmEngine*);
|
void InitCompileJob();
|
||||||
|
|
||||||
// {kCancelUnconditionally}: Cancel all compilation.
|
// {kCancelUnconditionally}: Cancel all compilation.
|
||||||
// {kCancelInitialCompilation}: Cancel all compilation if initial (baseline)
|
// {kCancelInitialCompilation}: Cancel all compilation if initial (baseline)
|
||||||
@ -784,9 +784,7 @@ void UpdateFeatureUseCounts(Isolate* isolate, const WasmFeatures& detected) {
|
|||||||
|
|
||||||
CompilationState::~CompilationState() { Impl(this)->~CompilationStateImpl(); }
|
CompilationState::~CompilationState() { Impl(this)->~CompilationStateImpl(); }
|
||||||
|
|
||||||
void CompilationState::InitCompileJob(WasmEngine* engine) {
|
void CompilationState::InitCompileJob() { Impl(this)->InitCompileJob(); }
|
||||||
Impl(this)->InitCompileJob(engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompilationState::CancelCompilation() {
|
void CompilationState::CancelCompilation() {
|
||||||
Impl(this)->CancelCompilation(CompilationStateImpl::kCancelUnconditionally);
|
Impl(this)->CancelCompilation(CompilationStateImpl::kCancelUnconditionally);
|
||||||
@ -1128,7 +1126,7 @@ bool CompileLazy(Isolate* isolate, Handle<WasmModuleObject> module_object,
|
|||||||
WasmEngine* engine = GetWasmEngine();
|
WasmEngine* engine = GetWasmEngine();
|
||||||
WasmFeatures detected_features;
|
WasmFeatures detected_features;
|
||||||
WasmCompilationResult result = baseline_unit.ExecuteCompilation(
|
WasmCompilationResult result = baseline_unit.ExecuteCompilation(
|
||||||
engine, &env, compilation_state->GetWireBytesStorage().get(), counters,
|
&env, compilation_state->GetWireBytesStorage().get(), counters,
|
||||||
&detected_features);
|
&detected_features);
|
||||||
compilation_state->OnCompilationStopped(detected_features);
|
compilation_state->OnCompilationStopped(detected_features);
|
||||||
|
|
||||||
@ -1218,8 +1216,7 @@ CompilationExecutionResult ExecuteJSToWasmWrapperCompilationUnits(
|
|||||||
if (!wrapper_unit) return kNoMoreUnits;
|
if (!wrapper_unit) return kNoMoreUnits;
|
||||||
isolate = wrapper_unit->isolate();
|
isolate = wrapper_unit->isolate();
|
||||||
wrapper_compilation_token =
|
wrapper_compilation_token =
|
||||||
compile_scope.native_module()->engine()->StartWrapperCompilation(
|
wasm::GetWasmEngine()->StartWrapperCompilation(isolate);
|
||||||
isolate);
|
|
||||||
if (!wrapper_compilation_token) return kNoMoreUnits;
|
if (!wrapper_compilation_token) return kNoMoreUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1277,7 +1274,6 @@ CompilationExecutionResult ExecuteCompilationUnits(
|
|||||||
|
|
||||||
// These fields are initialized in a {BackgroundCompileScope} before
|
// These fields are initialized in a {BackgroundCompileScope} before
|
||||||
// starting compilation.
|
// starting compilation.
|
||||||
WasmEngine* engine;
|
|
||||||
base::Optional<CompilationEnv> env;
|
base::Optional<CompilationEnv> env;
|
||||||
std::shared_ptr<WireBytesStorage> wire_bytes;
|
std::shared_ptr<WireBytesStorage> wire_bytes;
|
||||||
std::shared_ptr<const WasmModule> module;
|
std::shared_ptr<const WasmModule> module;
|
||||||
@ -1296,7 +1292,6 @@ CompilationExecutionResult ExecuteCompilationUnits(
|
|||||||
{
|
{
|
||||||
BackgroundCompileScope compile_scope(native_module);
|
BackgroundCompileScope compile_scope(native_module);
|
||||||
if (compile_scope.cancelled()) return kYield;
|
if (compile_scope.cancelled()) return kYield;
|
||||||
engine = compile_scope.native_module()->engine();
|
|
||||||
env.emplace(compile_scope.native_module()->CreateCompilationEnv());
|
env.emplace(compile_scope.native_module()->CreateCompilationEnv());
|
||||||
wire_bytes = compile_scope.compilation_state()->GetWireBytesStorage();
|
wire_bytes = compile_scope.compilation_state()->GetWireBytesStorage();
|
||||||
module = compile_scope.native_module()->shared_module();
|
module = compile_scope.native_module()->shared_module();
|
||||||
@ -1315,7 +1310,7 @@ CompilationExecutionResult ExecuteCompilationUnits(
|
|||||||
while (unit->tier() == current_tier) {
|
while (unit->tier() == current_tier) {
|
||||||
// (asynchronous): Execute the compilation.
|
// (asynchronous): Execute the compilation.
|
||||||
WasmCompilationResult result = unit->ExecuteCompilation(
|
WasmCompilationResult result = unit->ExecuteCompilation(
|
||||||
engine, &env.value(), wire_bytes.get(), counters, &detected_features);
|
&env.value(), wire_bytes.get(), counters, &detected_features);
|
||||||
results_to_publish.emplace_back(std::move(result));
|
results_to_publish.emplace_back(std::move(result));
|
||||||
|
|
||||||
bool yield = delegate && delegate->ShouldYield();
|
bool yield = delegate && delegate->ShouldYield();
|
||||||
@ -1369,8 +1364,7 @@ CompilationExecutionResult ExecuteCompilationUnits(
|
|||||||
using JSToWasmWrapperKey = std::pair<bool, FunctionSig>;
|
using JSToWasmWrapperKey = std::pair<bool, FunctionSig>;
|
||||||
|
|
||||||
// Returns the number of units added.
|
// Returns the number of units added.
|
||||||
int AddExportWrapperUnits(Isolate* isolate, WasmEngine* wasm_engine,
|
int AddExportWrapperUnits(Isolate* isolate, NativeModule* native_module,
|
||||||
NativeModule* native_module,
|
|
||||||
CompilationUnitBuilder* builder,
|
CompilationUnitBuilder* builder,
|
||||||
const WasmFeatures& enabled_features) {
|
const WasmFeatures& enabled_features) {
|
||||||
std::unordered_set<JSToWasmWrapperKey, base::hash<JSToWasmWrapperKey>> keys;
|
std::unordered_set<JSToWasmWrapperKey, base::hash<JSToWasmWrapperKey>> keys;
|
||||||
@ -1380,9 +1374,8 @@ int AddExportWrapperUnits(Isolate* isolate, WasmEngine* wasm_engine,
|
|||||||
JSToWasmWrapperKey key(function.imported, *function.sig);
|
JSToWasmWrapperKey key(function.imported, *function.sig);
|
||||||
if (keys.insert(key).second) {
|
if (keys.insert(key).second) {
|
||||||
auto unit = std::make_shared<JSToWasmWrapperCompilationUnit>(
|
auto unit = std::make_shared<JSToWasmWrapperCompilationUnit>(
|
||||||
isolate, wasm_engine, function.sig, native_module->module(),
|
isolate, function.sig, native_module->module(), function.imported,
|
||||||
function.imported, enabled_features,
|
enabled_features, JSToWasmWrapperCompilationUnit::kAllowGeneric);
|
||||||
JSToWasmWrapperCompilationUnit::kAllowGeneric);
|
|
||||||
builder->AddJSToWasmWrapperUnit(std::move(unit));
|
builder->AddJSToWasmWrapperUnit(std::move(unit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1455,9 +1448,8 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int num_import_wrappers = AddImportWrapperUnits(native_module, &builder);
|
int num_import_wrappers = AddImportWrapperUnits(native_module, &builder);
|
||||||
int num_export_wrappers =
|
int num_export_wrappers = AddExportWrapperUnits(
|
||||||
AddExportWrapperUnits(isolate, GetWasmEngine(), native_module, &builder,
|
isolate, native_module, &builder, WasmFeatures::FromIsolate(isolate));
|
||||||
WasmFeatures::FromIsolate(isolate));
|
|
||||||
compilation_state->InitializeCompilationProgress(
|
compilation_state->InitializeCompilationProgress(
|
||||||
lazy_module, num_import_wrappers, num_export_wrappers);
|
lazy_module, num_import_wrappers, num_export_wrappers);
|
||||||
builder.Commit();
|
builder.Commit();
|
||||||
@ -1631,10 +1623,9 @@ void CompileNativeModule(Isolate* isolate,
|
|||||||
class BackgroundCompileJob final : public JobTask {
|
class BackgroundCompileJob final : public JobTask {
|
||||||
public:
|
public:
|
||||||
explicit BackgroundCompileJob(std::weak_ptr<NativeModule> native_module,
|
explicit BackgroundCompileJob(std::weak_ptr<NativeModule> native_module,
|
||||||
WasmEngine* engine,
|
|
||||||
std::shared_ptr<Counters> async_counters)
|
std::shared_ptr<Counters> async_counters)
|
||||||
: native_module_(std::move(native_module)),
|
: native_module_(std::move(native_module)),
|
||||||
engine_barrier_(engine->GetBarrierForBackgroundCompile()),
|
engine_barrier_(GetWasmEngine()->GetBarrierForBackgroundCompile()),
|
||||||
async_counters_(std::move(async_counters)) {}
|
async_counters_(std::move(async_counters)) {}
|
||||||
|
|
||||||
void Run(JobDelegate* delegate) override {
|
void Run(JobDelegate* delegate) override {
|
||||||
@ -1830,7 +1821,6 @@ class AsyncStreamingProcessor final : public StreamingProcessor {
|
|||||||
|
|
||||||
ModuleDecoder decoder_;
|
ModuleDecoder decoder_;
|
||||||
AsyncCompileJob* job_;
|
AsyncCompileJob* job_;
|
||||||
WasmEngine* wasm_engine_;
|
|
||||||
std::unique_ptr<CompilationUnitBuilder> compilation_unit_builder_;
|
std::unique_ptr<CompilationUnitBuilder> compilation_unit_builder_;
|
||||||
int num_functions_ = 0;
|
int num_functions_ = 0;
|
||||||
bool prefix_cache_hit_ = false;
|
bool prefix_cache_hit_ = false;
|
||||||
@ -2452,7 +2442,6 @@ AsyncStreamingProcessor::AsyncStreamingProcessor(
|
|||||||
AccountingAllocator* allocator)
|
AccountingAllocator* allocator)
|
||||||
: decoder_(job->enabled_features_),
|
: decoder_(job->enabled_features_),
|
||||||
job_(job),
|
job_(job),
|
||||||
wasm_engine_(GetWasmEngine()),
|
|
||||||
compilation_unit_builder_(nullptr),
|
compilation_unit_builder_(nullptr),
|
||||||
async_counters_(async_counters),
|
async_counters_(async_counters),
|
||||||
allocator_(allocator) {}
|
allocator_(allocator) {}
|
||||||
@ -2576,7 +2565,7 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(
|
|||||||
|
|
||||||
prefix_hash_ = base::hash_combine(prefix_hash_,
|
prefix_hash_ = base::hash_combine(prefix_hash_,
|
||||||
static_cast<uint32_t>(code_section_length));
|
static_cast<uint32_t>(code_section_length));
|
||||||
if (!wasm_engine_->GetStreamingCompilationOwnership(prefix_hash_)) {
|
if (!GetWasmEngine()->GetStreamingCompilationOwnership(prefix_hash_)) {
|
||||||
// Known prefix, wait until the end of the stream and check the cache.
|
// Known prefix, wait until the end of the stream and check the cache.
|
||||||
prefix_cache_hit_ = true;
|
prefix_cache_hit_ = true;
|
||||||
return true;
|
return true;
|
||||||
@ -2611,8 +2600,8 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(
|
|||||||
int num_import_wrappers =
|
int num_import_wrappers =
|
||||||
AddImportWrapperUnits(native_module, compilation_unit_builder_.get());
|
AddImportWrapperUnits(native_module, compilation_unit_builder_.get());
|
||||||
int num_export_wrappers = AddExportWrapperUnits(
|
int num_export_wrappers = AddExportWrapperUnits(
|
||||||
job_->isolate_, wasm_engine_, native_module,
|
job_->isolate_, native_module, compilation_unit_builder_.get(),
|
||||||
compilation_unit_builder_.get(), job_->enabled_features_);
|
job_->enabled_features_);
|
||||||
compilation_state->InitializeCompilationProgress(
|
compilation_state->InitializeCompilationProgress(
|
||||||
lazy_module, num_import_wrappers, num_export_wrappers);
|
lazy_module, num_import_wrappers, num_export_wrappers);
|
||||||
return true;
|
return true;
|
||||||
@ -2825,12 +2814,11 @@ CompilationStateImpl::CompilationStateImpl(
|
|||||||
async_counters_(std::move(async_counters)),
|
async_counters_(std::move(async_counters)),
|
||||||
compilation_unit_queues_(native_module->num_functions()) {}
|
compilation_unit_queues_(native_module->num_functions()) {}
|
||||||
|
|
||||||
void CompilationStateImpl::InitCompileJob(WasmEngine* engine) {
|
void CompilationStateImpl::InitCompileJob() {
|
||||||
DCHECK_NULL(compile_job_);
|
DCHECK_NULL(compile_job_);
|
||||||
compile_job_ = V8::GetCurrentPlatform()->PostJob(
|
compile_job_ = V8::GetCurrentPlatform()->PostJob(
|
||||||
TaskPriority::kUserVisible,
|
TaskPriority::kUserVisible, std::make_unique<BackgroundCompileJob>(
|
||||||
std::make_unique<BackgroundCompileJob>(native_module_weak_, engine,
|
native_module_weak_, async_counters_));
|
||||||
async_counters_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilationStateImpl::CancelCompilation(
|
void CompilationStateImpl::CancelCompilation(
|
||||||
@ -3485,8 +3473,8 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
|
|||||||
JSToWasmWrapperKey key(function.imported, *function.sig);
|
JSToWasmWrapperKey key(function.imported, *function.sig);
|
||||||
if (queue.insert(key)) {
|
if (queue.insert(key)) {
|
||||||
auto unit = std::make_unique<JSToWasmWrapperCompilationUnit>(
|
auto unit = std::make_unique<JSToWasmWrapperCompilationUnit>(
|
||||||
isolate, GetWasmEngine(), function.sig, module, function.imported,
|
isolate, function.sig, module, function.imported, enabled_features,
|
||||||
enabled_features, JSToWasmWrapperCompilationUnit::kAllowGeneric);
|
JSToWasmWrapperCompilationUnit::kAllowGeneric);
|
||||||
compilation_units.emplace(key, std::move(unit));
|
compilation_units.emplace(key, std::move(unit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3520,7 +3508,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
|
|||||||
}
|
}
|
||||||
|
|
||||||
WasmCode* CompileImportWrapper(
|
WasmCode* CompileImportWrapper(
|
||||||
WasmEngine* wasm_engine, NativeModule* native_module, Counters* counters,
|
NativeModule* native_module, Counters* counters,
|
||||||
compiler::WasmImportCallKind kind, const FunctionSig* sig,
|
compiler::WasmImportCallKind kind, const FunctionSig* sig,
|
||||||
int expected_arity,
|
int expected_arity,
|
||||||
WasmImportWrapperCache::ModificationScope* cache_scope) {
|
WasmImportWrapperCache::ModificationScope* cache_scope) {
|
||||||
@ -3534,7 +3522,7 @@ WasmCode* CompileImportWrapper(
|
|||||||
WasmCodeRefScope code_ref_scope;
|
WasmCodeRefScope code_ref_scope;
|
||||||
CompilationEnv env = native_module->CreateCompilationEnv();
|
CompilationEnv env = native_module->CreateCompilationEnv();
|
||||||
WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
|
WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
|
||||||
wasm_engine, &env, kind, sig, source_positions, expected_arity);
|
&env, kind, sig, source_positions, expected_arity);
|
||||||
std::unique_ptr<WasmCode> wasm_code = native_module->AddCode(
|
std::unique_ptr<WasmCode> wasm_code = native_module->AddCode(
|
||||||
result.func_index, result.code_desc, result.frame_slot_count,
|
result.func_index, result.code_desc, result.frame_slot_count,
|
||||||
result.tagged_parameter_slots,
|
result.tagged_parameter_slots,
|
||||||
|
@ -64,7 +64,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
|
|||||||
// compiled yet.
|
// compiled yet.
|
||||||
V8_EXPORT_PRIVATE
|
V8_EXPORT_PRIVATE
|
||||||
WasmCode* CompileImportWrapper(
|
WasmCode* CompileImportWrapper(
|
||||||
WasmEngine* wasm_engine, NativeModule* native_module, Counters* counters,
|
NativeModule* native_module, Counters* counters,
|
||||||
compiler::WasmImportCallKind kind, const FunctionSig* sig,
|
compiler::WasmImportCallKind kind, const FunctionSig* sig,
|
||||||
int expected_arity, WasmImportWrapperCache::ModificationScope* cache_scope);
|
int expected_arity, WasmImportWrapperCache::ModificationScope* cache_scope);
|
||||||
|
|
||||||
|
@ -45,11 +45,10 @@ using ImportWrapperQueue = WrapperQueue<WasmImportWrapperCache::CacheKey,
|
|||||||
class CompileImportWrapperJob final : public JobTask {
|
class CompileImportWrapperJob final : public JobTask {
|
||||||
public:
|
public:
|
||||||
CompileImportWrapperJob(
|
CompileImportWrapperJob(
|
||||||
WasmEngine* engine, Counters* counters, NativeModule* native_module,
|
Counters* counters, NativeModule* native_module,
|
||||||
ImportWrapperQueue* queue,
|
ImportWrapperQueue* queue,
|
||||||
WasmImportWrapperCache::ModificationScope* cache_scope)
|
WasmImportWrapperCache::ModificationScope* cache_scope)
|
||||||
: engine_(engine),
|
: counters_(counters),
|
||||||
counters_(counters),
|
|
||||||
native_module_(native_module),
|
native_module_(native_module),
|
||||||
queue_(queue),
|
queue_(queue),
|
||||||
cache_scope_(cache_scope) {}
|
cache_scope_(cache_scope) {}
|
||||||
@ -65,14 +64,13 @@ class CompileImportWrapperJob final : public JobTask {
|
|||||||
void Run(JobDelegate* delegate) override {
|
void Run(JobDelegate* delegate) override {
|
||||||
while (base::Optional<WasmImportWrapperCache::CacheKey> key =
|
while (base::Optional<WasmImportWrapperCache::CacheKey> key =
|
||||||
queue_->pop()) {
|
queue_->pop()) {
|
||||||
CompileImportWrapper(engine_, native_module_, counters_, key->kind,
|
CompileImportWrapper(native_module_, counters_, key->kind, key->signature,
|
||||||
key->signature, key->expected_arity, cache_scope_);
|
key->expected_arity, cache_scope_);
|
||||||
if (delegate->ShouldYield()) return;
|
if (delegate->ShouldYield()) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WasmEngine* const engine_;
|
|
||||||
Counters* const counters_;
|
Counters* const counters_;
|
||||||
NativeModule* const native_module_;
|
NativeModule* const native_module_;
|
||||||
ImportWrapperQueue* const queue_;
|
ImportWrapperQueue* const queue_;
|
||||||
@ -997,8 +995,8 @@ bool InstanceBuilder::ProcessImportedFunction(
|
|||||||
if (wasm_code == nullptr) {
|
if (wasm_code == nullptr) {
|
||||||
WasmCodeRefScope code_ref_scope;
|
WasmCodeRefScope code_ref_scope;
|
||||||
WasmImportWrapperCache::ModificationScope cache_scope(cache);
|
WasmImportWrapperCache::ModificationScope cache_scope(cache);
|
||||||
wasm_code = compiler::CompileWasmCapiCallWrapper(
|
wasm_code =
|
||||||
wasm::GetWasmEngine(), native_module, expected_sig);
|
compiler::CompileWasmCapiCallWrapper(native_module, expected_sig);
|
||||||
WasmImportWrapperCache::CacheKey key(kind, expected_sig,
|
WasmImportWrapperCache::CacheKey key(kind, expected_sig,
|
||||||
expected_arity);
|
expected_arity);
|
||||||
cache_scope[key] = wasm_code;
|
cache_scope[key] = wasm_code;
|
||||||
@ -1438,8 +1436,7 @@ void InstanceBuilder::CompileImportWrappers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto compile_job_task = std::make_unique<CompileImportWrapperJob>(
|
auto compile_job_task = std::make_unique<CompileImportWrapperJob>(
|
||||||
wasm::GetWasmEngine(), isolate_->counters(), native_module,
|
isolate_->counters(), native_module, &import_wrapper_queue, &cache_scope);
|
||||||
&import_wrapper_queue, &cache_scope);
|
|
||||||
auto compile_job = V8::GetCurrentPlatform()->PostJob(
|
auto compile_job = V8::GetCurrentPlatform()->PostJob(
|
||||||
TaskPriority::kUserVisible, std::move(compile_job_task));
|
TaskPriority::kUserVisible, std::move(compile_job_task));
|
||||||
|
|
||||||
|
@ -863,7 +863,7 @@ NativeModule::NativeModule(WasmEngine* engine, const WasmFeatures& enabled,
|
|||||||
shared_this->reset(this);
|
shared_this->reset(this);
|
||||||
compilation_state_ =
|
compilation_state_ =
|
||||||
CompilationState::New(*shared_this, std::move(async_counters));
|
CompilationState::New(*shared_this, std::move(async_counters));
|
||||||
compilation_state_->InitCompileJob(engine);
|
compilation_state_->InitCompileJob();
|
||||||
DCHECK_NOT_NULL(module_);
|
DCHECK_NOT_NULL(module_);
|
||||||
if (module_->num_declared_functions > 0) {
|
if (module_->num_declared_functions > 0) {
|
||||||
code_table_ =
|
code_table_ =
|
||||||
|
@ -283,9 +283,9 @@ class DebugInfoImpl {
|
|||||||
Counters* counters = nullptr;
|
Counters* counters = nullptr;
|
||||||
WasmFeatures unused_detected;
|
WasmFeatures unused_detected;
|
||||||
WasmCompilationResult result = ExecuteLiftoffCompilation(
|
WasmCompilationResult result = ExecuteLiftoffCompilation(
|
||||||
native_module_->engine()->allocator(), &env, body, func_index,
|
&env, body, func_index, for_debugging, counters, &unused_detected,
|
||||||
for_debugging, counters, &unused_detected, offsets,
|
offsets, generate_debug_sidetable ? &debug_sidetable : nullptr,
|
||||||
generate_debug_sidetable ? &debug_sidetable : nullptr, dead_breakpoint);
|
dead_breakpoint);
|
||||||
// Liftoff compilation failure is a FATAL error. We rely on complete Liftoff
|
// Liftoff compilation failure is a FATAL error. We rely on complete Liftoff
|
||||||
// support for debugging.
|
// support for debugging.
|
||||||
if (!result.succeeded()) FATAL("Liftoff compilation failed");
|
if (!result.succeeded()) FATAL("Liftoff compilation failed");
|
||||||
|
@ -624,8 +624,7 @@ void WasmTableObject::UpdateDispatchTables(
|
|||||||
if (wasm_code == nullptr) {
|
if (wasm_code == nullptr) {
|
||||||
wasm::WasmCodeRefScope code_ref_scope;
|
wasm::WasmCodeRefScope code_ref_scope;
|
||||||
wasm::WasmImportWrapperCache::ModificationScope cache_scope(cache);
|
wasm::WasmImportWrapperCache::ModificationScope cache_scope(cache);
|
||||||
wasm_code = compiler::CompileWasmCapiCallWrapper(wasm::GetWasmEngine(),
|
wasm_code = compiler::CompileWasmCapiCallWrapper(native_module, &sig);
|
||||||
native_module, &sig);
|
|
||||||
wasm::WasmImportWrapperCache::CacheKey key(kind, &sig, param_count);
|
wasm::WasmImportWrapperCache::CacheKey key(kind, &sig, param_count);
|
||||||
cache_scope[key] = wasm_code;
|
cache_scope[key] = wasm_code;
|
||||||
wasm_code->IncRef();
|
wasm_code->IncRef();
|
||||||
@ -1544,7 +1543,7 @@ void WasmInstanceObject::ImportWasmJSFunctionIntoTable(
|
|||||||
.internal_formal_parameter_count();
|
.internal_formal_parameter_count();
|
||||||
}
|
}
|
||||||
wasm::WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
|
wasm::WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
|
||||||
wasm::GetWasmEngine(), &env, kind, sig, false, expected_arity);
|
&env, kind, sig, false, expected_arity);
|
||||||
std::unique_ptr<wasm::WasmCode> wasm_code = native_module->AddCode(
|
std::unique_ptr<wasm::WasmCode> wasm_code = native_module->AddCode(
|
||||||
result.func_index, result.code_desc, result.frame_slot_count,
|
result.func_index, result.code_desc, result.frame_slot_count,
|
||||||
result.tagged_parameter_slots,
|
result.tagged_parameter_slots,
|
||||||
|
@ -45,11 +45,11 @@ class LiftoffCompileEnvironment {
|
|||||||
WasmFeatures detected1;
|
WasmFeatures detected1;
|
||||||
WasmFeatures detected2;
|
WasmFeatures detected2;
|
||||||
WasmCompilationResult result1 = ExecuteLiftoffCompilation(
|
WasmCompilationResult result1 = ExecuteLiftoffCompilation(
|
||||||
isolate_->allocator(), &env, test_func.body, test_func.code->index(),
|
&env, test_func.body, test_func.code->index(), kNoDebugging,
|
||||||
kNoDebugging, isolate_->counters(), &detected1);
|
isolate_->counters(), &detected1);
|
||||||
WasmCompilationResult result2 = ExecuteLiftoffCompilation(
|
WasmCompilationResult result2 = ExecuteLiftoffCompilation(
|
||||||
isolate_->allocator(), &env, test_func.body, test_func.code->index(),
|
&env, test_func.body, test_func.code->index(), kNoDebugging,
|
||||||
kNoDebugging, isolate_->counters(), &detected2);
|
isolate_->counters(), &detected2);
|
||||||
|
|
||||||
CHECK(result1.succeeded());
|
CHECK(result1.succeeded());
|
||||||
CHECK(result2.succeeded());
|
CHECK(result2.succeeded());
|
||||||
@ -74,9 +74,8 @@ class LiftoffCompileEnvironment {
|
|||||||
WasmFeatures detected;
|
WasmFeatures detected;
|
||||||
std::unique_ptr<DebugSideTable> debug_side_table_via_compilation;
|
std::unique_ptr<DebugSideTable> debug_side_table_via_compilation;
|
||||||
auto result = ExecuteLiftoffCompilation(
|
auto result = ExecuteLiftoffCompilation(
|
||||||
CcTest::i_isolate()->allocator(), &env, test_func.body, 0,
|
&env, test_func.body, 0, kForDebugging, nullptr, &detected,
|
||||||
kForDebugging, nullptr, &detected, base::VectorOf(breakpoints),
|
base::VectorOf(breakpoints), &debug_side_table_via_compilation);
|
||||||
&debug_side_table_via_compilation);
|
|
||||||
CHECK(result.succeeded());
|
CHECK(result.succeeded());
|
||||||
|
|
||||||
// If there are no breakpoint, then {ExecuteLiftoffCompilation} should
|
// If there are no breakpoint, then {ExecuteLiftoffCompilation} should
|
||||||
|
@ -39,9 +39,8 @@ TEST(CacheHit) {
|
|||||||
auto sig = sigs.i_i();
|
auto sig = sigs.i_i();
|
||||||
int expected_arity = static_cast<int>(sig->parameter_count());
|
int expected_arity = static_cast<int>(sig->parameter_count());
|
||||||
|
|
||||||
WasmCode* c1 =
|
WasmCode* c1 = CompileImportWrapper(module.get(), isolate->counters(), kind,
|
||||||
CompileImportWrapper(GetWasmEngine(), module.get(), isolate->counters(),
|
sig, expected_arity, &cache_scope);
|
||||||
kind, sig, expected_arity, &cache_scope);
|
|
||||||
|
|
||||||
CHECK_NOT_NULL(c1);
|
CHECK_NOT_NULL(c1);
|
||||||
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
||||||
@ -66,9 +65,8 @@ TEST(CacheMissSig) {
|
|||||||
auto sig2 = sigs.i_ii();
|
auto sig2 = sigs.i_ii();
|
||||||
int expected_arity2 = static_cast<int>(sig2->parameter_count());
|
int expected_arity2 = static_cast<int>(sig2->parameter_count());
|
||||||
|
|
||||||
WasmCode* c1 =
|
WasmCode* c1 = CompileImportWrapper(module.get(), isolate->counters(), kind,
|
||||||
CompileImportWrapper(GetWasmEngine(), module.get(), isolate->counters(),
|
sig1, expected_arity1, &cache_scope);
|
||||||
kind, sig1, expected_arity1, &cache_scope);
|
|
||||||
|
|
||||||
CHECK_NOT_NULL(c1);
|
CHECK_NOT_NULL(c1);
|
||||||
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
||||||
@ -91,9 +89,8 @@ TEST(CacheMissKind) {
|
|||||||
auto sig = sigs.i_i();
|
auto sig = sigs.i_i();
|
||||||
int expected_arity = static_cast<int>(sig->parameter_count());
|
int expected_arity = static_cast<int>(sig->parameter_count());
|
||||||
|
|
||||||
WasmCode* c1 =
|
WasmCode* c1 = CompileImportWrapper(module.get(), isolate->counters(), kind1,
|
||||||
CompileImportWrapper(GetWasmEngine(), module.get(), isolate->counters(),
|
sig, expected_arity, &cache_scope);
|
||||||
kind1, sig, expected_arity, &cache_scope);
|
|
||||||
|
|
||||||
CHECK_NOT_NULL(c1);
|
CHECK_NOT_NULL(c1);
|
||||||
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
||||||
@ -117,9 +114,8 @@ TEST(CacheHitMissSig) {
|
|||||||
auto sig2 = sigs.i_ii();
|
auto sig2 = sigs.i_ii();
|
||||||
int expected_arity2 = static_cast<int>(sig2->parameter_count());
|
int expected_arity2 = static_cast<int>(sig2->parameter_count());
|
||||||
|
|
||||||
WasmCode* c1 =
|
WasmCode* c1 = CompileImportWrapper(module.get(), isolate->counters(), kind,
|
||||||
CompileImportWrapper(GetWasmEngine(), module.get(), isolate->counters(),
|
sig1, expected_arity1, &cache_scope);
|
||||||
kind, sig1, expected_arity1, &cache_scope);
|
|
||||||
|
|
||||||
CHECK_NOT_NULL(c1);
|
CHECK_NOT_NULL(c1);
|
||||||
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
CHECK_EQ(WasmCode::Kind::kWasmToJsWrapper, c1->kind());
|
||||||
@ -128,8 +124,8 @@ TEST(CacheHitMissSig) {
|
|||||||
|
|
||||||
CHECK_NULL(c2);
|
CHECK_NULL(c2);
|
||||||
|
|
||||||
c2 = CompileImportWrapper(GetWasmEngine(), module.get(), isolate->counters(),
|
c2 = CompileImportWrapper(module.get(), isolate->counters(), kind, sig2,
|
||||||
kind, sig2, expected_arity2, &cache_scope);
|
expected_arity2, &cache_scope);
|
||||||
|
|
||||||
CHECK_NE(c1, c2);
|
CHECK_NE(c1, c2);
|
||||||
|
|
||||||
|
@ -63,8 +63,7 @@ TestingModuleBuilder::TestingModuleBuilder(
|
|||||||
auto import_wrapper = cache_scope[key];
|
auto import_wrapper = cache_scope[key];
|
||||||
if (import_wrapper == nullptr) {
|
if (import_wrapper == nullptr) {
|
||||||
import_wrapper = CompileImportWrapper(
|
import_wrapper = CompileImportWrapper(
|
||||||
GetWasmEngine(), native_module_, isolate_->counters(), kind,
|
native_module_, isolate_->counters(), kind, maybe_import->sig,
|
||||||
maybe_import->sig,
|
|
||||||
static_cast<int>(maybe_import->sig->parameter_count()), &cache_scope);
|
static_cast<int>(maybe_import->sig->parameter_count()), &cache_scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,15 +558,14 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
|
|||||||
if (builder_->test_execution_tier() ==
|
if (builder_->test_execution_tier() ==
|
||||||
TestExecutionTier::kLiftoffForFuzzing) {
|
TestExecutionTier::kLiftoffForFuzzing) {
|
||||||
result.emplace(ExecuteLiftoffCompilation(
|
result.emplace(ExecuteLiftoffCompilation(
|
||||||
GetWasmEngine()->allocator(), &env, func_body, function_->func_index,
|
&env, func_body, function_->func_index, kForDebugging,
|
||||||
kForDebugging, isolate()->counters(), &unused_detected_features, {},
|
isolate()->counters(), &unused_detected_features, {}, nullptr, 0,
|
||||||
nullptr, 0, builder_->max_steps_ptr()));
|
builder_->max_steps_ptr()));
|
||||||
} else {
|
} else {
|
||||||
WasmCompilationUnit unit(function_->func_index, builder_->execution_tier(),
|
WasmCompilationUnit unit(function_->func_index, builder_->execution_tier(),
|
||||||
for_debugging);
|
for_debugging);
|
||||||
result.emplace(unit.ExecuteCompilation(
|
result.emplace(unit.ExecuteCompilation(
|
||||||
GetWasmEngine(), &env,
|
&env, native_module->compilation_state()->GetWireBytesStorage().get(),
|
||||||
native_module->compilation_state()->GetWireBytesStorage().get(),
|
|
||||||
isolate()->counters(), &unused_detected_features));
|
isolate()->counters(), &unused_detected_features));
|
||||||
}
|
}
|
||||||
WasmCode* code = native_module->PublishCode(
|
WasmCode* code = native_module->PublishCode(
|
||||||
|
Loading…
Reference in New Issue
Block a user