Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure...

306
Inline Caching in JavaScriptCore Filip Pizlo Apple Inc.

Transcript of Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure...

Page 1: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inline Caching in JavaScriptCore

Filip PizloApple Inc.

Page 2: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

webkit.org

https://svn.webkit.org/repository/webkit/trunk

Page 3: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JavaScriptCore.framework

Page 4: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Safari

Page 5: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Agenda

• JavaScript execution strategy

• Focus on property access inline caches - Simple inline caching

- Inline Caching Optimizations

- Lots of perf data

Page 6: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JavaScript execution strategy

Page 7: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Four Tiers

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

latency throughput

Page 8: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Profiling

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

Page 9: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Speculation and OSR

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

Page 10: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure
Page 11: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Page 12: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

ParserAST

Page 13: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

AST

Page 14: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

AST

unlinked bytecode

Page 15: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

AST

unlinked bytecode

Page 16: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

Bytecode Linker

AST

unlinked bytecode

Page 17: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

Bytecode Linker

AST

unlinked bytecode

bytecode

Page 18: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt

AST

unlinked bytecode

bytecode

Page 19: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

AST

unlinked bytecode

bytecode

Page 20: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

AST

unlinked bytecode

bytecodeDFG

Page 21: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG

Page 22: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

DFG Optimizer

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG

Page 23: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

DFG Optimizer

DFG Backend

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG

Page 24: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

DFG Optimizer

DFG Backend

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 25: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

DFG Optimizer

DFG Backend

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 26: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

DFG Optimizer

DFG Backend

Extended DFG Optimizer

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 27: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

FTL-to-B3 lowering

DFG Optimizer

DFG Backend

Extended DFG Optimizer

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 28: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

FTL-to-B3 lowering

DFG Optimizer

DFG Backend

Extended DFG Optimizer

B3 Optimizer

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 29: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

FTL-to-B3 lowering

DFG Optimizer

DFG Backend

Extended DFG Optimizer

B3 Optimizer

Instruction Selection

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 30: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

FTL-to-B3 lowering

DFG Optimizer

DFG Backend

Extended DFG Optimizer

B3 Optimizer

Instruction Selection

Air Optimizer

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 31: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

FTL-to-B3 lowering

DFG Optimizer

DFG Backend

Extended DFG Optimizer

B3 Optimizer

Instruction Selection

Air Optimizer

Air Backend

Parser

Bytecompiler

Generatorification

Bytecode Linker

LLInt Bytecode Template JIT

DFG Bytecode Parser

DFG Bytecode Parser

AST

unlinked bytecode

bytecodeDFG FTL

Page 32: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inline Caching

Page 33: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inline Caching• Performance

• Why?

• Simple inline caching- in interpreter

- in JIT

- prototype

• Advanced topics- Polymorphic Access JIT

- Inlining inline caches

- Type inference

Page 34: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Performance

Page 35: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Benchmark Summary Number of Samples in my experiments

JetStream 1.1 ES5 benchmarks(real and synthetic) 9

ARES-6 1.0.1 ES6 benchmarks(real and synthetic) 24

Speedometer 2.0DOM framework

benchmarks(real)

30

Source: browserbench.org

Page 36: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure
Page 37: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5×

Page 38: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5×

Baseline = no property inline caching

Page 39: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5×

Baseline = no property inline caching

Page 40: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{x: 1, y: 2}

{x: 42, y: 3}

{x: -5, y: 7}

Page 41: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{x: 1, y: 2}

{x: 42, y: 3}

{x: -5, y: 7}

var x = o.x;

Page 42: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{x: 1, y: 2}

{x: 42, y: 3}

{x: -5, y: 7}

o.x = x;

Page 43: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Hashtable

