Commit a22e8a70 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Fix code logging of wrappers

Import wrappers were only logged if logging was enabled during
compilation. If the profiler is enabled later, and regular wasm code is
logged via {NativeModule::LogWasmCodes}, the import wrappers were
missing.
This CL fixes the long-standing TODO, and adds tests which triggered
that code path. Those tests were hanging before because the expected
functions did never appear in the profile.

Drive-by: If {WasmEngine::LogOutstandingCodesForIsolate} detects that
code logging is disabled by now, it should still clear the {code_to_log}
vector.

R=thibaudm@chromium.org

Bug: chromium:1125986, chromium:1141787
Change-Id: I2566ef369bb61a09488f2d932b6c10d92e4cb12f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2574696Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71645}
parent cddaf66c
...@@ -862,13 +862,12 @@ void NativeModule::LogWasmCodes(Isolate* isolate) { ...@@ -862,13 +862,12 @@ void NativeModule::LogWasmCodes(Isolate* isolate) {
TRACE_EVENT1("v8.wasm", "wasm.LogWasmCodes", "functions", TRACE_EVENT1("v8.wasm", "wasm.LogWasmCodes", "functions",
module_->num_declared_functions); module_->num_declared_functions);
// TODO(titzer): we skip the logging of the import wrappers // Log all owned code, not just the current entries in the code table. This
// here, but they should be included somehow. // will also include import wrappers.
int start = module_->num_imported_functions;
int end = start + module_->num_declared_functions;
WasmCodeRefScope code_ref_scope; WasmCodeRefScope code_ref_scope;
for (int func_index = start; func_index < end; ++func_index) { base::MutexGuard lock(&allocation_mutex_);
if (WasmCode* code = GetCode(func_index)) code->LogCode(isolate); for (auto& owned_entry : owned_code_) {
owned_entry.second->LogCode(isolate);
} }
} }
......
...@@ -1026,9 +1026,6 @@ void WasmEngine::EnableCodeLogging(Isolate* isolate) { ...@@ -1026,9 +1026,6 @@ void WasmEngine::EnableCodeLogging(Isolate* isolate) {
} }
void WasmEngine::LogOutstandingCodesForIsolate(Isolate* isolate) { void WasmEngine::LogOutstandingCodesForIsolate(Isolate* isolate) {
// If by now we should not log code any more, do not log it.
if (!WasmCode::ShouldBeLogged(isolate)) return;
// Under the mutex, get the vector of wasm code to log. Then log and decrement // Under the mutex, get the vector of wasm code to log. Then log and decrement
// the ref count without holding the mutex. // the ref count without holding the mutex.
std::vector<WasmCode*> code_to_log; std::vector<WasmCode*> code_to_log;
...@@ -1037,6 +1034,10 @@ void WasmEngine::LogOutstandingCodesForIsolate(Isolate* isolate) { ...@@ -1037,6 +1034,10 @@ void WasmEngine::LogOutstandingCodesForIsolate(Isolate* isolate) {
DCHECK_EQ(1, isolates_.count(isolate)); DCHECK_EQ(1, isolates_.count(isolate));
code_to_log.swap(isolates_[isolate]->code_to_log); code_to_log.swap(isolates_[isolate]->code_to_log);
} }
// If by now we should not log code any more, do not log it.
if (!WasmCode::ShouldBeLogged(isolate)) return;
TRACE_EVENT1("v8.wasm", "wasm.LogCode", "codeObjects", code_to_log.size()); TRACE_EVENT1("v8.wasm", "wasm.LogCode", "codeObjects", code_to_log.size());
if (code_to_log.empty()) return; if (code_to_log.empty()) return;
for (WasmCode* code : code_to_log) { for (WasmCode* code : code_to_log) {
......
...@@ -11,3 +11,15 @@ Building wasm module with sentinel 2. ...@@ -11,3 +11,15 @@ Building wasm module with sentinel 2.
Running fib with increasing input until it shows up in the profile. Running fib with increasing input until it shows up in the profile.
Found expected functions in profile. Found expected functions in profile.
Wasm script id is NOT SET. Wasm script id is NOT SET.
testEnableProfilerAfterDebugger
Compiling wasm.
Building wasm module with sentinel 3.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is NOT SET.
testEnableProfilerBeforeDebugger
Compiling wasm.
Building wasm module with sentinel 4.
Running fib with increasing input until it shows up in the profile.
Found expected functions in profile.
Wasm script id is NOT SET.
...@@ -118,26 +118,50 @@ async function compileWasm() { ...@@ -118,26 +118,50 @@ async function compileWasm() {
async function testEnableProfilerEarly() { async function testEnableProfilerEarly() {
InspectorTest.log(arguments.callee.name); InspectorTest.log(arguments.callee.name);
Protocol.Profiler.enable(); checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start()); checkError(await Protocol.Profiler.start());
await compileWasm(); await compileWasm();
await runFibUntilProfileFound(); await runFibUntilProfileFound();
Protocol.Profiler.disable(); checkError(await Protocol.Profiler.disable());
} }
async function testEnableProfilerLate() { async function testEnableProfilerLate() {
InspectorTest.log(arguments.callee.name); InspectorTest.log(arguments.callee.name);
await compileWasm(); await compileWasm();
Protocol.Profiler.enable(); checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start()); checkError(await Protocol.Profiler.start());
await runFibUntilProfileFound(); await runFibUntilProfileFound();
Protocol.Profiler.disable(); checkError(await Protocol.Profiler.disable());
}
async function testEnableProfilerAfterDebugger() {
InspectorTest.log(arguments.callee.name);
checkError(await Protocol.Debugger.enable());
await compileWasm();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
await runFibUntilProfileFound();
checkError(await Protocol.Profiler.disable());
checkError(await Protocol.Debugger.disable());
}
async function testEnableProfilerBeforeDebugger() {
InspectorTest.log(arguments.callee.name);
await compileWasm();
await Protocol.Profiler.enable();
await Protocol.Debugger.enable();
checkError(await Protocol.Profiler.start());
await runFibUntilProfileFound();
await Protocol.Debugger.disable();
await Protocol.Profiler.disable();
} }
(async function test() { (async function test() {
try { try {
await testEnableProfilerEarly(); await testEnableProfilerEarly();
await testEnableProfilerLate(); await testEnableProfilerLate();
await testEnableProfilerAfterDebugger();
await testEnableProfilerBeforeDebugger();
} catch (e) { } catch (e) {
InspectorTest.log('caught: ' + e); InspectorTest.log('caught: ' + e);
} }
......
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