assuring object-oriented architecturealdrich/presentations/dahl-nygaard-final.pdf · • flexible...

56
Assuring Object-Oriented Architecture Jonathan Aldrich School of Computer Science Carnegie Mellon University Dahl-Nygaard Junior Prize Lecture ECOOP 2007 August 3, 2007

Upload: others

Post on 18-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

Assuring Object-Oriented Architecture

Jonathan AldrichSchool of Computer ScienceCarnegie Mellon University

Dahl-Nygaard Junior Prize LectureECOOP 2007

August 3, 2007

Page 2: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

2

Assuring Object-Oriented Architecture

• What is Architecture?• High-level design intent• Ensures important program properties

• Examples of Architectural Assurance• High-level object structure• Protocols of behavior

• Requirements for Impact• Natural expression of architectural intent• Provide immediate value and maintain over time• Work with object-oriented designs

• Inheritance, recursion, state, aliasing

Page 3: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

3

1998: What I Learned from Vortex

• Task: adding analysis to Vortex compiler• Optimizing synchronization in Java• As student of Craig Chambers

• How should I do this?• Many sub-tasks• Need to understand where

to plug in to infrastructure• Very difficult!

Infrastructure

Analysisplug-in

Page 4: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

4

1999: I learned about Software Architecture[Perry and Wolf 1992] [Garlan and Shaw 1993]

• Architecture is the fundamental organization of a system, embodied in its components, their relationships to each other and the environment, and the principles governing its design and evolution- ANSI/IEEE Std 1471-2000

Page 5: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

5

What does Architecturemean for Objects?

Page 6: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

6

Objects [Dahl and Nygaard ’67]

Model

Page 7: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

7

Patterns [Gamma, Helm, Johnson, and Vlissides ’95]

Model/ Subject

View

Controller

Factory

Observer

Command

Page 8: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

8

Patterns [Gamma, Helm, Johnson, and Vlissides ’95]

Model/ Subject

View

Controller

Factory

Observer

Command

Page 9: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

9

Architecture [Perry and Wolf 1992] [Garlan and Shaw 1993]

Model/ Subject

View

Controller

Factory

Observer

Command

Page 10: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

10

Object-Oriented Architecture:Patterns and Beyond

Model/ Subject

View

Controller

Factory

Observer

Command

Page 11: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

11

Object-Oriented Architecture:Patterns and Beyond

Model/ Subject

View

Controller

Factory

Observer

Command

/

/

/

/

Page 12: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

12

Object-Oriented Architecture:Patterns and Beyond

Model/ Subject

View

Controller

Factory

Observer

Command

/

/

/

/

Page 13: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

13

Object-Oriented Architecture:Patterns and Beyond

Model/ Subject

View

Controller

Factory

Observer

Command

Page 14: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

14

Object-Oriented Architecture:Patterns and Beyond

Page 15: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

15

Code vs. Execution Structure

Code structure• Shows classes• Shows relationships

• instantiation• calls• references

• Flat graph• Doesn’t scale to large applications• Doesn’t show what’s important

Execution structure• Shows object hierarchy

• Most important objects near root• Grouped according to logical

containment• NOT complete encapsulation• E.g. the Logic tier accesses

courses and students• Also shows relationships

Client

DataStudent

java::util::ArrayList

Logic

Logging

Course

Main«instantiate»

«instantiate»

«instantiate»

«instantiate» - objClient1

- objLogic 1

- objData

1

Main

List<Course>

List<Student>

Student

Course

DataClient

Logging

Logic

Page 16: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

16

Object-Oriented Architecture• High-level design constraints on the structure and

interaction of groups of objects• Shows object structure• Scales from patterns to applications• Assures quality attributes

• Examples• Components will have their own thread and will communicate

through pipes with no shared data [c.f. Erlang]• Benefits: ease of modification, safe concurrency

