coroutine support
Jim Baker
jbaker at zyasoft.com
Fri Nov 13 10:00:09 PST 2009
On Fri, Nov 13, 2009 at 10:48 AM, Charles Oliver Nutter <headius at headius.com
> wrote:
> On Fri, Nov 13, 2009 at 11:27 AM, Jochen Theodorou <blackdrag at gmx.org>
> wrote:
> > Charles Oliver Nutter schrieb:
> >> This is basically what all the bytecode-weaving coroutine/continuation
> >> libraries do. Jython also does this for their
> >> lambda/generator/coroutine stuff so they can jump in and out.
>
Except for the lambda part, this is correct. (Our lambdas are very simple,
they're just compiled to construct a function object wrapping that chunk of
code.) Because yield is a keyword in Python, it's very easy to do too.
> >> The
> >> primary issue is that you can only jump in and out of the methods you
> >> have performed this transformation on. That means you can't call
> >> through any untransformed code and expect to be able to resume it.
> >
> > but isn't here yield responsible for that? Does this means the coroutine
> > support here will allow calling yield from outside or from deep down the
> > stack? It will it mean the stack will be kept? This was not clear from
> > the first post. Since only one Thread is used I assumed it might not be
> > the case.
>
> Here's the Java stack leading up to the yield call in my previous example:
>
> at
> org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:106)
> at ruby.__dash_e__.block_0$RUBY$__block__(-e:1)
> at
> ruby.__dash_e__BlockCallback$block_0$RUBY$__block__xx1.call(Unknown Source)
> at org.jruby.runtime.CompiledBlock.yield(CompiledBlock.java:105)
> at org.jruby.runtime.Block.yield(Block.java:194)
> at org.jruby.RubyArray.eachCommon(RubyArray.java:1611)
> at org.jruby.RubyArray.each(RubyArray.java:1618)
> at
> org.jruby.RubyArray$i_method_0_0$RUBYFRAMEDINVOKER$each.call(org/jruby/RubyArray$i_method_0_0$RUBYFRAMEDINVOKER$each.gen)
> at
> org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:299)
> at
> org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:117)
> at
> org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:132)
> at ruby.__dash_e__.method__1$RUBY$each(-e:1)
> at
> ruby.__dash_e__Invokermethod__1$RUBY$eachFixed0.call(__dash_e__#each)
> at
> org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:299)
> at
> org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:117)
> at
> org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:132)
> at ruby.__dash_e__.__file__(-e:1)
>
> All of this would have to be instrumented to be resumable. Basically
> an impossible task.
>
>
Likewise with Jython for any nested coroutine usage, as seen in
stackless/greenlets. We could implement a trampoline in our experimental
Python bytecode VM, but this would be restricted to just any Python code
that is compiled to Python bytecode (reweaving artifacts compiled to Java
bytecode is too limited for real usage) and forget doing it in Java
libraries outside of our control. It might be interesting. But not as useful
and general as this new work by Lukas.
--
Jim Baker
jbaker at zyasoft.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20091113/15c28cd3/attachment-0001.html
More information about the mlvm-dev
mailing list