Lightweight Scheduling in a Single-Pass JavaScript JIT Compiler - - PowerPoint PPT Presentation

lightweight scheduling in a single pass javascript jit
SMART_READER_LITE
LIVE PREVIEW

Lightweight Scheduling in a Single-Pass JavaScript JIT Compiler - - PowerPoint PPT Presentation

Lightweight Scheduling in a Single-Pass JavaScript JIT Compiler Alexander Jordan, Vienna University of Technology ajordan@complang.tuwien.ac.at Christophe Guillon, STMicroelectronics christophe.guillon@st.com January 22, 2013 1/16 Alexander


slide-1
SLIDE 1

Lightweight Scheduling in a Single-Pass JavaScript JIT Compiler

Alexander Jordan, Vienna University of Technology

ajordan@complang.tuwien.ac.at

Christophe Guillon, STMicroelectronics

christophe.guillon@st.com

January 22, 2013

1/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-2
SLIDE 2

Introduction

SH4 (SuperH) ➙ 32-bit RISC ➙ Compact 16-bit instruction set ➙ 32/64-bit floating point hardware ➙ Dual-issue, in-order pipeline (with interlocking)

Issue Constraints: LS, MUL, BR, FPx Latencies: default: 1, LS:3, MUL:2, FP: long

2/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-3
SLIDE 3

V8 JavaScript Engine

V8 JavaScript Engine ➙ JIT-only (arm, ia32, mips, x64, sh4) ➙ Precise Garbage Collector ➙ Inline caching and adaptive optimizations (Crankshaft)

3/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-4
SLIDE 4

V8 JavaScript Engine

V8 JavaScript Engine ➙ JIT-only (arm, ia32, mips, x64, sh4) ➙ Precise Garbage Collector ➙ Inline caching and adaptive optimizations (Crankshaft) Efficient 1st-level JIT ➙ Single-pass code generation ➙ No register allocation ➙ Emits at the same time

Code Relocation information Constants (pooled)

➙ No instruction scheduling

3/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-5
SLIDE 5

V8 JavaScript Engine

4/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-6
SLIDE 6

Challenges

Computational Complexity Runtime: slower (optimizing) compiler impacts overall execution time

5/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-7
SLIDE 7

Challenges

Computational Complexity Runtime: slower (optimizing) compiler impacts overall execution time Dynamic-compilation issues Constants are pooled to optimize their placement Branches are written once their destinations are resolved Inline caching rewrites call sites during execution ➙ Instructions may be changed after being emitted (conflict: back-patching vs. reordering)

5/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-8
SLIDE 8

Challenge: Constant pool (example)

Emit instructions loading large constants...

0x42b1cb00 02 d0 mov.l ? , r0 ! 0xff000000 0x42b1cb02 2 2a e0 mov #42 , r1 0x42b1cb04 4 02 d0 mov.l ? , r2 ! 0 x f 0 f 0 f 0 f 0 0x42b1cb06 6 03 d0 mov.l ? , r3 ! 0 x f f f 0 f f f f 0x42b1cb08 8 0b 00 r t s 0x42b1cb0a 10 09 00 nop

6/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-9
SLIDE 9

Challenge: Constant pool (example)

..add constant pool and patch addresses.

0x42b1cb00 02 d0 mov.l 0x42b1cb0c , r0 ! 0xff000000 0x42b1cb02 2 2a e0 mov #42 , r1 0x42b1cb04 4 02 d0 mov.l 0x42b1cb10 , r2 ! 0 x f 0 f 0 f 0 f 0 0x42b1cb06 6 03 d0 mov.l 0x42b1cb14 , r3 ! 0 x f f f 0 f f f f 0x42b1cb08 8 0b 00 r t s 0x42b1cb0a 10 09 00 nop 0x42b1cb0c 12 ff000000 constant pool begin 0x42b1cb10 16 f 0 f 0 f 0 f 0 constant 0x42b1cb14 20 f f f 0 f f f f constant

7/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-10
SLIDE 10

Scoreboard Scheduling

In a nutshell ➙ Assigns issue dates to instructions during dispatch ➙ Keeps track of dependencies and resource use within a time window ➙ Lightweight (no dependency graph) but inferior results compared to List Scheduling

8/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-11
SLIDE 11

Scoreboard Scheduling

