Static Extraction of Hierarchical Runtime Object Graphs...

62
Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration Marwan Abi-Antoun Jonathan Aldrich School of Computer Science Carnegie Mellon University

Transcript of Static Extraction of Hierarchical Runtime Object Graphs...

Page 1: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Static Extraction of Hierarchical Runtime Object Graphs –Tool Demonstration

Marwan Abi-Antoun Jonathan Aldrich

School of Computer Science

Carnegie Mellon University

Page 2: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

2

Object-Oriented Code vs. Runtime Structure

“An object-oriented program's runtime structureoften bears little resemblance to its code structure.

The code structure [...] consists of classes in fixed inheritance relationships.

A program's runtime structure consists of [...]

networks of communicating objects [...]

Trying to understand one from the other is like trying

to understand the dynamism of living ecosystems from the static taxonomy of plants and animals, and

vice versa.” (Gamma et al., 1994)

Page 3: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

3

Object Diagram: a diagram of object structures which shows object instances exclusively.

Source: E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1994. (CD-ROM edition)

[…]

[…]

Page 4: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

4

ToolButton

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

PaletteIcon

fIcon

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

ToolButton

ToolButton

Main

app

Undoable

SelectionTool

SelectionTool

myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatchermyEventDispatcher

Object

SelectionTool

myUndoActivity

myDrawingEditorfChild

AbstractTool$EventDispatchermyEventDispatcher

SelectionTool

SelectionTool

myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatcher

myEventDispatcher

SelectionTool

myUndoActivity

myDrawingEditor

ToolfChild

AbstractTool$EventDispatchermyEventDispatcher

myUndoActivitymyDrawingEditor

fChild

AbstractTool$EventDispatcher

myEventDispatcher

myUndoActivity

JavaDrawApp

myDrawingEditor

fChild

myEventDispatcher

JavaDrawApp

JavaDrawApp

fSelectedToolButton

fDefaultToolButton

fTool

Animator

fAnimator

DrawingView

fView

Vector

mdiListeners

JComponent

desktop

JTextField

fStatusLine

EventListenerListlistenerList

fView

AnimatablefAnimatable

fDefaultToolButton

fSelectedToolButton

fTool

fAnimator

fView

Vector

mdiListeners

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

Vector

mdiListeners

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

mdiListeners

desktop

fStatusLine

listenerList

Rectangle

UndoableHandle

Image

DrawingEditor

Tool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatcher

myEventDispatcher

DragTrackermyWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatchermyEventDispatcher

myWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatcher

myEventDispatcher DragTracker

myWrappedTool

fSelected

fNormal

fPressed

DimensionfSize

Vector

Object[]elementData

AbstractTool$EventDispatcher

myRegisteredListeners

myObservedTool

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

ToolListener

myRegisteredListeners::elts

myObservedTool

myRegisteredListeners

myUndoActivity

myDrawingEditor

myEventDispatcher

Figure

fAnchorFigure

listenerList[]

NULL_ARRAY[]

Tool support to extract runtime structure less mature

• Low-level objects

• No architectural abstraction

• Some analyses incorrectlyhandle aliasing

JavaDrawApp,

DrawingEditor,

represent one

runtime object.

Output of Womble on JHotDraw (15 KLOC)

Page 5: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Key Insight

Ownership domain annotations enable the extraction of sound hierarchical object graphs using static analysis.

Page 6: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

6

Extracting sound hierarchical object graphs using static analysis

• Why static analysis?• Dynamic analysis shows object graphs for

a few program runs, not all

• Why sound?• To be most useful, show all objects and

relations that could exist at runtime

Page 7: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

7

Model

View

Controller

figureChangeEvent(+):DrawingChangeEvent

fPoly(+):Shape

textFigure1(+):Drawing

myBorderOffset(+):Point2D

polyLineConnector(+):Connector

fStartDecoration(+):AbstractLineDecoration

fLocator(+):Locator

undoableHandle(+):Handle

