HOME

TheInfoList



OR:

JRuby is an implementation of the
Ruby programming language Ruby is an interpreted, high-level, general-purpose programming language which supports multiple programming paradigms. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including p ...
atop the
Java Virtual Machine A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
, written largely in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's most ...
. It is
free software Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty, no ...
released under a three-way EPL/
GPL The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general u ...
/
LGPL The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their ow ...
license. JRuby is tightly integrated with
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's most ...
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 Jython is an implementation of the Python programming language designed to run on the Java platform. The implementation was formerly known as JPython until 1999. Overview Jython programs can import and use any Java class. Except for some standa ...
for the Python language). JRuby's lead developers are Charles Oliver Nutter and Thomas Enebo, with many current and past contributors including
Ola Bini Ola Bini, (born Ola Martin Gustafsson in 1982) is a Swedish programmer and Internet activist, working for the Digital Autonomy Center in Ecuador on issues of privacy, security and cryptography. He has been in Ecuador since 2013. In April 2019 ...
and Nick Sieger. In September 2006,
Sun Microsystems Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, th ...
hired Enebo and Nutter to work on JRuby full-time. In June 2007, ThoughtWorks hired Ola Bini to work on Ruby and JRuby. In July 2009, the JRuby developers left Sun to continue JRuby development at
Engine Yard Engine Yard is a San Francisco, California based, privately held platform as a service company focused on Ruby on Rails, PHP and Node.js deployment and management. History Engine Yard, founded in 2006, offers a cloud application management plat ...
. In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at
Red Hat Red Hat, Inc. is an American software company that provides open source software products to enterprises. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North Carolina, with other offices worldwide. Red Hat has become ass ...
.


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 In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is a way of executing computer code that involves compilation during execution of a program (at run time) rather than before execution. This may co ...
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. 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. In July 2009, the core JRuby developers at Sun Microsystems, Charles Oliver Nutter, Thomas Enebo and Nick Sieger, joined
Engine Yard Engine Yard is a San Francisco, California based, privately held platform as a service company focused on Ruby on Rails, PHP and Node.js deployment and management. History Engine Yard, founded in 2006, offers a cloud application management plat ...
to continue JRuby development. In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at
Red Hat Red Hat, Inc. is an American software company that provides open source software products to enterprises. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North Carolina, with other offices worldwide. Red Hat has become ass ...
. JRuby has supported compatibility with
Ruby MRI Matz's Ruby Interpreter or Ruby MRI (also called CRuby) was the reference implementation of the Ruby programming language named after Ruby creator Yukihiro Matsumoto ("Matz"). Until the specification of the Ruby language in 2011, the MRI impleme ...
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.0.0) supports Ruby 3.1.x


Ruby on Rails

JRuby has been able to run the
Ruby on Rails Ruby on Rails (simplified as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web p ...
web framework since version 0.9 (May 2006), with the ability to execute
RubyGems RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems ...
and
WEBrick WEBrick is a Ruby library providing simple HTTP web servers. It uses basic access authentication and digest access authentication for different kinds of servers that it can create - HTTP based server, HTTPS server, proxy server and virtual-host s ...
. 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. Since then, developers have begun to use JRuby for Rails applications in production environments.


Multiple virtual machine collaboration

On February 27, 2008,
Sun Microsystems Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, th ...
and the
University of Tokyo , abbreviated as or UTokyo, is a public research university located in Bunkyō, Tokyo, Japan. Established in 1877, the university was the first Imperial University and is currently a Top Type university of the Top Global University Project by ...
announced a joint-research project to implement a virtual machine capable of executing more than one
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sap ...
or JRuby application on one interpreter.


Dynamic invocation on Java Virtual Machines

JSR 292 The Da Vinci Machine, also called the Multi Language Virtual Machine, was a Sun Microsystems project aiming to prototype the extension of the Java Virtual Machine (JVM) to add support for dynamic languages. It was already possible to run dynami ...
(''Supporting Dynamically Typed Languages on the JavaTM Platform'') proposes: * adding a new invokedynamic instruction at the JVM level, allowing method invocation using dynamic
type checking In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progr ...
, * dynamically changing classes and methods at runtime. The Sun Open source project Multi Language Virtual Machine aims to prototype this JSR. The first working prototype, developed as a patch on
OpenJDK OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GPL-2.0-only wi ...
, was announced and made available on end of August 2008. The JRuby team has implemented dynamic invocation into their codebase. Dynamic invocation initially shipped with the 1.1.5 release in a primitive form. Version 1.7.0 enabled it by default on Java 8 builds.


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.


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 In computing, Java bytecode is the bytecode-structured instruction set of the Java virtual machine (JVM), a virtual machine that enables a computer to run programs written in the Java programming language and several other programming languages, ...
. 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. The compiler design allows for interpreted and compiled code to run side-by-side, as well as
decompilation A decompiler is a computer program that translates an executable file to a high-level source file which can be recompiled successfully. It does therefore the opposite of a typical compiler, which translates a high-level language to a low-level lan ...
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 Ruby is an interpreted, high-level, general-purpose programming language which supports multiple programming paradigms. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including p ...
(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. 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 Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's most ...
. JRuby features some of the same concepts, including
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
, and
dynamic typing In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer prog ...
as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs. 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 Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cros ...
. 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 In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1. The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized obj ...
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 Scripting for the Java Platform is a framework for embedding scripts into Java source code. There is no requirement for a given Java virtual machine (JVM) to include any engines by default, but the Oracle JVM (Java 6 and later) includes a JavaSc ...
Scripting for Java 6 or the Apache Bean Scripting framework. //Example using JSR 233 Scripting for Java 6 ScriptEngineManager 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 A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
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 A global interpreter lock (GIL) is a mechanism used in computer-language interpreters to synchronize the execution of threads so that only one native thread (per process) can execute at a time. An interpreter that uses GIL always allows exactly o ...
(similarly to
Rubinius Rubinius was an alternative Ruby implementation created by Evan Phoenix. Based loosely on the Smalltalk-80 ''Blue Book'' design, Rubinius sought to "provide a rich, high-performance environment for running Ruby code." Goals Rubinius follows in ...
), therefore achieving full parallelism within a process, which Ruby MRI cannot achieve despite leveraging OS threads. In a real
Mongrel A mongrel, mutt or mixed-breed dog is a dog that does not belong to one officially recognized breed and including those that are the result of intentional breeding. Although the term ''mixed-breed dog'' is sometimes preferred, many mongr ...
web server A web server is computer software and underlying hardware that accepts requests via HTTP (the network protocol created to distribute web content) or its secure variant HTTPS. A user agent, commonly a web browser or web crawler, initiate ...
application tested in 2007, JRuby performance is better than Ruby MRI 1.8, after the Java Virtual Machine had been instantiated. In a 2007 benchmark of Ruby implementations, JRuby was faster than Ruby MRI 1.8 in some tests, but
YARV YARV (Yet another Ruby VM) is a bytecode interpreter that was developed for the Ruby programming language by Koichi Sasada. The goal of the project was to greatly reduce the execution time of Ruby programs. Since YARV has become the official Ru ...
outperformed both of them. As of April 2014, in
The Computer Language Benchmarks Game The Computer Language Benchmarks Game (formerly called The Great Computer Language Shootout) is a free software project for comparing how a given subset of simple algorithms can be implemented in various popular programming languages. The project ...
, JRuby 1.7.4 typically has the same performance as Ruby MRI 2.1.0, but uses more memory.


See also

*
GraalVM GraalVM is a Java VM and JDK based on HotSpot/OpenJDK, implemented in Java. It supports additional programming languages and execution modes, like ahead-of-time compilation of Java applications for fast startup and low memory footprint. The f ...
*
List of Java scripting languages This list of JVM Languages comprises notable computer programming languages that are used to produce computer software that runs on the Java virtual machine (JVM). Some of these languages are interpreted by a Java program, and some are compiled ...
* ZK (framework) – an Ajax framework supporting JRuby


References


Further reading

* * * * *


External links

* {{DEFAULTSORT:Jruby Free software programmed in Java (programming language) Free software programmed in Ruby JVM programming languages Object-oriented programming languages Ruby (programming language) Scripting languages Software using the Eclipse license