EXPERIMENTAL: Running JRuby on J2ME: mobile JRuby.
Presentation by Roy Ben Hayun, via:
http://headius.blogspot.com/2007/11/jruby-on-me-devices.html
See more, here: https://github.com/jruby/jruby/wiki/JRubyOnJavaMicroEdition
2. Topics
• Requirements for mobile Ruby
• Port of the native Ruby VM (MRI)
• Porting JRuby to Java ME
> CLDC
> CDC
• More things to do..
Sun Confidential: Internal Only 2
4. Possible usages for mobile Ruby
• Simple application development
• Prototyping
• Development tools
• Education
• Not Ruby on Rails.
• Not much usage today.
• Possibly in few years when/if scripting languages
gain more traction in mobile space
Sun Confidential: Internal Only 4
5. Requirements from JRubyME
• What do we actually want to get?
> The power of Ruby language
> JRuby's Java bindings
> An acceptable working subset
• What can we keep for later?
> Ruby to JVM bytecode compilation
> Threading
> Any advanced feature
Sun Confidential: Internal Only 5
6. Port of the native Ruby VM (MRI)
Sun Confidential: Internal Only 6
7. Porting the native Ruby MRI
• See
http://developer.symbian.com/main/tools/opensrc/ruby
• Native porting effort is lengthy
• Need to port per OS
• Requires additional effort for API access
> Mobile APIs
> GUI
• MRI port gives only barebones Ruby language
> No mobile APIs
Sun Confidential: Internal Only 7
8. Comparing native MRI vs JRuby port
• Porting involved:
> Hybrid of C, K&R C, Symbian C++ vs Java only
• Porting time:
> Weeks vs Days
• Value achieved in those ports:
> Interpreter – approximately same in both
> No OS APIs vs Java APIs via JRuby Java binding
> Required customization vs platform independent
> JRubME is easier to extend and enhance
Sun Confidential: Internal Only 8
10. Choosing the Java ME plaform
• CLDC based solution
> The current Java ME de-facto standard
> MIDP provides rich mobile APIs
> Requires build-time modifications to replace reflection
> Requires source modifications to JRuby
• CDC based solution
> e.g., Sony Ericsson P990, M600
> Closer to a desktop Java environment
> Requires source modifications to JRuby
Sun Confidential: Internal Only 10
11. Choosing the JRuby baseline
• Newer versions (v0.9.8 from 2007)
> Closer to the main JRuby branch for easy integration
> Has more advanced features
• Taking an older version (v0.8.2 from 2006)
> Has less advanced features
> Minimize the porting effort to get a working subset
– Less code, fewer dependencies, fewer libraries
> Provides the interpreter and Java bindings
– Which is what we need for now
Sun Confidential: Internal Only 11
12. Various options for JRuby on Java ME
• Newer JRuby mainlines (X axis)
> More language and VM features
> Better Maintainability
• Java platform power (Y axis)
> Less porting effort
> More usability
features
Effort
/ JRuby 0.8.2 / JRuby 0.9.8
CDC CDC Maintainability
Java platform
closer to desktop Usability
/ JRuby 0.8.2 / JRuby 0.9.8 trade-off line
CLDC CLDC
Newer JRuby mainlines
Sun Confidential: Internal Only 12
13. JRuby 0.9.8 on CLDC
• Initial exploration to get some hands-on feeling
• Minor obstacles
> Missing classes/packages (i.e. collections, nio, regex)
> Missing methods in existing classes
> Migrating to GCF
> Obstacles accumulate
/ JRuby 0.9.8
CLDC
Sun Confidential: Internal Only 13
14. JRuby 0.9.8 on CLDC main obstacles
• Obstacles accumulate
• Java bindings require reflection capability
• Possible solutions:
> Pseudo reflection mechanism
> Hard wired code support for specific classes
– LCDUI, PIM, connectivity, persistance etc.
> Same process as using the C API for the native Ruby
VM
Sun Confidential: Internal Only 14
15. Usability obstacle on CLDC
• Sandboxing limits the usage of JRuby on mobiles
> Limits usage to MIDP APIs
> Can not jump out of the sandbox
> Limits options of development tools
– i.e. Limits dynamic extensions of testing frameworks
Sun Confidential: Internal Only 15
16. Summary of obstacles on CLDC
• CLDC porting effort becomes a handcrafted port
> Although, it’s not a full rewrite
> But big enough to diverge from the mainline JRuby
• Need to have a CLDC version.
• A more powerful JRuby on CDC should come first
> Provide a proof of concept
> Prototype for mobile usage
> Attract developers
Sun Confidential: Internal Only 16
17. Porting process to CDC
• Avoid “We don’t need all that!”
• Avoid the big bang blind port
• Decremental iterations to downgrade JRuby mainline and platform
> Ensure it is running on Java SE 1.X
> Regress down to Java SE 1.X-1
• Move to CDC
> And tell the world!
/ JRuby 0.8.2 / JRuby 0.9.8
CDC CDC
• Incremental iterative steps
> Integrate with newer JRuby mainlines / JRuby 0.8.2 / JRuby 0.9.8
> Migrate to CLDC CLDC CLDC
Sun Confidential: Internal Only 17
18. Regress on Java SE 1.4
• Ensuring it runs on Java SE 1.5 and 1.4
• Less libraries to remove then newer JRuby mainlines
> junit.jar
> bsf.jar and javasupport.bsf.*
> ant.jar and the AST serialization
• Remove asserts
• No java.nio.*
• (No autoboxing in the source..)
Sun Confidential: Internal Only 18
19. Regress on Java SE 1.3
• Chained exceptions
• Few more minor removals
> Missing methods i.e. String.split(), Boolean.valueOf()
> Missing classes i.e. StackTraceElement
> Restricted access i.e. java.util.Calendar.setTimeInMills()
Sun Confidential: Internal Only 19
20. Regress on Java SE 1.3
• Bigger obstacle is that there is no java.util.regex.*
• Solution
> Find a replacement package e.g.,Java 1.4
> Paste into a new package jrubyme.poc.[package]
> Modifications as required to package and client code
– e.g., sun.text.Normalizer silently commented out.
• And do the same for other dependencies
Sun Confidential: Internal Only 20
21. Move to CDC
• Introspection support incompatible
> java.beans.Introspector required by BeanExtender Ruby
class
• Solution:
> Disable the Ruby beans extension
> Serialize Abstract Syntax Tree and redeploy *.ast.ser
files
Sun Confidential: Internal Only 21
22. Evaluating the CDC port
• How does downgrading JRuby to 0.8.2 simplify things?
> i.e. Less than 40 locations of java.util.Regex package usage
> Less code e.g., 318 source files compared to 574 in 0.9.8
• How does porting to CDC via Java SE simplify things?
> Moving closer to CDC gradually
> Much fewer new APIs or API differences
– No need for handcrafted porting
• Remember: we’re trying to get to a working subset
Sun Confidential: Internal Only 22
23. Demo on a real device
• AWT UI
• Can load, modify and launch a script
• On device programming
Sun Confidential: Internal Only 23
24. Demo on a real device
Sun Confidential: Internal Only 24
25. Demo on a real device
Sun Confidential: Internal Only 25
26. There's a lot to do from here..
Sun Confidential: Internal Only 26
27. Bringing JRuby to the mobile space
• Co-existence of the native and Java options
> Attracts developers from different backgrounds
> No reason to limit the hosting platform options
• Anatomy of free open source success
> Governance and decision making capability
> Tools for collaboration
> Strong community values and commitment
Sun Confidential: Internal Only 27
28. Bringing JRuby to the mobile space
• JRubME ‘TODO’ list
> Create a mobile spec (desktop too)
> Adapt to mobile constraints (ROM, performance, ..)
> Rectify the initial porting
> Move upwards in the JRuby versions
> Migrate to CLDC as well
Sun Confidential: Internal Only 28
29. Bringing JRuby to the mobile space
• JRubME ‘Wish-list’
> Scripting languages gain more traction in the mobile
space
> CDC (or embedded Java SE flavour) to become the
mobile Java de-facto standard
> Dual compilation and JSR-292 (invokedynamic)
– Moore’s law will take care of speed
Sun Confidential: Internal Only 29