SlideShare ist ein Scribd-Unternehmen logo
1 von 51
About me
1
Guelph ES&C Grad – spring 2014
Currently employed at IBM as a
Runtime Technologies Software Dev
Twitter: @craiglehmann
Ruby Under The Hood
http://lolsnaps.com/upload_pic/EveryTimeILookUnderThe
HoodOfACar-97946.jpg
Program compilation
3
Program compilation
4
Program compilation
5
Program compilation
6
3.times do |n|
puts n
end
Program compilation
7
Tokens:
3.times do |n|
puts n
end puts
ndo
end
3 dot times
Program compilation
8
AST
3.times do |n|
puts n
end
puts n
3 times
call
block
command
Program compilation
9
The Ruby Interpreter?
The Ruby Interpreter implements a virtual machine.
10
Bytecode Interpreter
 The main VM execution loop.
 Maps bytecodes to executable native instructions.
 Implements a virtual stack machine.
 Individual bytecodes implemented in C.
11
12
Ruby is a Stack Machine!
Push Down Stack
13
1 + 2
Push Down Stack
14
1 + 2 Push 1
Push 2
opt_plus
Bytecodes:
Push Down Stack
15
1 + 2 Push 1
Push 2
opt_plus
Bytecodes:
1
Push 1
Push Down Stack
16
1 + 2 Push 1
Push 2
opt_plus
Bytecodes:
1
Push 1
2
Push 2
1
Push Down Stack
17
1 + 2 Push 1
Push 2
opt_plus
Bytecodes:
1
Push 1
2
Push 2
3
opt_plus
1
Call Stack example and compiled method
18
def do_things
puts "Hello World"
end
Putself
Putstring “Hello World”
opt_send_simple
Three Stacks
19
def do_things
puts "Hello World"
end
Putself
Putstring “Hello World”
opt_send_simple
C Stack VM Stack Ruby Call Stack
Call Stack example and compiled method
20
def do_things
puts "Hello World"
end
Putself
Putstring “Hello World”
opt_send_simple
call_method
C Stack
exec_core
…
main()
VM Stack Ruby Call Stack
Call Stack example and compiled method
21
def do_things
puts "Hello World"
end
Putself
Putstring “Hello World”
opt_send_simple
call_method
C Stack
exec_core
…
main()
opt_send_simple puts
VM Stack
“hello World”
self
Ruby Call Stack
Call Stack example and compiled method
22
def do_things
puts "Hello World"
end
Putself
Putstring “Hello World”
opt_send_simple
call_method
C Stack
exec_core
…
main()
opt_send_simple puts
VM Stack
“hello World”
self
puts
Ruby Call Stack
do_things
Three Stacks
23
call_method
C Stack
exec_core
…
main()
opt_send_simple puts
VM Stack
“hello World”
self
puts
Ruby Call Stack
do_things
What does this look like in the Ruby’s VM?
24
puts
Ruby Call Stack
do_things
def do_things
puts "Hello World"
end
What does this look like in the Ruby’s VM?
25
puts
Ruby Call Stack
do_things
def do_things
puts "Hello World"
end
PC
Control Frame
SP
Self
type
What does this look like in the Ruby’s VM?
26
puts
Ruby Call Stack
do_things
def do_things
puts "Hello World"
end
PC
Control Frame
SP
Self
type
putself
putstring “Hello World”
opt_send_simple
What does this look like in the Ruby’s VM?
27
puts
Ruby Call Stack
do_things
def do_things
puts "Hello World"
end
PC
Control Frame
SP
Self
type
putself
putstring “Hello World”
opt_send_simple
opt_send_simple puts
VM Stack
“hello World”
self
Class lookup? What happens when you want to create
an object?
28
class Person
end
p = Person.new()
Class lookup? What happens when you want to create
an object?
29
class Person
end
p = Person.new()
Class lookup? What happens when you want to create
an object?
30
class Person
end
p = Person.new()
Person = "Craig"
#Warning: already initialized constant person
Intro to garbage collection
What is garbage collection?
Different types of garbage collection algorithms
Mark & Sweep demo
31
32
What is garbage collection?
 Automatic memory management
 Manually managing memory is hard!
 Aggregate freeing memory & object destruction operations
 Gives the illusion of unlimited memory
33
Different types of garbage collection algorithms
 Reference Counting
• Keep a count along with each object indicating how many references it currently
has. An object with 0 references can have it's memory re-used.
• Cannot manage cyclically referenced objects.
 Tracing Algorithms
• keep track of which objects are in use by recursively tracing objects referring to
other objects, starting from a root set of objects.
What does it mean to die
• An object consumes one resource, memory.
• When an object becomes unreachable, it can never be used again.
• Cycles are collected together, the mutator cannot access these
object.
• Sweeping objects means adding it’s memory to a list for reuse.
• What about when an object consumes more than just one resource?
34
Mark and Sweep Demo
35
Mark and Sweep Demo
36
Mark and Sweep Demo
37
Mark and Sweep Demo
38
Mark and Sweep Demo
39
Mark and Sweep Demo
40
Mark and Sweep Demo
41
Mark and Sweep Demo
42
Object Finalization
• Some objects may have operations that need to occur pre/post
collection
• e.g. file object
43
Execution Environment
Architecture of a Managed Runtime
44
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
Execution Environment
Architecture of a Managed Runtime
45
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
Execution Environment
Architecture of a Managed Runtime
46
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
Execution Environment
Architecture of a Managed Runtime
47
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
 Interpreter context
 Thread context
 Language callstack
Execution Environment
Architecture of a Managed Runtime
48
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
Execution Environment
Architecture of a Managed Runtime
49
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
Execution Environment
Architecture of a Managed Runtime
50
Platform Abstraction Layer
Garbage Collector
Diagnostic Services
Source Code Bytecode/AST
Compiler
Just-In-Time Compiler
Interpreter
Thank You!
Twitter: @craigLehmann
Email: craigl@ca.ibm.com

Weitere ähnliche Inhalte

Was ist angesagt?

Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)OpenBlend society
 
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark... Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...Databricks
 
Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camelprajods
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and GroovyClaus Ibsen
 
Ruby/rails performance and profiling
Ruby/rails performance and profilingRuby/rails performance and profiling
Ruby/rails performance and profilingDanny Guinther
 
Atlanta Hadoop Users Meetup 09 21 2016
Atlanta Hadoop Users Meetup 09 21 2016Atlanta Hadoop Users Meetup 09 21 2016
Atlanta Hadoop Users Meetup 09 21 2016Chris Fregly
 
Getting Started with Apache Camel at DevNation 2014
Getting Started with Apache Camel at DevNation 2014Getting Started with Apache Camel at DevNation 2014
Getting Started with Apache Camel at DevNation 2014Claus Ibsen
 
Rails performance at Justin.tv - Guillaume Luccisano
Rails performance at Justin.tv - Guillaume LuccisanoRails performance at Justin.tv - Guillaume Luccisano
Rails performance at Justin.tv - Guillaume LuccisanoGuillaume Luccisano
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeJim Gough
 
Flink Forward SF 2017: Dean Wampler - Streaming Deep Learning Scenarios with...
Flink Forward SF 2017: Dean Wampler -  Streaming Deep Learning Scenarios with...Flink Forward SF 2017: Dean Wampler -  Streaming Deep Learning Scenarios with...
Flink Forward SF 2017: Dean Wampler - Streaming Deep Learning Scenarios with...Flink Forward
 
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Dan Halperin
 
The Future of Real-Time in Spark
The Future of Real-Time in SparkThe Future of Real-Time in Spark
The Future of Real-Time in SparkReynold Xin
 
Apache Camel - The integration library
Apache Camel - The integration libraryApache Camel - The integration library
Apache Camel - The integration libraryClaus Ibsen
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyDror Bereznitsky
 
Integrating systems in the age of Quarkus and Camel
Integrating systems in the age of Quarkus and CamelIntegrating systems in the age of Quarkus and Camel
Integrating systems in the age of Quarkus and CamelClaus Ibsen
 

Was ist angesagt? (20)

R ext world/ useR! Kiev
R ext world/ useR!  KievR ext world/ useR!  Kiev
R ext world/ useR! Kiev
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark... Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 
Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
Ruby/rails performance and profiling
Ruby/rails performance and profilingRuby/rails performance and profiling
Ruby/rails performance and profiling
 
Atlanta Hadoop Users Meetup 09 21 2016
Atlanta Hadoop Users Meetup 09 21 2016Atlanta Hadoop Users Meetup 09 21 2016
Atlanta Hadoop Users Meetup 09 21 2016
 
Getting Started with Apache Camel at DevNation 2014
Getting Started with Apache Camel at DevNation 2014Getting Started with Apache Camel at DevNation 2014
Getting Started with Apache Camel at DevNation 2014
 
Rails performance at Justin.tv - Guillaume Luccisano
Rails performance at Justin.tv - Guillaume LuccisanoRails performance at Justin.tv - Guillaume Luccisano
Rails performance at Justin.tv - Guillaume Luccisano
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java Code
 
Flink Forward SF 2017: Dean Wampler - Streaming Deep Learning Scenarios with...
Flink Forward SF 2017: Dean Wampler -  Streaming Deep Learning Scenarios with...Flink Forward SF 2017: Dean Wampler -  Streaming Deep Learning Scenarios with...
Flink Forward SF 2017: Dean Wampler - Streaming Deep Learning Scenarios with...
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
 
The Future of Real-Time in Spark
The Future of Real-Time in SparkThe Future of Real-Time in Spark
The Future of Real-Time in Spark
 
Stackato v6
Stackato v6Stackato v6
Stackato v6
 
Perl-Critic
Perl-CriticPerl-Critic
Perl-Critic
 
Apache Camel - The integration library
Apache Camel - The integration libraryApache Camel - The integration library
Apache Camel - The integration library
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better Concurrency
 
Integrating systems in the age of Quarkus and Camel
Integrating systems in the age of Quarkus and CamelIntegrating systems in the age of Quarkus and Camel
Integrating systems in the age of Quarkus and Camel
 

Ähnlich wie Ruby Under The Hood

Reuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless WorldReuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless WorldDmitri Zimine
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Railselliando dias
 
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
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task QueueRichard Leland
 
Concourse Workshop
Concourse WorkshopConcourse Workshop
Concourse WorkshopVMware Tanzu
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part IEugene Lazutkin
 
MacRuby for Fun and Profit
MacRuby for Fun and ProfitMacRuby for Fun and Profit
MacRuby for Fun and ProfitJoshua Ballanco
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisRuslan Shevchenko
 
How to really obfuscate your pdf malware
How to really obfuscate   your pdf malwareHow to really obfuscate   your pdf malware
How to really obfuscate your pdf malwarezynamics GmbH
 
How to really obfuscate your pdf malware
How to really obfuscate your pdf malwareHow to really obfuscate your pdf malware
How to really obfuscate your pdf malwarezynamics GmbH
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsSerge Stinckwich
 
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
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 

Ähnlich wie Ruby Under The Hood (20)

Reuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless WorldReuse, Reduce, Recycle in Serverless World
Reuse, Reduce, Recycle in Serverless World
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
OpenWhisk Go Runtime
OpenWhisk Go RuntimeOpenWhisk Go Runtime
OpenWhisk Go Runtime
 
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...
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 
Concourse Workshop
Concourse WorkshopConcourse Workshop
Concourse Workshop
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
MacRuby for Fun and Profit
MacRuby for Fun and ProfitMacRuby for Fun and Profit
MacRuby for Fun and Profit
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
How to really obfuscate your pdf malware
How to really obfuscate   your pdf malwareHow to really obfuscate   your pdf malware
How to really obfuscate your pdf malware
 
How to really obfuscate your pdf malware
How to really obfuscate your pdf malwareHow to really obfuscate your pdf malware
How to really obfuscate your pdf malware
 
.NET Debugging Workshop
.NET Debugging Workshop.NET Debugging Workshop
.NET Debugging Workshop
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 
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
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 

Kürzlich hochgeladen

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 

