Bug 1276029 - Baldr: provide alternative path that provides build-id (r=bbouvier)
authorLuke Wagner <luke@mozilla.com>
Fri, 15 Jul 2016 12:26:40 -0500
changeset 345189 09461dda5ac8cf17b9504d4997fc851c172fb885
parent 345188 606e6f6aebe26585dd35c400ce72c3032b5e3378
child 345190 86a5424096d537c318dd3d90b9f69c3dc6c85bdb
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1276029
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1276029 - Baldr: provide alternative path that provides build-id (r=bbouvier) MozReview-Commit-ID: DEUOVJAnZx2
js/src/asmjs/AsmJS.cpp
js/src/asmjs/WasmCompile.cpp
js/src/asmjs/WasmCompile.h
js/src/asmjs/WasmJS.cpp
js/src/asmjs/WasmTypes.cpp
js/src/asmjs/WasmTypes.h
--- a/js/src/asmjs/AsmJS.cpp
+++ b/js/src/asmjs/AsmJS.cpp
@@ -1746,39 +1746,40 @@ class MOZ_STACK_CLASS ModuleValidator
 
         // This flows into FunctionBox, so must be tenured.
         dummyFunction_ = NewScriptedFunction(cx_, 0, JSFunction::INTERPRETED, nullptr,
                                              /* proto = */ nullptr, gc::AllocKind::FUNCTION,
                                              TenuredObject);
         if (!dummyFunction_)
             return false;
 
+        UniqueChars filename;
+        if (parser_.ss->filename()) {
+            filename = DuplicateString(parser_.ss->filename());
+            if (!filename)
+                return false;
+        }
+
         CompileArgs args;
-        if (!args.init(cx_))
+        if (!args.initFromContext(cx_, Move(filename)))
             return false;
 
         auto genData = MakeUnique<ModuleGeneratorData>(args.assumptions.usesSignal, ModuleKind::AsmJS);
         if (!genData ||
             !genData->sigs.resize(MaxSigs) ||
             !genData->funcSigs.resize(MaxFuncs) ||
             !genData->funcImports.resize(MaxImports) ||
             !genData->tables.resize(MaxTables) ||
             !genData->asmJSSigToTableIndex.resize(MaxSigs))
         {
             return false;
         }
 
         genData->minMemoryLength = RoundUpToNextValidAsmJSHeapLength(0);
 
-        if (parser_.ss->filename()) {
-            args.filename = DuplicateString(parser_.ss->filename());
-            if (!args.filename)
-                return false;
-        }
-
         if (!mg_.init(Move(genData), Move(args), asmJSMetadata_.get()))
             return false;
 
         return true;
     }
 
     ExclusiveContext* cx() const             { return cx_; }
     PropertyName* moduleFunctionName() const { return moduleFunctionName_; }
@@ -8383,18 +8384,18 @@ LookupAsmJSModuleInCache(ExclusiveContex
     asmJSMetadata->scriptSource.reset(parser.ss);
 
     bool atEnd = cursor == entry.memory + entry.serializedSize;
     MOZ_ASSERT(atEnd, "Corrupt cache file");
     if (!atEnd)
         return true;
 
     Assumptions assumptions;
-    if (!assumptions.init(cx->buildIdOp()))
-        return true;
+    if (!assumptions.initBuildIdFromContext(cx))
+        return false;
 
     if (assumptions != (*module)->metadata().assumptions)
         return true;
 
     if (!parser.tokenStream.advance(asmJSMetadata->srcEndBeforeCurly()))
         return false;
 
     int64_t after = PRMJ_Now();
--- a/js/src/asmjs/WasmCompile.cpp
+++ b/js/src/asmjs/WasmCompile.cpp
@@ -1381,25 +1381,21 @@ DecodeUnknownSections(Decoder& d)
         if (!d.skipSection())
             return Fail(d, "failed to skip unknown section at end");
     }
 
     return true;
 }
 
 bool
