Bug 1529298 - Remove the |newContents| argument from ArrayBufferObject::detach that's now identical for every caller. r=sfink
authorJeff Walden <jwalden@mit.edu>
Wed, 20 Feb 2019 13:51:58 -0800
changeset 461627 ab967077f8a309b0d383297d071cd8397a100f7c
parent 461626 973c3800d5d6c10e06ce653add01316f9b0ee25e
child 461628 9103748036d1d9f72d34474014c9ce0267271eb5
push id35626
push usercsabou@mozilla.com
push dateThu, 28 Feb 2019 11:31:08 +0000
treeherdermozilla-central@2ea0c1db7e60 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1529298
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 1529298 - Remove the |newContents| argument from ArrayBufferObject::detach that's now identical for every caller. r=sfink
js/src/vm/ArrayBufferObject.cpp
js/src/vm/ArrayBufferObject.h
js/src/vm/ArrayBufferViewObject.cpp
js/src/vm/ArrayBufferViewObject.h
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -459,18 +459,17 @@ static uint8_t* NewCopiedBufferContents(
     if (auto count = buffer->byteLength()) {
       memcpy(dataCopy, buffer->dataPointer(), count);
     }
   }
   return dataCopy;
 }
 
 /* static */ void ArrayBufferObject::detach(JSContext* cx,
-                                            Handle<ArrayBufferObject*> buffer,
-                                            BufferContents newContents) {
+                                            Handle<ArrayBufferObject*> buffer) {
   cx->check(buffer);
   MOZ_ASSERT(!buffer->isPreparedForAsmJS());
 
   // When detaching buffers where we don't know all views, the new data must
   // match the old data. All missing views are typed objects, which do not
   // expect their data to ever change.
 
   // When detaching a buffer with typed object views, any jitcode accessing
@@ -484,21 +483,20 @@ static uint8_t* NewCopiedBufferContents(
     if (!JSObject::getGroup(cx, cx->global())) {
       oomUnsafe.crash("ArrayBufferObject::detach");
     }
     MarkObjectGroupFlags(cx, cx->global(),
                          OBJECT_FLAG_TYPED_OBJECT_HAS_DETACHED_BUFFER);
     cx->zone()->detachedTypedObjects = 1;
   }
 
-  auto NoteViewBufferWasDetached = [&cx,
-                                    &newContents](ArrayBufferViewObject* view) {
+  auto NoteViewBufferWasDetached = [&cx](ArrayBufferViewObject* view) {
     MOZ_ASSERT(!view->isSharedMemory());
 
-    view->notifyBufferDetached(newContents.data());
+    view->notifyBufferDetached();
 
     // Notify compiled jit code that the base pointer has moved.
     MarkObjectStateChange(cx, view);
   };
 
   // Update all views of the buffer to account for the buffer having been
   // detached, and clear the buffer's data and list of views.
   //
@@ -513,18 +511,19 @@ static uint8_t* NewCopiedBufferContents(
     }
     innerViews.removeViews(buffer);
   }
   if (JSObject* view = buffer->firstView()) {
     NoteViewBufferWasDetached(&view->as<ArrayBufferViewObject>());
     buffer->setFirstView(nullptr);
   }
 
-  if (newContents.data() != buffer->dataPointer()) {
-    buffer->setNewData(cx->runtime()->defaultFreeOp(), newContents);
+  if (buffer->dataPointer()) {
+    buffer->setNewData(cx->runtime()->defaultFreeOp(),
+                       BufferContents::createNoData());
   }
 
   buffer->setByteLength(0);
   buffer->setIsDetached();
 }
 
 void ArrayBufferObject::setNewData(FreeOp* fop, BufferContents newContents) {
   // XXX All callers of this check are changing data pointer, so this assertion
@@ -1069,21 +1068,20 @@ static void CheckStealPreconditions(Hand
                                                           newSize)) {
     return false;
   }
 
   // Extract the grown contents from |oldBuf|.
   BufferContents oldContents = oldBuf->contents();
 
   // Overwrite |oldBuf|'s data pointer *without* releasing old data.
-  BufferContents detachedContents = BufferContents::createNoData();
-  oldBuf->setDataPointer(detachedContents);
+  oldBuf->setDataPointer(BufferContents::createNoData());
 
   // Detach |oldBuf| now that doing so won't release |oldContents|.
-  ArrayBufferObject::detach(cx, oldBuf, detachedContents);
+  ArrayBufferObject::detach(cx, oldBuf);
 
   // Set |newBuf|'s contents to |oldBuf|'s original contents.
   newBuf->initialize(newSize, oldContents);
   return true;
 }
 
 #ifndef WASM_HUGE_MEMORY
 /* static */ bool ArrayBufferObject::wasmMovingGrowToSize(
@@ -1112,17 +1110,17 @@ static void CheckStealPreconditions(Hand
   if (!newRawBuf) {
     return false;
   }
   BufferContents contents =
       BufferContents::createWasm(newRawBuf->dataPointer());
   newBuf->initialize(newSize, contents);
 
   memcpy(newBuf->dataPointer(), oldBuf->dataPointer(), oldBuf->byteLength());
-  ArrayBufferObject::detach(cx, oldBuf, BufferContents::createNoData());
+  ArrayBufferObject::detach(cx, oldBuf);
   return true;
 }
 
 uint32_t ArrayBufferObject::wasmBoundsCheckLimit() const {
   if (isWasm()) {
     return contents().wasmBuffer()->boundsCheckLimit();
   }
   return byteLength();
@@ -1319,38 +1317,37 @@ ArrayBufferObject* ArrayBufferObject::cr
 
   switch (buffer->bufferKind()) {
     case MALLOCED: {
       uint8_t* stolenData = buffer->dataPointer();
       MOZ_ASSERT(stolenData);
 
       // Overwrite the old data pointer *without* releasing the contents
       // being stolen.
-      BufferContents newContents = BufferContents::createNoData();
-      buffer->setDataPointer(newContents);
+      buffer->setDataPointer(BufferContents::createNoData());
 
       // Detach |buffer| now that doing so won't free |stolenData|.
-      ArrayBufferObject::detach(cx, buffer, newContents);
+      ArrayBufferObject::detach(cx, buffer);
       return stolenData;
     }
 
     case INLINE_DATA:
     case NO_DATA:
     case USER_OWNED:
     case MAPPED:
     case EXTERNAL: {
       // We can't use these data types directly.  Make a copy to return.
       uint8_t* copiedData = NewCopiedBufferContents(cx, buffer);
       if (!copiedData) {
         return nullptr;
       }
 
       // Detach |buffer|.  This immediately releases the currently owned
       // contents, freeing or unmapping data in the MAPPED and EXTERNAL cases.
-      ArrayBufferObject::detach(cx, buffer, BufferContents::createNoData());
+      ArrayBufferObject::detach(cx, buffer);
       return copiedData;
     }
 
     case WASM:
       MOZ_ASSERT_UNREACHABLE(
           "wasm buffers aren't stealable except by a "
           "memory.grow operation that shouldn't call this "
           "function");
@@ -1376,30 +1373,29 @@ ArrayBufferObject::extractStructuredClon
     case INLINE_DATA:
     case NO_DATA:
     case USER_OWNED: {
       uint8_t* copiedData = NewCopiedBufferContents(cx, buffer);
       if (!copiedData) {
         return BufferContents::createFailed();
       }
 
-      ArrayBufferObject::detach(cx, buffer, BufferContents::createNoData());
+      ArrayBufferObject::detach(cx, buffer);
       return BufferContents::createMalloced(copiedData);
     }
 
     case MALLOCED:
     case MAPPED: {
       MOZ_ASSERT(contents);
 
       // Overwrite the old data pointer *without* releasing old data.
-      BufferContents newContents = BufferContents::createNoData();
-      buffer->setDataPointer(newContents);
+      buffer->setDataPointer(BufferContents::createNoData());
 
       // Detach |buffer| now that doing so won't release |oldContents|.
-      ArrayBufferObject::detach(cx, buffer, newContents);
+      ArrayBufferObject::detach(cx, buffer);
       return contents;
     }
 
     case WASM:
       JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                                 JSMSG_WASM_NO_TRANSFER);
       return BufferContents::createFailed();
 
@@ -1679,18 +1675,17 @@ JS_FRIEND_API bool JS_DetachArrayBuffer(
   Rooted<ArrayBufferObject*> buffer(cx, &obj->as<ArrayBufferObject>());
 
   if (buffer->isWasm() || buffer->isPreparedForAsmJS()) {
     JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                               JSMSG_WASM_NO_TRANSFER);
     return false;
   }
 
-  ArrayBufferObject::detach(cx, buffer,
-                            ArrayBufferObject::BufferContents::createNoData());
+  ArrayBufferObject::detach(cx, buffer);
   return true;
 }
 
 JS_FRIEND_API bool JS_IsDetachedArrayBufferObject(JSObject* obj) {
   ArrayBufferObject* aobj = obj->maybeUnwrapIf<ArrayBufferObject>();
   if (!aobj) {
     return false;
   }
--- a/js/src/vm/ArrayBufferObject.h
+++ b/js/src/vm/ArrayBufferObject.h
@@ -357,18 +357,17 @@ class ArrayBufferObject : public ArrayBu
   JSObject* firstView();
 
   bool addView(JSContext* cx, JSObject* view);
 
   void setNewData(FreeOp* fop, BufferContents newContents);
 
   // Detach this buffer from its original memory.  (This necessarily makes
   // views of this buffer unusable for modifying that original memory.)
-  static void detach(JSContext* cx, Handle<ArrayBufferObject*> buffer,
-                     BufferContents newContents);
+  static void detach(JSContext* cx, Handle<ArrayBufferObject*> buffer);
 
  private:
   void setFirstView(JSObject* view);
 
   uint8_t* inlineDataPointer() const;
 
   struct FreeInfo {
     JS::BufferContentsFreeFunc freeFunc;
--- a/js/src/vm/ArrayBufferViewObject.cpp
+++ b/js/src/vm/ArrayBufferViewObject.cpp
@@ -47,24 +47,24 @@ using namespace js;
   }
 }
 
 template <>
 bool JSObject::is<js::ArrayBufferViewObject>() const {
   return is<DataViewObject>() || is<TypedArrayObject>();
 }
 
-void ArrayBufferViewObject::notifyBufferDetached(void* newData) {
+void ArrayBufferViewObject::notifyBufferDetached() {
   MOZ_ASSERT(!isSharedMemory());
   MOZ_ASSERT(hasBuffer());
 
   setFixedSlot(LENGTH_SLOT, Int32Value(0));
   setFixedSlot(BYTEOFFSET_SLOT, Int32Value(0));
 
-  setPrivate(newData);
+  setPrivate(nullptr);
 }
 
 uint8_t* ArrayBufferViewObject::dataPointerUnshared(
     const JS::AutoRequireNoGC& nogc) {
   return static_cast<uint8_t*>(dataPointerUnshared());
 }
 
 void ArrayBufferViewObject::setDataPointerUnshared(uint8_t* data) {
--- a/js/src/vm/ArrayBufferViewObject.h
+++ b/js/src/vm/ArrayBufferViewObject.h
@@ -64,17 +64,17 @@ class ArrayBufferViewObject : public Nat
  public:
   MOZ_MUST_USE bool init(JSContext* cx, ArrayBufferObjectMaybeShared* buffer,
                          uint32_t byteOffset, uint32_t length,
                          uint32_t bytesPerElement);
 
   static ArrayBufferObjectMaybeShared* bufferObject(
       JSContext* cx, Handle<ArrayBufferViewObject*> obj);
 
-  void notifyBufferDetached(void* newData);
+  void notifyBufferDetached();
 
   // By construction we only need unshared variants here.  See
   // comments in ArrayBufferObject.cpp.
   uint8_t* dataPointerUnshared(const JS::AutoRequireNoGC&);
   void setDataPointerUnshared(uint8_t* data);
 
   void initDataPointer(SharedMem<uint8_t*> viewData) {
     // Install a pointer to the buffer location that corresponds