solving shape-analysis problems in languages with destructive updating

46
Solving Shape-Analysis Problems in Languages with Destructive Updating 増増 ( 増増増増増 ) 増増 ( 増増増増 西 )

Upload: serenity-mccarty

Post on 30-Dec-2015

19 views

Category:

Documents


2 download

DESCRIPTION

Solving Shape-Analysis Problems in Languages with Destructive Updating. 増山 ( 米澤研究室 ) 小野 ( 西田研究室 ). 参考文献. Mooly Sagiv et al , Solving Shape-Analysis Problems in Languages with Destructive Updating ACM Transactions on Programming Languages and Systems , 1998. 概要. Shape-Analysis とは ? - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Solving Shape-Analysis Problems in Languages with Destructive Updating

Solving Shape-Analysis Problems in Languages with

Destructive Updating

増山 ( 米澤研究室 )

小野 ( 西田研究室 )

Page 2: Solving Shape-Analysis Problems in Languages with Destructive Updating

参考文献

• Mooly Sagiv et al , Solving Shape-Analysis Problems in Languages with Destructive Updating

ACM Transactions on Programming Languages and Systems , 1998

Page 3: Solving Shape-Analysis Problems in Languages with Destructive Updating

概要

• Shape-Analysis とは ?• 理論 / 解析アルゴリズム

– DSG– SSG– 変換関数 / interpretation

• 解析の利点、欠点• 解析の安全性 (safety)• 応用 / まとめ

Page 4: Solving Shape-Analysis Problems in Languages with Destructive Updating

Shape-Analysis とは ?

Page 5: Solving Shape-Analysis Problems in Languages with Destructive Updating

Shape-Analysis とは ?

• データの形を静的に解析– 入力が

• リストならば出力もリストを保証• 木ならば出力も木を保証

– Pointer-Analysis , Alias-Analysis , Type Checking の問題を解くことができる

Page 6: Solving Shape-Analysis Problems in Languages with Destructive Updating

用途

• デバッグツールとして使用• 並列化に使用

– 共有されないデータを見つける

Page 7: Solving Shape-Analysis Problems in Languages with Destructive Updating

簡単な例 : リストの reverse

Page 8: Solving Shape-Analysis Problems in Languages with Destructive Updating

簡単な例 : リストの reverse

Page 9: Solving Shape-Analysis Problems in Languages with Destructive Updating

簡単な例 : リストの reverse

Page 10: Solving Shape-Analysis Problems in Languages with Destructive Updating

理論 / 解析アルゴリズム

Page 11: Solving Shape-Analysis Problems in Languages with Destructive Updating

対象言語

• 破壊的代入を伴う imperative な言語• Cons-cell  を扱う x : = nil x.sel := nil (sel { car, cdr })∈ x := new x := y x.sel := y x := y.sel

kill

generate

Page 12: Solving Shape-Analysis Problems in Languages with Destructive Updating

プログラムの形式化

• プログラムは Control-flow Graph (V,A)で表現 (V.. vertex, A .. arc)

• vertex– 代入文か条件式がひとつの vertex に対応

• arc– 制御の流れを示す

Page 13: Solving Shape-Analysis Problems in Languages with Destructive Updating

Shape Graph <Ev,Es>

• ノード– 変数 PVar– メモリのセルを表す shape_node

• car,cdr というセレクタを持つ

• 枝– 変数から出る枝  variable-edge (Ev)– shape_node から出る枝  selector_edge (Es)

Page 14: Solving Shape-Analysis Problems in Languages with Destructive Updating

DSG: deterministic shape-graph

• 定義– |Ev(x)| 1 (x PVar)≦ ∈– |Es(n,sel)| 1 (n shape_nodes)≦ ∈

• DSG のクラスを DSG と書く• 実行時のメモリ状態を表現する

Page 15: Solving Shape-Analysis Problems in Languages with Destructive Updating

Concrete Semantics[] : DSG → DSG

Page 16: Solving Shape-Analysis Problems in Languages with Destructive Updating

DSG と Control-Flow Graph の関係

DSGDSGDSGDSGDSGDSGDSGDSG

DSGDSGDSGDSG

DSGDSGDSGDSGDSGDSGDSGDSG

Page 17: Solving Shape-Analysis Problems in Languages with Destructive Updating

Collecting Semantics

• 定義  cs: V → 2DSG

• あるプログラムポイントでの実現しうるメモリ状態全ての集合

Page 18: Solving Shape-Analysis Problems in Languages with Destructive Updating

SSG: Static Shape-Graph

