mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 04:38:02 +00:00
Bug 1520931 - Baldr: another follow-up simplification from asm.js caching removal (r=bbouvier)
--HG-- extra : rebase_source : e379f66ed0785becfa63a17fb33ab62171545364
This commit is contained in:
parent
0f5eab5423
commit
b820dc9fb9
@ -2074,7 +2074,7 @@ class MOZ_STACK_CLASS JS_HAZ_ROOTED ModuleValidator
|
||||
str);
|
||||
}
|
||||
|
||||
SharedModule finish(UniqueLinkData* linkData) {
|
||||
SharedModule finish() {
|
||||
MOZ_ASSERT(env_.funcTypes.empty());
|
||||
if (!env_.funcTypes.resize(funcImportMap_.count() + funcDefs_.length())) {
|
||||
return nullptr;
|
||||
@ -2167,7 +2167,7 @@ class MOZ_STACK_CLASS JS_HAZ_ROOTED ModuleValidator
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mg.finishModule(*bytes, nullptr, linkData);
|
||||
return mg.finishModule(*bytes);
|
||||
}
|
||||
};
|
||||
|
||||
@ -6350,8 +6350,7 @@ static bool CheckModuleEnd(ModuleValidator<Unit>& m) {
|
||||
|
||||
template <typename Unit>
|
||||
static SharedModule CheckModule(JSContext* cx, AsmJSParser<Unit>& parser,
|
||||
ParseNode* stmtList, UniqueLinkData* linkData,
|
||||
unsigned* time) {
|
||||
ParseNode* stmtList, unsigned* time) {
|
||||
int64_t before = PRMJ_Now();
|
||||
|
||||
FunctionNode* moduleFunctionNode = parser.pc->functionBox()->functionNode;
|
||||
@ -6401,7 +6400,7 @@ static SharedModule CheckModule(JSContext* cx, AsmJSParser<Unit>& parser,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SharedModule module = m.finish(linkData);
|
||||
SharedModule module = m.finish();
|
||||
if (!module) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -7068,18 +7067,12 @@ static bool DoCompileAsmJS(JSContext* cx, AsmJSParser<Unit>& parser,
|
||||
return NoExceptionPending(cx);
|
||||
}
|
||||
|
||||
// Validate and generate code in a single linear pass over the chars of the
|
||||
// asm.js module.
|
||||
SharedModule module;
|
||||
// "Checking" parses, validates and compiles, producing a fully compiled
|
||||
// WasmModuleObject as result.
|
||||
unsigned time;
|
||||
{
|
||||
// "Checking" parses, validates and compiles, producing a fully compiled
|
||||
// WasmModuleObject as result.
|
||||
UniqueLinkData linkData;
|
||||
module = CheckModule(cx, parser, stmtList, &linkData, &time);
|
||||
if (!module) {
|
||||
return NoExceptionPending(cx);
|
||||
}
|
||||
SharedModule module = CheckModule(cx, parser, stmtList, &time);
|
||||
if (!module) {
|
||||
return NoExceptionPending(cx);
|
||||
}
|
||||
|
||||
// Hand over ownership to a GC object wrapper which can then be referenced
|
||||
|
@ -551,7 +551,7 @@ SharedModule wasm::CompileBuffer(const CompileArgs& args,
|
||||
const ShareableBytes& bytecode,
|
||||
UniqueChars* error,
|
||||
UniqueCharsVector* warnings,
|
||||
UniqueLinkData* maybeLinkData) {
|
||||
JS::OptimizedEncodingListener* listener) {
|
||||
Decoder d(bytecode.bytes, 0, error, warnings);
|
||||
|
||||
CompilerEnvironment compilerEnv(args);
|
||||
@ -575,7 +575,7 @@ SharedModule wasm::CompileBuffer(const CompileArgs& args,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mg.finishModule(bytecode, nullptr, maybeLinkData);
|
||||
return mg.finishModule(bytecode, listener);
|
||||
}
|
||||
|
||||
void wasm::CompileTier2(const CompileArgs& args, const Bytes& bytecode,
|
||||
|
@ -95,7 +95,7 @@ double EstimateCompiledCodeSize(Tier tier, size_t bytecodeSize);
|
||||
SharedModule CompileBuffer(const CompileArgs& args,
|
||||
const ShareableBytes& bytecode, UniqueChars* error,
|
||||
UniqueCharsVector* warnings,
|
||||
UniqueLinkData* maybeLinkData = nullptr);
|
||||
JS::OptimizedEncodingListener* listener = nullptr);
|
||||
|
||||
// Attempt to compile the second tier of the given wasm::Module.
|
||||
|
||||
|
@ -1094,8 +1094,7 @@ SharedMetadata ModuleGenerator::finishMetadata(const Bytes& bytecode) {
|
||||
|
||||
SharedModule ModuleGenerator::finishModule(
|
||||
const ShareableBytes& bytecode,
|
||||
JS::OptimizedEncodingListener* maybeTier2Listener,
|
||||
UniqueLinkData* maybeLinkData) {
|
||||
JS::OptimizedEncodingListener* maybeTier2Listener) {
|
||||
MOZ_ASSERT(mode() == CompileMode::Once || mode() == CompileMode::Tier1);
|
||||
|
||||
UniqueCodeTier codeTier = finishCodeTier();
|
||||
@ -1213,11 +1212,6 @@ SharedModule ModuleGenerator::finishModule(
|
||||
module->serialize(*linkData_, *maybeTier2Listener);
|
||||
}
|
||||
|
||||
if (maybeLinkData) {
|
||||
MOZ_ASSERT(!env_->debugEnabled());
|
||||
*maybeLinkData = std::move(linkData_);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
@ -220,8 +220,7 @@ class MOZ_STACK_CLASS ModuleGenerator {
|
||||
|
||||
SharedModule finishModule(
|
||||
const ShareableBytes& bytecode,
|
||||
JS::OptimizedEncodingListener* maybeTier2Listener = nullptr,
|
||||
UniqueLinkData* maybeLinkData = nullptr);
|
||||
JS::OptimizedEncodingListener* maybeTier2Listener = nullptr);
|
||||
MOZ_MUST_USE bool finishTier2(const Module& module);
|
||||
};
|
||||
|
||||
|
@ -452,6 +452,24 @@ bool wasm::Eval(JSContext* cx, Handle<TypedArrayObject*> code,
|
||||
globalObjs.get(), nullptr, instanceObj);
|
||||
}
|
||||
|
||||
struct MOZ_STACK_CLASS SerializeListener : JS::OptimizedEncodingListener {
|
||||
// MOZ_STACK_CLASS means these can be nops.
|
||||
MozExternalRefCountType MOZ_XPCOM_ABI AddRef() override { return 0; }
|
||||
MozExternalRefCountType MOZ_XPCOM_ABI Release() override { return 0; }
|
||||
|
||||
DebugOnly<bool> called = false;
|
||||
Bytes* serialized;
|
||||
SerializeListener(Bytes* serialized) : serialized(serialized) {}
|
||||
|
||||
void storeOptimizedEncoding(const uint8_t* bytes, size_t length) override {
|
||||
MOZ_ASSERT(!called);
|
||||
called = true;
|
||||
if (serialized->resize(length)) {
|
||||
memcpy(serialized->begin(), bytes, length);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool wasm::CompileAndSerialize(const ShareableBytes& bytecode,
|
||||
Bytes* serialized) {
|
||||
MutableCompileArgs compileArgs = js_new<CompileArgs>(ScriptedCaller());
|
||||
@ -459,28 +477,26 @@ bool wasm::CompileAndSerialize(const ShareableBytes& bytecode,
|
||||
return false;
|
||||
}
|
||||
|
||||
// The caller has ensured HasCachingSupport().
|
||||
// The caller has ensured HasCachingSupport(). Moreover, we want to ensure
|
||||
// we go straight to tier-2 so that we synchronously call
|
||||
// JS::OptimizedEncodingListener::storeOptimizedEncoding().
|
||||
compileArgs->baselineEnabled = false;
|
||||
compileArgs->ionEnabled = true;
|
||||
|
||||
SerializeListener listener(serialized);
|
||||
|
||||
UniqueChars error;
|
||||
UniqueCharsVector warnings;
|
||||
UniqueLinkData linkData;
|
||||
SharedModule module =
|
||||
CompileBuffer(*compileArgs, bytecode, &error, &warnings, &linkData);
|
||||
CompileBuffer(*compileArgs, bytecode, &error, &warnings, &listener);
|
||||
if (!module) {
|
||||
fprintf(stderr, "Compilation error: %s\n", error ? error.get() : "oom");
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(module->code().hasTier(Tier::Serialized));
|
||||
|
||||
size_t serializedSize = module->serializedSize(*linkData);
|
||||
if (!serialized->resize(serializedSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
module->serialize(*linkData, serialized->begin(), serialized->length());
|
||||
return true;
|
||||
MOZ_ASSERT(listener.called);
|
||||
return !listener.serialized->empty();
|
||||
}
|
||||
|
||||
bool wasm::DeserializeModule(JSContext* cx, const Bytes& serialized,
|
||||
|
Loading…
x
Reference in New Issue
Block a user