{x: 1, y: 2}{ hashtable

object

x: 1

y: 1

Page 44: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Hashtable

• Pointer chasing is slow

{x: 1, y: 2}{ hashtable

object

x: 1

y: 1

Page 45: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Hashtable

• Pointer chasing is slow

• Hash codes take time to compute

{x: 1, y: 2}{ hashtable

object

x: 1

y: 1

Page 46: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Hashtable

• Pointer chasing is slow

• Hash codes take time to compute

• Lots of instructions, hard to inline

{x: 1, y: 2}{ hashtable

object

x: 1

y: 1

Page 47: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Hashtable

• Pointer chasing is slow

• Hash codes take time to compute

• Lots of instructions, hard to inline

{x: 1, y: 2}{ hashtable

object

x: 1

y: 1

Page 48: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{x: 1, y: 2}

{x: 42, y: 3}

{x: -5, y: 7}

Page 49: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{1, 2}

{42, 3}

{-5, 7}

{x, y}

Page 50: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{1, 2}

{42, 3}

{-5, 7}

{x, y}

structure

Page 51: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{1, 2}

{42, 3}

{-5, 7}

{x, y}

structure

‣ hashtable

Page 52: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{1, 2}

{42, 3}

{-5, 7}

{x, y}

structure

‣ hashtable

‣ maps name to offset

Page 53: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{1, 2}

{42, 3}

{-5, 7}

{x, y}

structure

‣ hashtable

‣ maps name to offset

‣ hash-consed

Page 54: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

Page 55: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

64 bits

64 bits

64 bits 64 bits 64 bits

64 bits 64 bits

Page 56: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

Page 57: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

Page 58: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

Page 59: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

statically configurable

Page 60: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JSC Object Model

indexingtypeflags

cell state

structure ID butterfly pointer inline slot 0 inline slot 1

public length

vector lengthout of line slot 0 array slot 0

……

statically configurable

dynamically configurable

Page 61: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Fast JSObject

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Page 62: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Fast JSObject

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Page 63: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Fast JSObject

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Structure

Page 64: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Fast JSObject

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

Page 65: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Fast JSObject

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

Page 66: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Fast JSObject

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

g: inline(1)

Page 67: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

g: inline(1)

Page 68: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

g: inline(1)

Page 69: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

g: inline(1)

var v = o.f;

Page 70: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

g: inline(1)

var v = o.f;

if (o->structureID == 42) v = o->inlineStorage[0]else v = slowGet(o, “f”)

Page 71: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

“Inline Cache”

indexingtypeflags

cell state

structure ID: 42 null 0xffff000000000005

var o = {f: 5, g: 6};

0xffff000000000006

Structure Table

Property Table

Structure

f: inline(0)

g: inline(1)

var v = o.f;

if (o->structureID == 42) v = o->inlineStorage[0]else v = slowGet(o, “f”)

Page 72: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Interpreter Inline Cache

get_by_id <result>, <base>, <properyName>

Page 73: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Interpreter Inline Cache

get_by_id <result>, <base>, <properyName>, <cachedStructureID>, <cachedOffset>

Page 74: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Interpreter Inline Cache

get_by_id loc42, loc43, “g”, 0, 0

Page 75: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Interpreter Inline Cache

get_by_id loc42, loc43, “g”, 0, 0

indexingtypeflags

cell state

structure ID: 42 null

f:0xffff000000000005

g:0xffff000000000006

Page 76: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Interpreter Inline Cache

get_by_id loc42, loc43, “g”, 42, 1

indexingtypeflags

cell state

structure ID: 42 null

f:0xffff000000000005

g:0xffff000000000006

Page 77: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Inline Cache

0x46f8c30b9b0: mov 0x30(%rbp), %rax0x46f8c30b9b4: test %rax, %r150x46f8c30b9b7: jnz 0x46f8c30ba2c0x46f8c30b9bd: jmp 0x46f8c30ba2c0x46f8c30b9c2: o16 nop %cs:0x200(%rax,%rax)0x46f8c30b9d1: nop (%rax)0x46f8c30b9d4: mov %rax, -0x38(%rbp)

Page 78: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Inline Cache

0x46f8c30b9b0: mov 0x30(%rbp), %rax0x46f8c30b9b4: test %rax, %r150x46f8c30b9b7: jnz 0x46f8c30ba2c0x46f8c30b9bd: jmp 0x46f8c30ba2c0x46f8c30b9c2: o16 nop %cs:0x200(%rax,%rax)0x46f8c30b9d1: nop (%rax)0x46f8c30b9d4: mov %rax, -0x38(%rbp)

Page 79: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Inline Cache

0x46f8c30b9b0: mov 0x30(%rbp), %rax0x46f8c30b9b4: test %rax, %r150x46f8c30b9b7: jnz 0x46f8c30ba2c0x46f8c30b9bd: jmp 0x46f8c30ba2c0x46f8c30b9c2: o16 nop %cs:0x200(%rax,%rax)0x46f8c30b9d1: nop (%rax)0x46f8c30b9d4: mov %rax, -0x38(%rbp)

Page 80: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Inline Cache

0x46f8c30b9b0: mov 0x30(%rbp), %rax0x46f8c30b9b4: test %rax, %r150x46f8c30b9b7: jnz 0x46f8c30ba2c0x46f8c30b9bd: cmp $0x125, (%rax)0x46f8c30b9c3: jnz 0x46f8c30ba2c0x46f8c30b9c9: mov 0x18(%rax), %rax0x46f8c30b9cd: nop 0x200(%rax)0x46f8c30b9d4: mov %rax, -0x38(%rbp)

Page 81: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

“Self” IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.1× 1.2× 1.3× 1.4× 1.5× 1.6× 1.7× 1.8×

1.19×

1.66×

1.49×

Page 82: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

“Self” IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.1× 1.2× 1.3× 1.4× 1.5× 1.6× 1.7× 1.8×

1.19×

1.66×

1.49× p = 10-23

Page 83: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

“Self” IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.1× 1.2× 1.3× 1.4× 1.5× 1.6× 1.7× 1.8×

1.19×

1.66×

1.49× p = 10-23

p = 10-57

Page 84: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

“Self” IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.1× 1.2× 1.3× 1.4× 1.5× 1.6× 1.7× 1.8×

1.19×

1.66×

1.49× p = 10-23

p = 10-57

p = 10-46

Page 85: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Simple Inline Caching

• Interpreter edits instruction operands.

• JIT reserves a nop sled and patches it.

Page 86: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypes

Page 87: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesfunction Foo(f){ this.f = f;}

Foo.prototype.getF = function(){ return this.f;}

Page 88: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesfunction Foo(f){ this.f = f;}

Foo.prototype.getF = function(){ return this.f;}

getF: λ

Foo.prototype

Page 89: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesfunction Foo(f){ this.f = f;}

Foo.prototype.getF = function(){ return this.f;}

var o = new Foo(42);{f: 42}

getF: λ

Foo.prototype

Page 90: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesfunction Foo(f){ this.f = f;}

Foo.prototype.getF = function(){ return this.f;}

var o = new Foo(42);

var tmp = o.getF();

{f: 42}

getF: λ

Foo.prototype

Page 91: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesfunction Foo(f){ this.f = f;}

Foo.prototype.getF = function(){ return this.f;}

var o = new Foo(42);

var tmp = o.getF();

{f: 42}

getF: λ

Foo.prototype

Page 92: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesclass Foo { constructor(f) { this.f = f; }

getF() { return this.f; }}

var o = new Foo(42);

var tmp = o.getF();

{f: 42}

getF: λ

Foo.prototype

Page 93: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesclass Foo { constructor(f) { this.f = f; }

getF() { return this.f; }}

var o = new Foo(42);

var tmp = o.getF();

{f: 42}

getF: λ

Foo.prototype

Page 94: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototypesclass Foo { constructor(f) { this.f = f; }

getF() { return this.f; }}

var o = new Foo(42);

var tmp = o.getF();

{f: 42}

getF: λ

Foo.prototype

Page 95: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototype Inline Caching

• Goals:

• o.getF should be fast

• o.getF() should be inlineable

• o.newField = value should be fast

Page 96: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Prototype Inline Caching

• Mono proto

• Transition watchpoint

• Replacement watchpoint

Page 97: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Mono Proto

{1, 2}

{42, 3}

{-5, 7}

{x, y}

prototype

global object

Page 98: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Mono Proto

{1, 2}

{42, 3}

{-5, 7}

{x, y}

prototype

global object

structure

Page 99: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

Page 100: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

Page 101: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

Page 102: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

Page 103: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

prototype P2

Page 104: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Page 105: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

// tmp = o.getFif (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44) return P2->inlineStorage[…]else slowGet(o, “getF”)

Page 106: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

// tmp = o.getFif (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44) return P2->inlineStorage[…]else slowGet(o, “getF”)

Page 107: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

prototype P2

structure 44// o.newField = value

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44) o->inlineStorage[…] = value o->structureID = 100;else slowPut(o, “newField”, value)

Page 108: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Proto Chain

object

structure 42

prototype P1

structure 43

prototype P2

structure 44// o.newField = value

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44) o->inlineStorage[…] = value o->structureID = 100;else slowPut(o, “newField”, value)

Page 109: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{}

Transition Table

Transition Hash Consing

Structure {}

Page 110: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{x}

Transition Table

Transition Hash Consing

Structure {}

Transition Table

x Structure {x}

Page 111: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{x, y}

Transition Hash Consing

Structure {}

Transition Table

x Structure {x}

Structure {x, y}

Transition Table

y

Transition Table

Page 112: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44)

Page 113: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44)

Page 114: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44)

