SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
JRuby
Power on the JVM
          Ola Bini
   JRuby Core Developer
      ThoughtWorks
Vanity slide
•   Ola Bini

•   From Stockholm, Sweden

•   Programming language nerd (Lisp, Ruby, Java, Smalltalk, Io,
    Erlang, ML, C/C++, etc)

•   JRuby Core Developer (2 years and running)

•   Author of Practical JRuby on Rails (APress)
Agenda
•   What is JRuby

•   How to get started

•   The implementation

•   Cool things

•   Possibly some Rails

•   Q&A
What is JRuby
•   Implementation of the Ruby language

•   Java 1.5+ (1.4 for JRuby 1.0)
    •   Retroweaver can be used for 1.4 compatibility

•   Open source

•   “It’s just Ruby”

•   Compatible with Ruby 1.8.6

•   JRuby 1.0.3 and 1.1RC3 current releases
    •   1.0-branch rapidly falling behind
Community
•   8 Core developers

•   40-50 contributors

•   Outstanding contributions
    •   Like Marcin’s Oniguruma port
        •   Joni is probably the fastest Regexp engine for Java right now
Ruby Issues - Threading
•   Ruby 1.8: Green threading
    •   No scaling across processors/cores
    •   C libraries won’t/can’t yield
    •   One-size-fits-all scheduler

•   Ruby 1.9: Native, non-parallel execution

•   JRuby:
    •   Ruby threads are Java threads
    •   World class scheduler with tunable algorithms
Ruby Issues - Unicode
•   Ruby 1.8: Partial Unicode
    •   Internet connection applications MUST have solid Unicode
    •   Ruby 1.8 provides very partial support
    •   App devs roll their own: Rails Multi-byte

•   Ruby 1.9: Full encoding support
    •   Drastic changes to interface and implementation
    •   Performance issues
    •   Each string can have its own encoding

•   JRuby: Java Unicode
Ruby Issues - Performance
•   Ruby 1.8: Slower than most languages
    •   1.8 is usually called “fast enough”
    •   ...but routinely finishes last
    •   ...and no plans to improve in 1.8

•   Ruby 1.9: Improvement, but not scalable
    •   New engine about 1.5x for general appliciations
    •   Only implicit AOT compilation
    •   No JIT, no GC or threading changes

•   JRuby: Compiler provides better performance
Ruby Issues - Memory
•   Ruby 1.8: Memory management
    •   Simple design
    •   Good for many apps, but not scalable
    •   Stop-the-world GC

•   Ruby 1.9: No change
    •   Improved performance => more garbage
    •   GC problems could multiply

•   JRuby: World class Java GC’s
Ruby Issues - C
•   Ruby 1.8 & 1.9: C language extensions
    •   C is difficult to write well
    •   Badly-behaved extensions can cause large problems
    •   Threading and GC issues relating to extensions
    •   Portable, but often with recompilation
    •   No security restrictions in the system

•   JRuby
    •   Java extensions
    •   GC and threading no problem
Ruby Issues - Politics
•   Politics
    •   “You want me to switch to what?”
    •   “... and it needs servers/software/training?”
    •   Potentially better with time (e.g. 1.9)

•   Legacy
    •   Lots of Java apps in the world
    •   Extensive amount of Java frameworks

•   JRuby solves both of these by running on top of Java
    •   “Credibility by association”
