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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
monochrome
October 20, 2020
Programming
760
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rustでつくるガーベジコレクタ
shinjuku.rs #12
monochrome
October 20, 2020
More Decks by monochrome
See All by monochrome
RubyKaigi2026: Invariants in my own Ruby
sisshiki1969
0
27
Improving my own Ruby thereafter
sisshiki1969
1
250
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
1.1k
Improve my own Ruby
sisshiki1969
1
600
My own Ruby, thereafter
sisshiki1969
0
420
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
330
仮想マシンにおけるスタックの管理
sisshiki1969
0
250
Rustでゴミ集め
sisshiki1969
1
390
RustでつくるRubyのFiber
sisshiki1969
0
330
Other Decks in Programming
See All in Programming
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
2
110
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
370
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
200
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
100
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
200
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
Cloudflare is Agents
chimame
0
180
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
350
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.2k
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
580
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
1
310
Featured
See All Featured
Color Theory Basics | Prateek | Gurzu
gurzu
0
430
4 Signs Your Business is Dying
shpigford
187
23k
30 Presentation Tips
portentint
PRO
1
380
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
500
Building an army of robots
kneath
306
46k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
800
Balancing Empowerment & Direction
lara
6
1.2k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Designing Powerful Visuals for Engaging Learning
tmiket
1
510
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Exploring anti-patterns in Rails
aemeredith
3
470
Prompt Engineering for Job Search
mfonobong
0
420
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バグるとつらい。