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

Mark Compact GC in MRI

Mark Compact GC in MRI

My presentation about Mark Compact GC in MRI for GitHub Constellation Tokyo

Aaron Patterson

June 13, 2017
Tweet

More Decks by Aaron Patterson

Other Decks in Technology

Transcript

  1. How people build software ! ! GitHub Core Values 17

    • Collaboration • Empathy • Quality • Positive Impact • Shipping
  2. How people build software ! ! ϝϞϦྖҬͷϨΠΞ΢τ 32 ώʔϓྖҬ ϖʔδ

    ϖʔδ ϖʔδ ϖʔδ ϖʔδ ϖʔδ ϖʔδ ϖʔδ Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
  3. How people build software ! ! ϖʔδͷϨΠΞ΢τ 35 ϖʔδ FREE

    FREE FREE FREE FREE FREE FREE FREE FREE FREE SLOTS Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
  4. How people build software ! ! ϖʔδͷϨΠΞ΢τ 36 ϖʔδ FREE

    FREE FREE FREE FREE FREE FREE FREE FREE FREE SLOTS Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
  5. How people build software ! ! Tree of Objects 44

    Root A B C D a = [ { c: 'd' } ] Ruby Array Hash String Symbol
  6. How people build software ! ! Tree of Objects 45

    Root A B C D a = [ { c: 'd' } ] a = nil Ruby
  7. How people build software ! ! Free Space 53 ϖʔδ

    FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj ϖʔδ FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj ϖʔδ FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
  8. How people build software ! ! Free Space 54 FREE

    FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
  9. How people build software ! ! Free Space 55 FREE

    FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
  10. How people build software ! ! ΦϒδΣΫτͷҠಈ 62 1 2

    3 4 5 6 7 8 9 a b Free Free Free Obj Free Obj Obj Obj Free Free Obj ☝ ☝ Free Pointer Scan Pointer 1 2 3 5 Done! Address Heap
  11. How people build software ! ! ΦϒδΣΫτҠಈͷલ 63 1 2

    3 4 5 6 7 8 9 a b Free Free Free Obj Free Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd'
  12. How people build software ! ! ΦϒδΣΫτҠಈͷޙ 64 1 2

    3 4 5 6 7 8 9 a b Obj Free Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd' 1 2 3 5
  13. How people build software ! ! ϦϑΝϨϯεͷߋ৽ 65 1 2

    3 4 5 6 7 8 9 a b Obj Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd' 1 2 3 5 ☝ Done!
  14. How people build software ! ! ϦϑΝϨϯεͷߋ৽ 66 1 2

    3 4 5 6 7 8 9 a b Obj Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd' 1 2 3 5 Free Free Free Free
  15. How people build software ! ! C֦ுͷϦϑΝϨϯε 70 Hash Symbol

    String C code rb_gc_mark ෆҠಈ Ҡಈ Ҡ ಈ
  16. How people build software ! ! file.c in MRI 72

    separator = rb_obj_freeze(rb_usascii_str_new2("/")); /* separates directory parts in path */ rb_define_const(rb_cFile, "Separator", separator); rb_define_const(rb_cFile, "SEPARATOR", separator); static VALUE rb_file_s_join(VALUE klass, VALUE args) { return rb_file_join(args, separator); } άϩόϧม਺
  17. How people build software ! ! άϩόϧม਺ - SEGV 73

    $ ruby -e'File::Separator = File::SEPARATOR = nil; GC.start; File.join("a", "b")' # BOOM $ jruby -e'File::Separator = File::SEPARATOR = nil; GC.start; File.join("a", "b")'
  18. How people build software ! ! Compaction Code 77 GC.start

    File.open("pre_compact.json", "wb") { |f| ObjectSpace.dump_all(output: f) } GC.start p GC.compact GC.start File.open("post_compact.json", "wb") { |f| ObjectSpace.dump_all(output: f) } $ ruby bin/rails r script.rb