JRuby Source Code
Reading Guide
JRuby source code build requirements
JDK >= J2SE 5.0
Apache Ant
JRuby VM
src
org.jruby.*
org.jruby.Ruby*.java
org.jruby.ext.*
org.jruby.libraries.*
org.jruby.lexer.*
org.jruby.parser.*
org.jruby.ast.*
org.jruby.internal.*
org.jruby.runtime.*
org.jruby.compiler.*
org.jruby.compiler.ir.*
org.jruby.interpreter.*
org.jruby.ant.*
org.jruby.embed.*
org.jruby.java.*
org.jruby.javasupport.*
Rake/Ant integration
AST
JRuby Compiler
IR
Embedding JRuby in Java
JRuby scanner/parser
Java module impl
Ruby Ext class
Runtime information
Ruby Core class
implements Ruby Ext for Java integration
IRubyObject.java
Java interface for Ruby objects
Ruby*.java
Ruby Core class implementations:
RubyModule, RubyString, RubyFixnum, etc.
Main.java
creates JRuby VM instance and eval the given script
Ruby.java
JRuby VM instance
run JRuby Evaluator
RubyInstanceConfig.java
runtime settings for JRuby VM instance
Method | defined at runtime
CallSite | method invoker for each invocation
DynamicScope and Variables
Frame
ThreadContext | for each Java&Ruby Thread
ThreadService | for each VM
etc.
org.jruby.libraries.*
Ext lib loading entry point
org.jruby.ext.*
Ext lib implementations
Some ext libs are in org.jruby.Ruby*.java
ex. RubyDigest.java
from historical reason?
Call*Node.java
method invocation node | obj.foo
MethodDefNode.java
method definition node | def foo
*Node.java
etc.
% jruby -S ast foo.rb
% ruby19 --dump=parsetree foo.rb
[AST]
RootNode
NewlineNode
ClassNode
Colon2ImplicitNode:Foo
BlockNode
...
generates one AST per one *.rb file
compiles AST Call*Node into Java bytecode
invoked by JRuby Interpreter at runtime (JIT)
invoked at startup time by -J-Djruby.compile.mode=FORCE
jrubyc
don't confuse with JVM JIT Compiler!
[Java bytecode]
public class foo extends ... {
public <init>()V
ALOAD 0
INVOKESPECIAL ...
[AST]
RootNode
NewlineNode
ClassNode
Colon2ImplicitNode:Foo
BlockNode
...
Generated from AST
basis of new JRuby Interpreter and JRuby JIT Compiler
will make IR level optimization easier
will make JRuby JIT Compiler efficient (esp. on dynopt)
See new interpreter at org.jruby.interpreter.*
See "Distilling JRuby - The JIT Compiler" for more details
http://www.realjenius.com/2009/10/06/distilling-jruby-the-jit-compiler/
Scanner
Ported CRuby's scanner
Parser
based on 'jay' parser generator
generates AST
3 interfaces
RedBridge | original
BSF
JSR223
Runnable as an Ant task
Let Rake task run with JRuby VM
Rake task which runs Ant task:
lib/ruby/site_ruby/shared/ant/ant.rb (written in Ruby)
implements JRuby VM and script evaluation entry point
implements Ruby Core classes
represents Abstract Syntax Tree
implements JRuby Compiler
ASTCompiler: AST -> Java bytecode
JITCompiler: JIT control
implements new Intermediate Representation
under development | for JRuby 1.6?
implements Ruby Ext classes
implements Ruby scanner and parser
handles JRuby VM runtime information
implements embedding interfaces for Java
for accessing Java resources from Ruby.
require 'java'
see lib/ruby/site_ruby/shared/builtin/javasupport.rb for meta-programming
import
include_package
include_class
implements Ant task which runs Rake task
[Ruby]
class Foo
def initialize
@obj = ...
end
...
end
% git clone http://github.com/jruby/jruby.git
...
% cd jruby
% ant jar
Buildfile: /home/nahi/git/jruby/build.xml
...
BUILD SUCCESSFUL
Total time: 37 seconds
% bin/jruby -v
jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-08-10 d4d0d61) (OpenJDK 64-Bit Server VM 1.6.0_18) [amd64-java]
Related article:
See http://www.infoq.com/news/2009/11/jruby-ir
What's dynopt?
See http://bit.ly/JRubyJITCompilerInANutshell
by Hiroshi Nakamura
nahi@ruby-lang.org | @nahiMore presentations by Hiroshi Nakamura
Popular presentations
Future-Proof Your Education
Maria Andersen on
How do you prepare for uncertain career paths where technical knowledge doubles every two years? You pay attention to the skills that surround the content: ...
More popular prezis in Explore>