section‹ The Typing Framework for the JVM \label{sec:JVM} ›
theory TF_JVM imports Jinja.Typing_Framework_err EffectMono BVSpec begin
definition exec :: "jvm_prog ==> nat ==> ty ==> ex_table ==> instr list ==> tyi' err step_type" where "exec G maxs rT et bs ≡ err_step (size bs) (λpc. app (bs!pc) G maxs rT pc (size bs) et) (λpc. eff (bs!pc) G pc et)"
locale JVM_sl = fixes P :: jvm_prog and mxs and mxl0and n fixes b and Ts :: "ty list"and"is"and xt and Tr
fixes mxl and A and r and f and app and eff and step defines [simp]: "mxl ≡ (case b of Static ==> 0 | NonStatic ==> 1)+size Ts+mxl0" defines [simp]: "A ≡ states P mxs mxl" defines [simp]: "r ≡ JVM_SemiType.le P mxs mxl" defines [simp]: "f ≡ JVM_SemiType.sup P mxs mxl"
defines [simp]: "app ≡ λpc. Effect.app (is!pc) P mxs Tr pc (size is) xt" defines [simp]: "eff ≡ λpc. Effect.eff (is!pc) P pc xt" defines [simp]: "step ≡ err_step (size is) app eff"
assumes wf: "wf_prog p P" assumes C: "is_class P C" assumes Ts: "set Ts ⊆ types P"
fixes first :: tyi' and start defines [simp]: "first ≡ Some ([],(case b of Static ==> [] | NonStatic ==> [OK (Class C)]) @ map OK Ts @ replicate mxl0 Err)" defines [simp]: "start ≡ (OK first) # replicate (size is - 1) (OK None)" thm start_context.intro
lemma start_context_intro_auxi: fixes P b Ts p C assumes"b = Static ∨ b = NonStatic " and"wf_prog p P" and"is_class P C" and"set Ts ⊆ types P" shows" start_context P b Ts p C" using start_context.intro[OF JVM_sl.intro] start_context_axioms_def assms by auto
theorem (in start_context) exec_pres_type: "pres_type step (size is) A" (*<*) proof - let ?n = "size is"and ?app = app and ?step = eff let ?mxl = "(case b of Static ==> 0 | NonStatic ==> 1) + length Ts + mxl0" let ?A = "opt((Union {nlists n (types P) |n. n <= mxs}) × nlists ?mxl (err(types P)))" have"pres_type (err_step ?n ?app ?step) ?n (err ?A)" proof(rule pres_type_lift) have"∧s pc pc' s'. s∈?A ==> pc < ?n ==> ?app pc s ==> (pc', s')∈set (?step pc s) ==> s' ∈ ?A" proof - fix s pc pc' s' assume asms: "s∈?A""pc < ?n""?app pc s""(pc', s')∈set (?step pc s)" show"s' ∈ ?A" proof(cases s) case None thenshow ?thesis using asms by (fastforce dest: effNone) next case (Some ab) thenshow ?thesis using asms proof(cases "is!pc") case Load thenshow ?thesis using asms by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def
xcpt_eff_def norm_eff_def
dest: nlistsE_nth_in) next case Push thenshow ?thesis using asms Some by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def
xcpt_eff_def norm_eff_def typeof_lit_is_type) next case Getfield thenshow ?thesis using asms wf by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def
xcpt_eff_def norm_eff_def
dest: sees_field_is_type) next case Getstatic thenshow ?thesis using asms wf by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def
xcpt_eff_def norm_eff_def
dest: sees_field_is_type) next case (Invoke M n) obtain a b where [simp]: "s = ⌊(a,b)⌋"using Some asms(1) by blast show ?thesis proof(cases "a!n = NT") case True thenshow ?thesis usingInvoke asms wf by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def
xcpt_eff_def norm_eff_def) next case False have"(pc', s') ∈ set (norm_eff (Invoke M n) P pc (a, b)) ∨ (pc', s') ∈ set (xcpt_eff (Invoke M n) P pc (a, b) xt)" usingInvoke asms(4) by (simp add: Effect.eff_def) thenshow ?thesis proof(rule disjE) assume"(pc', s') ∈ set (xcpt_eff (Invoke M n) P pc (a, b) xt)" thenshow ?thesis usingInvoke asms(1-3) by (fastforce simp: Effect.app_def xcpt_app_def xcpt_eff_def) next assume norm: "(pc', s') ∈ set (norm_eff (Invoke M n) P pc (a, b))" alsohave"Suc (length a - Suc n) ≤ mxs"usingInvoke asms(1,3) by (simp add: Effect.app_def xcpt_app_def) arith ultimatelyshow ?thesis using False Invoke asms(1-3) wf by (auto simp: Effect.app_def xcpt_app_def norm_eff_def wf_mdecl_def
dest!: sees_wf_mdecl) qed qed next case (Invokestatic C M n) obtain a b where [simp]: "s = ⌊(a,b)⌋"using Some asms(1) by blast have"(pc', s') ∈ set (norm_eff (Invokestatic C M n) P pc (a, b)) ∨ (pc', s') ∈ set (xcpt_eff (Invokestatic C M n) P pc (a, b) xt)" using Invokestatic asms(4) by (simp add: Effect.eff_def) thenshow ?thesis proof(rule disjE) assume"(pc', s') ∈ set (xcpt_eff (Invokestatic C M n) P pc (a, b) xt)" thenshow ?thesis using Invokestatic asms(1-3) by (fastforce simp: Effect.app_def xcpt_app_def xcpt_eff_def) next assume norm: "(pc', s') ∈ set (norm_eff (Invokestatic C M n) P pc (a, b))" alsohave"Suc (length a - Suc n) ≤ mxs"using Invokestatic asms(1,3) by (simp add: Effect.app_def xcpt_app_def) arith ultimatelyshow ?thesis using Invokestatic asms(1-3) wf by (auto simp: Effect.app_def xcpt_app_def norm_eff_def wf_mdecl_def
dest!: sees_wf_mdecl) qed qed (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def
xcpt_eff_def norm_eff_def)+ qed qed thenshow"∀s∈?A. ∀p. p < ?n ⟶ ?app p s ⟶ (∀(q, s')∈set (?step p s). s' ∈ ?A)" by clarsimp qed thenshow ?thesis by (simp add: JVM_states_unfold) qed (*>*)
lemma lesubstep_type_simple: "xs [⊑.le (=) r] ys ==> set xs {⊑} set ys" (*<*) proof - assume assm: "xs [⊑.le (=) r] ys" have"∧a b i y. (a, b) = xs ! i ==> i < length xs ==>∃τ'. (∃i. (a, τ') = ys ! i ∧ i < length xs) ∧ b ⊑ τ'" proof - fix a b i assume ith: "(a, b) = xs ! i"and len: "i < length xs" obtain τ where"ys ! i = (a, τ) ∧ r b τ" using le_listD[OF assm len] ith by (clarsimp simp: lesub_def Product.le_def) thenhave"(a, τ) = ys ! i ∧ b ⊑ τ" by (clarsimp simp: lesub_def) with len show"∃τ'. (∃i. (a, τ') = ys ! i ∧ i < length xs) ∧ b ⊑ τ'" by fastforce qed thenshow"set xs {⊑} set ys"using assm by (clarsimp simp: lesubstep_type_def set_conv_nth) qed (*>*)
declare is_relevant_entry_def [simp del]
lemma conjI2: "[ A; A ==> B ]==> A ∧ B"by blast
lemma (in JVM_sl) eff_mono: assumes wf: "wf_prog p P"and"pc < length is"and
lesub: "s ⊑ P t"and app: "app pc t" shows"set (eff pc s) {⊑ P} set (eff pc t)" (*<*) proof(cases t) case None thenshow ?thesis using lesub by (simp add: Effect.eff_def lesub_def) next case tSome: (Some a) show ?thesis proof(cases s) case None thenshow ?thesis using lesub by (simp add: Effect.eff_def lesub_def) next case (Some b) let ?norm = "λx. norm_eff (is ! pc) P pc x" let ?xcpt = "λx. xcpt_eff (is ! pc) P pc x xt" let ?r = "Product.le (=) (sup_state_opt P)" let ?τ' = "⌊effi (is ! pc, P, a)⌋"
{ fix x assume xb: "x ∈ set (succs (is ! pc) b pc)" thenhave appi: "appi (is ! pc, P, pc, mxs, Tr, a)"and
bia: "P ⊨ b ≤i a"and appa: "app pc ⌊a⌋" using lesub app tSome Some by (auto simp add: lesub_def Effect.app_def) have xa: "x ∈ set (succs (is ! pc) a pc)" using xb succs_mono[OF wf appi bia] by auto thenhave"(x, ?τ') ∈ (λpc'. (pc', ?τ')) ` set (succs (is ! pc) a pc)" by (rule imageI) moreoverhave"P ⊨⌊effi (is ! pc, P, b)⌋≤' ?τ'" using xb xa effi_mono[OF wf bia] appa by fastforce ultimatelyhave"∃τ'. (x, τ') ∈ (λpc'. (pc', ⌊effi (is ! pc, P, a)⌋)) ` set (succs (is ! pc) a pc) ∧ P ⊨⌊effi (is ! pc, P, b)⌋≤' τ'"by blast
} thenhave norm: "set (?norm b) {⊑ P} set (?norm a)" using tSome Some by (clarsimp simp: norm_eff_def lesubstep_type_def lesub_def) obtain a1 b1 a2 b2 where a: "a = (a1, b1)"and b: "b = (a2, b2)" using tSome Some by fastforce thenhave a12: "size a2 = size a1"using lesub tSome Some by (clarsimp simp: lesub_def list_all2_lengthD) have"length (?xcpt b) = length (?xcpt a)" by (simp add: xcpt_eff_def split_beta) moreoverhave"∧n. n < length (?xcpt b) ==> (?xcpt b) ! n ⊑r (?xcpt a) ! n" using lesub tSome Some a b a12 by (simp add: xcpt_eff_def split_beta fun_of_def) (simp add: lesub_def) ultimatelyhave"?xcpt b [⊑r] ?xcpt a" by(rule le_listI) thenhave"set (?xcpt b) {⊑ P} set (?xcpt a)" by (rule lesubstep_type_simple) moreovernote norm ultimatelyhave "set (?norm b) ∪ set (?xcpt b) {⊑ P} set (?norm a) ∪ set (?xcpt a)" by(intro lesubstep_union) thenshow ?thesis using tSome Some by(simp add: Effect.eff_def) qed qed (*>*)
lemma (in start_context) first_in_A [iff]: "OK first ∈ A" using Ts C by (cases b; force intro!: nlists_appendI simp add: JVM_states_unfold)
lemma (in JVM_sl) wt_method_def2: "wt_method P C' b Ts Tr mxs mxl0 is xt τs = (is ≠ [] ∧ (b = Static ∨ b = NonStatic) ∧ size τs = size is ∧ OK ` set τs ⊆ states P mxs mxl ∧ wt_start P C' b Ts mxl0 τs ∧ wt_app_eff (sup_state_opt P) app eff τs)" (*<*)using staticb by (unfold wt_method_def wt_app_eff_def wt_instr_def lesub_def
check_types_def) auto (*>*)
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.