diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/wasm/wasm-engine.cc | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/wasm/wasm-engine.cc')
-rw-r--r-- | chromium/v8/src/wasm/wasm-engine.cc | 85 |
1 files changed, 54 insertions, 31 deletions
diff --git a/chromium/v8/src/wasm/wasm-engine.cc b/chromium/v8/src/wasm/wasm-engine.cc index 324d1b1d49c..133825122fd 100644 --- a/chromium/v8/src/wasm/wasm-engine.cc +++ b/chromium/v8/src/wasm/wasm-engine.cc @@ -22,6 +22,7 @@ #include "src/wasm/module-decoder.h" #include "src/wasm/module-instantiate.h" #include "src/wasm/streaming-decoder.h" +#include "src/wasm/wasm-debug.h" #include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-objects-inl.h" @@ -54,7 +55,7 @@ class LogCodesTask : public Task { DCHECK_NOT_NULL(isolate); } - ~LogCodesTask() { + ~LogCodesTask() override { // If the platform deletes this task before executing it, we also deregister // it to avoid use-after-free from still-running background threads. if (!cancelled()) DeregisterTask(); @@ -343,9 +344,8 @@ struct WasmEngine::IsolateInfo { } #endif - // All native modules that are being used by this Isolate (currently only - // grows, never shrinks). - std::set<NativeModule*> native_modules; + // All native modules that are being used by this Isolate. + std::unordered_map<NativeModule*, std::weak_ptr<NativeModule>> native_modules; // Scripts created for each native module in this isolate. std::unordered_map<NativeModule*, WeakScriptHandle> scripts; @@ -409,6 +409,7 @@ WasmEngine::~WasmEngine() { bool WasmEngine::SyncValidate(Isolate* isolate, const WasmFeatures& enabled, const ModuleWireBytes& bytes) { + TRACE_EVENT0("v8.wasm", "wasm.SyncValidate"); // TODO(titzer): remove dependency on the isolate. if (bytes.start() == nullptr || bytes.length() == 0) return false; ModuleResult result = @@ -421,6 +422,7 @@ MaybeHandle<AsmWasmData> WasmEngine::SyncCompileTranslatedAsmJs( Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes, Vector<const byte> asm_js_offset_table_bytes, Handle<HeapNumber> uses_bitset, LanguageMode language_mode) { + TRACE_EVENT0("v8.wasm", "wasm.SyncCompileTranslatedAsmJs"); ModuleOrigin origin = language_mode == LanguageMode::kSloppy ? kAsmJsSloppyOrigin : kAsmJsStrictOrigin; @@ -464,6 +466,7 @@ Handle<WasmModuleObject> WasmEngine::FinalizeTranslatedAsmJs( MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile( Isolate* isolate, const WasmFeatures& enabled, ErrorThrower* thrower, const ModuleWireBytes& bytes) { + TRACE_EVENT0("v8.wasm", "wasm.SyncCompile"); ModuleResult result = DecodeWasmModule(enabled, bytes.start(), bytes.end(), false, kWasmOrigin, isolate->counters(), allocator()); @@ -509,6 +512,7 @@ MaybeHandle<WasmInstanceObject> WasmEngine::SyncInstantiate( Isolate* isolate, ErrorThrower* thrower, Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports, MaybeHandle<JSArrayBuffer> memory) { + TRACE_EVENT0("v8.wasm", "wasm.SyncInstantiate"); return InstantiateToInstanceObject(isolate, thrower, module_object, imports, memory); } @@ -517,6 +521,7 @@ void WasmEngine::AsyncInstantiate( Isolate* isolate, std::unique_ptr<InstantiationResultResolver> resolver, Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports) { ErrorThrower thrower(isolate, "WebAssembly.instantiate()"); + TRACE_EVENT0("v8.wasm", "wasm.AsyncInstantiate"); // Instantiate a TryCatch so that caught exceptions won't progagate out. // They will still be set as pending exceptions on the isolate. // TODO(clemensb): Avoid TryCatch, use Execution::TryCall internally to invoke @@ -552,6 +557,7 @@ void WasmEngine::AsyncCompile( std::shared_ptr<CompilationResultResolver> resolver, const ModuleWireBytes& bytes, bool is_shared, const char* api_method_name_for_errors) { + TRACE_EVENT0("v8.wasm", "wasm.AsyncCompile"); if (!FLAG_wasm_async_compilation) { // Asynchronous compilation disabled; fall back on synchronous compilation. ErrorThrower thrower(isolate, api_method_name_for_errors); @@ -600,10 +606,15 @@ std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation( Isolate* isolate, const WasmFeatures& enabled, Handle<Context> context, const char* api_method_name, std::shared_ptr<CompilationResultResolver> resolver) { - AsyncCompileJob* job = - CreateAsyncCompileJob(isolate, enabled, std::unique_ptr<byte[]>(nullptr), - 0, context, api_method_name, std::move(resolver)); - return job->CreateStreamingDecoder(); + TRACE_EVENT0("v8.wasm", "wasm.StartStreamingCompilation"); + if (FLAG_wasm_async_compilation) { + AsyncCompileJob* job = CreateAsyncCompileJob( + isolate, enabled, std::unique_ptr<byte[]>(nullptr), 0, context, + api_method_name, std::move(resolver)); + return job->CreateStreamingDecoder(); + } + return StreamingDecoder::CreateSyncStreamingDecoder( + isolate, enabled, context, api_method_name, std::move(resolver)); } void WasmEngine::CompileFunction(Isolate* isolate, NativeModule* native_module, @@ -616,25 +627,27 @@ void WasmEngine::CompileFunction(Isolate* isolate, NativeModule* native_module, } void WasmEngine::TierDownAllModulesPerIsolate(Isolate* isolate) { - std::vector<NativeModule*> native_modules; + std::vector<std::shared_ptr<NativeModule>> native_modules; { base::MutexGuard lock(&mutex_); if (isolates_[isolate]->keep_tiered_down) return; isolates_[isolate]->keep_tiered_down = true; - for (auto* native_module : isolates_[isolate]->native_modules) { - native_modules.push_back(native_module); - native_module->SetTieringState(kTieredDown); + for (auto& entry : isolates_[isolate]->native_modules) { + entry.first->SetTieringState(kTieredDown); + if (auto shared_ptr = entry.second.lock()) { + native_modules.emplace_back(std::move(shared_ptr)); + } } } - for (auto* native_module : native_modules) { - native_module->TriggerRecompilation(); + for (auto& native_module : native_modules) { + native_module->RecompileForTiering(); } } void WasmEngine::TierUpAllModulesPerIsolate(Isolate* isolate) { // Only trigger recompilation after releasing the mutex, otherwise we risk // deadlocks because of lock inversion. - std::vector<NativeModule*> native_modules_to_recompile; + std::vector<std::shared_ptr<NativeModule>> native_modules_to_recompile; { base::MutexGuard lock(&mutex_); isolates_[isolate]->keep_tiered_down = false; @@ -646,17 +659,20 @@ void WasmEngine::TierUpAllModulesPerIsolate(Isolate* isolate) { } return false; }; - for (auto* native_module : isolates_[isolate]->native_modules) { + for (auto& entry : isolates_[isolate]->native_modules) { + auto* native_module = entry.first; if (!native_module->IsTieredDown()) continue; // Only start tier-up if no other isolate needs this modules in tiered // down state. if (test_keep_tiered_down(native_module)) continue; native_module->SetTieringState(kTieredUp); - native_modules_to_recompile.push_back(native_module); + if (auto shared_ptr = entry.second.lock()) { + native_modules_to_recompile.emplace_back(std::move(shared_ptr)); + } } } - for (auto* native_module : native_modules_to_recompile) { - native_module->TriggerRecompilation(); + for (auto& native_module : native_modules_to_recompile) { + native_module->RecompileForTiering(); } } @@ -762,11 +778,12 @@ Handle<WasmModuleObject> WasmEngine::ImportNativeModule( Handle<FixedArray> export_wrappers; CompileJsToWasmWrappers(isolate, native_module->module(), &export_wrappers); Handle<WasmModuleObject> module_object = WasmModuleObject::New( - isolate, std::move(shared_native_module), script, export_wrappers); + isolate, shared_native_module, script, export_wrappers); { base::MutexGuard lock(&mutex_); DCHECK_EQ(1, isolates_.count(isolate)); - isolates_[isolate]->native_modules.insert(native_module); + isolates_[isolate]->native_modules.emplace(native_module, + std::move(shared_native_module)); DCHECK_EQ(1, native_modules_.count(native_module)); native_modules_[native_module]->isolates.insert(isolate); } @@ -885,8 +902,8 @@ void WasmEngine::AddIsolate(Isolate* isolate) { WasmEngine* engine = isolate->wasm_engine(); base::MutexGuard lock(&engine->mutex_); DCHECK_EQ(1, engine->isolates_.count(isolate)); - for (auto* native_module : engine->isolates_[isolate]->native_modules) { - native_module->SampleCodeSize(counters, NativeModule::kSampling); + for (auto& entry : engine->isolates_[isolate]->native_modules) { + entry.first->SampleCodeSize(counters, NativeModule::kSampling); } }; isolate->heap()->AddGCEpilogueCallback(callback, v8::kGCTypeMarkSweepCompact, @@ -910,7 +927,8 @@ void WasmEngine::RemoveIsolate(Isolate* isolate) { DCHECK_NE(isolates_.end(), it); std::unique_ptr<IsolateInfo> info = std::move(it->second); isolates_.erase(it); - for (NativeModule* native_module : info->native_modules) { + for (auto& entry : info->native_modules) { + auto* native_module = entry.first; DCHECK_EQ(1, native_modules_.count(native_module)); DCHECK_EQ(1, native_modules_[native_module]->isolates.count(isolate)); auto* info = native_modules_[native_module].get(); @@ -920,6 +938,9 @@ void WasmEngine::RemoveIsolate(Isolate* isolate) { current_gc_info_->dead_code.erase(code); } } + if (native_module->HasDebugInfo()) { + native_module->GetDebugInfo()->RemoveIsolate(isolate); + } } if (current_gc_info_) { if (RemoveIsolateFromCurrentGC(isolate)) PotentiallyFinishCurrentGC(); @@ -1002,7 +1023,7 @@ std::shared_ptr<NativeModule> WasmEngine::NewNativeModule( DCHECK(pair.second); // inserted new entry. pair.first->second.get()->isolates.insert(isolate); auto& modules_per_isolate = isolates_[isolate]->native_modules; - modules_per_isolate.insert(native_module.get()); + modules_per_isolate.emplace(native_module.get(), native_module); if (isolates_[isolate]->keep_tiered_down) { native_module->SetTieringState(kTieredDown); } @@ -1025,14 +1046,15 @@ std::shared_ptr<NativeModule> WasmEngine::MaybeGetNativeModule( native_module_info = std::make_unique<NativeModuleInfo>(); } native_module_info->isolates.insert(isolate); - isolates_[isolate]->native_modules.insert(native_module.get()); + isolates_[isolate]->native_modules.emplace(native_module.get(), + native_module); if (isolates_[isolate]->keep_tiered_down) { native_module->SetTieringState(kTieredDown); recompile_module = true; } } // Potentially recompile the module for tier down, after releasing the mutex. - if (recompile_module) native_module->TriggerRecompilation(); + if (recompile_module) native_module->RecompileForTiering(); return native_module; } @@ -1054,14 +1076,15 @@ bool WasmEngine::UpdateNativeModuleCache( DCHECK_EQ(1, native_modules_.count(native_module->get())); native_modules_[native_module->get()]->isolates.insert(isolate); DCHECK_EQ(1, isolates_.count(isolate)); - isolates_[isolate]->native_modules.insert(native_module->get()); + isolates_[isolate]->native_modules.emplace(native_module->get(), + *native_module); if (isolates_[isolate]->keep_tiered_down) { native_module->get()->SetTieringState(kTieredDown); recompile_module = true; } } // Potentially recompile the module for tier down, after releasing the mutex. - if (recompile_module) native_module->get()->TriggerRecompilation(); + if (recompile_module) native_module->get()->RecompileForTiering(); return false; } @@ -1154,7 +1177,7 @@ void WasmEngine::SampleTopTierCodeSizeInAllIsolates( void WasmEngine::ReportLiveCodeForGC(Isolate* isolate, Vector<WasmCode*> live_code) { - TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), "ReportLiveCodeForGC"); + TRACE_EVENT0("v8.wasm", "wasm.ReportLiveCodeForGC"); TRACE_CODE_GC("Isolate %d reporting %zu live code objects.\n", isolate->id(), live_code.size()); base::MutexGuard guard(&mutex_); @@ -1227,7 +1250,7 @@ void WasmEngine::FreeDeadCode(const DeadCodeMap& dead_code) { } void WasmEngine::FreeDeadCodeLocked(const DeadCodeMap& dead_code) { - TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), "FreeDeadCode"); + TRACE_EVENT0("v8.wasm", "wasm.FreeDeadCode"); DCHECK(!mutex_.TryLock()); for (auto& dead_code_entry : dead_code) { NativeModule* native_module = dead_code_entry.first; |