1 / 28

Flexible Immutability with Frozen Objects

Flexible Immutability with Frozen Objects. K. Rustan M. Leino Microsoft Research Peter Müller ETH Zurich Angela Wallenburg Chalmers University. Executive summary. Context Verification system for object-oriented programs Contribution

Mercy
Télécharger la présentation

Flexible Immutability with Frozen Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Flexible Immutability with Frozen Objects K. Rustan M. LeinoMicrosoft Research Peter MüllerETH Zurich Angela WallenburgChalmers University

  2. Executive summary • Context • Verification system for object-oriented programs • Contribution • Specification and structuring technique for objects that no longer undergo change

  3. Object Invariants • class C {int x, y, z;invariant x < 0  y ≤ z;} • Boogie methodology (used in Spec#) • Spec# demo: shows/ads

  4. Invariants over multiple objects :C • class C { T t;invariantt.x = 10;} • class D { T s;invariants.x = 23;} • Spec# demo: guitar/level :D t s :T

  5. Ownership :C • class C {rep T t;invariantt.x = 10;} • class D {rep T s;invariants.x = 23;} • Spec# demo: rep :D t owner s :T owner :T

  6. Object states • An object is valid if it is not exposed • (o  o.owner.valid o.valid) • An object is consistent if it is valid and its owner is not valid • Spec# demo: strum :RockBand :Guitar :GtString :GtString

  7. Classes of immutable objects • Spec# demo: roadie/immutable

  8. Classes of immutable objects • Spec# demo: roadie/immutable • Example summary: • Cannot share a rep object • Base class of immutable class cannot be mutable • Cannot apply mutable methods on an immutable object

  9. Frozen objects • Indicate which instances, not just whole classes, are immutable • Indicate when an object becomes immutable • Frozen objects can be mentioned in invariants • freeze operation transfers ownership to an fictitious freezer object

  10. Using frozen in RockBand • classRockBand {frozen Roadie rd;invariantrd.Strength = 5;RockBand() { Roadie r = new Roadie(5);r.SchlepInstruments();r.PrepareStage();freeze r; rd = r; } …}

  11. RockBand picture freezer :RockBand rd gt owner owner :Guitar :Roadie

  12. Immutable classes revisited • Special case of frozen objects • Frozen objects give good encoding of immutable classes

  13. Alternative design • Partial ownership • Chalice demo: RockBand

  14. Chalice demo: RockBand classRockBand { var r: Roadie invariantrd(r) && r != null invariantacc(r.strength) && r.strength == 5 method Main() { vararnold := new Roadie arnold.strength := 5 varabba := newRockBand abba.r := arnold shareabba varnoDoubt := newRockBand noDoubt.r := arnold sharenoDoubt } } class Roadie { var strength: int } Monitor invariant might not hold. Insufficient fraction at 4.13 for Roadie.strength.

  15. Conclusion • Frozen objects are flexible. A program can: • decide which instances are frozen • decide when each instance becomes frozen • Frozen objects can fit into any system with ownership and ownership transfer • Frozen objects can encode immutable types • Invariants can be written over frozen objects • Future: implement in Spec# • http://research.microsoft.com/specsharp

More Related