-CompileArgs::init(ExclusiveContext* cx)
+CompileArgs::initFromContext(ExclusiveContext* cx, UniqueChars f)
 {
     alwaysBaseline = cx->options().wasmAlwaysBaseline();
-    if (!assumptions.init(cx->buildIdOp())) {
-        ReportOutOfMemory(cx);
-        return false;
-    }
-
-    return true;
+    filename = Move(f);
+    return assumptions.initBuildIdFromContext(cx);
 }
 
 SharedModule
 wasm::Compile(const ShareableBytes& bytecode, CompileArgs&& args, UniqueChars* error)
 {
     bool newFormat = args.assumptions.newFormat;
 
     auto init = js::MakeUnique<ModuleGeneratorData>(args.assumptions.usesSignal);
--- a/js/src/asmjs/WasmCompile.h
+++ b/js/src/asmjs/WasmCompile.h
@@ -29,18 +29,26 @@ namespace wasm {
 // and filename into a wasm::Module.
 
 struct CompileArgs
 {
     Assumptions assumptions;
     UniqueChars filename;
     bool alwaysBaseline;
 
-    CompileArgs() : alwaysBaseline(false) {}
-    bool init(ExclusiveContext* cx);
+    CompileArgs(Assumptions&& assumptions, UniqueChars filename)
+      : assumptions(Move(assumptions)),
+        filename(Move(filename)),
+        alwaysBaseline(false)
+    {}
+
+    // If CompileArgs is constructed without arguments, initFromContext() must
+    // be called to complete initialization.
+    CompileArgs() = default;
+    bool initFromContext(ExclusiveContext* cx, UniqueChars filename);
 };
 
 SharedModule
 Compile(const ShareableBytes& bytecode, CompileArgs&& args, UniqueChars* error);
 
 }  // namespace wasm
 }  // namespace js
 
--- a/js/src/asmjs/WasmJS.cpp
+++ b/js/src/asmjs/WasmJS.cpp
@@ -136,26 +136,29 @@ wasm::Eval(JSContext* cx, Handle<TypedAr
     if (!bytecode)
         return false;
 
     if (!bytecode->append((uint8_t*)code->viewDataEither().unwrap(), code->byteLength())) {
         ReportOutOfMemory(cx);
         return false;
     }
 
-    CompileArgs compileArgs;
-    if (!compileArgs.init(cx))
-        return false;
+    UniqueChars filename;
+    {
+        JS::AutoFilename af;
+        if (DescribeScriptedCaller(cx, &af)) {
+            filename = DuplicateString(cx, af.get());
+            if (!filename)
+                return false;
+        }
+    }
 
-    JS::AutoFilename af;
-    if (DescribeScriptedCaller(cx, &af)) {
-        compileArgs.filename = DuplicateString(cx, af.get());
-        if (!compileArgs.filename)
-            return false;
-    }
+    CompileArgs compileArgs;
+    if (!compileArgs.initFromContext(cx, Move(filename)))
+        return false;
 
     UniqueChars error;
     SharedModule module = Compile(*bytecode, Move(compileArgs), &error);
     if (!module) {
         if (error)
             JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_FAIL, error.get());
         else
             ReportOutOfMemory(cx);
@@ -326,29 +329,32 @@ WasmModuleObject::construct(JSContext* c
         ArrayBufferObject& buffer = callArgs[0].toObject().as<ArrayBufferObject>();
         if (!bytecode->append(buffer.dataPointer(), buffer.byteLength()))
             return false;
     } else {
         JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_BUF_ARG);
         return false;
     }
 
+    UniqueChars filename;
+    {
+        JS::AutoFilename af;
+        if (DescribeScriptedCaller(cx, &af)) {
+            filename = DuplicateString(cx, af.get());
+            if (!filename)
+                return false;
+        }
+    }
+
     CompileArgs compileArgs;
-    if (!compileArgs.init(cx))
-        return true;
+    if (!compileArgs.initFromContext(cx, Move(filename)))
+        return false;
 
     compileArgs.assumptions.newFormat = true;
 
-    JS::AutoFilename af;
-    if (DescribeScriptedCaller(cx, &af)) {
-        compileArgs.filename = DuplicateString(cx, af.get());
-        if (!compileArgs.filename)
-            return false;
-    }
-
     if (!CheckCompilerSupport(cx))
         return false;
 
     UniqueChars error;
     SharedModule module = Compile(*bytecode, Move(compileArgs), &error);
     if (!module) {
         if (error)
             JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_FAIL, error.get());
--- a/js/src/asmjs/WasmTypes.cpp
+++ b/js/src/asmjs/WasmTypes.cpp
@@ -288,62 +288,73 @@ SignalUsage::SignalUsage()
 {}
 
 bool
 SignalUsage::operator==(SignalUsage rhs) const
 {
     return forOOB == rhs.forOOB && forInterrupt == rhs.forInterrupt;
 }
 
-static inline MOZ_MUST_USE bool
-GetCPUID(uint32_t* cpuId)
+static uint32_t
+GetCPUID()
 {
     enum Arch {
         X86 = 0x1,
         X64 = 0x2,
         ARM = 0x3,
         MIPS = 0x4,
         MIPS64 = 0x5,
         ARCH_BITS = 3
     };
 
 #if defined(JS_CODEGEN_X86)
     MOZ_ASSERT(uint32_t(jit::CPUInfo::GetSSEVersion()) <= (UINT32_MAX >> ARCH_BITS));
-    *cpuId = X86 | (uint32_t(jit::CPUInfo::GetSSEVersion()) << ARCH_BITS);
-    return true;
+    return X86 | (uint32_t(jit::CPUInfo::GetSSEVersion()) << ARCH_BITS);
 #elif defined(JS_CODEGEN_X64)
     MOZ_ASSERT(uint32_t(jit::CPUInfo::GetSSEVersion()) <= (UINT32_MAX >> ARCH_BITS));
-    *cpuId = X64 | (uint32_t(jit::CPUInfo::GetSSEVersion()) << ARCH_BITS);
-    return true;
+    return X64 | (uint32_t(jit::CPUInfo::GetSSEVersion()) << ARCH_BITS);
 #elif defined(JS_CODEGEN_ARM)
     MOZ_ASSERT(jit::GetARMFlags() <= (UINT32_MAX >> ARCH_BITS));
-    *cpuId = ARM | (jit::GetARMFlags() << ARCH_BITS);
-    return true;
+    return ARM | (jit::GetARMFlags() << ARCH_BITS);
+#elif defined(JS_CODEGEN_ARM64)
+    MOZ_CRASH("not enabled");
 #elif defined(JS_CODEGEN_MIPS32)
     MOZ_ASSERT(jit::GetMIPSFlags() <= (UINT32_MAX >> ARCH_BITS));
-    *cpuId = MIPS | (jit::GetMIPSFlags() << ARCH_BITS);
-    return true;
+    return MIPS | (jit::GetMIPSFlags() << ARCH_BITS);
 #elif defined(JS_CODEGEN_MIPS64)
     MOZ_ASSERT(jit::GetMIPSFlags() <= (UINT32_MAX >> ARCH_BITS));
-    *cpuId = MIPS64 | (jit::GetMIPSFlags() << ARCH_BITS);
-    return true;
+    return MIPS64 | (jit::GetMIPSFlags() << ARCH_BITS);
+#elif defined(JS_CODEGEN_NONE)
+    return 0;
 #else
-    return false;
+# error "unknown architecture"
 #endif
 }
 
-MOZ_MUST_USE bool
-Assumptions::init(JS::BuildIdOp buildIdOp)
+Assumptions::Assumptions(JS::BuildIdCharVector&& buildId)
+  : usesSignal(),
+    cpuId(GetCPUID()),
+    buildId(Move(buildId)),
+    newFormat(false)
+{}
+
+Assumptions::Assumptions()
+  : usesSignal(),
+    cpuId(GetCPUID()),
+    buildId(),
+    newFormat(false)
+{}
+
+bool
+Assumptions::initBuildIdFromContext(ExclusiveContext* cx)
 {
-    if (!GetCPUID(&cpuId))
+    if (!cx->buildIdOp() || !cx->buildIdOp()(&buildId)) {
+        ReportOutOfMemory(cx);
         return false;
-
-    if (!buildIdOp || !buildIdOp(&buildId))
-        return false;
-
+    }
     return true;
 }
 
 bool
 Assumptions::operator==(const Assumptions& rhs) const
 {
     return usesSignal == rhs.usesSignal &&
            cpuId == rhs.cpuId &&
--- a/js/src/asmjs/WasmTypes.h
+++ b/js/src/asmjs/WasmTypes.h
@@ -812,18 +812,22 @@ struct SignalUsage
 
 struct Assumptions
 {
     SignalUsage           usesSignal;
     uint32_t              cpuId;
     JS::BuildIdCharVector buildId;
     bool                  newFormat;
 
-    Assumptions() : usesSignal(), cpuId(0), newFormat(false) {}
-    MOZ_MUST_USE bool init(JS::BuildIdOp buildIdOp);
+    explicit Assumptions(JS::BuildIdCharVector&& buildId);
+
+    // If Assumptions is constructed without arguments, initBuildIdFromContext()
+    // must be called to complete initialization.
+    Assumptions();
+    bool initBuildIdFromContext(ExclusiveContext* cx);
 
     bool operator==(const Assumptions& rhs) const;
     bool operator!=(const Assumptions& rhs) const { return !(*this == rhs); }
 
     WASM_DECLARE_SERIALIZABLE(Assumptions)
 };
 
 // A Module can either be asm.js or wasm.