Bug 1515917 - Generalize testing for wasm GC availability. r=bbouvier
authorLars T Hansen <lhansen@mozilla.com>
Fri, 21 Dec 2018 12:41:52 +0100
changeset 510511 7543b4c2813c76e1e2a3cc70fea991e725654877
parent 510510 2742b347ca238d6a8c475d8e79b556206d62d196
child 510512 baf99d3bdfea3cfb5bed7a6072ca713ecee67066
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1515917
milestone66.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 1515917 - Generalize testing for wasm GC availability. r=bbouvier Generalize the testing of GC availability so that it more accurately reflects whether GC support is actually available, this is a complicated predicate at present. (This was motivated by an attempt to generalize the testing directives, but that generalization does not land yet because it has some obscure effects that need to be addressed first.) The generalization sets us up for splitting apart the code and test cases for the "reftypes" and "gctypes" proposals in a subsequent patch.
js/src/builtin/TestingFunctions.cpp
js/src/jit/CompileWrappers.cpp
js/src/wasm/WasmCompile.cpp
js/src/wasm/WasmJS.cpp
js/src/wasm/WasmJS.h
js/src/wasm/WasmValidate.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -665,42 +665,28 @@ static bool WasmBulkMemSupported(JSConte
 #endif
 #else
   bool isSupported = false;
 #endif
   args.rval().setBoolean(isSupported);
   return true;
 }
 
