author | kleing |
Sat, 09 Mar 2002 20:39:46 +0100 | |
changeset 13052 | 3bf41c474a88 |
parent 12911 | 704713ca07ea |
child 13065 | d6585b32412b |
permissions | -rw-r--r-- |
12519 | 1 |
(* Title: HOL/MicroJava/JVM/JVMExceptions.thy |
2 |
ID: $Id$ |
|
3 |
Author: Gerwin Klein, Martin Strecker |
|
4 |
Copyright 2001 Technische Universitaet Muenchen |
|
5 |
*) |
|
6 |
||
12911 | 7 |
header {* \isaheader{Exception handling in the JVM} *} |
12519 | 8 |
|
9 |
theory JVMExceptions = JVMInstructions: |
|
10 |
||
11 |
constdefs |
|
12 |
match_exception_entry :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_entry \<Rightarrow> bool" |
|
13 |
"match_exception_entry G cn pc ee == |
|
14 |
let (start_pc, end_pc, handler_pc, catch_type) = ee in |
|
15 |
start_pc <= pc \<and> pc < end_pc \<and> G\<turnstile> cn \<preceq>C catch_type" |
|
16 |
||
17 |
||
18 |
consts |
|
19 |
match_exception_table :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_table |
|
20 |
\<Rightarrow> p_count option" |
|
21 |
primrec |
|
22 |
"match_exception_table G cn pc [] = None" |
|
23 |
"match_exception_table G cn pc (e#es) = (if match_exception_entry G cn pc e |
|
24 |
then Some (fst (snd (snd e))) |
|
25 |
else match_exception_table G cn pc es)" |
|
26 |
||
27 |
||
28 |
consts |
|
29 |
cname_of :: "aheap \<Rightarrow> val \<Rightarrow> cname" |
|
30 |
ex_table_of :: "jvm_method \<Rightarrow> exception_table" |
|
31 |
||
32 |
translations |
|
33 |
"cname_of hp v" == "fst (the (hp (the_Addr v)))" |
|
34 |
"ex_table_of m" == "snd (snd (snd m))" |
|
35 |
||
36 |
||
37 |
consts |
|
38 |
find_handler :: "jvm_prog \<Rightarrow> val option \<Rightarrow> aheap \<Rightarrow> frame list \<Rightarrow> jvm_state" |
|
39 |
primrec |
|
40 |
"find_handler G xcpt hp [] = (xcpt, hp, [])" |
|
41 |
"find_handler G xcpt hp (fr#frs) = |
|
42 |
(case xcpt of |
|
43 |
None \<Rightarrow> (None, hp, fr#frs) |
|
44 |
| Some xc \<Rightarrow> |
|
45 |
let (stk,loc,C,sig,pc) = fr in |
|
46 |
(case match_exception_table G (cname_of hp xc) pc |
|
47 |
(ex_table_of (snd(snd(the(method (G,C) sig))))) of |
|
48 |
None \<Rightarrow> find_handler G (Some xc) hp frs |
|
49 |
| Some handler_pc \<Rightarrow> (None, hp, ([xc], loc, C, sig, handler_pc)#frs)))" |
|
50 |
||
51 |
||
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
52 |
text {* |
13052 | 53 |
System exceptions are allocated in all heaps: |
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
54 |
*} |
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
55 |
constdefs |
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
56 |
preallocated :: "aheap \<Rightarrow> bool" |
13052 | 57 |
"preallocated hp \<equiv> \<forall>x. \<exists>fs. hp (XcptRef x) = Some (Xcpt x, fs)" |
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
58 |
|
13052 | 59 |
lemma preallocatedD: |
60 |
"preallocated hp \<Longrightarrow> \<exists>fs. hp (XcptRef x) = Some (Xcpt x, fs)" |
|
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
61 |
by (unfold preallocated_def) fast |
12519 | 62 |
|
13052 | 63 |
lemma preallocatedE [elim?]: |
64 |
"preallocated hp \<Longrightarrow> (\<And>fs. hp (XcptRef x) = Some (Xcpt x, fs) \<Longrightarrow> P hp) \<Longrightarrow> P hp" |
|
65 |
by (fast dest: preallocatedD) |
|
66 |
||
12519 | 67 |
lemma cname_of_xcp: |
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
68 |
"raise_system_xcpt b x = Some xcp \<Longrightarrow> preallocated hp |
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
69 |
\<Longrightarrow> cname_of (hp::aheap) xcp = Xcpt x" |
12519 | 70 |
proof - |
71 |
assume "raise_system_xcpt b x = Some xcp" |
|
72 |
hence "xcp = Addr (XcptRef x)" |
|
73 |
by (simp add: raise_system_xcpt_def split: split_if_asm) |
|
74 |
moreover |
|
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
75 |
assume "preallocated hp" |
13052 | 76 |
then obtain fs where "hp (XcptRef x) = Some (Xcpt x, fs)" .. |
12519 | 77 |
ultimately |
78 |
show ?thesis by simp |
|
79 |
qed |
|
80 |
||
13052 | 81 |
lemma preallocated_start: |
82 |
"preallocated (start_heap G)" |
|
83 |
apply (unfold preallocated_def) |
|
84 |
apply (unfold start_heap_def) |
|
85 |
apply (rule allI) |
|
86 |
apply (case_tac x) |
|
87 |
apply (auto simp add: blank_def) |
|
88 |
done |
|
89 |
||
12519 | 90 |
end |