user1784391
user1784391

Reputation: 35

JRuby is Ruby implemented on the JVM - what does this mean?

This is a very beginner-ish question.

JRuby is Ruby implemented on the JVM. Does this mean that the process for creation was just creating the Ruby language from scratch, implemented in Java methods and classes, instead of in C? That is, every Ruby method was one by one implemented in Java? I think my question is rooted in a lack of understanding of the JVM.

Upvotes: 1

Views: 407

Answers (1)

It means that all ruby code running in JRuby ultimately translates to bytecode that gets executed by the JVM. That "translation" can have already been done when JRuby was written and compiled, or it happens at runtime, when the JRuby compiler transforms Ruby code into something that can run on the JVM. More concretely:

  • The classic steps for a compiler such as lexing/parsing/AST walking/IR translation are done by code written in Java,
  • Lots of the core Ruby classes map to actual Java classes, or even libraries, which implement their functionalities (for example, the Ruby String methods, such as capitalize!, are implemented inside the org.jruby.RubyString Java class, or some of the date and time stuff is based on joda-time),
  • JRuby leverages the JVM features, such as garbage collection, multithreading, etc.,
  • the Ruby code can get JITed into Java bytecode.

Upvotes: 1

Related Questions