myDrawingView(+):DrawingView

myUndoableActivity(+):UndoableAdapter

myAlignment(+):Alignment

myUndoManager(+):UndoManager

fStorageFormatManager(+):StorageFormatManager

myDefaultStorageFormat(+):StorageFormat

fAnimator(+):Thread

autoscrollInsets(+):Insets

app(+):DrawingEditor

fDefaultToolButton(+):ToolListener

textTool(+):Tool

bufferedUpdateStrategy(+):Painter

constrainer(+):PointConstrainer

menu(+):CommandListener

cmd(+):Command

system:Main

Extracting sound hierarchical object graphs using static analysis

• Hierarchical graphs• Flat graphs do not

provide architectural abstraction or scale

ToolButton

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

PaletteIcon

fIcon

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

ToolButton

ToolButton

Main

app

Undoable

SelectionTool

SelectionTool

myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatchermyEventDispatcher

Object

SelectionTool

myUndoActivity

myDrawingEditorfChild

AbstractTool$EventDispatchermyEventDispatcher

SelectionTool

SelectionTool

myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatcher

myEventDispatcher

SelectionTool

myUndoActivity

myDrawingEditor

ToolfChild

AbstractTool$EventDispatchermyEventDispatcher

myUndoActivitymyDrawingEditor

fChild

AbstractTool$EventDispatcher

myEventDispatcher

myUndoActivity

JavaDrawApp

myDrawingEditor

fChild

myEventDispatcher

JavaDrawApp

JavaDrawApp

fSelectedToolButton

fDefaultToolButton

fTool

Animator

fAnimator

DrawingView

fView

Vector

mdiListeners

JComponent

desktop

JTextField

fStatusLine

EventListenerListlistenerList

fView

AnimatablefAnimatable

fDefaultToolButton

fSelectedToolButton

fTool

fAnimator

fView

Vector

mdiListeners

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

Vector

mdiListeners

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

mdiListeners

desktop

fStatusLine

listenerList

Rectangle

UndoableHandle

Image

DrawingEditor

Tool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatcher

myEventDispatcher

DragTrackermyWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatchermyEventDispatcher

myWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatcher

myEventDispatcher DragTracker

myWrappedTool

fSelected

fNormal

fPressed

DimensionfSize

Vector

Object[]elementData

AbstractTool$EventDispatcher

myRegisteredListeners

myObservedTool

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

ToolListener

myRegisteredListeners::elts

myObservedTool

myRegisteredListeners

myUndoActivity

myDrawingEditor

myEventDispatcher

Figure

fAnchorFigure

listenerList[]

NULL_ARRAY[]

Page 8: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

8

Demonstration Outline

• Ownership annotations• Adding annotations

• Typechecking annotations

• Runtime structure• Extraction tool

• Real-World Example• JHotDraw

• Additional material• Static analysis

Page 9: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Ownership Domains

Page 10: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

10

Ownership domains[Aldrich and Chambers, ECOOP’04]

• Each object defines conceptual groups (ownership domains) to hold its state

• Separate object’s internals from object’s boundary (accessible to outside)

• Ensure private state not leaked

• Distinguish different “subsystems” within object

Page 11: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

11

Example: Sequence

head iterator

@Domains@Domains@Domains@Domains({“ownedownedownedowned”, “itersitersitersiters”})

classclassclassclass Sequence {

@Domain@Domain@Domain@Domain(“ownedownedownedowned”) Cons head;

public public public public @Domain@Domain@Domain@Domain(“itersitersitersiters”)

Iterator iterator() {return new return new return new return new Iterator(head);

}

}

Object

LEGEND

• Sequence has private state (head)• Should not be accessible to outside

• Sequence has iterators that are accessible to outside• Can also access private state

seq: Sequence

Page 12: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

12

Sequence Code Structure

Page 13: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

13

Sequence: Private Domain

• Each object has one or more domains• E.g., Sequence declares domains owned and iters

• Each object is in exactly one domain• E.g., head in domain owned; iterator in domain iters

head

owned

@Domains@Domains@Domains@Domains({“ownedownedownedowned”, “itersitersitersiters”})

classclassclassclass Sequence {

@Domain@Domain@Domain@Domain(“ownedownedownedowned”) Cons head;

public public public public @Domain@Domain@Domain@Domain(“itersitersitersiters”)

Iterator iterator() {return new return new return new return new Iterator(head);

}

}

seq: Sequence

Object

LEGEND

Domain

Page 14: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

14

Sequence: Public Domain

• Each object has one or more domains• E.g., Sequence declares domains owned and iters

• Each object is in exactly one domain• E.g., head in domain owned; iterator in domain iters

head iterator

owned iters

@Domains@Domains@Domains@Domains({“ownedownedownedowned”, “itersitersitersiters”})

classclassclassclass Sequence {

@Domain@Domain@Domain@Domain(“ownedownedownedowned”) Cons head;

public public public public @Domain@Domain@Domain@Domain(“itersitersitersiters”)

Iterator iterator() {return new return new return new return new Iterator(head);

}

}

seq: Sequence

Object

Domain

LEGEND

Page 15: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

15

Sequence Runtime Structure

state

list

iters

owned

object:Object

it:Iterator

cons:Cons

seq:Sequence

system:SequenceClient

Page 16: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

16

Sequence Runtime Structure

• Collapse Sequence’s sub-structure

statelist

object:

Object

seq(+):

Sequencesystem:

SequenceClient

Page 17: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

17

Encapsulation and Containment

(1) Strict encapsulation(private domain)

(2) Logical containment(public domain)

OWNED

seq:Sequence

head:ConsX

seq:Sequence

it:Iterator

ITERS

Page 18: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

18

Annotation Tool Support

• Use Java 1.5 annotations

• Typechecker uses Eclipse JDT

• Warnings in Eclipse’s problem window

Page 19: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

19

Demo: Checking Sequence

• Cannot return head of list• Head of list in private domain

• Stronger than making field private

• Cannot nullify head of list• Stronger than Java visibility (e.g., private)

• Iterate over list• Iterator in public domain

Page 20: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

20

Ownership Domain Parameters

@DomainParams@DomainParams@DomainParams@DomainParams({“elemselemselemselems”})classclassclassclass Sequence {@Domain@Domain@Domain@Domain(“ownedownedownedowned<elemselemselemselems>”)Cons head;

…………}

@DomainParams@DomainParams@DomainParams@DomainParams({“elemselemselemselems”})classclassclassclass Cons {

@@@@DomainDomainDomainDomain(“elemselemselemselems”) Object obj; @@@@DomainDomainDomainDomain(“ownerownerownerowner<elemselemselemselems>”) Cons next;

}

• To share objects across domains• Add domain parameter to hold elements in list• Implicit domain parameter “owner”

(Same as me, a.k.a. “peer” or “same”)

ownedclientobjects

elems

seq : Sequence

:Cons

owner

Page 21: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Demo: Annotating Listeners

(Iteration 1)

Page 22: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

22

Listeners Example

• Listeners tricky in object-oriented code

• Reuse annotated Sequence• Disguised as ArrayList

Page 23: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

23

Listeners Code Structure

interfaceinterfaceinterfaceinterface Listener { }

classclassclassclass BaseChart implementsimplementsimplementsimplements Listener {

List< Listener> listeners;}classclassclassclass BarChart extendsextendsextendsextends BaseChart { }

classclassclassclass PieChart extendsextendsextendsextends BaseChart { }

classclassclassclass Model implementsimplementsimplementsimplements Listener {List<Listener> listeners;}

classclassclassclass Main {Model model;BarChart barChart;PieChart pieChart;

}

Class diagram by Eclipse UML.

Page 24: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

24

Demo: Listeners example

• Tool to add default annotations• Declare owned private domain• Private field à place in domain owned

