Backed out changeset 5988716b66bb (bug 1397128)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 15 Sep 2017 18:28:37 +0200
changeset 381114 b1630c159759298a39b7a33397832c458d28ab9f
parent 381113 852e0b52c84f041880f1ed404be20d6c8022977f
child 381115 0241711c57ebe826345fc38ee5e695ff301c24b8
push id95055
push userarchaeopteryx@coole-files.de
push dateFri, 15 Sep 2017 16:29:58 +0000
treeherdermozilla-inbound@ee4c8b6d9a08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1397128
milestone57.0a1
backs out5988716b66bba7ad38f8fe0cc7956d2120569ee5
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
Backed out changeset 5988716b66bb (bug 1397128)
dom/cache/ReadStream.cpp
--- a/dom/cache/ReadStream.cpp
+++ b/dom/cache/ReadStream.cpp
@@ -8,17 +8,16 @@
 
 #include "mozilla/Unused.h"
 #include "mozilla/dom/cache/CacheStreamControlChild.h"
 #include "mozilla/dom/cache/CacheStreamControlParent.h"
 #include "mozilla/dom/cache/CacheTypes.h"
 #include "mozilla/ipc/IPCStreamUtils.h"
 #include "mozilla/SnappyUncompressInputStream.h"
 #include "nsIAsyncInputStream.h"
-#include "nsStringStream.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 namespace dom {
 namespace cache {
 
 using mozilla::Unused;
 using mozilla::ipc::AutoIPCStream;
@@ -88,28 +87,16 @@ private:
   Forget();
 
   void
   NoteClosedOnOwningThread();
 
   void
   ForgetOnOwningThread();
 
-  nsIInputStream*
-  EnsureStream();
-
-  void
-  AsyncOpenStreamOnOwningThread();
-
-  void
-  MaybeAbortAsyncOpenStream();
-
-  void
-  OpenStreamFailed();
-
   // Weak ref to the stream control actor.  The actor will always call either
   // CloseStream() or CloseStreamWithoutReporting() before it's destroyed.  The
   // weak ref is cleared in the resulting NoteClosedOnOwningThread() or
   // ForgetOnOwningThread() method call.
   StreamControl* mControl;
 
   const nsID mId;
   nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
@@ -117,24 +104,23 @@ private:
   enum State
   {
     Open,
     Closed,
     NumStates
   };
   Atomic<State> mState;
   Atomic<bool> mHasEverBeenRead;
-  bool mAsyncOpenStarted;
+
 
   // The wrapped stream objects may not be threadsafe.  We need to be able
   // to close a stream on our owning thread while an IO thread is simultaneously
   // reading the same stream.  Therefore, protect all access to these stream
   // objects with a mutex.
   Mutex mMutex;
-  CondVar mCondVar;
   nsCOMPtr<nsIInputStream> mStream;
   nsCOMPtr<nsIInputStream> mSnappyStream;
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(cache::ReadStream::Inner, override)
 };
 
 // ----------------------------------------------------------------------------
 
@@ -211,19 +197,17 @@ private:
 
 ReadStream::Inner::Inner(StreamControl* aControl, const nsID& aId,
                          nsIInputStream* aStream)
   : mControl(aControl)
   , mId(aId)
   , mOwningEventTarget(GetCurrentThreadSerialEventTarget())
   , mState(Open)
   , mHasEverBeenRead(false)
-  , mAsyncOpenStarted(false)
   , mMutex("dom::cache::ReadStream")
-  , mCondVar(mMutex, "dom::cache::ReadStream")
   , mStream(aStream)
   , mSnappyStream(new SnappyUncompressInputStream(aStream))
 {
   MOZ_DIAGNOSTIC_ASSERT(mStream);
   MOZ_DIAGNOSTIC_ASSERT(mControl);
   mControl->AddReadStream(this);
 }
 
@@ -299,32 +283,30 @@ ReadStream::Inner::HasEverBeenRead() con
 
 nsresult
 ReadStream::Inner::Close()
 {
   // stream ops can happen on any thread
   nsresult rv = NS_OK;
   {
     MutexAutoLock lock(mMutex);
-    if (mSnappyStream) {
-      rv = mSnappyStream->Close();
-    }
+    rv = mSnappyStream->Close();
   }
   NoteClosed();
   return rv;
 }
 
 nsresult
 ReadStream::Inner::Available(uint64_t* aNumAvailableOut)
 {
   // stream ops can happen on any thread
   nsresult rv = NS_OK;
   {
     MutexAutoLock lock(mMutex);
-    rv = EnsureStream()->Available(aNumAvailableOut);
+    rv = mSnappyStream->Available(aNumAvailableOut);
   }
 
   if (NS_FAILED(rv)) {
     Close();
   }
 
   return rv;
 }
