Bug 1171540 - Properly gate atomics and SAB for asm.js. r=luke, a=jocheng
authorLars T Hansen <lhansen@mozilla.com>
Tue, 16 Jun 2015 16:41:12 +0200
changeset 238646 05fb211d4c6c60fba3964517f2218166a71f84a4
parent 238645 31820845d067e896a751894f75d389013caad22e
child 238647 14a1a46b54ab902504e5f8613fce8a4eed5eaa33
push id702
push userryanvm@gmail.com
push dateThu, 18 Jun 2015 14:43:27 +0000
treeherdermozilla-b2g37_v2_2@05fb211d4c6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke, jocheng
bugs1171540
milestone37.0
Bug 1171540 - Properly gate atomics and SAB for asm.js. r=luke, a=jocheng
js/src/asmjs/AsmJSValidate.cpp
js/src/jit-test/tests/asm.js/gating.js
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -9109,16 +9109,21 @@ CheckModule(ExclusiveContext* cx, AsmJSP
     if (!CheckModuleProcessingDirectives(m))
         return false;
 
     if (!CheckModuleGlobals(m))
         return false;
 
     m.startFunctionBodies();
 
+#if !defined(ENABLE_SHARED_ARRAY_BUFFER)
+    if (m.module().hasArrayView() && m.module().isSharedView())
+        return m.fail(nullptr, "shared views not supported by this build");
+#endif
+
     if (!CheckFunctions(m))
         return false;
 
     m.finishFunctionBodies();
 
     if (!CheckFuncPtrTables(m))
         return false;
 
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/asm.js/gating.js
@@ -0,0 +1,76 @@
+// Check gating of shared memory features in asm.js (bug 1171540).
+//
+// When run with -w this should produce a slew of warnings if shared
+// memory is not enabled.  There are several cases here because there
+// are various checks within Odin.
+//
+// Note code is not run, so the only issue here is whether it compiles
+// properly as asm.js.
+
+if (!isAsmJSCompilationAvailable())
+    quit(0);
+
+/*
+
+// Commented out until we can fix bug #1172517, which makes this fail
+// for other reasons.
+
+function module_a(stdlib, foreign, heap) {
+    "use asm";
+
+    // Without shared memory, this will be flagged as illegal view type
+    var view = stdlib.SharedInt32Array;
+    var i32a = new view(heap);
+    var ld = stdlib.Atomics.load;
+
+    function do_load() {
+	var v = 0;
+	v = ld(i32a, 0)|0;
+	return v|0;
+    }
+
+    return { load: do_load };
+}
+
+if (this.SharedArrayBuffer)
+    assertEq(isAsmJSModule(module_a), true);
+
+*/
+
+function module_b(stdlib, foreign, heap) {
+    "use asm";
+
+    // Without shared memory, this will be flagged as illegal view type
+    var i32a = new stdlib.SharedInt32Array(heap);
+    var ld = stdlib.Atomics.load;
+
+    function do_load() {
+	var v = 0;
+	v = ld(i32a, 0)|0;
+	return v|0;
+    }
+
+    return { load: do_load };
+}
+
+if (this.SharedArrayBuffer)
+    assertEq(isAsmJSModule(module_b), true);
+
+function module_d(stdlib, foreign, heap) {
+    "use asm";
+
+    var i32a = new stdlib.Int32Array(heap);
+    var ld = stdlib.Atomics.load;
+
+    function do_load() {
+	var v = 0;
+	// This should be flagged as a type error (needs shared view) regardless
+	// of whether shared memory is enabled.
+	v = ld(i32a, 0)|0;
+	return v|0;
+    }
+
+    return { load: do_load };
+}
+
+// module_d should never load properly.