• owned: object fully encapsulated

• String à mark shared• shared: shared persistently or globally

• Method parameter à mark lent• lent: temporary alias within method

• Not a smart inference tool!

Page 25: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

25

Standard and third-party libraries

• Annotate external code• Ideally, library provider adds annotations• Annotations shared amongst authors

• Only annotate parts of library in use

• Wizard to generate skeleton XML file

Page 26: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

26

Listeners Runtime Structure (version 1)

• Listeners at the top-level

DOCUMENT VIEW

model:

Model

listeners:

List<Listener>

barChart:

BarChart

pieChart:

PieChart

listeners:

List<Listener>

Page 27: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Runtime Structure

Page 28: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

28

Code Structure – Take 1

interfaceinterfaceinterfaceinterface Listener { }

classclassclassclass BaseChart implementsimplementsimplementsimplements Listener {

List< Listener> listeners;}classclassclassclass BarChart extendsextendsextendsextends BaseChart { }

classclassclassclass PieChart extendsextendsextendsextends BaseChart { }

classclassclassclass Model implementsimplementsimplementsimplements Listener {List<Listener> listeners;}

classclassclassclass Main {Model model;BarChart barChart;PieChart pieChart;

}

Class diagram extracted by Eclipse UML.

Page 29: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

29

Code Structure – Take 2

interfaceinterfaceinterfaceinterface Listener { }

classclassclassclass BaseChart implementsimplementsimplementsimplements Listener {

List< Listener> listeners;}classclassclassclass BarChart extendsextendsextendsextends BaseChart { }

classclassclassclass PieChart extendsextendsextendsextends BaseChart { }

classclassclassclass Model implementsimplementsimplementsimplements Listener {List<Listener> listeners;}

classclassclassclass Main {Model model;BarChart barChart;PieChart pieChart;

}Class diagram by AgileJ.

Page 30: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

30

• Who points to who?

• Do not distinguish between conceptually different instances of same class

• Extra details: abstract classes, interfaces, etc.

• No hierarchy

Code vs. Runtime Structure

DOCUMENT

VIEW

Class diagram extracted by AgileJ.

Page 31: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Demo: Annotating Listeners

(Iteration 2)

Page 32: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

32

Change annotations

• Instance encapsulation

• May require changing code to avoid representation exposure, e.g., • Return copy instead of alias to internal List• Pass object linearly

Page 33: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

33

Listeners Runtime Structure (version 2)

DOCUMENT

OWNED

VIEW

OWNED

OWNED

listeners:List<Listener>

barChart:BarChart

pieChart:PieChart

model:Model

listeners:List<Listener>

listeners:List<Listener>

X

pieChart.OWNED != barChart.OWNED

Page 34: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

34

Abstraction by Ownership Hierarchy

• Push secondary objects underprimary objects using

(1) Strict encapsulation(private domain)

(2) Logical containment(public domain)

OWNED

seq:Sequence

head:ConsX

seq:Sequence

it:Iterator

ITERS

Page 35: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

35

Hierarchy Provides Abstraction

• Can collapse object sub-structure

• Summary edges account for hidden objects

DOCUMENT

VIEW

model(+):Model

barChart(+):BarChart

pieChart(+):PieChart

Page 36: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

36

Tool Features

• Control projection depth

• Collapse/expand substructure• Selected domain or • Selected object

• Summary edges

• Elide private domains

• Control object labeling

Page 37: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Case Study: JHotDraw

Page 38: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

38

Extract As-BuiltRuntime Graph

Extract As-BuiltRuntime Graph

AnnotationsAnnotations

1. Add

3. Refine and iterate

CodeCode

Annotation/Extraction Process

2. Control Display4. (Optional) Change

code and refine

Page 39: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

39

Annotation/Extraction Process

1. Choose top-level domains

2. Achieve desired number of objects in top-level domainsa) Push secondary objects under primary objectsb) Use abstraction by types to merge objects

