Bug 792652 - Stop generating some simple sub-protocol methods (r=dvander)
authorBill McCloskey <billm@mozilla.com>
Mon, 31 Oct 2016 15:08:00 -0700
changeset 351809 1b4e8fdc3b837f16e4867627fc3404d303fa38c1
parent 351808 f6642de5fb7a88dc6c3dff07dc53b748436d13e7
child 351810 5435dcdac9095184247b2f46ca405140d30f6157
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs792652
milestone52.0a1
Bug 792652 - Stop generating some simple sub-protocol methods (r=dvander) This moves some of the generated methods in subprotocols that simply defer to the parent protocol to IProtocol. These methods are still overridden in the toplevel protocol.
ipc/glue/ProtocolUtils.cpp
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/ipc/glue/ProtocolUtils.cpp
+++ b/ipc/glue/ProtocolUtils.cpp
@@ -393,10 +393,67 @@ IProtocol::ReadActor(const IPC::Message*
     if (listener->GetProtocolTypeId() != aProtocolTypeId) {
         MismatchedActorTypeError(aActorDescription);
         return Nothing();
     }
 
     return Some(listener);
 }
 
+int32_t
+IProtocol::Register(IProtocol* aRouted)
+{
+  return Manager()->Register(aRouted);
+}
+
+int32_t
+IProtocol::RegisterID(IProtocol* aRouted, int32_t aId)
+{
+  return Manager()->RegisterID(aRouted, aId);
+}
+
+IProtocol*
+IProtocol::Lookup(int32_t aId)
+{
+  return Manager()->Lookup(aId);
+}
+
+void
+IProtocol::Unregister(int32_t aId)
+{
+  Manager()->Unregister(aId);
+}
+
+Shmem::SharedMemory*
+IProtocol::CreateSharedMemory(size_t aSize,
+                              SharedMemory::SharedMemoryType aType,
+                              bool aUnsafe,
+                              int32_t* aId)
+{
+  return Manager()->CreateSharedMemory(aSize, aType, aUnsafe, aId);
+}
+
+Shmem::SharedMemory*
+IProtocol::LookupSharedMemory(int32_t aId)
+{
+  return Manager()->LookupSharedMemory(aId);
+}
+
+bool
+IProtocol::IsTrackingSharedMemory(Shmem::SharedMemory* aSegment)
+{
+  return Manager()->IsTrackingSharedMemory(aSegment);
+}
+
+bool
+IProtocol::DestroySharedMemory(Shmem& aShmem)
+{
+  return Manager()->DestroySharedMemory(aShmem);
+}
+
+ProcessId
+IProtocol::OtherPid() const
+{
+  return Manager()->OtherPid();
+}
+
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -149,30 +149,30 @@ public:
     };
 
     typedef base::ProcessId ProcessId;
     typedef IPC::Message Message;
     typedef IPC::MessageInfo MessageInfo;
 
     IProtocol() : mManager(nullptr) {}
 
-    virtual int32_t Register(IProtocol*) = 0;
-    virtual int32_t RegisterID(IProtocol*, int32_t) = 0;
-    virtual IProtocol* Lookup(int32_t) = 0;
-    virtual void Unregister(int32_t) = 0;
+    virtual int32_t Register(IProtocol*);
+    virtual int32_t RegisterID(IProtocol*, int32_t);
+    virtual IProtocol* Lookup(int32_t);
+    virtual void Unregister(int32_t);
     virtual void RemoveManagee(int32_t, IProtocol*) = 0;
 
     virtual Shmem::SharedMemory* CreateSharedMemory(
-        size_t, SharedMemory::SharedMemoryType, bool, int32_t*) = 0;
-    virtual Shmem::SharedMemory* LookupSharedMemory(int32_t) = 0;
-    virtual bool IsTrackingSharedMemory(Shmem::SharedMemory*) = 0;
-    virtual bool DestroySharedMemory(Shmem&) = 0;
+        size_t, SharedMemory::SharedMemoryType, bool, int32_t*);
+    virtual Shmem::SharedMemory* LookupSharedMemory(int32_t);
+    virtual bool IsTrackingSharedMemory(Shmem::SharedMemory*);
+    virtual bool DestroySharedMemory(Shmem&);
 
     // XXX odd ducks, acknowledged