Page 115: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Transition Table

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44)

Page 116: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Transition Table

if (o->structureID == 42 && P1->structureID == 43 && P2->structureID == 44)

Page 117: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Transition Table

Page 118: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Transition Table

P1.thingy = “boom”;

Page 119: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Transition Table

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

structure 666

thingy

P1.thingy = “boom”;

Page 120: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Transition Table

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

structure 666

thingy

P1.thingy = “boom”;

Page 121: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Watchpoint

class Watchpoint {public: virtual void fire() = 0;};

Page 122: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Transition Table

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Page 123: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Transition Table

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Page 124: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Transition Table

Optimized Code

return P2->inlineStorage[…]else slowGet(o, “…”)

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

Replacement Map

field

Page 125: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Transition Table

Optimized Code

if (o->structureID == 42)

object

structure 42

prototype P1

structure 43

prototype P2

structure 44

Transition Table

Transition Table

return constantelse slowGet(o, “…”)

Replacement Map

field

Page 126: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Simple Inline Caching

• tmp = o.f // self

• o.f = tmp // self, existing

• o.f = tmp // self, new

• tmp = o.f // prototype

Page 127: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Simple Inline Caching

• tmp = o.f // self

• o.f = tmp // self, existing

• o.f = tmp // self, new

• tmp = o.f // prototype}only need one branch

