Jump to content

JRuby

From Alfawiki
JRuby
Company typeFree software
IndustrySoftware development
Founded2001
FounderJan Arne Petersen
Key people
Charles Oliver Nutter, Thomas Enebo, Ola Bini, Nick Sieger
ProductsRuby interpreter for JVM
Websitewww.jruby.org

JRuby represents an implementation of the Ruby programming language designed to run on the Java Virtual Machine, predominantly developed using Java. Distributed as free software, it is licensed under the EPL, GPL, and LGPL. JRuby offers deep integration with Java, allowing the Ruby interpreter to be embedded within Java applications and facilitating seamless two-way interaction between Ruby and Java code.

Key figures in its development include Charles Oliver Nutter and Thomas Enebo, with significant contributions from developers like Ola Bini and Nick Sieger. In September 2006, Sun Microsystems brought Enebo and Nutter on board as full-time JRuby developers. Subsequently, in June 2007, ThoughtWorks hired Ola Bini to further enhance Ruby and JRuby efforts.

By July 2009, the core JRuby team transitioned from Sun Microsystems to Engine Yard to continue its development initiatives. Later, in May 2012, Nutter and Enebo joined Red Hat to advance JRuby’s evolution.

History

Originating in 2001, JRuby was developed by Jan Arne Petersen as a direct port of Ruby 1.6’s C source code. Following the release of Ruby 1.8.6, JRuby began aligning its functionality and behavior with the newer version. Over time, numerous contributors expanded the project, culminating in a core team of approximately six members by 2012.

The release of JRuby 1.1 marked the introduction of Just-in-time (JIT) and Ahead-of-time (AOT) compilation techniques, resulting in performance that generally exceeded that of Ruby 1.8.7. It became available across major operating systems, with Fedora 9 being among the earliest distributions to include JRuby 1.1.1 as part of its standard packages.

In July 2009, principal JRuby developers—Charles Oliver Nutter, Thomas Enebo, and Nick Sieger—moved from Sun Microsystems to Engine Yard to further develop JRuby. By May 2012, Nutter and Enebo transitioned to Red Hat to continue their contributions.

JRuby has maintained compatibility with Ruby MRI versions ranging from 1.6 through 1.9.3: version 1.0 corresponded to Ruby 1.8.6; version 1.4 matched Ruby 1.8.7; version 1.6 introduced support for Ruby 1.9.2; and version 1.7 set Ruby 1.9.3 as its default while retaining backward compatibility via configuration options. The introduction of JRuby 9.0 brought support for Ruby 2.2, with the latest release (9.4.3.0) targeting compatibility with Ruby 3.1, although some features remain under development.

Ruby on Rails

Starting with version 0.9 in May 2006, JRuby enabled execution of the Ruby on Rails framework alongside supporting tools such as RubyGems and WEBrick servers. After key developers joined Sun Microsystems, both Rails compatibility and performance saw significant improvements. With JRuby 1.0 successfully passing nearly all Rails test suites, it gained adoption for production Rails applications by users seeking improved speed and tighter JVM integration.

Multiple virtual machine collaboration

On February 27, 2008, Sun Microsystems partnered with the University of Tokyo to initiate a research project aimed at creating a virtual machine capable of running multiple instances of Ruby or JRuby applications concurrently within a single interpreter environment.

Dynamic invocation on Java Virtual Machines

JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform) proposes enhancements including:

  • introduction of a new invokedynamic bytecode instruction within the JVM for dynamic method calls,
  • supporting runtime modifications to classes and methods.

Sun’s open source Multi Language Virtual Machine initiative serves as a prototype for this specification. The initial working prototype was released as an OpenJDK patch in August 2008, showcasing dynamic invocation functionality.

The JRuby project incorporated dynamic invocation starting with version 1.1.5 in a basic form and enabled it by default beginning with version 1.7.0 for builds targeting Java 8 environments.

Release history

The following table outlines significant JRuby versions that mark important business and technical achievements, omitting minor patches and routine performance enhancements.

