85
VIRTUAL MACHINES FITC Amsterdam 2013 | Joa Ebert | 02/19/2013

Virtual Machines

Embed Size (px)

DESCRIPTION

From the moment you open up a website in your browser multiple virtual machines (VMs) are at work. The server generating the website might use Java, your browser executes JavaScript and maybe there is some Flash content running — with everything being executed in a VM. Virtual machines became increasingly important and popular after Google’s introduction of V8. We expect our code to run fast but let’s step back for a second and see how these complicated pieces of software work. With a better understanding of how your daily ActionScript or JavaScript code is being executed you might start coding a little different. Join Joa and dive deep into the the world of virtual machines. Learn about different garbage collection strategies and understand why those beasts behave the way they do.

Citation preview

Page 1: Virtual Machines

VIRTUALMACHINES

FITC Amsterdam 2013 | Joa Ebert | 02/19/2013

Page 2: Virtual Machines

JOA EBERT@joa

Page 3: Virtual Machines
Page 4: Virtual Machines
Page 5: Virtual Machines
Page 6: Virtual Machines
Page 7: Virtual Machines
Page 8: Virtual Machines
Page 9: Virtual Machines
Page 10: Virtual Machines
Page 11: Virtual Machines
Page 12: Virtual Machines
Page 13: Virtual Machines
Page 14: Virtual Machines

WHAT is a virtual machine?WHY do we need them?HOW do they work?WHERE are the issues?

Agenda

Page 15: Virtual Machines

WHATis a virtual machine?

Page 16: Virtual Machines

„A machine is a tool that consistsof one or more parts, and uses energy to achieve a particular goal.“

WIKIPEDIA

Page 17: Virtual Machines

„A virtual machine (VM) is a simulation of a machine (abstract or real) that is usually different from the target machine (where it is being simulated on).“

WIKIPEDIA

Page 18: Virtual Machines

Programmers really love to make it complicated ...

Page 19: Virtual Machines

SYSTEMVIRTUAL

PROCESSVIRTUAL

Page 20: Virtual Machines

CODEEXECUTION

MEMORYMANAGEMENT

MULTITHREADING

Page 21: Virtual Machines

WHYdo we need them?

Page 22: Virtual Machines

PLATFORM AGNOSTIC

Page 23: Virtual Machines

PROFILING ANDDEBUGGING INPRODUCTION

Page 24: Virtual Machines

SANDBOXING AND SECURITY

Page 25: Virtual Machines

OPTIMIZATION

Page 26: Virtual Machines

EXISTING PROGRAMS RUN FASTER WHEN THE VM GETS FASTER.MORE SPACE FORINNOVATION.

Page 27: Virtual Machines

HOWdo they work?

Page 28: Virtual Machines

CODEEXECUTION

Page 29: Virtual Machines

FEEDBACK ABOUTTYPES AND HOT SPOTS

CODE

NATIVECODE

INTERPRETER

RUNTIME

VM

Page 30: Virtual Machines

HIDDENCLASSESfunction Person(age, gender) { this.age = age this.gender = gender}

var joa = new Person(26, „male“)

Page 31: Virtual Machines

function Person(age, gender) { this.age = age this.gender = gender}

var joa = new Person(26, „male“)

Person

Page 32: Virtual Machines

age

function Person(age, gender) { this.age = age this.gender = gender}

var joa = new Person(26, „male“)

Person Person

26 age

Page 33: Virtual Machines

age gender

function Person(age, gender) { this.age = age this.gender = gender}

var joa = new Person(26, „male“)

Person Person Person

26

0x80f54644

age age

gender

Page 34: Virtual Machines

POLYMORPHICINLINECACHES

function isAdult(person) { return person.age() > 17}

Page 35: Virtual Machines

POLYMORPHICINLINECACHES

function isAdult(person) { return person.age() > 17}

Page 36: Virtual Machines

isAdult lookup Person::agereturn this.age...

age()...

Page 37: Virtual Machines

isAdult Person::ageif not Person lookup()

return this.age

...age()...

Page 38: Virtual Machines

isAdult PIC stub Person::ageif not Person lookup()

return this.age

if Person Person::age()else if Robot Robot::age()else lookup()

...age()...

Page 39: Virtual Machines

isAdult PIC stubif Person return this.ageelse if Robot Robot::age()else lookup()

...age()...

Page 40: Virtual Machines

