Commit e174f4ab authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[wasm] Remove GetName getters in favor of GetNameOrNull

This will replace "<?>" in certain debug output with the empty string.
There should be no end-user visible changes, though.

Change-Id: I80db2f2169532c600662977025185378004f7cd5
Reviewed-on: https://chromium-review.googlesource.com/1213188
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55742}
parent 7e5a2878
......@@ -355,7 +355,7 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module,
ModuleWireBytes wire_bytes(native_module->wire_bytes());
WireBytesRef name_ref =
module_env->module->LookupFunctionName(wire_bytes, func_index);
func_name = wire_bytes.GetName(name_ref);
func_name = wire_bytes.GetNameOrNull(name_ref);
}
TRACE_LAZY("Compiling function '%.*s' (#%d).\n", func_name.length(),
......@@ -545,7 +545,8 @@ void InitializeCompilationUnits(NativeModule* native_module) {
Vector<const uint8_t> bytes(wire_bytes.start() + func->code.offset(),
func->code.end_offset() - func->code.offset());
WasmName name = wire_bytes.GetName(func, module);
// TODO(herhut): Use a more useful name if none exists.
WasmName name = wire_bytes.GetNameOrNull(func, module);
DCHECK_NOT_NULL(native_module);
builder.AddUnit(func, buffer_offset, bytes, name);
}
......@@ -680,7 +681,7 @@ void CompileSequentially(Isolate* isolate, NativeModule* native_module,
WasmCode* code = WasmCompilationUnit::CompileWasmFunction(
isolate, native_module, &detected, thrower, module_env, &func);
if (code == nullptr) {
TruncatedUserString<> name(wire_bytes.GetName(&func, module));
TruncatedUserString<> name(wire_bytes.GetNameOrNull(&func, module));
thrower->CompileError("Compilation of #%d:%.*s failed.", i, name.length(),
name.start());
break;
......@@ -716,7 +717,7 @@ void ValidateSequentially(Isolate* isolate, NativeModule* native_module,
&detected, body);
}
if (result.failed()) {
TruncatedUserString<> name(wire_bytes.GetName(&func, module));
TruncatedUserString<> name(wire_bytes.GetNameOrNull(&func, module));
thrower->CompileError("Compiling function #%d:%.*s failed: %s @+%u", i,
name.length(), name.start(),
result.error_msg().c_str(), result.error_offset());
......
......@@ -141,14 +141,16 @@ bool WasmCode::ShouldBeLogged(Isolate* isolate) {
void WasmCode::LogCode(Isolate* isolate) const {
DCHECK(ShouldBeLogged(isolate));
if (IsAnonymous()) return;
ModuleWireBytes wire_bytes(native_module()->wire_bytes());
// TODO(herhut): Allow to log code without on-heap round-trip of the name.
ModuleEnv* module_env = GetModuleEnv(native_module()->compilation_state());
WireBytesRef name_ref =
module_env->module->LookupFunctionName(wire_bytes, index());
WasmName name_vec = wire_bytes.GetName(name_ref);
MaybeHandle<String> maybe_name =
isolate->factory()->NewStringFromUtf8(Vector<const char>::cast(name_vec));
WasmName name_vec = wire_bytes.GetNameOrNull(name_ref);
if (!name_vec.is_empty()) {
MaybeHandle<String> maybe_name = isolate->factory()->NewStringFromUtf8(
Vector<const char>::cast(name_vec));
Handle<String> name;
if (!maybe_name.ToHandle(&name)) {
name = isolate->factory()->NewStringFromAsciiChecked("<name too long>");
......@@ -160,6 +162,13 @@ void WasmCode::LogCode(Isolate* isolate) const {
PROFILE(isolate,
CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this,
{cname.get(), static_cast<size_t>(name_length)}));
} else {
EmbeddedVector<char, 32> generated_name;
SNPrintF(generated_name, "wasm-function[%d]", index());
PROFILE(isolate, CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this,
generated_name));
}
if (!source_positions().is_empty()) {
LOG_CODE_EVENT(isolate, CodeLinePosInfoRecordEvent(instruction_start(),
source_positions()));
......
......@@ -47,20 +47,6 @@ void WasmModule::AddFunctionNameForTesting(int function_index,
function_names->insert(std::make_pair(function_index, name));
}
// Get a string stored in the module bytes representing a name.
WasmName ModuleWireBytes::GetName(WireBytesRef ref) const {
if (ref.is_empty()) return {"<?>", 3}; // no name.
CHECK(BoundsCheck(ref.offset(), ref.length()));
return WasmName::cast(
module_bytes_.SubVector(ref.offset(), ref.end_offset()));
}
// Get a string stored in the module bytes representing a function name.
WasmName ModuleWireBytes::GetName(const WasmFunction* function,
const WasmModule* module) const {
return GetName(module->LookupFunctionName(*this, function->func_index));
}
// Get a string stored in the module bytes representing a name.
WasmName ModuleWireBytes::GetNameOrNull(WireBytesRef ref) const {
if (!ref.is_set()) return {nullptr, 0}; // no name.
......
......@@ -194,13 +194,6 @@ struct V8_EXPORT_PRIVATE ModuleWireBytes {
DCHECK_GE(kMaxInt, end - start);
}
// Get a string stored in the module bytes representing a name.
WasmName GetName(WireBytesRef ref) const;
// Get a string stored in the module bytes representing a function name.
WasmName GetName(const WasmFunction* function,
const WasmModule* module) const;
// Get a string stored in the module bytes representing a name.
WasmName GetNameOrNull(WireBytesRef ref) const;
......
......@@ -690,7 +690,7 @@ Vector<const uint8_t> WasmModuleObject::GetRawFunctionName(
wasm::ModuleWireBytes wire_bytes(native_module()->wire_bytes());
wasm::WireBytesRef name_ref =
module()->LookupFunctionName(wire_bytes, func_index);
wasm::WasmName name = wire_bytes.GetName(name_ref);
wasm::WasmName name = wire_bytes.GetNameOrNull(name_ref);
return Vector<const uint8_t>::cast(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