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
640
Rustでつくるガーベジコレクタ
shinjuku.rs #12
monochrome
October 20, 2020
Tweet
Share
More Decks by monochrome
See All by monochrome
My own Ruby, thereafter
sisshiki1969
0
270
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
170
仮想マシンにおけるスタックの管理
sisshiki1969
0
180
Rustでゴミ集め
sisshiki1969
1
300
RustでつくるRubyのFiber
sisshiki1969
0
250
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.6k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
770
RustでつくるRubyのFiber
sisshiki1969
0
460
Other Decks in Programming
See All in Programming
技術を根付かせる / How to make technology take root
kubode
1
250
DROBEの生成AI活用事例 with AWS
ippey
0
130
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
270
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
330
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
120
GAEログのコスト削減
mot_techtalk
0
120
Introduction to kotlinx.rpc
arawn
0
700
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
850
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
9
1.8k
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
570
color-scheme: light dark; を完全に理解する
uhyo
5
390
CDK開発におけるコーディング規約の運用
yamanashi_ren01
2
140
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Producing Creativity
orderedlist
PRO
344
39k
The Language of Interfaces
destraynor
156
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Six Lessons from altMBA
skipperchong
27
3.6k
GraphQLとの向き合い方2022年版
quramy
44
13k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Designing for humans not robots
tammielis
250
25k
Raft: Consensus for Rubyists
vanstee
137
6.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Documentation Writing (for coders)
carmenintech
67
4.6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
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バグるとつらい。