SlideShare a Scribd company logo
Ruby on the JVM
  Kresten Krab Thorup, Ph.D.
         CTO, Trifork
A bit of history...
  Smalltalk
    Self            OTI Smalltalk
 Strongtalk          VisualAge

  HotSpot             IBM Java
              Sun             IBM
Adaptive Optimizations
• Key insight:   The VM knows more about
  your program than you do.
• Consequence: Let the VM adapt to
  program’s behavior
 • VM will observe, tally and measure
 • feed information into successive
    optimizations
Time/Space Trade Off
• Classical compiler “ideology”
 • “ahead of time” compilers don’t know
    which parts of the code to optimize
 • gcc -O0 ... -O6
• Adaptive VMs
 • Affords letting the program run for a while
    to see where optimizations will pay off.
The Ruby Nature
• Program is created as it is being
  executed
 • Class / module declarations are really
   statements, not declarations.
 • Programming style employs meta
   programming extensively
• Very similar to Java, just “worse” :-)
“Just In Time” VMs
• For interpreted-style languages, perform
  compilation when the program definition is
  known.
• AFAIK Strongtalk/HotSpot brought the
  innovation of a two-level VM:
  • start interpreted (running byte code)
  • optimize adaptively
The “HotRuby” project
• Explore a “Server VM” for Ruby
  based on Java
• Assume “long running processes” where we
  can afford “slow start”.
• Assume aggressive memory usage
• Exploit knowledge of how the JVM
  optimizes programs
HotRuby Architecture
                  shared meta
                     model



    interpreter                 compiler


 ~MRI performance        ~2.5 x YARV performance
Design Philosophy

• Develop compiler and interpreter in
  parallel, and
• Favor compiler in the design of the runtime
  meta model
• Make trade-offs that reduce memory usage
• Write as much as possible in Ruby itself
Major Head Aches
• Method invocation
 • Calling “virtual” methods is slow
 • Program can change in many ways while
    running


• Memory management
 • Garbage collection is a resource hog
Naive Implementation

class RubyObject {
   RubyClass isa;
   HashTable<String,RubyObject> ivars;
   boolean frozen, tainted;
}
Naive Implementation
class RubyModule extends RubyObject {
  RubyVM vm;
  List<RubyModule> included_modules;
  HashTable<String,Callable> imethods;
  HashTable<String,Callable> mmethods;
  HashTable<String,RubyObject> constants;
}

class RubyClass extends RubyModule {
  RubyClass super_class;
}
Naive Implementation

class Callable {
   RubyObject call(RubyObject self,
                   RubyObject[] args,
                   RubyBlock block,
                   CallContext ctx);
}
Naive Implementation
  def m(obj)
    obj.foo(1, BAR)
  end

... translates into something like ...
  ctx = new MethodActivation(...);
  ctx.set_local(args[0]);
  obj = ctx.get_local(0)
  one = ctx.new_fixnum(1);
  bar = ctx.lookup_const(“BAR”);
  callable = obj.isa.imethods.get(“foo”);
  callable.call(obj, [one, bar], null, ctx)
Naive Implementation

       Ruby level


       Java level
Optimizing Calls

• Special-case common method names for
  core classes (new, +, -, [], ...): They turn into
  Java-level virtual calls.
• Compiled code is “specialized”, ...
• Method lookup is “compiled”, ...
Method Specialization
• Compiled code is “specialized” for the
  receiving type,
  • making self-calls non virtual,
  • reducing public/private/protected checks:
    Security-checks happen at method-
    lookup, not invocation time.
  • making constant lookups really constant.
Compiled Lookup
• With the “Naive” implementation, method
  lookup is data-driven (HashTable).
• Compiled lookup means that we dynamically
  generate/modify code, as the lookup table
  changes.
• Allows the JVM’s optimizing compiler to
  “know” how/when to eliminate or inline
  lookups.
Reduce Footprint

• Reduce size of heap for “active state” in a
  virtual machine
• Reduce “object churn”, i.e. rate of generated
  garbage.
Reducing Footprint
• Java objects already have an “isa” pointer!
  The implicit class reference.
