Commit 70aacc2e authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Make WasmCompilationUnit independent of Isolate.

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

Change-Id: I3055d4d98c108ce6e576f7171b8fae4e6b2c3948
Reviewed-on: https://chromium-review.googlesource.com/1131132
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54470}
parent 8a011b57
...@@ -723,7 +723,7 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) { ...@@ -723,7 +723,7 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) {
buffer << "-- "; buffer << "-- ";
// Turbolizer only needs the source position, as it can reconstruct // Turbolizer only needs the source position, as it can reconstruct
// the inlining stack from other information. // the inlining stack from other information.
if (info->trace_turbo_json_enabled() || if (info->trace_turbo_json_enabled() || !tasm()->isolate() ||
tasm()->isolate()->concurrent_recompilation_enabled()) { tasm()->isolate()->concurrent_recompilation_enabled()) {
buffer << source_position; buffer << source_position;
} else { } else {
......
...@@ -105,6 +105,7 @@ class PipelineData { ...@@ -105,6 +105,7 @@ class PipelineData {
OptimizedCompilationInfo* info, OptimizedCompilationInfo* info,
PipelineStatistics* pipeline_statistics) PipelineStatistics* pipeline_statistics)
: isolate_(isolate), : isolate_(isolate),
allocator_(isolate->allocator()),
info_(info), info_(info),
debug_name_(info_->GetDebugName()), debug_name_(info_->GetDebugName()),
may_have_unverifiable_graph_(false), may_have_unverifiable_graph_(false),
...@@ -140,16 +141,17 @@ class PipelineData { ...@@ -140,16 +141,17 @@ class PipelineData {
} }
// For WebAssembly compile entry point. // For WebAssembly compile entry point.
PipelineData(ZoneStats* zone_stats, Isolate* isolate, PipelineData(ZoneStats* zone_stats, wasm::WasmEngine* wasm_engine,
wasm::WasmEngine* wasm_engine, OptimizedCompilationInfo* info, OptimizedCompilationInfo* info, MachineGraph* mcgraph,
MachineGraph* mcgraph, PipelineStatistics* pipeline_statistics, PipelineStatistics* pipeline_statistics,
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data, WasmCompilationData* wasm_compilation_data,
int wasm_function_index, int wasm_function_index,
const AssemblerOptions& assembler_options) const AssemblerOptions& assembler_options)
: isolate_(isolate), : isolate_(nullptr),
wasm_engine_(wasm_engine), wasm_engine_(wasm_engine),
allocator_(wasm_engine->allocator()),
info_(info), info_(info),
debug_name_(info_->GetDebugName()), debug_name_(info_->GetDebugName()),
wasm_function_index_(wasm_function_index), wasm_function_index_(wasm_function_index),
...@@ -179,6 +181,7 @@ class PipelineData { ...@@ -179,6 +181,7 @@ class PipelineData {
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()),
info_(info), info_(info),
debug_name_(info_->GetDebugName()), debug_name_(info_->GetDebugName()),
zone_stats_(zone_stats), zone_stats_(zone_stats),
...@@ -200,6 +203,7 @@ class PipelineData { ...@@ -200,6 +203,7 @@ class PipelineData {
PipelineData(ZoneStats* zone_stats, OptimizedCompilationInfo* info, PipelineData(ZoneStats* zone_stats, OptimizedCompilationInfo* info,
Isolate* isolate, InstructionSequence* sequence) Isolate* isolate, InstructionSequence* sequence)
: isolate_(isolate), : isolate_(isolate),
allocator_(isolate->allocator()),
info_(info), info_(info),
debug_name_(info_->GetDebugName()), debug_name_(info_->GetDebugName()),
zone_stats_(zone_stats), zone_stats_(zone_stats),
...@@ -223,6 +227,7 @@ class PipelineData { ...@@ -223,6 +227,7 @@ class PipelineData {
} }
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
AccountingAllocator* allocator() const { return allocator_; }
OptimizedCompilationInfo* info() const { return info_; } OptimizedCompilationInfo* info() const { return info_; }
ZoneStats* zone_stats() const { return zone_stats_; } ZoneStats* zone_stats() const { return zone_stats_; }
CompilationDependencies* dependencies() const { return dependencies_; } CompilationDependencies* dependencies() const { return dependencies_; }
...@@ -414,6 +419,7 @@ class PipelineData { ...@@ -414,6 +419,7 @@ class PipelineData {
private: private:
Isolate* const isolate_; Isolate* const isolate_;
wasm::WasmEngine* const wasm_engine_ = nullptr; wasm::WasmEngine* const wasm_engine_ = nullptr;
AccountingAllocator* const allocator_;
OptimizedCompilationInfo* const info_; OptimizedCompilationInfo* const info_;
std::unique_ptr<char[]> debug_name_; std::unique_ptr<char[]> debug_name_;
int wasm_function_index_ = -1; int wasm_function_index_ = -1;
...@@ -980,24 +986,27 @@ void PipelineCompilationJob::RegisterWeakObjectsInOptimizedCode( ...@@ -980,24 +986,27 @@ void PipelineCompilationJob::RegisterWeakObjectsInOptimizedCode(
code->set_can_have_weak_objects(true); code->set_can_have_weak_objects(true);
} }
// The stack limit used during compilation is used to limit the recursion
// depth in, e.g. AST walking. No such recursion happens in WASM compilations.
constexpr uintptr_t kNoStackLimit = 0;
class PipelineWasmCompilationJob final : public OptimizedCompilationJob { class PipelineWasmCompilationJob final : public OptimizedCompilationJob {
public: public:
explicit PipelineWasmCompilationJob( explicit PipelineWasmCompilationJob(
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine, OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
Isolate* isolate, MachineGraph* mcgraph, CallDescriptor* call_descriptor, MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins, SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data, WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module, wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index, bool asmjs_origin) wasm::NativeModule* native_module, int function_index, bool asmjs_origin)
: OptimizedCompilationJob(isolate->stack_guard()->real_climit(), info, : OptimizedCompilationJob(kNoStackLimit, info, "TurboFan",
"TurboFan", State::kReadyToExecute), State::kReadyToExecute),
zone_stats_(isolate->allocator()), zone_stats_(wasm_engine->allocator()),
pipeline_statistics_(CreatePipelineStatistics( pipeline_statistics_(CreatePipelineStatistics(
wasm_engine, function_body, wasm_module, info, &zone_stats_)), wasm_engine, function_body, wasm_module, info, &zone_stats_)),
data_(&zone_stats_, isolate, wasm_engine, info, mcgraph, data_(&zone_stats_, wasm_engine, info, mcgraph,
pipeline_statistics_.get(), source_positions, node_origins, pipeline_statistics_.get(), source_positions, node_origins,
wasm_compilation_data, function_index, wasm_compilation_data, function_index, WasmAssemblerOptions()),
WasmAssemblerOptions(isolate)),
pipeline_(&data_), pipeline_(&data_),
linkage_(call_descriptor), linkage_(call_descriptor),
native_module_(native_module), native_module_(native_module),
...@@ -1673,7 +1682,7 @@ struct InstructionSelectionPhase { ...@@ -1673,7 +1682,7 @@ struct InstructionSelectionPhase {
FLAG_turbo_instruction_scheduling FLAG_turbo_instruction_scheduling
? InstructionSelector::kEnableScheduling ? InstructionSelector::kEnableScheduling
: InstructionSelector::kDisableScheduling, : InstructionSelector::kDisableScheduling,
data->isolate()->serializer_enabled() !data->isolate() || data->isolate()->serializer_enabled()
? InstructionSelector::kDisableRootsRelativeAddressing ? InstructionSelector::kDisableRootsRelativeAddressing
: InstructionSelector::kEnableRootsRelativeAddressing, : InstructionSelector::kEnableRootsRelativeAddressing,
data->info()->GetPoisoningMitigationLevel(), data->info()->GetPoisoningMitigationLevel(),
...@@ -2242,14 +2251,14 @@ OptimizedCompilationJob* Pipeline::NewCompilationJob( ...@@ -2242,14 +2251,14 @@ OptimizedCompilationJob* Pipeline::NewCompilationJob(
// static // static
OptimizedCompilationJob* Pipeline::NewWasmCompilationJob( OptimizedCompilationJob* Pipeline::NewWasmCompilationJob(
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine, OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
Isolate* isolate, MachineGraph* mcgraph, CallDescriptor* call_descriptor, MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins, SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data, WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module, wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index, wasm::NativeModule* native_module, int function_index,
wasm::ModuleOrigin asmjs_origin) { wasm::ModuleOrigin asmjs_origin) {
return new PipelineWasmCompilationJob( return new PipelineWasmCompilationJob(
info, wasm_engine, isolate, mcgraph, call_descriptor, source_positions, info, wasm_engine, mcgraph, call_descriptor, source_positions,
node_origins, wasm_compilation_data, function_body, wasm_module, node_origins, wasm_compilation_data, function_body, wasm_module,
native_module, function_index, asmjs_origin); native_module, function_index, asmjs_origin);
} }
...@@ -2318,7 +2327,7 @@ bool PipelineImpl::SelectInstructions(Linkage* linkage) { ...@@ -2318,7 +2327,7 @@ bool PipelineImpl::SelectInstructions(Linkage* linkage) {
<< "--- End of " << data->debug_name() << " generated by TurboFan\n" << "--- End of " << data->debug_name() << " generated by TurboFan\n"
<< "--------------------------------------------------\n"; << "--------------------------------------------------\n";
} }
Zone temp_zone(data->isolate()->allocator(), ZONE_NAME); Zone temp_zone(data->allocator(), ZONE_NAME);
MachineGraphVerifier::Run(data->graph(), data->schedule(), linkage, MachineGraphVerifier::Run(data->graph(), data->schedule(), linkage,
data->info()->IsStub(), data->debug_name(), data->info()->IsStub(), data->debug_name(),
&temp_zone); &temp_zone);
...@@ -2545,7 +2554,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, ...@@ -2545,7 +2554,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config,
std::unique_ptr<Zone> verifier_zone; std::unique_ptr<Zone> verifier_zone;
RegisterAllocatorVerifier* verifier = nullptr; RegisterAllocatorVerifier* verifier = nullptr;
if (run_verifier) { if (run_verifier) {
verifier_zone.reset(new Zone(isolate()->allocator(), ZONE_NAME)); verifier_zone.reset(new Zone(data->allocator(), ZONE_NAME));
verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( verifier = new (verifier_zone.get()) RegisterAllocatorVerifier(
verifier_zone.get(), config, data->sequence()); verifier_zone.get(), config, data->sequence());
} }
......
...@@ -49,7 +49,7 @@ class Pipeline : public AllStatic { ...@@ -49,7 +49,7 @@ class Pipeline : public AllStatic {
// Returns a new compilation job for the WebAssembly compilation info. // Returns a new compilation job for the WebAssembly compilation info.
static OptimizedCompilationJob* NewWasmCompilationJob( static OptimizedCompilationJob* NewWasmCompilationJob(
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine, OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
Isolate* isolate, MachineGraph* mcgraph, CallDescriptor* call_descriptor, MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins, SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data, WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module, wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
......
...@@ -4852,7 +4852,7 @@ MaybeHandle<Code> CompileJSToWasmWrapper( ...@@ -4852,7 +4852,7 @@ MaybeHandle<Code> CompileJSToWasmWrapper(
&zone, false, params + 1, CallDescriptor::kNoFlags); &zone, false, params + 1, CallDescriptor::kNoFlags);
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting( MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, WasmAssemblerOptions(isolate)); &info, isolate, incoming, &graph, WasmAssemblerOptions());
Handle<Code> code; Handle<Code> code;
if (!maybe_code.ToHandle(&code)) { if (!maybe_code.ToHandle(&code)) {
return maybe_code; return maybe_code;
...@@ -5101,7 +5101,7 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( ...@@ -5101,7 +5101,7 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
WasmGraphBuilder builder(wasm_unit_->env_, mcgraph->zone(), mcgraph, WasmGraphBuilder builder(wasm_unit_->env_, mcgraph->zone(), mcgraph,
wasm_unit_->func_body_.sig, source_position_table); wasm_unit_->func_body_.sig, source_position_table);
graph_construction_result_ = graph_construction_result_ =
wasm::BuildTFGraph(wasm_unit_->isolate_->allocator(), &builder, wasm::BuildTFGraph(wasm_unit_->wasm_engine_->allocator(), &builder,
wasm_unit_->func_body_, node_origins); wasm_unit_->func_body_, node_origins);
if (graph_construction_result_.failed()) { if (graph_construction_result_.failed()) {
if (FLAG_trace_wasm_compiler) { if (FLAG_trace_wasm_compiler) {
...@@ -5123,8 +5123,9 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( ...@@ -5123,8 +5123,9 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
if (wasm_unit_->func_index_ >= FLAG_trace_wasm_ast_start && if (wasm_unit_->func_index_ >= FLAG_trace_wasm_ast_start &&
wasm_unit_->func_index_ < FLAG_trace_wasm_ast_end) { wasm_unit_->func_index_ < FLAG_trace_wasm_ast_end) {
PrintRawWasmCode(wasm_unit_->isolate_->allocator(), wasm_unit_->func_body_, PrintRawWasmCode(wasm_unit_->wasm_engine_->allocator(),
wasm_unit_->env_->module, wasm::kPrintLocals); wasm_unit_->func_body_, wasm_unit_->env_->module,
wasm::kPrintLocals);
} }
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
*decode_ms = decode_timer.Elapsed().InMillisecondsF(); *decode_ms = decode_timer.Elapsed().InMillisecondsF();
...@@ -5162,7 +5163,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() { ...@@ -5162,7 +5163,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
// Scope for the {graph_zone}. // Scope for the {graph_zone}.
{ {
Zone graph_zone(wasm_unit_->isolate_->allocator(), ZONE_NAME); Zone graph_zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME);
MachineGraph* mcgraph = new (&graph_zone) MachineGraph* mcgraph = new (&graph_zone)
MachineGraph(new (&graph_zone) Graph(&graph_zone), MachineGraph(new (&graph_zone) Graph(&graph_zone),
new (&graph_zone) CommonOperatorBuilder(&graph_zone), new (&graph_zone) CommonOperatorBuilder(&graph_zone),
...@@ -5171,7 +5172,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() { ...@@ -5171,7 +5172,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
InstructionSelector::SupportedMachineOperatorFlags(), InstructionSelector::SupportedMachineOperatorFlags(),
InstructionSelector::AlignmentRequirements())); InstructionSelector::AlignmentRequirements()));
Zone compilation_zone(wasm_unit_->isolate_->allocator(), ZONE_NAME); Zone compilation_zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME);
OptimizedCompilationInfo info( OptimizedCompilationInfo info(
GetDebugName(&compilation_zone, wasm_unit_->func_name_, GetDebugName(&compilation_zone, wasm_unit_->func_name_,
...@@ -5210,9 +5211,9 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() { ...@@ -5210,9 +5211,9 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmCompilationJob( Pipeline::NewWasmCompilationJob(
&info, wasm_unit_->isolate_->wasm_engine(), wasm_unit_->isolate_, &info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor,
mcgraph, call_descriptor, source_positions, node_origins, source_positions, node_origins, &wasm_compilation_data_,
&wasm_compilation_data_, wasm_unit_->func_body_, wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module), const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->native_module_, wasm_unit_->func_index_, wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin)); wasm_unit_->env_->module->origin));
...@@ -5446,8 +5447,8 @@ CallDescriptor* GetI32WasmCallDescriptorForSimd( ...@@ -5446,8 +5447,8 @@ CallDescriptor* GetI32WasmCallDescriptorForSimd(
MachineRepresentation::kWord32); MachineRepresentation::kWord32);
} }
AssemblerOptions WasmAssemblerOptions(Isolate* isolate) { AssemblerOptions WasmAssemblerOptions() {
AssemblerOptions options = AssemblerOptions::Default(isolate); AssemblerOptions options;
options.record_reloc_info_for_serialization = true; options.record_reloc_info_for_serialization = true;
options.enable_root_array_delta_access = false; options.enable_root_array_delta_access = false;
return options; return options;
......
...@@ -504,7 +504,7 @@ V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptor( ...@@ -504,7 +504,7 @@ V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptor(
V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptorForSimd( V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptorForSimd(
Zone* zone, CallDescriptor* call_descriptor); Zone* zone, CallDescriptor* call_descriptor);
AssemblerOptions WasmAssemblerOptions(Isolate* isolate); AssemblerOptions WasmAssemblerOptions();
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
......
...@@ -1840,7 +1840,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation() { ...@@ -1840,7 +1840,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation() {
compile_timer.Start(); compile_timer.Start();
} }
Zone zone(wasm_unit_->isolate_->allocator(), "LiftoffCompilationZone"); Zone zone(wasm_unit_->wasm_engine_->allocator(), "LiftoffCompilationZone");
const wasm::WasmModule* module = const wasm::WasmModule* module =
wasm_unit_->env_ ? wasm_unit_->env_->module : nullptr; wasm_unit_->env_ ? wasm_unit_->env_->module : nullptr;
auto call_descriptor = auto call_descriptor =
......
...@@ -39,8 +39,8 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ModuleEnv* env, ...@@ -39,8 +39,8 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ModuleEnv* env,
wasm::WasmName name, int index, wasm::WasmName name, int index,
CompilationMode mode, CompilationMode mode,
Counters* counters, bool lower_simd) Counters* counters, bool lower_simd)
: isolate_(isolate), : env_(env),
env_(env), wasm_engine_(isolate->wasm_engine()),
func_body_(body), func_body_(body),
func_name_(name), func_name_(name),
counters_(counters ? counters : isolate->counters()), counters_(counters ? counters : isolate->counters()),
......
...@@ -20,6 +20,7 @@ class LiftoffCompilationUnit; ...@@ -20,6 +20,7 @@ class LiftoffCompilationUnit;
struct ModuleWireBytes; struct ModuleWireBytes;
class NativeModule; class NativeModule;
class WasmCode; class WasmCode;
class WasmEngine;
struct WasmFunction; struct WasmFunction;
enum RuntimeExceptionSupport : bool { enum RuntimeExceptionSupport : bool {
...@@ -83,8 +84,8 @@ class WasmCompilationUnit final { ...@@ -83,8 +84,8 @@ class WasmCompilationUnit final {
friend class LiftoffCompilationUnit; friend class LiftoffCompilationUnit;
friend class compiler::TurbofanWasmCompilationUnit; friend class compiler::TurbofanWasmCompilationUnit;
Isolate* isolate_;
ModuleEnv* env_; ModuleEnv* env_;
WasmEngine* wasm_engine_;
wasm::FunctionBody func_body_; wasm::FunctionBody func_body_;
wasm::WasmName func_name_; wasm::WasmName func_name_;
Counters* counters_; Counters* counters_;
......
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