Search |
||
Holy crap: JVM has coroutine/continuation/fiber etc.Posted by forax on November 19, 2009 at 4:01 PM PST
Lukas Stadler is my hero,
at last JVM summit,
he just explain how coroutine and friends can be
implemented in the VM
and guess what, it now works (currently only with C1).
Generator
I have always wanted to have generator
in Java. After all, Python have this feature, Ruby and C#(*) too.
The implementation is based on continuation, yield stops the current execution and saves the stack frames as an object,
the value passed as argument to yield is received by the method next of the iterator. When next next is called,
the continuation is resumed, so the execution is restarted just after the yield.
(*) There is some weird limitations in C# but a friend of mine says to me that C# 4 doesn't have them anymore. By example, this generator specifies an iterator that will return the Fibonacci's numbers: public class FibonacciGenerator extends AbstractGenerator If you want to test it, there is two solutions:
$ /usr/jdk/jdk1.7.0b75/bin/java -coroutine -Xbootclasspath/p:coroutine.jar -cp classes FibonacciGeneratorTest value 1 value 2 value 3 value 5 value 8 The code of the abstract generator is here: public abstract class AbstractGenerator
Cheers, »
Comments
Comments are listed in date ascending order (oldest first)
Excellent news...
Submitted by opinali on Fri, 2009-11-20 06:08.
...not only for additional Java features, but for extra other-languages support (e.g. Scheme) and for interesting use cases like continuation-based web frameworks.
I hope the delay in JDK 7 will have the side effect that a bigger number of interesting MLVM projects will have time to mature - I'm strongly interested in full tail call support - to be part of the JDK 7 FCS.
Re: Excellent news...
Submitted by forax on Fri, 2009-11-20 07:02.
I wonder if a yield as a tail call can be optimized :) Rémi GOTO on steroids
Submitted by abies on Fri, 2009-11-20 07:45.
I find it quite interesting that language which has banned goto might be getting continuations, which are in certain way, superman non-local gotos.
Still, I'm all for enabling it on JVM level - there are other languages than java. Add tail calls and value types and we might be getting somewhere...
More coroutines for Java
Submitted by emorning on Fri, 2009-11-20 08:36.
I also came across this project the other day that adds coroutines to the current JVM...
http://code.google.com/p/coroutines/
RE: more coroutines for Java
Submitted by forax on Sun, 2009-11-22 06:53.
There are several projects that already provide coroutine by doing bytecode weaving, RIFE is the most popular. coroutine in the VM allows to get rid of all the limitations of the weaving approach.
cheers, |
||
|
Holy crap indeed!