+ All Categories
Home > Documents > Practical Static Extraction and Conformance Checking of ...

Practical Static Extraction and Conformance Checking of ...

Date post: 14-Nov-2021
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
166
1 Practical Static Extraction and Conformance Checking of the Runtime Architecture of Object-Oriented Systems Marwan Abi-Antoun Jonathan Aldrich School of Computer Science Carnegie Mellon University © 2009 Marwan Abi-Antoun and Jonathan Aldrich. All rights reserved.
Transcript
Page 1: Practical Static Extraction and Conformance Checking of ...

1

Practical Static Extraction and Conformance Checking of the Runtime Architecture of Object-Oriented Systems

Marwan Abi-Antoun Jonathan Aldrich

School of Computer Science

Carnegie Mellon University

© 2009 Marwan Abi-Antoun and Jonathan Aldrich. All rights reserved.

Page 2: Practical Static Extraction and Conformance Checking of ...

2

Software architecture: high-level description of a system’s organization

• Communication between stakeholders

• Analyzing quality attributes:• Maintainability,

• Security, performance, reliability …

• Different perspectives or views:• Code architecture

• Runtime architecture• Distinct but complementary• Focus today is on structure, not behavior

Page 3: Practical Static Extraction and Conformance Checking of ...

3

Code architecture shows code structure (classes, inheritance, etc.)

• Code architecture represents static code structure of system• Classes, packages, modules, layers, ..

• Inherits from class, implements interface

• Dependencies: imports, calls graphs.

• Impacts qualities like maintainability

• Mature tool support

Page 4: Practical Static Extraction and Conformance Checking of ...

4

Runtime architecture shows objects (instances) and relations between them

• Runtime architecture models runtime structure as runtime components and potential runtime interactions• Runtime component = sets of objects• Runtime interaction = e.g., points-to relation

• Impacts qualities such as security, performance, reliability, …

• Immature tool support

Page 5: Practical Static Extraction and Conformance Checking of ...

5

Analyze quality attribute, assuming architecture reflects all communication

Network

Contacts

Contacts

WSD

Control

Panel

Settings

Settings

Settings

API Boundary

Registry

Me Store

WAB

User

Application

User

Other Boundary

User Interactions• Microsoft uses threat

modeling and claims 50% reduction in vulnerabilities

• Security experts review

hand-drawn diagrams

(Vista has 1,400 diagrams)

• Checking conformance of

implementation to

architecture not addressed

• Potential security violationsRedacted diagram for

Windows Vista™ subsystem

Page 6: Practical Static Extraction and Conformance Checking of ...

6

Security analysis requires runtime architecture, not code architecture

Class diagram DFD

Page 7: Practical Static Extraction and Conformance Checking of ...

7

Security analysis requires runtime architecture, not code architecture

Class diagram Object diagram

Page 8: Practical Static Extraction and Conformance Checking of ...

8

Disclaimer: security architecture

• Threat modeling uses a Data Flow Diagram (DFD) with security annotations

• This presentation uses a different architectural style: a security architecture shows points-to (not data flow) connectors, has no explicit data stores or external interactors, and uses more general boundaries that are tiers.

Page 9: Practical Static Extraction and Conformance Checking of ...

9

Example security runtime architecture

• Runtime components and connections

• Hierarchicaldecomposition

• Partitioning into tiers

DFD Legend

BoundaryProcess

Data store

Dataflow

External

Interactor

TRUST LEGEND

Trusted

Partially Trusted

Untrusted

User Tier

Logic Tier

Data Tier

Web (-)Client

BusinessLogic(+)

Request (-)Response (+)

Data (+)Access

CRUD (+) CRUD (+)

Registration File (+)

RegistrationInfo(+)

