JRuby explained

JRuby
Developer:Charles Oliver Nutter, Thomas Enebo, Ola Bini and Nick Sieger
Latest Release Version:9.4.5.0
Latest Release Date:[1]
Programming Language:Ruby and Java
Operating System:Cross-platform
Platform:Java Virtual Machine
Genre:Ruby programming language interpreter
License:EPL/GPL/LGPL

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.[2] In June 2007, ThoughtWorks hired Ola Bini to work on Ruby and JRuby.[3]

In July 2009, the JRuby developers left Sun to continue JRuby development at Engine Yard.[4] In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.[5]

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 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.[6]

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.[7] [8]

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.[4] [9] In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.[5]

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.

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

JRuby has been able to run the Ruby on Rails web framework since version 0.9 (May 2006),[11] [12] 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.[13] Since then, developers have begun to use JRuby for Rails applications in production environments.[14]

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.[15]

Dynamic invocation on Java Virtual Machines

JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform)[16] proposes:

The Sun Open source project Multi Language Virtual Machine aims to prototype this JSR.[17] The first working prototype, developed as a patch on OpenJDK, 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

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.

width=60Releasewidth=110Release Datewidth=500Highlights
0.9August 1, 2006Rails support
1.1March 28, 2008Performs better than Ruby MRI 1.8.7
AOT mode and JIT mode
1.1.4August 28, 2008Refactored Java integration layer
Beginning of Ruby 1.9 support
FFI subsystem for calling C libraries[22]
1.2.0[23] March 16, 2009JIT compiler for Ruby 1.9
Preliminary Android support by the Ruboto project.
1.3.0[24] June 3, 2009JRuby runs in restricted environments better like GAE/J
1.4.0[25] [26] November 2, 2009Windows Native Launcher and Windows installer
Ruby 1.8.7 support
1.5.0[27] May 12, 2010Native Launcher for UNIX-based platforms
Ant support and Rake-Ant integration
Updates to the standard library, RubyGems, and RSpec
1.6.0[28] March 15, 2011Ruby 1.9.2 language and API compatibility
Built-in profiler
Experimental support for C extensions based on Ruby’s C API
1.7.0October 22, 2012Ruby 1.9.3 language is the default mode
Support for invokedynamic
1.7.4[29] May 16, 2013Experimental Ruby 2.0 support (most features and stdlib included)
9.0.0.0[30] July 22, 2015Ruby 2.x support
New optimizing runtime
New POSIX-friendly IO and ProcessFully ported encoding/transcoding logic from MRI
9.1.7.0[31] January 11, 2017Fixed serious LinkageError when using multiple threadsFixed 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[32] May 24, 2018Ruby 2.5 language support
9.2.9.0[33] October 30, 2019Ruby 2.5.7 language support
9.3.2.0[34] December 2, 2021Ruby 2.6.x language support
9.3.3.0[35] January 19, 2022Ruby 2.6.x language support
9.3.4.0[36] March 23, 2022Ruby 2.6.x language support
9.4.0.0[37] November 22, 2022Ruby 3.1 language support
9.4.1.0[38] February 7, 2023Ruby 3.1 language support
9.4.2.0[39] March 8, 2023Ruby 3.1 language support
9.4.3.0[40] June 7, 2023Ruby 3.1 language support

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.[41] 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.[42] [43] 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.[44] 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.newframe.getContentPane.add javax.swing.JLabel.new('Hello, World!')frame.setDefaultCloseOperation javax.swing.JFrame::EXIT_ON_CLOSEframe.packframe.set_visible trueJRuby 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 labelframe.visible = true

Calling JRuby from Java

JRuby can just as easily be called from Java, using either the JSR 223[45] Scripting for Java 6 or the Apache Bean Scripting framework.

//Example using JSR 233 Scripting for Java 6ScriptEngineManager mgr = new ScriptEngineManager;ScriptEngine rbEngine = mgr.getEngineByExtension("rb");try catch (ScriptException ex)

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.[46]

In a 2007 benchmark of Ruby implementations, JRuby was faster than Ruby MRI 1.8 in some tests, but YARV outperformed both of them.[47]

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.[48] [49]

See also

Further reading

