John Cowan wrote: > On Jan 17, 2008 1:06 PM, Charles Oliver Nutter <[EMAIL PROTECTED]> wrote: > >> * Then we used a hand-written indexed method handle like you describe. >> Again, it worked (albeit a bit slower than individual methods), but it >> was too much effort to implement by hand and wouldn't work for generated >> code. > That pattern is very amenable to both hand-coding and code generation, > and the only limit to it is how much code a class can hold. The > private static constants are just for documentation in hand-written > code, and aren't used in generated code. There is obviously a speed > problem resulting from the call-switch-call, but the great majority of > all calls bypass this path completely to invoke the static method > directly (namely, those which are direct in the source language).
It is the "hand coded" part that did not scale for us. Of course the pattern itself scales fine when code-generating, and JRuby has an optional flag that uses exactly this method for generating indexed methods. But the performance hit is real for a language that uses dynamic dispatch exclusively: fib(30) with non-indexed (direct) method handles: ~/NetBeansProjects/jruby $ bin/jruby -J-server test/bench/bench_fib_recursive.rb 0.952000 0.000000 0.952000 ( 0.952000) 0.647000 0.000000 0.647000 ( 0.648000) 0.636000 0.000000 0.636000 ( 0.636000) 0.651000 0.000000 0.651000 ( 0.651000) 0.634000 0.000000 0.634000 ( 0.635000) fib(30) with indexed method handles: ~/NetBeansProjects/jruby $ bin/jruby -J-server -J-Djruby.indexed.methods=true test/bench/bench_fib_recursive.rb 2.005000 0.000000 2.005000 ( 2.006000) 0.835000 0.000000 0.835000 ( 0.835000) 0.847000 0.000000 0.847000 ( 0.848000) 0.838000 0.000000 0.838000 ( 0.839000) 0.823000 0.000000 0.823000 ( 0.823000) >> * One .rb script is compiled into exactly one .class file. > > So Ruby classes don't correspond to JVM classes? They do not; Ruby's classes must be reified into first-class data structures since they can have methods and instance variables added and removed at runtime. An upcoming compiler extension for JRuby will allow generating a static type + methods for a specific set of Ruby methods, which will provide a more "Java-like" type and set of signatures. > I create one Java class for every source-code class, plus (currently) > one for each embedded anonymous procedure, plus several more, one for > each distinct namespace in the source language (functions, lexical > variables, dynamic variables). I create a single class for all of those and bind them at runtime. It was a key requirement I wanted for the compiler when I started. - Charlie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en -~----------~----~----~----~------~----~------~--~---
