Bug 1527974: Use non-shared memmove in self-hosting intrinsics when possible. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 08 Mar 2019 13:23:12 +0000
changeset 521214 835fc236080c725919da936a1719b4e0bf541131
parent 521213 8feadb1f48f21d9a024f3dec274f0c8e4cd7d26d
child 521215 3e43e15218d95eecc53546fe299373826cc66aaa
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1527974
milestone67.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 1527974: Use non-shared memmove in self-hosting intrinsics when possible. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D22508
js/src/vm/SelfHosting.cpp
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -1232,18 +1232,23 @@ static bool intrinsic_MoveTypedArrayElem
     MOZ_ASSERT(byteDest < viewByteLength);
     MOZ_ASSERT(byteSrc < viewByteLength);
     MOZ_ASSERT(byteDest <= viewByteLength - byteSize);
     MOZ_ASSERT(byteSrc <= viewByteLength - byteSize);
   }
 #endif
 
   SharedMem<uint8_t*> data = tarray->dataPointerEither().cast<uint8_t*>();
-  jit::AtomicOperations::memmoveSafeWhenRacy(data + byteDest, data + byteSrc,
-                                             byteSize);
+  if (tarray->isSharedMemory()) {
+    jit::AtomicOperations::memmoveSafeWhenRacy(data + byteDest, data + byteSrc,
+                                               byteSize);
+  } else {
+    memmove(data.unwrapUnshared() + byteDest, data.unwrapUnshared() + byteSrc,
+            byteSize);
+  }
 
   args.rval().setUndefined();
   return true;
 }
 
 // Extract the TypedArrayObject* underlying |obj| and return it.  This method,
 // in a TOTALLY UNSAFE manner, completely violates the normal compartment
 // boundaries, returning an object not necessarily in the current compartment
@@ -1698,18 +1703,24 @@ static bool intrinsic_TypedArrayBitwiseS
   // The same-type case requires exact copying preserving the bit-level
   // encoding of the source data, so use memcpy if possible. If source and
   // target are the same buffer, we can't use memcpy (or memmove), because
   // the specification requires sequential copying of the values. This case
   // is only possible if a @@species constructor created a specifically
   // crafted typed array. It won't happen in normal code and hence doesn't
   // need to be optimized.
   if (!TypedArrayObject::sameBuffer(source, unsafeTypedArrayCrossCompartment)) {
-    jit::AtomicOperations::memcpySafeWhenRacy(unsafeTargetDataCrossCompartment,
-                                              sourceData, byteLength);
+    if (source->isSharedMemory() ||
+        unsafeTypedArrayCrossCompartment->isSharedMemory()) {
+      jit::AtomicOperations::memcpySafeWhenRacy(
+          unsafeTargetDataCrossCompartment, sourceData, byteLength);
+    } else {
+      memcpy(unsafeTargetDataCrossCompartment.unwrapUnshared(),
+             sourceData.unwrapUnshared(), byteLength);
+    }
   } else {
     using namespace jit;
 
     for (; byteLength > 0; byteLength--) {
       AtomicOperations::storeSafeWhenRacy(
           unsafeTargetDataCrossCompartment++,
           AtomicOperations::loadSafeWhenRacy(sourceData++));
     }