• Use Java-level instance variables (in most
  cases)
• Eliminate the arguments array for method
  invocations (in most cases).
• Use Java-level local variables, removing the
  need for a “MethodActivation” object for
  each method call.
HotRuby Object
class RubyFoo {
   ObjectState state = null;
   RubyClass isa()
      { return state==null
          ? RubyClassFoo.class_object
          : state.singletonClass; }
}

class ObjectState {
    boolean frozen, tained;
    RubyClass singletonClass;
    HashTable<String,RubyObject> ivars;
}
HotRuby @ivars
• Generate Java classes lazily, upon first
  instantiation.
• At that point, analyze all applicable methods
  for reference to @ivars
• Generate Java-level ivars for all such
  references.
• Additional ivars go into ObjectState’s hash
  table.
Reducing Footprint
• The “Naive” implementation has an
  overhead per object of
     20 bytes + ~20 bytes / ivar
• HotRuby ideally reduces this to
     12 bytes + 4 bytes / ivar
• Heap of 100.000 object with an average 3
  ivars => 83% memory saving.
Use Java-Level locals
• The “cost” for having MethodActivation
  objects is both
 • The memory it consumes
 • The fact that such memory needs to be
    garbage collected
• Fall-back to MethodActivation object
  strategy for methods that call eval (and
  friends), and for local variables referenced
  from inner blocks.
HotRuby Status

• Runs basic Ruby programs (most
  importantly runit)
 • No Continuations, ObjectSpace,
    debugger, ... and many core classes
• Performance at 2.5 x YARV
• No, it does not run Rails.
Thanks
The Ruby
“Freak Show”
  ... getting started
Super Strange


def doit(x, y)
    super.doit(x, y)
end
Super Strange


def doit(x, y)
    super(x, y)
end
Super Strange


def doit(x, y)
    super
end
Super Strange


def doit(x, y=2, z=3)
    super
end
Super Strange


def doit(x, y=super, z=3)
    x+y+z
end
Super Strange


def doit(x, y=super(x,y,z), z=3)
    x+y+z
end
Thanks

More Related Content

What's hot (20)

Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Adler Hsieh
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
Tomer Gabel
 
Scalatra 2.2
Scalatra 2.2Scalatra 2.2
Scalatra 2.2
Ivan Porto Carrero
 
Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
prajods
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
Junichi Ishida
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
Metosin Oy
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
Carsten Ziegeler
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
How to-node-core
How to-node-coreHow to-node-core
How to-node-core
IsaacSchlueter
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
Ricardo Sanchez
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
krasserm
 
Rango
RangoRango
Rango
James Russell
 
Applying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScriptApplying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScript
Julian Gamble
 
Rango
RangoRango
Rango
James Russell
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
FuseSource.com
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Julian Gamble
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
guest05c09d
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
Alex Derkach
 
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Adler Hsieh
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
Tomer Gabel
 
Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
prajods
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
Junichi Ishida
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
Metosin Oy
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
Carsten Ziegeler
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
Ricardo Sanchez
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
krasserm
 
Applying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScriptApplying the paradigms of core.async in Clojure and ClojureScript
Applying the paradigms of core.async in Clojure and ClojureScript
Julian Gamble
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
FuseSource.com
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Julian Gamble
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
guest05c09d
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
Alex Derkach
 

Viewers also liked (9)

Ins Avis N4
Ins Avis N4Ins Avis N4
Ins Avis N4
marsetti
 
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Kresten Krab Thorup
 
Strade dipinte
Strade dipinteStrade dipinte
Strade dipinte
marsetti
 
Erjang - A JVM-based Erlang VM
Erjang - A JVM-based Erlang VMErjang - A JVM-based Erlang VM
Erjang - A JVM-based Erlang VM
Kresten Krab Thorup
 
Album 1 1976 1984
Album 1 1976 1984Album 1 1976 1984
Album 1 1976 1984
marsetti
 
Ins Avis N9
Ins Avis N9Ins Avis N9
Ins Avis N9
marsetti
 
Ins Avis N1
Ins Avis N1Ins Avis N1
Ins Avis N1
marsetti
 
