Commit 3b21b6d3 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[profiler] Allow empty source URL for asm modules

In contrast to wasm modules, asm.js modules have an empty source URL.
Thus loosen a DCHECK and handle the nullptr source_url correctly.
Also add regression tests that check that we don't crash. Those can
later be extended to check that the profile looks as expected; for now
they only check that we terminate.

R=bmeurer@chromium.org

Bug: chromium:1185919
Change-Id: I6b879f540a2c3647920ad2970efcf7c94712d8c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2745895Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73313}
parent cb2ec66d
......@@ -225,13 +225,16 @@ void ProfilerListener::CodeCreateEvent(LogEventsAndTags tag,
wasm::WasmName name,
const char* source_url, int code_offset,
int script_id) {
DCHECK_NOT_NULL(source_url);
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->instruction_start = code->instruction_start();
rec->entry =
new CodeEntry(tag, GetName(name), GetName(source_url), 1, code_offset + 1,
nullptr, true, CodeEntry::CodeType::WASM);
// Wasm modules always have a source URL. Asm.js modules never have one.
DCHECK_EQ(code->native_module()->module()->origin == wasm::kWasmOrigin,
source_url != nullptr);
rec->entry = new CodeEntry(
tag, GetName(name),
source_url ? GetName(source_url) : CodeEntry::kEmptyResourceName, 1,
code_offset + 1, nullptr, true, CodeEntry::CodeType::WASM);
rec->entry->set_script_id(script_id);
rec->entry->set_position(code_offset);
rec->instruction_size = code->instructions().length();
......
Test console profiles for asm.js.
testEnableProfilerEarly
Compiling asm.js module with sentinel 0.
testEnableProfilerLate
Compiling asm.js module with sentinel 1.
testEnableProfilerAfterDebugger
Compiling asm.js module with sentinel 2.
testEnableProfilerBeforeDebugger
Compiling asm.js module with sentinel 3.
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} =
InspectorTest.start('Test console profiles for asm.js.');
function compile(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; i++) {
view[i] = bytes[i] | 0;
}
let module = new WebAssembly.Module(buffer);
let fib = undefined;
function imp(i) { return fib(i); }
let instance = new WebAssembly.Instance(module, {q: {f: imp}});
fib = instance.exports.fib;
return instance;
}
function checkError(message) {
if (!message.error) return;
InspectorTest.log('Error: ');
InspectorTest.logMessage(message);
InspectorTest.completeTest();
}
// When build asm.js modules, include a sentinel such that the module will not
// be reused from the cache.
let sentinel = 0;
function AsmModule(stdlib, foreign, heap) {
"use asm";
function f() {
return sentinel;
}
return {f: f};
}
async function compileAsmJs() {
InspectorTest.log(`Compiling asm.js module with sentinel ${sentinel}.`);
let code = AsmModule.toString().replace('sentinel', sentinel.toString());
++sentinel;
checkError(await Protocol.Runtime.evaluate({expression: `(${code})().f()`}));
}
async function testEnableProfilerEarly() {
InspectorTest.log(arguments.callee.name);
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
await compileAsmJs();
checkError(await Protocol.Profiler.disable());
}
async function testEnableProfilerLate() {
InspectorTest.log(arguments.callee.name);
await compileAsmJs();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
checkError(await Protocol.Profiler.disable());
}
async function testEnableProfilerAfterDebugger() {
InspectorTest.log(arguments.callee.name);
checkError(await Protocol.Debugger.enable());
await compileAsmJs();
checkError(await Protocol.Profiler.enable());
checkError(await Protocol.Profiler.start());
checkError(await Protocol.Profiler.disable());
checkError(await Protocol.Debugger.disable());
}
async function testEnableProfilerBeforeDebugger() {
InspectorTest.log(arguments.callee.name);
await compileAsmJs();
await Protocol.Profiler.enable();
await Protocol.Debugger.enable();
checkError(await Protocol.Profiler.start());
await Protocol.Debugger.disable();
await Protocol.Profiler.disable();
}
(async function test() {
try {
await testEnableProfilerEarly();
await testEnableProfilerLate();
await testEnableProfilerAfterDebugger();
await testEnableProfilerBeforeDebugger();
} catch (e) {
InspectorTest.log('caught: ' + e);
}
})().catch(e => InspectorTest.log('caught: ' + e))
.finally(InspectorTest.completeTest);
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