| author | paulson | 
| Mon, 09 Jan 2006 13:29:08 +0100 | |
| changeset 18625 | 2db0982523fe | 
| parent 16417 | 9bc16273c2d4 | 
| child 26453 | 758c6fef7b94 | 
| permissions | -rw-r--r-- | 
| 8011 | 1 | (* Title: HOL/MicroJava/BV/BVSpec.thy | 
| 2 | ID: $Id$ | |
| 12516 | 3 | Author: Cornelia Pusch, Gerwin Klein | 
| 8011 | 4 | Copyright 1999 Technische Universitaet Muenchen | 
| 5 | ||
| 6 | *) | |
| 7 | ||
| 12911 | 8 | header {* \isaheader{The Bytecode Verifier}\label{sec:BVSpec} *}
 | 
| 9757 
1024a2d80ac0
functional LBV style, dead code, type safety -> Isar
 kleing parents: 
9559diff
changeset | 9 | |
| 16417 | 10 | theory BVSpec imports Effect begin | 
| 12516 | 11 | |
| 12 | text {*
 | |
| 13 | This theory contains a specification of the BV. The specification | |
| 14 | describes correct typings of method bodies; it corresponds | |
| 15 |   to type \emph{checking}.
 | |
| 16 | *} | |
| 8011 | 17 | |
| 18 | constdefs | |
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 19 | -- "The program counter will always be inside the method:" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 20 | check_bounded :: "instr list \<Rightarrow> exception_table \<Rightarrow> bool" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 21 | "check_bounded ins et \<equiv> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 22 | (\<forall>pc < length ins. \<forall>pc' \<in> set (succs (ins!pc) pc). pc' < length ins) \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 23 | (\<forall>e \<in> set et. fst (snd (snd e)) < length ins)" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 24 | |
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 25 | -- "The method type only contains declared classes:" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 26 | check_types :: "jvm_prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> state list \<Rightarrow> bool" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 27 | "check_types G mxs mxr phi \<equiv> set phi \<subseteq> states G mxs mxr" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 28 | |
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 29 | -- "An instruction is welltyped if it is applicable and its effect" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 30 | -- "is compatible with the type at all successor instructions:" | 
| 12516 | 31 | wt_instr :: "[instr,jvm_prog,ty,method_type,nat,p_count, | 
| 13006 | 32 | exception_table,p_count] \<Rightarrow> bool" | 
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 33 | "wt_instr i G rT phi mxs max_pc et pc \<equiv> | 
| 12516 | 34 | app i G mxs rT pc et (phi!pc) \<and> | 
| 35 | (\<forall>(pc',s') \<in> set (eff i G pc et (phi!pc)). pc' < max_pc \<and> G \<turnstile> s' <=' phi!pc')" | |
| 9549 
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
 kleing parents: 
9376diff
changeset | 36 | |
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 37 |   -- {* The type at @{text "pc=0"} conforms to the method calling convention: *}
 | 
| 13006 | 38 | wt_start :: "[jvm_prog,cname,ty list,nat,method_type] \<Rightarrow> bool" | 
| 12516 | 39 | "wt_start G C pTs mxl phi == | 
| 40 | G \<turnstile> Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err)) <=' phi!0" | |
| 8011 | 41 | |
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 42 | -- "A method is welltyped if the body is not empty, if execution does not" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 43 | -- "leave the body, if the method type covers all instructions and mentions" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 44 | -- "declared classes only, if the method calling convention is respected, and" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 45 | -- "if all instructions are welltyped." | 
| 12516 | 46 | wt_method :: "[jvm_prog,cname,ty list,ty,nat,nat,instr list, | 
| 13006 | 47 | exception_table,method_type] \<Rightarrow> bool" | 
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 48 | "wt_method G C pTs rT mxs mxl ins et phi \<equiv> | 
| 12516 | 49 | let max_pc = length ins in | 
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 50 | 0 < max_pc \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 51 | length phi = length ins \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 52 | check_bounded ins et \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 53 | check_types G mxs (1+length pTs+mxl) (map OK phi) \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 54 | wt_start G C pTs mxl phi \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 55 | (\<forall>pc. pc<max_pc \<longrightarrow> wt_instr (ins!pc) G rT phi mxs max_pc et pc)" | 
| 8011 | 56 | |
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 57 | -- "A program is welltyped if it is wellformed and all methods are welltyped" | 
| 13006 | 58 | wt_jvm_prog :: "[jvm_prog,prog_type] \<Rightarrow> bool" | 
| 12516 | 59 | "wt_jvm_prog G phi == | 
| 60 | wf_prog (\<lambda>G C (sig,rT,(maxs,maxl,b,et)). | |
| 61 | wt_method G C (snd sig) rT maxs maxl b et (phi C sig)) G" | |
| 9559 | 62 | |
| 63 | ||
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 64 | lemma check_boundedD: | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 65 | "\<lbrakk> check_bounded ins et; pc < length ins; | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 66 | (pc',s') \<in> set (eff (ins!pc) G pc et s) \<rbrakk> \<Longrightarrow> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 67 | pc' < length ins" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 68 | apply (unfold eff_def) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 69 | apply simp | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 70 | apply (unfold check_bounded_def) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 71 | apply clarify | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 72 | apply (erule disjE) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 73 | apply blast | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 74 | apply (erule allE, erule impE, assumption) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 75 | apply (unfold xcpt_eff_def) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 76 | apply clarsimp | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 77 | apply (drule xcpt_names_in_et) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 78 | apply clarify | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 79 | apply (drule bspec, assumption) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 80 | apply simp | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 81 | done | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 82 | |
| 9549 
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
 kleing parents: 
