JRuby
Developer(s) | Charles Oliver Nutter, Thomas Enebo, Ola Bini and Nick Sieger |
---|---|
Initial release | 2001 |
Stable release |
9.1.6.0
/ November 9, 2016 |
Development status | Active |
Written in | Ruby and Java |
Operating system | Cross-platform |
Platform | Java Virtual Machine |
Type | Ruby programming language interpreter |
License | EPL/GPL/LGPL |
Website |
www |
JRuby is an implementation of the Ruby programming language atop the Java Virtual Machine, written largely in Java. It is free software released under a three-way EPL/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 (similar to Jython for the Python language).
JRuby's lead developers are Charles Oliver Nutter and Thomas Enebo, with many current and past contributors including Ola Bini and Nick Sieger. 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]
In July 2009, the JRuby developers left Sun to continue JRuby development at Engine Yard.[3] In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.[4]
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 (2012) core team of around six members.
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 then-current Ruby 1.8.7 reference implementation.[5]
JRuby packages are available for most platforms; Fedora 9 was among the first to include it as a standard package at JRuby 1.1.1.[6][7]
In July 2009, the core JRuby developers at Sun Microsystems, Charles Oliver Nutter, Thomas Enebo and Nick Sieger, joined Engine Yard to continue JRuby development.[3][8] In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.[4]
JRuby has supported compatibility with Ruby MRI versions 1.6 through 1.9.3. JRuby 1.0 supported Ruby 1.8.6, with JRuby 1.4.0 updating that compatibility to Ruby 1.8.7. JRuby 1.6.0 added simultaneous support for Ruby 1.9.2, with JRuby 1.7.0 making Ruby 1.9.3 the default execution mode (Ruby 1.8.7 compatibility is available via a command-line flag). JRuby 9.0.0.0 added support for Ruby 2.2.
Ruby on Rails
JRuby has been able to run the Ruby on Rails web framework 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's own test cases.[11] Since then, developers have begun to use JRuby for Rails applications in production environments.[12]
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]
Dynamic invocation on Java Virtual Machines
JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform) [14] proposes:
- adding a new
invokedynamic
instruction at the JVM level, allowing method invocation using dynamic type checking, - dynamically changing classes and methods at runtime.
The Sun Open source project Multi Language Virtual Machine aims 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 implemented dynamic invocation into their codebase. Dynamic invocation initially shipped with the 1.1.5 release in a primitive form.[18] Version 1.7.0 enabled it by default on Java 8 builds.[19]
Release history
This table presents only releases that present significant steps in JRuby history, aside from versions that mainly fixed bugs and improved performance. Performance improvements are also not shown in the table below, as every release has usually brought such improvements.
The project gets coordinated here at codehaus.org, you can find also the official release history resp. plan there.
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[5] AOT mode and JIT mode[20] |
1.1.4 | 2008-08-28 | Refactored Java integration layer Beginning of Ruby 1.9 support FFI subsystem for calling C libraries[21] |
1.2.0[22] | 2009-03-16 | JIT compiler for Ruby 1.9 Preliminary Android support by the Ruboto project. |
1.3.0[23] | 2009-06-03 | JRuby runs in restricted environments better like GAE/J |
1.4.0[24][25] | 2009-11-02 | Windows Native Launcher and Windows installer Ruby 1.8.7 support |
1.5.0[26] | 2010-05-12 | Native Launcher for UNIX-based platforms Ant support and Rake-Ant integration Updates to the standard library, RubyGems, and RSpec |
1.6.0[27] | 2011-03-15 | Ruby 1.9.2 language and API compatibility Built-in profiler Experimental support for C extensions based on Ruby’s C API |
1.7.0[19] | 2012-10-22 | Ruby 1.9.3 language is the default mode Support for invokedynamic |
1.7.4[28] | 2013-05-16 | Experimental Ruby 2.0 support (most features and stdlib included) |
9.0.0.0[29] | 2015-07-22 | Ruby 2.x support New optimizing runtime New POSIX-friendly IO and Process |
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.[20] 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.
Frameworks support
JRuby has built-in support for Rails, RSpec, Rake, and RubyGems. It embeds an FFI subsystem to allow the use of C libraries bundled as gems. It also allows launching the Interactive Ruby Shell (irb) as Ruby MRI does.
The Netbeans Ruby Pack, available in NetBeans 6, allows IDE development with Ruby and JRuby, as well as Ruby on Rails for the two implementations of Ruby.[30][31] It is no longer included in NetBeans 7.0 and later.
Programming
Ruby meets Java
JRuby is similar to the standard Ruby interpreter except written in Java. JRuby features some of the same concepts, including object-oriented programming, and dynamic-typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs.[32] Java has significant footing in the development of web applications.
JRuby calling Java
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 "require 'java'". The following example creates a Java JFrame
with a JLabel
:
require '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
Calling JRuby from Java
JRuby can just as easily be called from Java, using either the JSR 223[33] Scripting for Java 6 or the Apache Bean Scripting framework. More information on this is available in the JRuby Wiki article.
//Example using JSR 233 Scripting for Java 6
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine rbEngine = mgr.getEngineByExtension("rb");
try {
rbEngine.eval("puts 'Hello World!'");
} catch (ScriptException ex) {
ex.printStackTrace();
}
Performance
According to some benchmarks, JRuby is faster than alternatives. Since implementations vary in how much code is loaded before execution, different methods of measuring speed can lead to biased interpretations of performance advantages. The time it takes for a Java Virtual Machine itself to load is often excluded from execution times when calculating benchmarks.
JRuby has the significant architectural advantage to be able to leverage JVM threads without being constrained by a global interpreter lock (similarly to Rubinius), therefore achieving full parallelism within a process, which Ruby MRI cannot achieve despite leveraging OS threads.
In a real Mongrel web server application tested in 2007, JRuby performance is better than Ruby MRI 1.8, after the Java Virtual Machine had been instantiated.[34]
In a 2007 benchmark of Ruby implementations, JRuby was faster than Ruby MRI 1.8 in some tests, but YARV outperformed both of them.[35]
As of April 2014, in the Computer Language Benchmarks Game, JRuby 1.7.4 typically has the same performance as Ruby MRI 2.1.0, but uses more memory.[36][37]
See also
- List of Java scripting languages
- ZK (framework) – an Ajax framework supporting JRuby
- Monkeybars Framework
- Da Vinci Machine
References
- ↑ Jacki (2006-09-07). "Sun Welcomes JRuby Developers". On the Record. Retrieved 2013-11-07.
- ↑ Ola Bini. "ThoughtWorks". On the Record.
- 1 2 "Sun's JRuby Team Jumps Ship to Engine Yard". PCWorld. 2009-07-28. Retrieved 2012-06-02.
- 1 2 "Red Hat lures in JRuby power pair". The Register. 2012-05-23. Retrieved 2012-06-02.
- 1 2 Cangiano, Antonio (2007-03-12). "The Great Ruby Shootout". Retrieved 2008-02-01.
- ↑ Nutter, Charles (2008-04-25). "JRuby 1.1.1 in RedHat Fedora". Retrieved 2008-04-26.
- ↑ "jruby". fedoraproject.org. Retrieved 2008-04-26.
- ↑ Nutter, Charles (2009-07-28). "JRuby's Future at Engine Yard". Retrieved 2009-07-28.
- 1 2 "Rails Support". JRuby Team. Retrieved 2008-02-17.
- ↑ Nutter, Charles (2008-08-24). "Zero to Production in 15 Minutes". Retrieved 2008-08-27.
- ↑ 98.6% of the 2,807 Rails-specific test cases execute successfully; see JRuby 0.9.8 Released Archived May 22, 2015, at the Wayback Machine.
- ↑ "Success Stories". JRuby Wiki on GitHub. 2011-01-05. Retrieved 2011-03-16.
- ↑ "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 2008-02-28.
- ↑ see JSR 292
- ↑ "Sub-Projects and Investigations". Sun Microsystems. 2007. Retrieved 2008-02-06.
- ↑ Rose, John (2008-08-26). "Happy International Invokedynamic Day!". Retrieved 2008-09-03.
- ↑ Lorimer, R.J. (2008-09-01). "Dynamic Invocation Runs on OpenJDK". infoq.com. Retrieved 2008-09-03.
- ↑ Nutter, Charles (2008-09-11). "A First Taste of InvokeDynamic". Retrieved 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).
- 1 2 "JRuby 1.7.0 Released". JRuby Team. 2012-10-22. Retrieved 2011-10-23.
- 1 2 Nutter, Charles (2007-09-27). "The Compiler Is Complete". Retrieved 2007-10-12.
- ↑ Enebo, Tom (2008-08-28). "JRuby 1.1.4 Released". Retrieved 2009-02-25.
- ↑ Enebo, Tom (2009-03-16). "JRuby 1.2.0 Released". JRuby Team. Retrieved 2009-03-17.
- ↑ Enebo, Tom (2009-06-03). "JRuby 1.3.0 Released". JRuby Team. Retrieved 2009-06-03.
- ↑ "JRuby 1.4.0 Released". JRuby Team. 2009-11-02. Retrieved 2009-11-03.
- ↑ "JRuby 1.4.0 Released". adtmag.com. 2009-11-10. Retrieved 2009-11-21.
- ↑ "JRuby 1.5.0 Released". JRuby Team. 2010-05-12. Retrieved 2010-05-12.
- ↑ "JRuby 1.6.0 Released". JRuby Team. 2011-03-15. Retrieved 2011-03-15.
- ↑ "JRuby 1.7.4 Released". JRuby Team. 2013-05-16. Retrieved 2013-05-19.
- ↑ "JRuby 9.0.0.0 Released". JRuby Team. 2015-07-22. Retrieved 2015-07-25.
- ↑ "Ruby & JRuby Support Available in NetBeans IDE". netbeans.org. 2007-03-06. Retrieved 2009-07-04.
- ↑ "Ruby brightens the NetBeans platform". infoworld.com. 2007-03-01. Retrieved 2008-07-04.
- ↑ Fox, Joshua (2006-07-17). "Script your Java applications and efficiently reuse your Java libraries with this dynamic language". JavaWorld. Retrieved 2008-04-26.
- ↑ JSR 223: Scripting for the Java Platform Specification Request
- ↑ Sieger, Nick (2007-10-25). "JRuby on Rails: Fast Enough". Retrieved 2007-10-28.
- ↑ Cangiano, Antonio (2007-12-03). "The Great Ruby Shootout". Retrieved 2014-02-02.
- ↑ "JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (1)". Retrieved 2014-02-02.
- ↑ "JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (2)". Retrieved 2014-02-02.
Further reading
- Kutner, Joe (August 22, 2012). "Deploying with JRuby: Deliver Scalable Web Apps using the JVM" (First ed.). Pragmatic Bookshelf: 200. ISBN 978-1934356975.
- O Nutter, Charles; Enebo, Thomas; Sieger, Nick; Bini, Ola; Dees, Ian (February 4, 2011). "Using JRuby: Bringing Ruby to Java" (First ed.). Pragmatic Bookshelf: 300. ISBN 978-1934356654.
- Edelson, Justin; Liu, Henry (November 18, 2008). "JRuby Cookbook" (First ed.). O'Reilly Media: 222. ISBN 0-596-51980-X.
- Bini, Ola (September 24, 2007). "Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java" (First ed.). Apress: 330. ISBN 1-59059-881-4.
- Kutler, Chris; Leonard, Brian (May 4, 2009). "NetBeans Ruby and Rails IDE with JRuby" (First ed.). Apress: 160. ISBN 1-4302-1636-0.