Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Ruby Object is a Java Object

Defined Java class:

RubyBasicObject, RubyObject,

RubyModule, RubyString, RubyFixnum, etc.

For example...

Ruby Object

is a

Java Object

GC? there's nothing special

Let JVM work!

Not really.

  • finalizer
  • fd
  • PermGen

Scanner

  • Ported CRuby's scanner

Parser

  • based on 'jay' parser generator
  • generates AST

% jruby -S ast foo.rb

% ruby19 --dump=parsetree foo.rb

Scanner&Parser

JRuby JIT Compiler

AST Compiler

AOT Compiler

(jrubyc)

Generated from AST

  • basis of new JRuby Interpreter and JRuby JIT Compiler
  • will make IR level optimization easier
  • will make JRuby JIT Compiler efficient

org.jruby.compiler.ir.*

IR Builder and Compiler

org.jruby.interpreter.*

New JRuby Evaluator

require 'java'

allow to access Java resource

'include_package'

include Java package to the namespace

'include_class'

include Java Class to the namespace

You saw "Keynote - JRuby: Pony Show", right?

Garbage Collection

Object

Extension objects

Ruby Core objects

org.jruby.Ruby*.java

implements Ruby Core objects

org.jruby.Ruby*.java

org.jruby.ext.*

implements Extension objects

in Java

digest, zlib, mathn, socket, etc.

IO

String

Syntax

Analysis

org.jruby.util.io.ChannelStream.java

implements FILE(stdio)

org.jruby.RubyString.java

org.jruby.RubyEncoding.java

Fixnum and Float

  • ByteList as buffer
  • Encoding

ByteList operation ...except UTF-8

org.jruby.util.io.ChannelDescriptor.java

implements fd and wraps;

  • Channel (NIO)
  • FileDescriptor (NIO)
  • fileno (virtual)
  • mode

org.jruby.RubyFixnum.java

org.jruby.RubyFloat.java

  • Boxing
  • Fixnum cache

AST

Scanner/Parser

org.jruby.ast.*

represents Abstract Syntax Tree

org.jruby.lexer.*

org.jruby.parser.*

implements Ruby scanner and parser

JRUBY_HOME/src

generates one AST per one *.rb file

Thread

org.jruby.RubyThread.java

org.jruby.runtime.ThreadContext.java

org.jruby.internal.runtime.ThreadService.java

handles JRuby VM runtime information

JRuby

Hacking

Guide

Evaluator

JRuby VM

Context

org.jruby.internal.*

org.jruby.runtime.*

handles VM's runtime information

org.jruby.Main.java (entry point)

org.jruby.Ruby.java (VM implementation)

org.jruby.RubyInstanceConfig.java

JRuby VM instance and runtime settings

JRuby Interpreter

  • Method | defined at runtime
  • CallSite | method invoker for each invocation
  • DynamicScope and Variables
  • Frame

JRuby Interpreter

Interpreters & Compilers

Compiler Settings

  • org.jruby.Ruby*.java
  • org.jruby.ext.*

  • org.jruby.lexer.*
  • org.jruby.parser.*
  • org.jruby.ast.*

  • org.jruby.Main.java
  • org.jruby.Ruby.java
  • org.jruby.internal.*
  • org.jruby.runtime.*

  • org.jruby.compiler.*
  • org.jruby.compiler.ir.*
  • org.jruby.interpreter.*

  • org.jruby.java.*
  • org.jruby.javasupport.*
  • org.jruby.embed.*
  • org.jruby.ant.*

http://bit.ly/JRubyHackingGuide

Compiler

AOT and JIT

AST Compiler

org.jruby.compiler.*

implements JRuby Compiler

JRuby Interpreter

JVM JIT Compiler

JVM

native machine code

dynamic Java bytecode generation

Rake/Ant integration

org.jruby.ant.*

implements Ant task which runs Rake task

lib/ruby/site_ruby/shared/ant/ant.rb

Rake task which runs Ant task

  • Runnable as an Ant taks
  • Let Rake task run with JRuby VM

Future

Integration

Java Integration

Embedding JRuby in Java

JRuby in 2002-12-11

And the Future

org.jruby.java.*

org.jruby.javasupport.*

lib/ruby/site_ruby/shared/builtin/javasupport.rb

for accessing Java resources from Ruby

org.jruby.embed.*

implements embedding interfaces for Java

  • Scanner&Parser compatibility
  • meta-programming feature
  • Core objects compatibility
  • Ext objects compatibility
  • UNIX layer compatibility
  • Performance

Excellent

NO

Poor

NO

NO

Poor

3 interfaces

  • RedBridge | original
  • BSF
  • JSR223

JRuby in 2010-08-28

  • Scanner&Parser compatibility
  • meta-programming feature
  • Core objects compatibility
  • Ext objects compatibility
  • UNIX layer compatibility
  • Performance

OK

OK

OK

OK + jffi, c-ext

OK

OK for Server

Startup-time matters

by Hiroshi Nakamura

nahi@ruby-lang.org

@nahi

Further Reading

Nihongo-JRuby by Hirotsugu Asari

http://jruby-ja.blogspot.com/

JRuby Wiki | Design: Internals

http://kenai.com/projects/jruby/pages/Internals

Distilling JRuby by R.J. Lorimer

http://www.realjenius.com/category/article/distilling-jruby/

Dynamic Optimization by Charles

http://blog.headius.com/2010/05/kicking-jruby-performance-up-notch.html

InfoQ Article about IR

http://www.infoq.com/news/2009/11/jruby-ir

JRuby Compile Settings by NaHi

http://bit.ly/JRubyCompileSettings

JRuby Source Code Reading Guide

http://bit.ly/JRubySrcReadingGuide

Learn more about creating dynamic, engaging presentations with Prezi