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
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