Album 5 2006 2007
Album 5 2006   2007Album 5 2006   2007
Album 5 2006 2007
marsetti
 
Storia_shay
Storia_shayStoria_shay
Storia_shay
marsetti
 
Ins Avis N4
Ins Avis N4Ins Avis N4
Ins Avis N4
marsetti
 
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Kresten Krab Thorup
 
Strade dipinte
Strade dipinteStrade dipinte
Strade dipinte
marsetti
 
Album 1 1976 1984
Album 1 1976 1984Album 1 1976 1984
Album 1 1976 1984
marsetti
 
Ins Avis N9
Ins Avis N9Ins Avis N9
Ins Avis N9
marsetti
 
Ins Avis N1
Ins Avis N1Ins Avis N1
Ins Avis N1
marsetti
 
Album 5 2006 2007
Album 5 2006   2007Album 5 2006   2007
Album 5 2006 2007
marsetti
 
Storia_shay
Storia_shayStoria_shay
Storia_shay
marsetti
 

Similar to Ruby on the JVM (20)

The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
juanvazquezslides
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
Wen-Tien Chang
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
Ortus Solutions, Corp
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
SVDevOps
 
BoxLang JVM Language : The Future is Dynamic
BoxLang JVM Language : The Future is DynamicBoxLang JVM Language : The Future is Dynamic
BoxLang JVM Language : The Future is Dynamic
Ortus Solutions, Corp
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Nayden Gochev
 
遇見 Ruby on Rails
遇見 Ruby on Rails遇見 Ruby on Rails
遇見 Ruby on Rails
Wen-Tien Chang
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
Joshua Ballanco
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
Invokedynamic / JSR-292
Invokedynamic / JSR-292Invokedynamic / JSR-292
Invokedynamic / JSR-292
ytoshima
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
Mario Camou Riveroll
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
juanvazquezslides
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
Wen-Tien Chang
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
Ortus Solutions, Corp
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
SVDevOps
 
BoxLang JVM Language : The Future is Dynamic
BoxLang JVM Language : The Future is DynamicBoxLang JVM Language : The Future is Dynamic
BoxLang JVM Language : The Future is Dynamic
Ortus Solutions, Corp
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Nayden Gochev
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?MacRuby: What is it? and why should you care?
MacRuby: What is it? and why should you care?
Joshua Ballanco
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
Invokedynamic / JSR-292
Invokedynamic / JSR-292Invokedynamic / JSR-292
Invokedynamic / JSR-292
ytoshima
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
Mario Camou Riveroll
 

Recently uploaded (20)

IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 