3. Achieve appropriate visual detaila) Collapse or expand substructure of objectsb) Change projection depth across all objects

Page 40: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

40

ConnectionFigure

Connector

DecoratorFigure

Handle

NullHandle TrackHandle

Locator

0..*

0..*

0..*2

Painter

PointConstrainer

Tool

DrawingEditor

DrawingView

CreationTool SelectionToolHandleTracker

Figure

Drawing

0..*

CompositeFigure

JHotDraw: Code Structure

Manually generated UML Class Diagram for JHotDraw [Riehle, Thesis 2000].

Page 41: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

41

View

Model

Controller

ConnectionFigure

Connector

DecoratorFigure

Handle

NullHandle TrackHandle

Locator

0..*

0..*

0..*2

Painter

PointConstrainer

Tool

DrawingEditor

DrawingView

CreationTool SelectionToolHandleTracker

Figure

Drawing

0..*

CompositeFigure

JHotDraw: Model-View-Controller (MVC)

Page 42: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

42

JHotDraw: Adding Annotations to Code

File: Main.java

Page 43: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

43

JHotDraw: “30-second Architecture”

• Hide contents of domains• Dotted edges summarize field references

• Interestingly: no callback from M to C

Model

View

Controller

Main

Page 44: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

44

JHotDraw: “30-minute Architecture”

Model

View

Controller

figureChangeEvent(+):DrawingChangeEvent

fPoly(+):Shape

textFigure1(+):Drawing

myBorderOffset(+):Point2D

polyLineConnector(+):Connector

fStartDecoration(+):AbstractLineDecoration

fLocator(+):Locator

undoableHandle(+):Handle

myDrawingView(+):DrawingView

myUndoableActivity(+):UndoableAdapter

myAlignment(+):Alignment

myUndoManager(+):UndoManager

fStorageFormatManager(+):StorageFormatManager

myDefaultStorageFormat(+):StorageFormat

fAnimator(+):Thread

autoscrollInsets(+):Insets

app(+):DrawingEditor

fDefaultToolButton(+):ToolListener

textTool(+):Tool

bufferedUpdateStrategy(+):Painter

constrainer(+):PointConstrainer

menu(+):CommandListener

cmd(+):Command

system:Main

Showing top-

level domains

and objects

LEGEND

formal_domain

domain1

domain2

Object:DeclaredType

Object1_with_Substructure (+):DeclaredType1

Object2:DeclaredType2

domain link

RootObject:Type

field reference

Page 45: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

45

Model

owned

owned

View

Controller

figureChangeEvent(+):DrawingChangeEvent

fPoly(+):Shape

fFigures:Vector<Figure>

textFigure1:Drawing

_theQuadTree(+):QuadTree

fMap:MapfAttributes:

FigureAttributes

fDisplayBox:Shape

fPoints:Vector<Point>

myBorderOffset(+):Point2D

fListeners:Vector<DrawingChangeListener>

myDrawingView(+):DrawingView

fDrawingLockHolder:Runnable

polyLineConnector(+):Connector

fStartDecoration(+):AbstractLineDecoration

fLocator(+):Locator

undoableHandle(+):Handle

myUndoableActivity(+):UndoableAdapter

myAlignment(+):Alignment

myUndoManager(+):UndoManager

fStorageFormatManager(+):StorageFormatManager

myDefaultStorageFormat(+):StorageFormat

fAnimator(+):Thread

autoscrollInsets(+):Insets

app(+):DrawingEditor

fDefaultToolButton(+):ToolListener

textTool(+):Tool

bufferedUpdateStrategy(+):Painter

constrainer(+):PointConstrainer

menu(+):CommandListener

cmd(+):Command

system:Main

JHotDraw: “30-minute Architecture”

Showing Drawing’s sub-

structure

ToolButton

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

PaletteIcon

fIcon

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

ToolButton

SelectionTool

fTool

JavaDrawApp

fListener

fIcon