Version Date Released Key Developments
0.9 August 1, 2006 Added support for Rails framework
1.1 March 28, 2008 Surpassed Ruby MRI 1.8.7 in performance; introduced ahead-of-time and just-in-time compilation options
1.1.4 August 28, 2008 Enhanced Java interoperability; initiated Ruby 1.9 compatibility; implemented FFI subsystem for interfacing with C libraries
1.2.0 March 16, 2009 Introduced JIT compiler for Ruby 1.9; early Android platform support through Ruboto project
1.3.0 June 3, 2009 Optimized functionality within constrained environments like Google App Engine
1.4.0 November 2, 2009 Released native launcher and installer for Windows; added support for Ruby 1.8.7
1.5.0 May 12, 2010 Deployed native launcher on UNIX systems; improved integration with Ant and Rake-Ant; updated standard libraries
1.6.0 March 15, 2011 Achieved compatibility with Ruby 1.9.2; introduced built-in profiling tools; experimental support for C extensions via Ruby’s C API
1.7.0 October 22, 2012 Set Ruby 1.9.3 mode as default; incorporated invokedynamic support
1.7.4 May 16, 2013 Experimental implementation of Ruby 2.0 features including core library support
9.0.0.0 July 22, 2015 Complete compatibility with Ruby 2.x; launched new optimizing runtime; POSIX-compliant IO and process management; fully ported encoding and transcoding from MRI
9.1.7.0 January 11, 2017 Fixed multi-threading LinkageError; resolved keyword argument and parser bugs; reduced JIT memory footprint; updated dependencies such as Psych and jruby-openssl
9.2.0.0 May 24, 2018 Introduced support for Ruby language version 2.5
9.2.9.0 October 30, 2019 Updated to support Ruby version 2.5.7
9.3.2.0 December 2, 2021 Added compatibility with Ruby language features from version 2.6.x
9.3.3.0 January 19, 2022 Continued enhancements supporting Ruby 2.6.x features
9.3.4.0 March 23, 2022 Maintained compatibility with Ruby version 2.6.x
9.4.0.0 November 22, 2022 Rolled out support for Ruby language version 3.1
9.4.1.0 February 7, 2023 Improved compatibility with Ruby version 3.1
9.4.2.0 March 8, 2023 Ongoing refinements to support Ruby language version 3.1
9.4.3.0 June 7, 2023 Latest release sustaining compatibility with Ruby version 3.1

Design

Since the beginning of development in early 2006, the JRuby core developers have pursued a vision of advancing JRuby beyond a basic C implementation by boosting efficiency and enabling compilation into Java bytecode. Their objective was to execute Ruby on Rails applications unaltered on the JRuby platform—a goal that led to extensive expansion of the JRuby test suite to ensure accuracy and allowed major core redesigns and refactoring efforts by late 2006 through early 2007.

JRuby functions as a hybrid virtual machine supporting multiple execution modes: interpreted execution, runtime just-in-time (JIT) compilation, and ahead-of-time (AOT) compilation producing Java bytecode artifacts. Prior to October 2007, full feature coverage was limited to interpreted mode only; however, starting with version 1.1, a comprehensive AOT/JIT compiler became available that permits simultaneous running of interpreted and compiled code paths, supports decompilation for dynamic reoptimization, and can output generated bytecode as Java class files for deployment or analysis purposes.

Framework Compatibility

JRuby provides native compatibility with frameworks such as Rails, RSpec, Rake, and RubyGems. It incorporates an FFI mechanism that allows integration with C libraries distributed as gems and supports initiating the Interactive Ruby Shell (irb) in a manner akin to Ruby MRI.

The NetBeans Ruby Pack, which was part of NetBeans 6, offered integrated development environment capabilities for Ruby and JRuby, including support for Ruby on Rails. This feature was discontinued starting with the release of NetBeans 7.0.

Ruby Integrated with Java

While JRuby is developed in Java, it preserves fundamental Ruby characteristics such as object-oriented programming and dynamic typing. Its primary advantage lies in seamless Java interoperability, enabling direct method calls from Java applications. This synergy capitalizes on Java’s widespread adoption in web development.

Invoking Java from JRuby

One of JRuby’s strengths is its capacity to access Java Platform classes by requiring "java". For instance, it can instantiate a Java JFrame containing a JLabel: <syntaxhighlight lang="ruby"> 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 </syntaxhighlight> JRuby also permits invoking Java methods using Ruby-style underscore-separated method names and treats JavaBean properties as accessible attributes: <syntaxhighlight lang="ruby"> frame.content_pane.add label frame.visible = true </syntaxhighlight>

Embedding JRuby within Java

Calling JRuby from Java applications is achievable via JSR 223 scripting support introduced in Java 6 or through the Apache Bean Scripting framework.

<syntaxhighlight lang='java'> // Example utilizing JSR 223 scripting API in Java 6 ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine rbEngine = mgr.getEngineByExtension("rb"); try {

   rbEngine.eval("puts 'Hello World!'");

} catch (ScriptException ex) {

   ex.printStackTrace();

} </syntaxhighlight>

Efficiency and Speed

JRuby frequently demonstrates superior benchmark results compared to other implementations, although outcomes depend on the benchmarking approach. Typically, JVM startup latency is omitted from runtime measurements.

From an architectural standpoint, JRuby exploits JVM threading capabilities without being limited by a global interpreter lock, allowing true parallel execution within a single process—an edge over Ruby MRI.

For example, in a 2007 benchmark involving a Mongrel web server application, JRuby exhibited enhanced performance relative to Ruby MRI 1.8 once the JVM was fully initialized. Nonetheless, some benchmarks have shown YARV outperforming both JRuby and Ruby MRI.

As reported in April 2014 by the Computer Language Benchmarks Game, JRuby version 1.7.4 delivered performance on par with Ruby MRI 2.1.0 but consumed more memory resources.

Related Topics

Additional Resources

External links