JRuby
From Wikipedia, the free encyclopedia
Developed by | Charles Nutter, Thomas Enebo, Ola Bini and Nick Sieger |
---|---|
Latest release | 1.2.0 / 2009-03-16 |
Preview release | - / - |
Written in | Ruby and Java |
Operating system | Cross-platform |
Platform | Java Virtual Machine |
Type | Ruby programming language interpreter |
License | CPL/GPL/LGPL |
Website | http://jruby.codehaus.org/ |
JRuby is a Java implementation of the Ruby programming language, being developed by the JRuby team.
JRuby is free software released under a three-way CPL/GPL/LGPL license.
JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code (compare Jython for the Python language).
JRuby's lead developers are Charles Nutter [1], Thomas Enebo [2] Ola Bini [3] and Nick Sieger [4]. In September 2006, Sun Microsystems hired Enebo and Nutter to work on JRuby full time.[1] In June 2007, ThoughtWorks hired Ola Bini to work on Ruby and JRuby.[2]
Contents |
[edit] History
JRuby was originally created by Jan Arne Petersen, in 2001. At that time and for several years following, the code was a direct port of the Ruby 1.6 C code. With the release of Ruby 1.8.6, an effort began to update JRuby to 1.8.6 features and semantics. Since 2001, several contributors have assisted the project, leading to the current (2008) core team of four members.
The Netbeans Ruby Pack, available since NetBeans 6.0, allows IDE development with Ruby and JRuby, as well as Ruby on Rails for the two implementations of Ruby [5] [6].
JRuby 1.1 added Just-in-time compilation and Ahead-of-time compilation modes to JRuby and was already faster in most cases than the current Ruby 1.8.7 reference implementation[3][4].
JRuby 1.1.1 is stated to be packaged in Fedora 9[5][6].
Since version 1.1.1, the JRuby team began to issue point releases often to quickly address issues that are brought up by users[7].
JRuby support Ruby MRI 1.8.6, and work is ongoing to add a Ruby 1.9 support, but as Ruby 1.8.7 is mainly a transitional version to 1.9, it will not be supported[8].
[edit] Rails
JRuby supports Ruby on Rails since version 0.9 (May 2006) [9][10], with the ability to execute RubyGems and WEBrick. Since the hiring of the two lead developers by Sun, Rails compatibility and speed have improved greatly. JRuby version 1.0 successfully passed nearly all of Rails' own test cases[11]. Since then, developers have begun to use JRuby for Rails applications in production environments [12].
[edit] Multiple Virtual Machine Collaboration
On February 27, 2008, Sun Microsystems and the University of Tokyo announced a joint-research project to implement a Virtual Machine capable of executing more than one Ruby or JRuby application on one interpreter[13].
[edit] Dynamic Invocation on Java Virtual Machines
JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform) [14] propose to:
- add a new
invokedynamic
instruction at the JVM level, to allow method invocation relying on dynamic Type checking, - to be able to change the classes and method at runtime dynamically in a production environment.
The Sun Open source project Multi Language Virtual Machine aim to prototype this JSR[15]. The first working prototype, developed as a patch on OpenJDK, was announced and made available on end of August 2008[16][17].
The JRuby team has successfully wired dynamic invocation in their codebase, albeit in a very primitive way. Dynamic invocation shipped with the 1.1.5 release, although being disabled on JVMs without Dynamic invocation capabilities[18].
[edit] Release History
This table present only releases that present significant steps in JRuby history, aside from versions that mainly fixed bugs and improved performance.
Release | Release Date | Highlights |
---|---|---|
0.9 | 2006-08-01 | Rails support[9] |
1.1 | 2008-03-28 | Performs better than Ruby MRI 1.8.7[4] AOT mode and JIT mode[19] |
1.1.4 | 2008-08-28 | Refactored Java integration layer Beginning of Ruby 1.9 support FFI subsystem for calling C libraries[20] |
1.2.0[21] | 2009-03-16 | Ruby 1.9 support almost complete (including JIT compiler) Preliminary Android support |
[edit] Design
Since early 2006, the current JRuby core team has endeavored to move JRuby beyond being a simple C port, to support better performance and to aid eventual compilation to Java bytecode. To support this end, the team set an ambitious goal: to be able to run Ruby on Rails unmodified using JRuby. In the process of achieving this goal, the JRuby test suite expanded to such extent that the team gained confidence in the "correctness" of JRuby. As a result, toward the end of 2006 and in the beginning of 2007, they began to commit much more complicated redesigns and refactorings of JRuby's core subsystems.
JRuby is designed to work as a mixed-mode virtual machine for Ruby, where code can be either interpreted directly, just-in-time compiled at runtime to Java bytecode, or ahead-of-time compiled to Java bytecode before execution. Until October 2007, only the interpreted mode supported all Ruby's constructs, but a full AOT/JIT compiler is available since version 1.1[19]. The compiler design allows for interpreted and compiled code to run side-by-side, as well as decompilation to reoptimize and outputting generated bytecode as Java class files.
[edit] JRuby Programming
[edit] Ruby meets Java
JRuby is essentially the Ruby interpreter, except this version is written entirely in Java. JRuby features some of the same concepts, including object-oriented programming, and duck-typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs[22].
[edit] Calling Java from JRuby
One powerful feature of JRuby is its ability to invoke the classes of the Java Platform. To do this, one must first load JRuby's Java support, by calling "include Java" ("require 'java'" in earlier versions). The following example creates a Java JFrame
with a JLabel
:
include Java frame = javax.swing.JFrame.new() frame.getContentPane().add(javax.swing.JLabel.new('Hello, World!')) frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE) frame.pack() frame.set_visible(true)
JRuby also allows the user to call Java code using the more Ruby-like underscore method naming and to refer to JavaBean properties as attributes:
frame.content_pane.add label frame.visible = true
[edit] Calling JRuby from Java
JRuby can just as easily be called from Java, using either the JSR 223[23] Scripting for Java 6 or the Apache Bean Scripting framework. More information on this is available in the JRuby Wiki article.
[edit] Performance
JRuby supports interpreted mode, AOT mode, and JIT mode (the last two modes are available since version 1.1[19]). JRuby evolved from being several times slower than Ruby Reference implementation[24], to being several times faster[25]
[edit] Interpreted mode
In this mode, JRuby 1.0 was slower than the C Ruby reference[26]. For example, serving up Rails requests in the standard interpreted mode, JRuby was 50% to 70% slower than C Ruby 1.8. Since then, JRuby performance in interpreted mode has improved a lot. The JRuby team claims that JRuby 1.4 is 15%-20% faster in interpreted mode than Ruby MRI [27].
When using Ruby 1.9 (YARV) benchmarks on Java 6, interpreted JRuby 1.0 was 4 times slower than Ruby (including startup time).
[edit] Just-in-time compilation mode
JIT mode is available since JRuby 1.1. In performance benchmarks, JRuby is consistently 200% to 300% faster than C Ruby 1.8.6 [25] but still 15%-25% slower than C Ruby 1.9. However, the JRuby 1.1.6 version outperforms C Ruby 1.9 in some cases [28][29].
Also in a real Mongrel web server application, JRuby performance is better than Ruby (after the Virtual Machine has instantiated)[30].
[edit] See also
[edit] References
- ^ Jacki (2006-09-07). "Sun Welcomes JRuby Developers". On the Record. http://blogs.sun.com/ontherecord/entry/sun_welcomes_jruby_developers. Retrieved on 2006-09-09.
- ^ Ola Bini. "ThoughtWorks". On the Record. http://ola-bini.blogspot.com/2007/03/thoughtworks.html.
- ^ "JRuby performance benchmark". shootout.alioth.debian.org. 2008-09-14. http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=jruby&lang2=ruby. Retrieved on 2008-09-14.
- ^ a b Cangiano, Antonio (2007-03-12). "The Great Ruby Shootout". http://antoniocangiano.com/2007/12/03/the-great-ruby-shootout/. Retrieved on 2008-02-01.
- ^ Nutter, Charles (2008-04-25). "JRuby 1.1.1 in RedHat Fedora". http://headius.blogspot.com/2008/04/jruby-111-in-redhat-fedora.html. Retrieved on 2008-04-26.
- ^ "jruby". fedoraproject.org. https://admin.fedoraproject.org/pkgdb/packages/name/jruby. Retrieved on 2008-04-26.
- ^ "JRuby 1.1.3 Released". jruby.codehaus.org. 2008-07-19. http://docs.codehaus.org/display/JRUBY/2008/07/19/JRuby+1.1.3+Released. Retrieved on 2008-07-19. "Our goal is to put out point releases more frequently for the next several months (about 3-4 weeks a release). We want a more rapid release cycle to better address issues brought up by users of JRuby."
- ^ "Ruby Future Roundup: Ruby 1.9.0-5 Released, JRuby Skips 1.8.7". infoq.com. 2008-10-08. http://www.infoq.com/news/2008/10/ruby-future-roundup-1.9.0-5. Retrieved on 2008-12-06. "Most 1.8.7 features that came from 1.9.1 are to make transition from 1.8 to 1.9 series easier(...)users should switch directly to 1.9 rather then writing code that only works in 1.8.7 "
- ^ a b "Rails Support". JRuby Team. http://wiki.jruby.org/wiki/Rails_Support. Retrieved on 2008-02-17.
- ^ Nutter, Charles (2008-08-24). "Zero to Production in 15 Minutes". http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html. Retrieved on 2008-08-27.
- ^ 98.6% of the 2,807 Rails-specific test cases execute successfully; see JRuby 0.9.8 Released
- ^ "Success Stories". JRuby Wiki. 2008-01-29. http://wiki.jruby.org/wiki/Success_Stories. Retrieved on 2008-02-17.
- ^ "The University of Tokyo and Sun Microsystems Commence Joint Research Projects on High Performance Computing and Web-based Programming Languages". Sun Microsystems. 2008-02-27. http://www.sun.com/aboutsun/pr/2008-02/sunflash.20080227.5.xml. Retrieved on 2008-02-28.
- ^ see JSR 292
- ^ "Sub-Projects and Investigations". Sun Microsystems. 2007. http://openjdk.java.net/projects/mlvm/subprojects.html. Retrieved on 2008-02-06.
- ^ Rose, John (2008-08-26). "Happy International Invokedynamic Day!". http://blogs.sun.com/jrose/entry/international_invokedynamic_day. Retrieved on 2008-09-03.
- ^ Lorimer, R.J. (2008-09-01). "Dynamic Invocation Runs on OpenJDK". infoq.com. http://www.infoq.com/news/2008/09/invokedynamic_day. Retrieved on 2008-09-03.
- ^ Nutter, Charles (2008-09-11). "A First Taste of InvokeDynamic". http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html. Retrieved on 2008-09-13. "I managed to successfully wire InvokeDynamic directly into JRuby's dispatch process! Such excitement! The code is already in JRuby's trunk, and will ship with JRuby 1.1.5 (though it obviously will be disabled on JVMs without InvokeDynamic)."
- ^ a b c Nutter, Charles (2007-09-27). "The Compiler Is Complete". http://headius.blogspot.com/2007/09/compiler-is-complete.html. Retrieved on 2007-10-12.
- ^ Enebo, Tom (2008-08-28). "JRuby 1.1.4 Released". http://www.bloglines.com/blog/ThomasEEnebo/2008_8. Retrieved on 2009-02-25.
- ^ Enebo, Tom (2009-03-16). "JRuby 1.2.0 Released". JRuby Team. http://docs.codehaus.org/display/JRUBY/2009/03/16/JRuby+1.2.0+Released. Retrieved on 2009-03-17.
- ^ Fox, Joshua (2006-07-17). "Script your Java applications and efficiently reuse your Java libraries with this dynamic language". javaworld.com. http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html. Retrieved on 2008-04-26.
- ^ JSR 223: Scripting for the Java Platform Specification Request
- ^ Cangiano, Antonio (2007-02-19). "Ruby Implementations Shootout: Ruby vs Yarv vs JRuby vs Gardens Point Ruby .NET vs Rubinius vs Cardinal". http://antoniocangiano.com/2007/02/19/ruby-implementations-shootout-ruby-vs-yarv-vs-jruby-vs-gardens-point-ruby-net-vs-rubinius-vs-cardinal/. Retrieved on 2008-12-14.
- ^ a b Cangiano, Antonio (2008-12-09). "The Great Ruby Shootout (December 2008)". http://antoniocangiano.com/2008/12/09/the-great-ruby-shootout-december-2008/. Retrieved on 2008-12-14.
- ^ Nutter, Charles (2007-04-16). "Paving the Road to JRuby 1.0: Performance". http://headius.blogspot.com/2007/04/paving-road-to-jruby-10-performance.html. Retrieved on 2007-11-05.
- ^ Nutter, Charles (2008-04-27). "Promise and Peril for Alternative Ruby Impls". http://blog.headius.com/2008/04/promise-and-peril-for-alternative-ruby.html. Retrieved on 2008-12-06. "We now run faster than Ruby 1.8 in both interpreted and compiled modes, with interpreted being perhaps 15-20% faster and compiled being at least a few times faster, generally on par with Ruby 1.9"
- ^ Nutter, Charles (2008-11-23). "Noise Cancelling". http://blog.headius.com/2008/11/noise-cancelling.html. Retrieved on 2008-12-07. "A year ago, we were generally a bit slower than Ruby 1.8.6; this year, we're faster in most cases than Ruby 1.9."
- ^ Nutter, Charles (2008-02-16). "JRuby RC2 Released; What's Next?". http://headius.blogspot.com/2008/02/jruby-rc2-released-whats-next.html. Retrieved on 2008-02-17. "JRuby's performance regularly exceeds Ruby 1.8.6, and in many cases has started to exceed Ruby 1.9."
- ^ Sieger, Nick (2007-10-25). "JRuby on Rails: Fast Enough". http://blog.nicksieger.com/articles/2007/10/25/jruby-on-rails-fast-enough. Retrieved on 2007-10-28.
[edit] External links
- The JRuby home page
- The JRuby Wiki
- JRubyHub.com: The hub for all resources related to JRuby and JRuby on Rails (JRoR)
- JRubyonRails.de: JRuby on Rails Blog (german)
- Joshua Fox, "Ruby for the Java world", JavaWorld
- JRuby Roadmap for 2007
- The Great Ruby Shootout: JRuby compared to other Ruby VMs
- Article on JRuby at IBM DeveloperWorks
- Joshua Fox, "JRuby on Rails", JavaWorld
- Scripting on the Java platform, JavaWorld
- JRuby development in NetBeans
- Deploying a Rails Application in Tomcat
- Calling Ruby’s ActiveRecord from Java Using the Bean Scripting Framework
- Deploying JRuby on Rails application on Sun Java System Web Server 7
- Easy to install distribution of JRuby, Tomcat and Glassfish
- Arun's Flash Demo: First JRuby app in GlassFish V2
- First JRuby app in GlassFish V3
- JRuby on Rails Blog (german)
[edit] Media
- JRuby: The power of Java and Ruby at YouTube
- JavaOne 2007 Exploiting JRuby
- JavaOne 2007 JRuby on Rails
- Roumen's Ruby Flash Demo (Part One): JRuby on Rails in NetBeans
- Roumen's Ruby Flash Demo (Part Two): Advanced JRuby editing features in NetBeans
- Java Posse, Interview with Charles Oliver Nutter and Thomas Enebo about JRuby
|