Verification of a Java Compiler in Isabelle Martin Strecker - - PowerPoint PPT Presentation

verification of a java compiler in isabelle
SMART_READER_LITE
LIVE PREVIEW

Verification of a Java Compiler in Isabelle Martin Strecker - - PowerPoint PPT Presentation

Verification of a Java Compiler in Isabelle Martin Strecker 7.1.2002 Java: Types, values, terms, ... Typing and operational semantics JVM Compiler Definition Proof Techniques Compilation and Bytecode Verification


slide-1
SLIDE 1

Verification of a Java Compiler in Isabelle

Martin Strecker 7.1.2002

  • Java:

– Types, values, terms, ... – Typing and operational semantics

  • JVM
  • Compiler

– Definition – Proof Techniques

  • Compilation and Bytecode Verification

VerifiCard, Marseille 7.1.2002

slide-2
SLIDE 2

1

Java and Isabelle-Java

− Num. types − Garbage collection − Threads − Interfaces − Arrays Compiler

Java µ JVM µ Java JVM Bali Source Byte− code language

VerifiCard, Marseille 7.1.2002

slide-3
SLIDE 3

2

Java: Types, Values, Terms (1)

... defined as inductive data types: Types: datatype prim_ty = Void | Boolean | Integer datatype ref_ty = NullT | ClassT cname datatype ty = PrimT prim_ty | RefT ref_ty Values: datatype val = Unit | Bool bool | Intg int | Null | Addr loc

  • No interfaces / arrays
  • Only numeric type: Integer

VerifiCard, Marseille 7.1.2002

slide-4
SLIDE 4

3

Java: Types, Values, Terms (2)

Terms: datatype expr = ... | NewC cname | vname ::= expr | {cname} expr . vname ::= expr | BinOp binop expr expr | {cname} expr . mname {(ty) list} (expr) list datatype stmt = ... | Expr expr | If (expr) stmt Else stmt | Throw expr Method Call: Annotation a2 . m(a3, c) = ⇒ {A2} a2 . m({ [A1, C] } [a3, c])

VerifiCard, Marseille 7.1.2002

slide-5
SLIDE 5

4

Java: Methods, Classes, Programs

Class name Superclass name

... ... ... ... ... ... ... ...

mdecl fdecl vname ty java_mb ty ty list mname

java mb = vname list × (vname × ty) list × stmt × expr mdecl = mname × ty list × ty × java mb

VerifiCard, Marseille 7.1.2002

slide-6
SLIDE 6

5

Java / JVM: Methods, Classes, Programs

mkMethod Class name Superclass name

... ... ... ... ... ... ... ...

Compiler vname ty mname ty list jvm_mb ty Class name Superclass name

... ... ... ... ... ... ... ...

mdecl fdecl vname ty java_mb ty ty list mname

java mb = vname list × (vname × ty) list × stmt × expr jvm mb = nat × nat × bytecode ’c mdecl = mname × ty list × ty × ’c ’c cdecl = cname × cname × fdecl list × ’c mdecl list

VerifiCard, Marseille 7.1.2002

slide-7
SLIDE 7

6

Java: Typing

Inductively defined judgements

  • Expressions: E ⊢ e ::E T
  • Statements: E ⊢ s ::S √

with environment E: java mb env = java mb prog × lenv

VerifiCard, Marseille 7.1.2002

slide-8
SLIDE 8

7

Java: Operational Semantics

State σ : xstate = xcpt option × heap × locals Evaluation

  • of expressions: Γ ⊢ (σ, e) −

→E (v, σ′)

  • of statements: Γ ⊢ (σ, s) −

→S σ′ with program Γ: java mb prog = ⇒ big step (“natural”) semantics Type Safety Evaluation transforms state σ conforming to E to state σ′ again conforming to E.

VerifiCard, Marseille 7.1.2002

slide-9
SLIDE 9

8

JVM: Instructions

datatype instr = Load nat | Store nat | LitPush val | New cname | Getfield vname cname | Putfield vname cname | Checkcast cname | Invoke cname mname (ty list) | Return | Pop | Dup | Dup_x1 | Dup_x2 | Swap | IAdd | Goto int | Ifcmpeq int bytecode = instr list

