Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rustでつくるガーベジコレクタ
Search
monochrome
October 20, 2020
Programming
0
740
Rustでつくるガーベジコレクタ
shinjuku.rs #12
monochrome
October 20, 2020
Tweet
Share
More Decks by monochrome
See All by monochrome
Improving my own Ruby thereafter
sisshiki1969
1
200
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
910
Improve my own Ruby
sisshiki1969
1
430
My own Ruby, thereafter
sisshiki1969
0
360
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
270
仮想マシンにおけるスタックの管理
sisshiki1969
0
220
Rustでゴミ集め
sisshiki1969
1
350
RustでつくるRubyのFiber
sisshiki1969
0
300
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
Other Decks in Programming
See All in Programming
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
240
dchart: charts from deck markup
ajstarks
3
940
Go コードベースの構成と AI コンテキスト定義
andpad
0
160
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
240
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
220
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
2.3k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
670
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
310
TestingOsaka6_Ozono
o3
0
270
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
110
CSC307 Lecture 03
javiergs
PRO
1
470
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
130
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
47
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
410
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
How GitHub (no longer) Works
holman
316
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
4 Signs Your Business is Dying
shpigford
187
22k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
270
Transcript
Rustでつくるガーベジコレクタ monochrome twitter: @s_isshiki1969 Slack: プログラミング言語処理系が好きな人の集まり https://prog-lang-sys-ja-slack.github.io/wiki/
ruruby (https://github.com/sisshiki1969/ruruby) • 純Rust製のRuby実装 • 仮想マシンインタプリタ • 他の既存実装・仮想マシンへの依存なし • Rubyの標準ライブラリはRustで実装
• ガーベジコレクタを独自実装 • 2万行ぐらい
• 動的型付けのオブジェクト指向言語 • クラス定義、メソッド定義など、全てが動的 • 豊富なメタ言語機能 • Cで書かれている(50万行ぐらい)。 Ruby
構成 virtual machine (VM) Rubyコード 抽象構文木 (AST) バイトコード parser codegen
a = 1 + 2 PUSH_INT 1 PUSH_INT 2 ADD SET_LVAR ‘a’ Add 1 1 1 2 3 Assign 2 LVAR ’a’
オブジェクトの内部表現
Garbage collector Mutator (VM) Allocator ヒープ割り当て Collector 不要なオブジェクトの回収 割り当て要求 GC起動
*mut RValue
Page 0 7 8 15 16 20 23 24 0x4_0000
20 mark bitmap 0 7 64b x 4032 slot ≒ 256Kb
Allocator Free list 64b x 4032 slot ≒ 256Kb
Allocator Free list
Collector 起動 Free list
Garbage collection: Mark local variables method Array local variables method
Hash K V K V K V K V Object Instance variables Free list
None
Garbage collection: Sweep local variables method Array local variables method
Hash K V K V K V K V Object Instance variables Free list
None
Collector 処理終了 Free list
Allocator Free list
benchmark: aobench.rb (GC on / off)
バグりがちな点 var = [o1, o2, o3].each { |x| x.to_s }
配列オブジェクトをイテレートし、 各要素を関数で処理して戻り値を集め 配列を作って返すRubyスクリプト
バグりがちな点
①VM実行中にGCが起動すると… バグりがちな点 GC! ②作成中のオブジェクト が回収されてしまう ③VMは気づかず処理続行 → いつの間にか上書きされてバグる
まとめ • GCつくりました。 • GCバグるとつらい。