Backed out changeset f4592864c982 (bug 1037360) for b2g mochitest-9 failures
authorWes Kocher <wkocher@mozilla.com>
Tue, 15 Jul 2014 15:45:38 -0700
changeset 216183 472e3405d85182be99fc4abdfb422c5c463b7221
parent 216182 3a419b592089220260b1b98a8188a6a975611ff1
child 216184 28dfed91343651e9958183f4ba9a88037f09985e
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1037360
milestone33.0a1
backs outf4592864c9828ef3e7be37b42c8f19d2ab8abffe
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 f4592864c982 (bug 1037360) for b2g mochitest-9 failures
gfx/layers/ipc/SharedBufferManagerParent.cpp
gfx/layers/ipc/SharedBufferManagerParent.h
gfx/layers/opengl/GrallocTextureHost.cpp
--- a/gfx/layers/ipc/SharedBufferManagerParent.cpp
+++ b/gfx/layers/ipc/SharedBufferManagerParent.cpp
@@ -9,17 +9,16 @@
 #include "base/process.h"               // for ProcessHandle
 #include "base/process_util.h"          // for OpenProcessHandle
 #include "base/task.h"                  // for CancelableTask, DeleteTask, etc
 #include "base/tracked.h"               // for FROM_HERE
 #include "base/thread.h"
 #include "mozilla/ipc/MessageChannel.h" // for MessageChannel, etc
 #include "mozilla/ipc/ProtocolUtils.h"
 #include "mozilla/ipc/Transport.h"      // for Transport
-#include "mozilla/UniquePtr.h"          // for UniquePtr
 #include "nsIMemoryReporter.h"
 #ifdef MOZ_WIDGET_GONK
 #include "ui/PixelFormat.h"
 #endif
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
 
 using namespace mozilla::ipc;
