the javascriptcore virtual machine
play

The JavaScriptCore Virtual Machine Filip Pizlo Apple Inc. 3 Pizlo - PowerPoint PPT Presentation

The JavaScriptCore Virtual Machine Filip Pizlo Apple Inc. 3 Pizlo Keynotes / Week ICCV17 Symmetry as the fundamental prior in human 3D vision Zygmunt Pizlo webkit.org https://svn.webkit.org/repository/webkit/trunk Safari What


  1. Optimizations • Generatorification • Strength Reduction • Inlining • Tail Duplication • Strength Reduction • Switch Inference • CSE (local and global) • Float Inference • LICM • DCE • Type/Bounds/Overflow Check Removal • Register Allocation • Object Allocation Sinking • Linear Scan • Arguments/Varargs Elimination • Briggs • Sparse Conditional Constant • Iterated Register Coalescing Propagation • Stack Allocation • Barrier Placement

  2. Interpreters and JITs • Optimized for breadth • Four tiers • Many optimizations in many IRs • Speculative

  3. Object Model

  4. {x: 1, y: 2} {x: 42, y: 3} {x: -5, y: 7}

  5. {x, y} {1, 2} {42, 3} {-5, 7}

  6. prototype {x, y} global object {1, 2} {42, 3} {-5, 7}

  7. prototype structure {x, y} global object {1, 2} {42, 3} {-5, 7}

  8. Mono Proto Poly Proto proto proto 1 {x, y} {x, y} global global object object {1, 2} {1, 2} {42, 3} {42, 3} {-5, 7} {-5, 7} proto 2 poly proto just landed last Thursday @saambarati and I have been working on it for ~2 months

  9. Structures • Fast property access • Property type inference • Immutable property inference • Prototype optimizations

  10. JSC Object Model cell state indexing structure flags type … butterfly pointer inline slot 0 inline slot 1 ID public vector … … out of line slot 0 array slot 0 length length

  11. JSC Object Model 64 bits 64 bits 64 bits 64 bits cell state indexing structure flags type … butterfly pointer inline slot 0 inline slot 1 ID 64 bits 64 bits 64 bits public vector … … out of line slot 0 array slot 0 length length

  12. JSC Object Model cell state indexing structure flags type … butterfly pointer inline slot 0 inline slot 1 ID public vector … … out of line slot 0 array slot 0 length length

  13. JSC Object Model statically configurable cell state indexing structure flags type … butterfly pointer inline slot 0 inline slot 1 ID public vector … … out of line slot 0 array slot 0 length length

  14. JSC Object Model statically configurable cell state indexing structure flags type … butterfly pointer inline slot 0 inline slot 1 ID public vector … … out of line slot 0 array slot 0 length length dynamically configurable

  15. Empty JSObject cell state indexing structure flags type null ID

  16. Fast JSObject cell state indexing structure flags type null 0xffff000000000005 0xffff000000000006 ID var o = {f: 5, g: 6};

  17. JSObject with dynamically added fields cell state indexing structure flags type butterfly 0xffff000000000005 0xffff000000000006 ID 0xffff000000000007 var o = {f: 5, g: 6}; o.h = 7;

  18. JSArray with room for 3 array elements cell state indexing structure flags type butterfly ID <hole> <hole> <hole> 0 3 var a = [];

  19. Object with fast properties and array elements cell state indexing structure flags type butterfly 0xffff000000000005 0xffff000000000006 ID 0xffff000000000007 <hole> <hole> 1 3 var o = {f: 5, g: 6}; o[0] = 7;

  20. Object with fast and dynamic properties and array elements cell state indexing structure flags type butterfly 0xffff000000000005 0xffff000000000006 ID 0xffff000000000008 0xffff000000000007 <hole> 1 2 var o = {f: 5, g: 6}; o[0] = 7; o.h = 8;

  21. Exotic object with dynamic properties and array elements cell state indexing structure flags type butterfly <C++ state> <C++ state> ID 0xffff000000000008 0xffff000000000007 <hole> 1 2 var o = new Date(); o[0] = 7; o.h = 8;

  22. Object Model • Structures • Cells • Butterflies

  23. Type Inference

  24. Type Inference • Watchpoints • Value Profiles • Polymorphic Inline Caches

  25. Type Inference • Watchpoints • Value Profiles • Polymorphic Inline Caches

  26. Watchpoints

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

  28. numberToStringWatchpoint

  29. numberToStringWatchpoint 1. Compiler wants to optimize 42.toString() to “42” 2. Check if already invalidated • If invalid, don’t do the optimization. • If valid, register watchpoint and do the optimization.

  30. Many watchpoints • haveABadTime • Structure transition • InferredValue • InferredType • many others

  31. Garbage Collector

  32. Garbage Collector • No copying • Conservative on the stack

  33. Garbage Collector • Constraint-based • Generational • Concurrent • Parallel

  34. Garbage Collector • Constraint-based • Generational • Concurrent • Parallel

  35. Constraint-Based Marking • Transitive reachability is not always enough • Common examples: • Soft references • Weak map

  36. Constraint-Based Marking • Transitive reachability is not always enough • WebKit examples: • Type inference • Weak map • DOM • Native code

  37. Constraint-Based Marking • Transitive reachability is not always enough • WebKit examples: • Type inference • Weak map • DOM • Native code

  38. Type Inference

  39. Structure prototype {x, y} global object {1, 2} Objects {42, 3} {-5, 7}

  40. prototype {x, y} global object {1, 2} {42, 3} {-5, 7}

  41. JIT code prototype {x, y} global object {1, 2} {42, 3} {-5, 7}

  42. Is this a weak reference? JIT code prototype {x, y} global object {1, 2} {42, 3} {-5, 7}

  43. JIT code references a structure • Strong reference? • Weak reference? • Marking constraint?

  44. Strong reference? JIT code prototype {x, y} global object {1, 2} {42, 3} {-5, 7}

  45. Strong reference? JIT code prototype {x, y} global object

  46. Strong reference? JIT code prototype {x, y} global object

  47. Strong reference? JIT code prototype {x, y} global object so many leaks

  48. Weak reference? JIT code prototype {x, y} global object {1, 2} {42, 3} {-5, 7}

Recommend


More recommend