Notes and References

  1. Web site: Releases · jruby/jruby . github.com . December 26, 2023.
  2. Web site: Sun Welcomes JRuby Developers . November 7, 2013 . Jacki . September 7, 2006 . On the Record . https://web.archive.org/web/20120829225411/https://blogs.oracle.com/ontherecord/entry/sun_welcomes_jruby_developers . August 29, 2012 . dead .
  3. Web site: ThoughtWorks . Ola Bini. 2007 . On the Record.
  4. Sun's JRuby Team Jumps Ship to Engine Yard . June 2, 2012. July 28, 2009. PCWorld.
  5. Web site: Red Hat lures in JRuby power pair . June 2, 2012 . May 23, 2012. The Register.
  6. Web site: The Great Ruby Shootout. March 12, 2007. Cangiano. Antonio. February 1, 2008.
  7. Web site: JRuby 1.1.1 in RedHat Fedora. April 25, 2008. Nutter. Charles. April 26, 2008.
  8. Web site: jruby. fedoraproject.org. April 26, 2008.
  9. Web site: Nutter. Charles. JRuby's Future at Engine Yard. July 28, 2009. July 28, 2009. https://web.archive.org/web/20090731123454/http://www.engineyard.com/blog/2009/jrubys-future-at-engine-yard/. July 31, 2009. dead.
  10. Web site: Unfinished Ruby 3.1 features. JRuby Team. June 13, 2023.
  11. Web site: Rails Support. JRuby Team. February 17, 2008. March 3, 2008. https://web.archive.org/web/20080303021232/http://wiki.jruby.org/wiki/Rails_Support. dead.
  12. Web site: Zero to Production in 15 Minutes. Nutter. Charles. August 24, 2008. August 27, 2008.
  13. 98.6% of the 2,807 Rails-specific test cases execute successfully; see JRuby 0.9.8 Released
  14. Web site: Success Stories. JRuby Wiki on GitHub. January 5, 2011. March 16, 2011.
  15. Web site: 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. February 28, 2008.
  16. http://www.jcp.org/en/jsr/detail?id=292 see JSR 292
  17. Web site: Sub-Projects and Investigations. 2007. Sun Microsystems. February 6, 2008.
  18. Web site: Happy International Invokedynamic Day!. August 26, 2008. Rose. John. September 3, 2008.
  19. Web site: Dynamic Invocation Runs on OpenJDK. Lorimer. R.J.. infoq.com. September 1, 2008. September 3, 2008.
  20. Web site: A First Taste of InvokeDynamic. Nutter. Charles. 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).. September 11, 2008. September 13, 2008.
  21. Web site: JRuby 1.7.0 Released. JRuby Team. October 22, 2012. October 23, 2011. October 25, 2012. https://web.archive.org/web/20121025001231/http://www.jruby.org/2012/10/22/jruby-1-7-0.html. dead.
  22. Web site: JRuby 1.1.4 Released . Enebo . Tom . August 28, 2008 . February 25, 2009.
  23. Web site: JRuby 1.2.0 Released . Enebo . Tom . JRuby Team . March 16, 2009 . March 17, 2009 . https://web.archive.org/web/20090319000144/http://docs.codehaus.org/display/JRUBY/2009/03/16/JRuby+1.2.0+Released . March 19, 2009 . dead.
  24. Web site: JRuby 1.3.0 Released . Enebo . Tom . JRuby Team . June 3, 2009 . June 3, 2009 . https://web.archive.org/web/20090612104551/http://docs.codehaus.org/display/JRUBY/2009/06/03/JRuby+1.3.0+Released . June 12, 2009 . dead.
  25. Web site: JRuby 1.4.0 Released. JRuby Team. November 2, 2009. November 3, 2009.
  26. Web site: JRuby 1.4.0 Released. adtmag.com. November 10, 2009. November 21, 2009.
  27. Web site: JRuby 1.5.0 Released. JRuby Team. May 12, 2010. May 12, 2010. May 16, 2010. https://web.archive.org/web/20100516225724/http://jruby.org/2010/05/12/jruby-1-5-0. dead.
  28. Web site: JRuby 1.6.0 Released . JRuby Team. March 15, 2011. March 15, 2011.
  29. Web site: JRuby 1.7.4 Released . JRuby Team. May 16, 2013. May 19, 2013.
  30. Web site: JRuby 9.0.0.0 Released . JRuby Team. July 22, 2015. July 25, 2015.
  31. Web site: JRuby 9.1.7.0 Released — JRuby.org. jruby.org. January 13, 2017.
  32. Web site: JRuby 9.2.0.0 Released. May 27, 2018. May 27, 2018. https://web.archive.org/web/20180527202544/http://jruby.org/2018/05/24/jruby-9-2-0-0.html. dead.
  33. Web site: JRuby 9.2.9.0 Released. November 5, 2019.
  34. Web site: JRuby 9.3.2.0 Released. January 11, 2022.
  35. Web site: JRuby 9.3.3.0 Released. January 19, 2022.
  36. Web site: JRuby 9.3.4.0 Released. March 23, 2022.
  37. Web site: JRuby 9.4.0.0 Released. December 1, 2022.
  38. Web site: JRuby 9.4.1.0 Released. February 15, 2023.
  39. Web site: JRuby 9.4.2.0 Released. June 13, 2023.
  40. Web site: JRuby 9.4.3.0 Released. June 13, 2023.
  41. Web site: The Compiler Is Complete. September 27, 2007. Nutter. Charles. October 12, 2007.
  42. Web site: Ruby & JRuby Support Available in NetBeans IDE. March 6, 2007. netbeans.org. July 4, 2009.
  43. Web site: Ruby brightens the NetBeans platform. March 1, 2007. infoworld.com. July 4, 2008.
  44. Web site: Fox . Joshua . July 17, 2006 . mdy . Ruby for the Java world . . July 26, 2020.
  45. http://jcp.org/aboutJava/communityprocess/final/jsr223/index.html JSR 223: Scripting for the Java Platform Specification Request
  46. Web site: JRuby on Rails: Fast Enough. October 25, 2007. Sieger. Nick. October 28, 2007.
  47. Web site: The Great Ruby Shootout. December 3, 2007. Cangiano. Antonio. February 2, 2014.
  48. Web site: JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (1). February 2, 2014. https://web.archive.org/web/20150123023501/http://benchmarksgame.alioth.debian.org/u64q/jruby.html. January 23, 2015. dead.
  49. Web site: JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (2) . February 2, 2014 . https://web.archive.org/web/20140723042024/http://benchmarksgame.alioth.debian.org/u64/jruby.php . July 23, 2014 . dead.