Native actor refcounting support in IPDL

2019-08-01 Thread Nika Layzell
Bug 1550560 (https://bugzilla.mozilla.org/show_bug.cgi?id=1550560) landed
recently, adding native support for declaring actors as *refcounted*. This
change improves the ergonomics for declaring and using IPDL actors, and
opens avenues for future improvements to the IPC core. *refcounted* is the
recommended way to define the lifecycle for an actor, and may become the
default in the future. The syntax currently looks as-follows:

async *refcounted* protocol PBrowserBridge {
https://searchfox.org/mozilla-central/rev/b38e3beb658b80e1ed03e0fdf64d225bd4a40327/dom/ipc/PBrowserBridge.ipdl#33

Adding this attribute has the following impacts:

   1. Generated actor classes have pure-virtual *AddRef* and *Release*
   methods to be overridden by the implementation.
   2. *AllocPFoo* methods return *already_AddRefed* instead of *PFoo**
   .
   3. No *DeallocPFoo* methods will be generated or called on the manager
   class.
   4. IPDL will automatically obtain a single reference to the actor when
   its underlying connection is established, and will release it when the
   actor is no longer in use by IPC.
   5. The "helper constructor" is no longer generated, so *AllocPFoo*
   methods on the constructor sender side, which are often implemented as
   *MOZ_ASSERT_UNREACHABLE()*, may be removed. This may require consumers
   of the helper constructor to slightly modify their code.

I have converted 16 actors to use this new annotation in bug 1570369 (
https://bugzilla.mozilla.org/show_bug.cgi?id=1570369). Patches on this bug,
such as https://phabricator.services.mozilla.com/D40263, can be used as a
reference when converting your actor.

Please reach out to me (:nika) on IRC or Slack if you have questions or
encounter bugs when converting your actor.

Thanks!
Nika
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Native actor refcounting support in IPDL

2019-08-01 Thread Kris Maglione

\o/

This is going to get rid of so much (often buggy, potentially leaky, and 
slightly varying) boilerplate from most of our IPC code.


Thanks!

On Thu, Aug 01, 2019 at 03:11:00PM -0400, Nika Layzell wrote:

Bug 1550560 (https://bugzilla.mozilla.org/show_bug.cgi?id=1550560) landed
recently, adding native support for declaring actors as *refcounted*. This
change improves the ergonomics for declaring and using IPDL actors, and
opens avenues for future improvements to the IPC core. *refcounted* is the
recommended way to define the lifecycle for an actor, and may become the
default in the future. The syntax currently looks as-follows:

async *refcounted* protocol PBrowserBridge {
https://searchfox.org/mozilla-central/rev/b38e3beb658b80e1ed03e0fdf64d225bd4a40327/dom/ipc/PBrowserBridge.ipdl#33

Adding this attribute has the following impacts:

  1. Generated actor classes have pure-virtual *AddRef* and *Release*
  methods to be overridden by the implementation.
  2. *AllocPFoo* methods return *already_AddRefed* instead of *PFoo**
  .
  3. No *DeallocPFoo* methods will be generated or called on the manager
  class.
  4. IPDL will automatically obtain a single reference to the actor when
  its underlying connection is established, and will release it when the
  actor is no longer in use by IPC.
  5. The "helper constructor" is no longer generated, so *AllocPFoo*
  methods on the constructor sender side, which are often implemented as
  *MOZ_ASSERT_UNREACHABLE()*, may be removed. This may require consumers
  of the helper constructor to slightly modify their code.

I have converted 16 actors to use this new annotation in bug 1570369 (
https://bugzilla.mozilla.org/show_bug.cgi?id=1570369). Patches on this bug,
such as https://phabricator.services.mozilla.com/D40263, can be used as a
reference when converting your actor.

Please reach out to me (:nika) on IRC or Slack if you have questions or
encounter bugs when converting your actor.

Thanks!
Nika

___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Native actor refcounting support in IPDL

2019-08-01 Thread Boris Zbarsky

On 8/1/19 3:11 PM, Nika Layzell wrote:

Bug 1550560 (https://bugzilla.mozilla.org/show_bug.cgi?id=1550560) landed
recently, adding native support for declaring actors as *refcounted*.


Would that allow us to add MOZ_CAN_RUN_SCRIPT bits to the generated code 
for those cases?


-Boris
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Native actor refcounting support in IPDL

2019-08-01 Thread Nika Layzell
On Thu, Aug 1, 2019 at 3:45 PM Boris Zbarsky  wrote:

> On 8/1/19 3:11 PM, Nika Layzell wrote:
> > Bug 1550560 (https://bugzilla.mozilla.org/show_bug.cgi?id=1550560)
> landed
> > recently, adding native support for declaring actors as *refcounted*.
>
> Would that allow us to add MOZ_CAN_RUN_SCRIPT bits to the generated code
> for those cases?
>

Yep, that should be possible. IPC still works with raw pointers internally
in many cases, and doesn't directly hold a RefPtr on the stack, so
it'll probably need to be a MOZ_CAN_RUN_SCRIPT_BOUNDARY.
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform