JRuby

Last updated

JRuby
Developer(s) Charles Oliver Nutter, Thomas Enebo, Ola Bini and Nick Sieger
Initial release2001;23 years ago (2001)
Stable release
9.4.5.0 / November 2, 2023;10 months ago (2023-11-02) [1]
Repository
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.org   OOjs UI icon edit-ltr-progressive.svg

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).

Contents

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 (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. [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.

ReleaseRelease DateHighlights
0.9August 1, 2006Rails support [11]
1.1March 28, 2008Performs better than Ruby MRI 1.8.7 [6]
AOT mode and JIT mode [22]
1.1.4August 28, 2008Refactored Java integration layer
Beginning of Ruby 1.9 support
FFI subsystem for calling C libraries [23]
1.2.0 [24] March 16, 2009 JIT compiler for Ruby 1.9
Preliminary Android support by the Ruboto project.
1.3.0 [25] June 3, 2009JRuby runs in restricted environments better like GAE/J
1.4.0 [26] [27] November 2, 2009Windows Native Launcher and Windows installer
Ruby 1.8.7 support
1.5.0 [28] 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 [29] 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.0 [21] October 22, 2012Ruby 1.9.3 language is the default mode
Support for invokedynamic
1.7.4 [30] May 16, 2013Experimental Ruby 2.0 support (most features and stdlib included)
9.0.0.0 [31] July 22, 2015Ruby 2.x support
New optimizing runtime
New POSIX-friendly IO and Process

Fully ported encoding/transcoding logic from MRI

9.1.7.0 [32] January 11, 2017Fixed 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, 2018Ruby 2.5 language support
9.2.9.0 [34] October 30, 2019Ruby 2.5.7 language support
9.3.2.0 [35] December 2, 2021Ruby 2.6.x language support
9.3.3.0 [36] January 19, 2022Ruby 2.6.x language support
9.3.4.0 [37] March 23, 2022Ruby 2.6.x language support
9.4.0.0 [38] November 22, 2022Ruby 3.1 language support
9.4.1.0 [39] February 7, 2023Ruby 3.1 language support
9.4.2.0 [40] March 8, 2023Ruby 3.1 language support
9.4.3.0 [41] 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. [22] 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.addjavax.swing.JLabel.new('Hello, World!')frame.setDefaultCloseOperationjavax.swing.JFrame::EXIT_ON_CLOSEframe.packframe.set_visibletrue

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:[ dubious discuss ]

frame.content_pane.addlabelframe.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 6ScriptEngineManagermgr=newScriptEngineManager();ScriptEnginerbEngine=mgr.getEngineByExtension("rb");try{rbEngine.eval("puts 'Hello World!'");}catch(ScriptExceptionex){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. [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

Related Research Articles

<span class="mw-page-title-main">Ruby (programming language)</span> General-purpose programming language

Ruby is an interpreted, high-level, general-purpose programming language. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including primitive data types. It was developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.

Java Platform, Micro Edition or Java ME is a computing platform for development and deployment of portable code for embedded and mobile devices. Java ME was formerly known as Java 2 Platform, Micro Edition or J2ME.

<span class="mw-page-title-main">NetBeans</span> Integrated development environment software for software development

NetBeans is an integrated development environment (IDE) for Java. NetBeans allows applications to be developed from a set of modular software components called modules. NetBeans runs on Windows, macOS, Linux and Solaris. In addition to Java development, it has extensions for other languages like PHP, C, C++, HTML5, and JavaScript. Applications based on NetBeans, including the NetBeans IDE, can be extended by third party developers.

Jakarta Faces, formerly Jakarta Server Faces and JavaServer Faces (JSF) is a Java specification for building component-based user interfaces for web applications. It was formalized as a standard through the Java Community Process as part of the Java Platform, Enterprise Edition. It is an MVC web framework that simplifies the construction of user interfaces (UI) for server-based applications by using reusable UI components in a page.

<span class="mw-page-title-main">Apache Groovy</span> Programming language

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.

Java Management Extensions (JMX) is a Java technology that supplies tools for managing and monitoring applications, system objects, devices and service-oriented networks. Those resources are represented by objects called MBeans. In the API, classes can be dynamically loaded and instantiated. Managing and monitoring applications can be designed and developed using the Java Dynamic Management Kit.

<span class="mw-page-title-main">Ruby on Rails</span> Server-side open source web application framework

Ruby on 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 pages. It encourages and facilitates the use of web standards such as JSON or XML for data transfer and HTML, CSS and JavaScript for user interfacing. In addition to MVC, Rails emphasizes the use of other well-known software engineering patterns and paradigms, including convention over configuration (CoC), don't repeat yourself (DRY), and the active record pattern.

HotSpot, released as Java HotSpot Performance Engine, is a Java virtual machine for desktop and server computers, developed by Sun Microsystems which was purchased by and became a division of Oracle Corporation in 2010. Its features improved performance via methods such as just-in-time compilation and adaptive optimization. It is the de facto Java Virtual Machine, serving as the reference implementation of the Java programming language.

The Bean Scripting Framework is a method of allowing the use of scripting in Java code. It provides a set of Java classes which provides support within Java applications for scripting languages, and also allows access to Java objects and methods. Some examples of languages that can be used in combination with BSF and Java include Python, Jython, ooRexx and Tcl, as well as JRuby and Apache Groovy using their own libraries.

<span class="mw-page-title-main">Apache Tapestry</span> Open-source web application framework

Apache Tapestry is an open-source component-oriented Java web application framework conceptually similar to JavaServer Faces and Apache Wicket. Tapestry was created by Howard Lewis Ship, and was adopted by the Apache Software Foundation as a top-level project in 2006.

<span class="mw-page-title-main">Java (software platform)</span> Set of computer software and specifications

Java is a set of computer software and specifications that provides a software platform for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers. Java applets, which are less common than standalone Java applications, were commonly run in secure, sandboxed environments to provide many features of native applications through being embedded in HTML pages.

Scripting for the Java Platform is a framework for embedding scripts into Java source code.

In software development, the programming language Java was historically considered slower than the fastest third-generation typed languages such as C and C++. In contrast to those languages, Java compiles by default to a Java Virtual Machine (JVM) with operations distinct from those of the actual computer hardware. Early JVM implementations were interpreters; they simulated the virtual operations one-by-one rather than translating them into machine code for direct hardware execution.

IronRuby is an implementation of the Ruby programming language targeting Microsoft .NET Framework. It is implemented on top of the Dynamic Language Runtime (DLR), a library running on top of the Common Language Infrastructure that provides dynamic typing and dynamic method dispatch, among other things, for dynamic languages.

<span class="mw-page-title-main">Da Vinci Machine</span> Sun Microsystems project

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.

V8 is a JavaScript and WebAssembly engine developed by Google for its Chrome browser. V8 is free and open-source software that is part of the Chromium project and also used separately in non-browser contexts, notably the Node.js runtime system.

ZK is an open-source Ajax Web application framework, written in Java, that enables creation of graphical user interfaces for Web applications with little required programming knowledge.

Mirah has been a programming language based on Ruby language syntax, local type inference, hybrid static–dynamic type system, and a pluggable compiler toolchain. Mirah was created by Charles Oliver Nutter to be "a 'Ruby-like' language, probably a subset of Ruby syntax, that [could] compile to solid, fast, idiomatic JVM bytecode." The word mirah refers to the gemstone ruby in the Javanese language, a play on the concept of Ruby in Java.

Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact form of data.

<span class="mw-page-title-main">Ola Bini</span> Swedish programmer and Internet activist

Ola Bini, 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.

References

  1. "Releases · jruby/jruby". github.com. Retrieved December 26, 2023.
  2. Jacki (September 7, 2006). "Sun Welcomes JRuby Developers". On the Record. Archived from the original on August 29, 2012. Retrieved November 7, 2013.
  3. Ola Bini (2007). "ThoughtWorks". On the Record.
  4. 1 2 "Sun's JRuby Team Jumps Ship to Engine Yard". PCWorld . July 28, 2009. Retrieved June 2, 2012.[ permanent dead link ]
  5. 1 2 "Red Hat lures in JRuby power pair". The Register . May 23, 2012. Retrieved June 2, 2012.
  6. 1 2 Cangiano, Antonio (March 12, 2007). "The Great Ruby Shootout" . Retrieved February 1, 2008.
  7. Nutter, Charles (April 25, 2008). "JRuby 1.1.1 in RedHat Fedora" . Retrieved April 26, 2008.
  8. "jruby". fedoraproject.org. Retrieved April 26, 2008.[ permanent dead link ]
  9. Nutter, Charles (July 28, 2009). "JRuby's Future at Engine Yard". Archived from the original on July 31, 2009. Retrieved July 28, 2009.
  10. "Unfinished Ruby 3.1 features". JRuby Team. Retrieved June 13, 2023.
  11. 1 2 "Rails Support". JRuby Team. Archived from the original on March 3, 2008. Retrieved February 17, 2008.
  12. Nutter, Charles (August 24, 2008). "Zero to Production in 15 Minutes" . Retrieved August 27, 2008.
  13. 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
  14. "Success Stories". JRuby Wiki on GitHub. January 5, 2011. Retrieved March 16, 2011.
  15. "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. Retrieved February 28, 2008.
  16. see JSR 292
  17. "Sub-Projects and Investigations". Sun Microsystems. 2007. Retrieved February 6, 2008.
  18. Rose, John (August 26, 2008). "Happy International Invokedynamic Day!" . Retrieved September 3, 2008.
  19. Lorimer, R.J. (September 1, 2008). "Dynamic Invocation Runs on OpenJDK". infoq.com. Retrieved September 3, 2008.
  20. Nutter, Charles (September 11, 2008). "A First Taste of InvokeDynamic" . Retrieved September 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).
  21. 1 2 "JRuby 1.7.0 Released". JRuby Team. October 22, 2012. Archived from the original on October 25, 2012. Retrieved October 23, 2011.
  22. 1 2 Nutter, Charles (September 27, 2007). "The Compiler Is Complete" . Retrieved October 12, 2007.
  23. Enebo, Tom (August 28, 2008). "JRuby 1.1.4 Released" . Retrieved February 25, 2009.[ permanent dead link ]
  24. Enebo, Tom (March 16, 2009). "JRuby 1.2.0 Released". JRuby Team. Archived from the original on March 19, 2009. Retrieved March 17, 2009.
  25. Enebo, Tom (June 3, 2009). "JRuby 1.3.0 Released". JRuby Team. Archived from the original on June 12, 2009. Retrieved June 3, 2009.
  26. "JRuby 1.4.0 Released". JRuby Team. November 2, 2009. Retrieved November 3, 2009.
  27. "JRuby 1.4.0 Released". adtmag.com. November 10, 2009. Archived from the original on November 15, 2009. Retrieved November 21, 2009.
  28. "JRuby 1.5.0 Released". JRuby Team. May 12, 2010. Archived from the original on May 16, 2010. Retrieved May 12, 2010.
  29. "JRuby 1.6.0 Released". JRuby Team. March 15, 2011. Retrieved March 15, 2011.
  30. "JRuby 1.7.4 Released". JRuby Team. May 16, 2013. Retrieved May 19, 2013.
  31. "JRuby 9.0.0.0 Released". JRuby Team. July 22, 2015. Archived from the original on July 24, 2015. Retrieved July 25, 2015.
  32. "JRuby 9.1.7.0 Released — JRuby.org". jruby.org. Archived from the original on January 16, 2017. Retrieved January 13, 2017.
  33. "JRuby 9.2.0.0 Released". Archived from the original on May 27, 2018. Retrieved May 27, 2018.
  34. "JRuby 9.2.9.0 Released" . Retrieved November 5, 2019.
  35. "JRuby 9.3.2.0 Released" . Retrieved January 11, 2022.
  36. "JRuby 9.3.3.0 Released" . Retrieved January 19, 2022.
  37. "JRuby 9.3.4.0 Released" . Retrieved March 23, 2022.
  38. "JRuby 9.4.0.0 Released" . Retrieved December 1, 2022.
  39. "JRuby 9.4.1.0 Released" . Retrieved February 15, 2023.
  40. "JRuby 9.4.2.0 Released" . Retrieved June 13, 2023.
  41. "JRuby 9.4.3.0 Released" . Retrieved June 13, 2023.
  42. "Ruby & JRuby Support Available in NetBeans IDE". netbeans.org. March 6, 2007. Archived from the original on July 19, 2011. Retrieved July 4, 2009.
  43. "Ruby brightens the NetBeans platform". infoworld.com. March 1, 2007. Retrieved July 4, 2008.
  44. Fox, Joshua (July 17, 2006). "Ruby for the Java world". JavaWorld . Retrieved July 26, 2020.
  45. JSR 223: Scripting for the Java Platform Specification Request
  46. Sieger, Nick (October 25, 2007). "JRuby on Rails: Fast Enough" . Retrieved October 28, 2007.
  47. Cangiano, Antonio (December 3, 2007). "The Great Ruby Shootout" . Retrieved February 2, 2014.
  48. "JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (1)". Archived from the original on January 23, 2015. Retrieved February 2, 2014.
  49. "JRuby compared to Ruby 1.9, Computer Language Benchmarks Game (2)". Archived from the original on July 23, 2014. Retrieved February 2, 2014.

Further reading