Nick Sieger: JRuby Serial Interview 3 http://blog.nicksieger.com/articles/2007/01/18/jruby-serial-interview-3 en-us 40 JRuby Serial Interview 3 <p><em>This is part 3 in our <a href="/articles/tag/jrubyserialinterview">ongoing conversation</a> tracking the development of JRuby&#46;</em></p> <p><strong><a href="http://archive.jruby.codehaus.org/dev/45A29BEE.1060908%40sun.com">Official Rails support in February</a>? That&#8217;s not far away! What do you mean by &#8220;official&#8221;?</strong></p> <p><em>Thomas Enebo:</em> Largely, we just want to spend some extra TLC on fixing up various Rails issues between now and February&#46; Basically, get rid of the remaining known issues with running Rails from JRuby&#46; I think beyond marshalling we are very close to saying that today&#46; We also want to provide a better deployment picture for Rails by then&#46; So we will need to spend some time on that as well (the community has been doing a great job spearheading this)&#46;</p> <p>Software is never perfect, so we know that there will continue to be Rails issues after we say it is supported&#46; By setting this goal, we should give ourselves some pressure to polish what we have and also get a larger number of people some incentive to kick the tires&#46;</p> <p><em>Ola Bini:</em> That&#8217;s a question of interpretation&#46; In my view, &#8220;official&#8221; is some kind of high number&#46; 95% of all test cases in 1&#46;1&#46;6, maybe? But the more important part of it is that all the common use cases should work&#46; You should be able to work through AWDwR and everything should work&#46;</p> <p>It&#8217;s ambitious, but we can do it&#46; What&#8217;s needed soon is to decide what needs to be done with ActiveRecord&#45;JDBC, and do that, since AR&#45;JDBC is one of the larger points in our Rails support, and sometimes I feel that the support there is our weak link&#46;</p> <p><em>Charles Nutter:</em> We could probably say we support Rails today, with a whole list of caveats&#46; Rails runs right now, people are using JRuby on Rails today (in some cases for production apps!), and things largely will &#8220;just work&#8221;&#46; There&#8217;s also a lot of community effort behind alternative deployment scenarios like within a WAR file or behind a fast HTTP server like Grizzly&#46; Rails does run on JRuby today&#46;</p> <p>Our challenge before making a big official announcement about &#8220;Rails support&#8221; is to shrink that list of caveats down as small as possible&#46; We want marshalling to work so sessions function correctly&#46; We want AR&#45;JDBC to be cleaned up a bit more, with more testing and even wider database support&#46; We want any remaining core library issues resolved&#46; We want those peripheral deployment projects to work perfectly&#46; There&#8217;s a lot of work to get there, but it&#8217;s now simply an incremental process; Rails runs today, and will run better tomorrow&#46;</p> <p><strong>What&#8217;s this about YARV instruction interoperability?</strong></p> <p><em>Readers: here&#8217;s an IRC recap for you:</em></p> <div class="typocode"><pre><code class="typocode_default ">[1:31pm] olabini: HAHA [1:31pm] olabini: YEAH BABY. [1:31pm] olabini: hehe. [1:31pm] olabini: echo 'puts &quot;Hello world&quot;' &gt; test1.rb [1:33pm] olabini: ruby-yarv ~/src/yarv/tool/compile.rb -o test1.rbc test1.rb [1:33pm] olabini: jruby -y test1.rbc #=&gt; &quot;Hello world&quot; [1:33pm] headius: hah, awesome [1:33pm] nicksieger: no way!</code></pre></div> <p><strong>So this is <em>awesome</em> that you guys are able to track so closely with YARV&#8217;s progress, but why do it? Hedge your bets?</strong></p> <p><em>Ola Bini:</em> First of all, it shows the maturity of the JRuby runtime that we can implement basic parts of the YARV VM this easily&#46; Second, it can be very interesting for us to try out parts of how 1&#46;9/2&#46;0 will work out within the current JRuby system&#46; Third, we don&#8217;t have a YARV compiler yet, but being able to run files compiled with YARV ensures that we stay on track for Ruby compatibility&#46; Fourth: Yeah, hedging your bets is always a good idea&#46; Diversity breeds evolution&#46; I believe where on the right track with the current AOT and JIT compiler works, but there is always a good idea to implement these things in more than one way&#46; And of course, it &#8216;s just fun!</p> <p>The next step for this will be to get the loading to handle more things&#46; At the moment, it only runs extremely simple scripts&#46; But I&#8217;m planning on handling the more complex things soon too, adding support for labels and defining YARV methods and other such things&#46; The very next step to handle is a compiled recursive fibonacci script&#46; The YARVMachine already has most things needed for it, but the YARV emitted by the compiler contains some tricks that needs to be fixed&#46;</p> <p><em>Charles Nutter:</em> I&#8217;ve been the primary person responsible for our various interpreter rewrites over the past year or two&#46; Originally I modified it to be mostly &#8220;stackless&#8221;, using an Instruction object for each element in the AST and pushing down an external stack of previous instructions to maintain context&#46; That seemed like a neat idea, and it certainly did move toward a stackless design (I actually demoed a recursive fib(100_000) at RubyConf 2005), but it was rather slow and complicated enough that only I could maintain it&#46; So in October of 2006 I did another rewrite, basically simplifying the interpreter down to a &#8220;big switch statement&#8221; that could quickly traverse the AST without a lot of objects and stack manipulation&#46; This new C&#45;like interpreter engine was quite a bit faster, but unfortunately the tradeoff was that we were again burning Java stack frames when we had to dig deeper into the AST, and our maximum stack depth suffered&#46;</p> <p>I&#8217;ve still always wanted the stackless design back in JRuby, and started to think about alternate routes to get there&#46; The most obvious was having our own bytecode engine&#46; The most readily&#45;available set of bytecodes for Ruby&#46;&#46;&#46;was YARV&#8217;s&#46;</p> <p>Implementing a stack machine is pretty trivial&#46; You need an operand stack, instructions for manipulating it, and instructions that consume values from it&#46; Over the past year, YARV&#8217;s core set of bytecodes have started to solidify to the point that I figured implementing a YARV machine in JRuby would be a good idea&#46; So I did a very simple initial implementation that just handled local variables, method calls, while loops, and so on, to see if it would be feasible&#46; I got it as far as running an iterative fib, and the results were very promising: it was quite a bit faster than the current interpreter&#46;</p> <p>I ended up putting that down for a while to look at Java bytecode compilation, which has been coming along very nicely&#46; Recently, Ola decided to pick up the YARV machine work, and made it double cool by loading real compiled YARV bytecodes into it&#46; And if that wasn&#8217;t good enough, the original partial machine I&#8217;d implemented was able to run them without modification!</p> <p>We&#8217;re looking toward the future with this work&#46; We know that YARV is now &#8220;The&#8221; Ruby VM, and that eventually people will start to run compiled Ruby bytecodes&#46; We also know that JRuby will never be able to fully escape interpreted&#45;mode execution&#46; I believe both goals are answered by having a fast Ruby bytecode machine that works in concert with our Ruby&#45;to&#45;Java compilers&#46; And that&#8217;s the current roadmap for JRuby&#8217;s execution model&#46;</p> <p><em>Thomas Enebo:</em> Personally, I would like to see us move from walking our current tree to walking a set of instructions&#46; I think dynamic optimizations (as well as static) will be much easier using instructions and we can also create a simpler AST/parser (the traditional AST in Ruby does quite a bit of static optimization which I think makes the grammar a little tougher to wrap your head around)&#46;</p> <p>Anything YARV&#45;related sort of hits my sweet spot since it may nudge us in this direction&#46; JRuby will probably always mix execution between compiled and interpreted code&#46; I think interpretation will be easier to support at an instruction level&#46; It will also give us a good opportunity to flatten the Java stack more&#46; YARV is a good place to start&#46; It may be right solution for us too&#46; Who knows? I think experimentation is the name of the game for this stuff&#46; So I love to see it happening :)</p> Thu, 18 Jan 2007 03:59:31 +0000 urn:uuid:e88d8aef-5251-449e-8d3d-37af48b62f22 Nick Sieger http://blog.nicksieger.com/articles/2007/01/18/jruby-serial-interview-3 jruby ruby jrubyserialinterview http://blog.nicksieger.com/articles/trackback/197