Settings File (#)

Settings(+)Registration

Info(+)Settings(#)

Page 10: Practical Static Extraction and Conformance Checking of ...

10

Data (+)Access

Registration File (+)

RegistrationInfo(+)

Settings File (#)

Settings(+)

Registry

RegistrationInfo(+)

Settings(#) Application <-> Registry

Some analyses must consider worst case of possible communication

• Results valid only if model is sound

• Sound: reveal all objects and relations that may exist at runtime – in any run

Entry points in implementation not reflected in architecture

Page 11: Practical Static Extraction and Conformance Checking of ...

11

Architectural extraction’s key property: soundness

• Definition: a runtime architecture is sound if it represents all runtime components and all possible interactions between those components.

• Informal Visio diagram often unsound

Page 12: Practical Static Extraction and Conformance Checking of ...

12

Data (+)Access

Registration File (+)

RegistrationInfo(+)

Settings File (#)

Settings(+)Registration

Info(+)Settings(#)

Runtime structure distinguishes between different instances of the same class

• Different instances usually have different architectural properties• Here, trustLevel = Full vs. Partial• Usually, one java.io.File class in class diagram

Two instances can have different values for crucial

trustLevelproperty.

TRUST LEGEND

Trusted

Partially Trusted

Untrusted

Page 13: Practical Static Extraction and Conformance Checking of ...

13

Data (+)Access

Registration File (+)

RegistrationInfo(+)

Settings File (#)

Settings(+)Registration

Info(+)Settings(#)

Aliasing or state sharing is a challenge in representing a runtime architecture

• Impacts architectural properties• Settings File (trustLevel = Partial)• vs. Registration File (trustLevel = Full)

• Combine these two instances into one?

Assume ‘Registration File’ and ‘Settings File’distinct, with different values for trustLevel.

Assume one File DataStore, with one value for trustLevel.

Data (+)Access

File(+)

FileData(+)

FileData(+)

TRUST LEGEND

Trusted

Partially Trusted

Untrusted

Page 14: Practical Static Extraction and Conformance Checking of ...

14

Other key property: aliasing soundness

• Definition: an architecture is sound w.r.t. aliasing if no one runtime entity appears as two “components” in the architecture

• Otherwise, could assign two different values of trustLevel architectural property for one true runtime entity

Page 15: Practical Static Extraction and Conformance Checking of ...

15

Architectural extraction: state-of-the-art

• Using static analysis still open problem• Can capture all possible executions

• Extract low-level non-architectural views

• Analyses often unscalable

• Using dynamic analysis• Analyze one or more program runs

• May miss important objects or relations

that arise only in other program runs

• E.g., security analysis must handle worst, not typical, possible runtime communication

Page 16: Practical Static Extraction and Conformance Checking of ...

16

Two components should communicate only if architecture allows them to do so

• E.g., prohibit direct comunication between

certain components, for all program runs

This edge should appear even if it occurs in 1 / 1,000,000 runs!

User Tier

Logic Tier

Web (-)

Client

Business

Logic(+)

Request (-)

Data (+)

Access

OOPS!

Response (+)

CRUD (+) CRUD (+)

Page 17: Practical Static Extraction and Conformance Checking of ...

17

Checking structural conformance of system to target architecture

• Key property: communication integrity

Definition: each component in the implementation may only communicate directly with the components to which it is connected in the architecture.[Moriconi et al., TSE’95] [Luckham and Vera, TSE’95]

• Informal diagrams omit communication; confirmed by experience at Microsoft [Murphy et al.,TSE’01] [Aldrich et al., ICSE’02]

Page 18: Practical Static Extraction and Conformance Checking of ...

18

Previous work to ensure conformance of runtime architecture has drawbacks

• Runtime monitoring• Cannot check all possible program runs

• Code generation• Hard to use for existing systems• More general to extract-abstract-check

• Language-based solutionsArchJava [Aldrich et al., ECOOP’02]

• Restrictions on object references

• Require re-engineering existing systems

• Library-based solutions

Page 19: Practical Static Extraction and Conformance Checking of ...

19

Today, you will learn SCHOLIA

SCHOLIA: static conformance checking of object-based structuralviews of architecture.

Scholia are annotations inserted on the margin of an ancient manuscript. The approach supports existing, i.e., legacy systems, and uses annotations.

Page 20: Practical Static Extraction and Conformance Checking of ...

20

First entirely static end-to-end approach to guarantee communication integrity for Java

• SCHOLIA relates code in widely-used object-

oriented language (Java) and a hierarchical

intended runtime architecture:

• Extract instance structure • Hierarchy provides abstraction

• Achieve soundness

• Abstract instance structure into architecture

• Structurally compare hierarchical views

• Check conformance • Enforce communication integrity

Page 21: Practical Static Extraction and Conformance Checking of ...

21

At SCHOLIA’s core is the static extraction of architectural runtime structure

• Extract sound object graph that conveys architectural abstraction by hierarchy and by types• Uses static analysis• Achieves soundness• Relies on backward-compatible statically

type-checkable annotations

• Minimally invasive hints about architecture

• Instead of using new language or library

Page 22: Practical Static Extraction and Conformance Checking of ...

22

Conformance checking uses general strategy of extract-abstract-check

• Extract instance structure • Add annotations to code

• Run static analysis

• Abstract into built architecture

• Document designed/target architecture

• Compare built and designed views

• Check conformance

Page 23: Practical Static Extraction and Conformance Checking of ...

23

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

Page 24: Practical Static Extraction and Conformance Checking of ...

24

Code vs. Execution StructureClasses ObjectsTypes InstancesStatic Runtime

Illustrated using example

Aphyds, an 8,000-line Java system

Page 25: Practical Static Extraction and Conformance Checking of ...

25

Developer posits a target hierarchical runtime architecture

user interface

viewerUI

floorplanUI placeRouteUI

channelRouteUI

partitioner

floorplanner placer

globalRouter

channelRouter

computational code

circuit

circuit database

node net

Page 26: Practical Static Extraction and Conformance Checking of ...

26

user interface

viewerUI

floorplanUI placeRouteUI

channelRouteUI

partitioner

floorplanner placer

globalRouter

channelRouter

computational code

circuit

circuit database

node net

Developer posits a target hierarchical runtime architecture

Page 27: Practical Static Extraction and Conformance Checking of ...

27

Class diagram shows code structure, e.g., classes, inheritance

VectorCircuit

NodeNode

NetTerminal

- circuit

- circuit

- circuit

«instantiate»

«instantiate»

- tnet

- tnode

Class

Page 28: Practical Static Extraction and Conformance Checking of ...

28

Object diagram shows instance structure, i.e., objects and relations

circ:Circuit

LEGEND

object:Type

Page 29: Practical Static Extraction and Conformance Checking of ...

29

In hierarchical object structure, an object can contain other objects

...

circ:Circuit

DB

circuit

circuit database

node net

LEGEND

object:Type

Page 30: Practical Static Extraction and Conformance Checking of ...

30

Instead of objects directly owning others, use domains to group related objects

...

circ:Circuit

DB

Box nesting indicates “inside”

object:Type

Public domain

LEGEND

Page 31: Practical Static Extraction and Conformance Checking of ...

31

A public domain in an object defines a conceptual group of contained objects

...

circ:Circuit

DB

Box nesting indicates “inside”

object:Type

Public domain

LEGEND

Page 32: Practical Static Extraction and Conformance Checking of ...

32

Placing object ‘net’ in domain ‘DB’ inside ‘circuit’ makes ‘net’ part of ‘circuit’

Box nesting indicates “inside”

DB

...

circ:Circuit

net:Net

object:Type

Public domain

LEGEND

Page 33: Practical Static Extraction and Conformance Checking of ...

33

Any object that can reference ‘circuit’ can also reference ‘net’ inside ‘DB’ domain

DB

...

circ:Circuit

net:Net

Thin border indicates logical containment

object:Type

Public domain

LEGEND

Page 34: Practical Static Extraction and Conformance Checking of ...

34

Each object can have domains, e.g., ‘net’has ‘OWNED’ domain and ‘terms’ inside it

DB

OWNED

...

terms:Vector<Terminal>

net:Net

circ:Circuit

object:Type

Public domain

Private domain

LEGEND

Box nesting indicates “inside”

Page 35: Practical Static Extraction and Conformance Checking of ...

35

A private domain defines a strict encapsulation or ownership model

DB

OWNED

...

terms:Vector<Terminal>

net:Net

circ:Circuit

object:Type

Public domain

Private domain

LEGEND

‘terms’ is in private domain of ‘net’

Page 36: Practical Static Extraction and Conformance Checking of ...

36

‘terms’ is strictly encapsulated inside ‘net’and cannot be leaked/aliased to outside

DB

OWNED

...

terms:Vector<Terminal>

net:Net

circ:Circuit

Xobject:Type

Public domain

Private domain

LEGEND

Thick border indicates strict encapsulation

Page 37: Practical Static Extraction and Conformance Checking of ...

37

Unlike class diagram, object diagram shows distinct ‘Vector’ instances

DB

OWNEDOWNED

...

terms:Vector<Terminal>

term:Terminal

node:Node

terms:Vector<Terminal>

net:Net

circ:Circuit

object:Type

Public domain

Private domain

LEGEND

But ‘terms’ Vectors can share other objects

Page 38: Practical Static Extraction and Conformance Checking of ...

38

Hierarchy allows varying abstraction level, by collapsing or expanding objects

DB

...

term:Terminal

node (+):Node

net (+):Net

circ:Circuit

(+) indicates collapsed sub-structure

object:Type

Public domain

Private domain

LEGEND

Page 39: Practical Static Extraction and Conformance Checking of ...

39

Central difficulty

Architectural hierarchy not readily observable in program written in general purpose programming language

Page 40: Practical Static Extraction and Conformance Checking of ...

40

All previous static analyses extract non-hierarchical abstractions

• Object graph analyses• Without using annotations

[Jackson and Waingold, ICSE’99,TSE’01][O’Callahan, Ph.D. thesis’01]

• Using non-ownership annotations[Lam and Rinard, ECOOP’03]

• Some unsound w.r.t. aliasing or inheritance

• Related static analyses• Points-to analysis [e.g., Milanova et al., TOSEM’05]

• Shape analysis [e.g., Sagiv et al., POPL’99]

Page 41: Practical Static Extraction and Conformance Checking of ...

41

Flat object graphs do not provide architectural abstraction

• Low-level objects mixed with architecturally significant ones• Show plethora of objects

• No scale-up to large programs

• Require graph summarization to get readability [Mitchell, ECOOP’06]

Output of WOMBLE (MIT) [Jackson and Waingold, TSE’01]on 8,000-line system.

Page 42: Practical Static Extraction and Conformance Checking of ...

42

Key insight

Add ownership annotations and leverage them using static analysis

Page 43: Practical Static Extraction and Conformance Checking of ...

43

Use hierarchy to convey architectural abstraction

• Pick top-level entry point

• Use ownership to impose conceptual hierarchy

• Convey abstraction by ownership hierarchy:• Architecturally significant

objects near top of hierarchy

• Low-level objects demoted

further down

Page 44: Practical Static Extraction and Conformance Checking of ...

44

Collapse objects based on ownership (and types) to achieve abstraction

Non-hierarchical

graph

Hierarchical graph

UI

MODEL

DB

ChannelRouteUI(+)

Viewer(+)

Channel(+)

Circuit

PartitionUI(+)

Partitioner(+)

FloorplanUI(+)

PlaceRouteUI(+)

Placer(+)

Floorplanner(+)

GlobalRouter(+)

Node(+) Terminal Net(+)

Page 45: Practical Static Extraction and Conformance Checking of ...

45

Add and check ownership domain annotations

Step 1

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 46: Practical Static Extraction and Conformance Checking of ...

46

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 47: Practical Static Extraction and Conformance Checking of ...

47

Group objects into ownership domains

classclassclassclass Main {

domaindomaindomaindomain UIUIUIUI, , , , MODELMODELMODELMODEL;;;;

UIUIUIUI Viewer viewerUI;

MODELMODELMODELMODEL Circuit circuit;

...

}

Main

UI

Declarations

are simplified

MODEL

viewerUI circuit

• Ownership domain = conceptual group of objects

• Each object in exactly one domain

object: Type

Object

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 48: Practical Static Extraction and Conformance Checking of ...

48

Domains can be declared inside each class

classclassclassclass Circuit {

domaindomaindomaindomain DBDBDBDB;;;;

DBDBDBDB Node node;

DBDBDBDB Net net;

...

}

Circuit

DB

Declarations

are simplified

node net

object: Type

Object

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 49: Practical Static Extraction and Conformance Checking of ...

49

Aphyds: concrete annotations

@Domains({@Domains({@Domains({@Domains({““““UIUIUIUI””””, , , , ““““MODELMODELMODELMODEL””””})})})})

classclassclassclass Main {

@Domain(@Domain(@Domain(@Domain(““““UIUIUIUI””””)))) Viewer viewerUI;

@Domain(@Domain(@Domain(@Domain(““““MODELMODELMODELMODEL””””)))) Circuit circuit;

...

}

• Tools use existing language support for annotations (available in Java 1.5, C#, …)

• Annotations do not change runtime semantics

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 50: Practical Static Extraction and Conformance Checking of ...

50

Circuit: private domain

• Each object has one or more domains

• E.g., Circuit declares domains owned and DB

• Each object is in exactly one domain

• E.g., nodes in domain owned

nodes:Vector

owned

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

classclassclassclass Circuit {

@@@@DomainDomainDomainDomain(“ownedownedownedowned”) Vector nodes;

}

circ: Circuit

Object

LEGEND

Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 51: Practical Static Extraction and Conformance Checking of ...

51

Circuit: public domain

• Each object has one or more domains

• E.g., Circuit declares domains owned and DB

• Each object is in exactly one domain

• E.g., nodes in domain owned; node in domain DB

nodes:Vector

node:Node

owned DB

@@@@DomainsDomainsDomainsDomains({“ownedownedownedowned”, “DBDBDBDB”})

classclassclassclass Circuit {

@@@@DomainDomainDomainDomain(“ownedownedownedowned”) Vector nodes;

@Domain@Domain@Domain@Domain(“DBDBDBDB”) Node node;

}

circ: Circuit

Object

Domain

LEGEND

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 52: Practical Static Extraction and Conformance Checking of ...

52

Strict encapsulation vs. logical containment

(1) Strict encapsulation(private domain)

(2) Logical containment(public domain)

circ:Circuit

nodesVectorX

circ:Circuit

node:Node

DB

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

owned

Page 53: Practical Static Extraction and Conformance Checking of ...

53

Example #2: 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

list: Sequence

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 54: Practical Static Extraction and Conformance Checking of ...

54

Sequence: private domain

• Sequence has private state (head)

• Should not be accessible to outside; in private domain

• Sequence has iterators that are accessible to outside

• Can also access private state

head

OWNED

@@@@DomainsDomainsDomainsDomains({“OWNEDOWNEDOWNEDOWNED””, “ITERSITERSITERSITERS”})

classclassclassclass Sequence {

@@@@DomainDomainDomainDomain(“OWNEDOWNEDOWNEDOWNED”) Cons head;

public public public public @@@@DomainDomainDomainDomain(“ITERSITERSITERSITERS”)

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

}

}

list: Sequence

Object

LEGEND

Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 55: Practical Static Extraction and Conformance Checking of ...

55

Sequence: public domain

• Sequence has private state (head)

• Not accessible to outside; in private domain OWNED

• Sequence has iterators that are accessible to outside

• Can also access private state; in public domain ITERS

head iterator

OWNED ITERS

@@@@DomainsDomainsDomainsDomains({“OWNEDOWNEDOWNEDOWNED”, “ITERSITERSITERSITERS”})

classclassclassclass Sequence {

@@@@DomainDomainDomainDomain(“OWNEDOWNEDOWNEDOWNED”) Cons head;

public public public public @@@@DomainDomainDomainDomain(“ITERSITERSITERSITERS”)

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

}

}

list: Sequence

Object

Domain

LEGEND

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 56: Practical Static Extraction and Conformance Checking of ...

56

Sequence: ownership domain parameters

@@@@DomainsDomainsDomainsDomains({“OWNEDOWNEDOWNEDOWNED”, “ITERSITERSITERSITERS”})

@@@@DomainParamsDomainParamsDomainParamsDomainParams({“ELTSELTSELTSELTS”})classclassclassclass Sequence {@@@@DomainDomainDomainDomain(“OWNEDOWNEDOWNEDOWNED<ELEMSELEMSELEMSELEMS>”) Cons head;

…………}

@@@@DomainParamsDomainParamsDomainParamsDomainParams({“ELTSELTSELTSELTS”})classclassclassclass Cons {

@@@@DomainDomainDomainDomain(“ELTSELTSELTSELTS”) Object obj; @@@@DomainDomainDomainDomain(“OWNEROWNEROWNEROWNER<ELTSELTSELTSELTS>”) Cons next;

}

• To share objects across domains

• Add domain parameter to hold elements in list

OWNEDclient

objects

ELTS

list : Sequence

:Cons

OWNER

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 57: Practical Static Extraction and Conformance Checking of ...

57

Sequence object graph

• Expand the sub-structure of ‘list’

STATE

LIST

ITERS

OWNED

object:Object

it:Iterator

head:Cons

list:Sequence

listClient:ListClient

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 58: Practical Static Extraction and Conformance Checking of ...

58

Sequence object graph (continued)

• Collapse the sub-structure of ‘list’

STATELIST

object:

Object

list(+):

SequencelistClient :

ListClient

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 59: Practical Static Extraction and Conformance Checking of ...

59

Strict encapsulation vs. logical containment

(1) Strict encapsulation(private domain)

(2) Logical containment(public domain)

OWNED

list:Sequence

head:ConsX

list:Sequence

it:Iterator

ITERS

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 60: Practical Static Extraction and Conformance Checking of ...

60

Demo: checking Sequence annotations

• Cannot return head of Sequence• 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 ITERS

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 61: Practical Static Extraction and Conformance Checking of ...

61

Annotation tool support

• Use Java 1.5 annotations

• Typechecker uses Eclipse JDT

• Warnings in Eclipse’s problem window

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 62: Practical Static Extraction and Conformance Checking of ...

62

Annotation language summary

• @Domains: declare domains

• @DomainParams: declare formal domain parameters

• @DomainLinks: declare domain link specifications

• @DomainInherits: specify parameters for supertypes

• @DomainReceiver: specify annotation on receiver

• @Domain: specify object annotation, actual domain

parameters and (optionally) array parameters“annotation<domParam, …> [arrayParam, …]”

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 63: Practical Static Extraction and Conformance Checking of ...

63

Special annotations

• lent: temporary alias within method

• shared: shared persistently or globally

• unique: unaliased object, e.g.,• newly created object

• passed linearly from one domain to another

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 64: Practical Static Extraction and Conformance Checking of ...

64

Annotation language

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

@Domains: declare domains

@Domains({@Domains({@Domains({@Domains({““““ownedownedownedowned””””}) }) }) }) // Private domainclassclassclassclass Sequence {...}

• Each object is declared in a domain

@Domain: declare domain for given object

@Domain(@Domain(@Domain(@Domain(““““ownedownedownedowned””””) Vector v; ) Vector v; ) Vector v; ) Vector v; // declare in ‘owned’ domain

Ł means instance encapsulated within object

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 65: Practical Static Extraction and Conformance Checking of ...

65

Annotation language (continued)

• @DomainParams: declare formal domain

parameters on a type

• @Domain: declare domain for object

• Optionally specify actual domains using the

parameter order in @DomainParams

• Similar to Java 1.5 generics• Declare formal type parameter

class ArrayList <T> {...• Bind formal type parameter to actual type

ArrayList <String> seq;

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 66: Practical Static Extraction and Conformance Checking of ...

66

Annotation language (continued)

• @DomainInherits: bind current type’s formal

parameters to parameters of supertypes

@DomainParams({“elems"})

@DomainInherits({“Iterator<elems>"})

classclassclassclass SeqIterator extendsextendsextendsextends Iterator {

...

}

// Again, similar to Java Generics...

classclassclassclass SeqIterator<T> extendsextendsextendsextends Iterator<T> {

...

}

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 67: Practical Static Extraction and Conformance Checking of ...

67

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use ArchCheckJ

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 68: Practical Static Extraction and Conformance Checking of ...

68

SCHOLIA ArchCheckJ on Aphyds

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 69: Practical Static Extraction and Conformance Checking of ...

69

Hands-on Exercises

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 70: Practical Static Extraction and Conformance Checking of ...

70

Getting setup

• Have Java 1.5 or later installed

• Install GraphViz• graphviz-2.20.2.exe in zip file

• Read setup.html

• Extract zip file• Contains Eclipse 3.4• AcmeStudio 3.4.x (build 20090415N)• SCHOLIA Eclipse plugins

• Accept license agreement• CMU patent-pending technology• Non-commercial, research evaluation OK

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 71: Practical Static Extraction and Conformance Checking of ...

71

Disclaimer

• Research-Off-The-Shelf (ROTS) tools• Highly specialized

• Poorly documented

• Mostly prototypes

• Advice on AcmeStudio• Save early, save often (Ctrl-S) • Restart often (File àààà Restart)

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 72: Practical Static Extraction and Conformance Checking of ...

72

Exercise #1: CryptoDB

Add annotations

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 73: Practical Static Extraction and Conformance Checking of ...

73

CryptoDB

• 3-KLOC Java

• Crypto application

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 74: Practical Static Extraction and Conformance Checking of ...

74

Add annotations and fix warnings

• LocalKeyStore and LocalKey

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 75: Practical Static Extraction and Conformance Checking of ...

75

LocalKeyStore and LocalKey

• Hint: use this as a guide

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 76: Practical Static Extraction and Conformance Checking of ...

76

Exercise #1: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 77: Practical Static Extraction and Conformance Checking of ...

77

LocalKeyStore, LocalKey annotations

class LocalKeyStore {private domain OWNED;public domain KEYS;private OWNED List<KEYS LocalKey> keys;

public unique List<KEYS LocalKey> getKeys() {unique List<KEYS LocalKey> copy = copy(keys);return copy;

}}class LocalKey {private shared String keyData; // encrypted keyprivate shared String keyId; // encrypted key id...

}

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 78: Practical Static Extraction and Conformance Checking of ...

78

Step 2

Extract hierarchical object graph using static analysis

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 79: Practical Static Extraction and Conformance Checking of ...

79

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 80: Practical Static Extraction and Conformance Checking of ...

80

Runtime Object Graph (ROG)

• Runtime Object Graph (ROG): graph where• A node represents a runtime object,

• An edge represents a points-to relation

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 81: Practical Static Extraction and Conformance Checking of ...

81

Goal of ObjectGraph static analysis

• Extract ObjectGraph that soundly

approximates all possible Runtime Object

Graph (ROG)s• Conveys architectural abstraction primarily by

ownership hierarchy• Optionally, merges more objects within a domain

based on their declared types

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 82: Practical Static Extraction and Conformance Checking of ...

82

Two phases of the static analysis

1. Build TypeGraph• Visitor over program’s Abstract Syntax Tree

• Represents type structure of objects in code

2. Convert TypeGraph to ObjectGraph• Instantiates the types in the TypeGraph

• Shows only objects and domains

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 83: Practical Static Extraction and Conformance Checking of ...

83

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

Node

OWNED

terms: List<Terminal>

Circuit

DB

term:Terminal

node:Node List<Terminal>

OWNED

head

ELTS

obj: Terminal

Is-Aobject: Type

Object

Type Type

F

A

Formal Domain

Actual Domain

net:Net

Net

OWNED

terms: List<Terminal>

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 84: Practical Static Extraction and Conformance Checking of ...

84

ObjectGraph: instantiate types, starting with root (user selected)

Node

OWNED

terms: List<Terminal>

Circuit

DB

term:Terminal

node:Node List<Terminal>

OWNED

head

ELTS

obj: Terminal

F

A

Formal Domain

Actual Domain

net:Net

Net

OWNED

terms: List<Terminal>

Is-Aobject: Type

Object

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 85: Practical Static Extraction and Conformance Checking of ...

85

ObjectGraph: instantiate types, starting with root (user selected)

Node

OWNED

terms: List<Terminal>

circuit: Circuit

DB

term:Terminal

node:Node List<Terminal>

OWNED

head

ELTS

obj: Terminal

F

A

Formal Domain

Actual Domain

net:Net

Net

OWNED

terms: List<Terminal>

Is-Aobject: Type

Object

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 86: Practical Static Extraction and Conformance Checking of ...

86

ObjectGraph: instantiate types, show domains and objects inside domains

Node

OWNED

terms: List<Terminal>

circuit: Circuit

DB

term:Terminal

node:Node List<Terminal>

OWNED

head

ELTS

obj: Terminal

F

A

Formal Domain

Actual Domain

net:Net

Net

OWNED

terms: List<Terminal>

Is-Aobject: Type

Object

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 87: Practical Static Extraction and Conformance Checking of ...

87

circuit: Circuit

DB

net: Net…

ObjectGraph: instantiate types, show domains and objects inside domains

node: Node

OWNED

terms: List<Terminal>

List<Terminal>

OWNED

head

ELTS

obj: Terminal

Is-A

object: Type

Object

F

A

Formal Domain

Actual Domain

term: Terminal…

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 88: Practical Static Extraction and Conformance Checking of ...

88

circuit: Circuit

DB

net: Net…

ObjectGraph: instantiate types, show domains and objects inside domains

node: Node

OWNED

terms: List<Terminal>

List<Terminal>

OWNED

head

ELTS

obj: Terminal

Is-A

object: Type

Object

F

A

Formal Domain

Actual Domain

term: Terminal…

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 89: Practical Static Extraction and Conformance Checking of ...

89

circuit: Circuit

DB

net: Net…

ObjectGraph: instantiate types, show domains and objects inside domains

node: Node

OWNED

terms: List<Terminal>

List<Terminal>

OWNED

head

ELTS

obj: Terminal

Is-A

object: Type

Object

F

A

Formal Domain

Actual Domain

term: Terminal…

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 90: Practical Static Extraction and Conformance Checking of ...

90

circuit: Circuit

DB

net: Net…

ObjectGraph: instantiate types, show domains and objects inside domains

node: Node

OWNED

terms: List<Terminal>

List<Terminal>

OWNED

head

ELTS

obj: Terminal

Is-A

object: Type

Object

F

A

Formal Domain

Actual Domain

term: Terminal…

Type Type

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 91: Practical Static Extraction and Conformance Checking of ...

91

circuit: Circuit

DB

net: Net…

ObjectGraph: instantiate types, show domains and objects inside domains

term: Terminal…

node: Node

OWNED

terms: List<Terminals>

OWNED

head

ELTS

obj: Terminal object:

TypeObject

F

A

Formal Domain

Actual Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 92: Practical Static Extraction and Conformance Checking of ...

92

Challenge: unbounded number of objects, based on different executions

• Invariant: Summarize multiple objects in a

domain with one canonical object

• Invariant: Merge two objects of the “same

type” that are in the same domain• I.e., same declared type, or subtype thereof• Or of compatible types (more later)

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 93: Practical Static Extraction and Conformance Checking of ...

93

Challenge: TypeGraph does not show all objects in each domain

• Reusable or library code often parametric with respect to ownership• List does not “own” its elements

• Takes domain parameter ELTS for elements

List<Terminal>

OWNED

head

ELTS

obj: Terminal

object: Type

Object

F

A

Formal Domain

Actual Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 94: Practical Static Extraction and Conformance Checking of ...

94

Challenge: TypeGraph does not show all objects in each domain

• At runtime domain parameter bound to other actual domain

• Invariant: In the ObjectGraph, each object that is in a given domain must appear where that domain is declared

• Pull each object declared inside formal domain parameter into each domain bound to the formal domain parameter

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 95: Practical Static Extraction and Conformance Checking of ...

95

circuit: Circuit

DB

net: Net…

ObjectGraph: pull objects from formal domains to actual domains

term: Terminal…

node: Node

OWNED

terms: List<Terminal>

OWNED

head

ELTS

obj: Terminal object:

TypeObject

F

A

Formal Domain

Actual Domain

classclassclassclass Node<OWNEROWNEROWNEROWNER>>>> {domaindomaindomaindomain OWNEDOWNEDOWNEDOWNED;// List::ELTS // List::ELTS // List::ELTS // List::ELTS àààà Node::OWNERNode::OWNERNode::OWNERNode::OWNEROWNEDOWNEDOWNEDOWNED List<OWNER OWNER OWNER OWNER Terminal> terms;

}

classclassclassclass List<ELTSELTSELTSELTS T> { // ELTS is for List elements// T is generic type parameter// Virtual fieldELTSELTSELTSELTS T obj;

}

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 96: Practical Static Extraction and Conformance Checking of ...

96

circuit: Circuit

DB

net: Net…

ObjectGraph: pull objects from formal domains to actual domains

term: Terminal…

node: Node

OWNED

terms: List<Terminal>

OWNED

head

ELTS

obj: Terminal object:

TypeObject

F

A

Formal Domain

Actual Domain

obj: Terminal

classclassclassclass Circuit {domaindomaindomaindomain DBDBDBDB;;;;// Node::OWNER // Node::OWNER // Node::OWNER // Node::OWNER àààà Circuit::DBCircuit::DBCircuit::DBCircuit::DBDB DB DB DB Node node;...

}

classclassclassclass Node<<<<OWNEROWNEROWNEROWNER>>>> {domaindomaindomaindomain OWNEDOWNEDOWNEDOWNED;OWNEDOWNEDOWNEDOWNED List<OWNER OWNER OWNER OWNER Terminal> terms;

}

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 97: Practical Static Extraction and Conformance Checking of ...

97

Challenge: TypeGraph does not reflect possible aliasing

• Invariant: the same object should not

appear multiple times in the ObjectGraph

• Ownership domain annotations give some

precision about aliasing:• Two objects in different domains cannot alias

• Two objects in same domain may alias

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 98: Practical Static Extraction and Conformance Checking of ...

98

circuit: Circuit

DB

net: Net…

ObjectGraph: merge equivalent objects inside a given domain

{term: Terminal, obj: Terminal}…

node: Node

OWNED

terms: List<Terminal>

OWNED

head

ELTS

obj: Terminal object:

TypeObject

F

A

Formal Domain

Actual Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 99: Practical Static Extraction and Conformance Checking of ...

99

circuit: Circuit

DB

net: Net…

ObjectGraph: add edges to represent points-to relations, incl. to pulled objects

{term: Terminal, obj: Terminal}…

node: Node

OWNED

terms: List<Terminal>

OWNED

head

ELTS

object: Type

Object

F

A

Formal Domain

Actual Domain

obj: Terminal

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 100: Practical Static Extraction and Conformance Checking of ...

100

Challenge: ObjectGraph can have cycles

• Project ObjectGraph to limited depthroot

domain1 domain2

object11 object22object21

domain111

object1111 object1112

ObjectGraph

Object

Domain

Has-a

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 101: Practical Static Extraction and Conformance Checking of ...

101

Challenge: objects from elided sub-structures could point to other objects

• Invariant: show all object relations, even ones due to elided sub-structures

• Lift edge to parent object when hidden sub-object points to external objects

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 102: Practical Static Extraction and Conformance Checking of ...

102

circuit: Circuit

DB

net: Net…

Aphyds: no longer show formal domains, e.g., ‘ELTS’ inside ‘terms’

{term: Terminal}…

node: Node

OWNED

terms: List<Terminal>

OWNED

head

object: Type

Object

A Actual Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 103: Practical Static Extraction and Conformance Checking of ...

103

circuit: Circuit

DB

net: Net…

Aphyds: ‘node’ substructure points to other objects, such as ‘term’ object

{term: Terminal}…

node: Node

OWNED

terms: List<Terminal>

OWNED

head

object: Type

Object

A Actual Domain

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 104: Practical Static Extraction and Conformance Checking of ...

104

circuit: Circuit

DB

net: Net…

Aphyds: collapsing substructure of ‘terms’ object causes edge lifting

{term: Terminal}…

node: Node

OWNED

terms (+) : List<Terminal>

object: Type

Object

A Actual Domain

(+) Substructure

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 105: Practical Static Extraction and Conformance Checking of ...

105

circuit: Circuit

DB

net: Net…

Aphyds: collapsing substructure of ‘node’object causes additional edge lifting

{term: Terminal}…

node (+): Node

object: Type

Object

A Actual Domain

(+) Substructure

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 106: Practical Static Extraction and Conformance Checking of ...

106

Extraction key property: soundness

• To be sound, must show all objects and relations that may exist in any run

• Aliasing soundness: no one object appears as two “boxes” in object graph

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 107: Practical Static Extraction and Conformance Checking of ...

107

Intuition behind soundness

Runtime Object Graph (ROG) ObjectGraph

UI

viewerUI

DISPLAY

displayer

MODEL

circuit

DB

net

partitioner

OWNED

listeners

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 108: Practical Static Extraction and Conformance Checking of ...

108

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use ArchRecJ

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 109: Practical Static Extraction and Conformance Checking of ...

109

SCHOLIA ArchRecJ on Aphyds

• Abstract objects by ownership hierarchy

• Optionally abstract objects by types

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 110: Practical Static Extraction and Conformance Checking of ...

110

Exercise #2: CryptoDB

Extract object graphs

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 111: Practical Static Extraction and Conformance Checking of ...

111

Exercise #2: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 112: Practical Static Extraction and Conformance Checking of ...

112

CryptoDB OOG – no abstraction by types

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 113: Practical Static Extraction and Conformance Checking of ...

113

CryptoDB abstraction by types

• Merge

CustomerInfo

and CreditCardInfo

• Both in CONSUMERS

• Merge objects when they share non-trivial

least upper bound types

• User configures list of “trivial types“; by

default, includes Object, Cloneable, etc.

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 114: Practical Static Extraction and Conformance Checking of ...

114

CryptoDB OOG, with abstraction by types

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 115: Practical Static Extraction and Conformance Checking of ...

115

Step 3

Abstract object graph into built architectures

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 116: Practical Static Extraction and Conformance Checking of ...

116

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 117: Practical Static Extraction and Conformance Checking of ...

117

Why need to abstract an object graph?

• Extracted object graph provides architectural abstraction by ownership hierarchy and by types

• May not be isomorphic to architect's intended architecture

• May require further abstraction

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 118: Practical Static Extraction and Conformance Checking of ...

118

Aphyds: object graph vs. target architecture

• Object graph • Target architecture

circuit

circuit database

node net

user interface

viewerUI

floorplanUI placeRouteUI

channelRouteUI

partitioner

floorplanner placer

globalRouter

channelRouter

computational code

circuit

circuit database

node net

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 119: Practical Static Extraction and Conformance Checking of ...

119

Elide and summarize domains/objects

• Private domainshold representation

• Public domainshold visible state

• Soundly summarize private domains

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 120: Practical Static Extraction and Conformance Checking of ...

120

Soundly summarizing elided objects

• Eliding object ‘term’ leads to summary edge to show transitive communication

• Effectively, abstracts object into edge

DB

node:

Node

term:

Terminal

net:

Net

DB

node:

Node

net:

Net

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 121: Practical Static Extraction and Conformance Checking of ...

121

Represent abstracted object graph in architecture description language

OOG ↔ C&C view

• Top-level ↔ Systemobject

• Object ↔ Component

• Domain ↔ Group

• Interface ↔ Provide port

• Field reference ↔ Use port

• Object relation ↔ Connector

• Substructure ↔ Representation

Aphyds

UI

MODEL

viewerUI

circuit

DB

nodenet

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 122: Practical Static Extraction and Conformance Checking of ...

122

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use ArchCog

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 123: Practical Static Extraction and Conformance Checking of ...

123

SCHOLIA ArchCog on Aphyds

• Abstract object graph into C&C view

• Control projection depth

• Elide private domains

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 124: Practical Static Extraction and Conformance Checking of ...

124

Exercise #3: CryptoDB

Abstract object graph

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 125: Practical Static Extraction and Conformance Checking of ...

125

Exercise #3: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 126: Practical Static Extraction and Conformance Checking of ...

126

CryptoDB built architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 127: Practical Static Extraction and Conformance Checking of ...

127

Step 4

Document target architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 128: Practical Static Extraction and Conformance Checking of ...

128

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 129: Practical Static Extraction and Conformance Checking of ...

129

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document[AcmeStudio]

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use AcmeStudio

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 130: Practical Static Extraction and Conformance Checking of ...

130

Aphyds: document designed architecture in architecture description language

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 131: Practical Static Extraction and Conformance Checking of ...

131

Exercise #4: CryptoDB

Document target architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 132: Practical Static Extraction and Conformance Checking of ...

132

CryptoDB

• DFD Level-1

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 133: Practical Static Extraction and Conformance Checking of ...

133

CryptoDB

• DFD Level-2

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 134: Practical Static Extraction and Conformance Checking of ...

134

Exercise #4: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 135: Practical Static Extraction and Conformance Checking of ...

135

CryptoDB target architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 136: Practical Static Extraction and Conformance Checking of ...

136

CryptoDB target architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 137: Practical Static Extraction and Conformance Checking of ...

137

Step 5

Compare built and designed architectures

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 138: Practical Static Extraction and Conformance Checking of ...

138

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 139: Practical Static Extraction and Conformance Checking of ...

139

Why is comparing built and designed architectures hard?

• No unique identifiers

• Renames

• Insertions

• Deletions

• Solution: use structural comparison

Designed Architecture

Built Architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 140: Practical Static Extraction and Conformance Checking of ...

140

Structural comparison

• Exploit hierarchy in architectural views to match the nodes

• Detect renames, insertions, deletionsand restricted moves

• Previous architectural comparison detected only insertions and deletions

• Lost node properties needed for architectural analyses

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 141: Practical Static Extraction and Conformance Checking of ...

141

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use ArchConf

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 142: Practical Static Extraction and Conformance Checking of ...

142

Aphyds: comparing built and designed architectures

• Accept results of structural comparison

• Optionally, force/prevent matches

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 143: Practical Static Extraction and Conformance Checking of ...

143

Exercise #5: CryptoDB

Compare build and target architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 144: Practical Static Extraction and Conformance Checking of ...

144

Exercise #5: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 145: Practical Static Extraction and Conformance Checking of ...

145

Step 6

Check conformance between built and designed architectures

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 146: Practical Static Extraction and Conformance Checking of ...

146

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 147: Practical Static Extraction and Conformance Checking of ...

147

How is conformance checking different from view differencing/merging?

• Goal is not to make the built and the designed architectures identical

• Account for communication in built system that is not in designed one• Do not propagate all implementation objects

• Enforce communication integrity

• Measure conformance as graph edit distance between built and designed views

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 148: Practical Static Extraction and Conformance Checking of ...

148

Conformance checking analysis

• Use built view names

• Do not directly propagate additional components

• Summarize additional components in built

architecture using summary edges

Designed view

Built view

Conformance view

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 149: Practical Static Extraction and Conformance Checking of ...

149

Conformance check identifies key differences

• Convergence: node or edge in bothbuilt and in designed view

• Divergence: node or edge in built, but not in designed view

• Absence: node or edge in designed view, but not in built view

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 150: Practical Static Extraction and Conformance Checking of ...

150

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use ArchConf

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 151: Practical Static Extraction and Conformance Checking of ...

151

Aphyds: developer investigates reported differences

• Study findings

• Trace to code

Convergence

Divergence

Absence

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 152: Practical Static Extraction and Conformance Checking of ...

152

Exercise #6: CryptoDB

Check conformance between built and designed architectures

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 153: Practical Static Extraction and Conformance Checking of ...

153

Exercise #6: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 154: Practical Static Extraction and Conformance Checking of ...

154

CryptoDB conformance analysis

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 155: Practical Static Extraction and Conformance Checking of ...

155

Step 7

Investigate and trace to code

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 156: Practical Static Extraction and Conformance Checking of ...

156

CodeCode

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

Built RuntimeArchitecture

Built RuntimeArchitecture

AnnotationsAnnotations

Investigate and refine

Extract[ArchRecJ]

Abstract[ArchCog]

Trace to Code

[CodeTraceJ]

Annotate

Document

ConformanceView

ConformanceViewCheck

[ArchConf]

Compare

Refine

Typecheck[ArchCheckJ]

SCHOLIA: use CodeTraceJ

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 157: Practical Static Extraction and Conformance Checking of ...

157

Aphyds: trace from runtime architecture, obtained statically, to lines of code

• Trace

finding to

code

• Previously,

only UML

class

diagrams

supported

this feature

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 158: Practical Static Extraction and Conformance Checking of ...

158

• Missing top-level

component

partitionUI

• Callback from

placer in MODEL to

placeRouteUI in UI

• Many connections

really bi-directional

Aphyds: summary of findings

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 159: Practical Static Extraction and Conformance Checking of ...

159

SCHOLIA conformance checking

DesignedArchitecture

DesignedArchitecture

HierarchicalObject Graph

HierarchicalObject Graph

BuiltArchitecture

BuiltArchitecture

AnnotationsAnnotations

Investigate and refine

Extract

Abstract

CodeCode

Trace to Code

Annotate

Document

ConformanceView

ConformanceViewCheck

Compare

Refine

Typecheck

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 160: Practical Static Extraction and Conformance Checking of ...

160

Outcomes of investigating findings

a) Iteratively refine annotations based on visualizing an extracted object graph, before abstracting it;

b) Fine-tune the abstraction of an object graph into an architecture;

c) Manually guide the comparison of the built and the designed architecture, if structural comparison fails to perform the proper match;

d) Update code if she decides designed architecture is correct, but implementation violates architecture;

e) Update designed architecture if she considers implementation highlights mission in architecture

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 161: Practical Static Extraction and Conformance Checking of ...

161

Exercise #7: CryptoDB

Investigate and trace to code

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 162: Practical Static Extraction and Conformance Checking of ...

162

Exercise #7: CryptoDB

Solution

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 163: Practical Static Extraction and Conformance Checking of ...

163

CryptoDB summary

• What did you learn?

● Annotate ● Extract ● Abstract ● Document ● Compare ● Analyze ● Investigate

Page 164: Practical Static Extraction and Conformance Checking of ...

164

Discussion

Page 165: Practical Static Extraction and Conformance Checking of ...

165

Limitations

• Manual annotation burden• Impractical without annotation inference• Active area of research

• Annotation expressiveness limitations

• Extraction does not handle • Distributed systems (single virtual machine)• Dynamic architectural reconfiguration

• Comparison can fail to match if views are too discrepant, quadratic in the view sizes

• False positives possible• As is the case with any sound static analysis• Few when developer fine-tunes annotations

Page 166: Practical Static Extraction and Conformance Checking of ...

166

Conclusion

• You learned about SCHOLIA, to extract statically a hierarchical runtime architecture from a program in a widely used object-oriented language, using typecheckable annotations

• If intended architecture exists, SCHOLIA can analyze, at compile-time, communication integrity between implementation and target architecture

• In practice, SCHOLIA can find structural differences between an existing system and its target architecture

• SCHOLIA can establish traceability between an implementation and an intended runtime architecture

• SCHOLIA complements architectural views of code structure or partial views of runtime architecture obtained using dynamic analysis


Recommended