In a nutshell ➙ Assigns issue dates to instructions during dispatch ➙ Keeps track of dependencies and resource use within a time window ➙ Lightweight (no dependency graph) but inferior results compared to List Scheduling Data structures ➙ Dependency records

2 per resource (read/write) Pseudo records

➙ Reservation table (window length × resources)

8/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-12
SLIDE 12

Scoreboard Scheduling Example

s✉❜ ✶✻✱r✶✺ ♠♦✈ r✶✺✱r✶✹ ❝♠♣✴❡q ✵✱r✶✺ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ❛❞❞ r✺✱r✵ ▲❙✿ ✵✵✵✵✵ ▼❯▲✿ ✵✵✵✵✵ ❇❘✿ ✵✵✵✵✵ ❋P❯✿ ✵✵✵✵✵ ✐ss✉❡✿ ✵✵✵✵✵ ❁♥♦ r❡❝♦r❞s❃

9/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-13
SLIDE 13

Scoreboard Scheduling Example

s✉❜ ✶✻✱r✶✺ ♠♦✈ r✶✺✱r✶✹ ❝♠♣✴❡q ✵✱r✶✺ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ❛❞❞ r✺✱r✵ ✵✳✵✿ s✉❜ ✶✻✱r✶✺ ▲❙✿ ✵✵✵✵✵ ▼❯▲✿ ✵✵✵✵✵ ❇❘✿ ✵✵✵✵✵ ❋P❯✿ ✵✵✵✵✵ ✐ss✉❡✿ ✶✵✵✵✵ r❡❛❞ ❬r✶✺❪✿ ✵ ✇r✐t❡❬r✶✺❪✿ ✶

9/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-14
SLIDE 14

Scoreboard Scheduling Example

s✉❜ ✶✻✱r✶✺ ♠♦✈ r✶✺✱r✶✹ ❝♠♣✴❡q ✵✱r✶✺ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ❛❞❞ r✺✱r✵ ✵✳✵✿ s✉❜ ✶✻✱r✶✺ ✶✳✵✿ ♠♦✈ r✶✺✱r✶✹ ▲❙✿ ✵✵✵✵✵ ▼❯▲✿ ✵✵✵✵✵ ❇❘✿ ✵✵✵✵✵ ❋P❯✿ ✵✵✵✵✵ ✐ss✉❡✿ ✶✶✵✵✵ ✇r✐t❡❬r✶✹❪✿ ✶ r❡❛❞ ❬r✶✺❪✿ ✶ ✇r✐t❡❬r✶✺❪✿ ✶

9/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-15
SLIDE 15

Scoreboard Scheduling Example

s✉❜ ✶✻✱r✶✺ ♠♦✈ r✶✺✱r✶✹ ❝♠♣✴❡q ✵✱r✶✺ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ❛❞❞ r✺✱r✵ ✵✳✵✿ s✉❜ ✶✻✱r✶✺ ✶✳✵✿ ♠♦✈ r✶✺✱r✶✹ ✶✳✶✿ ❝♠♣✴❡q ✵✱r✶✺ ▲❙✿ ✵✵✵✵✵ ▼❯▲✿ ✵✵✵✵✵ ❇❘✿ ✵✵✵✵✵ ❋P❯✿ ✵✵✵✵✵ ✐ss✉❡✿ ✶✷✵✵✵ ✇r✐t❡❬r✶✹❪✿ ✶ r❡❛❞ ❬r✶✺❪✿ ✶ ✇r✐t❡❬r✶✺❪✿ ✶ ✇r✐t❡❬❚❪✿ ✷

9/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-16
SLIDE 16

Scoreboard Scheduling Example

s✉❜ ✶✻✱r✶✺ ♠♦✈ r✶✺✱r✶✹ ❝♠♣✴❡q ✵✱r✶✺ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ❛❞❞ r✺✱r✵ ✵✳✵✿ s✉❜ ✶✻✱r✶✺ ✵✳✶✿ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ✶✳✵✿ ♠♦✈ r✶✺✱r✶✹ ✶✳✶✿ ❝♠♣✴❡q ✵✱r✶✺ ▲❙✿ ✶✵✵✵✵ ▼❯▲✿ ✵✵✵✵✵ ❇❘✿ ✵✵✵✵✵ ❋P❯✿ ✵✵✵✵✵ ✐ss✉❡✿ ✷✷✵✵✵ r❡❛❞ ❬r✺❪✿ ✵ ✇r✐t❡❬r✺❪✿ ✸ ✇r✐t❡❬r✶✹❪✿ ✶ r❡❛❞ ❬r✶✺❪✿ ✶ ✇r✐t❡❬r✶✺❪✿ ✶ ✇r✐t❡❬❚❪✿ ✷

