ruby under the hood - by craig lehmann and robert young - ottawa ruby november 2015 meetup
TRANSCRIPT
Ruby Under the Hood
Robert Young Craig Lehmann
Crob 2015
What’s under the hood?
I Reading your source
I understanding your program
I 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
I The main VM execution loop.
I Maps bytecodes to executable native instructions.
I Implements a virtual stack machine.
I 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 anobject?
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
I What is garbage collection
I Example of how a simple GC algorithm
What is garbage collection?
I Automatic memory management
What is garbage collection?
I Allocate and free objectsI Keep track of objects currently in use
I 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