Kilim - actors and message passing in Java

As discussed in The multicore crises: Scala vs. Erlang, massage passing and the actor model of concurrency is one promising way for the massive parallelization needed to utilize current and especially future CPUs. Erlang has it built in from the start and Scala incorporated the Scala Actor library into it’s framework. But there is also a pure Java solution - Kilim

Kilim is a message-passing framework for Java that claims provides ultra-lightweight threads and facilities for fast, safe, zero-copy messaging between these threads.

It consists of a bytecode postprocessor (a “weaver”), a run time library with buffered mailboxes (multi-producer, single consumer queues) and a user-level scheduler and a type system that puts certain constraints on pointer aliasing within messages to ensure interference-freedom between threads.

Kilim works with code annotations on methods and arguments. A method is annotated as @pausable if it directly it indirectly calls other pausable methods, which somewhere in the call chain will result in calls to Kilim methods, such as Actor.sleep() or Mailbox.get(). The annotated code is transformed by the bytecode weaver to code in a continuation passing style. Continuations are native in some languages but has been retrofitted into Java code before in well known web frameworks and web servers, such as RIFE and Jetty.

These qualifiers can be understood in terms of two orthogonal capabilities of an object in a tree: first, whether it is pointed to by another object or not (called a root in the latter case) and second, whether or not it is structurally modifiable (whether its pointer-valued fields are assignable). The latter is a transitive property; an object is structurally modifiable if its parent is.

Given this, an object is free if it is the root of a tree and is structurally modifiable. A cuttable object may or may not be the root, but is structurally modifiable. An object with a safe capability cannot be structurally modified (transitively so), and does not care whether or not it is the root.

The actor model is popping up in more and more contexts, and no matter which language or platform you will program in in the future, the concept is likely to be in important one.

Nice to see a Java only implementation I will definitely be checking this as a possible execution model type in Einstein. What's interesting is the way that he has chosen to annotate the degree of mutability. I think that thinking in gray-scale rather than monochrome is the way forward for general purpose (rather than specialist) scalability techniques. I'm not convinced yet by the absolutism of some languages/frameworks with rigid restrictions, like those in functional programming; I think we have a lot to learn from the results of using these idioms but need to be able to say the degree of, for example, idempotency, mutability, concurrency etc. that we desire or can assure etc. And exploration in this area is very interesting to see.

One of the big features of Actors, as used by the originators of the term (Carl Hewitt, Gul Agha), is isolation from one another. There is no point doing concurrent programming if you cannot isolate easily.

In Scala's actor model, isolation is not enforced; it is obtained by convention; the programmer must use immutable messages or be "very careful" while exchanging mutable messages.

On Continuations

A continuation is a snapshot of both the data and control planes. In that sense, Jetty doesn't provide continuations (it only restores the control plane, but no support on the data plane; it leaves it to the programmer to figure out which variables to restore, and where to store them before yielding.

Kilim can be downloaded at kilim.malhar.net. There's an "IFAQ" (Infrequently asked questions) in the download that provides more comparisons.

For some reason actor model does not seem like a natural extension to Java. I am no James Gosling to say whether Java is meant to do this or not. Perhaps should we shift the blame on to the frameworks which have made actor model like an after-thought on Java? These weaving strategy implementations like Kilim, ActorFoundry, Actors Guild etc… have to take some blame for making actor models look very unnatural to Java development – putting a kink in every development step and development tool. The leap of faith with actor models may perhaps never happen until it is made a part of Java platform itself (like how actors implementation is provided as part of the Scala standard library). For now, for die-hards Java nerds, I would suggest that among Java alternatives, Jetlang is the best because it provides a consistent model that does not feel misplaced or unnatural in the context of Java.

Kilim in my judgment is an attempt to misuse the purposes of a University in coming up with an offering to gain appeal with Java corporate world in the guise of academic research work. Hundreds of successful Java frameworks have been written during week-ends by great people through open source initiatives. Kilim can come no way close to them in terms of acceptance from the Java community. But unlike Kilim, none of them have got a PhD because they were willing to play by the moral rules of the game than go for fringe gains. You don’t need the paraphernalia of a University (professors, library, state grants …) to write a Java framework eh! Hope Universities see through this, if not they will be rendered inconsequential. For heaven’s sake, may Universities focus only on works which have larger impact on the society, bring real futuristic technologies that would make our generation proud!

Is your profile up-to-date? Please take a moment to review and update.

Email Address

Note: If updating/changing your email, a validation request will be sent

Company name:

Keep current company name

Update Company name to:

Company role:

Keep current company role

Update company role to:

Company size:

Keep current company Size

Update company size to:

Country/Zone:

Keep current country/zone

Update country/zone to:

State/Province/Region:

Keep current state/province/region

Update state/province/region to:

Subscribe to our newsletter?

Subscribe to our industry email notices?

You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.