Ownership and Reference Counting based Garbage
Collection in the Actor World
Sylvan Clebsch Sebastian Blessing Juliana Franco Sophia Drossopoulou
Causality, and Imperial College London
{sylvan,sebastian,sophia}@causality.io j.vicente-franco@imperial.ac.uk
Abstract
We propose Pony-ORCA, a fully concurrent protocol for garbage
collection in the actor paradigm. It allows actors to perform garbage
collection concurrently with any number of other actors. It does not
require any form of synchronization across actors except those in-
troduced through the actor paradigm, i.e. message send and mes-
sage receive.
Pony-ORCA is based on ideas from ownership and deferred,
distributed, weighted reference counting. It adapts the messaging
system of actors to keep the reference count consistent.
We introduce a formal model and describe the invariants on
which it relies. We illustrate through an example and sketch how
these invariants are maintained. We show some benchmarks and
argue that the protocol can be implemented efficiently.
1. Introduction
The actor paradigm [4] was proposed in 1973 by Carl Hewitt [22].
An actor is a computational entity that, in response to a message it
receives, can: 1) send a finite number of (asynchronous) messages
to other actors; 2) create a finite number of new actors; and 3)
designate the code to be executed for the next message it receives.
The code executed upon receipt of a message is called a behaviour.
The actor paradigm has been adopted in a functional setting, e.g. in
Erlang [7], and in the object-oriented paradigm [5, 10, 14, 32].
Implicit garbage collection is crucial for convenience of pro-
gramming, however automatic garbage collection often proves to
be a performance bottleneck, e.g, [12] reports pauses of around 3
seconds.
In this paper, we propose Pony-ORCA, a garbage collection
protocol for actor-based object oriented programming languages.
We have implemented Pony-ORCA for the language Pony [6],
but our protocol is applicable for any languages which fulfils the
criteria we give later. Our protocol is based on ownership and
deferred distributed weighted reference counting.
Ownership types [15, 30] were proposed with the remit to de-
limit groups of related objects into different areas of the heap. They
were used for garbage collection under the requirement that there
are no incoming references to these areas [31]. Such a scheme
[Copyright notice will appear here once ’preprint’ option is removed.]
works well in the concurrent setting, but the no-incoming refer-
ences requirement is often far too strong.
Reference counting garbage collection puts no requirement on
the heap structure; instead, it tracks, for each object, a count of the
number of references to it held by other objects [8]. This approach
has been further developed to detect cycles and to deal with the
distributed setting [19, 28]. However, the approach has poor local-
ity and thus, in the concurrent setting, it requires synchronization
across the various threads [25].
We employ the locality found in actors, and the implicit syn-
chronisation afforded by the actor messaging system, to develop a
fully concurrent garbage collection algorithm. Pony-ORCA allows
the fully concurrent garbage collection of objects as well as actors.
In particular:
•
An actor may perform garbage collection concurrently with
other actors while they are executing any kind of behaviour.
•
An actor may decide whether to garbage collect an object solely
based on its own local state, without consultation with, or in-
specting the state of, any other actor.
•
No synchronization between actors is required during garbage
collection, other than potential message sends.
•
An actor may garbage collect between its normal behaviours,
i.e. it need not wait until its message queue is empty.
•
Pony-ORCA can be applied to several programming languages,
provided that they satisfy the following two requirements:
Actor behaviours are atomic.
Message delivery is causal—i.e. messages arrive before any
messages they may have caused, if they have the same
destination.
Our approach is based on implicit ownership, whereby an actor
owns any object that it has allocated. Each actor is responsible for
garbage collecting the objects it owns. The challenge is that an actor
may have no path to an object it owns, while other actors may still
have paths to that object, or the object may appear in messages
in some other actor’s message queue. It would be erroneous to
garbage collect such an object.
In our approach, an actor maintains a reference count for all the
objects it owns. The reference count is guaranteed to be non-zero
for any object which is accessible from any message or any actor
other than its owner. Thus, an actor can safely garbage collect any
object which is locally unreachable, and whose reference count is
zero.
There is the remaining challenge of ensuring that the reference
count indeed is non-zero for objects which are accessible from
actors other than their owner. This is maintained through a system
whereby all the actors which may reach an object they do not
1 2015/4/13