verification of a java compiler in isabelle
play

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


  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

  2. 1 Java and Isabelle-Java Java Source − Threads Bali language − Garbage collection − Num. types − Interfaces µ Java − Arrays Compiler Byte− µ JVM code JVM VerifiCard, Marseille 7.1.2002

  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

  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 m(a 3 , c) = ⇒ { A 2 } a 2 . m( { [A 1 , C] } [a 3 , c]) a 2 . VerifiCard, Marseille 7.1.2002

  5. 4 Java: Methods, Classes, Programs Class name Superclass name vname ty ... ... fdecl ... ... mname ty list ty java_mb mdecl ... ... ... ... java mb = vname list × (vname × ty) list × stmt × expr mdecl = mname × ty list × ty × java mb VerifiCard, Marseille 7.1.2002

  6. 5 Java / JVM: Methods, Classes, Programs Class name Class name Superclass name Superclass name Compiler vname ty vname ty ... ... ... ... fdecl ... ... ... ... mkMethod mname ty list ty java_mb mname ty list ty jvm_mb mdecl ... ... ... ... ... ... ... ... java mb = jvm mb = vname list × (vname × ty) list nat × nat × bytecode × stmt × expr ’c mdecl = mname × ty list × ty × ’c ’c cdecl = cname × cname × fdecl list × ’c mdecl list VerifiCard, Marseille 7.1.2002

  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

  8. 7 Java: Operational Semantics State σ : xstate = xcpt option × heap × locals Evaluation • of expressions: Γ ⊢ ( σ, e ) − → E ( v, σ ′ ) → S σ ′ • of statements: Γ ⊢ ( σ, 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

  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

  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

  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

  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

  13. 12 Compiler: Correctness Statement Assumption (preliminary): No exceptions during evaluation Correctness (for expressions): (xc, hp, lvars) e (xc’, hp’, lvars’) v E = =? exec_all (hp, os, lvars, pc) (hp’, # os, lvars’, pc’) v ... ... mkExpr e Statements: similar VerifiCard, Marseille 7.1.2002

  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

  15. 14 Proof Techniques Proof: Induction over evaluation relation: • Propagate assumptions, e.g.: conformance (requires Type Safety) • Apply induction hypotheses • Evaluate symbolically (xc, hp, lvars) e1 + e2 E (xc’, hp’, lvars’) v e1 ?v1 e2 ?v2 E E =? = ?v1 # os ?v2 # ?v1# os (hp’, # os, lvars’, pc’) v (hp, os, lvars, pc) exec_all VerifiCard, Marseille 7.1.2002

  16. 15 Compilation and Bytecode Verification mkStTpStmt (If (e) c1 Else c2) Bool Bool Bool ST ST ST ST ST ST ST Push False e Ifcmpeq c1 Goto c2 mkStmt (If (e) c1 Else c2) mkStTpStmt :: java mb => stmt => statetype list mkStmt :: java mb => stmt => bytecode VerifiCard, Marseille 7.1.2002

  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

  18. 17 To do • Integrate exceptions • Compilation and bytecode verification • Streamline proofs • Tackle larger language fragments VerifiCard, Marseille 7.1.2002

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend