Survey: A Compositional Account of the Java Virtual Machine

24
Survey: A Compositional Account of the Java Virtual Machine 2000/05/ 24 中中 中中 POPL99 http://www.sun.com/tech/peop le/yelland/

description

Survey: A Compositional Account of the Java Virtual Machine. POPL99 http://www.sun.com/tech/people/yelland/. 2000/05/24 中尾 晴彦. 本研究の動機. JVM の仕様を厳密に記述する必要性が高いが、現在その手段がない。 今までにも JVM の仕様を形式的に行う研究はなされてきたが、 JVM のサイズと複雑さのため、それらの多くは部分的な仕様定義であったり扱いにくいものであった。. 本研究の目的. - PowerPoint PPT Presentation

Transcript of Survey: A Compositional Account of the Java Virtual Machine

Page 1: Survey: A Compositional Account of the Java Virtual Machine

Survey:A Compositional Account of theJava Virtual Machine

2000/05/24

中尾 晴彦

POPL99

http://www.sun.com/tech/people/yelland/

Page 2: Survey: A Compositional Account of the Java Virtual Machine

本研究の動機

JVM の仕様を厳密に記述する必要性が高いが、現在その手段がない。

今までにも JVM の仕様を形式的に行う研究はなされてきたが、 JVM のサイズと複雑さのため、それらの多くは部分的な仕様定義であったり扱いにくいものであった。

Page 3: Survey: A Compositional Account of the Java Virtual Machine

本研究の目的

包括的で扱いやすい形式で JVM の仕様を厳密に記述すること。

Page 4: Survey: A Compositional Account of the Java Virtual Machine

本研究のアプローチ

HASKELL のプログラムで JVM の仕様を記述する。

この際、プログラムのデータ型の型付けを巧くすることにより VERIFIER におけるチェックを HASKELL の型チェックで行う。

Page 5: Survey: A Compositional Account of the Java Virtual Machine

プログラムの概要 microinstruction と呼ばれる Haskell の小さな関数

群( μJVM )を用意し JVM の各 Primitive をそれらを用いて表す。– μJVM

• getl ローカル変数を取り出す• pushs スタックにプッシュする• load l tst k = getl l $ λw.pushs (tst w) $ k• pInt Int 型であるかチェックする

– Primitive• iload l = load l pInt

– Int 型のローカル変数を取り出し、スタックにプッシュする

Page 6: Survey: A Compositional Account of the Java Virtual Machine

省略事項 基本データ型は、 Integer 型と Float 型のみとする。 オブジェクト操作は、 creation, initialization, virtua

l method invocation のみとし、 static method invocation, direct field access は省略する。

全ての method は Integer 型を返すものとする。 例外をサポートしない。 インターフェースをサポートしない。 マルチスレッドをサポートしない。 ネイティブメソッド呼び出しをサポートしない。

Page 7: Survey: A Compositional Account of the Java Virtual Machine

Dynamic Semantics of μJVM

DataType の定義– JVM の基本データ型、クラス、オブジェクト、

メソッド、マシンステート等を表現する Haskellのデータ型を定義する。

microinstruction の定義– バイトコードのプリミティブを表現する HASKE

LL 関数のための補助的な関数を定義する。

Page 8: Survey: A Compositional Account of the Java Virtual Machine

DataTypes

data Word t = WInt Int | WFloat Float | WRef Int data JClassRT = TagA | TagB | TagC | TagD data JClass t = MkJClass JClassRT data Method p n = MkMethod (JClass(p, n)) Int data VMState s l h = MkVMState{stack::s, locals::l,

heap::h} data Cont s l h = MkCont {cfn::VMState s l h → Int }

Data type の例

Page 9: Survey: A Compositional Account of the Java Virtual Machine

Microinstructions

inInt v = WInt v outInt(WInt v) = v outInt _ = error "Verify error: Integer

word expected” pushs w (MkCont cfn) =

MkCont (λvms. let MkVMState {stack = s} = vms in cfn vms {stack ← (w, s)})

Micorinstruction の例

Page 10: Survey: A Compositional Account of the Java Virtual Machine

Microinstructions Call (MkMethod (MkClass imptag) mrslt) (Wref ref) fn =

