JRuby
Developer(s) | Charles Oliver Nutter, Thomas Enebo, Ola Bini and Nick Sieger |
---|---|
Initial release | 2001 |
Stable release | 9.4.5.0
/ November 2, 2023[1] |
Repository | |
Written in | RubyandJava |
Operating system | Cross-platform |
Platform | Java Virtual Machine |
Type | Ruby programming language interpreter |
License | EPL/GPL/LGPL |
Website | www |
JRubyis an implementation of theRuby programming languageatop theJava Virtual Machine,written largely inJava.It isfree softwarereleased under a three-wayEPL/GPL/LGPLlicense. JRuby is tightly integrated withJavato allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code (similar toJythonfor the Python language).
JRuby's lead developers areCharles Oliver NutterandThomas Enebo,with many current and past contributors includingOla BiniandNick Sieger.In September 2006,Sun Microsystemshired Enebo and Nutter to work on JRuby full-time.[2]In June 2007,ThoughtWorkshired Ola Bini to work on Ruby and JRuby.[3]
In July 2009, the JRuby developers left Sun to continue JRuby development atEngine Yard.[4]In May 2012, Nutter and Enebo left Engine Yard to work on JRuby atRed Hat.[5]
History
[edit]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.6Ccode. 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[update]) core team of around six members.
JRuby 1.1 addedJust-in-time compilationandAhead-of-time compilationmodes to JRuby and was already faster in most cases than the then-current Ruby 1.8.7 reference implementation.[6]
JRuby packages are available for most platforms;Fedora 9was among the first to include it as a standard package at JRuby 1.1.1.[7][8]
In July 2009, the core JRuby developers at Sun Microsystems,Charles Oliver Nutter,Thomas EneboandNick Sieger,joinedEngine Yardto continue JRuby development.[4][9]In May 2012, Nutter and Enebo left Engine Yard to work on JRuby atRed Hat.[5]
JRuby has supported compatibility withRuby MRIversions 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.
The current version of JRuby (9.4.3.0) targets Ruby 3.1, though some 3.1 features are still in work.[10]
Ruby on Rails
[edit]JRuby has been able to run theRuby on Railsweb framework since version 0.9 (May 2006),[11][12]with the ability to executeRubyGemsandWEBrick.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.[13]Since then, developers have begun to use JRuby for Rails applications in production environments.[14]
Multiple virtual machine collaboration
[edit]On February 27, 2008,Sun Microsystemsand theUniversity of Tokyoannounced a joint-research project to implement a virtual machine capable of executing more than oneRubyor JRuby application on one interpreter.[15]
Dynamic invocation on Java Virtual Machines
[edit]JSR 292(Supporting Dynamically Typed Languages on the JavaTM Platform)[16]proposes:
- adding a new
invokedynamic
instruction at the JVM level, allowing method invocation using dynamictype checking, - dynamically changing classes and methods at runtime.
The Sun Open source projectMulti Language Virtual Machineaims to prototype this JSR.[17]The first working prototype, developed as a patch onOpenJDK,was announced and made available on end of August 2008.[18][19]
The JRuby team has implemented dynamic invocation into their codebase. Dynamic invocation initially shipped with the 1.1.5 release in a primitive form.[20]Version 1.7.0 enabled it by default on Java 8 builds.[21]
Release history
[edit]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.
Release | Release Date | Highlights |
---|---|---|
0.9 | August 1, 2006 | Rails support[11] |
1.1 | March 28, 2008 | Performs better than Ruby MRI 1.8.7[6] AOT modeandJIT mode[22] |
1.1.4 | August 28, 2008 | Refactored Java integration layer Beginning of Ruby 1.9 support FFIsubsystem for callingClibraries[23] |
1.2.0[24] | March 16, 2009 | JITcompiler for Ruby 1.9 PreliminaryAndroidsupport by theRubotoproject. |
1.3.0[25] | June 3, 2009 | JRuby runs in restricted environments better likeGAE/J |
1.4.0[26][27] | November 2, 2009 | Windows Native Launcher and Windows installer Ruby 1.8.7 support |
1.5.0[28] | May 12, 2010 | Native Launcher forUNIX-based platforms Ant support and Rake-Ant integration Updates to the standard library,RubyGems,andRSpec |
1.6.0[29] | March 15, 2011 | 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[21] | October 22, 2012 | Ruby 1.9.3 language is the default mode Support forinvokedynamic |
1.7.4[30] | May 16, 2013 | Experimental Ruby 2.0 support (most features andstdlibincluded) |
9.0.0.0[31] | July 22, 2015 | Ruby 2.x support New optimizing runtime NewPOSIX-friendly IO and Process Fully ported encoding/transcoding logic from MRI |
9.1.7.0[32] | January 11, 2017 | Fixed serious LinkageError when using multiple threads
Fixed several keyword argument issues Fixed several parser issues Reduced memory use of the JIT Update Psych to 2.2.2 Update jruby-openssl to 0.9.18 72 issues fixed |
9.2.0.0[33] | May 24, 2018 | Ruby 2.5 language support |
9.2.9.0[34] | October 30, 2019 | Ruby 2.5.7 language support |
9.3.2.0[35] | December 2, 2021 | Ruby 2.6.x language support |
9.3.3.0[36] | January 19, 2022 | Ruby 2.6.x language support |
9.3.4.0[37] | March 23, 2022 | Ruby 2.6.x language support |
9.4.0.0[38] | November 22, 2022 | Ruby 3.1 language support |
9.4.1.0[39] | February 7, 2023 | Ruby 3.1 language support |
9.4.2.0[40] | March 8, 2023 | Ruby 3.1 language support |
9.4.3.0[41] | June 7, 2023 | Ruby 3.1 language support |
Design
[edit]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 toJava 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 theinterpretedmode supported all Ruby's constructs, but a full AOT/JIT compiler is available since version 1.1.[22]The compiler design allows for interpreted and compiled code to run side-by-side, as well asdecompilationto reoptimize and outputting generated bytecode as Java class files.
Frameworks support
[edit]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 theInteractive Ruby Shell(irb) as Ruby MRI does.
TheNetbeans 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.[42][43] It is no longer included in NetBeans 7.0 and later.
Programming
[edit]Ruby meets Java
[edit]JRuby is similar to the standard Ruby interpreter except written inJava.JRuby features some of the same concepts, includingobject-oriented programming,anddynamic typingas Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs.[44]Java has significant footing in the development of web applications.
JRuby calling Java
[edit]One powerful feature of JRuby is its ability to invoke the classes of theJava 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.addjavax.swing.JLabel.new('Hello, World!')
frame.setDefaultCloseOperationjavax.swing.JFrame::EXIT_ON_CLOSE
frame.pack
frame.set_visibletrue
JRuby also allows the user to call Java code using the more Ruby-likeunderscore method namingand to refer toJavaBeanproperties as attributes:[dubious–discuss]
frame.content_pane.addlabel
frame.visible=true
Calling JRuby from Java
[edit]JRuby can just as easily be called from Java, using either theJSR 223[45]Scripting for Java 6 or theApache Bean Scriptingframework.
//Example using JSR 233 Scripting for Java 6
ScriptEngineManagermgr=newScriptEngineManager();
ScriptEnginerbEngine=mgr.getEngineByExtension("rb");
try{
rbEngine.eval("puts 'Hello World!'");
}catch(ScriptExceptionex){
ex.printStackTrace();
}
Performance
[edit]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 aJava Virtual Machineitself 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 aglobal interpreter lock(similarly toRubinius), therefore achieving full parallelism within a process, which Ruby MRI cannot achieve despite leveraging OS threads.
In a realMongrelweb serverapplication tested in 2007, JRuby performance is better than Ruby MRI 1.8, after the Java Virtual Machine had been instantiated.[46]
In a 2007 benchmark of Ruby implementations, JRuby was faster than Ruby MRI 1.8 in some tests, butYARVoutperformed both of them.[47]
As of April 2014, inThe Computer Language Benchmarks Game,JRuby 1.7.4 typically has the same performance as Ruby MRI 2.1.0, but uses more memory.[48][49]
See also
[edit]- GraalVM
- List of Java scripting languages
- ZK (framework)– an Ajax framework supporting JRuby
References
[edit]- ^"Releases · jruby/jruby".github.RetrievedDecember 26,2023.
- ^Jacki (September 7, 2006)."Sun Welcomes JRuby Developers".On the Record. Archived fromthe originalon August 29, 2012.RetrievedNovember 7,2013.
- ^Ola Bini (2007)."ThoughtWorks".On the Record.
- ^ab"Sun's JRuby Team Jumps Ship to Engine Yard".PCWorld.July 28, 2009.RetrievedJune 2,2012.[permanent dead link]
- ^ab"Red Hat lures in JRuby power pair".The Register.May 23, 2012.RetrievedJune 2,2012.
- ^abCangiano, Antonio (March 12, 2007)."The Great Ruby Shootout".RetrievedFebruary 1,2008.
- ^Nutter, Charles (April 25, 2008)."JRuby 1.1.1 in RedHat Fedora".RetrievedApril 26,2008.
- ^ "jruby".fedoraproject.org.RetrievedApril 26,2008.[permanent dead link]
- ^Nutter, Charles (July 28, 2009)."JRuby's Future at Engine Yard".Archived fromthe originalon July 31, 2009.RetrievedJuly 28,2009.
- ^"Unfinished Ruby 3.1 features".JRuby Team.RetrievedJune 13,2023.
- ^ab"Rails Support".JRuby Team. Archived fromthe originalon March 3, 2008.RetrievedFebruary 17,2008.
- ^Nutter, Charles (August 24, 2008)."Zero to Production in 15 Minutes".RetrievedAugust 27,2008.
- ^98.6% of the 2,807 Rails-specific test cases execute successfully; seeJRuby 0.9.8 ReleasedArchivedMay 22, 2015, at theWayback Machine
- ^"Success Stories".JRuby Wiki on GitHub. January 5, 2011.RetrievedMarch 16,2011.
- ^"The University of Tokyo and Sun Microsystems Commence Joint Research Projects on High Performance Computing and Web-based Programming Languages".Sun Microsystems.February 27, 2008.RetrievedFebruary 28,2008.
- ^see JSR 292
- ^"Sub-Projects and Investigations".Sun Microsystems.2007.RetrievedFebruary 6,2008.
- ^Rose, John (August 26, 2008)."Happy International Invokedynamic Day!".RetrievedSeptember 3,2008.
- ^Lorimer, R.J. (September 1, 2008)."Dynamic Invocation Runs on OpenJDK".infoq.RetrievedSeptember 3,2008.
- ^Nutter, Charles (September 11, 2008)."A First Taste of InvokeDynamic".RetrievedSeptember 13,2008.
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).
- ^ab"JRuby 1.7.0 Released".JRuby Team. October 22, 2012. Archived fromthe originalon October 25, 2012.RetrievedOctober 23,2011.
- ^abNutter, Charles (September 27, 2007)."The Compiler Is Complete".RetrievedOctober 12,2007.
- ^Enebo, Tom (August 28, 2008)."JRuby 1.1.4 Released".RetrievedFebruary 25,2009.[permanent dead link]
- ^Enebo, Tom (March 16, 2009)."JRuby 1.2.0 Released".JRuby Team. Archived fromthe originalon March 19, 2009.RetrievedMarch 17,2009.
- ^Enebo, Tom (June 3, 2009)."JRuby 1.3.0 Released".JRuby Team. Archived fromthe originalon June 12, 2009.RetrievedJune 3,2009.
- ^"JRuby 1.4.0 Released".JRuby Team. November 2, 2009.RetrievedNovember 3,2009.
- ^"JRuby 1.4.0 Released".adtmag. November 10, 2009. Archived fromthe originalon November 15, 2009.RetrievedNovember 21,2009.
- ^"JRuby 1.5.0 Released".JRuby Team. May 12, 2010. Archived fromthe originalon May 16, 2010.RetrievedMay 12,2010.
- ^"JRuby 1.6.0 Released".JRuby Team. March 15, 2011.RetrievedMarch 15,2011.
- ^"JRuby 1.7.4 Released".JRuby Team. May 16, 2013.RetrievedMay 19,2013.
- ^"JRuby 9.0.0.0 Released".JRuby Team. July 22, 2015. Archived fromthe originalon July 24, 2015.RetrievedJuly 25,2015.
- ^"JRuby 9.1.7.0 Released — JRuby.org".jruby.org.Archived fromthe originalon January 16, 2017.RetrievedJanuary 13,2017.
- ^"JRuby 9.2.0.0 Released".Archived fromthe originalon May 27, 2018.RetrievedMay 27,2018.
- ^"JRuby 9.2.9.0 Released".RetrievedNovember 5,2019.
- ^"JRuby 9.3.2.0 Released".RetrievedJanuary 11,2022.
- ^"JRuby 9.3.3.0 Released".RetrievedJanuary 19,2022.
- ^"JRuby 9.3.4.0 Released".RetrievedMarch 23,2022.
- ^"JRuby 9.4.0.0 Released".RetrievedDecember 1,2022.
- ^"JRuby 9.4.1.0 Released".RetrievedFebruary 15,2023.
- ^"JRuby 9.4.2.0 Released".RetrievedJune 13,2023.
- ^"JRuby 9.4.3.0 Released".RetrievedJune 13,2023.
- ^"Ruby & JRuby Support Available in NetBeans IDE".netbeans.org. March 6, 2007. Archived fromthe originalon July 19, 2011.RetrievedJuly 4,2009.
- ^"Ruby brightens the NetBeans platform".infoworld. March 1, 2007.RetrievedJuly 4,2008.
- ^Fox, Joshua (July 17, 2006)."Ruby for the Java world".JavaWorld.RetrievedJuly 26,2020.
- ^JSR 223: Scripting for the Java Platform Specification Request
- ^Sieger, Nick (October 25, 2007)."JRuby on Rails: Fast Enough".RetrievedOctober 28,2007.
- ^Cangiano, Antonio (December 3, 2007)."The Great Ruby Shootout".RetrievedFebruary 2,2014.
- ^ "JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (1)".Archived fromthe originalon January 23, 2015.RetrievedFebruary 2,2014.
- ^"JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (2)".Archived fromthe originalon July 23, 2014.RetrievedFebruary 2,2014.
Further reading
[edit]- Kutner, Joe (August 22, 2012).Deploying with JRuby: Deliver Scalable Web Apps using the JVM(First ed.).Pragmatic Bookshelf.p. 200.ISBN978-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.pp.300.ISBN978-1934356654.
- Edelson, Justin; Liu, Henry (November 18, 2008).JRuby Cookbook(First ed.).O'Reilly Media.pp.222.ISBN978-0-596-51980-3.
- Bini, Ola (September 24, 2007).Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java(First ed.).Apress.pp.330.ISBN978-1-59059-881-8.
- Kutler, Chris; Leonard, Brian (May 4, 2009).NetBeans Ruby and Rails IDE with JRuby(First ed.).Apress.p. 160.ISBN978-1-4302-1636-0.Archived fromthe originalon August 27, 2012.RetrievedJuly 12,2009.