ToolButton

ToolButton

Main

app

Undoable

SelectionTool

SelectionTool

myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatchermyEventDispatcher

Object

SelectionTool

myUndoActivity

myDrawingEditorfChild

AbstractTool$EventDispatchermyEventDispatcher

SelectionTool

SelectionTool

myUndoActivity

JavaDrawApp

myDrawingEditor

Tool

fChild

AbstractTool$EventDispatcher

myEventDispatcher

SelectionTool

myUndoActivity

myDrawingEditor

ToolfChild

AbstractTool$EventDispatchermyEventDispatcher

myUndoActivitymyDrawingEditor

fChild

AbstractTool$EventDispatcher

myEventDispatcher

myUndoActivity

JavaDrawApp

myDrawingEditor

fChild

myEventDispatcher

JavaDrawApp

JavaDrawApp

fSelectedToolButton

fDefaultToolButton

fTool

Animator

fAnimator

DrawingView

fView

Vector

mdiListeners

JComponent

desktop

JTextField

fStatusLine

EventListenerListlistenerList

fView

AnimatablefAnimatable

fDefaultToolButton

fSelectedToolButton

fTool

fAnimator

fView

Vector

mdiListeners

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

Vector

mdiListeners

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

mdiListeners::elts

fAnimator

fView

desktop

fStatusLine

listenerList

fSelectedToolButton

fDefaultToolButton

fTool

fAnimator

fView

mdiListeners

desktop

fStatusLine

listenerList

Rectangle

UndoableHandle

Image

DrawingEditor

Tool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatcher

myEventDispatcher

DragTrackermyWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatchermyEventDispatcher

myWrappedTool

fSelectGroup

fAnchorHandle

myDrawingEditor

AbstractTool$EventDispatcher

myEventDispatcher DragTracker

myWrappedTool

fSelected

fNormal

fPressed

DimensionfSize

Vector

Object[]elementData

AbstractTool$EventDispatcher

myRegisteredListeners

myObservedTool

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

myRegisteredListeners

myObservedTool

ToolListener

myRegisteredListeners::elts

myObservedTool

myRegisteredListeners

myUndoActivity

myDrawingEditor

myEventDispatcher

Figure

fAnchorFigure

listenerList[]

NULL_ARRAY[]

Output of Womble

JHotDraw Runtime Object Graph

Page 46: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

Static Analysis

Page 47: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

47

Static analysis

• Build TypeGraph from program’s AST

• Convert to ObjectGraph that soundly approximates all runtime object graphs (ROG)

ROG: graph where nodes represent runtime objects, edges represent reference or usage relations

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 48: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

48

TypeGraph: show types, domains inside types, and objects in domains

BarChart

OWNED

listeners: List<Listener>

Main

DOCUMENT

VIEW

pieChart: PieChart

barChart:BarChart

model:Model List<Listener>

OWNED

head

ELTS

obj: Listener

M

Is-Aobj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 49: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

49

ObjectGraph: instantiate types, starting with root

BarChart

OWNED

listeners: List<Listener>

Main

DOCUMENT

VIEW

pieChart: PieChart

barChart:BarChart

model:Model List<Listener>

OWNED

head

ELTS

obj: Listener

M

Is-Aobj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 50: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

50

ObjectGraph: instantiate types, starting with root

BarChart

OWNED

listeners: List<Listener>

main: Main

DOCUMENT

VIEW

pieChart: PieChart

barChart:BarChart

model:Model List<Listener>

OWNED

head

ELTS

obj: Listener

M

Is-Aobj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 51: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

51

BarChart

OWNED

listeners: List<Listener>

ObjectGraph: instantiate types, show domains and objects inside domains

main: Main

DOCUMENT

VIEW

pieChart: PieChart

barChart:BarChart

model:Model List<Listener>

OWNED

head

ELTS

obj: Listener

M

Is-Aobj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 52: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

52

ObjectGraph: instantiate types, show domains and objects inside domains