MkCont(λvms. let MkVMState {heap = MkHeap { store = s,

hwm = hi} = vmsin if (ref < 0 || ref > hi) then

error “Verify error: Illeagal reference” else

case (s ref) ofMkObject {initialized = True, tag

= otag} | otag imptag →≦ let (MkCont cfn) = fn (inIn

t mrslt) in cfn vms _ →

error “Verify error: Illeagal method invocatio

n”)

Page 11: Survey: A Compositional Account of the Java Virtual Machine

Static Semantics of μJVM はじめに

– 型システムを用いて何をしようとしているのか。 クラスの継承関係の表現

– クラスの継承関係をどのように型を用いて表現するのか。

microinstruction の型付け– microinstruction に型を付ける。

Page 12: Survey: A Compositional Account of the Java Virtual Machine

はじめに スタックの初期状態( vms )の型

– vms :: VMState s0 スタックに Int を Push する関数( f1 )の型

– f1:: VMState s → VMState (Int, s) スタックから Int を Pop する関数( f2 )の型

– f2:: VMState (Int, s) → VMState s スタックから Float を Pop する関数( f3 )の

型– f3:: VMState (Float, s) → VMState s

f2 (f1 vms) OKf3 (f1 vms) 型エラー

5

27

(Int,Int,Int,())

Page 13: Survey: A Compositional Account of the Java Virtual Machine

クラスの継承関係の表現

A

B C

D

classA::TAclassB::TBclassC::TCclassD::TD

TA = JClass ((T, T, T, T), (a, b, c, d))

TB = JClass ((a, T, c, T), (F, b, F, d))

TC = JClass ((a, b, T, T), (F, F, c, d))

TD =JClass ((a, b, c, T), (F, F, F, d))

Page 14: Survey: A Compositional Account of the Java Virtual Machine

クラスの継承関係の表現

A

B C

D TX = JClass (X+, X-)

TY = JClass (Y+, Y-)

X が Y の Super class である。

⇔ X- ~ Y+

A = (a, b, c, d), B = (a, T, c, T)

A ~ B ⇔ ( 定義 )

A = (a, b, c, d) → (a, T, c, T)

B = (a, T, c, T) → (a, T, c, T)

Page 15: Survey: A Compositional Account of the Java Virtual Machine

クラスの継承関係の表現

wantClassB :: [ClassB の subclass] → Int

wantClassB :: JClass ((F, b, F, d), n) → IntclassA :: JClass ((T, T, T, T), (a, b, c, d))classB :: JClass ((a, T, c, T), (F, b, F, d))classC :: JClass ((a, b, T, T), (F, F, c, d))classD :: JClass ((a, b, c, T), (F, F, F, d))

wantClassB classA 型エラーwantClassB classB OKwantClassB classC 型エラーwantClassB classD OK

Page 16: Survey: A Compositional Account of the Java Virtual Machine

クラスの継承関係の表現

wantInherit :: [superclass] → [subclass] → Int

wantClassB :: JClass (m, n) → JClass (n, o) → IntclassA :: JClass ((T, T, T, T), (a, b, c, d))classB :: JClass ((a, T, c, T), (F, b, F, d))classC :: JClass ((a, b, T, T), (F, F, c, d))classD :: JClass ((a, b, c, T), (F, F, F, d))

wantClassB classA classB OKwantClassB classB classC 型エラー

Page 17: Survey: A Compositional Account of the Java Virtual Machine

microinstruction の型付け

pushs :: Word t → Cont ((Word t), s) l h → Cont s l h call :: Method n m → Word(WRef-,(m,(h, h’)))

→ (Word(WInt+,ch) → Cont s l (Heap h’)) → Cont s l (Heap h)

型付けの例

Page 18: Survey: A Compositional Account of the Java Virtual Machine

Bytecode 補助関数

– load l tst k = getl l $ λw.pushs (tst w) $ k– pInt w = inInt(outInt w)

Bytecode– iload l = load l pInt– invoke meth k = pops $ λw.call meth w $

λw’.pushs w’ $ k

Page 19: Survey: A Compositional Account of the Java Virtual Machine

Bytecode 補助関数

– new alloc site cls k = alloc site cls $ λl . pushs l $ k– new1 = new allocate site1– constr k = pops $ λl. initialize l k– retn pr = pops $ λv. result (pr v)– ireturn = retn outInt

Bytecode– p1 = new1 classD $ dup $ constr $

invokemethodB $ ireturn

– result = evaluate p1

Page 20: Survey: A Compositional Account of the Java Virtual Machine

μJVM の健全性

M := c | x | m1 m2 | λx.m | let x = m1 in m2

e := evaluate m | let x = m in e

∀e : closed

┣ e ⇒ 【 e 】 ≠ VError

Page 21: Survey: A Compositional Account of the Java Virtual Machine

関連研究

Qian: – A Formal specification of Java Virtual Machine   i

nstructions for objects, methods and subroutines. (http://www.informatik.uni-bremen.de/~qian/abs-fsjvm.html)

– 本研究と同様に JVM の dynamic な側面と staticな側面を別々に扱っている。

– 本研究とは違い dynamic 及び static behavior を記述するのに operational semantics を用いている。

Page 22: Survey: A Compositional Account of the Java Virtual Machine

関連研究

Stata, Abadi:– A type system for Java bytecode subroutines.

Freund, Mitchell:– A Type System for Object Initialization in the Java

Bytecode Language.

– これらの研究は Qian の研究や本研究と違い JVM仕様の一部分に焦点を当てたものである。

Page 23: Survey: A Compositional Account of the Java Virtual Machine

関連研究

Saraswat:– The Java bytecode verification problem. (http://ww

w.research.att.com/~vj/)

Hagiya, Tozawa:– On a new method for dataflow analysis of Java Virt

ual Machine subroutines. (http://nicosia.is.s.u-tokyo.ac.jp/members/hagiya.html)

– これらの研究はデータフロー解析を用いて Bytecode verification を行っている。

Page 24: Survey: A Compositional Account of the Java Virtual Machine

関連研究

Jones:– The functions of the Java bytecode.

– 本研究と同様な手法を用いた研究で、本研究とは独立にほぼ同時期に発表されている。

– 本研究と違い、拡張された HASKELL の TYPE SYSTEM を用いている。