src/HOL/MicroJava/BV/BVSpecTypeSafe.thy
author kleing
Tue, 26 Feb 2002 15:45:32 +0100
changeset 12951 a9fdcb71d252
parent 12911 704713ca07ea
child 13006 51c5f3f11d16
permissions -rw-r--r--
introduces SystemClasses and BVExample
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/BVSpecTypeSafe.thy
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     2
    ID:         $Id$
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
     3
    Author:     Cornelia Pusch, Gerwin Klein
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     4
    Copyright   1999 Technische Universitaet Muenchen
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     5
*)
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     6
12911
704713ca07ea new document
kleing
parents: 12545
diff changeset
     7
header {* \isaheader{BV Type Safety Proof}\label{sec:BVSpecTypeSafe} *}
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
     8
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
     9
theory BVSpecTypeSafe = Correct:
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    10
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    11
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    12
  This theory contains proof that the specification of the bytecode
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    13
  verifier only admits type safe programs.  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    14
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    15
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    16
section {* Preliminaries *}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    17
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    18
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    19
  Simp and intro setup for the type safety proof:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    20
*}
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
    21
lemmas defs1 = sup_state_conv correct_state_def correct_frame_def 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    22
               wt_instr_def eff_def norm_eff_def 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
    23
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
    24
lemmas widen_rules[intro] = approx_val_widen approx_loc_widen approx_stk_widen
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
    25
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    26
lemmas [simp del] = split_paired_All
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    27
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    28
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    29
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    30
  If we have a welltyped program and a conforming state, we
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    31
  can directly infer that the current instruction is well typed:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    32
*}
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    33
lemma wt_jvm_prog_impl_wt_instr_cor:
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    34
  "[| wt_jvm_prog G phi; method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
    35
      G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    36
  ==> wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    37
apply (unfold correct_state_def Let_def correct_frame_def)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    38
apply simp
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    39
apply (blast intro: wt_jvm_prog_impl_wt_instr)
9819
wenzelm
parents: 9757
diff changeset
    40
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
    41
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    42
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    43
section {* Exception Handling *}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    44
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    45
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    46
  Exceptions don't touch anything except the stack:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    47
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    48
lemma exec_instr_xcpt:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    49
  "(fst (exec_instr i G hp stk vars Cl sig pc frs) = Some xcp)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    50
  = (\<exists>stk'. exec_instr i G hp stk vars Cl sig pc frs = 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    51
            (Some xcp, hp, (stk', vars, Cl, sig, pc)#frs))"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    52
  by (cases i, auto simp add: split_beta split: split_if_asm)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    53
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    54
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    55
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    56
  Relates @{text match_any} from the Bytecode Verifier with 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    57
  @{text match_exception_table} from the operational semantics:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    58
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    59
lemma in_match_any:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    60
  "match_exception_table G xcpt pc et = Some pc' ==> 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    61
  \<exists>C. C \<in> set (match_any G pc et) \<and> G \<turnstile> xcpt \<preceq>C C \<and> 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    62
      match_exception_table G C pc et = Some pc'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    63
  (is "PROP ?P et" is "?match et ==> ?match_any et")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    64
proof (induct et)  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    65
  show "PROP ?P []" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    66
    by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    67
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    68
  fix e es
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    69
  assume IH: "PROP ?P es"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    70
  assume match: "?match (e#es)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    71
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    72
  obtain start_pc end_pc handler_pc catch_type where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    73
    e [simp]: "e = (start_pc, end_pc, handler_pc, catch_type)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    74
    by (cases e) 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    75
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    76
  from IH match
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    77
  show "?match_any (e#es)" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    78
  proof (cases "match_exception_entry G xcpt pc e")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    79
    case False
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    80
    with match
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    81
    have "match_exception_table G xcpt pc es = Some pc'" by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    82
    with IH
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    83
    obtain C where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    84
      set: "C \<in> set (match_any G pc es)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    85
      C:   "G \<turnstile> xcpt \<preceq>C C" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    86
      m:   "match_exception_table G C pc es = Some pc'" by blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    87
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    88
    from set
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    89
    have "C \<in> set (match_any G pc (e#es))" by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    90
    moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    91
    from False C
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    92
    have "\<not> match_exception_entry G C pc e"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    93
      by - (erule contrapos_nn, 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    94
            auto simp add: match_exception_entry_def elim: rtrancl_trans)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    95
    with m
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    96
    have "match_exception_table G C pc (e#es) = Some pc'" by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    97
    moreover note C
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    98
    ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
    99
    show ?thesis by blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   100
  next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   101
    case True with match
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   102
    have "match_exception_entry G catch_type pc e"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   103
      by (simp add: match_exception_entry_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   104
    moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   105
    from True match
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   106
    obtain 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   107
      "start_pc \<le> pc" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   108
      "pc < end_pc" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   109
      "G \<turnstile> xcpt \<preceq>C catch_type" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   110
      "handler_pc = pc'" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   111
      by (simp add: match_exception_entry_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   112
    ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   113
    show ?thesis by auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   114
  qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   115
qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   116
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   117
lemma match_et_imp_match:
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   118
  "match_exception_table G X pc et = Some handler
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   119
  \<Longrightarrow> match G X pc et = [X]"
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   120
  apply (simp add: match_some_entry)
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   121
  apply (induct et)
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   122
  apply (auto split: split_if_asm)
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   123
  done
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   124
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   125
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   126
  We can prove separately that the recursive search for exception
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   127
  handlers (@{text find_handler}) in the frame stack results in 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   128
  a conforming state (if there was no matching exception handler 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   129
  in the current frame). We require that the exception is a valid
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   130
  heap address, and that the state before the exception occured
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   131
  conforms. 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   132
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   133
lemma uncaught_xcpt_correct:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   134
  "!!f. [| wt_jvm_prog G phi; xcp = Addr adr; hp adr = Some T;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   135
      G,phi \<turnstile>JVM (None, hp, f#frs)\<surd> |]
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   136
  ==> G,phi \<turnstile>JVM (find_handler G (Some xcp) hp frs)\<surd>" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   137
  (is "!!f. [| ?wt; ?adr; ?hp; ?correct (None, hp, f#frs) |] ==> ?correct (?find frs)")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   138
proof (induct frs) 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   139
  -- "the base case is trivial, as it should be"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   140
  show "?correct (?find [])" by (simp add: correct_state_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   141
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   142
  -- "we will need both forms @{text wt_jvm_prog} and @{text wf_prog} later"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   143
  assume wt: ?wt 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   144
  then obtain mb where wf: "wf_prog mb G" by (simp add: wt_jvm_prog_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   145
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   146
  -- "these two don't change in the induction:"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   147
  assume adr: ?adr
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   148
  assume hp: ?hp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   149
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   150
  -- "the assumption for the cons case:"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   151
  fix f f' frs' 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   152
  assume cr: "?correct (None, hp, f#f'#frs')" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   153
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   154
  -- "the induction hypothesis as produced by Isabelle, immediatly simplified
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   155
    with the fixed assumptions above"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   156
  assume "\<And>f. [| ?wt; ?adr; ?hp; ?correct (None, hp, f#frs') |] ==> ?correct (?find frs')"  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   157
  with wt adr hp 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   158
  have IH: "\<And>f. ?correct (None, hp, f#frs') ==> ?correct (?find frs')" by blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   159
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   160
  from cr
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   161
  have cr': "?correct (None, hp, f'#frs')" by (auto simp add: correct_state_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   162
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   163
  obtain stk loc C sig pc where f' [simp]: "f' = (stk,loc,C,sig,pc)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   164
    by (cases f') 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   165
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   166
  from cr 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   167
  obtain rT maxs maxl ins et where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   168
    meth: "method (G,C) sig = Some (C,rT,maxs,maxl,ins,et)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   169
    by (simp add: correct_state_def, blast)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   170
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   171
  hence [simp]: "ex_table_of (snd (snd (the (method (G, C) sig)))) = et"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   172
    by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   173
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   174
  show "?correct (?find (f'#frs'))" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   175
  proof (cases "match_exception_table G (cname_of hp xcp) pc et")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   176
    case None
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   177
    with cr' IH 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   178
    show ?thesis by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   179
  next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   180
    fix handler_pc 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   181
    assume match: "match_exception_table G (cname_of hp xcp) pc et = Some handler_pc"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   182
    (is "?match (cname_of hp xcp) = _")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   183
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   184
    from wt meth cr' [simplified]
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   185
    have wti: "wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   186
      by (rule wt_jvm_prog_impl_wt_instr_cor)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   187
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   188
    from cr meth
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   189
    obtain C' mn pts ST LT where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   190
      ins: "ins!pc = Invoke C' mn pts" (is "_ = ?i") and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   191
      phi: "phi C sig ! pc = Some (ST, LT)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   192
      by (simp add: correct_state_def) blast    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   193
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   194
    from match
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   195
    obtain D where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   196
      in_any: "D \<in> set (match_any G pc et)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   197
      D:      "G \<turnstile> cname_of hp xcp \<preceq>C D" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   198
      match': "?match D = Some handler_pc"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   199
      by (blast dest: in_match_any)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   200
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   201
    from ins wti phi have 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   202
      "\<forall>D\<in>set (match_any G pc et). the (?match D) < length ins \<and> 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   203
      G \<turnstile> Some ([Class D], LT) <=' phi C sig!the (?match D)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   204
      by (simp add: wt_instr_def eff_def xcpt_eff_def)      
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   205
    with in_any match' obtain
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   206
      pc: "handler_pc < length ins" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   207
      "G \<turnstile> Some ([Class D], LT) <=' phi C sig ! handler_pc"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   208
      by auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   209
    then obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   210
      phi': "phi C sig ! handler_pc = Some (ST',LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   211
      less: "G \<turnstile> ([Class D], LT) <=s (ST',LT')"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   212
      by auto    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   213
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   214
    from cr' phi meth f'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   215
    have "correct_frame G hp (ST, LT) maxl ins f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   216
      by (unfold correct_state_def) auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   217
    then obtain
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   218
     len: "length loc = 1+length (snd sig)+maxl" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   219
     loc: "approx_loc G hp loc LT"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   220
      by (unfold correct_frame_def) auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   221
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   222
    let ?f = "([xcp], loc, C, sig, handler_pc)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   223
    have "correct_frame G hp (ST', LT') maxl ins ?f" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   224
    proof -
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   225
      from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   226
      have "approx_loc G hp loc LT'" by (simp add: sup_state_conv) blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   227
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   228
      from D adr hp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   229
      have "G,hp \<turnstile> xcp ::\<preceq> Class D" by (simp add: conf_def obj_ty_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   230
      with wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   231
      have "approx_stk G hp [xcp] ST'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   232
        by (auto simp add: sup_state_conv approx_stk_def approx_val_def 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   233
                 elim: conf_widen split: Err.split)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   234
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   235
      note len pc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   236
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   237
      show ?thesis by (simp add: correct_frame_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   238
    qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   239
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   240
    with cr' match phi' meth  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   241
    show ?thesis by (unfold correct_state_def) auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   242
  qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   243
qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   244
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   245
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   246
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   247
  The requirement of lemma @{text uncaught_xcpt_correct} (that
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   248
  the exception is a valid reference on the heap) is always met
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   249
  for welltyped instructions and conformant states:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   250
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   251
lemma exec_instr_xcpt_hp:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   252
  "[|  fst (exec_instr (ins!pc) G hp stk vars Cl sig pc frs) = Some xcp;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   253
       wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   254
       G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |]
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   255
  ==> \<exists>adr T. xcp = Addr adr \<and> hp adr = Some T" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   256
  (is "[| ?xcpt; ?wt; ?correct |] ==> ?thesis")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   257
proof -
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   258
  note [simp] = split_beta raise_system_xcpt_def
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   259
  note [split] = split_if_asm option.split_asm 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   260
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   261
  assume wt: ?wt ?correct
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   262
  hence pre: "preallocated hp" by (simp add: correct_state_def)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   263
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   264
  assume xcpt: ?xcpt with pre show ?thesis 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   265
  proof (cases "ins!pc")
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   266
    case New with xcpt pre
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   267
    show ?thesis by (auto dest: new_Addr_OutOfMemory) 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   268
  next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   269
    case Throw with xcpt wt
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   270
    show ?thesis
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   271
      by (auto simp add: wt_instr_def correct_state_def correct_frame_def 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   272
               dest: non_npD)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   273
  qed auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   274
qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   275
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   276
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   277
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   278
  Finally we can state that, whenever an exception occurs, the
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   279
  resulting next state always conforms:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   280
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   281
lemma xcpt_correct:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   282
  "[| wt_jvm_prog G phi;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   283
      method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   284
      wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   285
      fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = Some xcp; 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   286
      Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs); 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   287
      G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   288
  ==> G,phi \<turnstile>JVM state'\<surd>"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   289
proof -
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   290
  assume wtp: "wt_jvm_prog G phi"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   291
  assume meth: "method (G,C) sig = Some (C,rT,maxs,maxl,ins,et)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   292
  assume wt: "wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   293
  assume xp: "fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = Some xcp"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   294
  assume s': "Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   295
  assume correct: "G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   296
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   297
  from wtp obtain wfmb where wf: "wf_prog wfmb G" by (simp add: wt_jvm_prog_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   298
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   299
  note xp' = meth s' xp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   300
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   301
  note wtp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   302
  moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   303
  from xp wt correct
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   304
  obtain adr T where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   305
    adr: "xcp = Addr adr" "hp adr = Some T"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   306
    by (blast dest: exec_instr_xcpt_hp)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   307
  moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   308
  note correct
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   309
  ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   310
  have "G,phi \<turnstile>JVM find_handler G (Some xcp) hp frs \<surd>" by (rule uncaught_xcpt_correct)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   311
  with xp'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   312
  have "match_exception_table G (cname_of hp xcp) pc et = None \<Longrightarrow> ?thesis" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   313
    (is "?m (cname_of hp xcp) = _ \<Longrightarrow> _" is "?match = _ \<Longrightarrow> _")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   314
    by (clarsimp simp add: exec_instr_xcpt split_beta)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   315
  moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   316
  { fix handler
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   317
    assume some_handler: "?match = Some handler"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   318
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   319
    from correct meth
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   320
    obtain ST LT where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   321
      hp_ok:  "G \<turnstile>h hp \<surd>" and
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   322
      prehp:  "preallocated hp" and
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   323
      class:  "is_class G C" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   324
      phi_pc: "phi C sig ! pc = Some (ST, LT)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   325
      frame:  "correct_frame G hp (ST, LT) maxl ins (stk, loc, C, sig, pc)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   326
      frames: "correct_frames G hp phi rT sig frs"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   327
      by (unfold correct_state_def) auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   328
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   329
    from frame obtain 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   330
      stk: "approx_stk G hp stk ST" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   331
      loc: "approx_loc G hp loc LT" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   332
      pc:  "pc < length ins" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   333
      len: "length loc = 1+length (snd sig)+maxl"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   334
      by (unfold correct_frame_def) auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   335
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   336
    from wt obtain
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   337
      eff: "\<forall>(pc', s')\<in>set (xcpt_eff (ins!pc) G pc (phi C sig!pc) et).
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   338
             pc' < length ins \<and> G \<turnstile> s' <=' phi C sig!pc'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   339
      by (simp add: wt_instr_def eff_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   340
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   341
    from some_handler xp'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   342
    have state': 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   343
      "state' = (None, hp, ([xcp], loc, C, sig, handler)#frs)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   344
      by (cases "ins!pc", auto simp add: raise_system_xcpt_def split_beta 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   345
                               split: split_if_asm) (* takes long! *)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   346
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   347
    let ?f' = "([xcp], loc, C, sig, handler)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   348
    from eff
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   349
    obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   350
      phi_pc': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   351
      frame': "correct_frame G hp (ST',LT') maxl ins ?f'" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   352
    proof (cases "ins!pc")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   353
      case Return -- "can't generate exceptions:"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   354
      with xp' have False by (simp add: split_beta split: split_if_asm)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   355
      thus ?thesis ..
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   356
    next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   357
      case New
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   358
      with some_handler xp'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   359
      have xcp: "xcp = Addr (XcptRef OutOfMemory)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   360
        by (simp add: raise_system_xcpt_def split_beta new_Addr_OutOfMemory)
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   361
      with prehp have "cname_of hp xcp = Xcpt OutOfMemory" by simp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   362
      with New some_handler phi_pc eff 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   363
      obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   364
        phi': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   365
        less: "G \<turnstile> ([Class (Xcpt OutOfMemory)], LT) <=s (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   366
        pc':  "handler < length ins"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   367
        by (simp add: xcpt_eff_def match_et_imp_match) blast
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   368
      note phi'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   369
      moreover
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   370
      { from xcp prehp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   371
        have "G,hp \<turnstile> xcp ::\<preceq> Class (Xcpt OutOfMemory)"
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   372
          by (simp add: conf_def obj_ty_def)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   373
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   374
        from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   375
        have "approx_loc G hp loc LT'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   376
          by (simp add: sup_state_conv) blast        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   377
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   378
        note wf less pc' len 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   379
        ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   380
        have "correct_frame G hp (ST',LT') maxl ins ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   381
          by (unfold correct_frame_def) (auto simp add: sup_state_conv 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   382
              approx_stk_def approx_val_def split: err.split elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   383
      }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   384
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   385
      show ?thesis by (rule that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   386
    next 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   387
      case Getfield
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   388
      with some_handler xp'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   389
      have xcp: "xcp = Addr (XcptRef NullPointer)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   390
        by (simp add: raise_system_xcpt_def split_beta split: split_if_asm)
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   391
      with prehp have "cname_of hp xcp = Xcpt NullPointer" by simp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   392
      with Getfield some_handler phi_pc eff 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   393
      obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   394
        phi': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   395
        less: "G \<turnstile> ([Class (Xcpt NullPointer)], LT) <=s (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   396
        pc':  "handler < length ins"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   397
        by (simp add: xcpt_eff_def match_et_imp_match) blast
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   398
      note phi'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   399
      moreover
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   400
      { from xcp prehp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   401
        have "G,hp \<turnstile> xcp ::\<preceq> Class (Xcpt NullPointer)"
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   402
          by (simp add: conf_def obj_ty_def)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   403
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   404
        from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   405
        have "approx_loc G hp loc LT'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   406
          by (simp add: sup_state_conv) blast        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   407
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   408
        note wf less pc' len 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   409
        ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   410
        have "correct_frame G hp (ST',LT') maxl ins ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   411
          by (unfold correct_frame_def) (auto simp add: sup_state_conv 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   412
              approx_stk_def approx_val_def split: err.split elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   413
      }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   414
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   415
      show ?thesis by (rule that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   416
    next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   417
      case Putfield
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   418
      with some_handler xp'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   419
      have xcp: "xcp = Addr (XcptRef NullPointer)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   420
        by (simp add: raise_system_xcpt_def split_beta split: split_if_asm)
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   421
      with prehp have "cname_of hp xcp = Xcpt NullPointer" by simp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   422
      with Putfield some_handler phi_pc eff 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   423
      obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   424
        phi': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   425
        less: "G \<turnstile> ([Class (Xcpt NullPointer)], LT) <=s (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   426
        pc':  "handler < length ins"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   427
        by (simp add: xcpt_eff_def match_et_imp_match) blast
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   428
      note phi'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   429
      moreover
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   430
      { from xcp prehp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   431
        have "G,hp \<turnstile> xcp ::\<preceq> Class (Xcpt NullPointer)"
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   432
          by (simp add: conf_def obj_ty_def)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   433
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   434
        from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   435
        have "approx_loc G hp loc LT'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   436
          by (simp add: sup_state_conv) blast        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   437
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   438
        note wf less pc' len 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   439
        ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   440
        have "correct_frame G hp (ST',LT') maxl ins ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   441
          by (unfold correct_frame_def) (auto simp add: sup_state_conv 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   442
              approx_stk_def approx_val_def split: err.split elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   443
      }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   444
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   445
      show ?thesis by (rule that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   446
    next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   447
      case Checkcast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   448
      with some_handler xp'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   449
      have xcp: "xcp = Addr (XcptRef ClassCast)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   450
        by (simp add: raise_system_xcpt_def split_beta split: split_if_asm)
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   451
      with prehp have "cname_of hp xcp = Xcpt ClassCast" by simp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   452
      with Checkcast some_handler phi_pc eff 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   453
      obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   454
        phi': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   455
        less: "G \<turnstile> ([Class (Xcpt ClassCast)], LT) <=s (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   456
        pc':  "handler < length ins"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   457
        by (simp add: xcpt_eff_def match_et_imp_match) blast
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   458
      note phi'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   459
      moreover
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   460
      { from xcp prehp
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   461
        have "G,hp \<turnstile> xcp ::\<preceq> Class (Xcpt ClassCast)"
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   462
          by (simp add: conf_def obj_ty_def)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   463
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   464
        from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   465
        have "approx_loc G hp loc LT'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   466
          by (simp add: sup_state_conv) blast        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   467
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   468
        note wf less pc' len 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   469
        ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   470
        have "correct_frame G hp (ST',LT') maxl ins ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   471
          by (unfold correct_frame_def) (auto simp add: sup_state_conv 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   472
              approx_stk_def approx_val_def split: err.split elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   473
      }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   474
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   475
      show ?thesis by (rule that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   476
    next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   477
      case Invoke
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   478
      with phi_pc eff 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   479
      have 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   480
        "\<forall>D\<in>set (match_any G pc et). 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   481
        the (?m D) < length ins \<and> G \<turnstile> Some ([Class D], LT) <=' phi C sig!the (?m D)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   482
        by (simp add: xcpt_eff_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   483
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   484
      from some_handler
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   485
      obtain D where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   486
        "D \<in> set (match_any G pc et)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   487
        D: "G \<turnstile> cname_of hp xcp \<preceq>C D" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   488
        "?m D = Some handler"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   489
        by (blast dest: in_match_any)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   490
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   491
      obtain 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   492
        pc': "handler < length ins" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   493
        "G \<turnstile> Some ([Class D], LT) <=' phi C sig ! handler"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   494
        by auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   495
      then
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   496
      obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   497
        phi': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   498
        less: "G \<turnstile> ([Class D], LT) <=s (ST', LT')" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   499
        by auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   500
      from xp wt correct
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   501
      obtain addr T where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   502
        xcp: "xcp = Addr addr" "hp addr = Some T"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   503
        by (blast dest: exec_instr_xcpt_hp)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   504
      note phi'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   505
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   506
      { from xcp D
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   507
        have "G,hp \<turnstile> xcp ::\<preceq> Class D"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   508
          by (simp add: conf_def obj_ty_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   509
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   510
        from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   511
        have "approx_loc G hp loc LT'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   512
          by (simp add: sup_state_conv) blast        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   513
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   514
        note wf less pc' len 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   515
        ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   516
        have "correct_frame G hp (ST',LT') maxl ins ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   517
          by (unfold correct_frame_def) (auto simp add: sup_state_conv 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   518
              approx_stk_def approx_val_def split: err.split elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   519
      }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   520
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   521
      show ?thesis by (rule that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   522
    next
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   523
      case Throw
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   524
      with phi_pc eff 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   525
      have 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   526
        "\<forall>D\<in>set (match_any G pc et). 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   527
        the (?m D) < length ins \<and> G \<turnstile> Some ([Class D], LT) <=' phi C sig!the (?m D)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   528
        by (simp add: xcpt_eff_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   529
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   530
      from some_handler
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   531
      obtain D where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   532
        "D \<in> set (match_any G pc et)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   533
        D: "G \<turnstile> cname_of hp xcp \<preceq>C D" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   534
        "?m D = Some handler"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   535
        by (blast dest: in_match_any)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   536
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   537
      obtain 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   538
        pc': "handler < length ins" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   539
        "G \<turnstile> Some ([Class D], LT) <=' phi C sig ! handler"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   540
        by auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   541
      then
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   542
      obtain ST' LT' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   543
        phi': "phi C sig ! handler = Some (ST', LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   544
        less: "G \<turnstile> ([Class D], LT) <=s (ST', LT')" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   545
        by auto
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   546
      from xp wt correct
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   547
      obtain addr T where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   548
        xcp: "xcp = Addr addr" "hp addr = Some T"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   549
        by (blast dest: exec_instr_xcpt_hp)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   550
      note phi'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   551
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   552
      { from xcp D
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   553
        have "G,hp \<turnstile> xcp ::\<preceq> Class D"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   554
          by (simp add: conf_def obj_ty_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   555
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   556
        from wf less loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   557
        have "approx_loc G hp loc LT'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   558
          by (simp add: sup_state_conv) blast        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   559
        moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   560
        note wf less pc' len 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   561
        ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   562
        have "correct_frame G hp (ST',LT') maxl ins ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   563
          by (unfold correct_frame_def) (auto simp add: sup_state_conv 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   564
              approx_stk_def approx_val_def split: err.split elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   565
      }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   566
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   567
      show ?thesis by (rule that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   568
    qed (insert xp', auto) -- "the other instructions don't generate exceptions"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   569
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   570
    from state' meth hp_ok class frames phi_pc' frame' 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   571
    have ?thesis by (unfold correct_state_def) simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   572
  }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   573
  ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   574
  show ?thesis by (cases "?match") blast+ 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   575
qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   576
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   577
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   578
11085
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10920
diff changeset
   579
section {* Single Instructions *}
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10920
diff changeset
   580
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   581
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   582
  In this section we look at each single (welltyped) instruction, and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   583
  prove that the state after execution of the instruction still conforms.
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   584
  Since we have already handled exceptions above, we can now assume, that
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   585
  on exception occurs for this (single step) execution.
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   586
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   587
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   588
lemmas [iff] = not_Err_eq
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   589
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   590
lemma Load_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
   591
"[| wf_prog wt G;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   592
    method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   593
    ins!pc = Load idx; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   594
    wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   595
    Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs); 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   596
    G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |]
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   597
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   598
apply (clarsimp simp add: defs1 map_eq_Cons)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   599
apply (blast intro: approx_loc_imp_approx_val_sup)
9819
wenzelm
parents: 9757
diff changeset
   600
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   601
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   602
lemma Store_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
   603
"[| wf_prog wt G;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   604
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et);
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   605
  ins!pc = Store idx;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   606
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc;
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   607
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs);
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   608
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |]
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   609
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   610
apply (clarsimp simp add: defs1 map_eq_Cons)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   611
apply (blast intro: approx_loc_subst)
9819
wenzelm
parents: 9757
diff changeset
   612
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   613
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   614
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
   615
lemma LitPush_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
   616
"[| wf_prog wt G;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   617
    method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
   618
    ins!pc = LitPush v;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   619
    wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   620
    Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs);
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   621
    G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |]
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   622
==> G,phi \<turnstile>JVM state'\<surd>" 
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   623
apply (clarsimp simp add: defs1 sup_PTS_eq map_eq_Cons)
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   624
apply (blast dest: conf_litval intro: conf_widen)
9819
wenzelm
parents: 9757
diff changeset
   625
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   626
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
   627
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   628
lemma Cast_conf2:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   629
  "[| wf_prog ok G; G,h\<turnstile>v::\<preceq>RefT rt; cast_ok G C h v; 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   630
      G\<turnstile>Class C\<preceq>T; is_class G C|] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   631
  ==> G,h\<turnstile>v::\<preceq>T"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   632
apply (unfold cast_ok_def)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   633
apply (frule widen_Class)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   634
apply (elim exE disjE) 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   635
 apply (simp add: null)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   636
apply (clarsimp simp add: conf_def obj_ty_def)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   637
apply (cases v)
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
   638
apply (auto intro: rtrancl_trans)
9819
wenzelm
parents: 9757
diff changeset
   639
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   640
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   641
lemmas defs1 = defs1 raise_system_xcpt_def
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   642
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   643
lemma Checkcast_correct:
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   644
"[| wt_jvm_prog G phi;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   645
    method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   646
    ins!pc = Checkcast D; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   647
    wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   648
    Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   649
    G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   650
    fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None |] 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   651
==> G,phi \<turnstile>JVM state'\<surd>"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   652
apply (clarsimp simp add: defs1 wt_jvm_prog_def map_eq_Cons split: split_if_asm)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   653
apply (blast intro: Cast_conf2)
9819
wenzelm
parents: 9757
diff changeset
   654
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   655
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   656
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   657
lemma Getfield_correct:
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   658
"[| wt_jvm_prog G phi;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   659
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   660
  ins!pc = Getfield F D; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   661
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   662
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   663
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   664
  fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None |] 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   665
==> G,phi \<turnstile>JVM state'\<surd>"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   666
apply (clarsimp simp add: defs1 map_eq_Cons wt_jvm_prog_def 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   667
                split: option.split split_if_asm)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   668
apply (frule conf_widen)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   669
apply assumption+
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   670
apply (drule conf_RefTD)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   671
apply (clarsimp simp add: defs1)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   672
apply (rule conjI)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   673
 apply (drule widen_cfs_fields)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   674
 apply assumption+
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   675
 apply (erule conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   676
 prefer 2
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   677
  apply assumption
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   678
 apply (simp add: hconf_def oconf_def lconf_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   679
 apply (elim allE)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   680
 apply (erule impE, assumption)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   681
 apply simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   682
 apply (elim allE)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   683
 apply (erule impE, assumption)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   684
 apply clarsimp
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   685
apply blast
9819
wenzelm
parents: 9757
diff changeset
   686
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   687
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   688
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   689
lemma Putfield_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
   690
"[| wf_prog wt G;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   691
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   692
  ins!pc = Putfield F D; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   693
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   694
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   695
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   696
  fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None |] 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   697
==> G,phi \<turnstile>JVM state'\<surd>"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   698
apply (clarsimp simp add: defs1 split_beta split: option.split List.split split_if_asm)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   699
apply (frule conf_widen)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   700
prefer 2
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   701
  apply assumption
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   702
 apply assumption
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   703
apply (drule conf_RefTD)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   704
apply clarsimp
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   705
apply (blast 
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   706
       intro: 
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   707
         hext_upd_obj approx_stk_sup_heap
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   708
         approx_loc_sup_heap 
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   709
         hconf_field_update
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   710
         preallocated_field_update
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   711
         correct_frames_field_update conf_widen 
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   712
       dest: 
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
   713
         widen_cfs_fields)
9819
wenzelm
parents: 9757
diff changeset
   714
done
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   715
    
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   716
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   717
lemma New_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
   718
"[| wf_prog wt G;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   719
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   720
  ins!pc = New X; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   721
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   722
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   723
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   724
  fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None |] 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   725
==> G,phi \<turnstile>JVM state'\<surd>"
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   726
proof -
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   727
  assume wf:   "wf_prog wt G"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   728
  assume meth: "method (G,C) sig = Some (C,rT,maxs,maxl,ins,et)"
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   729
  assume ins:  "ins!pc = New X"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   730
  assume wt:   "wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc"
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   731
  assume exec: "Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs)"
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   732
  assume conf: "G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   733
  assume no_x: "fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None"
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   734
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   735
  from ins conf meth
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   736
  obtain ST LT where
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   737
    heap_ok:    "G\<turnstile>h hp\<surd>" and
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   738
    prealloc:   "preallocated hp" and
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   739
    phi_pc:     "phi C sig!pc = Some (ST,LT)" and
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   740
    is_class_C: "is_class G C" and
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   741
    frame:      "correct_frame G hp (ST,LT) maxl ins (stk, loc, C, sig, pc)" and
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   742
    frames:     "correct_frames G hp phi rT sig frs"
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   743
    by (auto simp add: correct_state_def iff del: not_None_eq)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   744
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   745
  from phi_pc ins wt
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   746
  obtain ST' LT' where
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   747
    is_class_X: "is_class G X" and
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   748
    maxs:       "length ST < maxs" and
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   749
    suc_pc:     "Suc pc < length ins" and
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   750
    phi_suc:    "phi C sig ! Suc pc = Some (ST', LT')" and
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   751
    less:       "G \<turnstile> (Class X # ST, LT) <=s (ST', LT')"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   752
    by (unfold wt_instr_def eff_def norm_eff_def) auto
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   753
 
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   754
  obtain oref xp' where
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   755
    new_Addr: "new_Addr hp = (oref,xp')"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   756
    by (cases "new_Addr hp") 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   757
  with ins no_x
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   758
  obtain hp: "hp oref = None" and "xp' = None"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   759
    by (auto dest: new_AddrD simp add: raise_system_xcpt_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   760
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   761
  with exec ins meth new_Addr 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   762
  have state':
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   763
    "state' = Norm (hp(oref\<mapsto>(X, init_vars (fields (G, X)))), 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   764
              (Addr oref # stk, loc, C, sig, Suc pc) # frs)" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   765
    (is "state' = Norm (?hp', ?f # frs)")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   766
    by simp    
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   767
  moreover
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   768
  from wf hp heap_ok is_class_X
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   769
  have hp': "G \<turnstile>h ?hp' \<surd>"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   770
    by - (rule hconf_newref, auto simp add: oconf_def dest: fields_is_type)
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   771
  moreover
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   772
  from hp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   773
  have sup: "hp \<le>| ?hp'" by (rule hext_new)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   774
  from hp frame less suc_pc wf
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   775
  have "correct_frame G ?hp' (ST', LT') maxl ins ?f"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   776
    apply (unfold correct_frame_def sup_state_conv)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   777
    apply (clarsimp simp add: map_eq_Cons conf_def fun_upd_apply approx_val_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   778
    apply (blast intro: approx_stk_sup_heap approx_loc_sup_heap sup)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   779
    done      
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   780
  moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   781
  from hp frames wf heap_ok is_class_X
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   782
  have "correct_frames G ?hp' phi rT sig frs"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   783
    by - (rule correct_frames_newref, 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   784
          auto simp add: oconf_def dest: fields_is_type)
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   785
  moreover
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   786
  from hp prealloc have "preallocated ?hp'" by (rule preallocated_newref)
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   787
  ultimately
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   788
  show ?thesis
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   789
    by (simp add: is_class_C meth phi_suc correct_state_def del: not_None_eq)
10920
9b74eceea2d2 newref -> new_Addr
kleing
parents: 10897
diff changeset
   790
qed
11085
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10920
diff changeset
   791
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   792
lemmas [simp del] = split_paired_Ex
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   793
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   794
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   795
lemma Invoke_correct: 
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   796
"[| wt_jvm_prog G phi; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   797
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   798
  ins ! pc = Invoke C' mn pTs; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   799
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   800
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   801
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   802
  fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None |] 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   803
==> G,phi \<turnstile>JVM state'\<surd>" 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   804
proof -
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   805
  assume wtprog: "wt_jvm_prog G phi"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   806
  assume method: "method (G,C) sig = Some (C,rT,maxs,maxl,ins,et)"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   807
  assume ins:    "ins ! pc = Invoke C' mn pTs"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   808
  assume wti:    "wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   809
  assume state': "Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs)"
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   810
  assume approx: "G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   811
  assume no_xcp: "fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   812
  
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   813
  from wtprog 
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   814
  obtain wfmb where
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   815
    wfprog: "wf_prog wfmb G" 
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   816
    by (simp add: wt_jvm_prog_def)
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   817
      
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   818
  from ins method approx
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   819
  obtain s where
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   820
    heap_ok: "G\<turnstile>h hp\<surd>" and
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   821
    prealloc:"preallocated hp" and
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   822
    phi_pc:  "phi C sig!pc = Some s" and
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   823
    is_class_C: "is_class G C" and
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   824
    frame:   "correct_frame G hp s maxl ins (stk, loc, C, sig, pc)" and
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   825
    frames:  "correct_frames G hp phi rT sig frs"
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   826
    by (clarsimp simp add: correct_state_def iff del: not_None_eq)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   827
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   828
  from ins wti phi_pc
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   829
  obtain apTs X ST LT D' rT body where 
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   830
    is_class: "is_class G C'" and
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   831
    s:  "s = (rev apTs @ X # ST, LT)" and
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   832
    l:  "length apTs = length pTs" and
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   833
    X:  "G\<turnstile> X \<preceq> Class C'" and
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   834
    w:  "\<forall>x\<in>set (zip apTs pTs). x \<in> widen G" and
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   835
    mC':"method (G, C') (mn, pTs) = Some (D', rT, body)" and
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   836
    pc: "Suc pc < length ins" and
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   837
    eff: "G \<turnstile> norm_eff (Invoke C' mn pTs) G (Some s) <=' phi C sig!Suc pc"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   838
    by (simp add: wt_instr_def eff_def del: not_None_eq) 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   839
       (elim exE conjE, rule that)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   840
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   841
  from eff
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   842
  obtain ST' LT' where
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   843
    s': "phi C sig ! Suc pc = Some (ST', LT')"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   844
    by (simp add: norm_eff_def split_paired_Ex) blast
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   845
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   846
  from X 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   847
  obtain T where
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   848
    X_Ref: "X = RefT T"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   849
    by - (drule widen_RefT2, erule exE, rule that)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   850
  
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   851
  from s ins frame 
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   852
  obtain 
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   853
    a_stk: "approx_stk G hp stk (rev apTs @ X # ST)" and
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   854
    a_loc: "approx_loc G hp loc LT" and
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   855
    suc_l: "length loc = Suc (length (snd sig) + maxl)"
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   856
    by (simp add: correct_frame_def)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   857
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   858
  from a_stk
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   859
  obtain opTs stk' oX where
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   860
    opTs:   "approx_stk G hp opTs (rev apTs)" and
10496
f2d304bdf3cc BCV integration (first step)
kleing
parents: 10387
diff changeset
   861
    oX:     "approx_val G hp oX (OK X)" and
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   862
    a_stk': "approx_stk G hp stk' ST" and
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   863
    stk':   "stk = opTs @ oX # stk'" and
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   864
    l_o:    "length opTs = length apTs" 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   865
            "length stk' = length ST"  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   866
    by - (drule approx_stk_append, auto)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   867
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   868
  from oX X_Ref
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   869
  have oX_conf: "G,hp \<turnstile> oX ::\<preceq> RefT T"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   870
    by (simp add: approx_val_def)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   871
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   872
  from stk' l_o l
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
   873
  have oX_pos: "last (take (Suc (length pTs)) stk) = oX" by simp
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   874
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   875
  with state' method ins no_xcp oX_conf
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   876
  obtain ref where oX_Addr: "oX = Addr ref"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   877
    by (auto simp add: raise_system_xcpt_def dest: conf_RefTD)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   878
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   879
  with oX_conf X_Ref
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   880
  obtain obj D where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   881
    loc:    "hp ref = Some obj" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   882
    obj_ty: "obj_ty obj = Class D" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   883
    D:      "G \<turnstile> Class D \<preceq> X"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   884
    by (auto simp add: conf_def) blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   885
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   886
  with X_Ref obtain X' where X': "X = Class X'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   887
    by (blast dest: widen_Class)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   888
      
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   889
  with X have X'_subcls: "G \<turnstile> X' \<preceq>C C'"  by simp
10612
779af7c58743 improved superclass entry for classes and definition status of is_class, class
oheimb
parents: 10592
diff changeset
   890
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   891
  with mC' wfprog
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   892
  obtain D0 rT0 maxs0 maxl0 ins0 et0 where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   893
    mX: "method (G, X') (mn, pTs) = Some (D0, rT0, maxs0, maxl0, ins0, et0)" "G\<turnstile>rT0\<preceq>rT"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   894
    by (auto dest: subtype_widen_methd intro: that)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   895
    
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   896
  from X' D have D_subcls: "G \<turnstile> D \<preceq>C X'" by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   897
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   898
  with wfprog mX
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   899
  obtain D'' rT' mxs' mxl' ins' et' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   900
    mD: "method (G, D) (mn, pTs) = Some (D'', rT', mxs', mxl', ins', et')" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   901
        "G \<turnstile> rT' \<preceq> rT0"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   902
    by (auto dest: subtype_widen_methd intro: that)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   903
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   904
  from mX mD have rT': "G \<turnstile> rT' \<preceq> rT" by - (rule widen_trans)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   905
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   906
  from is_class X'_subcls D_subcls
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   907
  have is_class_D: "is_class G D" by (auto dest: subcls_is_class2)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   908
  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   909
  with mD wfprog
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   910
  obtain mD'': 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   911
    "method (G, D'') (mn, pTs) = Some (D'', rT', mxs', mxl', ins', et')"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   912
    "is_class G D''"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   913
    by (auto dest: method_in_md)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   914
      
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   915
  from loc obj_ty have "fst (the (hp ref)) = D" by (simp add: obj_ty_def)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   916
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   917
  with oX_Addr oX_pos state' method ins stk' l_o l loc obj_ty mD no_xcp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   918
  have state'_val:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   919
    "state' =
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   920
     Norm (hp, ([], Addr ref # rev opTs @ replicate mxl' arbitrary, 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   921
                D'', (mn, pTs), 0) # (opTs @ Addr ref # stk', loc, C, sig, pc) # frs)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   922
    (is "state' = Norm (hp, ?f # ?f' # frs)")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   923
    by (simp add: raise_system_xcpt_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   924
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   925
  from wtprog mD''
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   926
  have start: "wt_start G D'' pTs mxl' (phi D'' (mn, pTs)) \<and> ins' \<noteq> []"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   927
    by (auto dest: wt_jvm_prog_impl_wt_start)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   928
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   929
  then obtain LT0 where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   930
    LT0: "phi D'' (mn, pTs) ! 0 = Some ([], LT0)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   931
    by (clarsimp simp add: wt_start_def sup_state_conv)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   932
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   933
  have c_f: "correct_frame G hp ([], LT0) mxl' ins' ?f"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   934
  proof -
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   935
    from start LT0
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   936
    have sup_loc: 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   937
      "G \<turnstile> (OK (Class D'') # map OK pTs @ replicate mxl' Err) <=l LT0"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   938
      (is "G \<turnstile> ?LT <=l LT0")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   939
      by (simp add: wt_start_def sup_state_conv)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   940
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   941
    have r: "approx_loc G hp (replicate mxl' arbitrary) (replicate mxl' Err)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   942
      by (simp add: approx_loc_def list_all2_def set_replicate_conv_if)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   943
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   944
    from wfprog mD is_class_D
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   945
    have "G \<turnstile> Class D \<preceq> Class D''"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   946
      by (auto dest: method_wf_mdecl)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   947
    with obj_ty loc
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   948
    have a: "approx_val G hp (Addr ref) (OK (Class D''))"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   949
      by (simp add: approx_val_def conf_def)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   950
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   951
    from opTs w l l_o wfprog 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   952
    have "approx_stk G hp opTs (rev pTs)" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   953
      by (auto elim!: approx_stk_all_widen simp add: zip_rev)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   954
    hence "approx_stk G hp (rev opTs) pTs" by (subst approx_stk_rev)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   955
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   956
    with r a l_o l
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   957
    have "approx_loc G hp (Addr ref # rev opTs @ replicate mxl' arbitrary) ?LT"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   958
      (is "approx_loc G hp ?lt ?LT")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   959
      by (auto simp add: approx_loc_append approx_stk_def)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   960
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   961
    from this sup_loc wfprog
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   962
    have "approx_loc G hp ?lt LT0" by (rule approx_loc_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   963
    with start l_o l
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   964
    show ?thesis by (simp add: correct_frame_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   965
  qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   966
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   967
  from state'_val heap_ok mD'' ins method phi_pc s X' l mX
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
   968
       frames s' LT0 c_f is_class_C stk' oX_Addr frame prealloc
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   969
  show ?thesis by (simp add: correct_state_def) (intro exI conjI, blast)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   970
qed
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   971
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   972
lemmas [simp del] = map_append
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   973
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   974
lemma Return_correct:
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
   975
"[| wt_jvm_prog G phi; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   976
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   977
  ins ! pc = Return; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   978
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
   979
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   980
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |]
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
   981
==> G,phi \<turnstile>JVM state'\<surd>"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   982
proof -
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   983
  assume wt_prog: "wt_jvm_prog G phi"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   984
  assume meth: "method (G,C) sig = Some (C,rT,maxs,maxl,ins,et)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   985
  assume ins: "ins ! pc = Return"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   986
  assume wt: "wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   987
  assume s': "Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs)"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   988
  assume correct: "G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   989
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   990
  from wt_prog 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   991
  obtain wfmb where wf: "wf_prog wfmb G" by (simp add: wt_jvm_prog_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   992
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   993
  from meth ins s'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   994
  have "frs = [] \<Longrightarrow> ?thesis" by (simp add: correct_state_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   995
  moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   996
  { fix f frs' 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   997
    assume frs': "frs = f#frs'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   998
    moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
   999
    obtain stk' loc' C' sig' pc' where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1000
      f: "f = (stk',loc',C',sig',pc')" by (cases f)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1001
    moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1002
    obtain mn pt where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1003
      sig: "sig = (mn,pt)" by (cases sig)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1004
    moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1005
    note meth ins s'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1006
    ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1007
    have state':
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1008
      "state' = (None,hp,(hd stk#(drop (1+length pt) stk'),loc',C',sig',pc'+1)#frs')"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1009
      (is "state' = (None,hp,?f'#frs')")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1010
      by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1011
    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1012
    from correct meth
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1013
    obtain ST LT where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1014
      hp_ok:  "G \<turnstile>h hp \<surd>" and
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
  1015
      alloc:  "preallocated hp" and
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1016
      phi_pc: "phi C sig ! pc = Some (ST, LT)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1017
      frame:  "correct_frame G hp (ST, LT) maxl ins (stk,loc,C,sig,pc)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1018
      frames: "correct_frames G hp phi rT sig frs"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1019
      by (simp add: correct_state_def, clarify, blast)    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1020
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1021
    from phi_pc ins wt
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1022
    obtain T ST' where "ST = T # ST'" "G \<turnstile> T \<preceq> rT"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1023
      by (simp add: wt_instr_def) blast    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1024
    with wf frame 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1025
    have hd_stk: "G,hp \<turnstile> (hd stk) ::\<preceq> rT"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1026
      by (auto simp add: correct_frame_def elim: conf_widen)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1027
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1028
    from f frs' frames sig
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1029
    obtain apTs ST0' ST' LT' D D' D'' rT' rT'' maxs' maxl' ins' et' body where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1030
      phi':   "phi C' sig' ! pc' = Some (ST',LT')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1031
      class': "is_class G C'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1032
      meth':  "method (G,C') sig' = Some (C',rT',maxs',maxl',ins',et')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1033
      ins':   "ins' ! pc' = Invoke D' mn pt" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1034
      frame': "correct_frame G hp (ST', LT') maxl' ins' f" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1035
      frames':"correct_frames G hp phi rT' sig' frs'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1036
      rT'':   "G \<turnstile> rT \<preceq> rT''" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1037
      meth'': "method (G, D) sig = Some (D'', rT'', body)" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1038
      ST0':   "ST' = rev apTs @ Class D # ST0'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1039
      len':   "length apTs = length pt" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1040
      by clarsimp blast    
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1041
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1042
    from f frame'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1043
    obtain
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1044
      stk': "approx_stk G hp stk' ST'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1045
      loc': "approx_loc G hp loc' LT'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1046
      pc':  "pc' < length ins'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1047
      lloc':"length loc' = Suc (length (snd sig') + maxl')"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1048
      by (simp add: correct_frame_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1049
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1050
    from wt_prog class' meth' pc'  
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1051
    have "wt_instr (ins'!pc') G rT' (phi C' sig') maxs' (length ins') et' pc'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1052
      by (rule wt_jvm_prog_impl_wt_instr)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1053
    with ins' phi' sig
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1054
    obtain apTs ST0 X ST'' LT'' body' rT0 mD where
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1055
      phi_suc: "phi C' sig' ! Suc pc' = Some (ST'', LT'')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1056
      ST0:     "ST' = rev apTs @ X # ST0" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1057
      len:     "length apTs = length pt" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1058
      less:    "G \<turnstile> (rT0 # ST0, LT') <=s (ST'', LT'')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1059
      methD':  "method (G, D') sig = Some (mD, rT0, body')" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1060
      lessD':  "G \<turnstile> X \<preceq> Class D'" and
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1061
      suc_pc': "Suc pc' < length ins'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1062
      by (clarsimp simp add: wt_instr_def eff_def norm_eff_def) blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1063
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1064
    from len len' ST0 ST0'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1065
    have "X = Class D" by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1066
    with lessD'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1067
    have "G \<turnstile> D \<preceq>C D'" by simp
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1068
    moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1069
    note wf meth'' methD'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1070
    ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1071
    have "G \<turnstile> rT'' \<preceq> rT0" by (auto dest: subcls_widen_methd)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1072
    with wf hd_stk rT''
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1073
    have hd_stk': "G,hp \<turnstile> (hd stk) ::\<preceq> rT0" by (auto elim: conf_widen widen_trans)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1074
        
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1075
    have frame'':
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1076
      "correct_frame G hp (ST'',LT'') maxl' ins' ?f'"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1077
    proof -
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1078
      from wf hd_stk' len stk' less ST0
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1079
      have "approx_stk G hp (hd stk # drop (1+length pt) stk') ST''" 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1080
        by (auto simp add: map_eq_Cons sup_state_conv
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1081
                 dest!: approx_stk_append elim: conf_widen)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1082
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1083
      from wf loc' less
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1084
      have "approx_loc G hp loc' LT''" by (simp add: sup_state_conv) blast
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1085
      moreover
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1086
      note suc_pc' lloc'
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1087
      ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1088
      show ?thesis by (simp add: correct_frame_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1089
    qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1090
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
  1091
    with state' frs' f meth hp_ok hd_stk phi_suc frames' meth' phi' class' alloc
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1092
    have ?thesis by (simp add: correct_state_def)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1093
  }
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1094
  ultimately
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1095
  show ?thesis by (cases frs) blast+
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1096
qed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1097
  
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1098
lemmas [simp] = map_append
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1099
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1100
lemma Goto_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1101
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1102
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1103
  ins ! pc = Goto branch; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1104
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1105
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1106
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1107
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1108
apply (clarsimp simp add: defs1)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1109
apply fast
9819
wenzelm
parents: 9757
diff changeset
  1110
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1111
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1112
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1113
lemma Ifcmpeq_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1114
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1115
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1116
  ins ! pc = Ifcmpeq branch; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1117
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1118
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1119
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1120
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1121
apply (clarsimp simp add: defs1)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1122
apply fast
9819
wenzelm
parents: 9757
diff changeset
  1123
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1124
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1125
lemma Pop_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1126
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1127
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1128
  ins ! pc = Pop;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1129
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1130
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1131
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1132
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1133
apply (clarsimp simp add: defs1)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1134
apply fast
9819
wenzelm
parents: 9757
diff changeset
  1135
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1136
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1137
lemma Dup_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1138
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1139
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1140
  ins ! pc = Dup;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1141
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1142
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1143
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1144
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1145
apply (clarsimp simp add: defs1 map_eq_Cons)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1146
apply (blast intro: conf_widen)
9819
wenzelm
parents: 9757
diff changeset
  1147
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1148
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1149
lemma Dup_x1_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1150
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1151
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1152
  ins ! pc = Dup_x1;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1153
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1154
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1155
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1156
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1157
apply (clarsimp simp add: defs1 map_eq_Cons)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1158
apply (blast intro: conf_widen)
9819
wenzelm
parents: 9757
diff changeset
  1159
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1160
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1161
lemma Dup_x2_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1162
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1163
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1164
  ins ! pc = Dup_x2;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1165
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1166
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1167
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1168
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1169
apply (clarsimp simp add: defs1 map_eq_Cons)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1170
apply (blast intro: conf_widen)
9819
wenzelm
parents: 9757
diff changeset
  1171
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1172
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1173
lemma Swap_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1174
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1175
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1176
  ins ! pc = Swap;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1177
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1178
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1179
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1180
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1181
apply (clarsimp simp add: defs1 map_eq_Cons)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1182
apply (blast intro: conf_widen)
9819
wenzelm
parents: 9757
diff changeset
  1183
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1184
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1185
lemma IAdd_correct:
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9941
diff changeset
  1186
"[| wf_prog wt G; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1187
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1188
  ins ! pc = IAdd; 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1189
  wt_instr (ins!pc) G rT (phi C sig) maxs (length ins) et pc; 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1190
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1191
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1192
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1193
apply (clarsimp simp add: defs1 map_eq_Cons approx_val_def conf_def)
11252
71c00cb091d2 cleanup, tuned
kleing
parents: 11085
diff changeset
  1194
apply blast
9819
wenzelm
parents: 9757
diff changeset
  1195
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1196
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1197
lemma Throw_correct:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1198
"[| wf_prog wt G; 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1199
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et); 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1200
  ins ! pc = Throw; 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1201
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs) ; 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1202
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd>;
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1203
  fst (exec_instr (ins!pc) G hp stk loc C sig pc frs) = None |] 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1204
==> G,phi \<turnstile>JVM state'\<surd>"
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1205
  by simp
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1206
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1207
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1208
text {*
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1209
  The next theorem collects the results of the sections above,
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1210
  i.e.~exception handling and the execution step for each 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1211
  instruction. It states type safety for single step execution:
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1212
  in welltyped programs, a conforming state is transformed
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1213
  into another conforming state when one instruction is executed.
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1214
*}
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1215
theorem instr_correct:
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1216
"[| wt_jvm_prog G phi;
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1217
  method (G,C) sig = Some (C,rT,maxs,maxl,ins,et);
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1218
  Some state' = exec (G, None, hp, (stk,loc,C,sig,pc)#frs); 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1219
  G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> |] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1220
==> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1221
apply (frule wt_jvm_prog_impl_wt_instr_cor)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1222
apply assumption+
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1223
apply (cases "fst (exec_instr (ins!pc) G hp stk loc C sig pc frs)")
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1224
defer
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1225
apply (erule xcpt_correct, assumption+) 
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1226
apply (cases "ins!pc")
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
  1227
prefer 8
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1228
apply (rule Invoke_correct, assumption+)
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
  1229
prefer 8
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1230
apply (rule Return_correct, assumption+)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1231
prefer 5
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1232
apply (rule Getfield_correct, assumption+)
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1233
prefer 6
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1234
apply (rule Checkcast_correct, assumption+)
10612
779af7c58743 improved superclass entry for classes and definition status of is_class, class
oheimb
parents: 10592
diff changeset
  1235
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1236
apply (unfold wt_jvm_prog_def)
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1237
apply (rule Load_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1238
apply (rule Store_correct, assumption+)
10897
697fab84709e removed instructions Aconst_null+Bipush, introduced LitPush
kleing
parents: 10812
diff changeset
  1239
apply (rule LitPush_correct, assumption+)
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1240
apply (rule New_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1241
apply (rule Putfield_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1242
apply (rule Pop_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1243
apply (rule Dup_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1244
apply (rule Dup_x1_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1245
apply (rule Dup_x2_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1246
apply (rule Swap_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1247
apply (rule IAdd_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1248
apply (rule Goto_correct, assumption+)
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1249
apply (rule Ifcmpeq_correct, assumption+)
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1250
apply (rule Throw_correct, assumption+)
9819
wenzelm
parents: 9757
diff changeset
  1251
done
10626
46bcddfe9e7b update for changes in Correct.thy and class/is_class defs
kleing
parents: 10612
diff changeset
  1252
11085
b830bf10bf71 tuned for 99-2 release
kleing
parents: 10920
diff changeset
  1253
section {* Main *}
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1254
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1255
lemma correct_state_impl_Some_method:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1256
  "G,phi \<turnstile>JVM (None, hp, (stk,loc,C,sig,pc)#frs)\<surd> 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1257
  ==> \<exists>meth. method (G,C) sig = Some(C,meth)"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1258
by (auto simp add: correct_state_def Let_def)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1259
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1260
9941
fe05af7ec816 renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents: 9906
diff changeset
  1261
lemma BV_correct_1 [rule_format]:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1262
"!!state. [| wt_jvm_prog G phi; G,phi \<turnstile>JVM state\<surd>|] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1263
 ==> exec (G,state) = Some state' --> G,phi \<turnstile>JVM state'\<surd>"
9819
wenzelm
parents: 9757
diff changeset
  1264
apply (simp only: split_tupled_all)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1265
apply (rename_tac xp hp frs)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1266
apply (case_tac xp)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1267
 apply (case_tac frs)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1268
  apply simp
9819
wenzelm
parents: 9757
diff changeset
  1269
 apply (simp only: split_tupled_all)
wenzelm
parents: 9757
diff changeset
  1270
 apply hypsubst
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1271
 apply (frule correct_state_impl_Some_method)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1272
 apply (force intro: instr_correct)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1273
apply (case_tac frs)
9819
wenzelm
parents: 9757
diff changeset
  1274
apply simp_all
wenzelm
parents: 9757
diff changeset
  1275
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1276
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1277
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1278
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1279
lemma L0:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1280
  "[| xp=None; frs\<noteq>[] |] ==> (\<exists>state'. exec (G,xp,hp,frs) = Some state')"
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1281
by (clarsimp simp add: neq_Nil_conv split_beta)
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1282
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1283
lemma L1:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1284
  "[|wt_jvm_prog G phi; G,phi \<turnstile>JVM (xp,hp,frs)\<surd>; xp=None; frs\<noteq>[]|] 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1285
  ==> \<exists>state'. exec(G,xp,hp,frs) = Some state' \<and> G,phi \<turnstile>JVM state'\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1286
apply (drule L0)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1287
apply assumption
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1288
apply (fast intro: BV_correct_1)
9819
wenzelm
parents: 9757
diff changeset
  1289
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1290
9941
fe05af7ec816 renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents: 9906
diff changeset
  1291
theorem BV_correct [rule_format]:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1292
"[| wt_jvm_prog G phi; G \<turnstile> s -jvm-> t |] ==> G,phi \<turnstile>JVM s\<surd> --> G,phi \<turnstile>JVM t\<surd>"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1293
apply (unfold exec_all_def)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1294
apply (erule rtrancl_induct)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1295
 apply simp
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1296
apply (auto intro: BV_correct_1)
9819
wenzelm
parents: 9757
diff changeset
  1297
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1298
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12516
diff changeset
  1299
theorem BV_correct_implies_approx:
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
  1300
"[| wt_jvm_prog G phi; 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10763
diff changeset
  1301
    G \<turnstile> s0 -jvm-> (None,hp,(stk,loc,C,sig,pc)#frs); G,phi \<turnstile>JVM s0 \<surd>|] 
12516
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1302
==> approx_stk G hp stk (fst (the (phi C sig ! pc))) \<and> 
d09d0f160888 exceptions
kleing
parents: 12389
diff changeset
  1303
    approx_loc G hp loc (snd (the (phi C sig ! pc)))"
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1304
apply (drule BV_correct)
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1305
apply assumption+
10056
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
  1306
apply (simp add: correct_state_def correct_frame_def split_def 
9f84ffa4a8d0 tuned spacing for document generation
kleing
parents: 10042
diff changeset
  1307
            split: option.splits)
9819
wenzelm
parents: 9757
diff changeset
  1308
done
9757
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1309
1024a2d80ac0 functional LBV style, dead code, type safety -> Isar
kleing
parents: 8011
diff changeset
  1310
end