main: Main

DOCUMENT

VIEW

pieChart: PieChart

barChart:BarChart

model:Model List<Listener>

OWNED

head

ELTS

obj: Listener

BarChart

OWNED

listeners: List<Listener>

M

Is-Aobj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 53: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

53

main: Main

VIEW

pieChart: PieChart…

ObjectGraph: instantiate types, show domains and objects inside domains

barChart: BarChart

OWNED

listeners: List<Listener>

List<Listener>

OWNED

head

ELTS

obj: Listener

MIs-A

obj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

DOCUMENT

model: Model…

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 54: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

54

main: Main

VIEW

pieChart: PieChart…

ObjectGraph: instantiate types, show domains and objects inside domains

barChart: BarChart

OWNED

listeners: List<Listener>

List<Listener>

OWNED

head

ELTS

obj: Listener

MIs-A

obj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

DOCUMENT

model: Model…

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 55: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

55

main: Main

VIEW

pieChart: PieChart…

ObjectGraph: instantiate types, show domains and objects inside domains

barChart: BarChart

OWNED

listeners: List<Listener>

List<Listener>

OWNED

head

ELTS

obj: Listener

MIs-A

obj: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

DOCUMENT

model: Model…

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 56: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

56

main: Main

VIEW

pieChart: PieChart…

DOCUMENT

ObjectGraph: instantiate types, show domains and objects inside domains

model: Model…

barChart: BarChart

OWNED

M

listeners: List<Listener>

OWNED

head

ELTS

obj: Listener obj:

TypeObject

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 57: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

57

main: Main

VIEW

pieChart: PieChart…

DOCUMENT

ObjectGraph: pull objects from formal domains to actual domains

model: Model…

barChart: BarChart

OWNED

M

listeners: List<Listener>

OWNED

head

ELTS

obj: Listener obj:

TypeObject

F

A

Formal Domain

Actual Domain

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 58: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

58

main: Main

VIEW

pieChart: PieChart…

DOCUMENT

ObjectGraph: pull objects from formal domains to actual domains

model: Model…

barChart: BarChart

OWNED

M

listeners: List<Listener>

OWNED

head

ELTS

obj: Listener obj:

TypeObject

F

A

Formal Domain

Actual Domain

obj: Listener

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 59: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

59

main: Main

VIEW

pieChart: PieChart…

DOCUMENT

ObjectGraph: pull objects from formal domains to actual domains

model: Model…

barChart: BarChart

OWNED

M

listeners: List<Listener>

OWNED

head

ELTS

obj: Listener obj:

TypeObject

F

A

Formal Domain

Actual Domain

obj: Listener

obj: Listener

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 60: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

60

main: Main

VIEW

pieChart: PieChart…

DOCUMENT

ObjectGraph: merge objects, in one domain, that may alias, based on types

{model: Model, obj:Listener}…

barChart: BarChart

OWNED

M

listeners: List<Listener>

OWNED

head

ELTS

obj: Listener obj:

TypeObject

F

A

Formal Domain

Actual Domain

obj: Listener

class Model implements Listener {…}

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 61: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

61

main: Main

VIEW

pieChart: PieChart…

DOCUMENT

ObjectGraph: add edges to represent field references

{model: Model, obj:Listener}…

barChart: BarChart

OWNED

M

listeners: List<Listener>

OWNED

head

ELTS

obj: Listener obj:

TypeObject

F

A

Formal Domain

Actual Domain

obj: Listener

● Problem ● Approach ● Analysis ● Evaluation ● Conclusion

Page 62: Static Extraction of Hierarchical Runtime Object Graphs ...mabianto//talks/08-demo-extraction-talk.pdf · Static Extraction of Hierarchical Runtime Object Graphs – Tool Demonstration

62

Conclusion

• Ownership domain annotationsenable extraction of hierarchicalruntime object graphs using static analysis

• Provide architectural abstraction by ownership hierarchy and by types