BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News JRuby on Java ME/CDC

JRuby on Java ME/CDC

This item in japanese

Charles Nutter has recently spent time bringing JRuby to mobile Java devices, first with the introduction of Ruboto, Android support for JRuby. The current version runs JRuby code in interpretation mode, but Charles plans to expand the Ahead of Time (AOT) compilation to be able to fully compile Ruby source code to Java bytecode, which could then be turned into bytecode for Android's VM:

Meanwhile, I'll probably start poking at an all-at-once compilation mode, since I think that's simpler initially than emitting Dalvik bytecode. It's already done in my head. You'll run a command to "fully compile" a target script or scripts, and it will create the .class file it does now along with all the method binding .class files it normally generates at runtime. I've been planning this feature for a while anyway. With the "completely compiled" Ruby code you should be able to just "dex" it and upload to the device.

Another important step is to modularize JRuby:

Given that most people will probably want to ship precompiled code, and given the fact that many libraries will never work, we need to modularize JRuby a bit more so we can rip out unsupported libraries, parser guts, interpreter guts, and compiler guts. That should shrink the total size of the binary substantially. And I have other ideas for shrinking it too.

The ability to compile Ruby code and only ship required parts of JRuby will be particularly important for the more resource constrained Java ME devices, which Charles targets in his latest project: jruby-cdc. As discussed previously, JRuby on Java ME has been considered before, but proved to be a challenge due to the many restrictions of the Java ME platform (compared to JRuby's target platform Java 5).

The new effort brings JRuby to Java ME CDC devices (CDC is a profile of Java ME):

The "cvm" is Sun's reference implementation of an embedded JVM, and this particular package includes the PBP level APIs as well. The jruby.jar here is the one I've stripped in the jruby-cdc project, but with the additional step of retroweaving it back to Java 1.3-compatible bytecode.

The Rhodes project already brings support for a subset of Ruby support to many mobile platforms, using either a version of MRI (for Symbian or Windows Mobile devices) or currently a custom version of XRuby (which compiles Ruby code to Java bytecode) for devices like Blackberry. A stripped down version of JRuby that can AOT compile to Java bytecode could certainly come in handy for the Rhodes project (Rhodes is Open Source and hosted on Github, so it's possible fork and experiment with a JRuby version once AOT compilation is available).

One interesting aspect of the Rhodes platform is the GUI environment which is based on HTML, with extensions that support accessing device features such as location, cameras or others. The concepts are similar to what Palm is using for the new WebOS, ie. local applications with GUIs built using HTML, Javascript and other web technologies, with the difference that Rhodes' application backends can be written in Ruby. 

While Rhodes is aimed at smartphones, JRuby on JME could capture the lower end segment, as Charles points out:

Why bother? Well, there are still a lot of Java ME devices out there. And while the device you carry in your pocket may be growing beyond Java ME, the set-top box or Blu-Ray player in your living room is just starting to reach that level. The technology is still sound, if perhaps less obvious than an iPhone or Android. And hey, we want "Ruby everywhere," don't we?

What would you do with JRuby on Java ME or Android devices?

 

Rate this Article

Adoption
Style

BT