Saturday, November 3, 2007

RubyConf 2007: JRuby: Ruby for the JVM

Charles Nutter and Thomas Enebo. They are working at Sun as full-time JRuby developers. Also, they are working on dynamic language support, in general, for the JVM.

What is it? Not just Ruby for the JVM. Ooh, looks like they are going to go in-depth.

Two days ago 1.0.2 was released. Last night 1.1b1 was released, during the town hall discussion.

Topics of discussion: Basics, Lexer and Parser, Design (Core Classes, Interpreter, Compiler, Performance Optimizations, Threading, Extensions and POSIX, Java Integration)

Hand-written lexer. LALR parser, Jay, a Bison for Java. DefaultRubyParser.y => DefaultRubyParser.java. Abstract syntax Tree similar to MRI's.

For demos, they arere using NetBeans. All the completion and formatting is based off of the parse tree.

For now, eval'ed code is always interpreted.

New in JRuby 1.1, there is full bytecode compilation.

There is a demo of the JRuby compiler, showing speed differences between interpreted and compiled mode.

ObjectSpace optimization. each_object is difficult to support on modern VMs. Have to save a weak reference to every object created during execution. Sucks two to five times as much as running normal code. Only real use is in TestUnit, where it looks for all TestCase classes. Someone from the audience asks what about the profilers and memory tools out there? Yes, but those are narrow in scope (Ruby only). Limited control over GC.

Another optimization is custom core classes. Yet another is with regexes. Ola Bini ported MRI's regex engine. There is also Joni, Java port of Oniguruma. It is in progress, but could be the holy grail. It will grow the size of JRuby ~25%, so it is a big project.

JRuby supports only native OS threads. They are heavier than MRI's green threads, but are truly parallel. In 1.1, there will be pooling of OS threads, to minimize spin-up time.

Do you support C extensions? No. Maybe in the future, but the Ruby API exposes too much. Native libraries are accesible with Java Native Access (JNA). It is used for POSIC functions not in Java, like file access.

Java Integration: Popular Use Case: Swing GUIs. Ruby magic simplifies most of the icky/tricky bits. Java is too verbose. No consistent cross-platform Ruby GUI. There are a few ways of going about doing this: direct (Charles' standard demo), cheri (builder approach; dsl), profligacy (targeted fixes; Zed Shaw), MonkeyBars (tool-friendly).

Other big domain is web applications. JRuby on Rails. ActiveRecord-JDBC. GoldSpike/Warbler for app server deployment. GlassFish gem for Mongrel-like deployment.

Upcoming: ActiveHibernate, Ruvlets (Ruby Servlets).

Another use case is Test and Behavior Driven Development. Test Driven Development is hard in Java. RSpec makes it easier.

No comments: