Commit 9d7de198 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Do not set a name on wasm scripts

The name has very few uses. I found at least one where the current
value does not make sense (on js-to-wasm wrappers in profiling), but I
found zero uses that were actually useful.

Hence this CL removes the name, i.e. just sets none on wasm scripts.

R=thibaudm@chromium.org, yangguo@chromium.org

Bug: chromium:1125986
Change-Id: I2f793986a3da905980132cd09349dd6a1d787957
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2584245
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71718}
parent aa89c107
......@@ -739,55 +739,56 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
script->set_type(Script::TYPE_WASM);
Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
int hash = StringHasher::HashSequentialString(
reinterpret_cast<const char*>(wire_bytes.begin()), wire_bytes.length(),
kZeroHashSeed);
const int kBufferSize = 32;
char buffer[kBufferSize];
// Script name is "<module_name>-hash" if name is available and "hash"
// otherwise.
// The source URL of the script is
// - the original source URL if available (from the streaming API),
// - wasm://wasm/<module name>-<hash> if a module name has been set, or
// - wasm://wasm/<hash> otherwise.
const WasmModule* module = native_module->module();
Handle<String> name_str;
if (module->name.is_set()) {
int name_chars = SNPrintF(ArrayVector(buffer), "-%08x", hash);
DCHECK(name_chars >= 0 && name_chars < kBufferSize);
Handle<String> name_hash =
isolate->factory()
->NewStringFromOneByte(
VectorOf(reinterpret_cast<uint8_t*>(buffer), name_chars),
AllocationType::kOld)
.ToHandleChecked();
Handle<String> module_name =
WasmModuleObject::ExtractUtf8StringFromModuleBytes(
isolate, wire_bytes, module->name, kNoInternalize);
name_str = isolate->factory()
->NewConsString(module_name, name_hash)
.ToHandleChecked();
} else {
int name_chars = SNPrintF(ArrayVector(buffer), "%08x", hash);
DCHECK(name_chars >= 0 && name_chars < kBufferSize);
name_str = isolate->factory()
->NewStringFromOneByte(
VectorOf(reinterpret_cast<uint8_t*>(buffer), name_chars),
AllocationType::kOld)
.ToHandleChecked();
}
script->set_name(*name_str);
MaybeHandle<String> url_str;
Handle<String> url_str;
if (!source_url.empty()) {
url_str =
isolate->factory()->NewStringFromUtf8(source_url, AllocationType::kOld);
url_str = isolate->factory()
->NewStringFromUtf8(source_url, AllocationType::kOld)
.ToHandleChecked();
} else {
Handle<String> url_prefix =
isolate->factory()->InternalizeString(StaticCharVector("wasm://wasm/"));
url_str = isolate->factory()->NewConsString(url_prefix, name_str);
int hash = StringHasher::HashSequentialString(
reinterpret_cast<const char*>(wire_bytes.begin()), wire_bytes.length(),
kZeroHashSeed);
EmbeddedVector<char, 32> buffer;
if (module->name.is_empty()) {
// Build the URL in the form "wasm://wasm/<hash>".
int url_len = SNPrintF(buffer, "wasm://wasm/%08x", hash);
DCHECK(url_len >= 0 && url_len < buffer.length());
url_str = isolate->factory()
->NewStringFromUtf8(buffer.SubVector(0, url_len),
AllocationType::kOld)
.ToHandleChecked();
} else {
// Build the URL in the form "wasm://wasm/<module name>-<hash>".
int hash_len = SNPrintF(buffer, "-%08x", hash);
DCHECK(hash_len >= 0 && hash_len < buffer.length());
Handle<String> prefix =
isolate->factory()->NewStringFromStaticChars("wasm://wasm/");
Handle<String> module_name =
WasmModuleObject::ExtractUtf8StringFromModuleBytes(
isolate, wire_bytes, module->name, kNoInternalize);
Handle<String> hash_str =
isolate->factory()
->NewStringFromUtf8(buffer.SubVector(0, hash_len))
.ToHandleChecked();
// Concatenate the three parts.
url_str = isolate->factory()
->NewConsString(prefix, module_name)
.ToHandleChecked();
url_str = isolate->factory()
->NewConsString(url_str, hash_str)
.ToHandleChecked();
}
}
script->set_source_url(*url_str.ToHandleChecked());
script->set_source_url(*url_str);
const WasmDebugSymbols& debug_symbols =
native_module->module()->debug_symbols;
const WasmDebugSymbols& debug_symbols = module->debug_symbols;
if (debug_symbols.type == WasmDebugSymbols::Type::SourceMap &&
!debug_symbols.external_url.is_empty()) {
Vector<const char> external_url =
......
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