Bug 1171540 - Properly gate atomics and SAB for asm.js. r=luke
authorLars T Hansen <lhansen@mozilla.com>
Tue, 16 Jun 2015 15:19:05 +0200
changeset 249052 e815b262f9ac0f747a09f36ddeca39540bb89b45
parent 249051 a726ca79e03d5c82f88f10c5c19cbc1db84118f3
child 249053 f5ce4d1cb3c294d740a7a625ff12e65957e08c71
push id61133
push userlhansen@mozilla.com
push dateTue, 16 Jun 2015 13:21:46 +0000
treeherdermozilla-inbound@f5ce4d1cb3c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1171540
milestone41.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 1171540 - Properly gate atomics and SAB for asm.js. r=luke
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
@@ -9222,16 +9222,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,73 @@
+// 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.
+
+/*
+
+// 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.