9376diff
changeset | 83 | lemma wt_jvm_progD: | 
| 13006 | 84 | "wt_jvm_prog G phi \<Longrightarrow> (\<exists>wt. wf_prog wt G)" | 
| 12516 | 85 | by (unfold wt_jvm_prog_def, blast) | 
| 9549 
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
 kleing parents: 
9376diff
changeset | 86 | |
| 10629 | 87 | lemma wt_jvm_prog_impl_wt_instr: | 
| 13006 | 88 | "\<lbrakk> wt_jvm_prog G phi; is_class G C; | 
| 89 | method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); pc < length ins \<rbrakk> | |
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 90 | \<Longrightarrow> wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc" | 
| 12516 | 91 | by (unfold wt_jvm_prog_def, drule method_wf_mdecl, | 
| 92 | simp, simp, simp add: wf_mdecl_def wt_method_def) | |
| 9549 
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
 kleing parents: 
9376diff
changeset | 93 | |
| 13214 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 94 | text {*
 | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 95 |   We could leave out the check @{term "pc' < max_pc"} in the 
 | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 96 |   definition of @{term wt_instr} in the context of @{term wt_method}.
 | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 97 | *} | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 98 | lemma wt_instr_def2: | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 99 | "\<lbrakk> wt_jvm_prog G Phi; is_class G C; | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 100 | method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); pc < length ins; | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 101 | i = ins!pc; phi = Phi C sig; max_pc = length ins \<rbrakk> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 102 | \<Longrightarrow> wt_instr i G rT phi maxs max_pc et pc = | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 103 | (app i G maxs rT pc et (phi!pc) \<and> | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 104 | (\<forall>(pc',s') \<in> set (eff i G pc et (phi!pc)). G \<turnstile> s' <=' phi!pc'))" | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 105 | apply (simp add: wt_instr_def) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 106 | apply (unfold wt_jvm_prog_def) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 107 | apply (drule method_wf_mdecl) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 108 | apply (simp, simp, simp add: wf_mdecl_def wt_method_def) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 109 | apply (auto dest: check_boundedD) | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 110 | done | 
| 
2aa33ed5f526
wt_method now checks bounded+types ==> wt_kildall <=> wt_method
 kleing parents: 
13006diff
changeset | 111 | |
| 10629 | 112 | lemma wt_jvm_prog_impl_wt_start: | 
| 13006 | 113 | "\<lbrakk> wt_jvm_prog G phi; is_class G C; | 
| 114 | method (G,C) sig = Some (C,rT,maxs,maxl,ins,et) \<rbrakk> \<Longrightarrow> | |
| 12516 | 115 | 0 < (length ins) \<and> wt_start G C (snd sig) maxl (phi C sig)" | 
| 116 | by (unfold wt_jvm_prog_def, drule method_wf_mdecl, | |
| 117 | simp, simp, simp add: wf_mdecl_def wt_method_def) | |
| 9549 
40d64cb4f4e6
BV and LBV specified in terms of app and step functions
 kleing parents: 
9376diff
changeset | 118 | |
| 8011 | 119 | end |