Kürzlich hochgeladen (20)

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Ruby Under The Hood

  • 1. About me 1 Guelph ES&C Grad – spring 2014 Currently employed at IBM as a Runtime Technologies Software Dev Twitter: @craiglehmann
  • 2. Ruby Under The Hood http://lolsnaps.com/upload_pic/EveryTimeILookUnderThe HoodOfACar-97946.jpg
  • 7. Program compilation 7 Tokens: 3.times do |n| puts n end puts ndo end 3 dot times
  • 8. Program compilation 8 AST 3.times do |n| puts n end puts n 3 times call block command
  • 10. The Ruby Interpreter? The Ruby Interpreter implements a virtual machine. 10
  • 11. Bytecode Interpreter  The main VM execution loop.  Maps bytecodes to executable native instructions.  Implements a virtual stack machine.  Individual bytecodes implemented in C. 11
  • 12. 12 Ruby is a Stack Machine!
  • 14. Push Down Stack 14 1 + 2 Push 1 Push 2 opt_plus Bytecodes:
  • 15. Push Down Stack 15 1 + 2 Push 1 Push 2 opt_plus Bytecodes: 1 Push 1
  • 16. Push Down Stack 16 1 + 2 Push 1 Push 2 opt_plus Bytecodes: 1 Push 1 2 Push 2 1
  • 17. Push Down Stack 17 1 + 2 Push 1 Push 2 opt_plus Bytecodes: 1 Push 1 2 Push 2 3 opt_plus 1
  • 18. Call Stack example and compiled method 18 def do_things puts "Hello World" end Putself Putstring “Hello World” opt_send_simple
  • 19. Three Stacks 19 def do_things puts "Hello World" end Putself Putstring “Hello World” opt_send_simple C Stack VM Stack Ruby Call Stack
  • 20. Call Stack example and compiled method 20 def do_things puts "Hello World" end Putself Putstring “Hello World” opt_send_simple call_method C Stack exec_core … main() VM Stack Ruby Call Stack
  • 21. Call Stack example and compiled method 21 def do_things puts "Hello World" end Putself Putstring “Hello World” opt_send_simple call_method C Stack exec_core … main() opt_send_simple puts VM Stack “hello World” self Ruby Call Stack
  • 22. Call Stack example and compiled method 22 def do_things puts "Hello World" end Putself Putstring “Hello World” opt_send_simple call_method C Stack exec_core … main() opt_send_simple puts VM Stack “hello World” self puts Ruby Call Stack do_things
  • 23. Three Stacks 23 call_method C Stack exec_core … main() opt_send_simple puts VM Stack “hello World” self puts Ruby Call Stack do_things
  • 24. What does this look like in the Ruby’s VM? 24 puts Ruby Call Stack do_things def do_things puts "Hello World" end
  • 25. What does this look like in the Ruby’s VM? 25 puts Ruby Call Stack do_things def do_things puts "Hello World" end PC Control Frame SP Self type
  • 26. What does this look like in the Ruby’s VM? 26 puts Ruby Call Stack do_things def do_things puts "Hello World" end PC Control Frame SP Self type putself putstring “Hello World” opt_send_simple
  • 27. What does this look like in the Ruby’s VM? 27 puts Ruby Call Stack do_things def do_things puts "Hello World" end PC Control Frame SP Self type putself putstring “Hello World” opt_send_simple opt_send_simple puts VM Stack “hello World” self
  • 28. Class lookup? What happens when you want to create an object? 28 class Person end p = Person.new()
  • 29. Class lookup? What happens when you want to create an object? 29 class Person end p = Person.new()
  • 30. Class lookup? What happens when you want to create an object? 30 class Person end p = Person.new() Person = "Craig" #Warning: already initialized constant person
  • 31. Intro to garbage collection What is garbage collection? Different types of garbage collection algorithms Mark & Sweep demo 31
  • 32. 32 What is garbage collection?  Automatic memory management  Manually managing memory is hard!  Aggregate freeing memory & object destruction operations  Gives the illusion of unlimited memory
  • 33. 33 Different types of garbage collection algorithms  Reference Counting • Keep a count along with each object indicating how many references it currently has. An object with 0 references can have it's memory re-used. • Cannot manage cyclically referenced objects.  Tracing Algorithms • keep track of which objects are in use by recursively tracing objects referring to other objects, starting from a root set of objects.
  • 34. What does it mean to die • An object consumes one resource, memory. • When an object becomes unreachable, it can never be used again. • Cycles are collected together, the mutator cannot access these object. • Sweeping objects means adding it’s memory to a list for reuse. • What about when an object consumes more than just one resource? 34
  • 35. Mark and Sweep Demo 35
  • 36. Mark and Sweep Demo 36
  • 37. Mark and Sweep Demo 37
  • 38. Mark and Sweep Demo 38
  • 39. Mark and Sweep Demo 39
  • 40. Mark and Sweep Demo 40
  • 41. Mark and Sweep Demo 41
  • 42. Mark and Sweep Demo 42
  • 43. Object Finalization • Some objects may have operations that need to occur pre/post collection • e.g. file object 43
  • 44. Execution Environment Architecture of a Managed Runtime 44 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter
  • 45. Execution Environment Architecture of a Managed Runtime 45 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter
  • 46. Execution Environment Architecture of a Managed Runtime 46 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter
  • 47. Execution Environment Architecture of a Managed Runtime 47 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter  Interpreter context  Thread context  Language callstack
  • 48. Execution Environment Architecture of a Managed Runtime 48 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter
  • 49. Execution Environment Architecture of a Managed Runtime 49 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter
  • 50. Execution Environment Architecture of a Managed Runtime 50 Platform Abstraction Layer Garbage Collector Diagnostic Services Source Code Bytecode/AST Compiler Just-In-Time Compiler Interpreter