Page 128: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

Page 129: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

Page 130: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

Page 131: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

Page 132: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

Page 133: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

Page 134: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

Page 135: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

p = 10-9

Page 136: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

p = 10-9

p = 0.06

Page 137: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

p = 10-9

p = 0.06

p = 0.009

Page 138: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

p = 10-9

p = 0.06

p = 0.009

p = 0.0001

Page 139: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

p = 10-9

p = 0.06

p = 0.009

p = 0.0001

p = 10-12

Page 140: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Monomorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4×

1.30×

3.52×

2.09×

1.29×

3.13×

2.05×

1.26×

3.05×

1.97×

1.25×

2.82×

1.87×

1.19×

1.66×

1.49× Self+ Proto+ New Property+ Transition Watch+ Replacement Watch

p = 10-18

p = 10-48

p = 10-13

p = 10-22

p = 10-9

p = 10-15

p = 10-9

p = 0.06

p = 0.009

p = 0.0001

p = 10-12

p = 0.09

Page 141: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Advanced Topics

• Polymorphic Inline Caches

• Inlining Inline Caches

• Type Inference

Page 142: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Polymorphic Inline Caches

Page 143: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure
Page 144: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

Page 145: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

Page 146: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

Page 147: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

{f: 342, g:5}

Page 148: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

{f: 342, g:5}

{f: 54, g:75, h:389}

Page 149: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

{f: 342, g:5}

{f: 54, g:75, h:389}

{f: 6, g:18, h:83}

Page 150: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

{f: 342, g:5}

{f: 54, g:75, h:389}

{f: 6, g:18, h:83}

{g: 37, f: 30}

Page 151: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

{f: 342, g:5}

{f: 54, g:75, h:389}

{f: 6, g:18, h:83}

{g: 37, f: 30}

{g: 835, f: 0}

Page 152: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{f: 64, g:75}

{f: 98, g:23}

{f: 7, g:32}

{f: 342, g:5}

{f: 54, g:75, h:389}

{f: 6, g:18, h:83}

{g: 37, f: 30}

{g: 835, f: 0}

{f, g}

{f, g, h}

{g, f}

Page 153: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

var tmp = o.f;

Page 154: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

var tmp = o.f;

{f: 64, g:75}

S1: {f, g}

Page 155: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389}

S1: {f, g}

S2: {f, g, h}

Page 156: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389} {g: 37, f: 30}

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

Page 157: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389} {g: 37, f: 30}

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

if (o->structureID == S1 || o->structureID == S2) o->inlineStorage[0]else if (o->structureID == S3) o->inlineStorage[1]else slowGet(o, “f”)

Page 158: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f;}

noInline(foo);

for (var i = 0; i < 10000; ++i) { foo({f: 1, g: 2}); foo({f: 1, g: 2, h:3}); foo({g: 2, f: 1});}

Page 159: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x456923529be: cmp $0x129, (%rax)0x456923529c4: jnz 0x45692352a2d0x456923529ca: mov 0x10(%rax), %rax0x456923529ce: nop 0x200(%rax)

S1: {f, g}

Page 160: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f;}

noInline(foo);

for (var i = 0; i < 10000; ++i) { foo({f: 1, g: 2}); foo({f: 1, g: 2, h:3}); foo({g: 2, f: 1});}

Page 161: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

Page 162: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