9/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-17
SLIDE 17

Scoreboard Scheduling Example

s✉❜ ✶✻✱r✶✺ ♠♦✈ r✶✺✱r✶✹ ❝♠♣✴❡q ✵✱r✶✺ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ❛❞❞ r✺✱r✵ ✵✳✵✿ s✉❜ ✶✻✱r✶✺ ✵✳✶✿ ♠♦✈✳❧ ❅✭❝♣✰✷✹✮✱r✺ ✶✳✵✿ ♠♦✈ r✶✺✱r✶✹ ✶✳✶✿ ❝♠♣✴❡q ✵✱r✶✺ ✸✳✵✿ ❛❞❞ r✺✱r✵ ▲❙✿ ✶✵✵✵✵ ▼❯▲✿ ✵✵✵✵✵ ❇❘✿ ✵✵✵✵✵ ❋P❯✿ ✵✵✵✵✵ ✐ss✉❡✿ ✷✷✵✶✵ ✇r✐t❡❬r✵❪✿ ✹ r❡❛❞ ❬r✺❪✿ ✸ ✇r✐t❡❬r✺❪✿ ✸ ✇r✐t❡❬r✶✹❪✿ ✶ r❡❛❞ ❬r✶✺❪✿ ✶ ✇r✐t❡❬r✶✺❪✿ ✶ ✇r✐t❡❬❚❪✿ ✷

9/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-18
SLIDE 18

Scoreboard Scheduling in V8

10/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-19
SLIDE 19

Scoreboard Scheduling in V8

Reordering Pitfalls ➙ Back-patching ➙ Atomic sequences ➙ Synchronized access to target buffer

10/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-20
SLIDE 20

Scoreboard Scheduling in V8

Reordering Pitfalls ➙ Back-patching ➙ Atomic sequences ➙ Synchronized access to target buffer Possible Solutions ➙ Naive: Flush frequently ➙ Better: Keep some extra information

10/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-21
SLIDE 21

Results: Execution time breakdown

crypto deltablue earley-boyer navier-stokes raytrace regexp richards splay 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 ·104 Profiling Ticks

GC Compilation JS VM

11/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-22
SLIDE 22

Results: Good News

Table: Profiled JS Ticks

Benchmark Unscheduled Scheduled Speedup(%) crypto 11,501 11,288 1.89 deltablue 729 684 6.58 earley-boyer 5,115 4,926 3.84 navier-stokes 16,351 15,629 4.62 raytrace 5,314 5,063 4.96 regexp 4,103 4,134 −0.75 richards 491 479 2.51 splay 625 616 1.46 Mean 3.11

12/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-23
SLIDE 23

Results: Bad News

Table: Scoreboard Scheduling Overhead (slowdown factor)

Benchmark Assembler* crypto 6.561 deltablue 3.952 earley-boyer 5.310 navier-stokes 6.870 raytrace 4.110 richards 7.609 splay 6.870 Mean 5.732

13/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-24
SLIDE 24

Results: A Mix of Both

Table: Total VM Execution Time (seconds)

Benchmark Unscheduled Scheduled Speedup(%) crypto 42.71 42.76 −0.12 deltablue 3.57 4.04 −11.55 earley-boyer 20.62 20.77 −0.74 navier-stokes 63.82 61.74 3.36 raytrace 24.28 24.58 −1.22 regexp 68.08 68.91 −1.19 richards 2.52 2.93 −13.78 splay 7.94 8.55 −7.17 Mean −4.22

14/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-25
SLIDE 25

Results: Silver Lining

Performance can be improved ➙ Delay slot filling ➙ Use Snapshot for (scheduled) builtins ➙ Adaptive control

15/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling

slide-26
SLIDE 26

Conclusion

Scoreboard Scheduling in V8 ➙ Profitable on in-order hardware ➙ Feasible when optimized for code generator

➙ In our case: no dynamic memory allocation

➙ Improving scheduling results possible

16/16 Alexander Jordan, Christophe Guillon Lightweight JavaScript JIT Scheduling