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

How Rubinius runs your code?

How Rubinius runs your code?

This talk presents the structure of Rubinius and how it works under the hood. It talks about its bootstrap process, the virtual machine, bytecode compiler, JIT, memory layout and garbage collection.

Presented at RubyConf Brazil 2013.

Carlos Galdino

August 29, 2013
Tweet

More Decks by Carlos Galdino

Other Decks in Programming

Transcript

  1. class Person def initialize(name, age) @name = name @age =

    age end def underage? @age < 21 end end
  2. =============== :Person ================ Arguments: 0 required, 0 post, 0 total

    Arity: 0 Locals: 0 Stack size: 5 Literals: 6: :initialize, <compiled code>, :method_visibility, :add_defn_method, :underage?, <compiled code> Lines to IP: 2: 2..15, 7: 16..29 0000: push_self 0001: add_scope 0002: push_rubinius 0003: push_literal :initialize 0005: push_literal #<Rubinius::CompiledCode initialize file=person.rb> 0007: push_scope 0008: push_variables 0009: send_stack :method_visibility, 0 0012: send_stack :add_defn_method, 4 0015: pop 0016: push_rubinius 0017: push_literal :underage? 0019: push_literal #<Rubinius::CompiledCode underage? file=person.rb> 0021: push_scope 0022: push_variables 0023: send_stack :method_visibility, 0 0026: send_stack :add_defn_method, 4 0029: ret ----------------------------------------
  3. 0000: push_self 0001: add_scope 0002: push_rubinius 0003: push_literal :initialize 0005:

    push_literal #<Rubinius::CompiledCode initialize file=person.rb> 0007: push_scope 0008: push_variables 0009: send_stack :method_visibility, 0 0012: send_stack :add_defn_method, 4 0015: pop 0016: push_rubinius 0017: push_literal :underage? 0019: push_literal #<Rubinius::CompiledCode underage? file=person.rb> 0021: push_scope 0022: push_variables 0023: send_stack :method_visibility, 0 0026: send_stack :add_defn_method, 4 0029: ret ----------------------------------------
  4. class Person def initialize(name, age) @name = name @age =

    age end def underage? @age < 21 end end
  5. ============= :initialize ============== Arguments: 2 required, 0 post, 2 total

    Arity: 2 Locals: 2: name, age Stack size: 3 Literals: 2: :@name, :@age Line: 2 Lines to IP: 3: 0..4, 4: 5..9 0000: push_local 0 # name 0002: set_ivar :@name 0004: pop 0005: push_local 1 # age 0007: set_ivar :@age 0009: ret ----------------------------------------
  6. class Person def initialize(name, age) @name = name @age =

    age end def underage? @age < 21 end end
  7. ============== :underage? ============== Arguments: 0 required, 0 post, 0 total

    Arity: 0 Locals: 0 Stack size: 2 Literals: 2: :@age, :< Line: 7 Lines to IP: 8: 0..7 0000: push_ivar :@age 0002: push_int 21 0004: send_stack :<, 1 0007: ret ----------------------------------------
  8. class Person def initialize(name, age) @name = name @age =

    age end def underage? @age < 21 end end
  9. class Person def initialize(name, age) @name = name @age =

    age end def underage? @age < 21 end end
  10. AST

  11. [:script, [:class, :Person, nil, [:scope, [:block, [:defn, :initialize, [:args, :name,

    :age], [:scope, [:block, [:iasgn, :@name, [:lvar, :name]], [:iasgn, :@age, [:lvar, :age]]]]], [:defn, :underage?, [:args], [:scope, [:block, [:call, [:ivar, :@age], :<, [:arglist, [:lit, 21]]]]]]]]]]
  12. 0000: push_self 0001: add_scope 0002: push_rubinius 0003: push_literal :initialize 0005:

    push_literal #<Rubinius::CompiledCode initialize file=person.rb> 0007: push_scope 0008: push_variables 0009: send_stack :method_visibility, 0 0012: send_stack :add_defn_method, 4 0015: pop 0016: push_rubinius 0017: push_literal :underage? 0019: push_literal #<Rubinius::CompiledCode underage? file=person.rb> 0021: push_scope 0022: push_variables 0023: send_stack :method_visibility, 0 0026: send_stack :add_defn_method, 4 0029: ret ----------------------------------------
  13. object_type obj_type : 8; gc_zone zone : 2; unsigned int

    age : 4; aux_meaning meaning : 3; unsigned int Forwarded : 1; unsigned int Remember : 1; unsigned int Marked : 3; unsigned int InImmix : 1; unsigned int Pinned : 1; unsigned int Frozen : 1; unsigned int Tainted : 1; unsigned int Untrusted : 1; unsigned int LockContended : 1; unsigned int unused : 4;
  14. object_type obj_type : 8; gc_zone zone : 2; unsigned int

    age : 4; aux_meaning meaning : 3; unsigned int Forwarded : 1; unsigned int Remember : 1; unsigned int Marked : 3; unsigned int InImmix : 1; unsigned int Pinned : 1; unsigned int Frozen : 1; unsigned int Tainted : 1; unsigned int Untrusted : 1; unsigned int LockContended : 1; unsigned int unused : 4;
  15. class Person def initialize(name, age) @name = name @age =

    age end def underage? @age < 21 end end