Skip to content

Commit fa3cd68

Browse files
backesV8 LUCI CQ
authored andcommitted
[isolate][cleanup] Remove pointer to WasmEngine
The WasmEngine is shared across the whole process, so there is no need to store it in every Isolate. Instead, we can just get it from everywhere on any thread using {wasm::GetWasmEngine()}, which is a simple read of a global. R=jkummerow@chromium.org Bug: v8:11879 Change-Id: I13afb8ca3d116aa14bfaec5a4bbd6d71faa9aa17 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2969825 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Maya Lekova <mslekova@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#75265}
1 parent 3e62300 commit fa3cd68

46 files changed

Lines changed: 190 additions & 224 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api/api.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7577,7 +7577,7 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
75777577
#if V8_ENABLE_WEBASSEMBLY
75787578
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
75797579
i::Handle<i::WasmModuleObject> module_object =
7580-
i_isolate->wasm_engine()->ImportNativeModule(
7580+
i::wasm::GetWasmEngine()->ImportNativeModule(
75817581
i_isolate, compiled_module.native_module_,
75827582
base::VectorOf(compiled_module.source_url()));
75837583
return Local<WasmModuleObject>::Cast(
@@ -8238,7 +8238,7 @@ void Isolate::RequestInterrupt(InterruptCallback callback, void* data) {
82388238
bool Isolate::HasPendingBackgroundTasks() {
82398239
#if V8_ENABLE_WEBASSEMBLY
82408240
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
8241-
return isolate->wasm_engine()->HasRunningCompileJob(isolate);
8241+
return i::wasm::GetWasmEngine()->HasRunningCompileJob(isolate);
82428242
#else
82438243
return false;
82448244
#endif // V8_ENABLE_WEBASSEMBLY
@@ -8579,9 +8579,9 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
85798579

85808580
#if V8_ENABLE_WEBASSEMBLY
85818581
heap_statistics->malloced_memory_ +=
8582-
isolate->wasm_engine()->allocator()->GetCurrentMemoryUsage();
8582+
i::wasm::GetWasmEngine()->allocator()->GetCurrentMemoryUsage();
85838583
heap_statistics->peak_malloced_memory_ +=
8584-
isolate->wasm_engine()->allocator()->GetMaxMemoryUsage();
8584+
i::wasm::GetWasmEngine()->allocator()->GetMaxMemoryUsage();
85858585
#endif // V8_ENABLE_WEBASSEMBLY
85868586
}
85878587

@@ -8895,7 +8895,7 @@ int Isolate::ContextDisposedNotification(bool dependant_context) {
88958895
// of that context.
88968896
// A handle scope for the native context.
88978897
i::HandleScope handle_scope(isolate);
8898-
isolate->wasm_engine()->DeleteCompileJobsOnContext(
8898+
i::wasm::GetWasmEngine()->DeleteCompileJobsOnContext(
88998899
isolate->native_context());
89008900
}
89018901
}

src/asmjs/asm-js.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ UnoptimizedCompilationJob::Status AsmJsCompilationJob::FinalizeJobImpl(
265265
// The result is a compiled module and serialized standard library uses.
266266
wasm::ErrorThrower thrower(isolate, "AsmJs::Compile");
267267
Handle<AsmWasmData> result =
268-
isolate->wasm_engine()
268+
wasm::GetWasmEngine()
269269
->SyncCompileTranslatedAsmJs(
270270
isolate, &thrower,
271271
wasm::ModuleWireBytes(module_->begin(), module_->end()),
@@ -322,7 +322,7 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,
322322
instantiate_timer.Start();
323323
Handle<HeapNumber> uses_bitset(wasm_data->uses_bitset(), isolate);
324324
Handle<Script> script(Script::cast(shared->script()), isolate);
325-
const auto& wasm_engine = isolate->wasm_engine();
325+
auto* wasm_engine = wasm::GetWasmEngine();
326326

327327
// Allocate the WasmModuleObject.
328328
Handle<WasmModuleObject> module =

src/compiler/pipeline.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ class PipelineData {
235235
const ProfileDataFromFile* profile_data)
236236
: isolate_(isolate),
237237
#if V8_ENABLE_WEBASSEMBLY
238-
wasm_engine_(isolate_->wasm_engine()),
238+
// TODO(clemensb): Remove this field, use GetWasmEngine directly
239+
// instead.
240+
wasm_engine_(wasm::GetWasmEngine()),
239241
#endif // V8_ENABLE_WEBASSEMBLY
240242
allocator_(allocator),
241243
info_(info),

src/compiler/wasm-compiler.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7695,7 +7695,7 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate* isolate,
76957695
// Run the compilation job synchronously.
76967696
std::unique_ptr<OptimizedCompilationJob> job(
76977697
Pipeline::NewWasmHeapStubCompilationJob(
7698-
isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
7698+
isolate, wasm::GetWasmEngine(), incoming, std::move(zone), graph,
76997699
CodeKind::WASM_TO_JS_FUNCTION, std::move(name_buffer),
77007700
AssemblerOptions::Default(isolate)));
77017701

@@ -7742,7 +7742,7 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate,
77427742
// Run the compilation job synchronously.
77437743
std::unique_ptr<OptimizedCompilationJob> job(
77447744
Pipeline::NewWasmHeapStubCompilationJob(
7745-
isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
7745+
isolate, wasm::GetWasmEngine(), incoming, std::move(zone), graph,
77467746
CodeKind::JS_TO_JS_FUNCTION, std::move(name_buffer),
77477747
AssemblerOptions::Default(isolate)));
77487748

@@ -7797,7 +7797,7 @@ Handle<CodeT> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig,
77977797
// Run the compilation job synchronously.
77987798
std::unique_ptr<OptimizedCompilationJob> job(
77997799
Pipeline::NewWasmHeapStubCompilationJob(
7800-
isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
7800+
isolate, wasm::GetWasmEngine(), incoming, std::move(zone), graph,
78017801
CodeKind::C_WASM_ENTRY, std::move(name_buffer),
78027802
AssemblerOptions::Default(isolate)));
78037803

src/debug/debug-interface.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,12 @@ MaybeLocal<UnboundScript> CompileInspectorScript(Isolate* v8_isolate,
776776
#if V8_ENABLE_WEBASSEMBLY
777777
void TierDownAllModulesPerIsolate(Isolate* v8_isolate) {
778778
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
779-
isolate->wasm_engine()->TierDownAllModulesPerIsolate(isolate);
779+
i::wasm::GetWasmEngine()->TierDownAllModulesPerIsolate(isolate);
780780
}
781781

782782
void TierUpAllModulesPerIsolate(Isolate* v8_isolate) {
783783
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
784-
isolate->wasm_engine()->TierUpAllModulesPerIsolate(isolate);
784+
i::wasm::GetWasmEngine()->TierUpAllModulesPerIsolate(isolate);
785785
}
786786
#endif // V8_ENABLE_WEBASSEMBLY
787787

src/diagnostics/disassembler.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ const char* V8NameConverter::NameOfAddress(byte* pc) const {
9999

100100
#if V8_ENABLE_WEBASSEMBLY
101101
wasm::WasmCodeRefScope wasm_code_ref_scope;
102-
wasm::WasmCode* wasm_code =
103-
isolate_ ? isolate_->wasm_engine()->code_manager()->LookupCode(
104-
reinterpret_cast<Address>(pc))
105-
: nullptr;
106-
if (wasm_code != nullptr) {
102+
if (auto* wasm_code = wasm::GetWasmEngine()->code_manager()->LookupCode(
103+
reinterpret_cast<Address>(pc))) {
107104
SNPrintF(v8_buffer_, "%p (%s)", static_cast<void*>(pc),
108105
wasm::GetWasmCodeKindAsString(wasm_code->kind()));
109106
return v8_buffer_.begin();

src/diagnostics/objects-printer.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,9 +2862,8 @@ V8_EXPORT_PRIVATE extern void _v8_internal_Print_Code(void* object) {
28622862
#if V8_ENABLE_WEBASSEMBLY
28632863
{
28642864
i::wasm::WasmCodeRefScope scope;
2865-
i::wasm::WasmCode* wasm_code =
2866-
isolate->wasm_engine()->code_manager()->LookupCode(address);
2867-
if (wasm_code) {
2865+
if (auto* wasm_code =
2866+
i::wasm::GetWasmEngine()->code_manager()->LookupCode(address)) {
28682867
i::StdoutStream os;
28692868
wasm_code->Disassemble(nullptr, os, address);
28702869
return;

src/execution/frames.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
571571
// returned {wasm_code} to be null and fall back to {GetContainingCode}.
572572
wasm::WasmCodeRefScope code_ref_scope;
573573
if (wasm::WasmCode* wasm_code =
574-
iterator->isolate()->wasm_engine()->code_manager()->LookupCode(
575-
pc)) {
574+
wasm::GetWasmEngine()->code_manager()->LookupCode(pc)) {
576575
switch (wasm_code->kind()) {
577576
case wasm::WasmCode::kFunction:
578577
return WASM;
@@ -946,7 +945,7 @@ void CommonFrame::IterateCompiledFrame(RootVisitor* v) const {
946945

947946
#if V8_ENABLE_WEBASSEMBLY
948947
if (auto* wasm_code =
949-
isolate()->wasm_engine()->code_manager()->LookupCode(inner_pointer)) {
948+
wasm::GetWasmEngine()->code_manager()->LookupCode(inner_pointer)) {
950949
is_wasm = true;
951950
SafepointTable table(wasm_code);
952951
safepoint_entry = table.FindEntry(inner_pointer);
@@ -982,7 +981,7 @@ void CommonFrame::IterateCompiledFrame(RootVisitor* v) const {
982981
// directly call a Wasm function from JavaScript. In this case the
983982
// parameters we pass to the callee are not tagged.
984983
wasm::WasmCode* wasm_callee =
985-
isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc());
984+
wasm::GetWasmEngine()->code_manager()->LookupCode(callee_pc());
986985
bool is_wasm_call = (wasm_callee != nullptr);
987986
if (is_wasm_call) has_tagged_outgoing_params = false;
988987
#endif // V8_ENABLE_WEBASSEMBLY
@@ -1862,8 +1861,7 @@ void WasmFrame::Print(StringStream* accumulator, PrintMode mode,
18621861
wasm::WasmCodeRefScope code_ref_scope;
18631862
accumulator->Add("WASM [");
18641863
accumulator->PrintName(script().name());
1865-
Address instruction_start = isolate()
1866-
->wasm_engine()
1864+
Address instruction_start = wasm::GetWasmEngine()
18671865
->code_manager()
18681866
->LookupCode(pc())
18691867
->instruction_start();
@@ -1886,7 +1884,7 @@ void WasmFrame::Print(StringStream* accumulator, PrintMode mode,
18861884
}
18871885

18881886
wasm::WasmCode* WasmFrame::wasm_code() const {
1889-
return isolate()->wasm_engine()->code_manager()->LookupCode(pc());
1887+
return wasm::GetWasmEngine()->code_manager()->LookupCode(pc());
18901888
}
18911889

18921890
WasmInstanceObject WasmFrame::wasm_instance() const {
@@ -1948,7 +1946,7 @@ bool WasmFrame::at_to_number_conversion() const {
19481946
// ToNumber conversion call.
19491947
wasm::WasmCode* code =
19501948
callee_pc() != kNullAddress
1951-
? isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc())
1949+
? wasm::GetWasmEngine()->code_manager()->LookupCode(callee_pc())
19521950
: nullptr;
19531951
if (!code || code->kind() != wasm::WasmCode::kWasmToJsWrapper) return false;
19541952
int offset = static_cast<int>(callee_pc() - code->instruction_start());
@@ -1961,7 +1959,7 @@ bool WasmFrame::at_to_number_conversion() const {
19611959

19621960
int WasmFrame::LookupExceptionHandlerInTable() {
19631961
wasm::WasmCode* code =
1964-
isolate()->wasm_engine()->code_manager()->LookupCode(pc());
1962+
wasm::GetWasmEngine()->code_manager()->LookupCode(pc());
19651963
if (!code->IsAnonymous() && code->handler_table_size() > 0) {
19661964
HandlerTable table(code);
19671965
int pc_offset = static_cast<int>(pc() - code->instruction_start());
@@ -1973,7 +1971,7 @@ int WasmFrame::LookupExceptionHandlerInTable() {
19731971
void WasmDebugBreakFrame::Iterate(RootVisitor* v) const {
19741972
DCHECK(caller_pc());
19751973
wasm::WasmCode* code =
1976-
isolate()->wasm_engine()->code_manager()->LookupCode(caller_pc());
1974+
wasm::GetWasmEngine()->code_manager()->LookupCode(caller_pc());
19771975
DCHECK(code);
19781976
SafepointTable table(code);
19791977
SafepointEntry safepoint_entry = table.FindEntry(caller_pc());

src/execution/isolate.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,10 @@ Object Isolate::UnwindAndFindHandler() {
17931793
wasm::WasmCodeRefScope code_ref_scope;
17941794
WasmFrame* wasm_frame = static_cast<WasmFrame*>(frame);
17951795
wasm::WasmCode* wasm_code =
1796-
wasm_engine()->code_manager()->LookupCode(frame->pc());
1796+
wasm::GetWasmEngine()->code_manager()->LookupCode(frame->pc());
17971797
int offset = wasm_frame->LookupExceptionHandlerInTable();
17981798
if (offset < 0) break;
1799-
wasm_engine()->SampleCatchEvent(this);
1799+
wasm::GetWasmEngine()->SampleCatchEvent(this);
18001800
// Compute the stack pointer from the frame pointer. This ensures that
18011801
// argument slots on the stack are dropped as returning would.
18021802
Address return_sp = frame->fp() +
@@ -1854,7 +1854,8 @@ Object Isolate::UnwindAndFindHandler() {
18541854
StubFrame* stub_frame = static_cast<StubFrame*>(frame);
18551855
#if defined(DEBUG) && V8_ENABLE_WEBASSEMBLY
18561856
wasm::WasmCodeRefScope code_ref_scope;
1857-
DCHECK_NULL(wasm_engine()->code_manager()->LookupCode(frame->pc()));
1857+
DCHECK_NULL(
1858+
wasm::GetWasmEngine()->code_manager()->LookupCode(frame->pc()));
18581859
#endif // defined(DEBUG) && V8_ENABLE_WEBASSEMBLY
18591860
Code code = stub_frame->LookupCode();
18601861
if (!code.IsCode() || code.kind() != CodeKind::BUILTIN ||
@@ -2722,13 +2723,6 @@ void Isolate::UnregisterManagedPtrDestructor(ManagedPtrDestructor* destructor) {
27222723
}
27232724

27242725
#if V8_ENABLE_WEBASSEMBLY
2725-
void Isolate::SetWasmEngine(wasm::WasmEngine* engine) {
2726-
DCHECK_NULL(wasm_engine_); // Only call once before {Init}.
2727-
DCHECK_NOT_NULL(engine);
2728-
wasm_engine_ = engine;
2729-
wasm_engine_->AddIsolate(this);
2730-
}
2731-
27322726
void Isolate::AddSharedWasmMemory(Handle<WasmMemoryObject> memory_object) {
27332727
HandleScope scope(this);
27342728
Handle<WeakArrayList> shared_wasm_memories =
@@ -3119,7 +3113,7 @@ void Isolate::Deinit() {
31193113
debug()->Unload();
31203114

31213115
#if V8_ENABLE_WEBASSEMBLY
3122-
wasm_engine()->DeleteCompileJobsOnIsolate(this);
3116+
wasm::GetWasmEngine()->DeleteCompileJobsOnIsolate(this);
31233117

31243118
BackingStore::RemoveSharedWasmMemoryObjects(this);
31253119
#endif // V8_ENABLE_WEBASSEMBLY
@@ -3194,7 +3188,7 @@ void Isolate::Deinit() {
31943188
if (logfile != nullptr) base::Fclose(logfile);
31953189

31963190
#if V8_ENABLE_WEBASSEMBLY
3197-
wasm_engine_->RemoveIsolate(this);
3191+
wasm::GetWasmEngine()->RemoveIsolate(this);
31983192
#endif // V8_ENABLE_WEBASSEMBLY
31993193

32003194
TearDownEmbeddedBlob();
@@ -3685,7 +3679,7 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
36853679
isolate_data_.external_reference_table()->Init(this);
36863680

36873681
#if V8_ENABLE_WEBASSEMBLY
3688-
SetWasmEngine(wasm::WasmEngine::GetWasmEngine());
3682+
wasm::GetWasmEngine()->AddIsolate(this);
36893683
#endif // V8_ENABLE_WEBASSEMBLY
36903684

36913685
if (setup_delegate_ == nullptr) {
@@ -3964,7 +3958,7 @@ void Isolate::DumpAndResetStats() {
39643958
// TODO(7424): There is no public API for the {WasmEngine} yet. So for now we
39653959
// just dump and reset the engines statistics together with the Isolate.
39663960
if (FLAG_turbo_stats_wasm) {
3967-
wasm_engine()->DumpAndResetTurboStatistics();
3961+
wasm::GetWasmEngine()->DumpAndResetTurboStatistics();
39683962
}
39693963
#endif // V8_ENABLE_WEBASSEMBLY
39703964
#if V8_RUNTIME_CALL_STATS

src/execution/isolate.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ class NodeObserver;
133133
class PerIsolateCompilerCache;
134134
} // namespace compiler
135135

136-
namespace wasm {
137-
class WasmEngine;
138-
} // namespace wasm
139-
140136
namespace win64_unwindinfo {
141137
class BuiltinUnwindInfo;
142138
} // namespace win64_unwindinfo
@@ -1725,10 +1721,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
17251721
}
17261722

17271723
#if V8_ENABLE_WEBASSEMBLY
1728-
// TODO(wasm): Replace all uses by {WasmEngine::GetWasmEngine}?
1729-
wasm::WasmEngine* wasm_engine() const { return wasm_engine_; }
1730-
void SetWasmEngine(wasm::WasmEngine* engine);
1731-
17321724
void AddSharedWasmMemory(Handle<WasmMemoryObject> memory_object);
17331725
#endif // V8_ENABLE_WEBASSEMBLY
17341726

@@ -2179,10 +2171,6 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
21792171

21802172
size_t elements_deletion_counter_ = 0;
21812173

2182-
#if V8_ENABLE_WEBASSEMBLY
2183-
wasm::WasmEngine* wasm_engine_ = nullptr;
2184-
#endif // V8_ENABLE_WEBASSEMBLY
2185-
21862174
std::unique_ptr<TracingCpuProfilerImpl> tracing_cpu_profiler_;
21872175

21882176
EmbeddedFileWriterInterface* embedded_file_writer_ = nullptr;

0 commit comments

Comments
 (0)