Continuations, here I come
Jim Baker
jbaker at zyasoft.com
Tue Jul 28 22:18:13 PDT 2009
There's certainly significant interest in Jython dev for continuation
support in the JVM.
Compared to Ruby's fibers, Python's standard coroutines can be readily
compiled to Java bytecode, simply because yield is a keyword in Python and
the exit point always returns to the caller. We always know our yield
points, and we simply compile a given coroutine into a large switch
statement of these entry points, doing stack restore/save against our
function frame objects. (Tobias' and my
presentation<http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-6039&yr=2008&track=tools>at
JavaOne 2008 goes into this in some detail.)
However, this is not at all exhaustive. We would like to support
greenlets<http://pypi.python.org/pypi/greenlet>,
which are extensively used by IronPort, Yahoo Groups, and Slide, among
others, pretty much in the same way as RIFE is used. Greenlets look just
like the full coroutine switching available with Ruby's
fiber.transfer<http://ruby-doc.org/core-1.9/classes/Fiber.html>(at
least as I understand it), and the switch function cannot be
identified
in advance. Although it's possible to implement pure-Python greenlets with a
VM on the JVM trick (in our case running Python bytecode), Java
interoperability is severely limited, and it's slower too. Continuation
support would of course solve this for Jython.
- Jim
On Tue, Jul 28, 2009 at 2:15 PM, Charles Oliver Nutter
<headius at headius.com>wrote:
> Ok, I've decided that along with tail calls and indy, the next thing
> on my list is delimited continuations.
>
> Ruby 1.9 has started to make heavier use of "fibers", which are
> basically just coroutines or generators. Not only can you use them
> directly, a la fiber = Fiber.new, you can also get generator behavior
> out of any method on Enumerable. So instead of writing:
>
> foo.each {|a| p a}
>
> you can do
>
> enum = foo.each
> p enum.next
> p enum.next
> ...
>
> This is implemented in CRuby by using coroutines and stack-saving
> techniques. On the JVM, if we can't reduce the enumeration to a simple
> case (like known core classes), or if the iteration is arbitrarily
> complex (as it could be for a user-defined enumerable type), our only
> option is to use a thread. And that will be pretty heavy if people are
> doing a lot of enumeration.
>
> So I need to ask:
>
> What's the status of the continuation patch?
> Who else has interest in it?
> Would delimited continuations reduce security concerns?
>
> - Charlie
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
--
Jim Baker
jbaker at zyasoft.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20090728/908bc987/attachment.html
More information about the mlvm-dev
mailing list