Page 163: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

done

Page 164: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

done

Page 165: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

done

done

Page 166: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

done

done

slow

Page 167: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

0x45692352be0: mov (%rax), %esi0x45692352be2: cmp $0x129, %esi0x45692352be8: jnz 0x45692352bf70x45692352bee: mov 0x10(%rax), %rax0x45692352bf2: jmp 0x456923529d50x45692352bf7: cmp $0x126, %esi0x45692352bfd: jnz 0x45692352c0c0x45692352c03: mov 0x10(%rax), %rax0x45692352c07: jmp 0x456923529d50x45692352c0c: cmp $0x12b, %esi0x45692352c12: jnz 0x45692352a2d0x45692352c18: mov 0x18(%rax), %rax0x45692352c1c: jmp 0x456923529d50x45692352c21: jmp 0x45692352a2d

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

done

done

done

slow

Page 168: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Polymorphic Access JIT• Self

• Prototype

• Transition (new property)

• Getters

• Setters

• Custom accessors

• Snippets (DOM JIT)

Page 169: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

Page 170: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

Page 171: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

Page 172: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

Page 173: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

p = 0.7

Page 174: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

p = 0.7

p = 0.05

Page 175: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

p = 0.7

p = 0.05

p = 0.7

Page 176: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

p = 0.7

p = 0.05

p = 0.7

p = 10-10

Page 177: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

p = 0.7

p = 0.05

p = 0.7

p = 10-10

p = 10-21

Page 178: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JIT Polymorphic IC speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5×

1.37×

4.68×

2.28×

1.32×

3.99×

2.14×

1.31×

3.92×

2.13×

1.30×

3.52×

2.09× Monomorphic IC+ Simple Poly IC+ Misses+ Accessors & Snippets

p = 0.003

p = 10-14

p = 0.4

p = 0.7

p = 0.05

p = 0.7

p = 10-10

p = 10-21

p = 0.004

Page 179: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inlining Inline Caches

Page 180: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Four Tiers

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

latency throughput

Page 181: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Four Tiers

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

latency throughput

profiling

Page 182: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Four Tiers

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

latency throughput

profiling

speculation and OSR

Page 183: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

get_by_idjmp Lslow jmp Lslow jmp Lslow

tmp = o.fS1:

{f, g}

Page 184: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

jmp Lslow jmp Lslow jmp Lslow

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 185: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

jmp Lslow jmp Lslow

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 186: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

jmp Lslow

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 187: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 188: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

get_by_id

tmp = o.fS1:

{f, g}

Page 189: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 190: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

jmp Lslow

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 191: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 192: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

Page 193: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

Page 194: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

Page 195: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.f

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

Page 196: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

get_by_id

tmp = o.ftmp2 = o.g

S1: {f, g}

get_by_id

Page 197: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

get_by_id

Page 198: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

get_by_id…, S1, 1

Page 199: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

jmp Lslow

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

jmp Lslowget_by_id…, S1, 1

Page 200: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

jmp Lslowget_by_id…, S1, 1

Page 201: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

get_by_id…, S1, 1

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 202: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

get_by_id…, S1, 1

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 203: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

get_by_id…, S1, 1

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 204: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

get_by_id…, S1, 1

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 205: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

get_by_id…, S1, 1

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 206: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

get_by_id…, S1, 1

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 207: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

get_by_id…, S1, 1

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 208: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

LLInt (interpreter)

Baseline (template JIT)

DFG (less optimizing JIT)

FTL (optimizing JIT)

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

tmp = o.ftmp2 = o.g

get_by_id…, S1, 0

S1: {f, g}

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

CheckStructure(@o, S1)GetByOffset(@o, “f”, 0)

get_by_id…, S1, 1

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

CheckStructure(@o, S1)GetByOffset(@o, “g”, 1)

cmp S1, (%rax)jnz Lslowmov 18(%rax), %rax

Page 209: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x10) Call(slow path)

… things …

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x18) Call(slow path)

… more things …

Inline Cache Control Flow

Page 210: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x10) Call(slow path)

… things …

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x18) Call(slow path)

… more things …

not redundant!

Inline Cache Control Flow

Page 211: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x10) Call(slow path)

… things …

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x18) Call(slow path)

… more things …

Branch(Equal( @structure, $S1))

OSR exit

Load(@object, offset = 0x10)

… things …

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x18)

… more things …

OSR exit

Inline Cache Control Flow Inlined with OSR exits

Page 212: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x10) Call(slow path)

… things …

Branch(Equal( @structure, $S1))

Load(@object, offset = 0x18) Call(slow path)

… more things …

Branch(Equal( @structure, $S1))

OSR exit

Load(@object, offset = 0x10)

… things …

Load(@object, offset = 0x18)

… more things …

Inline Cache Control Flow Inlined with OSR exits

Page 213: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Benefits of Inlining

• Common subexpression elimination

• Abstract interpreter models the structure

• Object allocation sinking

• Many other optimizations

Page 214: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Monomorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.37×

4.68×

2.28×Polymorphic IC+ Mono IC Inlining

Page 215: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Monomorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.37×

4.68×

2.28×Polymorphic IC+ Mono IC Inlining

p = 10-14

Page 216: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Monomorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.37×

4.68×

2.28×Polymorphic IC+ Mono IC Inlining

p = 10-14

p = 10-21

Page 217: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Monomorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.37×

4.68×

2.28×Polymorphic IC+ Mono IC Inlining

p = 10-14

p = 10-21

p = 0.02

Page 218: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

Page 219: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

p = 10-8

Page 220: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

p = 10-8

p = 10-9

Page 221: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

p = 10-8

p = 10-9

p = 0.0003

Page 222: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

p = 10-8

p = 10-9

p = 0.0003

p = 10-13

Page 223: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

p = 10-8

p = 10-9

p = 0.0003

p = 10-13

p = 10-26

Page 224: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Inlining and Watchpoints

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.39×

5.67×

2.49×

1.36×

4.54×

2.33×

1.32×

4.33×

2.24×IC Inlining w/o WatchpointsIC inlining w/ Transition WatchpointsIC Inlining w/ Transition & Replacement

p = 10-8

p = 10-9

p = 0.0003

p = 10-13

p = 10-26

p = 0.02

Page 225: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Minimorphic IC Inlining

var tmp = o.f;

Page 226: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Minimorphic IC Inlining

var tmp = o.f;

{f: 64, g:75}

S1: {f, g}

Page 227: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Minimorphic IC Inlining

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389}

S1: {f, g}

S2: {f, g, h}

Page 228: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Minimorphic IC Inlining

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389}

S1: {f, g}

S2: {f, g, h}

CheckStructure(@o, [S1, S2])GetByOffset(@o, “f”, 0)

Page 229: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Polymorphic IC Inlining

var tmp = o.f;

Page 230: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Polymorphic IC Inlining

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389} {g: 37, f: 30}

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

Page 231: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Polymorphic IC Inlining

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389} {g: 37, f: 30}

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

MultiGetByOffset(@o, “f”, [S1, S2] => 0, [S3] => 1)DFG IR:

Page 232: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Polymorphic IC Inlining

var tmp = o.f;

{f: 64, g:75} {f: 54, g:75, h:389} {g: 37, f: 30}

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

MultiGetByOffset(@o, “f”, [S1, S2] => 0, [S3] => 1)

if (o->structureID == S1 || o->structureID == S2) result = o->inlineStorage[0]else result = o->inlineStorage[1]

DFG IR:

B3 IR:

Page 233: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inlining

Page 234: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inliningp = 0.02

Page 235: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inliningp = 0.02

p = 0.5

Page 236: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inliningp = 0.02

p = 0.5

p = 0.6

Page 237: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inliningp = 0.02

p = 0.5

p = 0.6

p = 0.8

Page 238: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inliningp = 0.02

p = 0.5

p = 0.6

p = 0.8

p = 0.6

Page 239: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polymorphic Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7×

1.38×

5.76×

2.52×

1.40×

5.72×

2.52×

1.39×

5.67×

2.49× Mono IC Inlining+ Mini IC Inlining+ Poly IC Inliningp = 0.02

p = 0.5

p = 0.6

p = 0.8

p = 0.6

p = 0.3

Page 240: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure
Page 241: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

Page 242: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

Page 243: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

Page 244: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

S1: {f, g}

Page 245: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

S1: {f, g}

DFG (less optimizing JIT)

Page 246: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

S1: {f, g}

DFG (less optimizing JIT)

…—> foo

<- foo

jmp Lslow

Page 247: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

S1: {f, g}

DFG (less optimizing JIT)

…—> foo

<- foo

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

Page 248: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

S1: {f, g}

DFG (less optimizing JIT)

…—> foo

<- foo

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

FTL (optimizing JIT)

Page 249: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(o) { return o.f; }

S1: {f, g}

S2: {f, g, h}

S3: {g, f}

function bar(p) { return foo(p.g); }

S1: {f, g}

DFG (less optimizing JIT)

…—> foo

<- foo

cmp S1, (%rax)jnz Lslowmov 10(%rax), %rax

FTL (optimizing JIT)

…—> foo CheckStructure GetByOffset<- foo

Page 250: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polyvariant Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.14×

2.53×

1.38×

5.76×

2.52×Polymorphic IC Inlining+ Polyvariant IC Inlining

Page 251: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polyvariant Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.14×

2.53×

1.38×

5.76×

2.52×Polymorphic IC Inlining+ Polyvariant IC Inlining

p = 0.4

Page 252: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polyvariant Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.14×

2.53×

1.38×

5.76×

2.52×Polymorphic IC Inlining+ Polyvariant IC Inlining

p = 0.4

p = 0.0002

Page 253: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

IC Polyvariant Inlining Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.14×

2.53×

1.38×

5.76×

2.52×Polymorphic IC Inlining+ Polyvariant IC Inlining

p = 0.4

p = 0.0002

p = 0.9

Page 254: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

MultiGetByOffset(@o, “f”, [S1, S2] => 0, [S3] => 1)MultiGetByOffset(@o, “g”, [S1, S2] => 1, [S3] => 0)DFG IR:

Page 255: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

MultiGetByOffset(@o, “f”, [S1, S2] => 0, [S3] => 1)MultiGetByOffset(@o, “g”, [S1, S2] => 1, [S3] => 0)DFG IR:

B3 IR:

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

else

Page 256: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

else

Page 257: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

else

Page 258: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)Branch(Equal( @structure, $S1))

OSR exit

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

elsethenelse

Page 259: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)Branch(Equal( @structure, $S1))

OSR exit

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

else

then

else

Page 260: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)Branch(Equal( @structure, $S1))

OSR exit

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

else

then

else

Page 261: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)Branch(Equal( @structure, $S1))

OSR exit

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

elseelse

else

then

else

Page 262: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

else

else

elseelse

Page 263: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x18)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

else

else

elseelse

Page 264: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Load(@object, offset = 0x18)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

else

else

else

Page 265: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Load(@object, offset = 0x18)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

else

else

else

Page 266: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Load(@object, offset = 0x18)

Load(@object, offset = 0x10)

then

elsethen

then

else

else

Page 267: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))Load(@object,

offset = 0x10)Load(@object, offset = 0x18)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

else

else

Page 268: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

B3 IR before:

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))

Load(@object, offset = 0x10)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))

Load(@object, offset = 0x18)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

else

else

else

Page 269: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

B3 IR before:

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))

Load(@object, offset = 0x10)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)

OSR exit

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))

Load(@object, offset = 0x18)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

then

then

then

else

else

else

else

else

B3 IR after:

Branch(Equal( @structure, $S1))

Branch(Equal( @structure, $S2))

Load(@object, offset = 0x10)Load(@object, offset = 0x18)

Branch(Equal( @structure, $S3))

Load(@object, offset = 0x18)Load(@object, offset = 0x10)

OSR exit

then

elsethen

then

else

else

duplicateTails(procedure); foldPathConstants(procedure);

Page 270: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Taildup Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.23×

2.57×

1.39×

6.14×

2.53×Poly Poly IC Inlining+ Taildup

Page 271: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Taildup Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.23×

2.57×

1.39×

6.14×

2.53×Poly Poly IC Inlining+ Taildup

p = 0.03

Page 272: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Taildup Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.23×

2.57×

1.39×

6.14×

2.53×Poly Poly IC Inlining+ Taildup

p = 0.03

p = 0.5

Page 273: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Taildup Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.39×

6.23×

2.57×

1.39×

6.14×

2.53×Poly Poly IC Inlining+ Taildup

p = 0.03

p = 0.5

p = 0.6

Page 274: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

o.f.g

Page 275: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

o.f.g

a: CheckStructure(@o, S1)b: GetByOffset(@o)c: CheckStructure(@b, S2)d: GetByOffset(@c)

Page 276: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

o.f.g

a: CheckStructure(@o, S1)b: GetByOffset(@o)c: CheckStructure(@b, S2)d: GetByOffset(@c)

Page 277: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

Page 278: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

{f: , …)

Page 279: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

{f: , …)

{g: , …)

Page 280: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

{f: , …)

{g: , …)S1:

{f, …}

Page 281: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

{f: , …)

{g: , …)S1:

{f, …}

S2: {g, …}

Page 282: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

{f: , …)

{g: , …)S1:

{f, …}

S2: {g, …}Inferred Type

Table

Page 283: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

{f: , …)

{g: , …)S1:

{f, …}

S2: {g, …}Inferred Type

Table

f: S2

Page 284: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

• Stores to f check type{f: , …)

{g: , …)S1:

{f, …}

S2: {g, …}Inferred Type

Table

f: S2

Page 285: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

• Stores to f check type

• Loads don’t have to

{f: , …)

{g: , …)S1:

{f, …}

S2: {g, …}Inferred Type

Table

f: S2

Page 286: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Property Type Inference

• Stores to f check type

• Loads don’t have to

• S1’s inferred type table watches S2’s transitions

{f: , …)

{g: , …)S1:

{f, …}

S2: {g, …}Inferred Type

Table

f: S2

Page 287: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inferred Type “Speed-up”

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.04×

2.60×

1.39×

6.23×

2.57×Poly Poly IC Inlining + Taildup+ Inferred Type

Page 288: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inferred Type “Speed-up”

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.04×

2.60×

1.39×

6.23×

2.57×Poly Poly IC Inlining + Taildup+ Inferred Type

!!!

Page 289: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inferred Type “Speed-up”

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.04×

2.60×

1.39×

6.23×

2.57×Poly Poly IC Inlining + Taildup+ Inferred Type

!!!

!!!

Page 290: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inferred Type “Speed-up”

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.04×

2.60×

1.39×

6.23×

2.57×Poly Poly IC Inlining + Taildup+ Inferred Type

!!!

!!!

p = 0.03

Page 291: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inferred Type “Speed-up”

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.04×

2.60×

1.39×

6.23×

2.57×Poly Poly IC Inlining + Taildup+ Inferred Type

!!!

!!!

p = 0.03

p = 0.08

Page 292: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Inferred Type “Speed-up”

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.04×

2.60×

1.39×

6.23×

2.57×Poly Poly IC Inlining + Taildup+ Inferred Type

!!!

!!!

p = 0.03

p = 0.08

p = 0.02

Page 293: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

Page 294: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

P1

S1

Page 295: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

P1

S1 P2

S2

Page 296: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

P1

S1 P2

S2 P3

S3

Page 297: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

P1

S1 P2

S2 P3

S3 P4

S4

Page 298: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

P1

S1 P2

S2 P3

S3 P4

S4 P5

S5

Page 299: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

function foo(){ class Helper { … } var h = new Helper(); …}

P1

S1 P2

S2 P3

S3 P4

S4 P5

S5 P6

S6

Page 300: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

{1, 2}

{42, 3}{-5, 7}

{x, y}

proto

global object

Mono Proto

{1, 2}

{42, 3}{-5, 7}

{x, y}global object

Poly Proto

proto1

proto2

Page 301: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Poly Proto Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.27×

2.61×

1.37×

6.04×

2.60×Poly Poly + Taildup + Inferred Type+ Poly Proto

Page 302: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Poly Proto Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.27×

2.61×

1.37×

6.04×

2.60×Poly Poly + Taildup + Inferred Type+ Poly Proto

p = 0.8

Page 303: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Poly Proto Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.27×

2.61×

1.37×

6.04×

2.60×Poly Poly + Taildup + Inferred Type+ Poly Proto

p = 0.8

p = 0.02

Page 304: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

Poly Proto Speed-up

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5× 7× 7.5×

1.37×

6.27×

2.61×

1.37×

6.04×

2.60×Poly Poly + Taildup + Inferred Type+ Poly Proto

p = 0.8

p = 0.02

p = 0.7

Page 305: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

How I Ran These Experiments

• WebKit trunk revision 233406

• Safari trunk hash dd8296dbaac7afa5ed9a699aa261033ea5f5577c

• macOS Internal SDK

• make release (not a root, no shared cache)

• Patch, scripts, and raw data at webkit.org/b/187414

• MacBookPro11,5 2.8GHz 16GB RAM 1TB SSD

Page 306: Inline Caching in JavaScriptCore · “Inline Cache” indexing type flags cell state structure ID: 42 null 0xffff000000000005 var o = {f: 5, g: 6}; 0xffff000000000006 Structure

JetStream

ARES-6

Speedometer 2

1× 1.5× 2× 2.5× 3× 3.5× 4× 4.5× 5× 5.5× 6× 6.5×1.37×

6.27×

2.605×

Self+ Proto+ New Property+ Transition Watch+ Replacement Watch+ Polymorphic+ Miss+ Accessors+ Monomorphic Inlining+ Minimorphic Inlining+ Polymorphic Inlining+ Polyvariant Inlining+ Taildup+ Inferred Types+ Poly Proto