VerifiCard, Marseille 7.1.2002

slide-10
SLIDE 10

9

JVM: State and Operational Semantics

State datatype jvm state = xcpt option × heap × frame list frame = opstack × locvars × cname × sig × nat Operational Semantics

  • One-step execution relation:

exec_instr (Load idx) G hp stk vars Cl sig pc frs = (None, hp, ((vars ! idx) # stk, vars, Cl, sig, pc+1)#frs)

  • Execution exec all as transitive closure

VerifiCard, Marseille 7.1.2002

slide-11
SLIDE 11

10

Compiler: Definition (1)

mkExpr :: java mb => expr => bytecode mkStmt :: java mb => stmt => bytecode mkExpr jmb (vn::=e) = mkExpr jmb e @ [Dup , Store (index jmb vn)] mkExpr jmb ({cn}e1.mn {Ts}(ps)) = mkExpr jmb e1 @ mkExprs jmb ps @ [Invoke cn mn Ts] mkStmt jmb (c1;; c2) = (mkStmt jmb c1) @ (mkStmt jmb c2)

VerifiCard, Marseille 7.1.2002

slide-12
SLIDE 12

11

Compiler: Definition (2)

mkMethod :: java mb => nat * nat * bytecode mkMethod jmb == let (params,locals,blk,res) = jmb in (max_ssize jmb blk res, length locals, concat (map (mkInit jmb) locals) @ mkStmt jmb blk @ mkExpr jmb res @ [Return])

VerifiCard, Marseille 7.1.2002

slide-13
SLIDE 13

12

Compiler: Correctness Statement

Assumption (preliminary): No exceptions during evaluation Correctness (for expressions):

E

... ...

e mkExpr (xc, hp, lvars) e (xc’, hp’, lvars’) v (hp, os, lvars, pc) = =? exec_all v (hp’, # os, lvars’, pc’)

Statements: similar

VerifiCard, Marseille 7.1.2002

slide-14
SLIDE 14

13

Verification: Preconditions

Remember: Current environment (Γ, Λ) given by:

  • Current program Γ
  • locals Λ of current method (identified by class C and signature S)

Preconditions:

  • Γ is well-formed
  • C and S are defined in Γ
  • State (xc, hp, lvars) conforms to environment (Γ, Λ)
  • Expression e is well-typed: ∃T.(Γ, Λ) ⊢ e ::E T

❀ Correctness statement for “reasonable” programs only

VerifiCard, Marseille 7.1.2002

slide-15
SLIDE 15

14

Proof Techniques

Proof: Induction over evaluation relation:

  • Propagate assumptions, e.g.: conformance (requires Type Safety)
  • Apply induction hypotheses
  • Evaluate symbolically

E E # os ?v1 ?v2 # ?v1# os (xc, hp, lvars) e1 + e2 = (xc’, hp’, lvars’) v =? e1 ?v1 e2 ?v2 E (hp, os, lvars, pc) exec_all (hp’, # os, lvars’, pc’) v

VerifiCard, Marseille 7.1.2002

slide-16
SLIDE 16

15

Compilation and Bytecode Verification

Bool ST Bool Bool ST mkStmt (If (e) c1 Else c2) c2 Goto Push False e c1 Ifcmpeq ST ST ST ST ST mkStTpStmt (If (e) c1 Else c2)

mkStTpStmt :: java mb => stmt => statetype list mkStmt :: java mb => stmt => bytecode

VerifiCard, Marseille 7.1.2002

slide-17
SLIDE 17

16

Summary

Formalization

  • Contains most essentials, some details missing
  • Few Isabelle specifics ❀ transferable to other environments

Compiler

  • Translation of method bodies; no data refinements, no optimizations (which?)
  • Object-orientation of minor importance
  • Executable (extraction of ML code), easy to produce “real” class files
  • Big step semantics leads to concise correctness statement

VerifiCard, Marseille 7.1.2002

slide-18
SLIDE 18

17

To do

  • Integrate exceptions
  • Compilation and bytecode verification
  • Streamline proofs
  • Tackle larger language fragments

VerifiCard, Marseille 7.1.2002