JRuby
From Wikipedia, the free encyclopedia
| JRuby | |
|---|---|
| Developed by | Charles Nutter, Thomas Enebo, Ola Bini and Nick Sieger |
| Latest release | 1.1.2 / May 27, 2008 |
| Written in | Ruby and Java |
| OS | Cross-platform |
| Platform | Java Virtual Machine |
| Genre | Ruby programming language interpreter |
| License | CPL/GPL/LGPL |
| Website | http://jruby.codehaus.org/ |
JRuby is a Java implementation of the Ruby interpreter, 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 is faster in most cases than the current Ruby 1.8.6 reference implementation[3][4].
JRuby 1.1.1 is stated to be packaged in Fedora 9[5][6].
[edit] Rails
JRuby has supported Ruby on Rails since version 0.9 (May 2006) [7], 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 passes nearly all of Rails' own test cases[8]. Since then, developers have begun to use JRuby for Rails applications in production environments [9].
[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[10].
[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 now available in trunk and improving[11]. 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[12].
[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[13] Scripting for Java 6 or the Apache Bean Scripting framework. More information on this is available in the JRuby Wiki.
[edit] Performance
JRuby supports interpreted mode, AOT mode, and JIT mode (the last two modes are available since version 1.1[11]).
[edit] Interpreted mode
In this mode, JRuby is slower than the C Ruby Reference implementation[14].
For example, serving up Rails requests in the standard interpreted mode, JRuby is 50% to 70% slower than C Ruby 1.8.
When using Ruby 1.9 (YARV) benchmarks on Java 6, JRuby is 4 times slower than Ruby (including startup time)[15].
[edit] Just-in-time compilation mode
JIT mode is available since JRuby 1.1. In performance benchmarks, JRuby is faster in most cases than C Ruby 1.8 [16][3] [17] but still slower than C Ruby 1.9[4]. However, the JRuby Team claims that the performance of the 1.1 version is approaching, or starting to exceed C Ruby 1.9 in some benchmarks [18].
Also in a real Mongrel web server application, JRuby performance is better than Ruby (after the Virtual Machine has instantiated)[19].
[edit] See also
- XRuby
- BeanShell (interprets Java directly)
- Groovy
- JACL
- Jython
- PHP
- Ruby
- YARV
- ZK (an Ajax framework supporting JRuby)
- Monkeybars
- Da Vinci Machine
[edit] References
- ^ Jacki (2006-09-07). Sun Welcomes JRuby Developers. On the Record. Retrieved on 2006-09-09.
- ^ Ola Bini. ThoughtWorks. On the Record.
- ^ a b JRuby performance benchmark. shootout.alioth.debian.org (2007-11-05). Retrieved on 2007-11-05.
- ^ a b Cangiano, Antonio (2007-03-12). The Great Ruby Shootout. Retrieved on 2008-02-01.
- ^ Nutter, Charles (2008-04-25). JRuby 1.1.1 in RedHat Fedora. Retrieved on 2008-04-26.
- ^ jruby. fedoraproject.org. Retrieved on 2008-04-26.
- ^ Rails Support. JRuby Team. Retrieved on 2008-02-17.
- ^ 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). 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). Retrieved on 2008-02-28.
- ^ a b Nutter, Charles (2007-09-27). The Compiler Is Complete. Retrieved on 2007-10-12.
- ^ Script your Java applications and efficiently reuse your Java libraries with this dynamic language. javaworld.com (2006-07-17). Retrieved on 2008-04-26.
- ^ JSR 223: Scripting for the Java Platform Specification Request
- ^ Nutter, Charles (2007-04-16). Paving the Road to JRuby 1.0: Performance. Retrieved on 2007-11-05.
- ^ when removing a few specific test cases, it is only 50% slower than Ruby 1.8: thread_create_join, sieve, count_words, mandelbrot, and answer, 5 tests out of 39
- ^ Nutter, Charles (2007-10-12). Performance Update. Retrieved on 2007-10-12.
- ^ Nutter, Charles (2007-10-12). Performance Update. Retrieved on 2007-10-12.
- ^ Nutter, Charles (2008-02-16). JRuby RC2 Released; What's Next?. 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. 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)
- JRuby Roadmap for 2007
- 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
- The Great Ruby Shootout: JRuby compared to other Ruby VMs
- Article on JRuby at IBM DeveloperWorks
- JavaOne 2007 Exploiting JRuby
- JavaOne 2007 JRuby on Rails
- Joshua Fox, "JRuby on Rails", JavaWorld
- Java Posse, Interview with Charles Oliver Nutter and Thomas Enebo about JRuby
- JRuby development in NetBeans
- Deploying a Rails Application in Tomcat
- Calling Ruby’s ActiveRecord from Java Using the Bean Scripting Framework
- Arun's Flash Demo: First JRuby app in GlassFish V2
- First JRuby app in GlassFish V3
- Scripting on the Java platform, JavaWorld
- Deploying JRuby on Rails application on Sun Java System Web Server 7
- Easy to install distribution of JRuby, Tomcat and Glassfish
|
||||||||||||||