Ruby on the JVM

  • 1. Ruby on the JVM Kresten Krab Thorup, Ph.D. CTO, Trifork
  • 2. A bit of history... Smalltalk Self OTI Smalltalk Strongtalk VisualAge HotSpot IBM Java Sun IBM
  • 3. Adaptive Optimizations • Key insight: The VM knows more about your program than you do. • Consequence: Let the VM adapt to program’s behavior • VM will observe, tally and measure • feed information into successive optimizations
  • 4. Time/Space Trade Off • Classical compiler “ideology” • “ahead of time” compilers don’t know which parts of the code to optimize • gcc -O0 ... -O6 • Adaptive VMs • Affords letting the program run for a while to see where optimizations will pay off.
  • 5. The Ruby Nature • Program is created as it is being executed • Class / module declarations are really statements, not declarations. • Programming style employs meta programming extensively • Very similar to Java, just “worse” :-)
  • 6. “Just In Time” VMs • For interpreted-style languages, perform compilation when the program definition is known. • AFAIK Strongtalk/HotSpot brought the innovation of a two-level VM: • start interpreted (running byte code) • optimize adaptively
  • 7. The “HotRuby” project • Explore a “Server VM” for Ruby based on Java • Assume “long running processes” where we can afford “slow start”. • Assume aggressive memory usage • Exploit knowledge of how the JVM optimizes programs
  • 8. HotRuby Architecture shared meta model interpreter compiler ~MRI performance ~2.5 x YARV performance
  • 9. Design Philosophy • Develop compiler and interpreter in parallel, and • Favor compiler in the design of the runtime meta model • Make trade-offs that reduce memory usage • Write as much as possible in Ruby itself
  • 10. Major Head Aches • Method invocation • Calling “virtual” methods is slow • Program can change in many ways while running • Memory management • Garbage collection is a resource hog
  • 11. Naive Implementation class RubyObject { RubyClass isa; HashTable<String,RubyObject> ivars; boolean frozen, tainted; }
  • 12. Naive Implementation class RubyModule extends RubyObject { RubyVM vm; List<RubyModule> included_modules; HashTable<String,Callable> imethods; HashTable<String,Callable> mmethods; HashTable<String,RubyObject> constants; } class RubyClass extends RubyModule { RubyClass super_class; }
  • 13. Naive Implementation class Callable { RubyObject call(RubyObject self, RubyObject[] args, RubyBlock block, CallContext ctx); }
  • 14. Naive Implementation def m(obj) obj.foo(1, BAR) end ... translates into something like ... ctx = new MethodActivation(...); ctx.set_local(args[0]); obj = ctx.get_local(0) one = ctx.new_fixnum(1); bar = ctx.lookup_const(“BAR”); callable = obj.isa.imethods.get(“foo”); callable.call(obj, [one, bar], null, ctx)
  • 15. Naive Implementation Ruby level Java level
  • 16. Optimizing Calls • Special-case common method names for core classes (new, +, -, [], ...): They turn into Java-level virtual calls. • Compiled code is “specialized”, ... • Method lookup is “compiled”, ...
  • 17. Method Specialization • Compiled code is “specialized” for the receiving type, • making self-calls non virtual, • reducing public/private/protected checks: Security-checks happen at method- lookup, not invocation time. • making constant lookups really constant.
  • 18. Compiled Lookup • With the “Naive” implementation, method lookup is data-driven (HashTable). • Compiled lookup means that we dynamically generate/modify code, as the lookup table changes. • Allows the JVM’s optimizing compiler to “know” how/when to eliminate or inline lookups.
  • 19. Reduce Footprint • Reduce size of heap for “active state” in a virtual machine • Reduce “object churn”, i.e. rate of generated garbage.
  • 20. Reducing Footprint • Java objects already have an “isa” pointer! The implicit class reference. • Use Java-level instance variables (in most cases) • Eliminate the arguments array for method invocations (in most cases). • Use Java-level local variables, removing the need for a “MethodActivation” object for each method call.
  • 21. HotRuby Object class RubyFoo { ObjectState state = null; RubyClass isa() { return state==null ? RubyClassFoo.class_object : state.singletonClass; } } class ObjectState { boolean frozen, tained; RubyClass singletonClass; HashTable<String,RubyObject> ivars; }
  • 22. HotRuby @ivars • Generate Java classes lazily, upon first instantiation. • At that point, analyze all applicable methods for reference to @ivars • Generate Java-level ivars for all such references. • Additional ivars go into ObjectState’s hash table.
  • 23. Reducing Footprint • The “Naive” implementation has an overhead per object of 20 bytes + ~20 bytes / ivar • HotRuby ideally reduces this to 12 bytes + 4 bytes / ivar • Heap of 100.000 object with an average 3 ivars => 83% memory saving.
  • 24. Use Java-Level locals • The “cost” for having MethodActivation objects is both • The memory it consumes • The fact that such memory needs to be garbage collected • Fall-back to MethodActivation object strategy for methods that call eval (and friends), and for local variables referenced from inner blocks.
  • 25. HotRuby Status • Runs basic Ruby programs (most importantly runit) • No Continuations, ObjectSpace, debugger, ... and many core classes • Performance at 2.5 x YARV • No, it does not run Rails.
  • 27. The Ruby “Freak Show” ... getting started
  • 28. Super Strange def doit(x, y) super.doit(x, y) end
  • 29. Super Strange def doit(x, y) super(x, y) end
  • 31. Super Strange def doit(x, y=2, z=3) super end
  • 32. Super Strange def doit(x, y=super, z=3) x+y+z end
  • 33. Super Strange def doit(x, y=super(x,y,z), z=3) x+y+z end
  翻译: