SlideShare una empresa de Scribd logo
1 de 60
Descargar para leer sin conexión
a.k.a IBM’s Ruby JIT Talk
Experiments in Sharing Java
VM Technology with CRuby
1
RubyKaigi 2015
Matthew
Gaudet
• Compiler Developer
@ IBM Canada
• Compilation
Technology since
2008 – JIT since
last year.
• First time off the
North American
Tectonic Plate!
4
No Pressure!
Why does
have a Ruby JIT?
IBM + Cloud
It’s a
Polyglot
World Out
There
• Many languages! Great
reasons to use each
and every one of them!
• At IBM, we want to
support these
languages, helping
them to grow
capabilities.
• Let developers choose
the right language for
the job, rather than
selecting on capabilities
7
How can we
minimize
duplicated
effort?
8
The Plan:
9
OMR
OMR
An Open Source Toolkit for
Language Runtime
Technologies.
OMR
Heritage: Built out of IBM’s
Java Runtime Technology.
• Announced by Mark
Stoodley at JVMLS 2015
• See the complete talk on
YouTube.
OMR
Garbage
Collector
JIT Compiler
Monitoring
Porting Library
…More!
Components
OMR
Goal: Compatibility!
Integrate vs. Replace
OMR
Philosophy: Assemble the right
solution for your language.
Language Free
Monitoring Components
Your Language
Monitoring Components
Language Free
GC Components
Your language
GC Components
Language Free
JIT Components
Your Language JIT
Components
Your LanguageRuby
Why so quiet?
a.k.a Why haven’t you seen us posting on ruby-core?
16
“The future is already
here, it’s just not very
evenly distributed”
– William Gibson
18
• IBM is getting better at
Open Source
• We are coming from a
traditionally closed-
source part of IBM
• We are learning – part
of why I’m here is to
listen and learn.
19
“Open Source is a
huge part of IBM, but
isn’t evenly distributed”
– Me
Proving our Proof Of Concept
We wanted to ensure we were happy
with the concept.
We needed to know it would work before
coming to communities
20
This is real
technology
Early parts of this
already shipping in
IBM Products:
• Automatic Binary
Optimizer for
COBOL
• IBM JDK 8
• … and more!
21
“I don’t always re-engineer
my runtime technologies…
but when I do, I do it in
production”
-- The IBM Runtimes Team
This is real
technology
Working on Open
Source as fast as we
can, within the
constraints of
shipping software!
22
“I don’t always re-engineer
my runtime technologies…
but when I do, I do it in
production”
-- The IBM Runtimes Team
I’m a JIT person….
So let’s talk about JIT Compiler tech.
Testarossa
System Z
POWER
X86
C/C++
COBOL
ARM
OMR’s Compiler Technology: Testarossa
Started in 1999 as a dynamic language JIT for Java
COBOL binaries
StaticCompilers
• Written in C++
• 100+ Optimizations
MRI
YARV
Interpreter
Garbage
Collector
Ruby IL
Generator Optimizer Code
Generator
ProfilerRuntime
Testarossa
Code Cache
JIT integration
Our effort to date has emphasized
Functional Correctness.
No big changes to how MRI works (to ease
adoption)
No restrictions on native code used by extension
modules
No benchmark tuning
Very simple compilation control
We Can Run Rails Applications
Integrating
Testarossa
into MRI
1. Initialization /
Termination
void Init_BareVM(void) {
…
globals.ruby_vm_global_constant_state_ptr =
&ruby_vm_global_constant_state;
globals.ruby_rb_mRubyVMFrozenCore_ptr =
&rb_mRubyVMFrozenCore;
globals.ruby_vm_event_flags_ptr =
&ruby_vm_event_flags;
vm_jit_init(vm, globals);
…
}
int ruby_vm_destruct(rb_vm_t *vm)
{
…
vm_jit_destroy(vm);
…
}
Integrating
Testarossa
into MRI
static VALUE
vm_jitted_p(rb_thread_t *th, rb_iseq_t *iseq)
{
...
if (iseq->jit.state == ISEQ_JIT_STATE_JITTED)
return Qtrue;
...
--iseq->jit.u.count;
if (iseq->jit.u.count < 0) {
return vm_jit(th,iseq);
}
return Qfalse;
}
1. Initialization /
Termination
2. Compilation Control
Integrating
Testarossa
into MRI
vm_exec(rb_thread_t *th)
{
...
vm_loop_start:
result = vm_exec_core(th, initial);
...
1. Initialization /
Termination
2. Compilation Control
3. Code Dispatch
Integrating
Testarossa
into MRI
vm_exec(rb_thread_t *th)
{
...
vm_loop_start:
result = vm_exec2(th, initial);
...
static inline VALUE
vm_exec2(rb_thread_t *th, VALUE initial)
{
VALUE result;
if (VM_FRAME_TYPE(th->cfp)
!= VM_FRAME_MAGIC_RESCUE &&
VM_FRAME_TYPE_FINISH_P(th->cfp) &&
vm_jitted_p(th, th->cfp->iseq) == Qtrue) {
return vm_exec_jitted(th);
} else {
return vm_exec_core(th, initial);
}
}
1. Initialization /
Termination
2. Compilation Control
3. Code Dispatch
Integrating
Testarossa
into MRI
require 'test/unit'
class JITModuleTest < Test::Unit::TestCase
def addone(x)
return x + 1
end
def test_jit_control
am = method(:addone)
# No testing occurs unless the JIT exists.
if RubyVM::JIT::exists?
assert_equal(false,
RubyVM::JIT::compiled?(am) )
assert_equal(true,
RubyVM::JIT::compile(am) )
assert_equal(true,
RubyVM::JIT::compiled?(am) )
end
end
end
1. Initialization /
Termination
2. Compilation Control
3. Code Dispatch
4. Expose to Ruby
A brief YARV interlude
33
YARV: Yet Another Ruby VM
0000 trace 8
0002 trace 1
0004 putself
0005 getlocal a
0007 getlocal a
0009 opt_mult <ic:2>
0011 send :puts, 1, nil, 8, <ic:1>
0017 trace 16
0019 leave
def product(a)
puts a * a
end
YARV DEFINE_INSN
instruction_name
(instruction_operands, ...)
(pop values, ...)
(return values, ...)
{
... // insn body
}
• Instructions are
stored in a
definition file
• Processed by Ruby
code into C, then
#included in
YARV core
35
Complex
Op-Codes
DEFINE_INSN
getlocal
(lindex_t idx, rb_num_t level) //operand
() // pop
(VALUE val) // push
{
int i, lev = (int)level;
VALUE *ep = GET_EP();
for (i = 0; i < lev; i++) {
ep = GET_PREV_EP(ep);
}
val = *(ep - idx);
}
Many Ruby op-codes
have complex
semantics
36
Complex
Op-Codes
DEFINE_INSN
defined
(rb_num_t op_type, VALUE obj, VALUE needstr)
(VALUE v)
(VALUE val)
{
VALUE klass;
enum defined_type expr_type = 0;
enum defined_type type = (enum
defined_type)op_type;
val = Qnil;
switch (type) {
case DEFINED_IVAR:
if (rb_ivar_defined(GET_SELF(), SYM2ID(obj))) {
expr_type = DEFINED_IVAR;
}
break;
case DEFINED_IVAR2:
klass = vm_get_cbase(GET_ISEQ(), GET_EP());
break;
case DEFINED_GVAR:
if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) {
expr_type = DEFINED_GVAR;
}
break;
case DEFINED_CVAR: {
NODE *cref = rb_vm_get_cref(GET_ISEQ(),
GET_EP());
klass = vm_get_cvar_base(cref, GET_CFP());
if (rb_cvar_defined(klass, SYM2ID(obj))) {
expr_type = DEFINED_CVAR;
}
break;
}
case DEFINED_CONST:
klass = v;
if (vm_get_ev_const(th, GET_ISEQ(), klass,
SYM2ID(obj), 1)) {
expr_type = DEFINED_CONST;
}
break;
case DEFINED_FUNC:
klass = CLASS_OF(v);
if (rb_method_boundp(klass, SYM2ID(obj), 0)) {
expr_type = DEFINED_METHOD;
}
break;
case DEFINED_METHOD:{
VALUE klass = CLASS_OF(v);
const rb_method_entry_t *me =
rb_method_entry(klass, SYM2ID(obj), 0);
if (me) {
if (!(me->flag & NOEX_PRIVATE)) {
if (!((me->flag & NOEX_PROTECTED) &&
!rb_obj_is_kind_of(GET_SELF(),
rb_class_real(klass)))) {
expr_type = DEFINED_METHOD;
}
}
}
{
VALUE args[2];
VALUE r;
args[0] = obj; args[1] = Qfalse;
r = rb_check_funcall(v, idRespond_to_missing, 2,
args);
if (r != Qundef && RTEST(r))
expr_type = DEFINED_METHOD;
}
break;
}
case DEFINED_YIELD:
if (GET_BLOCK_PTR()) {
expr_type = DEFINED_YIELD;
}
break;
case DEFINED_ZSUPER:{
rb_call_info_t cit;
if (vm_search_superclass(GET_CFP(), GET_ISEQ(),
Qnil, &cit) == 0) {
VALUE klass = cit.klass;
ID id = cit.mid;
if (rb_method_boundp(klass, id, 0)) {
expr_type = DEFINED_ZSUPER;
}
}
break;
}
case DEFINED_REF:{
val = vm_getspecial(th, GET_LEP(), Qfalse,
FIX2INT(obj));
if (val != Qnil) {
expr_type = DEFINED_GVAR;
}
break;
}
default:
rb_bug("unimplemented defined? type (VM)");
break;
}
if (expr_type != 0) {
if (needstr != Qfalse) {
val = rb_iseq_defined_string(expr_type);
}
else {
val = Qtrue;
}
}
}
Many Ruby op-codes
have complex
semantics very
complex semantics.
37
Testarossa Intermediate Language
iload a
iload b
isub
bipush 2
imul
istore a
istore atreetop
iconst 2
imul
iload a
iload b
isub
Java Bytecode
• Testarossa uses a tree-based intermediate
representation.
• tree represents a single expression
• treetop represents statement and program order.
treetop …
…
…
Testarossa Intermediate Language
getlocal 0
lloadi (slot0)treetop
aloadi (ep)
aload (rb_thread_t)
aloadi (cfp)
Ruby Bytecode
• Ruby IL Generation creates trees for each bytecode.
• Complicated bytecode behavior leads to size expansion
th->cfp->ep[slot0]
Our
Strategy:
• Mimic interpreter
for maximum
compatibility.
• Implement
simple opcodes
directly in IL
40
IL
Our
Strategy:
• Build callbacks
to VM for
complex
opcodes.
• Automatically
generate
callbacks
from the
instruction
definition file.
41
IL
callback
Our
Strategy:
• Fast-path
particular
patterns
• e.g trace
42
IL
callback
IL
IL
callback
Our
Strategy:
• Don’t try to
handle
everything – let
interpreter
handle hard
cases!
43
IL
callback
IL
IL
callback
JIT Status:
Based on Ruby 2.2.3
Almost all opcodes supported
Running test-all, running real applications (like
Spree)
44
Performance
a.k.a. We’ve still got room to grow!
45
46
SpeedupRelativetoInterpreter
Micro Benchmarks
3x
2x
1x
47
‘Production’ Benchmarks
SpeedupRelativetoInterpreter
48
17.3% Improvement
(Geomean)
22.5%
Geomean
Improvement
Interpreter Interpreter + JIT
Onwards and Upwards
a.k.a. The Future
49
Challenges
MRI is challenging for JIT compilers!
• Highly dynamic
• Unmanaged direct use of internal data
structures by extensions
• Complicated runtime, with many subtle details:
setjmp/longjmp intertwined with control flow
and exception handling.
Opportunities to bring to Ruby
• Speculative optimizations powered by
decompilation and code-patching
• Class Hierarchy Based Optimization
• Guarded inlining
• Type Specialization
• Recompilation
• Interpreter and JIT Profiling
• Asynchronous Compilation
• More optimization!
• OMR’s Ruby JIT uses only 10 / 100+ optimizations.
Opportunities
Type
Specialization
Inlining
Value & Type
propagation
Opportunities
RecompilationProfilin
3x3
IBM Wants to Help
Share our experience, help make Ruby faster!
Contribute VM improvements.
Collaborate on designs: e.g. a JIT Interface,
event notification hooks, etc.
Ruby+OMR
Technology
Preview
Download @
goo.gl/P3yXuy
• Releasing a
preview so you
can start test-
driving
• Send us
feedback!
55
Long Term
OMR LLVM
≈
?
goo.gl/P3yXuy
Thank You!
ありがとう
57
Keep in Touch!
Matthew Gaudet,
OMR JIT Developer
magaudet@ca.ibm.com
@MattStudies
Mark Stoodley,
OMR Project Lead
mstoodle@ca.ibm.com
@mstoodle
John Duimovich,
CTO IBM Runtimes
duimovic@ca.ibm.com
@jduimovich
goo.gl/P3yXuy
Trademarks, Copyrights, Disclaimers
IBM’s statements regarding its plans, directions, and intent are subject to change or withdrawal without notice at IBM’s
sole discretion. Information regarding potential future products is intended to outline our general product direction and it
should not be relied on in making a purchasing decision. The information mentioned regarding potential future products is
not a commitment, promise, or legal obligation to deliver any material, code or functionality. Information about potential
future products may not be incorporated into any contract. The development, release, and timing of any future features or
functionality described for our products remains at our sole discretion.
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions
worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of other IBM trademarks is available on the
web at "Copyright and trademark information" at http://www.ibm.com/legal/copytrade.shtml
Other company, product, or service names may be trademarks or service marks of others.
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE
MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED "AS
IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON IBM’S CURRENT PRODUCT
PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM WITHOUT NOTICE. IBM SHALL NOT BE RESPONSIBLE FOR ANY
DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING
CONTAINED IN THIS PRESENTATION IS INTENDED TO, NOR SHALL HAVE THE EFFECT OF, CREATING ANY WARRANTIES OR
REPRESENTATIONS FROM IBM (OR ITS SUPPLIERS OR LICENSORS), OR ALTERING THE TERMS AND CONDITIONS OF ANY AGREEMENT
OR LICENSE GOVERNING THE USE OF IBM PRODUCTS OR SOFTWARE.
© Copyright International Business Machines Corporation 2015. All rights reserved.
Additional Important Disclaimers
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS
PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST
RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.
ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY,
WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE
RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
- CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR
LICENSORS
Attributions
 gopher.{ai,svg,png} was created by Takuya Ueda (http://u.hinoichi.net). Licensed under the
Creative Commons 3.0 Attributions license.
 Rails Photo: Arne Hückelheim ,
https://en.wikipedia.org/wiki/Railroad_switch#/media/File:SunsetTracksCrop.JPG

Más contenido relacionado

La actualidad más candente

Gemification plan of Standard Library on Ruby
Gemification plan of Standard Library on RubyGemification plan of Standard Library on Ruby
Gemification plan of Standard Library on RubyHiroshi SHIBATA
 
Improve extension API: C++ as better language for extension
Improve extension API: C++ as better language for extensionImprove extension API: C++ as better language for extension
Improve extension API: C++ as better language for extensionKouhei Sutou
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOLiran Zvibel
 
Java & low latency applications
Java & low latency applicationsJava & low latency applications
Java & low latency applicationsRuslan Shevchenko
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)Douglas Chen
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 FeaturesAndreas Enbohm
 
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 OredevMattias Karlsson
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby do_aki
 
How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?Hiroshi SHIBATA
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9Marcus Lagergren
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018Charles Nutter
 
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 TwitterAlex Payne
 
The secret of programming language development and future
The secret of programming  language development and futureThe secret of programming  language development and future
The secret of programming language development and futureHiroshi SHIBATA
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)Ontico
 
tDiary annual report 2009 - Sapporo Ruby Kaigi02
tDiary annual report 2009 - Sapporo Ruby Kaigi02tDiary annual report 2009 - Sapporo Ruby Kaigi02
tDiary annual report 2009 - Sapporo Ruby Kaigi02Hiroshi SHIBATA
 

La actualidad más candente (20)

Gemification plan of Standard Library on Ruby
Gemification plan of Standard Library on RubyGemification plan of Standard Library on Ruby
Gemification plan of Standard Library on Ruby
 
Improve extension API: C++ as better language for extension
Improve extension API: C++ as better language for extensionImprove extension API: C++ as better language for extension
Improve extension API: C++ as better language for extension
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
 
Java & low latency applications
Java & low latency applicationsJava & low latency applications
Java & low latency applications
 
Pfm technical-inside
Pfm technical-insidePfm technical-inside
Pfm technical-inside
 
Scala
ScalaScala
Scala
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
 
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
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby
 
How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?
 
Apache Thrift
Apache ThriftApache Thrift
Apache Thrift
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
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
 
The secret of programming language development and future
The secret of programming  language development and futureThe secret of programming  language development and future
The secret of programming language development and future
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
 
tDiary annual report 2009 - Sapporo Ruby Kaigi02
tDiary annual report 2009 - Sapporo Ruby Kaigi02tDiary annual report 2009 - Sapporo Ruby Kaigi02
tDiary annual report 2009 - Sapporo Ruby Kaigi02
 

Similar a Experiments in Sharing Java VM Technology with CRuby

Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsSerge Stinckwich
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)jeffz
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeDmitri Nesteruk
 
Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native CompilerSimon Ritter
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptx고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptxssuser1e7611
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for RubyHiroshi SHIBATA
 
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
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?Charlie Gracie
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?Charlie Gracie
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediZeroTurnaround
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingPositive Hack Days
 
Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Monica Beckwith
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 

Similar a Experiments in Sharing Java VM Technology with CRuby (20)

Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
Os Lattner
Os LattnerOs Lattner
Os Lattner
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Jax keynote
Jax keynoteJax keynote
Jax keynote
 
Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native Compiler
 
MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introduction
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptx고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptx
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for 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
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?JavaOne2015-What's in an Object?
JavaOne2015-What's in an Object?
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila Szegedi
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash Cracking
 
Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 

Último

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

Último (20)

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Experiments in Sharing Java VM Technology with CRuby

  • 1. a.k.a IBM’s Ruby JIT Talk Experiments in Sharing Java VM Technology with CRuby 1 RubyKaigi 2015
  • 2. Matthew Gaudet • Compiler Developer @ IBM Canada • Compilation Technology since 2008 – JIT since last year. • First time off the North American Tectonic Plate!
  • 3.
  • 5. Why does have a Ruby JIT?
  • 7. It’s a Polyglot World Out There • Many languages! Great reasons to use each and every one of them! • At IBM, we want to support these languages, helping them to grow capabilities. • Let developers choose the right language for the job, rather than selecting on capabilities 7
  • 10. OMR An Open Source Toolkit for Language Runtime Technologies.
  • 11. OMR Heritage: Built out of IBM’s Java Runtime Technology. • Announced by Mark Stoodley at JVMLS 2015 • See the complete talk on YouTube.
  • 14. OMR Philosophy: Assemble the right solution for your language.
  • 15. Language Free Monitoring Components Your Language Monitoring Components Language Free GC Components Your language GC Components Language Free JIT Components Your Language JIT Components Your LanguageRuby
  • 16. Why so quiet? a.k.a Why haven’t you seen us posting on ruby-core? 16
  • 17.
  • 18. “The future is already here, it’s just not very evenly distributed” – William Gibson 18
  • 19. • IBM is getting better at Open Source • We are coming from a traditionally closed- source part of IBM • We are learning – part of why I’m here is to listen and learn. 19 “Open Source is a huge part of IBM, but isn’t evenly distributed” – Me
  • 20. Proving our Proof Of Concept We wanted to ensure we were happy with the concept. We needed to know it would work before coming to communities 20
  • 21. This is real technology Early parts of this already shipping in IBM Products: • Automatic Binary Optimizer for COBOL • IBM JDK 8 • … and more! 21 “I don’t always re-engineer my runtime technologies… but when I do, I do it in production” -- The IBM Runtimes Team
  • 22. This is real technology Working on Open Source as fast as we can, within the constraints of shipping software! 22 “I don’t always re-engineer my runtime technologies… but when I do, I do it in production” -- The IBM Runtimes Team
  • 23. I’m a JIT person…. So let’s talk about JIT Compiler tech.
  • 24. Testarossa System Z POWER X86 C/C++ COBOL ARM OMR’s Compiler Technology: Testarossa Started in 1999 as a dynamic language JIT for Java COBOL binaries StaticCompilers • Written in C++ • 100+ Optimizations
  • 25. MRI YARV Interpreter Garbage Collector Ruby IL Generator Optimizer Code Generator ProfilerRuntime Testarossa Code Cache
  • 26. JIT integration Our effort to date has emphasized Functional Correctness. No big changes to how MRI works (to ease adoption) No restrictions on native code used by extension modules No benchmark tuning Very simple compilation control
  • 27. We Can Run Rails Applications
  • 28. Integrating Testarossa into MRI 1. Initialization / Termination void Init_BareVM(void) { … globals.ruby_vm_global_constant_state_ptr = &ruby_vm_global_constant_state; globals.ruby_rb_mRubyVMFrozenCore_ptr = &rb_mRubyVMFrozenCore; globals.ruby_vm_event_flags_ptr = &ruby_vm_event_flags; vm_jit_init(vm, globals); … } int ruby_vm_destruct(rb_vm_t *vm) { … vm_jit_destroy(vm); … }
  • 29. Integrating Testarossa into MRI static VALUE vm_jitted_p(rb_thread_t *th, rb_iseq_t *iseq) { ... if (iseq->jit.state == ISEQ_JIT_STATE_JITTED) return Qtrue; ... --iseq->jit.u.count; if (iseq->jit.u.count < 0) { return vm_jit(th,iseq); } return Qfalse; } 1. Initialization / Termination 2. Compilation Control
  • 30. Integrating Testarossa into MRI vm_exec(rb_thread_t *th) { ... vm_loop_start: result = vm_exec_core(th, initial); ... 1. Initialization / Termination 2. Compilation Control 3. Code Dispatch
  • 31. Integrating Testarossa into MRI vm_exec(rb_thread_t *th) { ... vm_loop_start: result = vm_exec2(th, initial); ... static inline VALUE vm_exec2(rb_thread_t *th, VALUE initial) { VALUE result; if (VM_FRAME_TYPE(th->cfp) != VM_FRAME_MAGIC_RESCUE && VM_FRAME_TYPE_FINISH_P(th->cfp) && vm_jitted_p(th, th->cfp->iseq) == Qtrue) { return vm_exec_jitted(th); } else { return vm_exec_core(th, initial); } } 1. Initialization / Termination 2. Compilation Control 3. Code Dispatch
  • 32. Integrating Testarossa into MRI require 'test/unit' class JITModuleTest < Test::Unit::TestCase def addone(x) return x + 1 end def test_jit_control am = method(:addone) # No testing occurs unless the JIT exists. if RubyVM::JIT::exists? assert_equal(false, RubyVM::JIT::compiled?(am) ) assert_equal(true, RubyVM::JIT::compile(am) ) assert_equal(true, RubyVM::JIT::compiled?(am) ) end end end 1. Initialization / Termination 2. Compilation Control 3. Code Dispatch 4. Expose to Ruby
  • 33. A brief YARV interlude 33
  • 34. YARV: Yet Another Ruby VM 0000 trace 8 0002 trace 1 0004 putself 0005 getlocal a 0007 getlocal a 0009 opt_mult <ic:2> 0011 send :puts, 1, nil, 8, <ic:1> 0017 trace 16 0019 leave def product(a) puts a * a end
  • 35. YARV DEFINE_INSN instruction_name (instruction_operands, ...) (pop values, ...) (return values, ...) { ... // insn body } • Instructions are stored in a definition file • Processed by Ruby code into C, then #included in YARV core 35
  • 36. Complex Op-Codes DEFINE_INSN getlocal (lindex_t idx, rb_num_t level) //operand () // pop (VALUE val) // push { int i, lev = (int)level; VALUE *ep = GET_EP(); for (i = 0; i < lev; i++) { ep = GET_PREV_EP(ep); } val = *(ep - idx); } Many Ruby op-codes have complex semantics 36
  • 37. Complex Op-Codes DEFINE_INSN defined (rb_num_t op_type, VALUE obj, VALUE needstr) (VALUE v) (VALUE val) { VALUE klass; enum defined_type expr_type = 0; enum defined_type type = (enum defined_type)op_type; val = Qnil; switch (type) { case DEFINED_IVAR: if (rb_ivar_defined(GET_SELF(), SYM2ID(obj))) { expr_type = DEFINED_IVAR; } break; case DEFINED_IVAR2: klass = vm_get_cbase(GET_ISEQ(), GET_EP()); break; case DEFINED_GVAR: if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) { expr_type = DEFINED_GVAR; } break; case DEFINED_CVAR: { NODE *cref = rb_vm_get_cref(GET_ISEQ(), GET_EP()); klass = vm_get_cvar_base(cref, GET_CFP()); if (rb_cvar_defined(klass, SYM2ID(obj))) { expr_type = DEFINED_CVAR; } break; } case DEFINED_CONST: klass = v; if (vm_get_ev_const(th, GET_ISEQ(), klass, SYM2ID(obj), 1)) { expr_type = DEFINED_CONST; } break; case DEFINED_FUNC: klass = CLASS_OF(v); if (rb_method_boundp(klass, SYM2ID(obj), 0)) { expr_type = DEFINED_METHOD; } break; case DEFINED_METHOD:{ VALUE klass = CLASS_OF(v); const rb_method_entry_t *me = rb_method_entry(klass, SYM2ID(obj), 0); if (me) { if (!(me->flag & NOEX_PRIVATE)) { if (!((me->flag & NOEX_PROTECTED) && !rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass)))) { expr_type = DEFINED_METHOD; } } } { VALUE args[2]; VALUE r; args[0] = obj; args[1] = Qfalse; r = rb_check_funcall(v, idRespond_to_missing, 2, args); if (r != Qundef && RTEST(r)) expr_type = DEFINED_METHOD; } break; } case DEFINED_YIELD: if (GET_BLOCK_PTR()) { expr_type = DEFINED_YIELD; } break; case DEFINED_ZSUPER:{ rb_call_info_t cit; if (vm_search_superclass(GET_CFP(), GET_ISEQ(), Qnil, &cit) == 0) { VALUE klass = cit.klass; ID id = cit.mid; if (rb_method_boundp(klass, id, 0)) { expr_type = DEFINED_ZSUPER; } } break; } case DEFINED_REF:{ val = vm_getspecial(th, GET_LEP(), Qfalse, FIX2INT(obj)); if (val != Qnil) { expr_type = DEFINED_GVAR; } break; } default: rb_bug("unimplemented defined? type (VM)"); break; } if (expr_type != 0) { if (needstr != Qfalse) { val = rb_iseq_defined_string(expr_type); } else { val = Qtrue; } } } Many Ruby op-codes have complex semantics very complex semantics. 37
  • 38. Testarossa Intermediate Language iload a iload b isub bipush 2 imul istore a istore atreetop iconst 2 imul iload a iload b isub Java Bytecode • Testarossa uses a tree-based intermediate representation. • tree represents a single expression • treetop represents statement and program order. treetop … … …
  • 39. Testarossa Intermediate Language getlocal 0 lloadi (slot0)treetop aloadi (ep) aload (rb_thread_t) aloadi (cfp) Ruby Bytecode • Ruby IL Generation creates trees for each bytecode. • Complicated bytecode behavior leads to size expansion th->cfp->ep[slot0]
  • 40. Our Strategy: • Mimic interpreter for maximum compatibility. • Implement simple opcodes directly in IL 40 IL
  • 41. Our Strategy: • Build callbacks to VM for complex opcodes. • Automatically generate callbacks from the instruction definition file. 41 IL callback
  • 42. Our Strategy: • Fast-path particular patterns • e.g trace 42 IL callback IL IL callback
  • 43. Our Strategy: • Don’t try to handle everything – let interpreter handle hard cases! 43 IL callback IL IL callback
  • 44. JIT Status: Based on Ruby 2.2.3 Almost all opcodes supported Running test-all, running real applications (like Spree) 44
  • 45. Performance a.k.a. We’ve still got room to grow! 45
  • 49. Onwards and Upwards a.k.a. The Future 49
  • 50. Challenges MRI is challenging for JIT compilers! • Highly dynamic • Unmanaged direct use of internal data structures by extensions • Complicated runtime, with many subtle details: setjmp/longjmp intertwined with control flow and exception handling.
  • 51. Opportunities to bring to Ruby • Speculative optimizations powered by decompilation and code-patching • Class Hierarchy Based Optimization • Guarded inlining • Type Specialization • Recompilation • Interpreter and JIT Profiling • Asynchronous Compilation • More optimization! • OMR’s Ruby JIT uses only 10 / 100+ optimizations.
  • 54. 3x3 IBM Wants to Help Share our experience, help make Ruby faster! Contribute VM improvements. Collaborate on designs: e.g. a JIT Interface, event notification hooks, etc.
  • 55. Ruby+OMR Technology Preview Download @ goo.gl/P3yXuy • Releasing a preview so you can start test- driving • Send us feedback! 55
  • 57. Thank You! ありがとう 57 Keep in Touch! Matthew Gaudet, OMR JIT Developer magaudet@ca.ibm.com @MattStudies Mark Stoodley, OMR Project Lead mstoodle@ca.ibm.com @mstoodle John Duimovich, CTO IBM Runtimes duimovic@ca.ibm.com @jduimovich goo.gl/P3yXuy
  • 58. Trademarks, Copyrights, Disclaimers IBM’s statements regarding its plans, directions, and intent are subject to change or withdrawal without notice at IBM’s sole discretion. Information regarding potential future products is intended to outline our general product direction and it should not be relied on in making a purchasing decision. The information mentioned regarding potential future products is not a commitment, promise, or legal obligation to deliver any material, code or functionality. Information about potential future products may not be incorporated into any contract. The development, release, and timing of any future features or functionality described for our products remains at our sole discretion. IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of other IBM trademarks is available on the web at "Copyright and trademark information" at http://www.ibm.com/legal/copytrade.shtml Other company, product, or service names may be trademarks or service marks of others. THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM WITHOUT NOTICE. IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, NOR SHALL HAVE THE EFFECT OF, CREATING ANY WARRANTIES OR REPRESENTATIONS FROM IBM (OR ITS SUPPLIERS OR LICENSORS), OR ALTERING THE TERMS AND CONDITIONS OF ANY AGREEMENT OR LICENSE GOVERNING THE USE OF IBM PRODUCTS OR SOFTWARE. © Copyright International Business Machines Corporation 2015. All rights reserved.
  • 59. Additional Important Disclaimers THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS
  • 60. Attributions  gopher.{ai,svg,png} was created by Takuya Ueda (http://u.hinoichi.net). Licensed under the Creative Commons 3.0 Attributions license.  Rails Photo: Arne Hückelheim , https://en.wikipedia.org/wiki/Railroad_switch#/media/File:SunsetTracksCrop.JPG