SlideShare uma empresa Scribd logo
1 de 62
Baixar para ler offline
Nick Sieger
@nicksieger
(RE-)
INTRO
Ruby on
the JVM
Best of Ruby
 and Java...
 Together!
http://www.flickr.com/photos/texascooking/5864122096/
COMPAT
IBILITY
runs nearly all pure ruby code

runs 92% of rubyspec suite

runs ~30% of 1.9 test suite

(even more with 1.8 mode)
http://jruby.org/download

    rvm install jruby

   INSTALL   gem install jruby-lint




             $ jrlint
drawbacks
startup time

memory footprint

native code

no Kernel#fork
PERFOR
MANCE
GC.pauses =
 “no thanks”
class Simple
  attr_accessor :next
end

top = Simple.new

puts Benchmark.measure {
  outer = 10
  total = 100000
  per = 100

  outer.times do
    total.times do
      per.times { Simple.new }
      s = Simple.new
      top.next = s
      top = s
    end
  end
}
Ruby 1.9.3              JRuby
8000


6000


4000


2000


  0
                    GC count
Ruby 1.9.3              JRuby
10000


 1000


  100


   10


    1
                     GC count
15
     Ruby 1.9.3               JRuby

12


9


6


3


0
                  GC time %
Time per GC versus heap usage

300ms

              Ruby 2.0.0                JRuby
225ms


150ms


75ms


 0ms
 188KB/29MB                27MB/127MB           199MB/238MB

                 Heap usage (MRI/JRuby)
REAL
THREADS
Ruby 1.9     Ruby 1.9
unthreaded   threaded




  JRuby        JRuby
unthreaded   threaded
sidekiq.org
 What if 1 Sidekiq process could
 do the work of 20 Resque or
 DelayedJob processes?
COMPILER
Ruby application code

     JVM bytecode           Key

        Native code




                          Ruby             Ruby
     Ruby code
                          code             code
                                  Ruby             Ruby
        JRuby             JRuby            JRuby
                                  code             code
                                                           Ruby
         JVM              JVM     JRuby    JVM     JRuby
                                                           code


Full interpretation      JRuby compiler   HotSpot compiler

 Time
BENCH
MARKS
Red-Black Tree
5


4
          ruby 1.9.3p286
          jruby 1.7.0 java 1.6.0_29
3
          jruby 1.7.0 java 1.7.0_09
          jruby 1.7.0 java 1.7.0_09-b05 +indy
2


1


0
Times Faster than Ruby 1.9.3
  5
           JRuby/Java 6                   JRuby/Java 7+indy
                                                     4.226           4.32
3.75
                                          3.66
                           3.44
 2.5       2.658

                                  1.914          1.806
1.25               1.538                                     1.565
       1.346


  0
        base64     richards        neural mandelbrot redblack
Java 7
Get JDK 7
   (OSX too!)
java.oracle.com
INVOKE
DYNAMIC
experthuman.com/
programming-with-
      nothing
    Tom Stuart
    @tomstuart
# lambda
-> x {
}
# call
p[x]
FIZZ
BUZZ
(1..100).each do |n|
  if (n % 15).zero?
    puts 'FizzBuzz'
  elsif (n % 3).zero?
    puts 'Fizz'
  elsif (n % 5).zero?
    puts 'Buzz'
  else
    puts n.to_s
  end
