src/HOL/MicroJava/JVM/JVMExceptions.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 39758 b8a53e3a0ee2
child 58886 8a6cac7c7247
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/JVM/JVMExceptions.thy
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     2
    Author:     Gerwin Klein, Martin Strecker
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     3
    Copyright   2001 Technische Universitaet Muenchen
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     4
*)
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     5
12911
704713ca07ea new document
kleing
parents: 12545
diff changeset
     6
header {* \isaheader{Exception handling in the JVM} *}
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     7
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 13674
diff changeset
     8
theory JVMExceptions imports JVMInstructions begin
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     9
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 35102
diff changeset
    10
definition match_exception_entry :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_entry \<Rightarrow> bool" where
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    11
  "match_exception_entry G cn pc ee == 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    12
                 let (start_pc, end_pc, handler_pc, catch_type) = ee in
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    13
                 start_pc <= pc \<and> pc < end_pc \<and> G\<turnstile> cn \<preceq>C catch_type"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    14
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    15
39758
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    16
primrec match_exception_table :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_table
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    17
    \<Rightarrow> p_count option"
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    18
where
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    19
  "match_exception_table G cn pc []     = None"
39758
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    20
| "match_exception_table G cn pc (e#es) = (if match_exception_entry G cn pc e
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    21
                                           then Some (fst (snd (snd e))) 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    22
                                           else match_exception_table G cn pc es)"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    23
35102
cc7a0b9f938c modernized translations;
wenzelm
parents: 16417
diff changeset
    24
abbreviation
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    25
  ex_table_of :: "jvm_method \<Rightarrow> exception_table"
35102
cc7a0b9f938c modernized translations;
wenzelm
parents: 16417
diff changeset
    26
  where "ex_table_of m == snd (snd (snd m))"
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    27
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    28
39758
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    29
primrec find_handler :: "jvm_prog \<Rightarrow> val option \<Rightarrow> aheap \<Rightarrow> frame list
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    30
    \<Rightarrow> jvm_state"
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    31
where
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    32
  "find_handler G xcpt hp [] = (xcpt, hp, [])"
39758
b8a53e3a0ee2 modernized primrecs
haftmann
parents: 35416
diff changeset
    33
| "find_handler G xcpt hp (fr#frs) = 
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    34
      (case xcpt of
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    35
         None \<Rightarrow> (None, hp, fr#frs)
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    36
       | Some xc \<Rightarrow> 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    37
       let (stk,loc,C,sig,pc) = fr in
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    38
       (case match_exception_table G (cname_of hp xc) pc 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    39
              (ex_table_of (snd(snd(the(method (G,C) sig))))) of
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    40
          None \<Rightarrow> find_handler G (Some xc) hp frs
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    41
        | Some handler_pc \<Rightarrow> (None, hp, ([xc], loc, C, sig, handler_pc)#frs)))"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    42
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    43
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12519
diff changeset
    44
text {*
13052
3bf41c474a88 canonical start state
kleing
parents: 12911
diff changeset
    45
  System exceptions are allocated in all heaps:
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12519
diff changeset
    46
*}
13052
3bf41c474a88 canonical start state
kleing
parents: 12911
diff changeset
    47
13065
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    48
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    49
text {*
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    50
  Only program counters that are mentioned in the exception table
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    51
  can be returned by @{term match_exception_table}:
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    52
*}
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    53
lemma match_exception_table_in_et:
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    54
  "match_exception_table G C pc et = Some pc' \<Longrightarrow> \<exists>e \<in> set et. pc' = fst (snd (snd e))"
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    55
  by (induct et) (auto split: split_if_asm)
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    56
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    57
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    58
end