Upgrade to Pro — share decks privately, control downloads, hide ads and more …

YJIT: Dive into Ruby's JIT compiler written in ...

YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022

Rust.Tokyo 2022

Takashi Kokubun

September 23, 2022
Tweet

More Decks by Takashi Kokubun

Other Decks in Programming

Transcript

  1. How YJIT works 1 + 2 Parse Ruby code Abstract

    Syntax Tree putobject 1 putobject 2 opt_plus leave Compile Bytecode
  2. How YJIT works 1 + 2 Parse Ruby code Abstract

    Syntax Tree putobject 1 putobject 2 opt_plus leave Compile JIT Bytecode Machine code
  3. How YJIT works: Ruby 3.1 putobject 1 putobject 2 opt_plus

    leave x86_64 Codegen Machine code Bytecode
  4. getlocal a getlocal b opt_plus setlocal c getlocal c putobject

    1 opt_gt branchunless getlocal a leave getlocal b leave Lazily compile basic blocks
  5. getlocal a getlocal b opt_plus setlocal c getlocal c putobject

    1 opt_gt branchunless Branch stub Branch stub Lazily compile basic blocks
  6. getlocal a getlocal b opt_plus setlocal c getlocal c putobject

    1 opt_gt branchunless getlocal a leave Branch stub Lazily compile basic blocks
  7. getlocal a getlocal b opt_plus setlocal c getlocal c putobject

    1 opt_gt branchunless getlocal a leave Branch stub Lazily compile basic blocks
  8. getlocal a getlocal b opt_plus setlocal c getlocal c putobject

    1 opt_gt branchunless getlocal a leave getlocal b leave Lazily compile basic blocks
  9. Why lazy compilation? 1. Better code locality a. Only compile

    used paths b. Related code is put together
  10. Why lazy compilation? 1. Better code locality a. Only compile

    used paths b. Related code is put together 2. More type information
  11. Type Profiling getlocal a getlocal b opt_plus (int) setlocal c

    getlocal c putobject 1 opt_gt branchunless
  12. IR