This C is Kilim me

Memory models are just too complicated at the user level and even compiler implementers have a a hard time getting their JITs to work correctly.

Structuring code as series of single threaded objects, typically using Agents, has always seemed like a really good idea, though writing code in a suitable style to handle the inversion of control has always been a problem.

Kilim is a Java library that has a couple of novel solutions to the problems of using Actors. First, a post-processor recognises annotations in the Java code and rewrites the byte code to handle the inversion of control aspect. @Pausable methods are rewritten to take an extra parameter of type Fiber (a lightweight thread) which is used for storing the current state when the current execution needs to wait, allowing the computation to be restarted at the later point. This rewriting implements a kind of coroutine, allowing lightweight threading and also allowing an OS thread to be shared by many computations with very low overhead. This is the kind of transformation that Microsoft are doing in their C# and VB compilers to implement the new async feature for C# 5, though in the Microsoft case the signatures of the methods need to be modified to return a Task of the appropriate type and the waiting is carried out by adding new contextual keywords to the language.

The second novel idea is to ensure that messages are not being shared between Actors, effectively isolating them. Messages are instances of Java classes, but are treated specially by the system which analyses method annotations to ensure that fields within the message are not being shared between threads. The idea here is that a method can be annotated to say what it does with a message. This annotation can be checked by the post processor and the system can therefore ensure that when a message has been passed into another method, the current method can no longer access it.

There’s a Google Tech talk on Kilim here and a paper on the design. Some discussion on this library and whether it solves any problems (or just introduces more) can be found here.

This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s