A faithful implementation of the actor message-passing semantics would mean that message contents are deep-copied from a logical point-of-view, even for immutable types. Deep-copying of message contents remains one the biggest bottlenecks for naïve implementations the actor model, so some implementations (ie. Kilim) support zero-copy message passing.
My question is, how is zero-copy message-passing (as part of an Actor library/framework) implemented in a shared-memory platform like the JVM? I assume it can only work for messages with immutable content, and that the visibility of message references must be restricted in some way. However, I'm having trouble finding the "theory" behind implementations of the Actor model.
Not that I know how any actual implementation is done, but when immutability is ensured at compile time like this:
You could simply pass along a reference, right? It's not a Actor library, but Google Guava gives you this idiom
return ImmutableList.copyOf(someList);
and it will be a zero copy ifsomeList
is immutable (that is, if it is an instance of ImmutableList). guess a similar approach could be used, e.g. by implementing a marker interfaceImmutable
and checking for that, and thereby deciding if to copy or not.