Commit 0db45cb1 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Remove unneeded heap roundtrip for logging

This was probably meant by the TODO removed in
https://crrev.com/c/1946354, I just failed to see it because the TODO
was placed at the wrong place.

The fix triggered a bug in the profiler, which made the wrong
assumption that the passed wasm name is null-terminated. This is also
fixed in this CL.

R=jkummerow@chromium.org, petermarshall@chromium.org

Change-Id: Ibf798e7511e61f6b305dd2d05d1aeca43be774a0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1948704Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65319}
parent 2fe1552c
......@@ -4,6 +4,8 @@
#include "src/profiler/profiler-listener.h"
#include <algorithm>
#include "src/codegen/reloc-info.h"
#include "src/codegen/source-position-table.h"
#include "src/deoptimizer/deoptimizer.h"
......@@ -15,6 +17,7 @@
#include "src/objects/string-inl.h"
#include "src/profiler/cpu-profiler.h"
#include "src/profiler/profile-generator-inl.h"
#include "src/utils/vector.h"
#include "src/wasm/wasm-code-manager.h"
namespace v8 {
......@@ -205,7 +208,7 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->instruction_start = code->instruction_start();
rec->entry = new CodeEntry(
tag, GetName(name.begin()), CodeEntry::kWasmResourceNamePrefix,
tag, GetName(name), CodeEntry::kWasmResourceNamePrefix,
CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo,
nullptr, code->instruction_start(), true);
rec->instruction_size = code->instructions().length();
......@@ -285,6 +288,14 @@ void ProfilerListener::NativeContextMoveEvent(Address from, Address to) {
DispatchCodeEvent(evt_rec);
}
const char* ProfilerListener::GetName(Vector<const char> name) {
// TODO(all): Change {StringsStorage} to accept non-null-terminated strings.
OwnedVector<char> null_terminated = OwnedVector<char>::New(name.size() + 1);
std::copy(name.begin(), name.end(), null_terminated.begin());
null_terminated[name.size()] = '\0';
return GetName(null_terminated.begin());
}
Name ProfilerListener::InferScriptName(Name name, SharedFunctionInfo info) {
if (name.IsString() && String::cast(name).length()) return name;
if (!info.script().IsScript()) return name;
......
......@@ -66,6 +66,7 @@ class V8_EXPORT_PRIVATE ProfilerListener : public CodeEventListener {
const char* GetName(const char* name) {
return function_and_resource_names_.GetCopy(name);
}
const char* GetName(Vector<const char> name);
const char* GetConsName(const char* prefix, Name name) {
return function_and_resource_names_.GetConsName(prefix, name);
}
......
......@@ -180,7 +180,7 @@ void WasmCode::LogCode(Isolate* isolate) const {
ModuleWireBytes wire_bytes(native_module()->wire_bytes());
WireBytesRef name_ref =
native_module()->module()->LookupFunctionName(wire_bytes, index());
WasmName name_vec = wire_bytes.GetNameOrNull(name_ref);
WasmName name = wire_bytes.GetNameOrNull(name_ref);
const std::string& source_map_url = native_module()->module()->source_map_url;
auto load_wasm_source_map = isolate->wasm_load_source_map_callback();
......@@ -195,9 +195,8 @@ void WasmCode::LogCode(Isolate* isolate) const {
}
std::unique_ptr<char[]> name_buffer;
Vector<const char> name;
if (kind_ == kWasmToJsWrapper) {
DCHECK(name_vec.empty());
DCHECK(name.empty());
constexpr size_t kNameBufferLen = 128;
constexpr size_t kNamePrefixLen = 11;
name_buffer = std::make_unique<char[]>(kNameBufferLen);
......@@ -207,22 +206,8 @@ void WasmCode::LogCode(Isolate* isolate) const {
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()) {
} else if (name.empty()) {
name = CStrVector("<wasm-unnamed>");
} else {
HandleScope scope(isolate);
MaybeHandle<String> maybe_name = isolate->factory()->NewStringFromUtf8(
Vector<const char>::cast(name_vec));
Handle<String> name_string;
if (maybe_name.ToHandle(&name_string)) {
int name_len = 0;
name_buffer = name_string->ToCString(
AllowNullsFlag::DISALLOW_NULLS,
RobustnessFlag::ROBUST_STRING_TRAVERSAL, &name_len);
name = VectorOf(name_buffer.get(), name_len);
} else {
name = CStrVector("<name too long>");
}
}
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