diff options
Diffstat (limited to 'deps/v8/src/wasm/wasm-engine.cc')
-rw-r--r-- | deps/v8/src/wasm/wasm-engine.cc | 107 |
1 files changed, 87 insertions, 20 deletions
diff --git a/deps/v8/src/wasm/wasm-engine.cc b/deps/v8/src/wasm/wasm-engine.cc index 3dd8fa0ce7..339e6c9775 100644 --- a/deps/v8/src/wasm/wasm-engine.cc +++ b/deps/v8/src/wasm/wasm-engine.cc @@ -389,6 +389,16 @@ struct WasmEngine::IsolateInfo { // Keep new modules in tiered down state. bool keep_tiered_down = false; + + // Elapsed time since last throw/rethrow/catch event. + base::ElapsedTimer throw_timer; + base::ElapsedTimer rethrow_timer; + base::ElapsedTimer catch_timer; + + // Total number of exception events in this isolate. + int throw_count = 0; + int rethrow_count = 0; + int catch_count = 0; }; struct WasmEngine::NativeModuleInfo { @@ -453,7 +463,9 @@ 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"); + int compilation_id = next_compilation_id_.fetch_add(1); + TRACE_EVENT1("v8.wasm", "wasm.SyncCompileTranslatedAsmJs", "id", + compilation_id); ModuleOrigin origin = language_mode == LanguageMode::kSloppy ? kAsmJsSloppyOrigin : kAsmJsStrictOrigin; @@ -475,9 +487,9 @@ MaybeHandle<AsmWasmData> WasmEngine::SyncCompileTranslatedAsmJs( // Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated // in {CompileToNativeModule}. Handle<FixedArray> export_wrappers; - std::shared_ptr<NativeModule> native_module = - CompileToNativeModule(isolate, WasmFeatures::ForAsmjs(), thrower, - std::move(result).value(), bytes, &export_wrappers); + std::shared_ptr<NativeModule> native_module = CompileToNativeModule( + isolate, WasmFeatures::ForAsmjs(), thrower, std::move(result).value(), + bytes, &export_wrappers, compilation_id); if (!native_module) return {}; return AsmWasmData::New(isolate, std::move(native_module), export_wrappers, @@ -499,7 +511,8 @@ Handle<WasmModuleObject> WasmEngine::FinalizeTranslatedAsmJs( MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile( Isolate* isolate, const WasmFeatures& enabled, ErrorThrower* thrower, const ModuleWireBytes& bytes) { - TRACE_EVENT0("v8.wasm", "wasm.SyncCompile"); + int compilation_id = next_compilation_id_.fetch_add(1); + TRACE_EVENT1("v8.wasm", "wasm.SyncCompile", "id", compilation_id); ModuleResult result = DecodeWasmModule( enabled, bytes.start(), bytes.end(), false, kWasmOrigin, isolate->counters(), isolate->metrics_recorder(), @@ -513,9 +526,9 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile( // Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated // in {CompileToNativeModule}. Handle<FixedArray> export_wrappers; - std::shared_ptr<NativeModule> native_module = - CompileToNativeModule(isolate, enabled, thrower, - std::move(result).value(), bytes, &export_wrappers); + std::shared_ptr<NativeModule> native_module = CompileToNativeModule( + isolate, enabled, thrower, std::move(result).value(), bytes, + &export_wrappers, compilation_id); if (!native_module) return {}; #ifdef DEBUG @@ -596,7 +609,8 @@ 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"); + int compilation_id = next_compilation_id_.fetch_add(1); + TRACE_EVENT1("v8.wasm", "wasm.AsyncCompile", "id", compilation_id); if (!FLAG_wasm_async_compilation) { // Asynchronous compilation disabled; fall back on synchronous compilation. ErrorThrower thrower(isolate, api_method_name_for_errors); @@ -634,10 +648,10 @@ void WasmEngine::AsyncCompile( std::unique_ptr<byte[]> copy(new byte[bytes.length()]); base::Memcpy(copy.get(), bytes.start(), bytes.length()); - AsyncCompileJob* job = - CreateAsyncCompileJob(isolate, enabled, std::move(copy), bytes.length(), - handle(isolate->context(), isolate), - api_method_name_for_errors, std::move(resolver)); + AsyncCompileJob* job = CreateAsyncCompileJob( + isolate, enabled, std::move(copy), bytes.length(), + handle(isolate->context(), isolate), api_method_name_for_errors, + std::move(resolver), compilation_id); job->Start(); } @@ -645,11 +659,13 @@ std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation( Isolate* isolate, const WasmFeatures& enabled, Handle<Context> context, const char* api_method_name, std::shared_ptr<CompilationResultResolver> resolver) { - TRACE_EVENT0("v8.wasm", "wasm.StartStreamingCompilation"); + int compilation_id = next_compilation_id_.fetch_add(1); + TRACE_EVENT1("v8.wasm", "wasm.StartStreamingCompilation", "id", + compilation_id); if (FLAG_wasm_async_compilation) { AsyncCompileJob* job = CreateAsyncCompileJob( isolate, enabled, std::unique_ptr<byte[]>(nullptr), 0, context, - api_method_name, std::move(resolver)); + api_method_name, std::move(resolver), compilation_id); return job->CreateStreamingDecoder(); } return StreamingDecoder::CreateSyncStreamingDecoder( @@ -867,11 +883,11 @@ AsyncCompileJob* WasmEngine::CreateAsyncCompileJob( Isolate* isolate, const WasmFeatures& enabled, std::unique_ptr<byte[]> bytes_copy, size_t length, Handle<Context> context, const char* api_method_name, - std::shared_ptr<CompilationResultResolver> resolver) { + std::shared_ptr<CompilationResultResolver> resolver, int compilation_id) { Handle<Context> incumbent_context = isolate->GetIncumbentContext(); AsyncCompileJob* job = new AsyncCompileJob( isolate, enabled, std::move(bytes_copy), length, context, - incumbent_context, api_method_name, std::move(resolver)); + incumbent_context, api_method_name, std::move(resolver), compilation_id); // Pass ownership to the unique_ptr in {async_compile_jobs_}. base::MutexGuard guard(&mutex_); async_compile_jobs_[job] = std::unique_ptr<AsyncCompileJob>(job); @@ -992,10 +1008,14 @@ void WasmEngine::RemoveIsolate(Isolate* isolate) { if (current_gc_info_) { if (RemoveIsolateFromCurrentGC(isolate)) PotentiallyFinishCurrentGC(); } - if (auto* task = info->log_codes_task) task->Cancel(); - for (auto& log_entry : info->code_to_log) { - WasmCode::DecrementRefCount(VectorOf(log_entry.second.code)); + if (auto* task = info->log_codes_task) { + task->Cancel(); + for (auto& log_entry : info->code_to_log) { + WasmCode::DecrementRefCount(VectorOf(log_entry.second.code)); + } + info->code_to_log.clear(); } + DCHECK(info->code_to_log.empty()); } void WasmEngine::LogCode(Vector<WasmCode*> code_vec) { @@ -1365,6 +1385,53 @@ WasmEngine::GetBarrierForBackgroundCompile() { return operations_barrier_; } +namespace { +void SampleExceptionEvent(base::ElapsedTimer* timer, TimedHistogram* counter) { + if (!timer->IsStarted()) { + timer->Start(); + return; + } + counter->AddSample(static_cast<int>(timer->Elapsed().InMilliseconds())); + timer->Restart(); +} +} // namespace + +void WasmEngine::SampleThrowEvent(Isolate* isolate) { + base::MutexGuard guard(&mutex_); + IsolateInfo* isolate_info = isolates_[isolate].get(); + int& throw_count = isolate_info->throw_count; + // To avoid an int overflow, clip the count to the histogram's max value. + throw_count = + std::min(throw_count + 1, isolate->counters()->wasm_throw_count()->max()); + isolate->counters()->wasm_throw_count()->AddSample(throw_count); + SampleExceptionEvent(&isolate_info->throw_timer, + isolate->counters()->wasm_time_between_throws()); +} + +void WasmEngine::SampleRethrowEvent(Isolate* isolate) { + base::MutexGuard guard(&mutex_); + IsolateInfo* isolate_info = isolates_[isolate].get(); + int& rethrow_count = isolate_info->rethrow_count; + // To avoid an int overflow, clip the count to the histogram's max value. + rethrow_count = std::min(rethrow_count + 1, + isolate->counters()->wasm_rethrow_count()->max()); + isolate->counters()->wasm_rethrow_count()->AddSample(rethrow_count); + SampleExceptionEvent(&isolate_info->rethrow_timer, + isolate->counters()->wasm_time_between_rethrows()); +} + +void WasmEngine::SampleCatchEvent(Isolate* isolate) { + base::MutexGuard guard(&mutex_); + IsolateInfo* isolate_info = isolates_[isolate].get(); + int& catch_count = isolate_info->catch_count; + // To avoid an int overflow, clip the count to the histogram's max value. + catch_count = + std::min(catch_count + 1, isolate->counters()->wasm_catch_count()->max()); + isolate->counters()->wasm_catch_count()->AddSample(catch_count); + SampleExceptionEvent(&isolate_info->catch_timer, + isolate->counters()->wasm_time_between_catch()); +} + void WasmEngine::TriggerGC(int8_t gc_sequence_index) { DCHECK(!mutex_.TryLock()); DCHECK_NULL(current_gc_info_); |