Environmental Acquisition Revisited Richard Cobbe and Matthias Felleisen Northeastern University Environmental Acquisition Revisited — POPL 2005 – p.1/30
What is Acquisition? Environmental Acquisition Revisited — POPL 2005 – p.2/30
Example: Swing Containers JDialog JRootPane JPanel JPanel JPanel JButton located only at top level � ✁ ☎ ✄ ✂ ✂ ✆ ✝ ✞ must chase pointers to access root pane � ✟ ✄ ✄ ✠ ✂ ✝ Environmental Acquisition Revisited — POPL 2005 – p.3/30
Example: Financial Application Fund Account TaxInfo taxPolicy Fund funds MutualFund FundGroup int fundID Fund funds int balance TaxInfo taxPolicy TaxInfo getTaxPolicy() { ... } Operations on s must know tax policy � ✄ ✁ ✂ Environmental Acquisition Revisited — POPL 2005 – p.4/30
Example: Financial Application Fund Account TaxInfo taxPolicy contains Fund funds MutualFund FundGroup int fundID contains Fund funds int balance TaxInfo taxPolicy acquires TaxInfo taxPolicy Operations on s must know tax policy � ✄ ✁ ✂ With acquisition, no longer need to maintain and chase parent refs Environmental Acquisition Revisited — POPL 2005 – p.4/30
Example: IDE Wizard Dialog HorizontalPanel ... ClassUnionWizard errorMessage( ) produce( ) VariantPanel add( ) produce( ) UnionInfo errorMessage( ) vPanel Environmental Acquisition Revisited — POPL 2005 – p.5/30
Example: Wizard with Acquisition Dialog HorizontalPanel ... ClassUnionWizard errorMessage( ) produce( ) VariantPanel add( ) produce( ) UnionInfo acquires errorMessage( ) vPanel Environmental Acquisition Revisited — POPL 2005 – p.6/30
Containment Invariants Invariants ensured by language support for acquisition: Environmental Acquisition Revisited — POPL 2005 – p.7/30
Containment Invariants Invariants ensured by language support for acquisition: Objects allow access to their containers � Environmental Acquisition Revisited — POPL 2005 – p.7/30
Containment Invariants Invariants ensured by language support for acquisition: Objects allow access to their containers � Two-way links (or their analog) are consistent � Environmental Acquisition Revisited — POPL 2005 – p.7/30
Restrictions on Acquisition Limit object’s “environment” to its containers � Only specifically marked fields establish containment � relationship An object may have at most one container � Object containment cycles forbidden � Environmental Acquisition Revisited — POPL 2005 – p.8/30
Jacques : the Formal Model Environmental Acquisition Revisited — POPL 2005 – p.9/30
Jacques Based on ClassicJava , formal model of Java by Flatt, Krishnamurthi, and Felleisen (1998). Supported features: core OO: classes, inheritance, method dispatch � field assignment � Environmental Acquisition Revisited — POPL 2005 – p.10/30
Jacques Based on ClassicJava , formal model of Java by Flatt, Krishnamurthi, and Felleisen (1998). Supported features: core OO: classes, inheritance, method dispatch � field assignment � field and method acquisition � explicit marks for “containment” fields � list of possible containers in class definitions � Environmental Acquisition Revisited — POPL 2005 – p.10/30
Environmental Acquisition Revisited — POPL 2005 – p.11/30 ✌ ✌ ✁ ✞ ✒ ✟ ✝ ✆ ☞ ✑ ✆ ☎ ✑ ☛ ✁ ✑ ✆ ☎ ✡ ✌ ✄ ✝ ✝ ✂ ✂ ✕ ✘ ☎ ☛ ✝ ☎ ✂ ✄ ✚ ☞ ✂ ✂ ✒ ✘ ✓ ✂ ✆ ✝ ✑ ✁ ✂ ☎ ✑ Wizard Example ✟ ☞ ✠ ✒ ✑ ✝ ✄ ✏ ✙ ✂ ✁ ✞ ✌ ✑ ✟ ✞ ✄ ✔ ✏ ✑ ✝ ✝ ✞ ✝ ✞ ✕ ✑ ✆ ✘ ✞ ✞ ✂ ✑ ✆ ☎ ✄ ✄ ✌ ✑ ✞ ✎ ✁ ✂ ✄ ✑ ✠ ✞ ✞ ✂ ✔ ✕ ✝ ✟ ✁ ✞ ✞ ✑ ✆ ✞ ✗ ✂ ✄ � ✑ ✝ ✠ ☎ ☞ ✝ ☎ ✑ ✝ ✆ ✟ ✟ ✄ ✂ ✔ ✝ ✟ ☞ ✆ ☎ ✞ ✂ ✆ ✝ ✟ ☞ ☞ ✄ ✝ ✝ ✆ ✂ ✖ ✞ ☎ ✆ ☞ ✂ ☎ ✝ ✆ ✟ ✟ ✟ ☎ ✄ ✄ ☞ ✍ ✄ ☎ ☎ ☎ ✑ ✆ ✠ ✂ ✂ ✂ ✑ ✍ ✎ ✎ ✎ ✂ ✂ ✟ ✑ ✂ ✂ ✆ ✆ ✁ ✁ � ✒ � ✒
Environmental Acquisition Revisited — POPL 2005 – p.12/30 ✏ ✌ ✁ ✕ Jacques : Wizard Example ✘ ✞ ✟ ✝ ✂ ✆ ✚ ☞ ✆ ☎ ✘ ☛ ✁ ✆ ✝ ☎ ✌ ✡ ✄ ☎ ✝ ✝ ✟ ☞ ☞ ✂ ✂ ✄ ✏ ✆ ✙ ☎ ✁ ☛ ✝ ☛ ✞ ☎ ✔ ✄ ✝ ☞ ✞ ☎ ✆ ✡ ✘ ✂ ✂ ✒ ✆ ✓ ✝ ✂ ☎ ✆ ✎ ✂ ✂ ✑ ✁ ✂ ✂ ☎ ✑ ✟ ✝ ✠ ✁ ✒ ✞ ✑ ✝ ✄ ✗ ✞ ✝ ☞ ✂ ✞ ✂ ✌ ✑ ✟ ✆ ✂ ✄ ✂ ✏ ✑ ✝ ✞ ✆ ✝ ☎ ☞ ✕ ✑ ☞ ✞ ✄ ✞ ✁ ✂ ✑ ✝ ✠ ✄ ✄ ✌ ✞ ✑ ✆ ✞ ✁ ✄ ✑ ✟ ✠ ✟ ✞ ✞ ☎ ✔ ✕ ☞ ✝ ✟ ✞ ✞ ☎ ✑ ✆ ✆ ✝ ✂ ✄ � ✂ ✑ ✍ ✠ ☎ ✎ ✝ ☎ ☎ ✑ ✝ ✆ ✟ ✟ ✄ ✔ ✝ ✟ ✆ ✂ ✄ ✞ ✂ ✂ ✆ ✝ ✝ ✝ ✟ ☞ ✞ ✝ ✆ ✂ ✂ ✖ ☞ ☎ ☎ ✆ ☞ � ✂ ☎ ☎ ✝ ✆ ✟ ✟ ✠ ✄ ✄ ✄ � ✝ ✍ ✄ ☎ ☎ ✑ ✠ ✂ ✂ ✂ � ✑ ✎ ✎ ✆ ✂ � ✂ ✟ ✑ ✂ ✂ ✆ ✆ ✁ ✁ � ✒ � ✒
Static Check I A B : contained A C : contained B D : contained C bool fd int fd contains D d acquires int fd contains B b contains C c Environmental Acquisition Revisited — POPL 2005 – p.13/30
Static Check I A B : contained A C : contained B D : contained C bool fd int fd contains D d acquires int fd contains B b contains C c acquires from , and types match. � ✝ ✟ ✟ Program is well-typed. Environmental Acquisition Revisited — POPL 2005 – p.13/30
Static Check II A B : contained A C : contained B D : contained C bool fd int fd bool fd acquires int fd contains B b contains C c contains D d Environmental Acquisition Revisited — POPL 2005 – p.14/30
Static Check II A B : contained A C : contained B D : contained C bool fd int fd bool fd acquires int fd contains B b contains C c contains D d acquires from , and types are not compatible. ✠ � ✝ ✟ Program is not well-typed. Environmental Acquisition Revisited — POPL 2005 – p.14/30
Design Decisions Environmental Acquisition Revisited — POPL 2005 – p.15/30
Running Example Ctnr1 Ctnr2 Prop1 fd Prop2 fd contains Item it contains Item it Prop1 meth(Property p) { ... } Property meth(Prop2 x) { ... } Property Item : contained Ctnr1, Ctnr2 ... acquires Property fd acquires Property meth(Prop2) Prop1 Prop2 ... ... Environmental Acquisition Revisited — POPL 2005 – p.16/30
Acquisition by Value and by Name aCtnr1 : Ctnr1 anItem : Item aCtnr2 : Ctnr2 contains Item it acquires Property fd contains Item it Prop1 fd Prop2 fd When does acquire ’s value? ✆ ✝ ✟ ✄ ✆ ✞ ✝ ✚ Environmental Acquisition Revisited — POPL 2005 – p.17/30
Acquisition by Value and by Name aCtnr1 : Ctnr1 anItem : Item aCtnr2 : Ctnr2 contains Item it acquires Property fd contains Item it Prop1 fd Prop2 fd When does acquire ’s value? ✆ ✝ ✟ ✄ ✆ ✞ ✝ ✚ By value: when is placed into . ✠ � ✆ ✄ ✄ � ✆ ✝ ✞ ✚ ✆ ✝ ☞ Environmental Acquisition Revisited — POPL 2005 – p.17/30
Acquisition by Value and by Name aCtnr1 : Ctnr1 anItem : Item aCtnr2 : Ctnr2 contains Item it acquires Property fd contains Item it Prop1 fd Prop2 fd When does acquire ’s value? ✆ ✝ ✟ ✄ ✆ ✞ ✝ ✚ By value: when is placed into . ✠ � ✆ ✄ ✄ � ✆ ✝ ✞ ✚ ✆ ✝ ☞ By name: when is referenced. ✆ ✝ ✟ ✄ � ✆ ✝ ✞ ✚ ✑ Environmental Acquisition Revisited — POPL 2005 – p.17/30
Acquisition by Value and by Name aCtnr1 : Ctnr1 anItem : Item aCtnr2 : Ctnr2 contains Item it acquires Property fd contains Item it Prop1 fd Prop2 fd When does acquire ’s value? ✆ ✝ ✟ ✄ ✆ ✞ ✝ ✚ By value: when is placed into . ✠ � ✆ ✄ ✄ � ✆ ✝ ✞ ✚ ✆ ✝ ☞ By name: when is referenced. ✆ ✝ ✟ ✄ � ✆ ✝ ✞ ✚ ✑ Both are sound; primarily affects visibility of assignments. Environmental Acquisition Revisited — POPL 2005 – p.17/30
Acquisition by Value and by Name aCtnr1 : Ctnr1 anItem : Item aCtnr2 : Ctnr2 contains Item it acquires Property fd contains Item it Prop1 fd Prop2 fd Two questions with acquisition-by-value: Environmental Acquisition Revisited — POPL 2005 – p.18/30
Acquisition by Value and by Name aCtnr1 : Ctnr1 anItem : Item aCtnr2 : Ctnr2 contains Item it acquires Property fd contains Item it Prop1 fd Prop2 fd Two questions with acquisition-by-value: null ; 1. ✠ � ☎ ✄ ✄ ✆ ✝ ☞ : � ✑ : previous value or undefined? ✆ ✝ ✟ ✄ ✆ ✝ ✞ ✚ ✑ Environmental Acquisition Revisited — POPL 2005 – p.18/30
Recommend
More recommend