SlideShare une entreprise Scribd logo
1  sur  120
@ryzokuken
V8 by Example
A journey through the compilation pipeline
1
@ryzokuken
Ujjwal Sharma (@ryzokuken)
● Node.js – Core Collaborator
● Electron.js – Maintainer
● Contribute to the JS/Node.js ecosystem
○ V8
○ TC39
○ libuv
○ …
● Student
● Google Summer of Code
● Speaker
2
@ryzokuken@ryzokuken
What is V8?
3
@ryzokuken@ryzokuken4
@ryzokuken@ryzokuken
How does V8 work?
5
@ryzokuken@ryzokuken6
Source
@ryzokuken@ryzokuken7
Source
Parser
@ryzokuken@ryzokuken8
Source
Parser
@ryzokuken@ryzokuken9
Source
IIFE?
@ryzokuken@ryzokuken10
Source
IIFE?
Eager
@ryzokuken@ryzokuken11
Source
IIFE? Lazy
Eager
@ryzokuken@ryzokuken12
Source
IIFE?
* Eventually
Eager
Lazy
@ryzokuken@ryzokuken13
Source
IIFE?
Eager
Lazy
AST +
Scopes
@ryzokuken@ryzokuken14
Source
Parser
AST +
Scopes
@ryzokuken@ryzokuken15
Source
Parser
AST +
Scopes
Ignition
@ryzokuken@ryzokuken16
Source
Parser
AST +
Scopes
Ignition Bytecode
@ryzokuken@ryzokuken17
Source
Parser
AST +
Scopes
Ignition Bytecode
@ryzokuken@ryzokuken18
But interpreters are so slow!
Idea: Let’s not be slow.
Let’s use a JIT compiler.
@ryzokuken@ryzokuken19
@ryzokuken@ryzokuken20
Source
Parser
AST +
Scopes
Ignition Bytecode
Turbofan
+ profiling data
OPTIMIZE!
@ryzokuken@ryzokuken21
Source
Parser
AST +
Scopes
Ignition Bytecode
Turbofan
Optimized
Code
DEOPTIMIZE!
@ryzokuken@ryzokuken22
Source
Parser
AST +
Scopes
Ignition Bytecode
Turbofan
Optimized
Code
@ryzokuken@ryzokuken
How you feel about everything.
Let’s take a couple steps back.23
@ryzokuken@ryzokuken
How does V8 work?
24
@ryzokuken@ryzokuken
How does V8 work?
a compiler
25
@ryzokuken@ryzokuken
Source
Code
Parser
Abstract
Syntax
Tree
Assembler
Machine
Code (R)
Compiler
Assembly
Program
Linker
Machine
Code (T)
26
@ryzokuken@ryzokuken
Is it simple enough yet?
27
@ryzokuken@ryzokuken
Source
Code
Parser
Abstract
Syntax
Tree
Assembler
Machine
Code (R)
Compiler
Assembly
Program
Linker
Machine
Code (T)
28
@ryzokuken@ryzokuken
Source
Code
Parser
Abstract
Syntax
Tree
Compiler
Machine
Code (T)
29
@ryzokuken@ryzokuken30
BAD NEWS: V8 isn’t this simple
@ryzokuken@ryzokuken
Because ECMAScript is slow by default, that’s why.
31
@ryzokuken@ryzokuken
Idea: Let’s not be slow.
BUT HOW?
Speculative Optimization
32
@ryzokuken@ryzokuken
But wait…
What even is
Speculative Optimization?
33
@ryzokuken@ryzokuken
Speculative Optimization
[spek-yuh-ley-tiv, -luh-tiv][op-tuh-muh-zey-shuh n]
Noun.
Guessing what is about to happen based
on what has happened.
34
@ryzokuken@ryzokuken
Speculative Optimization
[spek-yuh-ley-tiv, -luh-tiv][op-tuh-muh-zey-shuh n]
Noun.
Guessing what is about to happen based
on what has happened.
Making assumptions about possible
future inputs based on previous inputs.
35
@ryzokuken@ryzokuken
Top three reasons why a JavaScript
function might need optimization:
1. Dynamic Types
2. Dynamic Types
3. Dynamic Types
Alright, but how does it help?
36
@ryzokuken@ryzokuken
Source
Code
Parser
Abstract
Syntax
Tree
Compiler
Machine
Code (T)
37
@ryzokuken@ryzokuken
Source
Code
Parser
Abstract
Syntax
Tree
1. Baseline Interpreter
2. Optimizing Compiler
Machine
Code (T)
38
@ryzokuken@ryzokuken
AST
Baseline
Interpreter
Optimizing
Compiler
Bytecode
Optimized Code
optimize
deoptimize
39
@ryzokuken@ryzokuken
Compiler
Baseline
Interpreter
Optimizing
Compiler
40
@ryzokuken@ryzokuken
AST
Baseline
Interpreter
Optimizing
Compiler
Bytecode
Optimized Code
optimize
deoptimize
41
@ryzokuken@ryzokuken
AST
Bytecode
Optimized Code
optimize
deoptimize
42
@ryzokuken@ryzokuken43
Okay, that’s great.
But how does it even work?
Let’s consider an example.
@ryzokuken@ryzokuken44
function add(x, y) {
return x + y;
}
console.log(add(1, 2));
@ryzokuken@ryzokuken45
Not too intuitive?
I’ve got you covered, fam.
Let’s see how the Abstract Syntax Tree actually looks.
@ryzokuken@ryzokuken46
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
@ryzokuken@ryzokuken47
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
@ryzokuken@ryzokuken48
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
@ryzokuken@ryzokuken49
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add”
@ryzokuken@ryzokuken50
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS
@ryzokuken@ryzokuken51
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS
VAR “x”
@ryzokuken@ryzokuken52
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS
VAR “x” VAR “y”
@ryzokuken@ryzokuken53
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS RETURN
VAR “x” VAR “y”
@ryzokuken@ryzokuken54
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS RETURN
VAR “x” VAR “y” ADD
@ryzokuken@ryzokuken55
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS RETURN
VAR “x” VAR “y” ADD
PROXY “x”
@ryzokuken@ryzokuken56
[generating bytecode for function: add]
--- AST ---
FUNC at 12
. KIND 0
. SUSPEND COUNT 0
. NAME "add"
. PARAMS
. . VAR (...) (mode = VAR) "x"
. . VAR (...) (mode = VAR) "y"
. RETURN at 22
. . ADD at 31
. . . VAR PROXY parameter[0] (...) (mode = VAR) "x"
. . . VAR PROXY parameter[1] (...) (mode = VAR) "y"
FUNC
NAME “add” PARAMS RETURN
VAR “x” VAR “y” ADD
PROXY “x” PROXY “y”
@ryzokuken@ryzokuken57
Scope Resolution
FUNC
NAME “add” PARAMS RETURN
VAR “x” VAR “y” ADD
PROXY “y”PROXY “x”
@ryzokuken@ryzokuken58
Let’s step through the bytecode.
Hope you like Assembly.
Once this is done, we can generate bytecode.
@ryzokuken@ryzokuken59
[generated bytecode for function: add]
Parameter count 3
Frame size 0
12 E> 0x38d5f59df42 @ 0 : a5 StackCheck
22 S> 0x38d5f59df43 @ 1 : 25 02 Ldar a1
31 E> 0x38d5f59df45 @ 3 : 34 03 00 Add a0, [0]
35 S> 0x38d5f59df48 @ 6 : a9 Return
Constant pool (size = 0)
Handler Table (size = 0)
@ryzokuken@ryzokuken60
[generated bytecode for function: add]
Parameter count 3
Frame size 0
12 E> 0x38d5f59df42 @ 0 : a5 StackCheck
22 S> 0x38d5f59df43 @ 1 : 25 02 Ldar a1
31 E> 0x38d5f59df45 @ 3 : 34 03 00 Add a0, [0]
35 S> 0x38d5f59df48 @ 6 : a9 Return
Constant pool (size = 0)
Handler Table (size = 0)
@ryzokuken@ryzokuken61
[generated bytecode for function: add]
Parameter count 3
Frame size 0
12 E> 0x38d5f59df42 @ 0 : a5 StackCheck
22 S> 0x38d5f59df43 @ 1 : 25 02 Ldar a1
31 E> 0x38d5f59df45 @ 3 : 34 03 00 Add a0, [0]
35 S> 0x38d5f59df48 @ 6 : a9 Return
Constant pool (size = 0)
Handler Table (size = 0)
@ryzokuken@ryzokuken62
[generated bytecode for function: add]
Parameter count 3
Frame size 0
12 E> 0x38d5f59df42 @ 0 : a5 StackCheck
22 S> 0x38d5f59df43 @ 1 : 25 02 Ldar a1
31 E> 0x38d5f59df45 @ 3 : 34 03 00 Add a0, [0]
35 S> 0x38d5f59df48 @ 6 : a9 Return
Constant pool (size = 0)
Handler Table (size = 0)
@ryzokuken@ryzokuken63
StackCheck
Ldar a1
Add a0, [0]
Return
@ryzokuken@ryzokuken64
StackCheck
Ldar a1
Add a0, [0]
Return
@ryzokuken@ryzokuken65
StackCheck
Ldar a1
Add a0, [0]
Return
@ryzokuken@ryzokuken66
StackCheck
Ldar a1
Add a0, [0]
Return
@ryzokuken@ryzokuken67
Two important things happen here.
1. Addition: It’s complicated.
2. Profiling: Feedback Vectors help.
@ryzokuken@ryzokuken68
StackCheck
Ldar a1
Add a0, [0]
Return
@ryzokuken@ryzokuken69
What about that Speculative Optimization thingie he
was talking about earlier?
Now that we finally have the baseline code running,
let’s put that profiling data to good use.
But wait...
@ryzokuken@ryzokuken70
Oh, also, remember that time when
I said addition in JavaScript was
complicated?
@ryzokuken@ryzokuken71
@ryzokuken@ryzokuken72
Let me break it down for you.
@ryzokuken@ryzokuken73
Number
String
Object
@ryzokuken@ryzokuken74
@ryzokuken@ryzokuken75
Remember Feedback Vectors?
Let’s see how they really look to see how it all works.
Awesome! But how do we make that assumption?
@ryzokuken@ryzokuken76
function add(x, y) {
return x + y;
}
console.log(add(1, 2));
@ryzokuken@ryzokuken77
function add(x, y) {
return x + y;
}
console.log(add(1, 2));
%DebugPrint(add);
@ryzokuken@ryzokuken78
...
- feedback vector: 0x18bc7711df89: [FeedbackVector] in OldSpace
- map: 0x18bc38c00bc1 <Map>
- length: 1
- shared function info: 0x18bc7711dc59 <SharedFunctionInfo add>
- optimized code/marker: OptimizationMarker::kNone
- invocation count: 1
- profiler ticks: 0
- slot #0 BinaryOp BinaryOp:SignedSmall {
[0]: 1
}
...
@ryzokuken@ryzokuken79
function add(x, y) {
return x + y;
}
console.log(add(1, 2));
%DebugPrint(add);
@ryzokuken@ryzokuken80
function add(x, y) {
return x + y;
}
console.log(add(1, 2));
console.log(add(1.1, 2.2));
%DebugPrint(add);
@ryzokuken@ryzokuken81
...
- feedback vector: 0xcbd92d1dfe1: [FeedbackVector] in OldSpace
- map: 0x0cbd4f880bc1 <Map>
- length: 1
- shared function info: 0x0cbd92d1dc59 <SharedFunctionInfo add>
- optimized code/marker: OptimizationMarker::kNone
- invocation count: 2
- profiler ticks: 0
- slot #0 BinaryOp BinaryOp:Number {
[0]: 7
}
...
@ryzokuken@ryzokuken82
@ryzokuken@ryzokuken83
Question: Is there a method to all this?
Answer: Yes, it is called the Feedback Lattice.
@ryzokuken@ryzokuken84
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken85
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken86
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken87
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken88
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken89
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken90
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken91
None
SignedSmall
Number
BigIntString
NumberOrOddball
Any
@ryzokuken@ryzokuken92
This data in the Feedback Vectors is used to finally optimize
your code once a function is hot.
When is a function “hot”?
Let’s see what actually happens by explicitly triggering
optimization.
@ryzokuken@ryzokuken93
function add(x, y) {
return x + y;
}
add(1, 2);
@ryzokuken@ryzokuken94
@ryzokuken@ryzokuken95
function add(x, y) {
return x + y;
}
add(1, 2); // Warm up with SignedSmall feedback.
%OptimizeFunctionOnNextCall(add);
add(1, 2); // Optimize and run generated code.
@ryzokuken@ryzokuken96
Question: What did we just do?
@ryzokuken@ryzokuken97
Let’s see the optimized code generated by passing the --
print-opt-code flag to d8.
@ryzokuken@ryzokuken98
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
@ryzokuken@ryzokuken99
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Prologue
@ryzokuken@ryzokuken100
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Check x is Smi
@ryzokuken@ryzokuken101
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Check y is Smi
@ryzokuken@ryzokuken102
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Smi → Word32 (x)
@ryzokuken@ryzokuken103
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Smi → Word32 (y)
@ryzokuken@ryzokuken104
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Add x and y
Overflow Check
@ryzokuken@ryzokuken105
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Result to Smi
@ryzokuken@ryzokuken106
leaq rbx,[rip+0xfffffff9]
movq rbx,[rcx-0x20]
testb [rbx+0xf],0x1
jz 0x198104882dfb <+0x3b>
movq r10,0x10efbfde0 (CompileLazyDeoptimizedCode)
jmp r10
push rbp
movq rbp,rsp
push rsi
push rdi
cmpq rsp,[r13+0x11e8] (root (stack_limit))
jna 0x198104882e55 <+0x95>
movq rdx,[rbp+0x18]
testb rdx,0x1
jnz 0x198104882e7b <+0xbb>
movq rcx,[rbp+0x10]
testb rcx,0x1
jnz 0x198104882e87 <+0xc7>
movq rdi,rcx
shrq rdi, 32
movq r8,rdx
shrq r8, 32
addl rdi,r8
jo 0x198104882e93 <+0xd3>
shlq rdi, 32
movq rax,rdi
movq rsp,rbp
pop rbp
ret 0x18
Epilogue
@ryzokuken@ryzokuken107
Now, let’s try something fun.
@ryzokuken@ryzokuken108
function add(x, y) {
return x + y;
}
add(1, 2); // Warm up with SignedSmall feedback.
%OptimizeFunctionOnNextCall(add);
add(1, 2); // Optimize and run generated code.
@ryzokuken@ryzokuken109
function add(x, y) {
return x + y;
}
add(1, 2); // Warm up with SignedSmall feedback.
%OptimizeFunctionOnNextCall(add);
add(1, 2); // Optimize and run generated code.
add(1.1, 2.2) // DEOPTIMIZE!
@ryzokuken@ryzokuken110
@ryzokuken@ryzokuken111
Note: I’m obviously kidding.
Deoptimization is no laughing matter.
@ryzokuken@ryzokuken112
Let’s see how the code is actually deoptimized by passing the
--trace-deopt flag to d8.
@ryzokuken@ryzokuken113
[deoptimizing (DEOPT eager): begin 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> (opt #0)
@0, FP to SP delta: 24, caller sp: 0x7ffee7bee248]
;;; deoptimize at <add.js:2:12>, not a Smi
reading input frame add => bytecode_offset=0, args=3, height=1, retval=0(#0); inputs:
0: 0x08d97929dbc1 ; [fp - 16] 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)>
1: 0x08d9c6b81521 ; [fp + 32] 0x08d9c6b81521 <JSGlobal Object>
2: 0x08d97929da31 ; rdx 0x08d97929da31 <HeapNumber 1.1>
3: 0x08d97929da41 ; [fp + 16] 0x08d97929da41 <HeapNumber 2.2>
4: 0x08d979281749 ; [fp - 24] 0x08d979281749 <NativeContext[247]>
5: 0x08d92b080e19 ; (literal 2) 0x08d92b080e19 <Odd Oddball: optimized_out>
translating interpreted frame add => bytecode_offset=0, height=8
0x7ffee7bee240: [top + 72] <- 0x08d9c6b81521 <JSGlobal Object> ; stack parameter (input #1)
0x7ffee7bee238: [top + 64] <- 0x08d97929da31 <HeapNumber 1.1> ; stack parameter (input #2)
0x7ffee7bee230: [top + 56] <- 0x08d97929da41 <HeapNumber 2.2> ; stack parameter (input #3)
-------------------------
0x7ffee7bee228: [top + 48] <- 0x00010d2881e8 ; caller's pc
0x7ffee7bee220: [top + 40] <- 0x7ffee7bee290 ; caller's fp
0x7ffee7bee218: [top + 32] <- 0x08d979281749 <NativeContext[247]> ; context (input #4)
0x7ffee7bee210: [top + 24] <- 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> ;
function (input #0)
0x7ffee7bee208: [top + 16] <- 0x08d97929dca1 <BytecodeArray[7]> ; bytecode array
0x7ffee7bee200: [top + 8] <- 0x003900000000 <Smi 57> ; bytecode offset
-------------------------
0x7ffee7bee1f8: [top + 0] <- 0x08d92b080e19 <Odd Oddball: optimized_out> ; accumulator
(input #5)
[deoptimizing (eager): end 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> @0 => node=0,
pc=0x00010d2886c0, caller sp=0x7ffee7bee248, took 1.163 ms]
@ryzokuken@ryzokuken
Don’t worry, I got you.114
@ryzokuken@ryzokuken115
[deoptimizing (DEOPT eager): begin 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> (opt #0)
@0, FP to SP delta: 24, caller sp: 0x7ffee7bee248]
;;; deoptimize at <add.js:2:12>, not a Smi
reading input frame add => bytecode_offset=0, args=3, height=1, retval=0(#0); inputs:
0: 0x08d97929dbc1 ; [fp - 16] 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)>
1: 0x08d9c6b81521 ; [fp + 32] 0x08d9c6b81521 <JSGlobal Object>
2: 0x08d97929da31 ; rdx 0x08d97929da31 <HeapNumber 1.1>
3: 0x08d97929da41 ; [fp + 16] 0x08d97929da41 <HeapNumber 2.2>
4: 0x08d979281749 ; [fp - 24] 0x08d979281749 <NativeContext[247]>
5: 0x08d92b080e19 ; (literal 2) 0x08d92b080e19 <Odd Oddball: optimized_out>
translating interpreted frame add => bytecode_offset=0, height=8
0x7ffee7bee240: [top + 72] <- 0x08d9c6b81521 <JSGlobal Object> ; stack parameter (input #1)
0x7ffee7bee238: [top + 64] <- 0x08d97929da31 <HeapNumber 1.1> ; stack parameter (input #2)
0x7ffee7bee230: [top + 56] <- 0x08d97929da41 <HeapNumber 2.2> ; stack parameter (input #3)
-------------------------
0x7ffee7bee228: [top + 48] <- 0x00010d2881e8 ; caller's pc
0x7ffee7bee220: [top + 40] <- 0x7ffee7bee290 ; caller's fp
0x7ffee7bee218: [top + 32] <- 0x08d979281749 <NativeContext[247]> ; context (input #4)
0x7ffee7bee210: [top + 24] <- 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> ;
function (input #0)
0x7ffee7bee208: [top + 16] <- 0x08d97929dca1 <BytecodeArray[7]> ; bytecode array
0x7ffee7bee200: [top + 8] <- 0x003900000000 <Smi 57> ; bytecode offset
-------------------------
0x7ffee7bee1f8: [top + 0] <- 0x08d92b080e19 <Odd Oddball: optimized_out> ; accumulator
(input #5)
[deoptimizing (eager): end 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> @0 => node=0,
pc=0x00010d2886c0, caller sp=0x7ffee7bee248, took 1.163 ms]
@ryzokuken@ryzokuken116
[deoptimizing (DEOPT eager): begin 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> (opt #0)
@0, FP to SP delta: 24, caller sp: 0x7ffee7bee248]
;;; deoptimize at <add.js:2:12>, not a Smi
reading input frame add => bytecode_offset=0, args=3, height=1, retval=0(#0); inputs:
0: 0x08d97929dbc1 ; [fp - 16] 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)>
1: 0x08d9c6b81521 ; [fp + 32] 0x08d9c6b81521 <JSGlobal Object>
2: 0x08d97929da31 ; rdx 0x08d97929da31 <HeapNumber 1.1>
3: 0x08d97929da41 ; [fp + 16] 0x08d97929da41 <HeapNumber 2.2>
4: 0x08d979281749 ; [fp - 24] 0x08d979281749 <NativeContext[247]>
5: 0x08d92b080e19 ; (literal 2) 0x08d92b080e19 <Odd Oddball: optimized_out>
translating interpreted frame add => bytecode_offset=0, height=8
0x7ffee7bee240: [top + 72] <- 0x08d9c6b81521 <JSGlobal Object> ; stack parameter (input #1)
0x7ffee7bee238: [top + 64] <- 0x08d97929da31 <HeapNumber 1.1> ; stack parameter (input #2)
0x7ffee7bee230: [top + 56] <- 0x08d97929da41 <HeapNumber 2.2> ; stack parameter (input #3)
-------------------------
0x7ffee7bee228: [top + 48] <- 0x00010d2881e8 ; caller's pc
0x7ffee7bee220: [top + 40] <- 0x7ffee7bee290 ; caller's fp
0x7ffee7bee218: [top + 32] <- 0x08d979281749 <NativeContext[247]> ; context (input #4)
0x7ffee7bee210: [top + 24] <- 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> ;
function (input #0)
0x7ffee7bee208: [top + 16] <- 0x08d97929dca1 <BytecodeArray[7]> ; bytecode array
0x7ffee7bee200: [top + 8] <- 0x003900000000 <Smi 57> ; bytecode offset
-------------------------
0x7ffee7bee1f8: [top + 0] <- 0x08d92b080e19 <Odd Oddball: optimized_out> ; accumulator
(input #5)
[deoptimizing (eager): end 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> @0 => node=0,
pc=0x00010d2886c0, caller sp=0x7ffee7bee248, took 1.163 ms]
@ryzokuken@ryzokuken117
[deoptimizing (DEOPT eager): begin 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> (opt #0)
@0, FP to SP delta: 24, caller sp: 0x7ffee7bee248]
;;; deoptimize at <add.js:2:12>, not a Smi
reading input frame add => bytecode_offset=0, args=3, height=1, retval=0(#0); inputs:
0: 0x08d97929dbc1 ; [fp - 16] 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)>
1: 0x08d9c6b81521 ; [fp + 32] 0x08d9c6b81521 <JSGlobal Object>
2: 0x08d97929da31 ; rdx 0x08d97929da31 <HeapNumber 1.1>
3: 0x08d97929da41 ; [fp + 16] 0x08d97929da41 <HeapNumber 2.2>
4: 0x08d979281749 ; [fp - 24] 0x08d979281749 <NativeContext[247]>
5: 0x08d92b080e19 ; (literal 2) 0x08d92b080e19 <Odd Oddball: optimized_out>
translating interpreted frame add => bytecode_offset=0, height=8
0x7ffee7bee240: [top + 72] <- 0x08d9c6b81521 <JSGlobal Object> ; stack parameter (input #1)
0x7ffee7bee238: [top + 64] <- 0x08d97929da31 <HeapNumber 1.1> ; stack parameter (input #2)
0x7ffee7bee230: [top + 56] <- 0x08d97929da41 <HeapNumber 2.2> ; stack parameter (input #3)
-------------------------
0x7ffee7bee228: [top + 48] <- 0x00010d2881e8 ; caller's pc
0x7ffee7bee220: [top + 40] <- 0x7ffee7bee290 ; caller's fp
0x7ffee7bee218: [top + 32] <- 0x08d979281749 <NativeContext[247]> ; context (input #4)
0x7ffee7bee210: [top + 24] <- 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> ;
function (input #0)
0x7ffee7bee208: [top + 16] <- 0x08d97929dca1 <BytecodeArray[7]> ; bytecode array
0x7ffee7bee200: [top + 8] <- 0x003900000000 <Smi 57> ; bytecode offset
-------------------------
0x7ffee7bee1f8: [top + 0] <- 0x08d92b080e19 <Odd Oddball: optimized_out> ; accumulator
(input #5)
[deoptimizing (eager): end 0x08d97929dbc1 <JSFunction add (sfi = 0x8d97929d999)> @0 => node=0,
pc=0x00010d2886c0, caller sp=0x7ffee7bee248, took 1.163 ms]
@ryzokuken@ryzokuken118
Pro Tip: If you don’t want your code to be slow,
try to stick to certain types.
It makes things easier.
@ryzokuken
Special Thanks
● Benedikt Meurer (@bmeurer)
● Yang Guo (@hashseed)
● Sathya Gunasekaran (@_gsathya)
● Jakob Gruber (@schuay)
● Sigurd Schneider (@sigurdschn)
● ...and everyone else from the V8 team.
● The organizers.
119
@ryzokuken@ryzokuken
Paldies!
120

Contenu connexe

Tendances

Tendances (20)

The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
The Ring programming language version 1.4 book - Part 8 of 30
The Ring programming language version 1.4 book - Part 8 of 30The Ring programming language version 1.4 book - Part 8 of 30
The Ring programming language version 1.4 book - Part 8 of 30
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189
 
The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
 
The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185
 
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181
 
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematician
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 
The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180
 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181
 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84
 
The Ring programming language version 1.3 book - Part 21 of 88
The Ring programming language version 1.3 book - Part 21 of 88The Ring programming language version 1.3 book - Part 21 of 88
The Ring programming language version 1.3 book - Part 21 of 88
 
New SPL Features in PHP 5.3 (TEK-X)
New SPL Features in PHP 5.3 (TEK-X)New SPL Features in PHP 5.3 (TEK-X)
New SPL Features in PHP 5.3 (TEK-X)
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
Millionways
MillionwaysMillionways
Millionways
 
The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185
 
The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84
 
The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.1 book - Part 34 of 180The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.1 book - Part 34 of 180
 

Similaire à V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at FrontCon 2019

Similaire à V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at FrontCon 2019 (20)

The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185
 
The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
 
The Ring programming language version 1.10 book - Part 40 of 212
The Ring programming language version 1.10 book - Part 40 of 212The Ring programming language version 1.10 book - Part 40 of 212
The Ring programming language version 1.10 book - Part 40 of 212
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 
Xm lparsers
Xm lparsersXm lparsers
Xm lparsers
 
The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184
 
JavaScript ∩ WebAssembly
JavaScript ∩ WebAssemblyJavaScript ∩ WebAssembly
JavaScript ∩ WebAssembly
 
The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210The Ring programming language version 1.9 book - Part 38 of 210
The Ring programming language version 1.9 book - Part 38 of 210
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
On Beyond (PostgreSQL) Data Types
On Beyond (PostgreSQL) Data TypesOn Beyond (PostgreSQL) Data Types
On Beyond (PostgreSQL) Data Types
 
Monadologie
MonadologieMonadologie
Monadologie
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
 

Plus de DevClub_lv

Plus de DevClub_lv (20)

Fine-tuning Large Language Models by Dmitry Balabka
Fine-tuning Large Language Models by Dmitry BalabkaFine-tuning Large Language Models by Dmitry Balabka
Fine-tuning Large Language Models by Dmitry Balabka
 
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ..."Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
 
From 50 to 500 product engineers – data-driven approach to building impactful...
From 50 to 500 product engineers – data-driven approach to building impactful...From 50 to 500 product engineers – data-driven approach to building impactful...
From 50 to 500 product engineers – data-driven approach to building impactful...
 
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
 
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
 
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
 
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
 
SRE (service reliability engineer) on big DevOps platform running on the clou...
SRE (service reliability engineer) on big DevOps platform running on the clou...SRE (service reliability engineer) on big DevOps platform running on the clou...
SRE (service reliability engineer) on big DevOps platform running on the clou...
 
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
 
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile foc...
 
Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
 
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
 
Bridging the gap between UX and development - A Storybook by Marko Letic at F...
Bridging the gap between UX and development - A Storybook by Marko Letic at F...Bridging the gap between UX and development - A Storybook by Marko Letic at F...
Bridging the gap between UX and development - A Storybook by Marko Letic at F...
 
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
 
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
 
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
 
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at FrontCon 2019

Notes de l'éditeur

  1. V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chormium, the open source browser from Google and it’s derivatives, and in Node.js, among others.
  2. Here we explicitly warm up the x+y site with SignedSmall feedback by passing in two integer values whose sum also fits into the small integer range. Then we tell V8 that it should optimize the function add (with TurboFan) when it’s called the next time, and eventually we call add, which triggers TurboFan and then runs the generated machine code.
  3. The prologue checks whether the code object is still valid or whether some condition changed which requires us to throw away the code object. Once we know that the code is still valid, we build the stack frame and check that there’s enough space left on the stack to execute the code.
  4. Then we start with the body of the function. We load the values of the parameters x and y from the stack (relative to the frame pointer in rbp) and check if both values have Smi representation (since feedback for + says that both inputs have always been Smi so far). This is done by testing the least significant bit. Once we know that they are both represented as Smi, we need to convert them to 32-bit representation, which is done by shifting the value by 32 bit to the right. If either x or y is not a Smi the execution of the optimized code aborts immediately and the deoptimizer restores the state of the function in the interpreter right before the Add.
  5. Then we go on to perform the integer addition on the inputs. We need to test explicitly for overflow, since the result of the addition might be outside the range of 32-bit integers, in which case we’d need to go back to the interpreter, which will then learn Number feedback on the Add. Finally we convert the result back to Smi representation by shifting the signed 32-bit value up by 32 bit, and then we return the value in the accumulator register rax.
  6. As said before, this is not yet the perfect code for this case, since here it would be beneficial to just perform the addition on Smi representation directly, instead of going to Word32, which would save us three shift instructions. But even putting aside this minor aspect, you can see that the generated code is highly optimized and specialized to the profiling feedback. It doesn’t even try to deal with other numbers, strings, big ints or arbitrary JavaScript objects here, but focuses only on the kind of values we’ve seen so far. This is the key ingredient to peak performance for many JavaScript applications.