@@ -333,17 +315,17 @@ nsresult
 ReadStream::Inner::Read(char* aBuf, uint32_t aCount, uint32_t* aNumReadOut)
 {
   // stream ops can happen on any thread
   MOZ_DIAGNOSTIC_ASSERT(aNumReadOut);
 
   nsresult rv = NS_OK;
   {
     MutexAutoLock lock(mMutex);
-    rv = EnsureStream()->Read(aBuf, aCount, aNumReadOut);
+    rv = mSnappyStream->Read(aBuf, aCount, aNumReadOut);
   }
 
   if ((NS_FAILED(rv) && rv != NS_BASE_STREAM_WOULD_BLOCK) ||
       *aNumReadOut == 0) {
     Close();
   }
 
   mHasEverBeenRead = true;
@@ -361,17 +343,17 @@ ReadStream::Inner::ReadSegments(nsWriteS
   if (aCount) {
     mHasEverBeenRead = true;
   }
 
 
   nsresult rv = NS_OK;
   {
     MutexAutoLock lock(mMutex);
-    rv = EnsureStream()->ReadSegments(aWriter, aClosure, aCount, aNumReadOut);
+    rv = mSnappyStream->ReadSegments(aWriter, aClosure, aCount, aNumReadOut);
   }
 
   if ((NS_FAILED(rv) && rv != NS_BASE_STREAM_WOULD_BLOCK &&
                         rv != NS_ERROR_NOT_IMPLEMENTED) || *aNumReadOut == 0) {
     Close();
   }
 
   // Verify bytes were actually read before marking as being ever read.  For
@@ -385,21 +367,17 @@ ReadStream::Inner::ReadSegments(nsWriteS
   return rv;
 }
 
 nsresult
 ReadStream::Inner::IsNonBlocking(bool* aNonBlockingOut)
 {
   // stream ops can happen on any thread
   MutexAutoLock lock(mMutex);
-  if (mSnappyStream) {
-    return mSnappyStream->IsNonBlocking(aNonBlockingOut);
-  }
-  *aNonBlockingOut = false;
-  return NS_OK;
+  return mSnappyStream->IsNonBlocking(aNonBlockingOut);
 }
 
 ReadStream::Inner::~Inner()
 {
   // Any thread
   MOZ_DIAGNOSTIC_ASSERT(mState == Closed);
   MOZ_DIAGNOSTIC_ASSERT(!mControl);
 }
@@ -445,131 +423,36 @@ ReadStream::Inner::NoteClosedOnOwningThr
 {
   MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
 
   // Mark closed and do nothing if we were already closed
   if (!mState.compareExchange(Open, Closed)) {
     return;
   }
 
-  MaybeAbortAsyncOpenStream();
-
   MOZ_DIAGNOSTIC_ASSERT(mControl);
   mControl->NoteClosed(this, mId);
   mControl = nullptr;
 }
 
 void
 ReadStream::Inner::ForgetOnOwningThread()
 {
   MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
 
   // Mark closed and do nothing if we were already closed
   if (!mState.compareExchange(Open, Closed)) {
     return;
   }
 
-  MaybeAbortAsyncOpenStream();
-
   MOZ_DIAGNOSTIC_ASSERT(mControl);
   mControl->ForgetReadStream(this);
   mControl = nullptr;
 }
 
-nsIInputStream*
-ReadStream::Inner::EnsureStream()
-{
-  mMutex.AssertCurrentThreadOwns();
-
-  // We need to block the current thread while we open the stream.  We
-  // cannot do this safely from the main owning thread since it would
-  // trigger deadlock.  This should be ok, though, since a blocking
-  // stream like this should never be read on the owning thread anyway.
-  if (mOwningEventTarget->IsOnCurrentThread()) {
-    MOZ_CRASH("Blocking read on the js/ipc owning thread!");
-  }
-
-  if (mSnappyStream) {
-    return mSnappyStream;
-  }
-
-  nsCOMPtr<nsIRunnable> r =
-    NewCancelableRunnableMethod("ReadStream::Inner::AsyncOpenStreamOnOwningThread",
-                                this,
-                                &ReadStream::Inner::AsyncOpenStreamOnOwningThread);
-  nsresult rv = mOwningEventTarget->Dispatch(r.forget(),
-                                             nsIThread::DISPATCH_NORMAL);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    OpenStreamFailed();
-    return mSnappyStream;
-  }
-
-  mCondVar.Wait();
-  MOZ_DIAGNOSTIC_ASSERT(mSnappyStream);
-
-  return mSnappyStream;
-}
-
-void
-ReadStream::Inner::AsyncOpenStreamOnOwningThread()
-{
-  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
-
-  if (!mControl || mState == Closed) {
-    MutexAutoLock lock(mMutex);
-    OpenStreamFailed();
-    mCondVar.NotifyAll();
-    return;
-  }
-
-  if (mAsyncOpenStarted) {
-    return;
-  }
-  mAsyncOpenStarted = true;
-
-  RefPtr<ReadStream::Inner> self = this;
-  mControl->OpenStream(mId, [self](nsCOMPtr<nsIInputStream>&& aStream) {
-    MutexAutoLock lock(self->mMutex);
-    self->mAsyncOpenStarted = false;
-    if (!self->mStream) {
-      if (!aStream) {
-        self->OpenStreamFailed();
-      } else {
-        self->mStream = Move(aStream);
-        self->mSnappyStream = new SnappyUncompressInputStream(self->mStream);
-      }
-    }
-    self->mCondVar.NotifyAll();
-  });
-}
-
-void
-ReadStream::Inner::MaybeAbortAsyncOpenStream()
-{
-  if (!mAsyncOpenStarted) {
-    return;
-  }
-
-  MutexAutoLock lock(mMutex);
-  OpenStreamFailed();
-  mCondVar.NotifyAll();
-}
-
-void
-ReadStream::Inner::OpenStreamFailed()
-{
-  MOZ_DIAGNOSTIC_ASSERT(!mStream);
-  MOZ_DIAGNOSTIC_ASSERT(!mSnappyStream);
-  mMutex.AssertCurrentThreadOwns();
-  Unused << NS_NewCStringInputStream(getter_AddRefs(mStream), EmptyCString());
-  mSnappyStream = mStream;
-  mStream->Close();
-  NoteClosed();
-}
-
 // ----------------------------------------------------------------------------
 
 NS_IMPL_ISUPPORTS(cache::ReadStream, nsIInputStream, ReadStream);
 
 // static
 already_AddRefed<ReadStream>
 ReadStream::Create(const CacheReadStreamOrVoid& aReadStreamOrVoid)
 {