Bug 1329019 - Baldr: Only compute bytecode hash in debug mode (r=yury)

MozReview-Commit-ID: GKxQzBznHJh
This commit is contained in:
Luke Wagner 2017-09-22 11:05:05 -05:00
parent bb375a16d4
commit bbe32a26fd
5 changed files with 25 additions and 16 deletions

View File

@ -5,6 +5,7 @@ if (!wasmDebuggingIsSupported())
quit();
var g = newGlobal();
var dbg = new Debugger(g);
g.eval(`
function initWasm(s) { return new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(s))); }
o1 = initWasm('(module (func) (export "" 0))');
@ -19,7 +20,6 @@ function isValidWasmURL(url) {
return /^wasm:(?:[^:]*:)*?[0-9a-f]{16}$/.test(url);
}
var dbg = new Debugger(g);
var foundScripts = dbg.findScripts().filter(isWasm);
assertEq(foundScripts.length, 2);
assertEq(isValidWasmURL(foundScripts[0].source.url), true);

View File

@ -559,8 +559,7 @@ Metadata::serializedSize() const
SerializedPodVectorSize(tables) +
SerializedPodVectorSize(funcNames) +
SerializedPodVectorSize(customSections) +
filename.serializedSize() +
sizeof(hash);
filename.serializedSize();
}
size_t
@ -592,7 +591,6 @@ Metadata::serialize(uint8_t* cursor) const
cursor = SerializePodVector(cursor, funcNames);
cursor = SerializePodVector(cursor, customSections);
cursor = filename.serialize(cursor);
cursor = WriteBytes(cursor, hash, sizeof(hash));
return cursor;
}
@ -606,8 +604,7 @@ Metadata::deserialize(const uint8_t* cursor)
(cursor = DeserializePodVector(cursor, &tables)) &&
(cursor = DeserializePodVector(cursor, &funcNames)) &&
(cursor = DeserializePodVector(cursor, &customSections)) &&
(cursor = filename.deserialize(cursor)) &&
(cursor = ReadBytes(cursor, hash, sizeof(hash)));
(cursor = filename.deserialize(cursor));
debugEnabled = false;
debugFuncArgTypes.clear();
debugFuncReturnTypes.clear();

View File

@ -379,7 +379,8 @@ class Metadata : public ShareableBase<Metadata>, public MetadataCacheablePod
explicit Metadata(UniqueMetadataTier tier, ModuleKind kind = ModuleKind::Wasm)
: MetadataCacheablePod(kind),
metadata1_(Move(tier)),
debugEnabled(false)
debugEnabled(false),
debugHash()
{}
virtual ~Metadata() {}
@ -406,12 +407,12 @@ class Metadata : public ShareableBase<Metadata>, public MetadataCacheablePod
NameInBytecodeVector funcNames;
CustomSectionVector customSections;
CacheableChars filename;
ModuleHash hash;
// Debug-enabled code is not serialized.
bool debugEnabled;
FuncArgTypesVector debugFuncArgTypes;
FuncReturnTypesVector debugFuncReturnTypes;
ModuleHash debugHash;
bool usesMemory() const { return UsesMemory(memoryUsage); }
bool hasSharedMemory() const { return memoryUsage == MemoryUsage::Shared; }

View File

@ -612,9 +612,11 @@ DebugState::debugDisplayURL(JSContext* cx) const
// - "wasm:" as protocol;
// - URI encoded filename from metadata (if can be encoded), plus ":";
// - 64-bit hash of the module bytes (as hex dump).
js::StringBuffer result(cx);
if (!result.append("wasm:"))
return nullptr;
if (const char* filename = metadata().filename.get()) {
js::StringBuffer filenamePrefix(cx);
// EncodeURI returns false due to invalid chars or OOM -- fail only
@ -623,12 +625,16 @@ DebugState::debugDisplayURL(JSContext* cx) const
if (!cx->isExceptionPending())
return nullptr;
cx->clearPendingException(); // ignore invalid URI
} else if (!result.append(filenamePrefix.finishString()) || !result.append(":")) {
} else if (!result.append(filenamePrefix.finishString())) {
return nullptr;
}
}
const ModuleHash& hash = metadata().hash;
if (metadata().debugEnabled) {
if (!result.append(":"))
return nullptr;
const ModuleHash& hash = metadata().debugHash;
for (size_t i = 0; i < sizeof(ModuleHash); i++) {
char digit1 = hash[i] / 16, digit2 = hash[i] % 16;
if (!result.append((char)(digit1 < 10 ? digit1 + '0' : digit1 + 'a' - 10)))
@ -636,6 +642,8 @@ DebugState::debugDisplayURL(JSContext* cx) const
if (!result.append((char)(digit2 < 10 ? digit2 + '0' : digit2 + 'a' - 10)))
return nullptr;
}
}
return result.finishString();
}

View File

@ -1100,11 +1100,14 @@ static_assert(sizeof(ModuleHash) <= sizeof(mozilla::SHA1Sum::Hash),
void
ModuleGenerator::generateBytecodeHash(const ShareableBytes& bytecode)
{
if (!env_->debugEnabled())
return;
mozilla::SHA1Sum::Hash hash;
mozilla::SHA1Sum sha1Sum;
sha1Sum.update(bytecode.begin(), bytecode.length());
sha1Sum.finish(hash);
memcpy(metadata_->hash, hash, sizeof(ModuleHash));
memcpy(metadata_->debugHash, hash, sizeof(ModuleHash));
}
bool