Commit 5c1ed319 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Fix logged name of wasm-to-js wrappers

Instead of logging them as "wasm-unnamed" functions, log them as
"wasm-to-js", and append the signature.

This moves and generalizes the {AppendSignature} method that was already
used to produce the signature string for other wrappers.

R=jkummerow@chromium.org

Bug: chromium:1029470
Change-Id: Ic911cb19a49dcbc332bf5a4aa195107522ac6945
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1946350
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65287}
parent 5191f664
......@@ -6362,22 +6362,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
wasm::WasmFeatures enabled_features_;
};
void AppendSignature(char* buffer, size_t max_name_len,
wasm::FunctionSig* sig) {
size_t name_len = strlen(buffer);
auto append_name_char = [&](char c) {
if (name_len + 1 < max_name_len) buffer[name_len++] = c;
};
for (wasm::ValueType t : sig->parameters()) {
append_name_char(wasm::ValueTypes::ShortNameOf(t));
}
append_name_char(':');
for (wasm::ValueType t : sig->returns()) {
append_name_char(wasm::ValueTypes::ShortNameOf(t));
}
buffer[name_len] = '\0';
}
} // namespace
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
......@@ -6409,10 +6393,12 @@ std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
//----------------------------------------------------------------------------
// Create the compilation job.
//----------------------------------------------------------------------------
static constexpr size_t kMaxNameLen = 128;
auto debug_name = std::unique_ptr<char[]>(new char[kMaxNameLen]);
memcpy(debug_name.get(), "js_to_wasm:", 12);
AppendSignature(debug_name.get(), kMaxNameLen, sig);
constexpr size_t kMaxNameLen = 128;
constexpr size_t kNamePrefixLen = 11;
auto name_buffer = std::unique_ptr<char[]>(new char[kMaxNameLen]);
memcpy(name_buffer.get(), "js-to-wasm:", kNamePrefixLen);
PrintSignature(VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen,
sig);
int params = static_cast<int>(sig->parameter_count());
CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
......@@ -6420,7 +6406,8 @@ std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob(
return Pipeline::NewWasmHeapStubCompilationJob(
isolate, wasm_engine, incoming, std::move(zone), graph,
Code::JS_TO_WASM_FUNCTION, std::move(debug_name), WasmAssemblerOptions());
Code::JS_TO_WASM_FUNCTION, std::move(name_buffer),
WasmAssemblerOptions());
}
std::pair<WasmImportCallKind, Handle<JSReceiver>> ResolveWasmImportCall(
......@@ -6819,17 +6806,19 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate,
CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
zone.get(), false, wasm_count + 1, CallDescriptor::kNoFlags);
// Build a name in the form "js-to-js-wrapper:<params>:<returns>".
static constexpr size_t kMaxNameLen = 128;
auto debug_name = std::unique_ptr<char[]>(new char[kMaxNameLen]);
memcpy(debug_name.get(), "js-to-js-wrapper:", 18);
AppendSignature(debug_name.get(), kMaxNameLen, sig);
// Build a name in the form "js-to-js:<params>:<returns>".
constexpr size_t kMaxNameLen = 128;
constexpr size_t kNamePrefixLen = 9;
auto name_buffer = std::unique_ptr<char[]>(new char[kMaxNameLen]);
memcpy(name_buffer.get(), "js-to-js:", kNamePrefixLen);
PrintSignature(VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen,
sig);
// Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob(
isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
Code::JS_TO_JS_FUNCTION, std::move(debug_name),
Code::JS_TO_JS_FUNCTION, std::move(name_buffer),
AssemblerOptions::Default(isolate)));
if (job->ExecuteJob(isolate->counters()->runtime_call_stats()) ==
......@@ -6877,16 +6866,18 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
Linkage::GetSimplifiedCDescriptor(zone.get(), &incoming_sig, flags);
// Build a name in the form "c-wasm-entry:<params>:<returns>".
static constexpr size_t kMaxNameLen = 128;
auto debug_name = std::unique_ptr<char[]>(new char[kMaxNameLen]);
memcpy(debug_name.get(), "c-wasm-entry:", 14);
AppendSignature(debug_name.get(), kMaxNameLen, sig);
constexpr size_t kMaxNameLen = 128;
constexpr size_t kNamePrefixLen = 13;
auto name_buffer = std::unique_ptr<char[]>(new char[kMaxNameLen]);
memcpy(name_buffer.get(), "c-wasm-entry:", kNamePrefixLen);
PrintSignature(VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen,
sig);
// Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob(
isolate, isolate->wasm_engine(), incoming, std::move(zone), graph,
Code::C_WASM_ENTRY, std::move(debug_name),
Code::C_WASM_ENTRY, std::move(name_buffer),
AssemblerOptions::Default(isolate)));
if (job->ExecuteJob(isolate->counters()->runtime_call_stats()) ==
......
......@@ -235,7 +235,7 @@ void CodeEventLogger::CodeCreateEvent(LogEventsAndTags tag,
wasm::WasmName name) {
name_buffer_->Init(tag);
if (name.empty()) {
name_buffer_->AppendBytes("<wasm-unknown>");
name_buffer_->AppendBytes("<wasm-unnamed>");
} else {
name_buffer_->AppendBytes(name.begin(), name.length());
}
......
......@@ -196,7 +196,18 @@ void WasmCode::LogCode(Isolate* isolate) const {
std::unique_ptr<char[]> name_buffer;
Vector<const char> name;
if (name_vec.empty()) {
if (kind_ == kWasmToJsWrapper) {
DCHECK(name_vec.empty());
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> sig_buf =
VectorOf(name_buffer.get(), kNameBufferLen) + kNamePrefixLen;
FunctionSig* sig = native_module()->module()->functions[index_].sig;
size_t name_len = kNamePrefixLen + PrintSignature(sig_buf, sig);
name = VectorOf(name_buffer.get(), name_len);
} else if (name_vec.empty()) {
name = CStrVector("<wasm-unnamed>");
} else {
HandleScope scope(isolate);
......
......@@ -605,6 +605,26 @@ size_t EstimateStoredSize(const WasmModule* module) {
VectorSize(module->export_table) + VectorSize(module->exceptions) +
VectorSize(module->elem_segments);
}
size_t PrintSignature(Vector<char> buffer, wasm::FunctionSig* sig) {
if (buffer.empty()) return 0;
size_t old_size = buffer.size();
auto append_char = [&buffer](char c) {
if (buffer.size() == 1) return; // Keep last character for '\0'.
buffer[0] = c;
buffer += 1;
};
for (wasm::ValueType t : sig->parameters()) {
append_char(wasm::ValueTypes::ShortNameOf(t));
}
append_char(':');
for (wasm::ValueType t : sig->returns()) {
append_char(wasm::ValueTypes::ShortNameOf(t));
}
buffer[0] = '\0';
return old_size - buffer.size();
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -376,6 +376,11 @@ class TruncatedUserString {
char buffer_[kMaxLen];
};
// Print the signature into the given {buffer}. If {buffer} is non-empty, it
// will be null-terminated, even if the signature is cut off. Returns the number
// of characters written, excluding the terminating null-byte.
size_t PrintSignature(Vector<char> buffer, wasm::FunctionSig*);
} // namespace wasm
} // namespace internal
} // namespace v8
......
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