Bug 1259392 - nail down isLockFree(4) for good. r=jolesen
authorLars T Hansen <lhansen@mozilla.com>
Thu, 24 Mar 2016 19:42:29 +0100
changeset 291506 ed673a43a40ffe7de3cc40ae465e9c7cd8c1d522
parent 291505 71eb251a0f29de94082623b91326e2449a3aa81e
child 291507 df3ddeee164770c7abf6448a38b72dbf70adec8a
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjolesen
bugs1259392
milestone48.0a1
Bug 1259392 - nail down isLockFree(4) for good. r=jolesen
js/src/jit-test/tests/atomics/basic-tests.js
js/src/jit/AtomicOperations.h
js/src/jit/CodeGenerator.cpp
--- a/js/src/jit-test/tests/atomics/basic-tests.js
+++ b/js/src/jit-test/tests/atomics/basic-tests.js
@@ -375,17 +375,17 @@ function adHocExchange() {
     assertEq(exchangeLoop(a), -100000);
 }
 
 // isLockFree(n) may return true only if there is an integer array
 // on which atomic operations is allowed whose byte size is n,
 // ie, it must return false for n=8.
 //
 // SpiderMonkey has isLockFree(1), isLockFree(2), isLockFree(4) on all
-// supported platforms, though this is not guaranteed by the spec.
+// supported platforms, only the last is guaranteed by the spec.
 
 var sizes   = [    1,     2,     3,     4,     5,     6,     7,  8,
                    9,    10,    11,    12];
 var answers = [ true,  true, false,  true, false, false, false, false,
 	       false, false, false, false];
 
 function testIsLockFree() {
     // This ought to defeat most compile-time resolution.
--- a/js/src/jit/AtomicOperations.h
+++ b/js/src/jit/AtomicOperations.h
@@ -294,18 +294,21 @@ class RegionLock
 
 inline bool
 AtomicOperations::isLockfree(int32_t size)
 {
     // Keep this in sync with visitAtomicIsLockFree() in jit/CodeGenerator.cpp.
 
     switch (size) {
       case 1:
+        return true;
       case 2:
+        return true;
       case 4:
+        // The spec requires Atomics.isLockFree(4) to return true.
         return true;
       case 8:
         // The spec requires Atomics.isLockFree(n) to return false
         // unless n is the BYTES_PER_ELEMENT value of some integer
         // TypedArray that admits atomic operations.  At the time of
         // writing (February 2016) there is no such array with n=8.
         // return AtomicOperations::isLockfree8();
         return false;
--- a/js/src/jit/CodeGenerator.cpp
+++ b/js/src/jit/CodeGenerator.cpp
@@ -10002,17 +10002,20 @@ CodeGenerator::visitStoreTypedArrayEleme
 
 void
 CodeGenerator::visitAtomicIsLockFree(LAtomicIsLockFree* lir)
 {
     Register value = ToRegister(lir->value());
     Register output = ToRegister(lir->output());
 
     // Keep this in sync with isLockfree() in jit/AtomicOperations.h.
-    MOZ_ASSERT(!AtomicOperations::isLockfree(8));
+    MOZ_ASSERT(AtomicOperations::isLockfree(1));  // Implementation artifact
+    MOZ_ASSERT(AtomicOperations::isLockfree(2));  // Implementation artifact
+    MOZ_ASSERT(AtomicOperations::isLockfree(4));  // Spec requirement
+    MOZ_ASSERT(!AtomicOperations::isLockfree(8)); // Implementation invariant, for now
 
     Label Ldone, Lfailed;
     masm.move32(Imm32(1), output);
     masm.branch32(Assembler::Equal, value, Imm32(4), &Ldone);
     masm.branch32(Assembler::Equal, value, Imm32(2), &Ldone);
     masm.branch32(Assembler::Equal, value, Imm32(1), &Ldone);
     masm.move32(Imm32(0), output);
     masm.bind(&Ldone);