Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Reasoning about modules:data refinement and simulation
David [email protected]
Stevens Institute of Technology
Naumann - POPL’02 Java Verification Workshop – p.1/17
Objectives of talk
• Introduce collaborative projects with• Paulo Borba, Ana Cavalcanti, Augusto
Sampaio; Federal U. of Pernambuco, Recife.• Uday Reddy; University of Birmingham.• Hongseok Yang; Korean Advanced Inst. of Sci.
and Tech. (ROPAS).• Anindya Banerjee; Kansas State University.
• Survey results on simulation for data refinement.• Suggest an approach to pointer confinement.
Naumann - POPL’02 Java Verification Workshop – p.2/17
Outline
• project overview• simulation for alias-free programs• simulation and aliasing (cf. POPL talk)• confinement and patterns• sidelights
Naumann - POPL’02 Java Verification Workshop – p.3/17
Refinement calculus for OOP
Specification statements: x : [pre, post] modifies “onlyx” and establishes post if pre initially; else aborts.Assertion: ∅ : [P, true].Assumption: ∅ : [true, P ].Correctness: x : [pre, post] v prog
Applications:• Formalize stepw ise development (to guide
semi-informal methodology or etc.).Proof rules as refinement laws, e.g.,x, y : [pre, post] v x : [pre,mid]; y : [mid, post]
• Specifications, esp. design patterns with callbacks.• Normal-form compilation.
Naumann - POPL’02 Java Verification Workshop – p.4/17
Refinement calculus for OOP
Specification statements: x : [pre, post] modifies “onlyx” and establishes post if pre initially; else aborts.Assertion: ∅ : [P, true].Assumption: ∅ : [true, P ].Correctness: x : [pre, post] v progApplications:• Formalize stepw ise development (to guide
semi-informal methodology or etc.).Proof rules as refinement laws, e.g.,x, y : [pre, post] v x : [pre,mid]; y : [mid, post]
• Specifications, esp. design patterns with callbacks.• Normal-form compilation.
Naumann - POPL’02 Java Verification Workshop – p.4/17
Project overview• Sequential fragment of Java including: dynamic
dispatch, recursion, visibility control.Omit: pointers, exceptions, concurrency.
• Weakest-precondition semantics without requiringspecifications or behavioral subclassing.
• Aim to extend Morgan’s imperative refinementcalculus, e.g., initially used predicates=formulas.
• Use semantics to prove basic laws.• Compiler status: normal form and VM defined. . .• Design laws: unnesting etc., complete for rewriting
to imperative normal form where classes are usedonly for type tagging and testing [BS01].
Naumann - POPL’02 Java Verification Workshop – p.5/17
Project overview• Sequential fragment of Java including: dynamic
dispatch, recursion, visibility control.Omit: pointers, exceptions, concurrency.
• Weakest-precondition semantics without requiringspecifications or behavioral subclassing.
• Aim to extend Morgan’s imperative refinementcalculus, e.g., initially used predicates=formulas.
• Use semantics to prove basic laws.• Compiler status: normal form and VM defined. . .• Design laws: unnesting etc., complete for rewriting
to imperative normal form where classes are usedonly for type tagging and testing [BS01].
Naumann - POPL’02 Java Verification Workshop – p.5/17
Project overview• Sequential fragment of Java including: dynamic
dispatch, recursion, visibility control.Omit: pointers, exceptions, concurrency.
• Weakest-precondition semantics without requiringspecifications or behavioral subclassing.
• Aim to extend Morgan’s imperative refinementcalculus, e.g., initially used predicates=formulas.
• Use semantics to prove basic laws.• Compiler status: normal form and VM defined. . .• Design laws: unnesting etc., complete for rewriting
to imperative normal form where classes are usedonly for type tagging and testing [BS01].
Naumann - POPL’02 Java Verification Workshop – p.5/17
Project overview• Sequential fragment of Java including: dynamic
dispatch, recursion, visibility control.Omit: pointers, exceptions, concurrency.
• Weakest-precondition semantics without requiringspecifications or behavioral subclassing.
• Aim to extend Morgan’s imperative refinementcalculus, e.g., initially used predicates=formulas.
• Use semantics to prove basic laws.
• Compiler status: normal form and VM defined. . .• Design laws: unnesting etc., complete for rewriting
to imperative normal form where classes are usedonly for type tagging and testing [BS01].
Naumann - POPL’02 Java Verification Workshop – p.5/17
Project overview• Sequential fragment of Java including: dynamic
dispatch, recursion, visibility control.Omit: pointers, exceptions, concurrency.
• Weakest-precondition semantics without requiringspecifications or behavioral subclassing.
• Aim to extend Morgan’s imperative refinementcalculus, e.g., initially used predicates=formulas.
• Use semantics to prove basic laws.• Compiler status: normal form and VM defined. . .
• Design laws: unnesting etc., complete for rewritingto imperative normal form where classes are usedonly for type tagging and testing [BS01].
Naumann - POPL’02 Java Verification Workshop – p.5/17
Project overview• Sequential fragment of Java including: dynamic
dispatch, recursion, visibility control.Omit: pointers, exceptions, concurrency.
• Weakest-precondition semantics without requiringspecifications or behavioral subclassing.
• Aim to extend Morgan’s imperative refinementcalculus, e.g., initially used predicates=formulas.
• Use semantics to prove basic laws.• Compiler status: normal form and VM defined. . .• Design laws: unnesting etc., complete for rewriting
to imperative normal form where classes are usedonly for type tagging and testing [BS01].
Naumann - POPL’02 Java Verification Workshop – p.5/17
Class refinement
class A {private Boolean g; // rep objectunit init(){ g := new Boolean();
g.set(∼true); }unit setg(bool x){ g.set(∼x); }bool getg(){ return ∼g.get(); } }
Equivalent or refined behavior for all clients, e.g.
z:= new A(); z.setg(true); b:= z.getg();
if ∼(pt instanceof ColorPt) skip else abort
Naumann - POPL’02 Java Verification Workshop – p.6/17
Soundness of forward simulation
• Uses: info flow, theory underlying behavioralsubclassing, data refinement...
• Prior work – imperative: single variable (vs. new),non-recursive type, fixed state space, no pointers,no expressions except in [Nau01b]; functional:deterministic, continuous (no specs)
• Soundness of healthy forward simulation for classrefinement (private fields) [CN01].
Naumann - POPL’02 Java Verification Workshop – p.7/17
Soundness of forward simulation
• Uses: info flow, theory underlying behavioralsubclassing, data refinement...
• Prior work – imperative: single variable (vs. new),non-recursive type, fixed state space, no pointers,no expressions except in [Nau01b]; functional:deterministic, continuous (no specs)
• Soundness of healthy forward simulation for classrefinement (private fields) [CN01].
Naumann - POPL’02 Java Verification Workshop – p.7/17
Soundness of forward simulation
• Uses: info flow, theory underlying behavioralsubclassing, data refinement...
• Prior work – imperative: single variable (vs. new),non-recursive type, fixed state space, no pointers,no expressions except in [Nau01b]; functional:deterministic, continuous (no specs)
• Soundness of healthy forward simulation for classrefinement (private fields) [CN01].
Naumann - POPL’02 Java Verification Workshop – p.7/17
Healthy couplings• Early work required simulations to be, e.g.,
surjective functions, but this proved unnecessaryand incomplete.
• [[var x : T • c]]ψ = ∀t ∈ [[T ]] • [[c]]ψsurjective: demonic choice of any concrete initialvalue t must be matched by some abstract choice.
• [[avar x : T • c]]ψ = ∃t ∈ [[T ]] • [[c]]ψtotal: e.g., angelic choice makes(avar x : T • ∅ : [x = v, true]) behave as skipbut if v has no concrete counterpart, it behaves as(avar x : T • ∅ : [false, true]), i.e., abort
• [[x : [pre, post]]]ψ = pre ∧ ∀x • post ⇒ ψ
• A solution: object invariant, choices amongsatisfying values.
Naumann - POPL’02 Java Verification Workshop – p.8/17
Healthy couplings• Early work required simulations to be, e.g.,
surjective functions, but this proved unnecessaryand incomplete.
• [[var x : T • c]]ψ = ∀t ∈ [[T ]] • [[c]]ψsurjective: demonic choice of any concrete initialvalue t must be matched by some abstract choice.
• [[avar x : T • c]]ψ = ∃t ∈ [[T ]] • [[c]]ψtotal: e.g., angelic choice makes(avar x : T • ∅ : [x = v, true]) behave as skipbut if v has no concrete counterpart, it behaves as(avar x : T • ∅ : [false, true]), i.e., abort
• [[x : [pre, post]]]ψ = pre ∧ ∀x • post ⇒ ψ
• A solution: object invariant, choices amongsatisfying values.
Naumann - POPL’02 Java Verification Workshop – p.8/17
Healthy couplings• Early work required simulations to be, e.g.,
surjective functions, but this proved unnecessaryand incomplete.
• [[var x : T • c]]ψ = ∀t ∈ [[T ]] • [[c]]ψsurjective: demonic choice of any concrete initialvalue t must be matched by some abstract choice.
• [[avar x : T • c]]ψ = ∃t ∈ [[T ]] • [[c]]ψtotal: e.g., angelic choice makes(avar x : T • ∅ : [x = v, true]) behave as skipbut if v has no concrete counterpart, it behaves as(avar x : T • ∅ : [false, true]), i.e., abort
• [[x : [pre, post]]]ψ = pre ∧ ∀x • post ⇒ ψ
• A solution: object invariant, choices amongsatisfying values.
Naumann - POPL’02 Java Verification Workshop – p.8/17
Healthy couplings• Early work required simulations to be, e.g.,
surjective functions, but this proved unnecessaryand incomplete.
• [[var x : T • c]]ψ = ∀t ∈ [[T ]] • [[c]]ψsurjective: demonic choice of any concrete initialvalue t must be matched by some abstract choice.
• [[avar x : T • c]]ψ = ∃t ∈ [[T ]] • [[c]]ψtotal: e.g., angelic choice makes(avar x : T • ∅ : [x = v, true]) behave as skipbut if v has no concrete counterpart, it behaves as(avar x : T • ∅ : [false, true]), i.e., abort
• [[x : [pre, post]]]ψ = pre ∧ ∀x • post ⇒ ψ
• A solution: object invariant, choices amongsatisfying values.
Naumann - POPL’02 Java Verification Workshop – p.8/17
Healthy couplings• Early work required simulations to be, e.g.,
surjective functions, but this proved unnecessaryand incomplete.
• [[var x : T • c]]ψ = ∀t ∈ [[T ]] • [[c]]ψsurjective: demonic choice of any concrete initialvalue t must be matched by some abstract choice.
• [[avar x : T • c]]ψ = ∃t ∈ [[T ]] • [[c]]ψtotal: e.g., angelic choice makes(avar x : T • ∅ : [x = v, true]) behave as skipbut if v has no concrete counterpart, it behaves as(avar x : T • ∅ : [false, true]), i.e., abort
• [[x : [pre, post]]]ψ = pre ∧ ∀x • post ⇒ ψ
• A solution: object invariant, choices amongsatisfying values.
Naumann - POPL’02 Java Verification Workshop – p.8/17
Representation exposure
class A {private Boolean g; // rep objectunit init(){ g := new Boolean();
g.set(∼true); }unit setg(bool x){ g.set(∼x); }bool getg(){ return ∼g.get(); }Object bad(){ return g; } }
Client behavior depends on representation:
z := new A(); w := (Boolean) z.bad();if (w.get()) skip else diverge;
Naumann - POPL’02 Java Verification Workshop – p.9/17
Confinement
Boole
C
D
A
A
Client objects Interface objects Representations
disallowed
allowedBoole
Naumann - POPL’02 Java Verification Workshop – p.10/17
Confinement
• Confinement is an end in itself[Boyland,Potter,Clark,Noble,Vitek,Bokowski...]
• Modular reasoning about modification of extendedstate [Leino,Poetzsch-Heffter,Müller...]
• Reasoning about modules: soundness of forward(bi)simulation for sequential Java (sansspecifications and nondeterminacy) [BN02, BN].
Naumann - POPL’02 Java Verification Workshop – p.11/17
Heap confinement for A, Rep
disallowed
C
D
Rep
Rep
A
A
Rep
allowed
conf h iff h has admissible partitionh = hOut ∗ hA1 ∗ hRep1 ∗ . . . ∗ hAn ∗ hRepn withhOut 6; hRepk, hRepk 6; hOut , andhAk ∗ hRepk 6; hAj ∗ hRepj for k 6= j
Naumann - POPL’02 Java Verification Workshop – p.12/17
Pointers
x
y
patvar a, b, c, hturn (x→ a, b) ∗ (y → -, -) ∗ (b→ x, c) ∗ hinto (x→ a, y) ∗ (y → x, b) ∗ (b→ y, c) ∗ h
Naumann - POPL’02 Java Verification Workshop – p.13/17
Explicit confinementAlternative to type system for tracking confinement.To maintain hOut 6; hRep it suffices to checkassignments to cells in hOut.//heap = hOut ∗ (x→ -, b) ∗ hRep with hOut 6; hRep
y := new Rep();
//heap = hOut ∗ (x→ -, b) ∗ hRep ∗ (y → -, nil) with// hOut 6; hRep ∧ hOut 6; (y → -, nil)...
//heap = hOut ∗ (x→ -, y) ∗ hRep ∗ (y → -, b) ∗ with// hOut 6; hRep ∧ hOut 6; (y → -, nil)
Useful for tools that treat types as predicates in anuntyped logic?
Naumann - POPL’02 Java Verification Workshop – p.14/17
Sidelights
• Established theories of parametricity usingexistential types: apply to instance-based visibility[Red98] [elaborating Reynolds]
• Semantics of specification statements:sets-of-state-transformers corresponds toconjunctive predicate transformers[YR00, Nau01a] [Leino&Manohar]
Naumann - POPL’02 Java Verification Workshop – p.15/17
Sidelights
• Established theories of parametricity usingexistential types: apply to instance-based visibility[Red98] [elaborating Reynolds]
• Semantics of specification statements:sets-of-state-transformers corresponds toconjunctive predicate transformers[YR00, Nau01a] [Leino&Manohar]
Naumann - POPL’02 Java Verification Workshop – p.15/17
ReferencesReferences[BN] Anindya Banerjee and David A. Naumann. A static analysis for
instance-based confinement in Java. Submitted.
[BN02] Anindya Banerjee and David A. Naumann. Representation independence,confinement and access control. In POPL, 2002. to appear.
[BS01] P. H. M. Borba and A. C. A. Sampaio. A normal form reduction strategy forROOL: an object-oriented language. Submitted to ESOP, 2001.
[CN01] Ana Cavalcanti and David A. Naumann. Forward simulation for datarefinement of classes. submitted, 2001.
[Nau01a] David A. Naumann. Calculating sharp adaptation rules. InformationProcessing Letters, 77:201–208, 2001.
[Nau01b] David A. Naumann. Soundness of data refinement for a higher orderimperative language. Theoretical Computer Science, 2001. To appear.
[Red98] U. S. Reddy. Objects and classes in Algol-like languages. In Fifth Intern.Workshop on Foundations of Object-oriented Languages, Jan 1998. Fullversion to appear in Information and Computation.
[YR00] H. Yang and U. S. Reddy. On the semantics of refinement calculi. InFoundations of Software Science and Computation Structures, volume 1784,pages 359–374. Springer-Verlag, 2000. Naumann - POPL’02 Java Verification Workshop – p.16/17
Appendix: static confinement
Signatures: C ≤ Rep ⇒ U ≤ A ∨ U ≤ Rep for all U ∈ T
Phrases:C ≤ A ⇒ U >6≤ A
Γ; C � e : U
Γ; C � x.f := e
C 6= A ⇒ B 6≤ Rep
C ≤ A ⇒ B 6≤ A
Γ; C � x := new B( )
mtype(m,D) = (x : T ) → T
C ≤ A ⇒ T >6≤ A
Γ; C � e : D Γ; C � e : U
Γ; C � e.m(e) : T
These suffice for semantic condition stronger thanneeded for abstraction theorem.
Naumann - POPL’02 Java Verification Workshop – p.17/17