• 定義– Shape-Graph(SG#) と、 shape_node の共有状態

を表す真偽値関数 (is#) とのペア (<SG#, is#>)

– shape_node は変数の集合で名前付けされている  ( 例 n{x,y,z})

• SSG のクラスを SSG と書く• あるプログラムポイントでのメモリ状態

を抽象化している

Page 19: Solving Shape-Analysis Problems in Languages with Destructive Updating

DSG と SSG と Control-Flow Graph の関係

SSG

SSGDSGDSGDSGDSG

SSG

DSGDSGDSGDSGDSGDSGDSGDSG

DSGDSGDSGDSG

DSGDSGDSGDSGDSGDSGDSGDSG

Page 20: Solving Shape-Analysis Problems in Languages with Destructive Updating

DSG から SSG への変換

• 定義 β: DSG → SSG– β(l) : shape_node 間の変換

• DSG 上で l を指す変数集合で名前付け

– is#(n) : SSG の shape_node→{true,false}• iis[Es](l) = |{<*,*,l> Es}| 2∈ ≧• is#(n) =

Page 21: Solving Shape-Analysis Problems in Languages with Destructive Updating

変換の例x

y

z

w

x

y

z

w

n{w,y} n{z}

n{x}

Page 22: Solving Shape-Analysis Problems in Languages with Destructive Updating

複数の DSG のマージ

• α: 2DSG→SSG

Page 23: Solving Shape-Analysis Problems in Languages with Destructive Updating

DSG のマージの例

Page 24: Solving Shape-Analysis Problems in Languages with Destructive Updating

Concrete and Abstract Properties

Page 25: Solving Shape-Analysis Problems in Languages with Destructive Updating

Safe Approximation

• 定義

• DSG で p が成り立つならば、 SSG 上でも p# が成り立つ

• compatible , = などは Safe Approximationである

• その対偶である !p# !p⇒ が重要

Page 26: Solving Shape-Analysis Problems in Languages with Destructive Updating

Abstract Interpretation

SSG

SSGDSGDSGDSGDSG

SSG

DSGDSGDSGDSGDSGDSGDSGDSG

DSGDSGDSGDSG

DSGDSGDSGDSGDSGDSGDSGDSG

AbstractInterpretation

AbstractInterpretation

Page 27: Solving Shape-Analysis Problems in Languages with Destructive Updating

Abstract Semantics

• 定義– []#: SSG → SSG

• x := nil• x.sel := nil• x := new• x := y• x.sel := y• x := y.selそれぞれの文について定義する

Page 28: Solving Shape-Analysis Problems in Languages with Destructive Updating

x := nil {v7 : t1 := nil}

Page 29: Solving Shape-Analysis Problems in Languages with Destructive Updating

x.sel := nil {v11 : y.cdr := nil}

Page 30: Solving Shape-Analysis Problems in Languages with Destructive Updating

x := new

• 新しく共有されていない shape_node を作成

• Ev に新たな枝 [x,n{x}] を加える

Page 31: Solving Shape-Analysis Problems in Languages with Destructive Updating

x := y {v6 : y := x}

Page 32: Solving Shape-Analysis Problems in Languages with Destructive Updating

x.sel := y {v12 : y.cdr := t}

Page 33: Solving Shape-Analysis Problems in Languages with Destructive Updating

x := y.sel {v8 : t1 := x.cdr}

Page 34: Solving Shape-Analysis Problems in Languages with Destructive Updating

Shape-Analysis Algorithm

•  Control-Flow Graph の各頂点に対して上の式から計算できる least fixed point を求める• 反復法•  SSG の shape_node は 2|Pvar| で抑えられ、反復によって、枝数は単調に増加する ⇒ 解析は停止する

Page 35: Solving Shape-Analysis Problems in Languages with Destructive Updating

データタイプを表す SSG

Page 36: Solving Shape-Analysis Problems in Languages with Destructive Updating

Concretization Function

• 定義 γ: SSG → 2DSG

• SSG から実現されうる DSG の集合

Page 37: Solving Shape-Analysis Problems in Languages with Destructive Updating

この解析の利点、欠点

Page 38: Solving Shape-Analysis Problems in Languages with Destructive Updating

Strong nullification

Page 39: Solving Shape-Analysis Problems in Languages with Destructive Updating

e.cdr := tiis#(n{t}) = true

n{y,z},n{x,y} から n{t} への枝が消せる

⇒ iis#(n{t}) = false ⇒ is#(n{t}) = false

Page 40: Solving Shape-Analysis Problems in Languages with Destructive Updating

この解析の問題点

• nφ が多くのノードを抽象化– 精度を落とす原因nφ をより詳しく分類する

• ノード数がプログラムの変数の数の指数オーダー– 分岐が多いプログラムでは特に問題精度は落ちるがノード数を減らした解析は

可能

Page 41: Solving Shape-Analysis Problems in Languages with Destructive Updating

解析の安全性 (safety)

Page 42: Solving Shape-Analysis Problems in Languages with Destructive Updating

安全性• Local Safety

∀SG∈DSG,st

• Grobal Safety

∀v V∈(v は Control-Flow Graph の vertex)

SGi# = <<Evi

#,Esi#>,isi

#>の定義

Page 43: Solving Shape-Analysis Problems in Languages with Destructive Updating

安全性の証明の流れ

Page 44: Solving Shape-Analysis Problems in Languages with Destructive Updating

応用 / まとめ

Page 45: Solving Shape-Analysis Problems in Languages with Destructive Updating

応用• Aliases の発見

– あるプログラムポイント v で、 2 つのアクセスパス e1,e2 が

• 同じ cons-cell を指すような実行があるか ?  (may)

• 必ず同じ cons-cell を指すか ? (must)

• 共有されうるデータの発見

Page 46: Solving Shape-Analysis Problems in Languages with Destructive Updating

まとめ

• Shape-Analysis– ヒープの状態を静的に解析– 変数の aliasing を正確に追うことである程

度正確な解析が可能– 状態数の抑制と精度のトレードオフあり