-    virtual ProcessId OtherPid() const = 0;
+    virtual ProcessId OtherPid() const;
     virtual MessageChannel* GetIPCChannel() = 0;
 
     virtual void FatalError(const char* const aProtocolName, const char* const aErrorMsg) const = 0;
 
     Maybe<IProtocol*> ReadActor(const IPC::Message* aMessage, PickleIterator* aIter, bool aNullable,
                                 const char* aActorDescription, int32_t aProtocolTypeId);
 
     virtual Result OnMessageReceived(const Message& aMessage) = 0;
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -3611,64 +3611,77 @@ class _GenerateProtocolActorCode(ipdl.as
         typevar = ExprVar('aType')
         unsafevar = ExprVar('aUnsafe')
         protocolbase = Type('ProtocolBase', ptr=1)
         sourcevar = ExprVar('aSource')
         ivar = ExprVar('i')
         kidsvar = ExprVar('kids')
         ithkid = ExprIndex(kidsvar, ivar)
 
-        register = MethodDefn(MethodDecl(
-            p.registerMethod().name,
-            params=[ Decl(protocolbase, routedvar.name) ],
-            ret=_actorIdType(), virtual=1))
-        registerid = MethodDefn(MethodDecl(
-            p.registerIDMethod().name,
-            params=[ Decl(protocolbase, routedvar.name),
-                     Decl(_actorIdType(), idvar.name) ],
-            ret=_actorIdType(),
-            virtual=1))
-        lookup = MethodDefn(MethodDecl(
-            p.lookupIDMethod().name,
-            params=[ Decl(_actorIdType(), idvar.name) ],
-            ret=protocolbase, virtual=1))
-        unregister = MethodDefn(MethodDecl(
-            p.unregisterMethod().name,
-            params=[ Decl(_actorIdType(), idvar.name) ],
-            virtual=1))
-
-        createshmem = MethodDefn(MethodDecl(
-            p.createSharedMemory().name,
-            ret=_rawShmemType(ptr=1),
-            params=[ Decl(Type.SIZE, sizevar.name),
-                     Decl(_shmemTypeType(), typevar.name),
-                     Decl(Type.BOOL, unsafevar.name),
-                     Decl(_shmemIdType(ptr=1), idvar.name) ],
-            virtual=1))
-        lookupshmem = MethodDefn(MethodDecl(
-            p.lookupSharedMemory().name,
-            ret=_rawShmemType(ptr=1),
-            params=[ Decl(_shmemIdType(), idvar.name) ],
-            virtual=1))
-        destroyshmem = MethodDefn(MethodDecl(
-            p.destroySharedMemory().name,
-            ret=Type.BOOL,
-            params=[ Decl(_shmemType(ref=1), shmemvar.name) ],
-            virtual=1))
-        istracking = MethodDefn(MethodDecl(
-            p.isTrackingSharedMemory().name,
-            ret=Type.BOOL,
-            params=[ Decl(_rawShmemType(ptr=1), rawvar.name) ],
-            virtual=1))
-
-        otherpid = MethodDefn(MethodDecl(
-            p.otherPidMethod().name,
-            ret=Type('base::ProcessId'),
-            const=1,
-            virtual=1))
+        methods = []
+
+        if p.decl.type.isToplevel():
+            register = MethodDefn(MethodDecl(
+                p.registerMethod().name,
+                params=[ Decl(protocolbase, routedvar.name) ],
+                ret=_actorIdType(), virtual=1))
+            registerid = MethodDefn(MethodDecl(
+                p.registerIDMethod().name,
+                params=[ Decl(protocolbase, routedvar.name),
+                         Decl(_actorIdType(), idvar.name) ],
+                ret=_actorIdType(),
+                virtual=1))
+            lookup = MethodDefn(MethodDecl(
+                p.lookupIDMethod().name,
+                params=[ Decl(_actorIdType(), idvar.name) ],
+                ret=protocolbase, virtual=1))
+            unregister = MethodDefn(MethodDecl(
+                p.unregisterMethod().name,
+                params=[ Decl(_actorIdType(), idvar.name) ],
+                virtual=1))
+
+            createshmem = MethodDefn(MethodDecl(
+                p.createSharedMemory().name,
+                ret=_rawShmemType(ptr=1),
+                params=[ Decl(Type.SIZE, sizevar.name),
+                         Decl(_shmemTypeType(), typevar.name),
+                         Decl(Type.BOOL, unsafevar.name),
+                         Decl(_shmemIdType(ptr=1), idvar.name) ],
+                virtual=1))
+            lookupshmem = MethodDefn(MethodDecl(
+                p.lookupSharedMemory().name,
+                ret=_rawShmemType(ptr=1),
+                params=[ Decl(_shmemIdType(), idvar.name) ],
+                virtual=1))
+            destroyshmem = MethodDefn(MethodDecl(
+                p.destroySharedMemory().name,
+                ret=Type.BOOL,
+                params=[ Decl(_shmemType(ref=1), shmemvar.name) ],
+                virtual=1))
+            istracking = MethodDefn(MethodDecl(
+                p.isTrackingSharedMemory().name,
+                ret=Type.BOOL,
+                params=[ Decl(_rawShmemType(ptr=1), rawvar.name) ],
+                virtual=1))
+
+            otherpid = MethodDefn(MethodDecl(
+                p.otherPidMethod().name,
+                ret=Type('base::ProcessId'),
+                const=1,
+                virtual=1))
+
+            methods += [ register,
+                         registerid,
+                         lookup,
+                         unregister,
+                         createshmem,
+                         lookupshmem,
+                         istracking,
+                         destroyshmem,
+                         otherpid ]
 
         getchannel = MethodDefn(MethodDecl(
             p.getChannelMethod().name,
             ret=Type('MessageChannel', ptr=1),
             virtual=1))
 
         if p.decl.type.isToplevel():
             tmpvar = ExprVar('tmp')
@@ -3823,44 +3836,16 @@ class _GenerateProtocolActorCode(ipdl.as
                 self.asyncSwitch.addcase(
                     CaseLabel('SHMEM_CREATED_MESSAGE_TYPE'), abort)
                 self.asyncSwitch.addcase(
                     CaseLabel('SHMEM_DESTROYED_MESSAGE_TYPE'), abort)
 
             otherpid.addstmt(StmtReturn(p.otherPidVar()))
             getchannel.addstmt(StmtReturn(ExprAddrOf(p.channelVar())))
         else:
-            # delegate registration to manager
-            register.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.registerMethod().name),
-                [ routedvar ])))
-            registerid.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.registerIDMethod().name),
-                [ routedvar, idvar ])))
-            lookup.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.lookupIDMethod().name),
-                [ idvar ])))
-            unregister.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.unregisterMethod().name),
-                [ idvar ])))
-            createshmem.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.createSharedMemory().name),
-                [ sizevar, typevar, unsafevar, idvar ])))
-            lookupshmem.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.lookupSharedMemory().name),
-                [ idvar ])))
-            istracking.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->',
-                           p.isTrackingSharedMemory().name),
-                [ rawvar ])))
-            destroyshmem.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.destroySharedMemory().name),
-                [ shmemvar ])))
-            otherpid.addstmt(StmtReturn(
-                p.callOtherPid(p.managerVar())))
             getchannel.addstmt(StmtReturn(p.channelVar()))
 
         othervar = ExprVar('other')
         managertype = Type(_actorName(p.name, self.side), ptr=1)
 
         # Keep track of types created with an INOUT ctor. We need to call
         # Register() or RegisterID() for them depending on the side the managee
         # is created.
@@ -3911,28 +3896,17 @@ class _GenerateProtocolActorCode(ipdl.as
                 ])
                 switchontype.addcase(CaseLabel(_protocolId(manageeipdltype).name),
                                      case)
             default = StmtBlock()
             default.addstmts([ _fatalError('unreached'), StmtReturn() ])
             switchontype.addcase(DefaultLabel(), default)
             removemanagee.addstmt(switchontype)
 
-        return [ register,
-                 registerid,
-                 lookup,
-                 unregister,
-                 removemanagee,
-                 createshmem,
-                 lookupshmem,
-                 istracking,
-                 destroyshmem,
-                 otherpid,
-                 getchannel,
-                 Whitespace.NL ]
+        return methods + [removemanagee, getchannel, Whitespace.NL]
 
     def makeShmemIface(self):
         p = self.protocol
         idvar = ExprVar('id')
         sizevar = ExprVar('aSize')
         typevar = ExprVar('aType')
         memvar = ExprVar('aMem')
         outmemvar = ExprVar('aOutMem')