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, ...@@ -238,11 +238,8 @@ void CodeEventLogger::CodeCreateEvent(LogEventsAndTags tag,
const wasm::WasmCode* code, const wasm::WasmCode* code,
wasm::WasmName name) { wasm::WasmName name) {
name_buffer_->Init(tag); name_buffer_->Init(tag);
if (name.empty()) { DCHECK(!name.empty());
name_buffer_->AppendBytes("<wasm-unnamed>"); name_buffer_->AppendBytes(name.begin(), name.length());
} else {
name_buffer_->AppendBytes(name.begin(), name.length());
}
name_buffer_->AppendByte('-'); name_buffer_->AppendByte('-');
if (code->IsAnonymous()) { if (code->IsAnonymous()) {
name_buffer_->AppendBytes("<anonymous>"); name_buffer_->AppendBytes("<anonymous>");
...@@ -1303,11 +1300,9 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code, ...@@ -1303,11 +1300,9 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
AppendCodeCreateHeader(msg, tag, AbstractCode::Kind::WASM_FUNCTION, AppendCodeCreateHeader(msg, tag, AbstractCode::Kind::WASM_FUNCTION,
code->instructions().begin(), code->instructions().begin(),
code->instructions().length(), &timer_); code->instructions().length(), &timer_);
if (name.empty()) { DCHECK(!name.empty());
msg << "<unknown wasm>"; msg.AppendString(name);
} else {
msg.AppendString(name);
}
// We have to add two extra fields that allow the tick processor to group // 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 // 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 // normal JS functions, we use the shared function info. For wasm, the pointer
......
...@@ -195,28 +195,28 @@ void WasmCode::LogCode(Isolate* isolate) const { ...@@ -195,28 +195,28 @@ void WasmCode::LogCode(Isolate* isolate) const {
std::make_unique<WasmModuleSourceMap>(v8_isolate, source_map_str)); std::make_unique<WasmModuleSourceMap>(v8_isolate, source_map_str));
} }
std::unique_ptr<char[]> name_buffer; std::string name_buffer;
if (kind_ == kWasmToJsWrapper) { if (kind_ == kWasmToJsWrapper) {
constexpr size_t kNameBufferLen = 128; name_buffer = "wasm-to-js:";
constexpr size_t kNamePrefixLen = 11; size_t prefix_len = name_buffer.size();
name_buffer = std::make_unique<char[]>(kNameBufferLen); constexpr size_t kMaxSigLength = 128;
memcpy(name_buffer.get(), "wasm-to-js:", kNamePrefixLen); name_buffer.resize(prefix_len + kMaxSigLength);
Vector<char> remaining_buf =
VectorOf(name_buffer.get(), kNameBufferLen) + kNamePrefixLen;
FunctionSig* sig = native_module()->module()->functions[index_].sig; 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 the import has a name, also append that (separated by "-").
if (!name.empty() && remaining_buf.length() > 1) { if (!name.empty()) {
remaining_buf[0] = '-'; name_buffer += '-';
remaining_buf += 1; name_buffer.append(name.begin(), name.size());
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);
name = VectorOf(name_buffer.get(), name_len);
} else if (name.empty()) { } 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, PROFILE(isolate,
CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this, name)); 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