@@ -47,17 +46,17 @@ public:
     if (SharedBufferManagerParent::sManagerMonitor) {
       SharedBufferManagerParent::sManagerMonitor->Lock();
     }
     map<base::ProcessId, SharedBufferManagerParent*>::iterator it;
     for (it = SharedBufferManagerParent::sManagers.begin(); it != SharedBufferManagerParent::sManagers.end(); it++) {
       base::ProcessId pid = it->first;
       SharedBufferManagerParent *mgr = it->second;
 
-      MutexAutoLock lock(mgr->mLock);
+      MutexAutoLock lock(mgr->mBuffersMutex);
       std::map<int64_t, android::sp<android::GraphicBuffer> >::iterator buf_it;
       for (buf_it = mgr->mBuffers.begin(); buf_it != mgr->mBuffers.end(); buf_it++) {
         nsresult rv;
         android::sp<android::GraphicBuffer> gb = buf_it->second;
         int bpp = android::bytesPerPixel(gb->getPixelFormat());
         int stride = gb->getStride();
         int height = gb->getHeight();
         int amount = bpp > 0
@@ -97,35 +96,22 @@ NS_IMPL_ISUPPORTS(GrallocReporter, nsIMe
 
 void InitGralloc() {
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 #ifdef MOZ_WIDGET_GONK
   RegisterStrongMemoryReporter(new GrallocReporter());
 #endif
 }
 
-/**
- * Task that deletes SharedBufferManagerParent on a specified thread.
- */
-class DeleteSharedBufferManagerParentTask : public Task
-{
-public:
-    DeleteSharedBufferManagerParentTask(UniquePtr<SharedBufferManagerParent> aSharedBufferManager)
-        : mSharedBufferManager(Move(aSharedBufferManager)) {
-    }
-    virtual void Run() MOZ_OVERRIDE {}
-private:
-    UniquePtr<SharedBufferManagerParent> mSharedBufferManager;
-};
-
 SharedBufferManagerParent::SharedBufferManagerParent(Transport* aTransport, base::ProcessId aOwner, base::Thread* aThread)
   : mTransport(aTransport)
   , mThread(aThread)
-  , mDestroyed(false)
-  , mLock("SharedBufferManagerParent.mLock")
+#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
+  , mBuffersMutex("BuffersMonitor")
+#endif
 {
   if (!sManagerMonitor) {
     sManagerMonitor = new Monitor("Manager Monitor");
   }
 
   MonitorAutoLock lock(*sManagerMonitor.get());
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread");
   if (!aThread->IsRunning()) {
@@ -148,24 +134,20 @@ SharedBufferManagerParent::~SharedBuffer
   }
   sManagers.erase(mOwner);
   delete mThread;
 }
 
 void
 SharedBufferManagerParent::ActorDestroy(ActorDestroyReason aWhy)
 {
-  MutexAutoLock lock(mLock);
-  mDestroyed = true;
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
+  MutexAutoLock lock(mBuffersMutex);
   mBuffers.clear();
 #endif
-  DeleteSharedBufferManagerParentTask* task =
-    new DeleteSharedBufferManagerParentTask(UniquePtr<SharedBufferManagerParent>(this));
-  XRE_GetIOMessageLoop()->PostTask(FROM_HERE, task);
 }
 
 static void
 ConnectSharedBufferManagerInParentProcess(SharedBufferManagerParent* aManager,
                                           Transport* aTransport,
                                           base::ProcessHandle aOtherProcess)
 {
   aManager->Open(aTransport, aOtherProcess, XRE_GetIOMessageLoop(), ipc::ParentSide);
@@ -224,83 +206,67 @@ bool SharedBufferManagerParent::RecvAllo
     bufferKey = ++sBufferKey; 
   }
   GrallocBufferRef ref;
   ref.mOwner = mOwner;
   ref.mKey = bufferKey;
   *aHandle = MagicGrallocBufferHandle(outgoingBuffer, ref);
 
   {
-    MutexAutoLock lock(mLock);
+    MutexAutoLock lock(mBuffersMutex);
     mBuffers[bufferKey] = outgoingBuffer;
   }
 #endif
   return true;
 }
 
 bool SharedBufferManagerParent::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle)
 {
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
   NS_ASSERTION(handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef, "We shouldn't interact with the real buffer!");
   int64_t bufferKey = handle.get_GrallocBufferRef().mKey;
   sp<GraphicBuffer> buf = GetGraphicBuffer(bufferKey);
   MOZ_ASSERT(buf.get());
-  MutexAutoLock lock(mLock);
+  MutexAutoLock lock(mBuffersMutex);
   NS_ASSERTION(mBuffers.count(bufferKey) == 1, "No such buffer");
   mBuffers.erase(bufferKey);
 
   if(!buf.get()) {
     printf_stderr("SharedBufferManagerParent::RecvDropGrallocBuffer -- invalid buffer key.");
     return true;
   }
 
 #endif
   return true;
 }
 
-/*static*/
 void SharedBufferManagerParent::DropGrallocBufferSync(SharedBufferManagerParent* mgr, mozilla::layers::SurfaceDescriptor aDesc)
 {
   mgr->DropGrallocBufferImpl(aDesc);
 }
 
-/*static*/
-void SharedBufferManagerParent::DropGrallocBuffer(ProcessId id, mozilla::layers::SurfaceDescriptor aDesc)
+void SharedBufferManagerParent::DropGrallocBuffer(mozilla::layers::SurfaceDescriptor aDesc)
 {
   if (aDesc.type() != SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
     return;
   }
 
-  MonitorAutoLock lock(*sManagerMonitor.get());
-  SharedBufferManagerParent* mgr = SharedBufferManagerParent::GetInstance(id);
-  if (!mgr) {
-    return;
-  }
-
-  MutexAutoLock mgrlock(mgr->mLock);
-  if (mgr->mDestroyed) {
-    return;
-  }
-
-  if (PlatformThread::CurrentId() == mgr->mThread->thread_id()) {
-    MOZ_CRASH("SharedBufferManagerParent::DropGrallocBuffer should not be called on SharedBufferManagerParent thread");
+  if (PlatformThread::CurrentId() == mThread->thread_id()) {
+    DropGrallocBufferImpl(aDesc);
   } else {
-    mgr->mThread->message_loop()->PostTask(FROM_HERE,
-                                      NewRunnableFunction(&DropGrallocBufferSync, mgr, aDesc));
+    mThread->message_loop()->PostTask(FROM_HERE,
+                                      NewRunnableFunction(&DropGrallocBufferSync, this, aDesc));
   }
   return;
 }
 
 void SharedBufferManagerParent::DropGrallocBufferImpl(mozilla::layers::SurfaceDescriptor aDesc)
 {
-  MutexAutoLock lock(mLock);
-  if (mDestroyed) {
-    return;
-  }
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
+  MutexAutoLock lock(mBuffersMutex);
   int64_t key = -1;
   MaybeMagicGrallocBufferHandle handle;
   if (aDesc.type() == SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
     handle = aDesc.get_NewSurfaceDescriptorGralloc().buffer();
   } else {
     return;
   }
 
@@ -319,38 +285,38 @@ void SharedBufferManagerParent::DropGral
 
 MessageLoop* SharedBufferManagerParent::GetMessageLoop()
 {
   return mThread->message_loop();
 }
 
 SharedBufferManagerParent* SharedBufferManagerParent::GetInstance(ProcessId id)
 {
+  MonitorAutoLock lock(*sManagerMonitor.get());
   NS_ASSERTION(sManagers.count(id) == 1, "No BufferManager for the process");
   return sManagers[id];
 }
 
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
 android::sp<android::GraphicBuffer>
 SharedBufferManagerParent::GetGraphicBuffer(int64_t key)
 {
-  MutexAutoLock lock(mLock);
+  MutexAutoLock lock(mBuffersMutex);
   if (mBuffers.count(key) == 1) {
     return mBuffers[key];
   } else {
     // The buffer can be dropped, or invalid
     printf_stderr("SharedBufferManagerParent::GetGraphicBuffer -- invalid key");
     return nullptr;
   }
 }
 
 android::sp<android::GraphicBuffer>
 SharedBufferManagerParent::GetGraphicBuffer(GrallocBufferRef aRef)
 {
-  MonitorAutoLock lock(*sManagerMonitor.get());
   return GetInstance(aRef.mOwner)->GetGraphicBuffer(aRef.mKey);
 }
 #endif
 
 IToplevelProtocol*
 SharedBufferManagerParent::CloneToplevel(const InfallibleTArray<ProtocolFdMapping>& aFds,
                                  base::ProcessHandle aPeerProcess,
                                  mozilla::ipc::ProtocolCloneContext* aCtx)
--- a/gfx/layers/ipc/SharedBufferManagerParent.h
+++ b/gfx/layers/ipc/SharedBufferManagerParent.h
@@ -35,16 +35,21 @@ class SharedBufferManagerParent : public
 {
 friend class GrallocReporter;
 public:
   /**
    * Create a SharedBufferManagerParent for child process, and link to the child side before leaving
    */
   static PSharedBufferManagerParent* Create(Transport* aTransport, ProcessId aOtherProcess);
 
+  /**
+   * Function for find the buffer owner, most buffer passing on IPC contains only owner/key pair.
+   * Use these function to access the real buffer.
+   */
+  static SharedBufferManagerParent* GetInstance(ProcessId id);
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
   android::sp<android::GraphicBuffer> GetGraphicBuffer(int64_t key);
   static android::sp<android::GraphicBuffer> GetGraphicBuffer(GrallocBufferRef aRef);
 #endif
   /**
    * Create a SharedBufferManagerParent but do not open the link
    */
   SharedBufferManagerParent(Transport* aTransport, ProcessId aOwner, base::Thread* aThread);
@@ -56,61 +61,52 @@ public:
   virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
   virtual bool RecvAllocateGrallocBuffer(const IntSize&, const uint32_t&, const uint32_t&, mozilla::layers::MaybeMagicGrallocBufferHandle*);
   virtual bool RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle);
 
   /**
    * Break the buffer's sharing state, decrease buffer reference for both side
    */
-  static void DropGrallocBuffer(ProcessId id, mozilla::layers::SurfaceDescriptor aDesc);
+  void DropGrallocBuffer(mozilla::layers::SurfaceDescriptor aDesc);
 
   // Overriden from IToplevelProtocol
   IToplevelProtocol*
   CloneToplevel(const InfallibleTArray<ProtocolFdMapping>& aFds,
                 base::ProcessHandle aPeerProcess,
                 mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
   MessageLoop* GetMessageLoop();
 
 protected:
+  /**
+   * All living SharedBufferManager instances used to find the buffer owner, and parent->child IPCs
+   */
+  static std::map<base::ProcessId, SharedBufferManagerParent*> sManagers;
 
   /**
    * Break the buffer's sharing state, decrease buffer reference for both side
    *
    * Must be called from SharedBufferManagerParent's thread
    */
   void DropGrallocBufferImpl(mozilla::layers::SurfaceDescriptor aDesc);
 
   // dispatched function
   static void DropGrallocBufferSync(SharedBufferManagerParent* mgr, mozilla::layers::SurfaceDescriptor aDesc);
 
-  /**
-   * Function for find the buffer owner, most buffer passing on IPC contains only owner/key pair.
-   * Use these function to access the real buffer.
-   * Caller needs to hold sManagerMonitor.
-   */
-  static SharedBufferManagerParent* GetInstance(ProcessId id);
-
-  /**
-   * All living SharedBufferManager instances used to find the buffer owner, and parent->child IPCs
-   */
-  static std::map<base::ProcessId, SharedBufferManagerParent*> sManagers;
-
 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
   /**
    * Buffers owned by this SharedBufferManager pair
    */
   std::map<int64_t, android::sp<android::GraphicBuffer> > mBuffers;
+  Mutex mBuffersMutex;
 #endif
   
   Transport* mTransport;
   base::ProcessId mOwner;
   base::Thread* mThread;
-  bool mDestroyed;
-  Mutex mLock;
+  static uint64_t sBufferKey;
 
-  static uint64_t sBufferKey;
   static StaticAutoPtr<Monitor> sManagerMonitor;
 };
 
 } /* namespace layers */
 } /* namespace mozilla */
 #endif /* SharedBufferManagerPARENT_H_ */
--- a/gfx/layers/opengl/GrallocTextureHost.cpp
+++ b/gfx/layers/opengl/GrallocTextureHost.cpp
@@ -378,17 +378,17 @@ GrallocTextureHostOGL::DeallocateSharedD
     base::ProcessId owner;
     if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
       owner = handle.get_GrallocBufferRef().mOwner;
     }
     else {
       owner = handle.get_MagicGrallocBufferHandle().mRef.mOwner;
     }
 
-    SharedBufferManagerParent::DropGrallocBuffer(owner, mGrallocHandle);
+    SharedBufferManagerParent::GetInstance(owner)->DropGrallocBuffer(mGrallocHandle);
   }
 }
 
 void
 GrallocTextureHostOGL::ForgetSharedData()
 {
   if (mTextureSource) {
     mTextureSource->ForgetBuffer();