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
750
0
Share
Rustでつくるガーベジコレクタ
shinjuku.rs #12
monochrome
October 20, 2020
More Decks by monochrome
See All by monochrome
Improving my own Ruby thereafter
sisshiki1969
1
230
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
1k
Improve my own Ruby
sisshiki1969
1
550
My own Ruby, thereafter
sisshiki1969
0
390
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
300
仮想マシンにおけるスタックの管理
sisshiki1969
0
240
Rustでゴミ集め
sisshiki1969
1
370
RustでつくるRubyのFiber
sisshiki1969
0
320
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
Other Decks in Programming
See All in Programming
書き換えて学ぶTemporal #fukts
pirosikick
2
380
AIを導入する前にやるべきこと
negima
2
360
Agentic UI in the Frontend: Architectures with Open Standards @JAX 2026 in Mainz
manfredsteyer
PRO
0
110
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
150
Cloudflare で始める Data Platform
ta93abe
0
160
Kubernetesを使わない環境にもCloud Nativeなデプロイを実現する / Enabling Cloud Native deployments without the complexity of Kubernetes
linyows
3
400
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
390
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
460
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
150
ローカルLLMでどこまでコードが書けるか / How much code can be written on a local LLM
kishida
2
360
Skillは並べた。動かなかった。契約で繋いだ。— 65個のSkillから、自走する開発サイクルへ
junholee
0
600
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
550
First, design no harm
axbom
PRO
2
1.2k
Why Our Code Smells
bkeepers
PRO
340
58k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
70
39k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Optimizing for Happiness
mojombo
378
71k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
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バグるとつらい。