C libraries
•   JRuby can’t support native extensions
    •   Designed around single-threaded execution
        •   (i.e. one app, one request per process at a time

    •   Stability, security problems
    •   Too permissive Ruby extension API

•   But who cares?
    •   If you want to do it, there’s a Java library
    •   If no, we support natives access through JNA
    •   And even porting is not that hard
Getting started
•   Java installation

•   Download JRuby binary distro
    •   Includes JRuby, Ruby stdlib, RubyGems and rake

•   Unpack
    •   Multiple copies on the system is fine

•   Add <jruby-dir>/bin to PATH

•   Install gems (gem install or jruby -S gem install)
Calling Ruby from Java
•   // One-time load Ruby runtime
    ScriptEngineManager factory =
        new ScriptEngineManager();

    ScriptEngine engine =
        factory.getEngineByName(quot;jrubyquot;);

    // Evaluate JRuby code from string.
    try {
        engine.eval(quot;puts('Hello')quot;);
    } catch (ScriptException exception) {
        exception.printStackTrace();
    }
DEMO
Java Integration
Implementation: Lexing, parsing
•   Hand written lexer
    •   Originally ported from MRI
    •   Many changes since then

•   LALR parser
    •   Port of MRI’s YACC/Bison-based parser

•   Abstract Syntax Tree quite similar to MRI
    •   We’ve made a few changes and additions
Implementation: Core classes
•   Mostly 1:1 core classes map to Java types
    •   String is RubyString, Array is RubyArray, etc

•   Annotation based method binding
    public @interface JRubyMethod {
        String[] name() default {};
        int required() default 0;
        int optional() default 0;
        boolean rest() default false;
        String[] alias() default {};
        boolean meta() default false;
        boolean module() default false;
        boolean frame() default false;
        boolean scope() default false;
        boolean rite() default false;
        Visibility visibility() default Visibility.PUBLIC;
    }
    ...
    @JRubyMethod(name = quot;openquot;, required = 1, frame = true)
Implementation: Interpreter
•   Simple switch based AST walker

•   Recurses for nested structures

•   Most code start out interpreted
    •   Command line scripts compiled immediately
    •   Precompiled script (.class) instead of .rb
    •   Eval’ed code is always interpreted (for now)

•   Reasonably straight forward code
Implementation: Compilation
•   Full Bytecode compilation
    •   1.0 had partial JIT compiler (25%)

•   AST walker emits code structure

•   Bytecode emitter generates Java class + methods
    •   Real Java bytecode
    •   AOT mode: 1:1 mapping .rb file to .class file
        •   Not a “real” Java class, more a bunch of methods

        •   ... but has a “main” for CLI execution

    •   JIT mode: 1:1 mapping method to in-memory class
DEMO
Precompilation
Compiler problems
•   AOT pain
    •   Code bodies as Java methods need method handles
        •   Generated as adaptor methods

    •   Ruby is very terse - the compiled output is much more verbose
    •   Mapping symbols safely (class, package, method names)

•   JIT pain
    •   Method body must live on a class
        •   Class must be live in separate classloader to GC

        •   Class name must be unique within that classloader
Compiler optimizations
•   Preallocated, cached Ruby literals

•   Java opcodes for local flow-control where possible
    •   Explicit local “return” as cheap as implicit
    •   Explicit local “next”, “break”, etc simple jumps

•   Java local variables when possible
    •   Methods and leaf closures
        •   leaf == no contained closures

•   No eval(), binding(), etc calls present

•   Monomorphic inline method cache
    •   Polymorphic for 1.1 (probably)
Core class implementations
•   String as copy-on-write byte[] impl

•   Array as copy-on-write Object[] impl

•   Fast-read Hash implementation

•   Java “New IO” (NIO) based IO implementation
    •   Example: implementing analogs for libc IO functions

•   Two custom Regexp implementations
    •   New one works with byte[] directly
Threading
•   JRuby supports only native OS threads
    •   Much heavier than Ruby's green threads
    •   But truly parallel, unlike Ruby 1.9 (GIL)

•   Emulates unsafe green operations
    •   Thread#kill, Thread#raise inherently unsafe
    •   Thread#critical impossible to guarantee
    •   All emulated with checkpoints (pain...)

•   Pooling of OS threads minimizes spinup cost
POSIX
•   Normal Ruby native extensions not supported
    •   Maybe in future, but Ruby API exposes too much

•   Native libraries accessible with JNA
    •   Not JNI...JNA = Java Native Access
    •   Programmatically load libs, call functions
    •   Similar to DL in Ruby
    •   Could easily be used for porting extensions

•   JNA used for POSIX functions not in Java
    •   Filesystem support (symlinks, stat, chmod, chown, ...)
Java Integration
•   Java types are presented as Ruby types
    •   Construct instances, call methods, pass objects around
    •   camelCase or under_score_case both work
    •   Most Ruby-calling-Java code looks just like Ruby

•   Integration with Java type hierarchy
    •   Implement Java interfaces
        •   longhand “include SomeInterface”

•   shorthand “SomeInterface.impl { ... }”

•   closure conversion “add_action_listener { ... }”

•   Extend Java concrete and abstract Java types
Performance
•   No, it's not all that important
    •   Until it is!

•   JRuby 1.0 was about 2x slower than Ruby 1.8.6

•   JRuby 1.1 Beta 1 was about 2x faster

•   JRuby trunk is 5x faster, often faster than 1.9
    •   As a result, we've stopped working on perf for now
    •   ...but targeting Java performance next
DEMO
Benchmarks
JRuby Internals
•   JRuby::ast_for(“1+1”) #-> Java AST

    JRuby::ast_for { 1+1 } #-> Java AST

    JRuby::compile(“1+1”) #-> CompiledScript

    CompiledScript.inspect_bytecode

    JRuby::runtime

    JRuby::reference(“str”)
... evil stuff
•   a = “foobar”
    a.freeze
    JRuby::reference(a).setFrozen(false)


•   class Foobar; end
    something = Object.new
    JRuby::reference(something).setMetaClass(Foobar)


•   class Foobar; end
    JRuby::reference(Foobar).getMethods()
JRuby on Rails - end to end
•   Create application

•   Package into a WAR-file, using
    •   Warbler
    •   JRubyWorks
    •   Goldspike

•   Deploy WAR file to any Java Web Container
    •   Jetty, Tomcat, GlassFish
    •   Oracle Application Server, JBoss, WebSphere
    •   WebLogic
JtestR
•   Test Java code with Ruby

•   Glues JRuby together with state of the art Ruby libraries

•   Includes RSpec, Test::Unit, dust, Mocha, etc

•   Ant and Maven 2 integration

•   0.2 to be released “any time now” (tm)
Rubiq
•   Lisp layer on top of JRuby

•   Transforms to JRuby AST

•   ... and lets JRuby execute it

    •   Macros

    •   Read macros (used to implement regexp syntax, for
        example)

    •   Pure lexical scoping

    •   Lambdas transparently transforms to blocks or Proc.new
ActiveHibernate
•   # define a model (or you can use existing)
    class Project
      include Hibernate
      with_table_name quot;PROJECTSquot; #optional
      #column name is optional
      primary_key_accessor :id, :long, :PROJECT_ID
      hattr_accessor :name, :string
      hattr_accessor :complexity, :double
    end

    # connect
    ActiveHibernate.establish_connection(DB_CONFIG)

    # create
    project = Project.new(:name => quot;JRubyquot;, :complexity => 10)
    project.save
    project_id = project.id

    # query
    all_projects = Project.find(:all)
    jruby_project = Project.find(project_id)

    # update
    jruby_project.complexity = 37
    jruby_project.save
Ruvlets
•   Expose Servlets as Ruby API
    •   Because we can!
    •   People keep asking for this....really!
    •   Expose highly tuned web-infrastructure to Ruby
    •   Similar in L&F to Camping

•   How it works:
    •   Evaluates file from load path based on URL
    •   File returns an object with a 'service' method defined
    •   Object cached for all future requests
Bare bones Ruvlet
 •   class HelloWorld
       def service(context, request, response)
         response.content_type = quot;text/htmlquot;
         response.writer << <<-EOF
           <html>
             <head><title>Hello World!</title></head>
             <body>Hello World!</body>
           </html>
         EOF
       end
     end

     HelloWorld.new
YARV & Rubinius machine
•   YARV
    •   2.0 Compatibility
    •   Simple machine
    •   Simple compiler
    •   Might give interpreted performance improvement

•   Rubinius
    •   Simple machine
    •   Quite outdated at the moment
    •   Why do it? Why not?
JSR292, JLR & DaVinci
•   Dynamic invocation: non-java call sites

•   Method handles

•   Anonymous classes

•   Faster reflection, escape analysis
    •   Interface injection
    •   Continuations
    •   Value objects (Lisp fixnums)
    •   Tuple types
    •   Tail calls
JRuby’s future
 •   Get 1.1 out there
 •   Rework the Java Integration features
 •   Create a stable public API for extensions
 •   Better performance (as always)
 •   Support for Ruby 1.9 features
 •   Light weight objects
 •   JSR292 support
 •   Rubinius?
 •   More primitives in Ruby?
Resources
•   jruby.org

•   #jruby on freenode

•   glassfish.dev.java.net

•   openjdk.java.net/projects/mlvm

•   jtestr.codehaus.org

•   code.google.com/p/activehibernate

•   headius.blogspot.com

•   ola-bini.blogspot.com
Q&A

Contenu connexe

Tendances

GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22Jorge Hidalgo
 
GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28Jorge Hidalgo
 
Intro to Crystal Programming Language
Intro to Crystal Programming LanguageIntro to Crystal Programming Language
Intro to Crystal Programming LanguageAdler Hsieh
 
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOUHOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOULucas Jellema
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Thomas Lundström
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language Mobio Solutions
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devopsRob Kinyon
 
JRuby in a Java World
JRuby in a Java WorldJRuby in a Java World
JRuby in a Java WorldMark Menard
 
Agile Graduation Using Ruby
Agile Graduation Using RubyAgile Graduation Using Ruby
Agile Graduation Using RubyWen-Kai Huang
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesCharlie Gracie
 
Ruby formatters
Ruby formattersRuby formatters
Ruby formattersVisuality
 
Functional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakFunctional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakSigma Software
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Why JVM will outlive java?
Why JVM will outlive java?Why JVM will outlive java?
Why JVM will outlive java?Ram Lakshmanan
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereJ On The Beach
 

Tendances (20)

GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22
 
GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28
 
Intro to Crystal Programming Language
Intro to Crystal Programming LanguageIntro to Crystal Programming Language
Intro to Crystal Programming Language
 
Jax keynote
Jax keynoteJax keynote
Jax keynote
 
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOUHOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
HOW AND WHY GRAALVM IS QUICKLY BECOMING RELEVANT FOR YOU
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
Workflow Yapceu2010
Workflow Yapceu2010Workflow Yapceu2010
Workflow Yapceu2010
 
JRuby in a Java World
JRuby in a Java WorldJRuby in a Java World
JRuby in a Java World
 
Agile Graduation Using Ruby
Agile Graduation Using RubyAgile Graduation Using Ruby
Agile Graduation Using Ruby
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
Ruby formatters
Ruby formattersRuby formatters
Ruby formatters
 
Functional solid
Functional solidFunctional solid
Functional solid
 
Functional Solid, Aleksandr Sugak
Functional Solid, Aleksandr SugakFunctional Solid, Aleksandr Sugak
Functional Solid, Aleksandr Sugak
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Why JVM will outlive java?
Why JVM will outlive java?Why JVM will outlive java?
Why JVM will outlive java?
 
History of java
History of javaHistory of java
History of java
 
GraalVM
GraalVMGraalVM
GraalVM
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster Everywhere
 

En vedette

Stefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To RestStefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To Restdeimos
 
Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...
Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...
Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...CA Technologies
 
API, Integration, and SOA Convergence
API, Integration, and SOA ConvergenceAPI, Integration, and SOA Convergence
API, Integration, and SOA ConvergenceKasun Indrasiri
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your BusinessFabernovel
 
API Frenzy: API Strategy 101
API Frenzy: API Strategy 101API Frenzy: API Strategy 101
API Frenzy: API Strategy 101Akana
 
Putting Strategy into Your Social Media Outreach
Putting Strategy into Your Social Media OutreachPutting Strategy into Your Social Media Outreach
Putting Strategy into Your Social Media OutreachKivi Leroux Miller
 
Studywiz whats new - april 2011
Studywiz   whats new - april 2011Studywiz   whats new - april 2011
Studywiz whats new - april 2011Andrew McCarthy
 
Ragtag leadership presentation - BarCamp Auckland 2010
Ragtag leadership presentation - BarCamp Auckland 2010Ragtag leadership presentation - BarCamp Auckland 2010
Ragtag leadership presentation - BarCamp Auckland 2010Simon Young
 
World Tower Sculpture Proposal
World Tower Sculpture ProposalWorld Tower Sculpture Proposal
World Tower Sculpture ProposalBockit
 
syENGAGE Company Profile
syENGAGE Company ProfilesyENGAGE Company Profile
syENGAGE Company ProfileSimon Young
 
Front end development - Les 01
Front end development - Les 01Front end development - Les 01
Front end development - Les 01Atticus
 
Tega Cay Trails
Tega Cay TrailsTega Cay Trails
Tega Cay TrailsBen Ullman
 
Secrets of Social Conversations
Secrets of Social ConversationsSecrets of Social Conversations
Secrets of Social ConversationsJason Falls
 
Granada 1878-g
Granada  1878-gGranada  1878-g
Granada 1878-gamfelisa
 
Toegankelijkheid
ToegankelijkheidToegankelijkheid
ToegankelijkheidAtticus
 
El Arte En Las Manos
El Arte En Las ManosEl Arte En Las Manos
El Arte En Las ManosDescojonate
 

En vedette (20)

Stefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To RestStefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To Rest
 
From webservices to APIs
From webservices to APIsFrom webservices to APIs
From webservices to APIs
 
Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...
Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...
Tech Talk: CA Live API Creator: Modern Integration Strategies—API Integration...
 
API, Integration, and SOA Convergence
API, Integration, and SOA ConvergenceAPI, Integration, and SOA Convergence
API, Integration, and SOA Convergence
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business
 
API Frenzy: API Strategy 101
API Frenzy: API Strategy 101API Frenzy: API Strategy 101
API Frenzy: API Strategy 101
 
CHL
CHLCHL
CHL
 
Putting Strategy into Your Social Media Outreach
Putting Strategy into Your Social Media OutreachPutting Strategy into Your Social Media Outreach
Putting Strategy into Your Social Media Outreach
 
Studywiz whats new - april 2011
Studywiz   whats new - april 2011Studywiz   whats new - april 2011
Studywiz whats new - april 2011
 
Kwis
KwisKwis
Kwis
 
Ragtag leadership presentation - BarCamp Auckland 2010
Ragtag leadership presentation - BarCamp Auckland 2010Ragtag leadership presentation - BarCamp Auckland 2010
Ragtag leadership presentation - BarCamp Auckland 2010
 
Dont Hug Me
Dont Hug MeDont Hug Me
Dont Hug Me
 
World Tower Sculpture Proposal
World Tower Sculpture ProposalWorld Tower Sculpture Proposal
World Tower Sculpture Proposal
 
syENGAGE Company Profile
syENGAGE Company ProfilesyENGAGE Company Profile
syENGAGE Company Profile
 
Front end development - Les 01
Front end development - Les 01Front end development - Les 01
Front end development - Les 01
 
Tega Cay Trails
Tega Cay TrailsTega Cay Trails
Tega Cay Trails
 
Secrets of Social Conversations
Secrets of Social ConversationsSecrets of Social Conversations
Secrets of Social Conversations
 
Granada 1878-g
Granada  1878-gGranada  1878-g
Granada 1878-g
 
Toegankelijkheid
ToegankelijkheidToegankelijkheid
Toegankelijkheid
 
El Arte En Las Manos
El Arte En Las ManosEl Arte En Las Manos
El Arte En Las Manos
 

Similaire à Ola Bini J Ruby Power On The Jvm

J Ruby Power On The Jvm
J Ruby Power On The JvmJ Ruby Power On The Jvm
J Ruby Power On The JvmQConLondon2008
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyelliando dias
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyAmit Solanki
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0Jan Sifra
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro MerbPaul Pajo
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro MerbPaul Pajo
 
Rails on JRuby
Rails on JRubyRails on JRuby
Rails on JRubyRob C
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018Charles Nutter
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsRobert Glaser
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and JavaCharles Anderson
 
JRuby - Java version of Ruby
JRuby - Java version of RubyJRuby - Java version of Ruby
JRuby - Java version of RubyUday Bhaskar
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
New Features of Java7 SE
New Features of Java7 SENew Features of Java7 SE
New Features of Java7 SEdogangoko
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applicationsrailsconf
 

Similaire à Ola Bini J Ruby Power On The Jvm (20)

J Ruby Power On The Jvm
J Ruby Power On The JvmJ Ruby Power On The Jvm
J Ruby Power On The Jvm
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
 
JRuby Basics
JRuby BasicsJRuby Basics
JRuby Basics
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
Why Java
Why JavaWhy Java
Why Java
 
Rails on JRuby
Rails on JRubyRails on JRuby
Rails on JRuby
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
re7olabini
re7olabinire7olabini
re7olabini
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
Modern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On RailsModern Webdevelopment With Ruby On Rails
Modern Webdevelopment With Ruby On Rails
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
 
JRuby - Java version of Ruby
JRuby - Java version of RubyJRuby - Java version of Ruby
JRuby - Java version of Ruby
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
New Features of Java7 SE
New Features of Java7 SENew Features of Java7 SE
New Features of Java7 SE
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applications
 

Plus de deimos

Randy Shoup eBays Architectural Principles
Randy Shoup eBays Architectural PrinciplesRandy Shoup eBays Architectural Principles
Randy Shoup eBays Architectural Principlesdeimos
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwrdeimos
 
Aslak Hellesoy Executable User Stories R Spec Bdd
Aslak Hellesoy Executable User Stories R Spec BddAslak Hellesoy Executable User Stories R Spec Bdd
Aslak Hellesoy Executable User Stories R Spec Bdddeimos
 
Venkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic LanguagesVenkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic Languagesdeimos
 
Udi Dahan Intentions And Interfaces
Udi Dahan Intentions And InterfacesUdi Dahan Intentions And Interfaces
Udi Dahan Intentions And Interfacesdeimos
 
Tim Mackinnon Agile And Beyond
Tim Mackinnon Agile And BeyondTim Mackinnon Agile And Beyond
Tim Mackinnon Agile And Beyonddeimos
 
Steve Vinoski Rest And Reuse And Serendipity
Steve Vinoski Rest And Reuse And SerendipitySteve Vinoski Rest And Reuse And Serendipity
Steve Vinoski Rest And Reuse And Serendipitydeimos
 
Stefan Tilkov Soa Rest And The Web
Stefan Tilkov Soa Rest And The WebStefan Tilkov Soa Rest And The Web
Stefan Tilkov Soa Rest And The Webdeimos
 
Rod Johnson Cathedral
Rod Johnson CathedralRod Johnson Cathedral
Rod Johnson Cathedraldeimos
 
Mike Stolz Dramatic Scalability
Mike Stolz Dramatic ScalabilityMike Stolz Dramatic Scalability
Mike Stolz Dramatic Scalabilitydeimos
 
Matt Youill Betfair
Matt Youill BetfairMatt Youill Betfair
Matt Youill Betfairdeimos
 
Pete Goodliffe A Tale Of Two Systems
Pete Goodliffe A Tale Of Two SystemsPete Goodliffe A Tale Of Two Systems
Pete Goodliffe A Tale Of Two Systemsdeimos
 
Paul Fremantle Restful SOA Registry
Paul Fremantle Restful SOA RegistryPaul Fremantle Restful SOA Registry
Paul Fremantle Restful SOA Registrydeimos
 
Neal Gafter Java Evolution
Neal Gafter Java EvolutionNeal Gafter Java Evolution
Neal Gafter Java Evolutiondeimos
 
Markus Voelter Textual DSLs
Markus Voelter Textual DSLsMarkus Voelter Textual DSLs
Markus Voelter Textual DSLsdeimos
 
Marc Evers People Vs Process Beyond Agile
Marc Evers People Vs Process Beyond AgileMarc Evers People Vs Process Beyond Agile
Marc Evers People Vs Process Beyond Agiledeimos
 
Magnus Christerson Henk Kolk Domain Expert DSLs
Magnus Christerson Henk Kolk Domain Expert DSLsMagnus Christerson Henk Kolk Domain Expert DSLs
Magnus Christerson Henk Kolk Domain Expert DSLsdeimos
 
Linda Rising Born To Cycle
Linda Rising Born To CycleLinda Rising Born To Cycle
Linda Rising Born To Cycledeimos
 
Lasse Koskela What Does It Do Does It Work
Lasse Koskela What Does It Do Does It WorkLasse Koskela What Does It Do Does It Work
Lasse Koskela What Does It Do Does It Workdeimos
 

Plus de deimos (20)

Randy Shoup eBays Architectural Principles
Randy Shoup eBays Architectural PrinciplesRandy Shoup eBays Architectural Principles
Randy Shoup eBays Architectural Principles
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
 
Aslak Hellesoy Executable User Stories R Spec Bdd
Aslak Hellesoy Executable User Stories R Spec BddAslak Hellesoy Executable User Stories R Spec Bdd
Aslak Hellesoy Executable User Stories R Spec Bdd
 
Venkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic LanguagesVenkat Subramaniam Blending Java With Dynamic Languages
Venkat Subramaniam Blending Java With Dynamic Languages
 
Udi Dahan Intentions And Interfaces
Udi Dahan Intentions And InterfacesUdi Dahan Intentions And Interfaces
Udi Dahan Intentions And Interfaces
 
Tim Mackinnon Agile And Beyond
Tim Mackinnon Agile And BeyondTim Mackinnon Agile And Beyond
Tim Mackinnon Agile And Beyond
 
Steve Vinoski Rest And Reuse And Serendipity
Steve Vinoski Rest And Reuse And SerendipitySteve Vinoski Rest And Reuse And Serendipity
Steve Vinoski Rest And Reuse And Serendipity
 
Stefan Tilkov Soa Rest And The Web
Stefan Tilkov Soa Rest And The WebStefan Tilkov Soa Rest And The Web
Stefan Tilkov Soa Rest And The Web
 
Rod Johnson Cathedral
Rod Johnson CathedralRod Johnson Cathedral
Rod Johnson Cathedral
 
Mike Stolz Dramatic Scalability
Mike Stolz Dramatic ScalabilityMike Stolz Dramatic Scalability
Mike Stolz Dramatic Scalability
 
Matt Youill Betfair
Matt Youill BetfairMatt Youill Betfair
Matt Youill Betfair
 
Pete Goodliffe A Tale Of Two Systems
Pete Goodliffe A Tale Of Two SystemsPete Goodliffe A Tale Of Two Systems
Pete Goodliffe A Tale Of Two Systems
 
Paul Fremantle Restful SOA Registry
Paul Fremantle Restful SOA RegistryPaul Fremantle Restful SOA Registry
Paul Fremantle Restful SOA Registry
 
Neal Gafter Java Evolution
Neal Gafter Java EvolutionNeal Gafter Java Evolution
Neal Gafter Java Evolution
 
Markus Voelter Textual DSLs
Markus Voelter Textual DSLsMarkus Voelter Textual DSLs
Markus Voelter Textual DSLs
 
Marc Evers People Vs Process Beyond Agile
Marc Evers People Vs Process Beyond AgileMarc Evers People Vs Process Beyond Agile
Marc Evers People Vs Process Beyond Agile
 
Magnus Christerson Henk Kolk Domain Expert DSLs
Magnus Christerson Henk Kolk Domain Expert DSLsMagnus Christerson Henk Kolk Domain Expert DSLs
Magnus Christerson Henk Kolk Domain Expert DSLs
 
Linda Rising Born To Cycle
Linda Rising Born To CycleLinda Rising Born To Cycle
Linda Rising Born To Cycle
 
Lasse Koskela What Does It Do Does It Work
Lasse Koskela What Does It Do Does It WorkLasse Koskela What Does It Do Does It Work
Lasse Koskela What Does It Do Does It Work
 

Dernier

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Dernier (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Ola Bini J Ruby Power On The Jvm

  • 1. JRuby Power on the JVM Ola Bini JRuby Core Developer ThoughtWorks
  • 2. Vanity slide • Ola Bini • From Stockholm, Sweden • Programming language nerd (Lisp, Ruby, Java, Smalltalk, Io, Erlang, ML, C/C++, etc) • JRuby Core Developer (2 years and running) • Author of Practical JRuby on Rails (APress)
  • 3. Agenda • What is JRuby • How to get started • The implementation • Cool things • Possibly some Rails • Q&A
  • 4. What is JRuby • Implementation of the Ruby language • Java 1.5+ (1.4 for JRuby 1.0) • Retroweaver can be used for 1.4 compatibility • Open source • “It’s just Ruby” • Compatible with Ruby 1.8.6 • JRuby 1.0.3 and 1.1RC3 current releases • 1.0-branch rapidly falling behind
  • 5. Community • 8 Core developers • 40-50 contributors • Outstanding contributions • Like Marcin’s Oniguruma port • Joni is probably the fastest Regexp engine for Java right now
  • 6. Ruby Issues - Threading • Ruby 1.8: Green threading • No scaling across processors/cores • C libraries won’t/can’t yield • One-size-fits-all scheduler • Ruby 1.9: Native, non-parallel execution • JRuby: • Ruby threads are Java threads • World class scheduler with tunable algorithms
  • 7. Ruby Issues - Unicode • Ruby 1.8: Partial Unicode • Internet connection applications MUST have solid Unicode • Ruby 1.8 provides very partial support • App devs roll their own: Rails Multi-byte • Ruby 1.9: Full encoding support • Drastic changes to interface and implementation • Performance issues • Each string can have its own encoding • JRuby: Java Unicode
  • 8. Ruby Issues - Performance • Ruby 1.8: Slower than most languages • 1.8 is usually called “fast enough” • ...but routinely finishes last • ...and no plans to improve in 1.8 • Ruby 1.9: Improvement, but not scalable • New engine about 1.5x for general appliciations • Only implicit AOT compilation • No JIT, no GC or threading changes • JRuby: Compiler provides better performance
  • 9. Ruby Issues - Memory • Ruby 1.8: Memory management • Simple design • Good for many apps, but not scalable • Stop-the-world GC • Ruby 1.9: No change • Improved performance => more garbage • GC problems could multiply • JRuby: World class Java GC’s
  • 10. Ruby Issues - C • Ruby 1.8 & 1.9: C language extensions • C is difficult to write well • Badly-behaved extensions can cause large problems • Threading and GC issues relating to extensions • Portable, but often with recompilation • No security restrictions in the system • JRuby • Java extensions • GC and threading no problem
  • 11. Ruby Issues - Politics • Politics • “You want me to switch to what?” • “... and it needs servers/software/training?” • Potentially better with time (e.g. 1.9) • Legacy • Lots of Java apps in the world • Extensive amount of Java frameworks • JRuby solves both of these by running on top of Java • “Credibility by association”
  • 12. C libraries • JRuby can’t support native extensions • Designed around single-threaded execution • (i.e. one app, one request per process at a time • Stability, security problems • Too permissive Ruby extension API • But who cares? • If you want to do it, there’s a Java library • If no, we support natives access through JNA • And even porting is not that hard
  • 13. Getting started • Java installation • Download JRuby binary distro • Includes JRuby, Ruby stdlib, RubyGems and rake • Unpack • Multiple copies on the system is fine • Add <jruby-dir>/bin to PATH • Install gems (gem install or jruby -S gem install)
  • 14. Calling Ruby from Java • // One-time load Ruby runtime ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName(quot;jrubyquot;); // Evaluate JRuby code from string. try { engine.eval(quot;puts('Hello')quot;); } catch (ScriptException exception) { exception.printStackTrace(); }
  • 16. Implementation: Lexing, parsing • Hand written lexer • Originally ported from MRI • Many changes since then • LALR parser • Port of MRI’s YACC/Bison-based parser • Abstract Syntax Tree quite similar to MRI • We’ve made a few changes and additions
  • 17. Implementation: Core classes • Mostly 1:1 core classes map to Java types • String is RubyString, Array is RubyArray, etc • Annotation based method binding public @interface JRubyMethod { String[] name() default {}; int required() default 0; int optional() default 0; boolean rest() default false; String[] alias() default {}; boolean meta() default false; boolean module() default false; boolean frame() default false; boolean scope() default false; boolean rite() default false; Visibility visibility() default Visibility.PUBLIC; } ... @JRubyMethod(name = quot;openquot;, required = 1, frame = true)
  • 18. Implementation: Interpreter • Simple switch based AST walker • Recurses for nested structures • Most code start out interpreted • Command line scripts compiled immediately • Precompiled script (.class) instead of .rb • Eval’ed code is always interpreted (for now) • Reasonably straight forward code
  • 19. Implementation: Compilation • Full Bytecode compilation • 1.0 had partial JIT compiler (25%) • AST walker emits code structure • Bytecode emitter generates Java class + methods • Real Java bytecode • AOT mode: 1:1 mapping .rb file to .class file • Not a “real” Java class, more a bunch of methods • ... but has a “main” for CLI execution • JIT mode: 1:1 mapping method to in-memory class
  • 21. Compiler problems • AOT pain • Code bodies as Java methods need method handles • Generated as adaptor methods • Ruby is very terse - the compiled output is much more verbose • Mapping symbols safely (class, package, method names) • JIT pain • Method body must live on a class • Class must be live in separate classloader to GC • Class name must be unique within that classloader
  • 22. Compiler optimizations • Preallocated, cached Ruby literals • Java opcodes for local flow-control where possible • Explicit local “return” as cheap as implicit • Explicit local “next”, “break”, etc simple jumps • Java local variables when possible • Methods and leaf closures • leaf == no contained closures • No eval(), binding(), etc calls present • Monomorphic inline method cache • Polymorphic for 1.1 (probably)
  • 23. Core class implementations • String as copy-on-write byte[] impl • Array as copy-on-write Object[] impl • Fast-read Hash implementation • Java “New IO” (NIO) based IO implementation • Example: implementing analogs for libc IO functions • Two custom Regexp implementations • New one works with byte[] directly
  • 24. Threading • JRuby supports only native OS threads • Much heavier than Ruby's green threads • But truly parallel, unlike Ruby 1.9 (GIL) • Emulates unsafe green operations • Thread#kill, Thread#raise inherently unsafe • Thread#critical impossible to guarantee • All emulated with checkpoints (pain...) • Pooling of OS threads minimizes spinup cost
  • 25. POSIX • Normal Ruby native extensions not supported • Maybe in future, but Ruby API exposes too much • Native libraries accessible with JNA • Not JNI...JNA = Java Native Access • Programmatically load libs, call functions • Similar to DL in Ruby • Could easily be used for porting extensions • JNA used for POSIX functions not in Java • Filesystem support (symlinks, stat, chmod, chown, ...)
  • 26. Java Integration • Java types are presented as Ruby types • Construct instances, call methods, pass objects around • camelCase or under_score_case both work • Most Ruby-calling-Java code looks just like Ruby • Integration with Java type hierarchy • Implement Java interfaces • longhand “include SomeInterface” • shorthand “SomeInterface.impl { ... }” • closure conversion “add_action_listener { ... }” • Extend Java concrete and abstract Java types
  • 27. Performance • No, it's not all that important • Until it is! • JRuby 1.0 was about 2x slower than Ruby 1.8.6 • JRuby 1.1 Beta 1 was about 2x faster • JRuby trunk is 5x faster, often faster than 1.9 • As a result, we've stopped working on perf for now • ...but targeting Java performance next
  • 29. JRuby Internals • JRuby::ast_for(“1+1”) #-> Java AST JRuby::ast_for { 1+1 } #-> Java AST JRuby::compile(“1+1”) #-> CompiledScript CompiledScript.inspect_bytecode JRuby::runtime JRuby::reference(“str”)
  • 30. ... evil stuff • a = “foobar” a.freeze JRuby::reference(a).setFrozen(false) • class Foobar; end something = Object.new JRuby::reference(something).setMetaClass(Foobar) • class Foobar; end JRuby::reference(Foobar).getMethods()
  • 31. JRuby on Rails - end to end • Create application • Package into a WAR-file, using • Warbler • JRubyWorks • Goldspike • Deploy WAR file to any Java Web Container • Jetty, Tomcat, GlassFish • Oracle Application Server, JBoss, WebSphere • WebLogic
  • 32. JtestR • Test Java code with Ruby • Glues JRuby together with state of the art Ruby libraries • Includes RSpec, Test::Unit, dust, Mocha, etc • Ant and Maven 2 integration • 0.2 to be released “any time now” (tm)
  • 33. Rubiq • Lisp layer on top of JRuby • Transforms to JRuby AST • ... and lets JRuby execute it • Macros • Read macros (used to implement regexp syntax, for example) • Pure lexical scoping • Lambdas transparently transforms to blocks or Proc.new
  • 34. ActiveHibernate • # define a model (or you can use existing) class Project include Hibernate with_table_name quot;PROJECTSquot; #optional #column name is optional primary_key_accessor :id, :long, :PROJECT_ID hattr_accessor :name, :string hattr_accessor :complexity, :double end # connect ActiveHibernate.establish_connection(DB_CONFIG) # create project = Project.new(:name => quot;JRubyquot;, :complexity => 10) project.save project_id = project.id # query all_projects = Project.find(:all) jruby_project = Project.find(project_id) # update jruby_project.complexity = 37 jruby_project.save
  • 35. Ruvlets • Expose Servlets as Ruby API • Because we can! • People keep asking for this....really! • Expose highly tuned web-infrastructure to Ruby • Similar in L&F to Camping • How it works: • Evaluates file from load path based on URL • File returns an object with a 'service' method defined • Object cached for all future requests
  • 36. Bare bones Ruvlet • class HelloWorld def service(context, request, response) response.content_type = quot;text/htmlquot; response.writer << <<-EOF <html> <head><title>Hello World!</title></head> <body>Hello World!</body> </html> EOF end end HelloWorld.new
  • 37. YARV & Rubinius machine • YARV • 2.0 Compatibility • Simple machine • Simple compiler • Might give interpreted performance improvement • Rubinius • Simple machine • Quite outdated at the moment • Why do it? Why not?
  • 38. JSR292, JLR & DaVinci • Dynamic invocation: non-java call sites • Method handles • Anonymous classes • Faster reflection, escape analysis • Interface injection • Continuations • Value objects (Lisp fixnums) • Tuple types • Tail calls
  • 39. JRuby’s future • Get 1.1 out there • Rework the Java Integration features • Create a stable public API for extensions • Better performance (as always) • Support for Ruby 1.9 features • Light weight objects • JSR292 support • Rubinius? • More primitives in Ruby?
  • 40.
  • 41. Resources • jruby.org • #jruby on freenode • glassfish.dev.java.net • openjdk.java.net/projects/mlvm • jtestr.codehaus.org • code.google.com/p/activehibernate • headius.blogspot.com • ola-bini.blogspot.com
  • 42. Q&A