1 / 26

An Exception Aware Behavioral Type System for Object-Oriented Programs

This paper introduces a type system that statically checks the observable behavior of objects, ensuring termination and handling exceptions in object-oriented programs.

sfrancois
Download Presentation

An Exception Aware Behavioral Type System for Object-Oriented Programs

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. An Exception Aware Behavioral Type System for Object-Oriented Programs CITI / Departamento de Informática Universidade Nova de Lisboa - Portugal Filipe Militãoand LuísCaires CoRTA 2009

  2. TravelOrderClass class TravelOrder { void flight(){ … } void hotel(){ … } void buy(){ … } void cancel(){ … } string show(){ … } }

  3. TravelOrderDocumentation /** * A TravelOrder requires the selection of * a flight and an hotel before it can be bought * or canceled. */

  4. TravelOrderClass class TravelOrder { void flight(){ … } void hotel(){ … } void buy(){ … } void cancel(){ … } string show(){ … } } only available on specific situations can be called freely

  5. Background • Increasing software complexity • Effort to eliminate bugs • Faster feedback on errors (static detection)

  6. Objectives and Contributions • Statically check the externally observable behavior of objects (based on formal description) • Guarantee termination (reaches stop) • Exceptions (checked) • Linear ownership + Borrowing (call-by-ref) • Class body consistent with class behavior • Working prototype

  7. Checking call sequences TravelOrder object flight(…) hotel(…) buy() . buy flight . hotel • Hidden internal state (like in regular expressions) • Tracks observable calls (i.e., the behavior), not states

  8. What is a Behavioral Type? TravelOrder Type Type TravelOrder Behavior Behavioral void hotel() void flight() void order() void cancel() string show() 1stflight 2ndhotel 3rdbuy or cancel +

  9. Describing the Behavior • What about “string show()” ? free / non-behavioral, can be called at any time... TravelOrder Behavior 1stflight 2ndhotel 3rdbuy or cancel • Regular expression-like protocol: flight . hotel . (buy + cancel)

  10. TravelOrderClass class TravelOrder { void flight(){ … } void hotel(){ … } void buy(){ … } void cancel(){ … } string show(){ … } } usage flight.hotel.(buy+cancel)

  11. Example let tin t = new TravelOrder(); t.flight(); t.show(); t.hotel(); if( … ) t.buy() else t.cancel() flight . hotel . stop ( buy + cancel )

  12. The rest of this talk… • Introduction • Type System • Exceptions • Linear Ownership • Borrowing • Subtyping • Consistency check • Related work • Future work

  13. Basic typing judgement expression environment (before) environment (after) type of expression

  14. Sequence e0 e1 T0 T1 Will be lost!

  15. Example (try branch) voidmethod(N#buy[Error: undo] v){ try v.buy() catch(Errorexcp) v.undo() } on Error{v undo } [Error: undo] v stop buy

  16. Example (catch branch) voidmethod(N#buy[Error: undo] v){ try v.buy() catch(Errorexcp) v.undo() } on Error{v undo } undo v stop

  17. Exceptions - throw expression produces compatible environment Runtime is behavior agnostic, so thrown object must be stopped Exception handler for N

  18. Exceptions - try catch Try branch with new exception handler Catch branch restores old handler etry T throw “N” ecatch

  19. Linear Ownership • Only one owner at a time* ( *unless the object was borrowed… ) let t0in let t1 in t0 = new TravelOrder(); t1 = t0 ; t1.flight(); t0.hotel() Type Error! t1  stop t0  flight. hotel.(buy+cancel)

  20. Borrowing • Checking call-by-reference let tin t= new TravelOrder(); orderStuff(t); t.buy() voidorderStuff(TravelOrder#flight.hotelx) t flight.hotel. (buy+cancel) • Storing values requires ownedpermission

  21. The rest of this talk… • Introduction • Type System • Exceptions • Linear Ownership • Borrowing • Subtyping • Consistency check • Related work • Future work

  22. Subtyping • Structural subtyping • Requires compatible behavior • Subtype must accept same behavior as super… (flight+swim).hotel <: flight.hotel flight.hotel <: flight[Full: cancel].hotel

  23. Consistency check • Server code must also obey protocols class ABC { usage a.b.c TravelOrdert; void a(){t = new TravelOrder();} void b(){t.flight(); } void c(){ t.buy(); } } Type Error!

  24. Related work • Resource usage analysis (2002) Atsushi Igarashi and Naoki Kobayashi • Lightweight object specification with typestates (2007) Kevin Bierhoff and Jonathan Aldrich • Dynamic interfaces (2009) Vasco T. Vasconcelos, Simon Gay, AntónioRavara, Nils Gesbert, and Alexandre Z. Caldeira. • …

  25. Future work • Concurrency

  26. Questions? Filipe Militãoand LuísCaires • Paper: • Web site: An Exception Aware Behavioral Type System for Object-Oriented Programs yak prototype http://ctp.di.fct.unl.pt/yak/

More Related