Ruby Under the Hood
Robert Young Craig Lehmann
Crob 2015
What’s under the hood?
Reading your source
understanding your program
memory management
What’s under the hood?
Ruby is an Interpreted language.
Program Parsing
Syntax Tree
The ruby Interpreter?
The Ruby interpreter implements a virtual machine.
Bytecode Interpreter
The main VM execution loop.
Maps bytecodes to executable native instructions.
Implements a virtual stack machine.
Individual bytecodes implemented in C.
s
Push down Stack
Call Stack example and compiled method
Three Stacks
Control Frame Data Structure
Class lookup? What happens when you want to create an
object?
class Person
end
arbitraryConstant = "zZz"
A class is listed in a datastructure full of constants
class Person
end
arbitraryConstant = "zZz"
A class is listed in a datastructure full of constants
constants with the same name as a class? That’s a No No
class Person
end
Person = "hello"
# warning: already initialized constant Person
Intro to GC
What is garbage collection
Example of how a simple GC algorithm
What is garbage collection?
Automatic memory management
What is garbage collection?
Allocate and free objects
Keep track of objects currently in use
Run finalizers
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep
A simple GC example - Mark and Sweep

Ruby Under The Hood - By Craig Lehmann and Robert Young - Ottawa Ruby November 2015 Meetup