end
fizzbuzz = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x {
f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p {
p[-> x { -> y { x } } ] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { ->
y { y } } ] }[-> p { p[-> x { -> y { y } } ] }[l]] }[l]][x][g]][-> l {
-> p { p[-> x { -> y { x } } ] }[-> p { p[-> x { -> y { y } } ] }[l]]
}[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y
{ x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y
{ -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f {
f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y {
x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b
{ b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y
{ x } }] }[-> m { -> n { n[-> n { -> f { -> x { n[-> g { -> h {
h[g[f]] } }][-> y { x }][-> y { y }] } } }][m] } }[m][n]] }
}[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x
{ -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n {
-> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f {
f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p {
-> x { p[x] } }][-> p { -> x {p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[
p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[
p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[
p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]} }]][-> n { -> b {
b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f
{ -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f {
-> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y
} } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> f { -> x {
n[-> g { -> h { h[g[f]] } }][-> y { x }][-> y { y }] } } }][m] }
METHOD
HANDLES
INVOKEDYNAMIC
           [bootstrapMethod]


bootstrapMethod():
                           Call Site
  CallSite (once)
                                target

                           Method
                           Handle
package java.lang.invoke;

public abstract class MethodHandle {
    public final native Object invoke(Object... args)
        throws Throwable;
}
LAMBDA
  p[x]
methodHandle.invoke(x);
java.lang.invoke.
       MethodHandles
 arrayElementGetter arrayElementSetter
   spreadInvoker exactInvoker invoker
explicitCastArguments permuteArguments
    constant identity insertArguments
       dropArguments dropArguments
    filterArguments filterReturnValue
       foldArguments guardWithTest
      catchException throwException
String literal
 Constant lookup
  Other literals
Instance variables
Method invocation
 Math operations
IT’S A JVM
  WORLD
DRIVE JAVA
FROM RUBY
require 'java'
require 'rubygems'
require 'flying_saucer'

java_import org.xhtmlrenderer.pdf.ITextRenderer

document = <<-HTML
<html><body><h1>Hello Flying Saucer!</h1></body></html>
HTML

File.open("doc.pdf", "wb") do |out|
  renderer = ITextRenderer.new
  renderer.set_document_from_string document
  renderer.layout
  renderer.create_pdf out.to_outputstream
end

system("open doc.pdf")



 jruby -S gem install flying_saucer to try this example.
$ jruby saucer.rb
DECORATE
JAVA OBJECTS
 WITH JRUBY
module java::util::Iterator
  include Enumerable

  def each
    while has_next
      yield self.next
    end
  end
end
DRIVE RUBY
   FROM JAVA
(org.jruby.embed)
import org.jruby.embed.ScriptingContainer;

public class EmbedJRuby {
    public static void main(String[] args) {
        ScriptingContainer container = new ScriptingContainer();
        container.runScriptlet("puts 'Hello from Ruby'");
    }
}



(defn -main
  "Call JRuby!"
  [& args]
  (doto (org.jruby.embed.ScriptingContainer.)
    (.runScriptlet "puts 'Hello from Ruby!'")))
JRuby +
 Clojure
;; examples.clj
(def hmap (hash-map "foo" "FOO"
                    "bar" "BAR"
                    "baz" "BAZ"))

(println hmap)
(println (get hmap "bar"))
(println (contains? hmap "foo"))
# ruby
Java::clojure.main.main(["./examples.clj"])
github.com/
  daveray/
  familiar
Familiar.with do
  # clojure.core functions here
  # ‘-’ replaced with ‘_’
  # e.g. hash-map => hash_map
end
Familiar.with do
  r = ref(nil)

  begin
    ref_set r, 'foo'
  rescue
    puts "no transaction! #{$!}"
  end

  dosync do
    ref_set r, 'foo'
  end
  p deref(r)
end
j.mp/
  clojure-
from-jruby
FUTURE
{,bugs,wiki,ci}
   jruby.org
github.com/
    jruby
Thanks!

Mais conteúdo relacionado

Mais procurados

JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
Tom Croucher
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 
Oral presentation v2
Oral presentation v2Oral presentation v2
Oral presentation v2
Yeqi He
 

Mais procurados (20)

Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Supercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicSupercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamic
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
 
node ffi
node ffinode ffi
node ffi
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.
 
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
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Web
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Java libraries you can't afford to miss
Java libraries you can't afford to missJava libraries you can't afford to miss
Java libraries you can't afford to miss
 
mruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしmruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなし
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Alfresco the clojure way
Alfresco the clojure wayAlfresco the clojure way
Alfresco the clojure way
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Dispatch in Clojure
Dispatch in ClojureDispatch in Clojure
Dispatch in Clojure
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Oral presentation v2
Oral presentation v2Oral presentation v2
Oral presentation v2
 

Semelhante a JRuby @ Boulder Ruby

Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
Keith Bennett
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
Jan Sifra
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
tobiascrawley
 

Semelhante a JRuby @ Boulder Ruby (20)

JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 
Aloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyAloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRuby
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Profiling Ruby
Profiling RubyProfiling Ruby
Profiling Ruby
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
JRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVMJRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVM
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
How to Begin Developing Ruby Core
How to Begin Developing Ruby CoreHow to Begin Developing Ruby Core
How to Begin Developing Ruby Core
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
 
Groovy
GroovyGroovy
Groovy
 
Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Quick Intro To JRuby
Quick Intro To JRubyQuick Intro To JRuby
Quick Intro To JRuby
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

JRuby @ Boulder Ruby

  • 2.
  • 5. Best of Ruby and Java... Together!
  • 8. runs nearly all pure ruby code runs 92% of rubyspec suite runs ~30% of 1.9 test suite (even more with 1.8 mode)
  • 9. http://jruby.org/download rvm install jruby INSTALL gem install jruby-lint $ jrlint
  • 13. GC.pauses = “no thanks”
  • 14. class Simple   attr_accessor :next end top = Simple.new puts Benchmark.measure {   outer = 10   total = 100000   per = 100   outer.times do     total.times do       per.times { Simple.new }       s = Simple.new       top.next = s       top = s     end   end }
  • 15. Ruby 1.9.3 JRuby 8000 6000 4000 2000 0 GC count
  • 16. Ruby 1.9.3 JRuby 10000 1000 100 10 1 GC count
  • 17. 15 Ruby 1.9.3 JRuby 12 9 6 3 0 GC time %
  • 18. Time per GC versus heap usage 300ms Ruby 2.0.0 JRuby 225ms 150ms 75ms 0ms 188KB/29MB 27MB/127MB 199MB/238MB Heap usage (MRI/JRuby)
  • 20. Ruby 1.9 Ruby 1.9 unthreaded threaded JRuby JRuby unthreaded threaded
  • 21. sidekiq.org What if 1 Sidekiq process could do the work of 20 Resque or DelayedJob processes?
  • 23. Ruby application code JVM bytecode Key Native code Ruby Ruby Ruby code code code Ruby Ruby JRuby JRuby JRuby code code Ruby JVM JVM JRuby JVM JRuby code Full interpretation JRuby compiler HotSpot compiler Time
  • 25. Red-Black Tree 5 4 ruby 1.9.3p286 jruby 1.7.0 java 1.6.0_29 3 jruby 1.7.0 java 1.7.0_09 jruby 1.7.0 java 1.7.0_09-b05 +indy 2 1 0
  • 26. Times Faster than Ruby 1.9.3 5 JRuby/Java 6 JRuby/Java 7+indy 4.226 4.32 3.75 3.66 3.44 2.5 2.658 1.914 1.806 1.25 1.538 1.565 1.346 0 base64 richards neural mandelbrot redblack
  • 28. Get JDK 7 (OSX too!) java.oracle.com
  • 30. experthuman.com/ programming-with- nothing Tom Stuart @tomstuart
  • 34. (1..100).each do |n| if (n % 15).zero? puts 'FizzBuzz' elsif (n % 3).zero? puts 'Fizz' elsif (n % 5).zero? puts 'Buzz' else puts n.to_s end end
  • 35. fizzbuzz = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } } ] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } } ] }[-> p { p[-> x { -> y { y } } ] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } } ] }[-> p { p[-> x { -> y { y } } ] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> f { -> x { n[-> g { -> h { h[g[f]] } }][-> y { x }][-> y { y }] } } }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x {p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[ p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[ p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[ p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]} }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> f { -> x { n[-> g { -> h { h[g[f]] } }][-> y { x }][-> y { y }] } } }][m] }
  • 37. INVOKEDYNAMIC [bootstrapMethod] bootstrapMethod(): Call Site CallSite (once) target Method Handle
  • 38. package java.lang.invoke; public abstract class MethodHandle { public final native Object invoke(Object... args) throws Throwable; }
  • 41. java.lang.invoke. MethodHandles arrayElementGetter arrayElementSetter spreadInvoker exactInvoker invoker explicitCastArguments permuteArguments constant identity insertArguments dropArguments dropArguments filterArguments filterReturnValue foldArguments guardWithTest catchException throwException
  • 42. String literal Constant lookup Other literals Instance variables Method invocation Math operations
  • 43. IT’S A JVM WORLD
  • 45. require 'java' require 'rubygems' require 'flying_saucer' java_import org.xhtmlrenderer.pdf.ITextRenderer document = <<-HTML <html><body><h1>Hello Flying Saucer!</h1></body></html> HTML File.open("doc.pdf", "wb") do |out| renderer = ITextRenderer.new renderer.set_document_from_string document renderer.layout renderer.create_pdf out.to_outputstream end system("open doc.pdf") jruby -S gem install flying_saucer to try this example.
  • 48. module java::util::Iterator include Enumerable def each while has_next yield self.next end end end
  • 49. DRIVE RUBY FROM JAVA (org.jruby.embed)
  • 50. import org.jruby.embed.ScriptingContainer; public class EmbedJRuby { public static void main(String[] args) { ScriptingContainer container = new ScriptingContainer(); container.runScriptlet("puts 'Hello from Ruby'"); } } (defn -main "Call JRuby!" [& args] (doto (org.jruby.embed.ScriptingContainer.) (.runScriptlet "puts 'Hello from Ruby!'")))
  • 52. ;; examples.clj (def hmap (hash-map "foo" "FOO" "bar" "BAR" "baz" "BAZ")) (println hmap) (println (get hmap "bar")) (println (contains? hmap "foo"))
  • 55. Familiar.with do # clojure.core functions here # ‘-’ replaced with ‘_’ # e.g. hash-map => hash_map end
  • 56. Familiar.with do r = ref(nil) begin ref_set r, 'foo' rescue puts "no transaction! #{$!}" end dosync do ref_set r, 'foo' end p deref(r) end
  • 59.
  • 60. {,bugs,wiki,ci} jruby.org
  • 61. github.com/ jruby