Bug 1509846: Validate in parallel when compiling with Cranelift; r=lth
authorBenjamin Bouvier <benj@benj.me>
Mon, 26 Nov 2018 14:13:47 +0100
changeset 504719 2b4844c3f4d88f746755c49d8d41de016ef8f2cb
parent 504718 e3ca695c95b2f5f69e6be409e8be394ade8932b3
child 504720 9fcec7e5baa7e044e0a403d70ded222dc4d7bb1f
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1509846
milestone65.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 1509846: Validate in parallel when compiling with Cranelift; r=lth
js/src/wasm/WasmCompile.cpp
js/src/wasm/WasmCraneliftCompile.cpp
js/src/wasm/WasmCraneliftCompile.h
js/src/wasm/WasmGenerator.cpp
js/src/wasm/WasmValidate.cpp
js/src/wasm/WasmValidate.h
--- a/js/src/wasm/WasmCompile.cpp
+++ b/js/src/wasm/WasmCompile.cpp
@@ -537,28 +537,16 @@ wasm::CompileBuffer(const CompileArgs& a
     CompilerEnvironment compilerEnv(args);
     ModuleEnvironment env(args.gcTypesConfigured,
                           &compilerEnv,
                           args.sharedMemoryEnabled ? Shareable::True : Shareable::False);
     if (!DecodeModuleEnvironment(d, &env)) {
         return nullptr;
     }
 
-#ifdef ENABLE_WASM_CRANELIFT
-    if (compilerEnv.tier() == Tier::Optimized &&
-        compilerEnv.optimizedBackend() == OptimizedBackend::Cranelift)
-    {
-        // At the moment, Cranelift performs no validation, so validate
-        // explicitly.
-        if (!ValidateForCranelift(bytecode, error)) {
-           return nullptr;
-        }
-    }
-#endif
-
     ModuleGenerator mg(args, &env, nullptr, error);
     if (!mg.init()) {
         return nullptr;
     }
 
     if (!DecodeCodeSection(env, d, mg)) {
         return nullptr;
     }
--- a/js/src/wasm/WasmCraneliftCompile.cpp
+++ b/js/src/wasm/WasmCraneliftCompile.cpp
@@ -274,16 +274,17 @@ env_global(const CraneliftModuleEnvironm
     return &env->env.globals[globalIndex];
 }
 
 bool
 wasm::CraneliftCompileFunctions(const ModuleEnvironment& env,
                                 LifoAlloc& lifo,
                                 const FuncCompileInputVector& inputs,
                                 CompiledCode* code,
+                                ExclusiveDeferredValidationState& dvs,
                                 UniqueChars* error)
 {
     MOZ_ASSERT(env.tier() == Tier::Optimized);
     MOZ_ASSERT(env.optimizedBackend() == OptimizedBackend::Cranelift);
 
     AutoCranelift compiler(env);
     if (!compiler.init()) {
         return false;
@@ -296,16 +297,21 @@ wasm::CraneliftCompileFunctions(const Mo
 
     // Swap in already-allocated empty vectors to avoid malloc/free.
     MOZ_ASSERT(code->empty());
     if (!code->swap(masm)) {
         return false;
     }
 
     for (const FuncCompileInput& func : inputs) {
+        Decoder d(func.begin, func.end, func.lineOrBytecode, error);
+        if (!ValidateFunctionBody(env, func.index, func.end - func.begin, d, dvs)) {
+            return false;
+        }
+
         CraneliftFuncCompileInput clifInput(func);
 
         CraneliftCompiledFunc clifFunc;
         if (!cranelift_compile_function(compiler, &clifInput, &clifFunc)) {
             *error = JS_smprintf("Cranelift error in clifFunc #%u", clifInput.index);
             return false;
         }
 
--- a/js/src/wasm/WasmCraneliftCompile.h
+++ b/js/src/wasm/WasmCraneliftCompile.h
@@ -27,14 +27,15 @@ namespace js {
 namespace wasm {
 
 // Generates code with Cranelift.
 MOZ_MUST_USE bool
 CraneliftCompileFunctions(const ModuleEnvironment& env,
                          LifoAlloc& lifo,
                          const FuncCompileInputVector& inputs,
                          CompiledCode* code,
+                         ExclusiveDeferredValidationState& dvs,
                          UniqueChars* error);
 
 } // namespace wasm
 } // namespace js
 
 #endif // wasm_cranelift_compile_h
--- a/js/src/wasm/WasmGenerator.cpp
+++ b/js/src/wasm/WasmGenerator.cpp
@@ -667,17 +667,17 @@ ExecuteCompileTask(CompileTask* task, Un
     MOZ_ASSERT(task->lifo.isEmpty());
     MOZ_ASSERT(task->output.empty());
 
     switch (task->env.tier()) {
       case Tier::Optimized:
 #ifdef ENABLE_WASM_CRANELIFT
         if (task->env.optimizedBackend() == OptimizedBackend::Cranelift) {
             if (!CraneliftCompileFunctions(task->env, task->lifo, task->inputs, &task->output,
-                                           error))
+                                           task->dvs, error))
             {
                 return false;
             }
             break;
         }
 #endif
         MOZ_ASSERT(task->env.optimizedBackend() == OptimizedBackend::Ion);
         if (!IonCompileFunctions(task->env, task->lifo, task->inputs,
--- a/js/src/wasm/WasmValidate.cpp
+++ b/js/src/wasm/WasmValidate.cpp
@@ -2528,18 +2528,17 @@ DecodeFunctionBody(Decoder& d, const Mod
     if (!ValidateFunctionBody(env, funcIndex, bodySize, d, dvs)) {
         return false;
     }
 
     return true;
 }
 
 static bool
-DecodeCodeSection(Decoder& d, ModuleEnvironment* env,
-                  ExclusiveDeferredValidationState& dvs)
+DecodeCodeSection(Decoder& d, ModuleEnvironment* env, ExclusiveDeferredValidationState& dvs)
 {
     if (!env->codeSection) {
         if (env->numFuncDefs() != 0) {
             return d.fail("expected code section");
         }
         return true;
     }
 
@@ -2858,40 +2857,8 @@ wasm::Validate(JSContext* cx, const Shar
 
     if (!DecodeModuleTail(d, &env, dvs)) {
         return false;
     }
 
     MOZ_ASSERT(!*error, "unreported error in decoding");
     return true;
 }
-
-bool
-wasm::ValidateForCranelift(const ShareableBytes& bytecode, UniqueChars* error)
-{
-    Decoder d(bytecode.bytes, 0, error);
-
-    // Cranelift doesn't support GC yet.
-    HasGcTypes hasGcTypes = HasGcTypes::False;
-
-    // Cranelift doesn't support threads yet.
-    Shareable threadSupport = Shareable::False;
-
-    CompilerEnvironment compilerEnv(CompileMode::Once, Tier::Optimized,
-                                    OptimizedBackend::Cranelift, DebugEnabled::False, hasGcTypes);
-    ModuleEnvironment env(hasGcTypes, &compilerEnv, threadSupport);
-
-    if (!DecodeModuleEnvironment(d, &env)) {
-        return false;
-    }
-
-    ExclusiveDeferredValidationState dvs(mutexid::WasmDeferredValidation);
-
-    if (!DecodeCodeSection(d, &env, dvs)) {
-        return false;
-    }
-    if (!DecodeModuleTail(d, &env, dvs)) {
-        return false;
-    }
-
-    MOZ_ASSERT(!*error, "unreported error in decoding");
-    return true;
-}
--- a/js/src/wasm/WasmValidate.h
+++ b/js/src/wasm/WasmValidate.h
@@ -927,17 +927,12 @@ ConvertMemoryPagesToBytes(Limits* memory
 // Validate an entire module, returning true if the module was validated
 // successfully. If Validate returns false:
 //  - if *error is null, the caller should report out-of-memory
 //  - otherwise, there was a legitimate error described by *error
 
 MOZ_MUST_USE bool
 Validate(JSContext* cx, const ShareableBytes& bytecode, UniqueChars* error);
 
-// Same, but don't require a JSContext.
-MOZ_MUST_USE bool
-ValidateForCranelift(const ShareableBytes& bytecode, UniqueChars* error);
-
-
 }  // namespace wasm
 }  // namespace js
 
 #endif // namespace wasm_validate_h