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

[wasm] Fix name used for code logging

Different loggers had different logic to handle unnamed wasm functions.
This CL makes sure that we always set a reasonable name when logging
wasm code, and removes handling for unnamed code in individual loggers.

Since logging only happens on user action, the code is not optimized for
performance (i.e. we always just write to a {std::string}, even if the
length of the string is known to be limited).

R=jkummerow@chromium.org

Bug: chromium:863205
Change-Id: I941f7e8050c97dc938afd7883aaeb3b6347b762d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2064977Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66370}
parent 5bc05aa5
......@@ -238,11 +238,8 @@ void CodeEventLogger::CodeCreateEvent(LogEventsAndTags tag,
const wasm::WasmCode* code,
wasm::WasmName name) {
name_buffer_->Init(tag);
if (name.empty()) {
name_buffer_->AppendBytes("<wasm-unnamed>");
} else {
DCHECK(!name.empty());
name_buffer_->AppendBytes(name.begin(), name.length());
}
name_buffer_->AppendByte('-');
if (code->IsAnonymous()) {
name_buffer_->AppendBytes("<anonymous>");
......@@ -1303,11 +1300,9 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
AppendCodeCreateHeader(msg, tag, AbstractCode::Kind::WASM_FUNCTION,
code->instructions().begin(),
code->instructions().length(), &timer_);
if (name.empty()) {
msg << "<unknown wasm>";
} else {
DCHECK(!name.empty());
msg.AppendString(name);
}
// We have to add two extra fields that allow the tick processor to group
// events for the same wasm function, even if it gets compiled again. For
// normal JS functions, we use the shared function info. For wasm, the pointer
......
......@@ -195,28 +195,28 @@ void WasmCode::LogCode(Isolate* isolate) const {
std::make_unique<WasmModuleSourceMap>(v8_isolate, source_map_str));
}
std::unique_ptr<char[]> name_buffer;
std::string name_buffer;
if (kind_ == kWasmToJsWrapper) {
constexpr size_t kNameBufferLen = 128;
constexpr size_t kNamePrefixLen = 11;
name_buffer = std::make_unique<char[]>(kNameBufferLen);
memcpy(name_buffer.get(), "wasm-to-js:", kNamePrefixLen);
Vector<char> remaining_buf =
VectorOf(name_buffer.get(), kNameBufferLen) + kNamePrefixLen;
name_buffer = "wasm-to-js:";
size_t prefix_len = name_buffer.size();
constexpr size_t kMaxSigLength = 128;
name_buffer.resize(prefix_len + kMaxSigLength);
FunctionSig* sig = native_module()->module()->functions[index_].sig;
remaining_buf += PrintSignature(remaining_buf, sig);
size_t sig_length =
PrintSignature(VectorOf(&name_buffer[prefix_len], kMaxSigLength), sig);
name_buffer.resize(prefix_len + sig_length);
// If the import has a name, also append that (separated by "-").
if (!name.empty() && remaining_buf.length() > 1) {
remaining_buf[0] = '-';
remaining_buf += 1;
size_t suffix_len = std::min(name.size(), remaining_buf.size());
memcpy(remaining_buf.begin(), name.begin(), suffix_len);
remaining_buf += suffix_len;
}
size_t name_len = remaining_buf.begin() - name_buffer.get();
name = VectorOf(name_buffer.get(), name_len);
if (!name.empty()) {
name_buffer += '-';
name_buffer.append(name.begin(), name.size());
}
name = VectorOf(name_buffer);
} else if (name.empty()) {
name = CStrVector("<wasm-unnamed>");
name_buffer.resize(32);
name_buffer.resize(
SNPrintF(VectorOf(&name_buffer.front(), name_buffer.size()),
"wasm-function[%d]", index()));
name = VectorOf(name_buffer);
}
PROFILE(isolate,
CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this, name));
......
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