• Plugins will follow lifecycle constraints on calling framework methods [c.f. EJB, Eclipse]• Benefits: safe reuse of framework code

Page 17: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

17

Assuring Architecture• Even the best architecture may degrade over time

• Implementers may be unaware of architectural constraints• Need architectural knowledge specific to coding context

• Ad-hoc workarounds for architectural limitations• Need mechanism for triggering review/revision or architecture

• My research: static verification of OO architectural structure and behavior• Document architectural constraints in implementation

• Ensures awareness of architecture within a specific context• Verify implementation conforms to architecture

• Ensures architecture evolves as it is needed

• Doing this right for objects is challenging!• Natural expression of architectural constraints• Provide immediate value• Support OO designs, including inheritance, recursion, state,

aliasing

Page 18: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

18

AssuringArchitectural

Structure

Page 19: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

19

ArchJava: Structural Conformance Checkingwith Craig Chambers and David Notkin

• Specifies architecture within implementation• Identifies certain objects as components• Explicitly declares connections between

components• Describe what data is part of which component

• Enforces conformance with types• Can’t pass component references across

architecture• Private data must be confined to its component

Page 20: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

20

public component class Scanner {public port tokens { provides Token next(); }

}

public component class Compiler {private final owned Scanner scanner = new Scanner();private final owned Parser parser = new Parser();private final owned CodeGen codegen = new CodeGen();

connect scanner.tokens, parser.tokens;connect parser.ast, codegen.ast;

}

ArchJava ExampleCompiler

scanner parser codegen

Page 21: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

21

Architectural Conformance in ArchJava• Communication Integrity [Moriconi et al., Luckham et al.]

• Components in the implementationcommunicate only as specifiedin the architecture

• Control Flow Integrity [ECOOP ’02]• All inter-component control flow

falls into one of the following categories:• A parent component invokes a method on one of its

children

Main

View Model

Page 22: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

22

Architectural Conformance in ArchJava• Communication Integrity [Moriconi et al., Luckham et al.]

• Components in the implementationcommunicate only as specifiedin the architecture

• Control Flow Integrity [ECOOP ’02]• All inter-component control flow

falls into one of the following categories:• A parent component invokes a method on one of its

children• A component invokes a method through a connection

Main

View Model

Page 23: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

23

Architectural Conformance in ArchJava• Communication Integrity [Moriconi et al., Luckham et al.]

• Components in the implementationcommunicate only as specifiedin the architecture

• Control and Data Flow Integrity [dissertation, 2003]• All inter-component control and data flow

falls into one of the following categories:• A parent component invokes a method on one of its

children• A component invokes a method through a connection• A component writes to another component’s data, along a

path documented in the architecture• [and two others based on lent/unique annotations]

Main

View Model

Page 24: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

24

What makes it work?

• Ownership [Noble, Vitek, Potter ’98]• Shows which objects are part

of the representation of others• Many contributors: Clarke,

Boyland, Boyapati, Drossopoulou, Smith, Müller, Dietl, Wrigstad, Lu, …

• Challenges:• Structure within objects• Certain design patterns

• New idea: Ownership Domains [ECOOP ’04, PLDI ’05]• Declare multiple domains per

object [Clarke ’01]• Represents a group of objects• Adds flexibility, expressiveness• Maintains strong architectural

reasoning

• Public domains (listeners)• Hold interface objects• Accessible from outside

• Private domains (owned)• Encapsulated• Accessible from public domain

List Main

View Modelowned listeners

Page 25: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

25

• Circuit layout app.• 12 kLOC

• Expressed in ArchJava• 3 days effort

• Benefits observed• Discourages coupling• Aids understanding• Aids defect repair

Case Study: Aphydswith Craig Chambers and David Notkin [ICSE ’02]

Page 26: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

26

• Islamic tile design app.• 12 kLOC

• Expressed in ArchJava• Control architecture only• 5 hours effort

• Observations• Reduced coupling• Expressed dynamic

structure

Case Study: Tapratswith Craig Chambers and David Notkin [ECOOP ’02]

Page 27: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

27

• Optimization app.• 16 kLOC

• Expressed in ArchJava

• Suggestions for improvements in ArchJava

Case Study: HillClimberwith Marwan Abi-Antoun and Wesley Coelho [JSS ’07]

Page 28: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

28

ArchJava Summary• Advantages

• Naturally express architecture within implementation• Write code = specify architecture

• Immediate benefits• Improve code structure, better understanding, facilitates evolution

• Maintain architectural consistency over time• Facilitates engineer architect communication

• Works with OO designs• Flexible model allows interface object aliasing

• Validated in theory and practice• Proof of conformance property• 3 case studies show benefits

• Limitations• Some dynamic idioms awkward• New language and toolset• Cost for converting legacy applications

• Papers, open source implementation• http://www.archjava.org/

Page 29: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

29

Ownership Object Graphswith Marwan Abi-Antoun

• ArchJava, v2.0• No language change: just annotate code• Support more object-oriented designs• Reduce cost

• 5-year vision: a big picture you can trust• Summarize million LOC systems in 1 page• Zoom in to any level of detail

• Look inside a top-level component• Assure that the 1-page summary is complete

• Communication integrity

Page 30: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

30

Architectural Ownership Declarations

@Domains ({"user", "logic", "data"})@DomainLinks ({"user->logic", "logic->data"})public class ThreeTier {

private @Domain("data") Data objData;private @Domain("logic") Logic objLogic;private @Domain("user “) Client objClient;. . .

}

ThreeTier

user

Declarationsare simplified

logic data

objClient objLogic objData

Page 31: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

31

ToolButton

ToolButton

SelectionToolfTool

JavaDrawApp

fListener

PaletteIcon

fIcon

String

fName

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

fName

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

fName

ToolButton

ToolButton

Main app

Undoable

SelectionTool

SelectionTool myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatcher

myEventDispatcher

Object

SelectionToolmyUndoActivity

myDrawingEditor

fChild

AbstractTool$EventDispatchermyEventDispatcher

SelectionTool

SelectionTool myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatcher

myEventDispatcher

SelectionTool

myUndoActivity

myDrawingEditor Tool

fChildAbstractTool$EventDispatchermyEventDispatcher

myUndoActivity

myDrawingEditor

fChild

AbstractTool$EventDispatchermyEventDispatcher

myUndoActivity

JavaDrawAppmyDrawingEditor

fChild

myEventDispatcher

JavaDrawApp

JavaDrawApp

fSelectedToolButton

fDefaultToolButton

fTool

AnimatorfAnimator

DrawingView

fView

VectormdiListeners

fgSampleImagesPath

fApplicationName

fgSampleImagesResourcePath

JComponent

desktop

JTextFieldfStatusLine

EventListenerList

listenerList

fView

AnimatablefAnimatable

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

Vector

mdiListeners

fgSampleImagesPath

fApplicationName

fgSampleImagesResourcePath

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

Vector

mdiListeners

fgSampleImagesPath

fApplicationName

fgSampleImagesResourcePath

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

fgSampleImagesPath

fApplicationName

fgSampleImagesResourcePath

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

fgSampleImagesPath

fApplicationName

fgSampleImagesResourcePath

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

mdiListeners

fgSampleImagesPath

fApplicationName

fgSampleImagesResourcePath

desktop

fStatusLine

listenerList

Rectangle

UndoableHandle

Image

DrawingEditor

ToolfSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatchermyEventDispatcher

DragTracker

myWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatchermyEventDispatcher

myWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatchermyEventDispatcher

DragTracker

myWrappedTool

fSelected

fNormal

fPressed Dimension

fSize

Vector

Object[]elementData

AbstractTool$EventDispatcher myRegisteredListeners

myObservedTool

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

ToolListener

myRegisteredListeners::elts

myObservedTool

myRegisteredListeners

myUndoActivity

myDrawingEditor

myEventDispatcher

Figure

fAnchorFigure POPUP_MENU

listenerList[]NULL_ARRAY[]

Case Study: JHotDraw

• JHotDraw v. 5.3• 195 classes• 15,000 LOC

• Object graph from Womble• Shows details effectively• Does not scale to

high-level view• Unsound

Output of Womble (Jackson and Waingold [JW01])

Page 32: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

32

Case Study: JHotDraw

• Live Demonstration

Page 33: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

33

Case Study: JHotDraw• Architectural structure

• Shows object relationships

• Displays Model-View-Controller design intent

• Fits on a page

• Characteristics• Hierarchical

• Top level objects are summaries

• Can zoom in to details• Sound

• Represents all objects• Shows all field links

Page 34: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

34

Ongoing Work• Increasing expressiveness

• Existential types [Clarke ’01] [Krishnaswami & Aldrich ’05][Lu and Potter ’06] [Dietl et al. ’07]

• Extract richer architectural information• More edge types• Node arities

• Reducing cost with inference• Builds on recent work [Aldrich et al. ’03] [Liu & Milanova ’07]

[Ma & Foster ’07] [Dietl & Müller ’07]

• Prove soundness of architectural extraction

• Case studies to show benefits in practice

Page 35: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

35

AssuringArchitectural

Behavior

Page 36: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

36

Architectural Behaviorwith Kevin Bierhoff

• Source of many defects• Incorrect assumptions about how a component is used

• Pioneering work• Wright [Allen and Garlan, ’97]

• Formalize component protocols using CSP• Model-check for consistency• Found defects in simulation and JavaBeans specs

• Model checking protocols in C• examples: [Chaki et al. ’03], [Giannakopoulou et al ’04]

• Typestates for Objects• [DeLine et al.][Fink et al.][Lam et al.]

• Open problems• Tracking protocols of aliased objects• Protocols for reentrant methods• Supporting object-oriented idioms

• Examples: Pipes and Streams

Page 37: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

37

Pipes in Java

Thread 1

PipeInputStreamPipeOutputStream

Thread 2

1. write()

2. receive()

3. read()

4. close()

Throws exception if PipeOutputStream

not closed

Page 38: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

38

Pipes in Java

Thread 1

PipeInputStreamPipeOutputStream

Thread 2

1. write()

4. close()

2. receive()

5. lastReceived() 3. read()

6. close()

Returns -1 at EOF

• Key intuition• Thread 1 and Thread 2 share the pipe• Thread 1 can’t close until Thread 2 gives Thread 1 the permission to do so• This occurs through close() -> lastReceived() -> read() returning -1

• Idea: apply fractional permissions [Boyland ’03]• Can split permission for an object in half, giving part to each thread• A half permission allows reads/writes, but not closes• Permissions can later be recombined through the lastReceived() call,

allowing the close

Page 39: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

39

Pipes in Java

• Key intuition• Thread 1 and Thread 2 share the pipe• Thread 1 can’t close until Thread 2 gives Thread 1 the permission to do so• This occurs through close() -> lastReceived() -> read() returning -1

• Idea: apply fractional permissions [Boyland ’03]• Can split permission for an object in half, giving part to each thread• A half permission allows reads/writes, but not closes• Permissions can later be recombined through the lastReceived() call,

allowing the close

Thread 1

PipeInputStream

1

Page 40: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

40

Pipes in Java

• Key intuition• Thread 1 and Thread 2 share the pipe• Thread 1 can’t close until Thread 2 gives Thread 1 the permission to do so• This occurs through close() -> lastReceived() -> read() returning -1

• Idea: apply fractional permissions [Boyland ’03]• Can split permission for an object in half, giving part to each thread• A half permission allows reads/writes, but not closes• Permissions can later be recombined through the lastReceived() call ,

allowing the close

Thread 1

PipeOutputStream

Thread 2

PipeInputStream1. write()

4. close()

2. receive()

5. lastReceived() 3. read()

½

½1 ½

1

½

Returns -1 at EOF

6. close()½

Page 41: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

41

Pipes in Java

Thread 1

PipeInputStreamPipeOutputStream

Thread 2

1. write()

4. close()

2. receive()

5. lastReceived() 3. read()

6. close()

Returns -1 at EOF

11

1

• Key intuition• Thread 1 and Thread 2 share the pipe• Thread 1 can’t close until Thread 2 gives Thread 1 the permission to do so• This occurs through close() -> lastReceived() -> read() returning -1

• Idea: apply fractional permissions [Boyland ’03]• Can split permission for an object in half, giving part to each thread• A half permission allows reads/writes, but not closes• Permissions can later be recombined through the lastReceived() call,

allowing the close• Contribution: better support for OO designs

• Allow writes through two pointers• e.g. Thread 1 and Thread 2 are still changing PipeInputStream’s state, but they

can’t close it until the permissions are combined

Page 42: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

42

Pipes Analysis• Verification challenges

• Aliases to the pipe in 2 threads• Data mutated through both aliases

• Cooperative Permissions• Naturally express design intent

• Who’s allowed to do what• How permissions are transferred

• Immediate benefits and assurance as code evolves• Catch incorrect use of architectural pipe connector

• Support OO designs• Allowing shared mutable data

Page 43: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

43

BufferedInputStream Defect

• Live Demonstration

Page 44: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

44

BufferedInputStream Defectint read() {

if (pos >= count) {fill();if (pos >= count) {

return -1;}return buf[pos++];

}

void fill() {pos = 0;count = pos;int n = in.read(buf, pos, buf.length - pos);if (n > 0)

count = n + pos;}

1. Initially pos = count = 0

2. Call fill(…)

3. Sets pos = count = 0

4. Reads n = 8192 chars

5. What is count? 8192, right?

What does the debugger say?

6. pos < count here, so if count = 8192,we should not get an array bounds exception

Page 45: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

45

BufferedInputStream Defectint read() {

if (pos >= count) {fill();if (pos >= count) {

return -1;}return buf[pos++];

}

void fill() {pos = 0;count = pos;int n = in.read(buf, pos, buf.length - pos);if (n > 0)

count = n + pos;}

1. Initially pos = count = 0

2. Call fill(…)

3. Sets pos = count = 0

4. Calls in.read(…)Results in recursive call!

4(a). pos = count = 0, still

4(b). Call fill(…) recursively

4(c). Sets pos = count = 0

4(d). Reads n = 8192 chars4(g). Reads n = 8192 chars4(e). Sets count = 8192

4(f). Sets pos = 1

5. Now pos = 1 so count = 8193!

Eventually pos = 8192: Array out of bounds!

Page 46: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

46

BufferedInputStream Invariantint read() {

if (pos >= count) {fill();if (pos >= count) {

return -1;}return buf[pos++];

}

void fill() {pos = 0;count = pos;int n = in.read(buf, pos, buf.length - pos);if (n > 0)

count = n + pos;}

Invariant: pos should notchange in read(…) call

Page 47: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

47

BufferedInputStream Analyzed• Is it a major defect?

• No; this is unlikely to occur in practice• But documentation does not forbid recursive use• Furthermore, a library should not throw an internal exception

• Anyone here from Sun? Read our defect report!

• Don’t ignore recursion! [Lu et al., ECOOP ’07]• Ubiquitous in object-oriented code• Potential source of very subtle defects

• How to verify?• Forbidding recursion

• Exclusive-write permission in our system or [DeLine et al. ’04]• Omit the stream from the modifies clause in Spec#• Use ownership [Müller ’02][Lu et al. ECOOP ’07]

• Allowing recursion• Our system: use shared permissions, re-set the necessary fields

Page 48: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

48

Verifying BufferedInputStream/* requires full permission on this */int read() {

if (pos >= count) {fill();if (pos >= count) {

return -1;}return buf[pos++];

}

/* requires full permission on this */void fill() {

pos = 0;count = pos;

int n = in.read(buf, pos, buf.length - pos);

if (n > 0)count = n + pos;

}

We have full permission,so no one else can modifypos. The recursive call isforbidden.

Technically there’s a pack-unpackpair surrounding the call.

Page 49: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

49

Verifying BufferedInputStream/* requires shared permission on this */int read() {

if (pos >= count) {fill();if (pos >= count) {

return -1;}return buf[pos++];

}

/* requires shared permission on this */void fill() {

pos = 0;count = pos;int oldpos = pos;int n = in.read(buf, pos, buf.length - pos);pos = oldpos;if (n > 0)

count = n + pos;}

With a shared permission,anyone else could modifythe fields. So we need toreset pos to the value weneed. The recursive callis allowed.

Page 50: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

50

Related Paper

• Tracking Linear and Affine Resources with Java(X)• Tracks object typestate• Relaxes previous work that required

typestate uniqueness

• Today at 14:00, by Markus Degen, Peter Thiemann, and Stefan Wehr

Page 51: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

51

Scaling Cooperative Permissions Up• No implementation yet

• Examples worked by hand suggest the approach can handle new constructs

• Still challenges with decidability, concurrency, practical design

• Ultimate goal: scale to architecture• First step: leverage structure to check behavior

• Specify protocols in ArchJava ports• Interprocedural analysis checks code against protocol• Model checker verifies protocols in architecture are compatible

• Following [Allen and Garlan, ’97]• Technical advances in modular checking and handling recursion

• But limited to static architectures• Bierhoff et al., April 2006 tech report (work ongoing)

• Cooperative Permissions could be used to check architectural protocols without the limitations of ArchJava

Page 52: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

52

Cooperative Permissions - Summary

• Lightweight verification of architectural protocols• Naturally express coordination among pointers

• Follows engineering intuition• Immediate benefits and consistency over time

• Assure correct usage of libraries, frameworks; find defects• Works with OO designs

• Supports aliasing, recursion, and inheritance• Proved sound, validated on small but real examples

• For more, come to OOPSLA 2007!

Page 53: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

53

Assuring Object-Oriented Architecture• High-level design constraints on the structure

and interaction of groups of objects• Abstraction scales beyond design patterns

• Emerging assurance approaches• Architectural structure• Behavioral protocols

• Nearing major impact on practice• Natural expression of architectural intent• Provide immediate value and maintain over time• Work with object-oriented designs

• Inheritance, recursion, state, aliasing

Page 54: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

54

Thanks• Dahl-Nygaard Prize

Committee

• My advisors• Craig Chambers• David Notkin

• My students• Donna Malayeri• Neel Krishnaswami• Marwan Abi-Antoun• Kevin Bierhoff• Nels Beckman• Ciera Jaspan

• Mentors (a few of many!)• My parents• Ron Tennison• Rusty Whitney• Lougie Anderson• Mani Chandy• Susan Eggers• Doug Lea• Gary Leavens• Gail Murphy• David Garlan• Bill Scherlis• Frank Pfenning

Page 55: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

55

Questions?

Page 56: Assuring Object-Oriented Architecturealdrich/presentations/dahl-nygaard-final.pdf · • Flexible model allows interface object aliasing • Validated in theory and practice ... •

7 October 2016 Dahl-Nygaard Lecture© 2007 Jonathan Aldrich

56

Object-Oriented Architecture Principles

• Expressing• Instances matter• Hierarchy is

important for scale• Capture

engineering intuition

• Checking• Allow aliasing• Allow recursion• Support object-

oriented abstractions

We are approaching a revolution in our ability to express and verify the architectural properties on which object-oriented software depends