SPECULATIVEOPTIMIZATIONS

Page 41: Virtual Machines

STATIC TYPING

DYNAMICTYPING

Page 42: Virtual Machines

STRUCTURAL TYPING

def using[I <: { def close() }, O](stream: I)(f: I ⇒ O): O = try { f(stream) } finally { stream.close() }

Page 43: Virtual Machines

def using[I <: { def close() }, O](stream: I)(f: I ⇒ O): O = try { f(stream) } finally { stream.close() }

Remember those PICs?

STRUCTURAL TYPING

Page 44: Virtual Machines

DEOPTIMIZATIONAND OSR

while(true) { computeTheAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything();

}

Page 45: Virtual Machines

DEBUG RELEASE

Page 46: Virtual Machines

oracle.com/us/technologies/java/java7-renaissance-vm-428200.pdf

Page 47: Virtual Machines

GARBAGECOLLECTION

Page 48: Virtual Machines

CONSERVATIVE PRECISE

Page 49: Virtual Machines

0x00 0x00 0x00 0x10 0x00 0x00 0x00 0x000x80 0x00 0x00 0x01 0x80 0x00 0x00 0x040xde 0xad 0xbe 0xef 0x00 0x10 0x00 0x00

MEMORY

Page 50: Virtual Machines

0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000

MEMORY (DWORD ALIGNED)

Page 51: Virtual Machines

0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000

MEMORY (DWORD ALIGNED)

Page 52: Virtual Machines

0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000

MEMORY (DWORD ALIGNED)

Page 53: Virtual Machines

0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000

MEMORY (DWORD ALIGNED)

Page 54: Virtual Machines

0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000

MEMORY (DWORD ALIGNED)

Page 55: Virtual Machines

Conservative GCs suck!

Page 56: Virtual Machines

REFERENCECOUNTING

1 1

Page 57: Virtual Machines

Reference counting sucks!

Page 58: Virtual Machines

COPYINGCOLLECTOR

Page 59: Virtual Machines

FROM-Space

TO-Space

Page 60: Virtual Machines

FROM-Space

TO-Space

Page 61: Virtual Machines

TO-Space

FROM-Space

Page 62: Virtual Machines

Copying collectors are really cool but for a

8GB heap they require 16GB total memory!

Page 63: Virtual Machines

MARK & COMPACT

Page 64: Virtual Machines

EPHEMERAL GC

YoungGeneration

OldGeneration

Survivors

Page 65: Virtual Machines

THREADING

Page 66: Virtual Machines

CONCURRENCY PARALLELISM

Page 67: Virtual Machines

SHARED ISOLATED

Page 68: Virtual Machines

WHEREare the issues?

Page 69: Virtual Machines

ALL VMS ARE CREATED EQUAL.

Page 70: Virtual Machines

ALL VMS ARE CREATED EQUAL. NOT.

Page 71: Virtual Machines

JAVASCRIPT

IS NOTJAVASCRIPT

Page 72: Virtual Machines

J A V A

IS NOTJ A V A

Page 73: Virtual Machines

PEOPLE MAKE AN ARGUMENT FOR A PARTICULAR VM

„Don‘t do this“ IS NOT ALWAYS TRUE

Page 74: Virtual Machines

STARTUP COSTS ARE PAINFUL FOR SHORT RUNNING APPLICATIONS

Page 75: Virtual Machines

TODAYS ADVICE IS NOT TRUE FOR TOMORROW

Page 76: Virtual Machines

BENCHMARKING IS REALLY HARD. MICROBENCHMARKS ARE EVEN MORE USELESS.

Page 77: Virtual Machines

WITH GREATPOWERCOME GREATEXPLOITS

Page 78: Virtual Machines

GC DOESNOT COMEFOR FREE

Page 79: Virtual Machines

Is your GC predictable?

Page 80: Virtual Machines

MEMORYvs.

SPEED

Page 81: Virtual Machines

Write Code for the Future.Don‘t try to outsmart

todays technology.

Page 82: Virtual Machines

Always Remember:

Page 83: Virtual Machines

Always Remember:Math kicks everyones ass!

Page 84: Virtual Machines

O(1)O(log n)O(n)

O(n log n)O(n²)O(n³)...O(x )O(n!)

n

Page 85: Virtual Machines

THANKYOU

Enjoy the party tonight and

bon voyage!FITC Amsterdam 2013 | Joa Ebert | 02/19/2013