Upload
joa-ebert
View
738
Download
2
Tags:
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
VIRTUALMACHINES
FITC Amsterdam 2013 | Joa Ebert | 02/19/2013
JOA EBERT@joa
WHAT is a virtual machine?WHY do we need them?HOW do they work?WHERE are the issues?
Agenda
WHATis a virtual machine?
„A machine is a tool that consistsof one or more parts, and uses energy to achieve a particular goal.“
WIKIPEDIA
„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
Programmers really love to make it complicated ...
SYSTEMVIRTUAL
PROCESSVIRTUAL
CODEEXECUTION
MEMORYMANAGEMENT
MULTITHREADING
WHYdo we need them?
PLATFORM AGNOSTIC
PROFILING ANDDEBUGGING INPRODUCTION
SANDBOXING AND SECURITY
OPTIMIZATION
EXISTING PROGRAMS RUN FASTER WHEN THE VM GETS FASTER.MORE SPACE FORINNOVATION.
HOWdo they work?
CODEEXECUTION
FEEDBACK ABOUTTYPES AND HOT SPOTS
CODE
NATIVECODE
INTERPRETER
RUNTIME
VM
HIDDENCLASSESfunction Person(age, gender) { this.age = age this.gender = gender}
var joa = new Person(26, „male“)
function Person(age, gender) { this.age = age this.gender = gender}
var joa = new Person(26, „male“)
Person
age
function Person(age, gender) { this.age = age this.gender = gender}
var joa = new Person(26, „male“)
Person Person
26 age
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
POLYMORPHICINLINECACHES
function isAdult(person) { return person.age() > 17}
POLYMORPHICINLINECACHES
function isAdult(person) { return person.age() > 17}
isAdult lookup Person::agereturn this.age...
age()...
isAdult Person::ageif not Person lookup()
return this.age
...age()...
isAdult PIC stub Person::ageif not Person lookup()
return this.age
if Person Person::age()else if Robot Robot::age()else lookup()
...age()...
isAdult PIC stubif Person return this.ageelse if Robot Robot::age()else lookup()
...age()...
SPECULATIVEOPTIMIZATIONS
STATIC TYPING
DYNAMICTYPING
STRUCTURAL TYPING
def using[I <: { def close() }, O](stream: I)(f: I ⇒ O): O = try { f(stream) } finally { stream.close() }
def using[I <: { def close() }, O](stream: I)(f: I ⇒ O): O = try { f(stream) } finally { stream.close() }
Remember those PICs?
STRUCTURAL TYPING
DEOPTIMIZATIONAND OSR
while(true) { computeTheAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything();
}
DEBUG RELEASE
oracle.com/us/technologies/java/java7-renaissance-vm-428200.pdf
GARBAGECOLLECTION
CONSERVATIVE PRECISE
0x00 0x00 0x00 0x10 0x00 0x00 0x00 0x000x80 0x00 0x00 0x01 0x80 0x00 0x00 0x040xde 0xad 0xbe 0xef 0x00 0x10 0x00 0x00
MEMORY
0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000
MEMORY (DWORD ALIGNED)
0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000
MEMORY (DWORD ALIGNED)
0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000
MEMORY (DWORD ALIGNED)
0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000
MEMORY (DWORD ALIGNED)
0x00000010 0x000000000x80000001 0x800000040xdeadbeef 0x00100000
MEMORY (DWORD ALIGNED)
Conservative GCs suck!
REFERENCECOUNTING
1 1
Reference counting sucks!
COPYINGCOLLECTOR
FROM-Space
TO-Space
FROM-Space
TO-Space
TO-Space
FROM-Space
Copying collectors are really cool but for a
8GB heap they require 16GB total memory!
MARK & COMPACT
EPHEMERAL GC
YoungGeneration
OldGeneration
Survivors
THREADING
CONCURRENCY PARALLELISM
SHARED ISOLATED
WHEREare the issues?
ALL VMS ARE CREATED EQUAL.
ALL VMS ARE CREATED EQUAL. NOT.
JAVASCRIPT
IS NOTJAVASCRIPT
J A V A
IS NOTJ A V A
PEOPLE MAKE AN ARGUMENT FOR A PARTICULAR VM
„Don‘t do this“ IS NOT ALWAYS TRUE
STARTUP COSTS ARE PAINFUL FOR SHORT RUNNING APPLICATIONS
TODAYS ADVICE IS NOT TRUE FOR TOMORROW
BENCHMARKING IS REALLY HARD. MICROBENCHMARKS ARE EVEN MORE USELESS.
WITH GREATPOWERCOME GREATEXPLOITS
GC DOESNOT COMEFOR FREE
Is your GC predictable?
MEMORYvs.
SPEED
Write Code for the Future.Don‘t try to outsmart
todays technology.
Always Remember:
Always Remember:Math kicks everyones ass!
O(1)O(log n)O(n)
O(n log n)O(n²)O(n³)...O(x )O(n!)
n
THANKYOU
Enjoy the party tonight and
bon voyage!FITC Amsterdam 2013 | Joa Ebert | 02/19/2013