ruby under the hood - by craig lehmann and robert young - ottawa ruby november 2015 meetup

27
Ruby Under the Hood Robert Young Craig Lehmann Crob 2015

Upload: ottawaruby

Post on 15-Apr-2017

170 views

Category:

Software


1 download

TRANSCRIPT

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

Ruby Under the Hood

Robert Young Craig Lehmann

Crob 2015

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

What’s under the hood?

I Reading your source

I understanding your program

I memory management

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

What’s under the hood?

Ruby is an Interpreted language.

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

Program Parsing

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

Syntax Tree

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

The ruby Interpreter?

The Ruby interpreter implements a virtual machine.

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

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.

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

s

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

Push down Stack

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

Call Stack example and compiled method

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

Three Stacks

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

Control Frame Data Structure

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

Class lookup? What happens when you want to create anobject?

class Person

end

arbitraryConstant = "zZz"

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

A class is listed in a datastructure full of constants

class Person

end

arbitraryConstant = "zZz"

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

A class is listed in a datastructure full of constants

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

constants with the same name as a class? That’s a No No

class Person

end

Person = "hello"

# warning: already initialized constant Person

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

Intro to GC

I What is garbage collection

I Example of how a simple GC algorithm

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

What is garbage collection?

I Automatic memory management

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

What is garbage collection?

I Allocate and free objectsI Keep track of objects currently in use

I Run finalizers

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep

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

A simple GC example - Mark and Sweep