-static bool TestGCEnabled(JSContext* cx) {
-#ifdef ENABLE_WASM_GC
-  bool isSupported = cx->options().wasmBaseline() && cx->options().wasmGc();
-#ifdef ENABLE_WASM_CRANELIFT
-  if (cx->options().wasmForceCranelift()) {
-    isSupported = false;
-  }
-#endif
-  return isSupported;
-#else
-  return false;
-#endif
-}
-
 static bool WasmGcEnabled(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
-  args.rval().setBoolean(TestGCEnabled(cx));
+  args.rval().setBoolean(wasm::HasGcSupport(cx));
   return true;
 }
 
 static bool WasmGeneralizedTables(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
 #ifdef ENABLE_WASM_GENERALIZED_TABLES
   // Generalized tables depend on anyref, though not currently on (ref T)
   // types nor on structures or other GC-proposal features.
-  bool isSupported = TestGCEnabled(cx);
+  bool isSupported = wasm::HasGcSupport(cx);
 #else
   bool isSupported = false;
 #endif
   args.rval().setBoolean(isSupported);
   return true;
 }
 
 static bool WasmCompileMode(JSContext* cx, unsigned argc, Value* vp) {
--- a/js/src/jit/CompileWrappers.cpp
+++ b/js/src/jit/CompileWrappers.cpp
@@ -220,11 +220,11 @@ JitCompileOptions::JitCompileOptions()
 
 JitCompileOptions::JitCompileOptions(JSContext* cx) {
   cloneSingletons_ = cx->realm()->creationOptions().cloneSingletons();
   profilerSlowAssertionsEnabled_ =
       cx->runtime()->geckoProfiler().enabled() &&
       cx->runtime()->geckoProfiler().slowAssertionsEnabled();
   offThreadCompilationAvailable_ = OffThreadCompilationAvailable(cx);
 #ifdef ENABLE_WASM_GC
-  wasmGcEnabled_ = cx->options().wasmGc();
+  wasmGcEnabled_ = wasm::HasGcSupport(cx);
 #endif
 }
--- a/js/src/wasm/WasmCompile.cpp
+++ b/js/src/wasm/WasmCompile.cpp
@@ -70,17 +70,17 @@ uint32_t wasm::ObservedCPUFeatures() {
 #else
 #error "unknown architecture"
 #endif
 }
 
 CompileArgs::CompileArgs(JSContext* cx, ScriptedCaller&& scriptedCaller)
     : scriptedCaller(std::move(scriptedCaller)) {
 #ifdef ENABLE_WASM_GC
-  bool gcEnabled = cx->options().wasmGc();
+  bool gcEnabled = HasGcSupport(cx);
 #else
   bool gcEnabled = false;
 #endif
 
   baselineEnabled = cx->options().wasmBaseline();
   ionEnabled = cx->options().wasmIon();
 #ifdef ENABLE_WASM_CRANELIFT
   forceCranelift = cx->options().wasmForceCranelift();
--- a/js/src/wasm/WasmJS.cpp
+++ b/js/src/wasm/WasmJS.cpp
@@ -52,16 +52,29 @@ using namespace js::jit;
 using namespace js::wasm;
 
 using mozilla::CheckedInt;
 using mozilla::Nothing;
 using mozilla::RangedPtr;
 
 extern mozilla::Atomic<bool> fuzzingSafe;
 
+bool wasm::HasGcSupport(JSContext* cx) {
+#ifdef ENABLE_WASM_CRANELIFT
+  if (cx->options().wasmForceCranelift()) {
+    return false;
+  }
+#endif
+#ifdef ENABLE_WASM_GC
+  return cx->options().wasmGc() && cx->options().wasmBaseline();
+#else
+  return false;
+#endif
+}
+
 bool wasm::HasCompilerSupport(JSContext* cx) {
 #if !MOZ_LITTLE_ENDIAN || defined(JS_CODEGEN_NONE)
   return false;
 #endif
 
   if (gc::SystemPageSize() > wasm::PageSize) {
     return false;
   }
@@ -2042,17 +2055,17 @@ bool WasmTableObject::isNewborn() const 
     return false;
   }
 
   TableKind tableKind;
   if (StringEqualsAscii(elementLinearStr, "anyfunc")) {
     tableKind = TableKind::AnyFunction;
 #ifdef ENABLE_WASM_GENERALIZED_TABLES
   } else if (StringEqualsAscii(elementLinearStr, "anyref")) {
-    if (!cx->options().wasmGc()) {
+    if (!HasGcSupport(cx)) {
       JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr,
                                JSMSG_WASM_BAD_ELEMENT);
       return false;
     }
     tableKind = TableKind::AnyRef;
 #endif
   } else {
 #ifdef ENABLE_WASM_GENERALIZED_TABLES
@@ -2455,17 +2468,17 @@ const Class WasmGlobalObject::class_ = {
     // For the time being, i64 is allowed only if there is not an
     // initializing value.
     globalType = ValType::I64;
   } else if (StringEqualsAscii(typeLinearStr, "f32")) {
     globalType = ValType::F32;
   } else if (StringEqualsAscii(typeLinearStr, "f64")) {
     globalType = ValType::F64;
 #ifdef ENABLE_WASM_GC
-  } else if (cx->options().wasmGc() &&
+  } else if (HasGcSupport(cx) &&
              StringEqualsAscii(typeLinearStr, "anyref")) {
     globalType = ValType::AnyRef;
 #endif
   } else {
     JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr,
                              JSMSG_WASM_BAD_GLOBAL_TYPE);
     return false;
   }
--- a/js/src/wasm/WasmJS.h
+++ b/js/src/wasm/WasmJS.h
@@ -48,16 +48,21 @@ bool HasSupport(JSContext* cx);
 
 // Return whether WebAssembly streaming/caching is supported on this platform.
 // This takes into account prefs and necessary embedding callbacks.
 
 bool HasStreamingSupport(JSContext* cx);
 
 bool HasCachingSupport(JSContext* cx);
 
+// Returns true if WebAssembly as configured by compile-time flags and run-time
+// options can support reference types and stack walking.
+
+bool HasGcSupport(JSContext* cx);
+
 // Compiles the given binary wasm module given the ArrayBufferObject
 // and links the module's imports with the given import object.
 
 MOZ_MUST_USE bool Eval(JSContext* cx, Handle<TypedArrayObject*> code,
                        HandleObject importObj,
                        MutableHandleWasmInstanceObject instanceObj);
 
 // For testing cross-process (de)serialization, this pair of functions are
--- a/js/src/wasm/WasmValidate.cpp
+++ b/js/src/wasm/WasmValidate.cpp
@@ -2787,17 +2787,17 @@ bool wasm::DecodeModuleTail(Decoder& d, 
 // Validate algorithm.
 
 bool wasm::Validate(JSContext* cx, const ShareableBytes& bytecode,
                     UniqueChars* error) {
   Decoder d(bytecode.bytes, 0, error);
 
 #ifdef ENABLE_WASM_GC
   HasGcTypes gcTypesConfigured =
-      cx->options().wasmGc() ? HasGcTypes::True : HasGcTypes::False;
+      HasGcSupport(cx) ? HasGcTypes::True : HasGcTypes::False;
 #else
   HasGcTypes gcTypesConfigured = HasGcTypes::False;
 #endif
 
   CompilerEnvironment compilerEnv(CompileMode::Once, Tier::Optimized,
                                   OptimizedBackend::Ion, DebugEnabled::False,
                                   gcTypesConfigured);
   ModuleEnvironment env(