Inlining
Combine and optimize across calls
Method 1
CALL Method 2
Slide 13
Slide 13 text
Inlining
Combine and optimize across calls
Method 1
Method 2
Slide 14
Slide 14 text
Ruby was slow
Once upon a time...
Slide 15
Slide 15 text
Ruby with JIT
•JRuby
•Rubinius
•MacRuby
Slide 16
Slide 16 text
JRuby JIT
Slide 17
Slide 17 text
Architecture Diagram
Slide 18
Slide 18 text
Start by interpreting
Walk the parse tree
RUBY
Slide 19
Slide 19 text
Locate “hot spots”
RUBY
Over 50 method invocations
Slide 20
Slide 20 text
Compile to bytecode
RUBY
Ruby code becomes JVM instructions
B
Y
T
E
C
O
D
E
B
Y
T
E
C
O
D
E
B
Y
T
E
C
O
D
E
B
Y
T
E
C
O
D
E
B
Y
T
E
C
O
D
E
Slide 21
Slide 21 text
HotSpot JITs too
RUBY
Ruby code becomes machine code
B
Y
T
E
C
O
D
E
B
Y
T
E
C
O
D
E
1
0
1
0
1
0
1
0
1
0
1
0
Slide 22
Slide 22 text
JVM Limitations
Slide 23
Slide 23 text
Made for Java
•InvokeVirtual
•InvokeInterface
•InvokeStatic
•InvokeSpecial
Slide 24
Slide 24 text
JVM is smart!
•C++ virtual methods: SLOW!
•InvokeVirtual: FAST!
Slide 25
Slide 25 text
JVM = old dog
Can’t learn new tricks
Slide 26
Slide 26 text
Y U NO InvokeRuby?
Slide 27
Slide 27 text
Y U NO InvokeRuby?
Y U NO InvokeGroovy?
Y U NO InvokeJavaScript?
Y U NO InvokeClojure?
Slide 28
Slide 28 text
What if we could
teach the JVM the
fast path?
Slide 29
Slide 29 text
What if it worked for
any language?
Slide 30
Slide 30 text
One Invoke to rule
them all!
Slide 31
Slide 31 text
How?
Slide 32
Slide 32 text
InvokeDynamic
Slide 33
Slide 33 text
InDy
Slide 34
Slide 34 text
InDy
•Shipped in Java 7
•Supported in JRuby 1.7
•JRuby 1.7 release preview available
next week!
Slide 35
Slide 35 text
What is InDy?
Slide 36
Slide 36 text
New JVM
instruction
Slide 37
Slide 37 text
method_missing
for Invoke
Slide 38
Slide 38 text
InDy is a
“callback”
Slide 39
Slide 39 text
Bootstrap method
Slide 40
Slide 40 text
Bootstrap method
Wire up the call site
Slide 41
Slide 41 text
Bootstrap method
Your own code!
Slide 42
Slide 42 text
Bootstrap Method
•Called on all classes that use InDy
•Find MethodHandle to dispatch
•Return CallSite object
Slide 43
Slide 43 text
Bootstrap Method
•Invoked the first time a call site is used
•Resulting call site object is “bound” to
where InDy was invoked and is used
for subsequent calls
•CallSites can designate their own
caching behavior