Upload
serenity-mccarty
View
19
Download
2
Embed Size (px)
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
Citation preview
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 とは ?• 理論 / 解析アルゴリズム
– DSG– SSG– 変換関数 / interpretation
• 解析の利点、欠点• 解析の安全性 (safety)• 応用 / まとめ
Shape-Analysis とは ?
Shape-Analysis とは ?
• データの形を静的に解析– 入力が
• リストならば出力もリストを保証• 木ならば出力も木を保証
– Pointer-Analysis , Alias-Analysis , Type Checking の問題を解くことができる
用途
• デバッグツールとして使用• 並列化に使用
– 共有されないデータを見つける
簡単な例 : リストの reverse
簡単な例 : リストの reverse
簡単な例 : リストの reverse
理論 / 解析アルゴリズム
対象言語
• 破壊的代入を伴う imperative な言語• Cons-cell を扱う x : = nil x.sel := nil (sel { car, cdr })∈ x := new x := y x.sel := y x := y.sel
kill
generate
プログラムの形式化
• プログラムは Control-flow Graph (V,A)で表現 (V.. vertex, A .. arc)
• vertex– 代入文か条件式がひとつの vertex に対応
• arc– 制御の流れを示す
Shape Graph <Ev,Es>
• ノード– 変数 PVar– メモリのセルを表す shape_node
• car,cdr というセレクタを持つ
• 枝– 変数から出る枝 variable-edge (Ev)– shape_node から出る枝 selector_edge (Es)
DSG: deterministic shape-graph
• 定義– |Ev(x)| 1 (x PVar)≦ ∈– |Es(n,sel)| 1 (n shape_nodes)≦ ∈
• DSG のクラスを DSG と書く• 実行時のメモリ状態を表現する
Concrete Semantics[] : DSG → DSG
DSG と Control-Flow Graph の関係
DSGDSGDSGDSGDSGDSGDSGDSG
DSGDSGDSGDSG
DSGDSGDSGDSGDSGDSGDSGDSG
Collecting Semantics
• 定義 cs: V → 2DSG
• あるプログラムポイントでの実現しうるメモリ状態全ての集合
SSG: Static Shape-Graph
• 定義– Shape-Graph(SG#) と、 shape_node の共有状態
を表す真偽値関数 (is#) とのペア (<SG#, is#>)
– shape_node は変数の集合で名前付けされている ( 例 n{x,y,z})
• SSG のクラスを SSG と書く• あるプログラムポイントでのメモリ状態
を抽象化している
DSG と SSG と Control-Flow Graph の関係
SSG
SSGDSGDSGDSGDSG
SSG
DSGDSGDSGDSGDSGDSGDSGDSG
DSGDSGDSGDSG
DSGDSGDSGDSGDSGDSGDSGDSG
DSG から SSG への変換
• 定義 β: DSG → SSG– β(l) : shape_node 間の変換
• DSG 上で l を指す変数集合で名前付け
– is#(n) : SSG の shape_node→{true,false}• iis[Es](l) = |{<*,*,l> Es}| 2∈ ≧• is#(n) =
変換の例x
y
z
w
x
y
z
w
n{w,y} n{z}
nφ
n{x}
複数の DSG のマージ
• α: 2DSG→SSG
DSG のマージの例
Concrete and Abstract Properties
Safe Approximation
• 定義
• DSG で p が成り立つならば、 SSG 上でも p# が成り立つ
• compatible , = などは Safe Approximationである
• その対偶である !p# !p⇒ が重要
Abstract Interpretation
SSG
SSGDSGDSGDSGDSG
SSG
DSGDSGDSGDSGDSGDSGDSGDSG
DSGDSGDSGDSG
DSGDSGDSGDSGDSGDSGDSGDSG
AbstractInterpretation
AbstractInterpretation
Abstract Semantics
• 定義– []#: SSG → SSG
• x := nil• x.sel := nil• x := new• x := y• x.sel := y• x := y.selそれぞれの文について定義する
x := nil {v7 : t1 := nil}
x.sel := nil {v11 : y.cdr := nil}
x := new
• 新しく共有されていない shape_node を作成
• Ev に新たな枝 [x,n{x}] を加える
x := y {v6 : y := x}
x.sel := y {v12 : y.cdr := t}
x := y.sel {v8 : t1 := x.cdr}
Shape-Analysis Algorithm
• Control-Flow Graph の各頂点に対して上の式から計算できる least fixed point を求める• 反復法• SSG の shape_node は 2|Pvar| で抑えられ、反復によって、枝数は単調に増加する ⇒ 解析は停止する
データタイプを表す SSG
Concretization Function
• 定義 γ: SSG → 2DSG
• SSG から実現されうる DSG の集合
この解析の利点、欠点
Strong nullification
e.cdr := tiis#(n{t}) = true
n{y,z},n{x,y} から n{t} への枝が消せる
⇒ iis#(n{t}) = false ⇒ is#(n{t}) = false
この解析の問題点
• nφ が多くのノードを抽象化– 精度を落とす原因nφ をより詳しく分類する
• ノード数がプログラムの変数の数の指数オーダー– 分岐が多いプログラムでは特に問題精度は落ちるがノード数を減らした解析は
可能
解析の安全性 (safety)
安全性• Local Safety
∀SG∈DSG,st
• Grobal Safety
∀v V∈(v は Control-Flow Graph の vertex)
SGi# = <<Evi
#,Esi#>,isi
#>の定義
安全性の証明の流れ
応用 / まとめ
応用• Aliases の発見
– あるプログラムポイント v で、 2 つのアクセスパス e1,e2 が
• 同じ cons-cell を指すような実行があるか ? (may)
• 必ず同じ cons-cell を指すか ? (must)
• 共有されうるデータの発見
まとめ
• Shape-Analysis– ヒープの状態を静的に解析– 変数の aliasing を正確に追うことである程
度正確な解析が可能– 状態数の抑制と精度のトレードオフあり