Professional Documents
Culture Documents
void foo() {
/* do something */
}
void foo() {
/* before stuff */
is s bstit tion or an
/* before stuff */
/* do something */
/* after stuff */
}
=
is substitution or an
equivalent encoding
Don Batory
UT-Austin Computer Sciences
intro 46
Connecting the Dots... Connecting the Dots...
Scalability Scalability
refinement is not limited to a single class
collaborations modularize refinements of multiple
classes and add new classes
adding new classes that can be refined is critical
Don Batory
UT-Austin Computer Sciences
intro 47
Connecting the Dots... Connecting the Dots...
A collaboration has meaning when it
implements a feature p
ever add a new feature to an existing OO program?
several existing classes may be refined
several new classes may be added
Don Batory
UT-Austin Computer Sciences
intro 48
Synthesis Paradigm Synthesis Paradigm
Program P = featureX featureY
Note: each
feature updates
featureZ
class1 class2 class3 class4
Program P = featureX featureY
feature updates
multiple classes
featureZ
class1 class2 class3 class4
featureX
featureY featureY
featureZ
By composing features, packages of fully-formed classes are synthesized
Don Batory
UT-Austin Computer Sciences
intro 49
Contributors to this View Contributors to this View
Many researchers have variants of this idea:
refinements Dijkstra, Wirth 68
layers Dijkstra 68, Batory 84 layers Dijkstra 68, Batory 84
product-line architectures Kang 90, Gomaa 92
collaborations Reenskaug 92, Lieberherr 95, g , ,
Mezini 03
program verification Boerger 96
aspects Kiczales 97, et al.
concerns Ossher-Harrison-Tarr 99
Don Batory
UT-Austin Computer Sciences
intro 50
Connecting the Dots... Connecting the Dots...
You can always decompose software in this manner
trick is that your refinements are reusable
th t th ti ith f t d t li thats the connection with features, product-lines
features are reusable so too must be their implementations
software that is not designed to be reusable, composable, etc. with
other software wont be this is co-design or
designing to a standard
Architectural Mismatch (ICSE 1995) Architectural Mismatch (ICSE 1995)
Product-Line Design feature implementations are
designed with compositionality, reusability in mind designed with compositionality, reusability in mind
Don Batory
UT-Austin Computer Sciences
intro 51
GenVoca GenVoca GenVoca GenVoca
Genesis + Avoca
Th Fi t G ti The First Generation
Don Batory
UT-Austin Computer Sciences
intro 52
GenVoca (1988,1992) GenVoca (1988,1992)
Equates constants, functions
with features
A domain model
or product-line model
Constants:
f base program with feature f
or GenVoca model M
set of constants
f base program with feature f
h base program with feature h
set of constants
(base programs)
functions
Functions
i x adds feature i to program x
functions
(program refinements)
j x adds feature j to program x
M = { f, h, ... i, j, ... }
Don Batory
UT-Austin Computer Sciences
intro 53
Function Composition Function Composition
Multi-featured applications are expressions
app1 = i f
application with features f and i
app2 = j h
app3 = i j f
application with features h and j
your turn... y
Given a GenVoca model we can Given a GenVoca model, we can
create a family of applications by
composing features
Don Batory
UT-Austin Computer Sciences
intro 54
Expression Optimization Expression Optimization
Constants, functions represent both a feature and its
implementation
different functions can be different implementations of the same feature
k
1
x // adds k with implementation #1 to x
k x // adds k with implementation #2 to x
When application requires feature k, it is a matter of optimization
t d t i th b t i l t ti f
k
2
x // adds k with implementation #2 to x
to determine the best implementation of k
counterpart of relational optimization
more complicated rewrites possible too
See:
Batory, et al. Design Wizards and Visual Programming Environments
for GenVoca Generators. IEEE TSE, May 2000.
Don Batory
UT-Austin Computer Sciences
intro 55
Generalization of Relational Algebra Generalization of Relational Algebra
Keys to success of Relational Optimizers
expression representations of program designs
rewrite expressions using algebraic identities
Heres the generalization: g
domain model is an algebra for a domain or product-line
i t f ti ( t t f ti ) th t t is set of operations (constants, functions) that represent
stereo-typical building blocks of programs/members
compositions define space of programs that can be synthesized
given an algebra:
there will always be algebraic identities among operations
these identities can be used to optimize expression these identities can be used to optimize expression
representations of programs, like relational algebra
Don Batory
UT-Austin Computer Sciences
intro 56
AHEAD: AHEAD:
The Next Generation The Next Generation
Algebraic Hierarchical Expressions for
Application Design
Don Batory
UT-Austin Computer Sciences
intro 57
Scaling Program Generation Scaling Program Generation
Generating code for an individual program is OK,
but not sufficient
Todays systems are not individual programs,
but groups of collaborating programs but groups of collaborating programs
client-server systems, tool suites (IDEs)
Further, systems are not solely defined by code
architects routinely use many knowledge representations
formal models, UML models, makefiles, documents, ...
Need 4 insights to capture these ideas g p
Don Batory
UT-Austin Computer Sciences
intro 58
Insight #1: Platonic Forms and Languages Insight #1: Platonic Forms and Languages
Each program representation captures different
i f i i diff l information in different languages
html java perf class xml
program
We want all these representations in a single module
.html .java .perf .class .xml
p g
Don Batory
UT-Austin Computer Sciences
intro 59
Insight #2: Generalize Features Insight #2: Generalize Features
When a program is refined, any or all of its
representations may be updated
Ex: Add a new feature F to program P changes:
code (to implement F)
documentation (to document F)
makefiles (to build F) makefiles (to build F)
formal properties (to characterize F)
performance properties (to profile F)
This is a collaboration
Don Batory
UT-Austin Computer Sciences
intro 60
Vectors and Vector Refinements Vectors and Vector Refinements
A program is a vector of representations
Features refine vectors component wise Features refine vectors component-wise
P0
d
P1
d
P2
d
G F
code
0
binary
code
1
binary
code
2
binary binary
0
make
0
binary
1
make
1
binary
2
make
2
make
0
doc
0
make
1
doc
1
make
2
doc
2
Don Batory
UT-Austin Computer Sciences
intro 61
0 1 2
Vector Representations Vector Representations
We are reducing
program synthesis to P0 F P1
p g y
vector composition
code
0
code
F
code
1
GenVoca model
constant P0
function F
binary
0
binary
F
binary
1
=
Feature composition
= vector composition
make
0
make
F
make
1
= vector composition
Still need another idea
doc
0
doc
F
doc
1
Don Batory
UT-Austin Computer Sciences
intro 62
Insight #3: Generalize Modularity Insight #3: Generalize Modularity
A module is a containment hierarchy of related artifacts
J2EE EAR File
l i f
package
methods fields
class
constants methods
interface
deployment
descriptors
HTML
files
Generalize module hierarchies to arbitrary depth contents
methods fields constants methods descriptors files
Generalize module hierarchies to arbitrary depth, contents
Don Batory
UT-Austin Computer Sciences
intro 63
Modularization of Multiple Programs Modularization of Multiple Programs
system
client server
code UML HTML code UML HTML
*.java, *.class *.html state-machines
...
*.java, *.class
*.html class diagrams
...
Modules contain all needed representations of a system
Don Batory
UT-Austin Computer Sciences
intro 64
Modules are Nested Vectors Modules are Nested Vectors
Program as vector idea recurses:
each subrepresentation can itself be a vector
system
system= [ client, server ]
client = [ code
c
, UML
c
, HTML
c
]
client server
y [ , ]
server = [ code
s
, UML
s
, HTML
s
] client [ code
c
, UML
c
, HTML
c
]
code
c
UML
c
HTML
c
code
s
UML
s
HTML
s
server [ code
s
, UML
s
, HTML
s
]
Module is a (nested) vector
Name of a subrepresentation is unique; Name of a subrepresentation is unique;
it defines its index position in a vector
Don Batory
UT-Austin Computer Sciences
intro 65
Law of Composition Law of Composition
Consider base program P and refinement R:
P = [ A
P
, B
P
, C
P
, ]
R = [ A
R
, , C
R
, D
R
]
implicit vector padding with blanks
base programs have nulls ()
refinements have identity functions (i) refinements have identity functions (i)
What is R P ? What is R P ?
Don Batory
UT-Austin Computer Sciences
intro 66
Law of Composition Law of Composition
R P is:
P = [ A
P
, B
P
, C
P
, ]
R = [ A
R
, , C
R
, D
R
]
RP = [ A
R
A
P
, B
P
, C
R
C
P
, D
R
]
Says how composition distributes over
modularization
Do you recognize this law?
Don Batory
UT-Austin Computer Sciences
intro 67
Inheritance! Inheritance!
class representation vector representation
class P {
member A
P
;
member B
P
;
P = [ A
P
, B
P
, C
P
, ]
P
;
member C
P
;
}
l R { e tends P class R {
member A
R
;
member C
R
;
member D
R;
R = [ A
R
, C
R
, D
R
]
extends P
R;
}
class RP extends R {}
RP = [ A
R
A
P
, B
P
, C
R
C
P
, D
R
]
Don Batory
UT-Austin Computer Sciences
intro 68
class RP extends R {}
Simple Implementation Simple Implementation
Module hierarchies = nested vectors
vector directory
A = [ Code, R.drc, Htm ]
A
Code = [ X.java, Y.java ]
Code
R.drc
Htm
Htm = [ W.htm, Z.htm ]
X.java W.htm Y.java Z.htm
Don Batory
UT-Austin Computer Sciences
intro 69
Simple Implementation Simple Implementation
Feature composition = directory composition Feature composition = directory composition
produces directory isomorphic to inputs
A B C
Code Htm
A
Code Htm
B
= Code Htm
C
Code
Xj Y j Zh
R.drc
Htm
Xj Wh Y j
Code
R.drc
Htm
=
Xj Wh Y j Zh
Code
R.drc
Htm
X.java = X.java X.java
X.javaY.java Z.htm X.java W.htm Y.java X.java W.htm Y.java Z.htm
Don Batory
UT-Austin Computer Sciences
intro 70
j j j
Simple Theory Simple Theory
Result computed algebraically by recursively Result computed algebraically by recursively
expanding and applying the law of composition
C = B A C = B A
= [ Code
B
, R.drc
B
, Htm
B
] [ Code
A
, R.drc
A
, Htm
A
]
= [ Code
B
Code
A
, R.drc
B
R.drc
A
, Htm
B
Htm
A
] = [ Code
B
Code
A
, R.drc
B
R.drc
A
, Htm
B
Htm
A
]
= [ [ X.java
B
, Y.java
B
] [ X.java
A
, Y.java
A
], R.drc
B
R.drc
A
, [ W.htm
B
, ] [ , Z.htm
A
] ]
= [ [ X.java
B
X.java
A
, Y.java
B
Y.java
A
], R.drc
B
R.drc
A
, [ W.htm
B
, Z.htm
A
] ]
Don Batory
UT-Austin Computer Sciences
intro 71
Note! Note!
Each expression defines an artifact to be produced
C
Code
R.drc
Htm
X.java W.htm Y.java Z.htm
C = [ [ X.java
B
X.java
A
, Y.java
B
Y.java
A
], R.drc
B
R.drc
A
, [ W.htm
B
, Z.htm
A
] ]
Don Batory
UT-Austin Computer Sciences
intro 72
Polymorphism... Polymorphism...
Composition operation is polymorphic
law of composition says how vectors are composed
different implementation of for each representation
for code
th f ht l fil t another for html files, etc.
But what does refining a non code artifact mean? But what does refining a non-code artifact mean?
what general principle guides refinement?
Don Batory
UT-Austin Computer Sciences
intro 73
Example: Makefiles Example: Makefiles
Instructions to build parts of a system
it is a language for synthesizing programs it is a language for synthesizing programs
When we synthesize code for a system, y y ,
we also have to synthesize a makefile for it
Sounds good, but...
what is a refinement of a makefile?????
Don Batory
UT-Austin Computer Sciences
intro 74
Makefile Makefile
mymake y
main
compile A
common
compile X
clean
delete *.class
depends
compile B
compile C
compile Y
compile Z
command line> make main
Don Batory
UT-Austin Computer Sciences
intro 75
Makefile Refinements Makefile Refinements
mymake
note
collaborations!
y
main
compile A
common
compile X
clean
delete *.class
depends
b
a
compile B
compile C
compile Y
compile Z
s
e
f
o
compile D compile F
o
o compile D compile F
delete *.ser
b
a
r
compile E
Question: what is a general paradigm for refining
non-code artifact types?
Don Batory
UT-Austin Computer Sciences
intro 76
non code artifact types?
Makefiles Makefiles Have a Class Structure! Have a Class Structure!
<project myMake>
class myMake {
<project myMake>
<target main depends=common>
<compile A>
<compile B>
y {
void main {
{ ...
<co p e >
<compile C>
</target>
<target common>
}
void common {
<compile X>
<compile Y>
<compile Z>
/
...
}
</target>
...
</project>
}
...
}
Don Batory
UT-Austin Computer Sciences
intro 77
Insight #4: Principle of Uniformity Insight #4: Principle of Uniformity
Treat all artifacts equally, as objects or classes
create analog in OO representation create analog in OO representation
Refine non-code representations same as code
representations
That is you can refine any artifact That is, you can refine any artifact
understand it as an object, collection of objects, or classes
We are creating a theory of information
structure based on features
it k f d d ll th t ti it works for code and all other representations
Don Batory
UT-Austin Computer Sciences
intro 78
Big Picture Big Picture
Most artifacts today (HTML, XML, etc.) have or can have
a hierarchical structure
But there is no refinement relationship among artifacts!
whats missing are refinement operations for artifacts
Need tools to refine instances of each artifact type
MS Word?
given such tools scale step-wise refinement scales without bounds given such tools, scale step-wise refinement scales without bounds...
Features modularize changes/additions to
all representations of a system p y
so all artifacts (code, makefiles, etc.) are updated consistently
Compositions yield consistent representations of a system
l h exactly what we want
simple, elegant theory behind simple implementation
Don Batory
UT-Austin Computer Sciences
intro 79
Product Member Synthesis Overview Product Member Synthesis Overview
declarative DSL
generalizes RQO paradigm
scales to large systems
Engineer
artifacts of
specified system
Engineer
h
1
g
1
f
1
generator
hgf
artifact
1
specified system
h
2
g
2
f
2
generator
generator
expression
artifact
1
artifact
2
h
3
g
3
f
3
generator
expression
composition
and optimization ...
Don Batory
UT-Austin Computer Sciences
intro 80
Recommended Readings Recommended Readings
Batory, O'Malley. The Design and Implementation of Hierarchical Software Systems
with Reusable Components. ACM TOSEM, October 1992.
Batory Sarvela Rauschmayer Scaling Step Wise Refinement IEEE TSE June 2004 Batory, Sarvela, Rauschmayer. Scaling Step-Wise Refinement . IEEE TSE, June 2004.
Batory, Johnson, MacDonald, von Heeder. Achieving Extensibility Through Product-
Lines and Domain-Specific Languages: A Case Study. ACM TOSEM, April 2002.
Batory, Chen, Robertson, Wang. Design Wizards and Visual Programming
Environments for GenVoca Generators. IEEE TSE, May 2000.
Batory, Singhal, Thomas, Sirkin. Scalable Software Libraries. ACM SIGSOFT 1993.
Batory. Concepts for a Database System Compiler. ACM PODS 1988.
Brger, Schulte. Defining the Java Virtual Machine as Platform for Provably Correct
Java Compilation MFCS 1998 Java Compilation . MFCS 1998.
Baxter. Design Maintenance Systems. CACM, April 1992.
Czarnecki Eisenecker Generative Programming Methods Tools and Applications Czarnecki, Eisenecker. Generative Programming Methods, Tools and Applications.
Addison-Wesley 2000.
Don Batory
UT-Austin Computer Sciences
intro 81
Recommended Readings Recommended Readings
Czarnecki, Bednasch, Unger, Eisenecker. Generative Programming for Embedded
Software: An Industrial Experience Report. GPCE 2002.
Dijk t A Di i li f P i P ti H ll 1976 Dijkstra. A Discipline of Programming. Prentice-Hall, 1976.
Ernst. Higher-Order Hierarchies. ECOOP 2003.
G l All O k bl A hit t l Mi t h Wh it i h d t b ild S t Garlan, Allen, Ockerbloom. Architectural Mismatch or Why it is hard to build Systems
out of existing parts. ICSE 1995.
Flatt, Krishnamurthi, Felleisen. Classes and Mixins. ACM POPL 1998.
Harrison, Ossher. Subject-Oriented Programming (A Critique of Pure Objects).
OOPSLA 1993.
Kang et al Feature Oriented Domain Analysis Feasibility Study SEI 1990 Kang, et al. Feature Oriented Domain Analysis Feasibility Study . SEI 1990.
Kang, et al. FORM: A Feature-Oriented Reuse Method with Domain-Specific
Reference Architectures. Annals of Software Engineering 1998, 143-168.
Kiczales, et al. An Overview of AspectJ. ECOOP 2001.
Don Batory
UT-Austin Computer Sciences
intro 82
Recommended Readings Recommended Readings
Lieberherr. Adaptive Object-Oriented Software. PWS publishing, 1995.
Mezini, Lieberherr. Adaptive Plug-and-Play Components for Evolutionary Software
Development OOPSLA 1998 Development . OOPSLA 1998.
Mezini, Ostermann. Conquering Aspects with Caesar. AOSD 2003.
Mezini Ostermann Variability Management with Feature-Oriented Programming Mezini, Ostermann. Variability Management with Feature Oriented Programming
and Aspects. SIGSOFT 2004.
McDirmid, Flatt, and Hsieh. Jiazzi: new-Age Components for Old-Fashioned Java.
OOPSLA 2001.
Ossher and Tarr. Using Multi-Dimensional Separation of Concerns to (Re)Shape
Evolving Software. CACM October 2001.
Ossher and Tarr Multi dimensional separation of concerns and the Hyperspace Ossher and Tarr. Multi-dimensional separation of concerns and the Hyperspace
approach. In Software Architectures and Component Technology (M. Aksit, ed.),
2002
Reenskaug, et al. OORASS: Seamless Support for the Creation and Maintenance of g, pp
Object-Oriented Systems. Journal of OO Programming, 5(6): October 1992.
Don Batory
UT-Austin Computer Sciences
intro 83
Recommended Readings Recommended Readings
Simonyi. The Death of Computer Languages, the Birth of Intentional Programming.
NATO Science Committee Conference, 1995.
S d ki B t I l ti L d D i ith Mi i L ECOOP 1998 Smaragdakis, Batory. Implementing Layered Designs with Mixin Layers. ECOOP 1998.
Smaragdakis, Batory. Scoping Constructs for Program Generators. GCSE 1999.
Smaragdakis Batory Mixin Layers: An Object Oriented Implementation Technique for Smaragdakis, Batory. Mixin Layers: An Object-Oriented Implementation Technique for
Refinements and Collaboration-Based Designs . ACM TOSEM April 2002.
Tarr, et al. N Degrees of Separation: Multi-Dimensional Separation of Concerns. ICSE
1999.
Van Hilst, Notkin. Using Role Components to Implement Collaboration-Based Designs.
OOPSLA 1996.
Don Batory
UT-Austin Computer Sciences
intro 84
The AHEAD Tool Suite The AHEAD Tool Suite
Don Batory
Department of Computer Sciences
University of Texas at Austin
batory@cs utexas edu batory@cs.utexas.edu
www.cs.utexas.edu/users/dsb/
Copyright is held by the author/owner(s).
Presented at: Lipari School for Advances in Software Engineering Presented at: Lipari School for Advances in Software Engineering
July 8 - July 21, 2007, Lipari Island, Italy
Composer Tool Composer Tool
Key tool in AHEAD Tool Suite (ATS) is composer
composer expands AHEAD expression to yield target system composer expands AHEAD expression to yield target system
feat1
feat2 composer
feat321
feat2
feat3
composer
feat321 = feat3 feat2 feat1
> composer target=feat321 feat1 feat2 feat3
Don Batory
UT-Austin Computer Sciences
tools 2
Jak Files Jak Files
Program in extended-Java files
Jak(arta) files ( )
Java + feature declarations, etc.
Jak is an extensible language Jak is an extensible language
AHEAD is bootstrapped AHEAD is bootstrapped
Most AHEAD tools are written in Jak
Don Batory
UT-Austin Computer Sciences
tools 3
Other Tools... Other Tools...
Besides composer
jak2java translates Jak files to Java files
j javac compiler javac javac compiler
reform Jak or Java file formatter/pretty-printer
others...
f1
f2
f321 f321
jak2java
javac
f321
f2
f3
composer
jak2java
javac
> cd <model-directory>
> composer target=... p g
> reform *.jak
> jak2java *.jak
> reform *.java
> javac * java
Don Batory
UT-Austin Computer Sciences
tools 4
> javac *.java
Jak Jak- -File Composition Tools File Composition Tools
composer invokes Jak-specific tools to compose
Jak files Jak files
two tools now: jampack and mixin
jak2java translates Jak to Java
A.jak
(from feat 1)
A.jak
(from feat 2)
jampack
or mixin
A.jak
(composed)
jak2java A.java
A.jak
(from feat 3)
step #1 step #2
Don Batory
UT-Austin Computer Sciences
tools 5
jampack jampack
Flattens inheritance hierarchies
takes expression as input, produces single file as output p p p g p
basically macro expansion with a twist...
class top {
int a;
void foo() {...}
}
class top {
int a;
{ }
}
refines class top {
void foo() {...}
int b;
int bar() {...}
}
int b;
int bar() {...}
}
}
Don Batory
UT-Austin Computer Sciences
tools 6
jampack jampack
jampack may not be composition tool of choice
look at typical debugging cycle yp gg g y
problem: manual propagation of changes
reason: jampack doesnt preserve feature boundaries
A.jak
(from f1)
A.jak
(from f2)
jampack
A.jak
(composed)
jak2java A.java
A.jak
(from f3)
translate
debug
update
compose
propagate
Don Batory
UT-Austin Computer Sciences
tools 7
propagate
mixin mixin
Encodes class and its refinements as an inheritance
hierarchyy
SoUrCe A/top.jak
class top {
int a;
void foo() {...}
abstract class top$$A {
int a;
void foo() {...}
}
}
refines class top {
}
SoUrCe B/mid.jak
refines class top {
int b;
int bar() {...}
}
public class top extends top$$A {
int b;
int bar() {...}
}
Don Batory
UT-Austin Computer Sciences
tools 8
}
unmixin unmixin
Edit, debug composed A.jak files
unmixin propagates changes from composed file to unmixin propagates changes from composed file to
original feature files automatically
A.jak
(from feat 1)
A.jak
(composed)
jak2java A.java
A.jak
(from feat 2)
unmixin
translate
debug
update
A.jak
(from feat 3)
propagate
Don Batory
UT-Austin Computer Sciences
tools 9
Composable Representations Composable Representations
Current list...
*.jak extended Java files (Jakarta)
class
AHEAD tools
are written in
extended Java.
interface
state machine (ex: embedded DSL)
AHEAD has been
bootstrapped so
that its tools have
*. equation named expression files
*. b grammar files
that its tools have
been written using
AHEAD tools.
*. drc design rule files
others...
Don Batory
UT-Austin Computer Sciences
tools 10
Demo... Demo... see files,
compositions compositions
model
tree
view
Don Batory
UT-Austin Computer Sciences
tools 11
file view
Cultural Enrichment Cultural Enrichment
Note algebraic underpinning...
feat321
jak2java
feat1
feat2
composer
feat321 javac
feat321
f3 f2 f1 j k2j ( )
feat3
j ( )
Same paradigm as AHEAD
P = f3 f2 f1 jak2java( ) javac( )
Same paradigm as AHEAD
progressively elaborating a containment hierarchy
can optimize expression (not this one...)
Don Batory
UT-Austin Computer Sciences
tools 12
Cultural Enrichment Cultural Enrichment
To see connection, watch how module hierarchy is
transformed...
adding new artifacts is example of module refinement
feat1
feat2
feat3
composer
feat321 feat321
jak2java
javac
feat321
module
produced:
Big picture: lots of operations on AHEAD modules
produced:
Big picture: lots of operations on AHEAD modules
seems that lots of optimizations are possible too...
Don Batory
UT-Austin Computer Sciences
tools 13
A Simple Example A Simple Example A Simple Example A Simple Example
to illustrate concepts, tools
Don Batory
UT-Austin Computer Sciences
tools 14
Domain of Graph Applications Domain of Graph Applications
A grammar is a simple way to express family of
related applications related applications
tokens are features
sentences are feature compositions
cycle checking
undirected
directed
graph
depth-first
breadth-first
search
vertex numbering
connected regions
...
choose one
choose at least one
choose one
Don Batory
UT-Austin Computer Sciences
tools 15
Example Family Members Example Family Members
cycle checking
undirected
directed
graph
depth-first
breadth-first
search
vertex numbering
connected regions
...
undirected
graph
depth-first
search
cycle checking
vertex numbering
directed
graph
breadth-first
search
connected regions
...
Don Batory
UT-Austin Computer Sciences
tools 16
It is Easy to... It is Easy to...
Imagine a GUI tool
that allows you to
specify any possible
combination
declarative language
tool generates an g
explanation of your
specification
and identifies errors
(and suggests
corrections) when
combinations of features
See next lecture on
Verification of
Feature Compositions combinations of features
are not possible
Don Batory
UT-Austin Computer Sciences
tools 17
Feature Compositions
Thats Easy... Thats Easy...
So too is creating the underlying FOP model:
Gpl = {
DIRECTED directed graphs
UNDIRECTED di t d h
constants
UNDIRECTED undirected graphs
BFS breadth first search
d h fi h DFS depth first search
CYCLE cycle checking
functions
NUMBER vertex numbering
REGIONS connected regions
...
}
Don Batory
UT-Austin Computer Sciences
tools 18
}
Constructing Applications Constructing Applications
demo
graph_app = region vertex dfs directed
= vertex region dfs directed
automatic
mapping
= vertex region dfs directed
Don Batory
UT-Austin Computer Sciences
tools 19
Recommended Readings Recommended Readings
Batory, A Tutorial on Feature Oriented Programming and the AHEAD Tool Suite, January
2003.
Batory, Sarvela, Rauschmayer, "Scaling Step-Wise Refinement", IEEE TSE, June 2004.
Batory, Cardone, and Smaragdakis, Object-Oriented Frameworks and Product-Lines. SPLC
1999.
Ernst, Higher-Order Hierarchies, ECOOP 2003.
Holland, Specifying Reusable Components Using Contracts, ECOOP 1992, 287-308.
Lee, Siek, and Lumsdaine, The Generic Graph Component Library, OOPSLA 1999.
Lopez-Herrejon and Batory, A Standard Problem for Evaluating Product-Line Methodologies,
GCSE 2001.
Smaragdakis and Batory, Implementing Layered Designs with Mixin Layers, ECOOP 1998.
Smaragdakis and Batory, Mixin Layers: An Object-Oriented Implementation Technique for
Refinements and Collaboration-Based Designs, ACM TOSEM, March 2002.
Don Batory
UT-Austin Computer Sciences
tools 20
Verification of Verification of
F t C iti F t C iti Feature Compositions Feature Compositions
Don Batory
Department of Computer Sciences
University of Texas at Austin
batory@cs utexas edu batory@cs.utexas.edu
www.cs.utexas.edu/users/dsb/
Copyright is held by the author/owner(s).
Presented at: Lipari School for Advances in Software Engineering Presented at: Lipari School for Advances in Software Engineering
July 8 - July 21, 2007, Lipari Island, Italy
Introduction Introduction
Fundamental problem: not all compositions
of features are correct of features are correct
but code can still be generated! but code can still be generated!
and maybe code will still compile!
and maybe code will run for a while! and maybe code will run for a while!
impossible for users to figure out what went wrong!
Don Batory
UT-Austin Computer Sciences
verify 2
Introduction Introduction
Must verify correctness of compositions automatically
not all features are compatible not all features are compatible
selection of a feature may enable others, disable others
D i ifi t i t id tif l l iti Domain-specific constraints identify legal compositions
Want process of applying/testing constraints to be Want process of applying/testing constraints to be
automatic
too easy for users to make mistakes
Presentation overview:
tool demonstration tool demonstration
present theory behind the tool
Don Batory
UT-Austin Computer Sciences
verify 3
Tool Demo Tool Demo
Illustrate on Graph Product Line
has been applied to much larger examples pp g p
Declarative domain-specific language
t t t D ll b counterpart to Dell web page
Constraints propagated as selections are made Co st a ts p opagated as se ect o s a e ade
cannot specify incorrect design
C d b d l ifi ti Can debug model specifications
by verifying known properties of feature combinations
Don Batory
UT-Austin Computer Sciences
verify 4
Tool Demo Tool Demo
Don Batory
UT-Austin Computer Sciences
verify 5
Feature Diagrams and Grammars Feature Diagrams and Grammars
(The Theory Behind The Tool) (The Theory Behind The Tool)
Grammar
Feature
Diagram
?
Diagram
Don Batory
UT-Austin Computer Sciences
verify 6
Feature Diagrams Feature Diagrams
Feature diagrams are standard product-line notations
declarative way to specify products by selecting features
FDs are trees:
leaves are primitive features
internal nodes are compound features internal nodes are compound features
parent-child are containment relationships
car car
Car Body Transmission Engine Pulls Trailer Car Body Transmission Engine Pulls Trailer
Automatic Manual Electric Gasoline
Don Batory
UT-Austin Computer Sciences
verify 7
Automatic Manual Electric Gasoline
How To Read Feature Diagrams How To Read Feature Diagrams
Mandatory features that are required
Optional features that are optional Optional features that are optional
And all subfeatures (children) are selected
Alternative only 1 subfeature can be selected
Or 1+ or 0+ subfeatures can be selected
car car
Car Body Transmission Engine Pulls Trailer
and
Car Body Transmission Engine Pulls Trailer
Automatic Manual Electric Gasoline
or: 1+ choose1
Don Batory
UT-Austin Computer Sciences
verify 8
Automatic Manual Electric Gasoline
Another Example Another Example
What is a legal product specification?
E is ?
R is ?
and
R is ?
S is ?
and
choose1
and
Sound familiar?
de Jonge and Visser 2002:
FDs are graphical representations of grammars
GenVoca Grammars 1992:
grammar defines legal orders in which features can be composed grammar defines legal orders in which features can be composed
Don Batory
UT-Austin Computer Sciences
verify 9
Recall GPL Model Recall GPL Model
Gpl = {
DIRECTED directed graphs
UNDIRECTED undirected graphs
constants
BFS breadth first search
DFS depth first search
functions
CYCLE cycle checking
NUMBER vertex numbering
STRONGC strongly connected g y
...
}
Don Batory
UT-Austin Computer Sciences
verify 10
GPL Grammar GPL Grammar
Gpl : Alg+ [Src] Wgt Gtp;
Gt DIRECTED | UNDIRECTED h t k i Gtp : DIRECTED | UNDIRECTED ;
Wgt : WEIGHTED | UNWEIGHTED ;
each token is an
AHEAD
constant or
function
Src : DFS | BFS ;
Alg : NUMBER | CONNECTED | STRONGC
A t f thi d fi iti f f t
Alg : NUMBER | CONNECTED | STRONGC
| CYCLE | MSTPRIM | MSTKRUSKAL | SHORTEST ;
A sentence of this grammar defines a composition of features
Prog = NUMBER CYCLE BFS UNWEIGHTED DIRECTED
Don Batory
UT-Austin Computer Sciences
verify 11
Mapping of FDs to Grammars Mapping of FDs to Grammars
Diagram Grammar
S : e1 [e2] en ;
and
S
S : e1 | e2 | en ;
choose1
S : e1 | e2 | en ;
... S+ ... ... S+ ...
S : e1 | e2 | en ;
or: 1+
Don Batory
UT-Austin Computer Sciences
verify 12
Example: Convert FD to Grammar Example: Convert FD to Grammar
E : R S ;
and
R : g | h | i ;
S : a [ b] c ;
choose1 and
Application defined by Feature Model = sentence of grammar E
S : a [ b ] c ;
Resulting grammar is a GenVoca grammar (1992)
Don Batory
UT-Austin Computer Sciences
verify 13
Grammars and Propositional Formulas Grammars and Propositional Formulas Grammars and Propositional Formulas Grammars and Propositional Formulas
Grammar
Feature
Diagram
Propositional
Formula
?
Don Batory
UT-Austin Computer Sciences
verify 14
Formula
Propositional Formula Propositional Formula
Set of boolean variables and a propositional logic
predicate that constrains values of these variables predicate that constrains values of these variables
Standard operations Standard , , , , operations
Nonstandard: o sta da d
atmost1(e
1
...e
k
) at most one e
i
is true
Insight: A grammar is a compact representation of
a propositional formula a propositional formula
Don Batory
UT-Austin Computer Sciences
verify 15
Mapping Productions to Formulas Mapping Productions to Formulas
Given production: R : P1 | ... | Pn ;
R can be referenced in two ways:
R
Pattern Predicate
R P1 P2 ... Pn
R
R (P1 P2 Pn)
... R+ ...
(choose 1 or more)
... R ...
(choose 1)
R (P1 P2 ... Pn)
atmost1(P1,P2, ..., Pn)
Don Batory
UT-Austin Computer Sciences
verify 16
Mapping Patterns to Formulas Mapping Patterns to Formulas
T1 T2 ... Tn :: P
formula:
PT1 ^ PT2 ^ ... ^ PTn
T1 [T2] Tn :: Q T1 [T2] ... Tn :: Q
formula:
QT1 ^T2Q^... ^QTn QT1 T2Q ... QTn
Don Batory
UT-Austin Computer Sciences
verify 17
Example: Grammars to Formulas Example: Grammars to Formulas
Convert each production, pattern to formula
Take conjunction of all formulas Take conjunction of all formulas
Conjoin root of grammar
E : R S ;
E R ^ E S
E : R S ;
R : g | h | i ;
E R E S
R (g h i ) ^
^
R : g | h | i ;
S : a [ b ] c ;
(g )
atmost1( g, h, i )
Sa ^ bS ^ Sc
^
E
^
grammar
propositional formula
Don Batory
UT-Austin Computer Sciences
verify 18
p p
A sentence of E satisfies the propositional formula
and vice versa
Last Example Last Example
car
Car Body Transmission Engine Pulls Trailer
C CB^ C T ^ C E ^ PtC
Automatic Manual Electric Gasoline
Tr(Auto Man) ^ atmost1(Auto,Man)
CarCB ^ CarTr ^ CarEng ^ PtCar
^
Eng (Ele Gas)
^
C
^
Don Batory
UT-Austin Computer Sciences
verify 19
Car
Recap Recap
We can map any AHEAD model or
Feature Diagram to a propositional formula Feature Diagram to a propositional formula
But what about constraints? But what about constraints?
Any additional arbitrary propositional formulas Any additional, arbitrary propositional formulas
conjoined onto grammar formula
Ex: if features i and b are incompatible Ex: if features i and b are incompatible,
add the formula
i b b i) i b (b i)
Don Batory
UT-Austin Computer Sciences
verify 20
Example: Additional Constraints in GPL Example: Additional Constraints in GPL
Straight from Graph Algorithm Text
Don Batory
UT-Austin Computer Sciences
verify 21
GPL Model Specification GPL Model Specification
Gpl : Alg+ [Src] Wgt Gtp;
Gtp : DIRECTED | UNDIRECTED ;
| Wgt : WEIGHTED | UNWEIGHTED ;
Src : DFS | BFS ;
Alg : NUMBER | CONNECTED
| STRONGC | CYCLE | MSTPRIM
| |
grammar
| MSTKRUSKAL | SHORTEST ;
%%
NUMBER implies Gtp and Src;
CONNECTED implies UNDIRECTED and Src;
C C i li G d S CYCLE implies Gtp and DFS;
SHORTEST implies DIRECTED and WEIGHTED;
STRONGC implies DIRECTED and DFS;
constraints
MSTKRUSKAL or MSTPRIM implies
UNDIRECTED and WEIGHTED;
Don Batory
UT-Austin Computer Sciences
verify 22
Recap Recap
An AHEAD Model is a propositional formula! An AHEAD Model is a propositional formula!
primitive features and compound features are variables
Grammar:
specifies order in which features are composed
ordering very important for AHEAD
Additional propositional constraints: Additional propositional constraints:
weed out incompatible feature combinations
Don Batory
UT-Austin Computer Sciences
verify 23
Declarative Domain Declarative Domain--Specific Languages Specific Languages Declarative Domain Declarative Domain Specific Languages Specific Languages
GenVoca
Grammar
Feature
Diagram
?
Propositional
DDSLs
?
Don Batory
UT-Austin Computer Sciences
verify 24
Formula
Declarative Languages Declarative Languages
Features enable declarative program specifications
thats what feature diagrams are for!
counterpart of SQL, Dell web pages
Want a declarative GUI DSL that acts like a
syntax-directed editor
user selects desired features
tool precludes specifying incorrect programs y g g
Don Batory
UT-Austin Computer Sciences
verify 25
Constraint Propagation Constraint Propagation
1980s result from Artificial Intelligence
Logic Truth Maintenance System
boolean constraint propagation (BCP) algorithm boolean constraint propagation (BCP) algorithm
takes a boolean predicate, set of variable assignments as input,
deduces other variable assignments as output
i l ffi i t l ith very simple, efficient algorithm
See: Forbus and de Kleer, ,
Building Problem Solvers, MIT Press 1993.
BDDs (Binary Decision Diagrams) are also popular
Don Batory
UT-Austin Computer Sciences
verify 26
Debugging Feature Models Debugging Feature Models Debugging Feature Models Debugging Feature Models
very useful model debugging aid
Don Batory
UT-Austin Computer Sciences
verify 27
Debugging Feature Models Debugging Feature Models
We know features A and B are compatible
let P
model
be the predicate of our feature model
P
model
A B must be satisfiable
that is, is there a product that has both A and B?
Satisfiability (SAT) Solver
off-the-shelf tool that automatically determines if a boolean predicate is
satisfiable satisfiable
very efficient
Basis for feature model debugging gg g
provide a script of compatible, incompatible features and
verify that our feature model has these properties
solver confirms known properties of a model
Don Batory
UT-Austin Computer Sciences
verify 28
Experience Experience
Has worked well...
Use off the shelf constraint solvers
Predicates are simple Predicates are simple
Reason: architects think in terms of features
if predicates were really complicated
architects couldnt design
people couldnt program
because it would be too difficult because it would be too difficult
We are making explicit what is implicit now...
Don Batory
UT-Austin Computer Sciences
verify 29
Theres More... Theres More...
Benavides noticed you could add numerical
attributes to grammar g
Don Batory
UT-Austin Computer Sciences
verify 30
Theres More... and is Very Exciting! Theres More... and is Very Exciting!
Allow features to have additional parameters
property lists property lists
Generalize predicates to include constraints on
numeric variables
select product that maximizes/minimizes criteria
(performance!) (performance!)
restrict products based on performance requirements, criteria
use standard Constraint Satisfaction Problem (CSP) Solvers
see: Benavides, et al. Automated Reasoning on Feature
Models, CAISE 2005
Don Batory
UT-Austin Computer Sciences
verify 31
Future Future
Basic result:
software design is a satisfiability problem software design is a satisfiability problem
does there exist a system that satisfies the following set of
constraints?
Research: to find optimal system configurations Research: to find optimal system configurations
automatically
true automatic programming!
counterpart to relational query optimizers p q y p
Don Batory
UT-Austin Computer Sciences
verify 32
Recommended Readings Recommended Readings
Batory and O'Malley. The Design and Implementation of Hierarchical Software Systems with Reusable
Components. ACM TOSEM, October 1992.
Batory and Geraci Composition Validation and Subjectivity in GenVoca Generators IEEE TSE Feb 1997 Batory and Geraci. Composition Validation and Subjectivity in GenVoca Generators , IEEE TSE, Feb 1997.
Batory, Feature Models, Grammars, and Propositional Formulas, SPLC 2005.
version
1
version
0
++
client
program
=
client
code
version
0
++ U
version
1
version
0
++
thi i t h
version
1
client
code
= ++
this is not how
result is presented by
Dig and Johnson;
it is an architectural
metaprogramming
Don Batory
UT-Austin Computer Sciences
meta 26
1 code
p g g
expression of their
results
In the Future In the Future
IDEs will be component evolution calculators
IDEs will create update functions like U for distribution
distribute meta-functions, not components
U(x) U(x) U(x) U(x) U(x) U(x)
U(x) U(x) U(x)
IDEs will apply functions to code bases to automatically update them
Architectural metaprogramming is at the core of this technology
Don Batory
UT-Austin Computer Sciences
Architectural metaprogramming is at the core of this technology
meta 27
#3: Advances in Program Synthesis #3: Advances in Program Synthesis #3: Advances in Program Synthesis #3: Advances in Program Synthesis
Don Batory
UT-Austin Computer Sciences
meta 28
Background Background
Previous lectures have presented basic ideas on
feature modularity and product lines feature modularity and product lines
But now lets look inside the structure of features But now, let s look inside the structure of features
and see how it is related to
aspect-oriented programming (AOP) aspect o e ted p og a g ( O )
find similarities and differences between aspects and features
Don Batory
UT-Austin Computer Sciences
meta 29
What Are FOP Features? What Are FOP Features?
If we peer inside features we see familiar ideas popularized
by AOP
here I use ideas of AOP
Introduction adds new members to existing classes
corresponds to metaprogramming addition
Advice modifies methods at particular points, p p ,
called join points
quantification means advise all parts of a program distributivity!
advice is a distributive transformation
advice is behavior-extending not behavior-preserving
No subtraction in AOP or in FOP
Don Batory
UT-Austin Computer Sciences
meta 30
Introduction Introduction
Incrementally add new members, classes
class C {
Program P
void foo(){ }
String b;
}
void foo(){..}
int i;
}
class D {
i b String bar;
int cnt(){..}
}
Don Batory
UT-Austin Computer Sciences
meta 31
}
Meta Meta--Algebra Interpretation Algebra Interpretation
P = C.b + C.foo + C.i + D.bar + D.cnt
class C {
Program P
void foo(){ }
String b;
}
void foo(){..}
int i;
}
class D {
St i b String bar;
int cnt(){..}
}
Don Batory
UT-Austin Computer Sciences
meta 32
Advice Advice
Defined in terms of events called join points
when method is called
when method is executed
when a field is updated
...
Advice: when particular join points occur, execute a given
piece of code
Although advice has a dynamic interpretation, we can
give it a static metaprogramming interpretation give it a static metaprogramming interpretation
Don Batory
UT-Austin Computer Sciences
meta 33
Advice Example Advice Example
Program P
class C {
int i,j;
void setI (int x){ i=x; }
g
void setI (int x){ i=x; }
void setJ (int x){ j=x; }
}
f () i ( id ( )) after(): execution (void C.set*(..))
{ print(hi); } print(hi); print(hi);
Don Batory
UT-Austin Computer Sciences
meta 34
Meta Meta--Algebra Interpretation Algebra Interpretation
Program P
class C {
int i,j;
void setI (int x){ i=x; }
g
void setI (int x){ i=x; }
void setJ (int x){ j=x; }
}
f () i ( id ( ))
m
T
ikm
There are 3! different
summation orders
all yield the same
scalar result
=
m
k
T
ikm
scalar result
= ...
Don Batory
UT-Austin Computer Sciences
tensors 14
Tensor Projection Tensor Projection
Remove elements from dimensions
t l i l ti i t l l not a classical operation in tensor calculus
similar to data cubes of database systems
M M
C
1
C
2
C
3
C
c
..
M
ijk
C
1
C
2
C
3
i(1..3) k(1..3)
M
ijk
B
3
B
b
..
1
B
3
B
b
..
B
1
B
2
B
1
B
2
3
Don Batory
UT-Austin Computer Sciences
tensors 15
A
1
A
2
A
3
A
a
..
1
A
1
A
2
A
3
Program Cubes Program Cubes Program Cubes Program Cubes
Don Batory
UT-Austin Computer Sciences
tensors 16
Program Cubes (PCs) Program Cubes (PCs)
Are a fundamental design technique in FOP
Given model F = [ F
n
, ... F
2
, F
1
] // notice vector
Let program G = F
8
+ F
4
+ F
2
+ F
1
where + denotes composition operator
Can write G as:
G =
i (8 4 2 1)
F
i
G
i(8,4,2,1)
F
i
Don Batory
UT-Austin Computer Sciences
tensors 17
Generalize Interpretation Generalize Interpretation
An FOP model is a vector
F = [ F F F ] F = [ F
n
, ... F
2
, F
1
]
no longer a set
tensor of rank 1, dimension n ,
A program G =
i (8 4 2 1)
F
i
A program G =
i(8,4,2,1)
F
i
is a projection of model F
that includes only the needed features y
features in the vector are in composition order
vector is then contracted to a scalar
Don Batory
UT-Austin Computer Sciences
tensors 18
Program Cubes Program Cubes
Use n rank-1 FOP models called dimension
models to specify features or indices along a p y g
dimension
C
c
..
M
A 3-D model M with
A, B, C as dimension
B
C
1
C
2
C
3
A, B, C as dimension
models
A = [ A
1
, ... A
a
]
B [ B B ]
B
2
B
3
B
b
..
B = [ B
1
, ... B
b
]
C = [ C
1
, ... C
c
]
A A A A
B
1
B
2
..
Don Batory
UT-Austin Computer Sciences
tensors 19
A
1
A
2
A
3
A
a
Program Cubes Program Cubes
M is a tensor product: A B C
M has abc entries
C
c
..
M
E t M i l t th
B
C
1
C
2
C
3
Entry M
ijk
implements the
interaction of features
(A
i
, B
j
, C
k
)
B
2
B
3
B
b
..
(
i j k
)
examples shortly
A A A A
B
1
B
2
..
Don Batory
UT-Austin Computer Sciences
tensors 20
A
1
A
2
A
3
A
a
NN--Dimensional Models Dimensional Models
A program is now specified by n expressions
1 per dimension p
Program P in product-line of M has 3 expressions: g p p
P = A
6
+ A
3
+ A
1
=
i(6 3 1)
A
i 6 3 1 i(6,3,1) i
P = B
7
+ B
4
+ B
3
+ B
2
=
j(7 4 3 2)
B
j 7 4 3 2 j(7,4,3,2) j
P = C
9
+ C
1
=
k(9 1)
C
k 9 1 k(9,1) k
Don Batory
UT-Austin Computer Sciences
tensors 21
Contracting Tensors Contracting Tensors
The 3-expression specification of P is translated
into an M expression scalar by contracting M into an M expression scalar by contracting M
along each dimension
P =
i(6,3,1)
j(7,4,3,2)
k(9,1)
M
ijk
A indices B indices C indices
Really a projection and contraction to a scalar:
A indices B indices C indices
P =
ijk
(
i(6,3,1)
j(7,4,3,2)
k(9,1)
M
ijk
)
Don Batory
UT-Austin Computer Sciences
tensors 22
Contracting Tensors Contracting Tensors
Order in which dimensions are summed
(contracted) does not matter! (contracted) does not matter!
P = M
i j k
j(7,4,3,2)
i(6,3,1)
k(9,1)
i,j,k
B indices
A indices C indices
Commutativity property of tensor contraction
Provided that dimensions are orthogonal
this needs to be proven
Don Batory
UT-Austin Computer Sciences
tensors 23
Significance is Scalability! Significance is Scalability!
Complexity of program is # of features
Given n dimensions with d features per dimension
program complexity is O(d
n
)
using cubes O(dn)
ex: program P specified by 342 features of M or
only 3 + 4 + 2 dimensional features!
FOP program specifications are exponentially
shorter when using cubes shorter when using cubes
Don Batory
UT-Austin Computer Sciences
tensors 24
Academic Legacy Academic Legacy
Extensibility Problem or Expression Problem
classical problem in Programming Languages classical problem in Programming Languages
see papers by: Cook, Reynolds, Wadler, Torgensen
focus is on achieving data type and operation focus is on achieving data type and operation
extensibility in a type-safe manner
operation
f t features
how operation j
is implemented in
(i j)
structure
features
is implemented in
structure i
tensor entries are
refinements
(i,j)
Don Batory
UT-Austin Computer Sciences
tensors 25
Academic Legacy Academic Legacy
Multi-Dimensional Separation of Concerns
(MDSoC) (MDSoC)
Tarr, Ossher IBM
Cubes are tensor formulation of MDSoC and
Expression Problem Expression Problem
review a micro example (~35 line programs)
th l l ( 35K li ) then a large example (~35K line programs)
synthesis of the AHEAD Tool Suite
fi ll t h i t th lit f di i finally techniques to prove orthogonality of dimensions
Don Batory
UT-Austin Computer Sciences
tensors 26
Micro Example Micro Example Micro Example Micro Example
Calculator Model revisited
Don Batory
UT-Austin Computer Sciences
tensors 27
Calculator Matrix Calculator Matrix
View product-line as a matrix
Tensor product of Calc GUI = CT Tensor product of Calc
r
GUI
c
= CT
rc
GUI model
... ... ... ... ...
...
Core GUI
1
Cmd GUI
2
...
...
...
...
Sub
Form
...
Sub
2
Sub
c
Form
2
Form
c
... ...
Sub
1
Form
1
...
Sub
Form
Calc
model
...
...
Add
Base
Add
2
Add
c
Base
2
Base
c
Add
1
Base
1
Base
Add
model
Don Batory
UT-Austin Computer Sciences
tensors 28
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which GUI features to compose
MyCalc = GUI
1
+ Core MyCalc GUI
1
+ Core
project and contract the matrix
...
Core
...
GUI
1
... ... ...
Cmd GUI
2
Sub
Form
...
Sub
Form
Sub
1
Form
1
...
Sub
2
Sub
c
Form
2
Form
c
... ...
Add
Base
Base
Add Add
1
Base
1
Add
2
Add
c
Base
2
Base
c
Don Batory
UT-Austin Computer Sciences
tensors 29
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which GUI features to compose
MyCalc = GUI
1
+ Core MyCalc GUI
1
+ Core
project and contract the matrix
...
Core
...
GUI
1
...
+
+
Sub
Form
...
Sub
Form
Sub
1
Form
1
...
+
+
Add
Base
Base
Add Add
1
Base
1
+
+
Don Batory
UT-Austin Computer Sciences
tensors 30
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which Calc features to compose
MyCalc = Add + Base MyCalc Add + Base
project and contract the matrix
...
...
...
+
Core GUI
1
+
Sub
Form
...
Sub
Form
Sub
1
Form
1
...
+
+
Add
Base
Base
Add Add
1
Base
1
+
+
Don Batory
UT-Austin Computer Sciences
tensors 31
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which Calc features to compose
MyCalc = Add + Base MyCalc Add + Base
project and contract the matrix
MyCalc = Add
1
+ Add + Base
1
+ Base
Core GUI
1
+ process is symmetrical
i l l if
Add
Base
Base
Add Add
1
Base
1
+
+
+
get equivalent result if
rows are contracted
first
Don Batory
UT-Austin Computer Sciences
tensors 32
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which Calc features to compose
MyCalc = Add + Base MyCalc Add + Base
project and contract the matrix
Core GUI
1
Cmd GUI
2
...
...
... ... ...
Sub
Form
...
Sub
Form
Sub
1
Form
1
...
Sub
2
Sub
c
Form
2
Form
c
... ...
Add
Base
Base
Add Add
1
Base
1
Add
2
Add
c
Base
2
Base
c
Don Batory
UT-Austin Computer Sciences
tensors 33
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which Calc features to compose
MyCalc = Add + Base MyCalc Add + Base
project and contract the matrix
Core GUI
1
Cmd GUI
2
Add
Base
Base
Add Add
1
Base
1
Add
2
Add
c
Base
2
Base
c
+ + + + +
Don Batory
UT-Austin Computer Sciences
tensors 34
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which GUI features to compose
MyCalc = GUI
1
+ Core MyCalc GUI
1
+ Core
project and contract the matrix
Core GUI
1
Cmd GUI
2
Add
Base
Base
Add Add
1
Base
1
+ +
Add
2
Add
c
Base
2
Base
c
+ + +
Don Batory
UT-Austin Computer Sciences
tensors 35
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Define which GUI features to compose
MyCalc = GUI
1
+ Core MyCalc GUI
1
+ Core
project and contract the matrix
MyCalc = Add
1
+ Base
1
+ Add + Base
Core GUI
1
+
Add
Base
Base
Add Add
1
Base
1
+ + +
+
Don Batory
UT-Austin Computer Sciences
tensors 36
Calculator Synthesis is Tensor Contraction Calculator Synthesis is Tensor Contraction
Note generated expressions are not syntactically
identical identical
columns, rows:
MyCalc = Add + Add + Base + Base
rows, columns:
MyCalc = Add
1
+ Add + Base
1
+ Base
,
MyCalc = Add
1
+ Base
1
+ Add + Base
Expressions are equal because Add and Base
1
are commutative (orthogonal) ( g )
see how we prove this property later
Don Batory
UT-Austin Computer Sciences
tensors 37
When to Use Multiple Dimensions? When to Use Multiple Dimensions?
Rule: When adding a feature requires the
lock-step updating of many other features lock-step updating of many other features
row feature updates all columns row feature updates all columns
column feature updates all row features
Don Batory
UT-Austin Computer Sciences
tensors 38
A Macro Example A Macro Example A Macro Example A Macro Example
Synthesizing the AHEAD Tool Suite
Don Batory
UT-Austin Computer Sciences
tensors 39
Perspective Perspective
So far, our models customize individual programs
set of all such programs is a product-line set of all such programs is a product line
Tool Suite is an integrated set of programs,
each with different capabilities
MS Office (Excel, Word, Access, ...)
Question: Do features scale to tool suites?
product-line of tool suites product line of tool suites
Don Batory
UT-Austin Computer Sciences
tensors 40
IDEs: A Tool Suite IDEs: A Tool Suite
Integrated Development Environment (IDE)
it f t l t it d b d t suite of tools to write, debug, document programs
AHEAD variant: Java language extensibility
compiler formatter edit debugger
Java
Sm Sm
(state machine DSL)
I i i l f t l !!!
Don Batory
UT-Austin Computer Sciences
tensors 41
In principle, features scale!!!
The Problem The Problem Declarative IDE Declarative IDE
From this declarative DSL spec, how do we generate AHEAD tools?
Don Batory
UT-Austin Computer Sciences
tensors 42
Define Dimensional Model #1 Define Dimensional Model #1
AHEAD Model of Java Language Dialects
functions (optional features) constant
Dialects of Java specified by expression
J = [ Java, Sm, Tmpl, Ds, ... ]
p y p
Jak = Tmpl + Sm + Java // java + p // j
// state machines +
// templates
Don Batory
UT-Austin Computer Sciences
tensors 43
Define Orthogonal Model #2 Define Orthogonal Model #2
Tools can be specified by a different, orthogonal model
functions (optional features) constant
IDE = [ Parse, ToJava, Harvest, Doclet, ... ]
Different tools have different expressions
jak2java ToJava + Parse jak2java = ToJava + Parse
jedi = Doclet + Harvest + Parse
Don Batory
UT-Austin Computer Sciences
tensors 44
...
Tool Specification Tool Specification
Defined by a pair of expressions
one defines tool language g g
other defines tool actions
ex: jedi (i e javadoc) for the Jak dialect of Java ex: jedi (i.e., javadoc) for the Jak dialect of Java
jedi = Tmpl + Sm + Java // using J Model
Synthesize jedi by projecting and contracting the
jedi = Doclet + Harvest + Parse // using IDE Model
Synthesize jedi by projecting and contracting the
tensor product of the J and IDE models
Don Batory
UT-Austin Computer Sciences
tensors 45
Tensor for Tensor for jedi jedi
Rows are language features
Columns are tool features
Entries are modules (refinements) that implement a
language feature for a tool feature
Shows relationship between IDE and J models p
D l H P
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse
Cube
f
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
for
jedi
Don Batory
UT-Austin Computer Sciences
tensors 46
Tensor for Tensor for jedi jedi
Composition of these modules yields jedi
Synthesize jedi expression by contracting the Synthesize jedi expression by contracting the
tensor according to its dimensional expressions
D l H P
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse
Tensor
f
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
for
jedi
Don Batory
UT-Austin Computer Sciences
tensors 47
Contract the Tensor! Contract the Tensor!
IDE expression
jedi = Doclet + Harvest + Parse jedi = Doclet + Harvest + Parse
Tells us the column summation order
D l H P D l H P D l H P
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse
Sum Harvest
ith P
Sum remaining
columns
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse +
+ +
+
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
with Parse
columns
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
+
+
+
+
Don Batory
UT-Austin Computer Sciences
tensors 48
Now Contract the Rows Now Contract the Rows
J expression
jedi = Tmpl + Sm + Java jedi = Tmpl + Sm + Java
Tells us the row summation order
D l H P D l H P D l H P
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse + + JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse
Sum Java
d S R
+ +
+
JDoclet
JHarvest
Java
Doclet Harvest Parse
JParse
now add
+ +
+ +
+ +
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
+
+
+
+
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
and Sm Rows
+
+
+
+
SDoclet
SHarvest
Sm
Tmpl
SParse
TDoclet
THarvest TParse
Tmpl Row
+
+
+
+
+ +
Don Batory
UT-Austin Computer Sciences
tensors 49
Resulting Expression Resulting Expression
jedi = ( TDoclet + THarvest + TParse ) +
( SDoclet + SHarvest + SParse ) +
( l ) ( JDoclet + JHarvest + JParse )
Using Cubes we can synthesize an expression for a
language-dialect specific tool
Don Batory
UT-Austin Computer Sciences
tensors 50
Using Cubes to Generate Using Cubes to Generate
Tool Suites...
Don Batory
UT-Austin Computer Sciences
tensors 51
Product Product--Line Tensor Line Tensor
That relates J and IDE models
Rows are language features
Columns are tool features
Entries implement feature interactions (refinements)
P T J H t D l t Si t
Java
Parse ToJava Harvest Doclet Signat
JParse J2Java JHarvest JDoclet JSig
Sm
Tmpl
SParse
TParse
S2Java
T2Java
SHarvest
THarvest
SDoclet
TDoclet
SSig
TSig
Ds DParse D2Java DHarvest DDoclet DSig
Don Batory
UT-Austin Computer Sciences
tensors 52
To Synthesize IDE Tools To Synthesize IDE Tools
Project unneeded rows and columns
directly from IDE GUI input
l j di j k2j f J S T l example: jedi, jak2java for Java + Sm + Tmpl
Java
Parse ToJava Harvest Doclet Signat
JParse J2Java JHarvest JDoclet JSig
Sm
Tmpl
SParse
TParse
S2Java
T2Java
SHarvest
THarvest
SDoclet
TDoclet
SSig
TSig
Ds DParse D2Java DHarvest DDoclet DSig
Don Batory
UT-Austin Computer Sciences
tensors 53
Tensor for IDE Tools Tensor for IDE Tools
Contract rows
Note the semantics of the result...
P T J H t D l t P T J H t D l t P T J H t D l t
Java
Parse ToJava Harvest Doclet
JParse J2Java JHarvest JDoclet Java
Parse ToJava Harvest Doclet
JParse J2Java JHarvest JDoclet
+ + + +
Java
Parse ToJava Harvest Doclet
JParse J2Java JHarvest JDoclet
+ + + +
Sm
Tmpl
SParse
TParse
S2Java
T2Java
SHarvest
THarvest
SDoclet
TDoclet
Sm
Tmpl
SParse
TParse
S2Java
T2Java
SHarvest
THarvest
SDoclet
TDoclet
Sm
Tmpl
SParse
TParse
S2Java
T2Java
SHarvest
THarvest
SDoclet
TDoclet
+ + + +
Don Batory
UT-Austin Computer Sciences
tensors 54
Yields Expression For Each Tool Feature! Yields Expression For Each Tool Feature!
Parse = TParse + SParse + JParse
ToJava = T2Java + S2Java + J2Java
Harvest = THarvest + SHarvest + JHarvest
And we know expressions for each tool!
Doclet = TDoclet + SDoclet + JDoclet
And we know expressions for each tool!
jak2java = ToJava + Parse
jedi = Doclet + Harvest + Parse
...
Don Batory
UT-Austin Computer Sciences
tensors 55
IDE Generator is Simple IDE Generator is Simple
For each selected tool, evaluate its expression
And generate the code
for each tool
automatically! automatically!
Don Batory
UT-Austin Computer Sciences
tensors 56
Generator of IDE Tool Suite Generator of IDE Tool Suite
Engineer h
1
+g
1
+f
1
generator
jak2java
h
2
+g
2
+f
2
f
generator
jedi
cube
h
3
+g
3
+f
3
generator
...
generator
Don Batory
UT-Austin Computer Sciences
tensors 57
Experimental Results Experimental Results Experimental Results Experimental Results
Don Batory
UT-Austin Computer Sciences
tensors 58
Bootstrapping AHEAD Bootstrapping AHEAD
We contracted a tensor of rank 3,
dimension (868) to generate 5 tools of the
AHEAD T l S i AHEAD Tool Suite
Tool Features
Lang
Features
3 d di i
Lang
Features
Features
3rd dimension captures
language feature interactions
Don Batory
UT-Austin Computer Sciences
tensors 59
Bootstrapping AHEAD Bootstrapping AHEAD
Contract tensor to produce IDE model, from which
we can generate tool expression g p
Tool Features
Lang
Features
Sum 3
rd
dimension
Sum rows
Features
Lang
Features
IDE Model IDE Model
Don Batory
UT-Austin Computer Sciences
tensors 60
Results of AHEAD Bootstrap Results of AHEAD Bootstrap
90 distinct features
Typical tool contains 20-30 features
most tools share 10 features
Generated Java for each tool is ~35K LOC
Generating well close to 150K from simple, declarative
specifications
exactly what we want
Making designs for multiple tools to conform to a tensor
controlling the complexity of tool suites controlling the complexity of tool suites
Don Batory
UT-Austin Computer Sciences
tensors 61
Tensor Representations Scale!! Tensor Representations Scale!!
Micro example ~150 LOC total p
AHEAD example ~150K LOC total p
3 orders of magnitude!
Cubes apply to all levels of abstraction equally
Cubes scale to much larger systems
Don Batory
UT-Austin Computer Sciences
tensors 62
Proving Commutativity Properties Proving Commutativity Properties
of Tensors of Tensors
On going work
Don Batory
UT-Austin Computer Sciences
tensors 63
Contracting Tensors Contracting Tensors
We assumed a basic property of tensors
Order in which dimensions are contracted
does not matter
commutativity property that we have to verify
C b d t b th l t l Cubes need not be orthogonal, as next example
shows
Don Batory
UT-Austin Computer Sciences
tensors 64
Example of Non Example of Non--Orthogonal Cube Orthogonal Cube
A non-orthogonal Cube
by rows first
by columns
first
Don Batory
UT-Austin Computer Sciences
tensors 65
So What? So What?
Contract tensors differently to provide different views of
software
viewing modules from language feature viewpoint or tool feature view
point is occasionally useful
Properties derived in one view (contraction), might not hold
in other views
Edits or code repairs performed in one view might not work
correctly in other views
Need consistent views!!
simple design changes can make a cube orthogonal simple design changes can make a cube orthogonal
Don Batory
UT-Austin Computer Sciences
tensors 66
A Fix: An Orthogonal Cube A Fix: An Orthogonal Cube
An orthogonal cube and its contraction
Don Batory
UT-Austin Computer Sciences
tensors 67
Properties to Preserve Properties to Preserve
Same program must be synthesized when tensor
dimensions are contracted in any order y
For a tensor A of rank 2:
k
A
ik
=
k
i
A
ik
For a tensor of rank n, there are n! summation orders,
all must produce equivalent results a us p oduce equ a e esu s
Need algorithms to verify these properties
Don Batory
UT-Austin Computer Sciences
tensors 68
Orthogonality Property Orthogonality Property
Reduces to testing 2D matrix
F h b b l h f ll i h ld For the above to be equal, the following must hold
composition of the bottom left and upper right quadrants
must commute must commute
Don Batory
UT-Austin Computer Sciences
tensors 69
aa
21 21
and a and a
12 12
commute if commute if
(1) they do not add or refine the same member
they add or refine non-overlapping sets of methods and they add or refine non-overlapping sets of methods and
variables
(2) they do not refer to members added by each
other
Both conditions are easy to verify;
th h d t i d i ffi i tl the hard part is doing so efficiently
brute force doesnt work as it would be hideously slow
Don Batory
UT-Austin Computer Sciences
tensors 70
Essence of the Algorithm Essence of the Algorithm
For an arbitrary rank, dimension tensor T
For every member m added or refined in feature F, store it
along with the coordinates of F in T in a hash table
If a prior definition of m exists (meaning it was added or
refined by another feature G), see if the coordinates of F
d G fli t d if th d if F d G b l i and G conflict and if they do, see if F and G can belong in
the same product
if so, T is not orthogonal , g
Similar analysis for references
Almost linear in the size of the code base
Don Batory
UT-Austin Computer Sciences
tensors 71
Example: Bali Tools of ATS Example: Bali Tools of ATS
f t
require refines
method defined
in composer |
bali2jak |
feature
model
grammar
bali2jak | ...
Don Batory
UT-Austin Computer Sciences
tensors 72
Example Error Example Error
Require refines method defined in Composer
public Object driver( String[] args ) throws Throwable {
setVersion( "v2003.02.17" ) ;
composer.main
...
Collector collector = collectSources( inpFiles ) ;
...
return collector ;
}
i j i ( i [] ) {
require.main
public Object driver( String args[] ) throws Throwable {
setVersion( "v2002.09.03" ) ;
return Super( String[] ).driver( args ) ;
}
Don Batory
UT-Austin Computer Sciences
tensors 73
Another Error Another Error
require and
codegen
both refine
method in bali
grammar
method in bali
Don Batory
UT-Austin Computer Sciences
tensors 74
Example Error Example Error
Require and Codegen both refine method in Bali
bali.main
public Object driver( String args[] ) throws Throwable {
...
return parseTree ;
}
public Object driver( String args[] ) throws Throwable {
codegen.main
}
setVersion( "v2002.09.04" ) ;
return Super( String[] ).driver( args ) ;
}
require main
public Object driver( String args[] ) throws Throwable {
setVersion( "v2002.09.03" ) ;
return Super( String[] ).driver( args ) ;
}
require.main
Don Batory
UT-Austin Computer Sciences
tensors 75
}
Other Statistics Other Statistics
Fast didnt find errors in JPL
Don Batory
UT-Austin Computer Sciences
tensors 76
Insights Insights
Oddly, we didnt find serious errors in the ATS
designs designs
only benign (inconsequential) errors were found
Created these designs long before we had any
analysis tools y
suggests that creating orthogonal tensors is not difficult
Don Batory
UT-Austin Computer Sciences
tensors 77
Final Comments Final Comments Final Comments Final Comments
Don Batory
UT-Austin Computer Sciences
tensors 78
Future Work Future Work
Commutativity or orthogonal properties have a
simple description in category theory
deep interconnection with our use of tensors
Other forms of feature interactions Other forms of feature interactions
generalization of the ideas presented here seem to account for
many of such interactions
developing theories and supporting tools for this p g pp g
Additional analyses
want to analyze product-lines to ensure that all legal want to analyze product lines to ensure that all legal
compositions of features yield type safe programs
Thaker, Batory, Kitchin, Cook.
S f C iti f P d t Li GPCE 2007 Safe Composition of Product Lines, GPCE 2007
Don Batory
UT-Austin Computer Sciences
tensors 79
Recommended Readings Recommended Readings
Batory, Lopez-Herrejon, Martin, Generating Product-Lines of Product Families,
Automated Software Engineering 2002.
Batory Liu Sarvela Refinements and Multi Dimensional Separation of Concerns ACM Batory, Liu, Sarvela, Refinements and Multi-Dimensional Separation of Concerns , ACM
Sigsoft 2003.
M. Calder, M. Kolberg, E.H. Magill, and S. Reiff-Marganiec, Feature Interaction:
A Critical Review and Considered Forecast.Computer Networks, January 2003.
Cook Object-Oriented Programming versus Abstract Data Types. Workshop on
Foundations of Object-Oriented Languages, Lecture Notes in Computer Science, Vol.
173. Spring-Verlag, (1990) 151-178
Harrison and Ossher, Subject-Oriented Programming (A Critique of Pure Objects),
OOPSLA 1993, 411-427.
Kay, Tensor Calculus, Shaums Outlines, 1988. y, , ,
J. Liu, D. Batory, and C. Lengauer. "Feature Oriented Refactoring of Legacy
Applications", ICSE 2006.
Don Batory
UT-Austin Computer Sciences
tensors 80
Recommended Readings Recommended Readings
Ossher and Tarr, Using Multi-Dimensional Separation of Concerns to (Re)Shape
Evolving Software. CACM 44(10): 43-50, October 2001.
Reynolds User defined types and procedural data as complementary approaches to Reynolds User-defined types and procedural data as complementary approaches to
data abstraction. Reprinted in C.A. Gunter and J.C.Mitchell, Theoretical Aspects of
Object-Oriented Programming, MIT Press,1994.
Thaker, Design and Analysis of MultiDimensional Program Structures, M.Sc. Thesis, , g y g , ,
Dept. Computer Sciences, University of Texas at Austin, 2006.
Thaker, Batory, Kitchin, Cook, Towards Safe Composition of Product-Lines, GPCE
2007.
Tarr, Ossher, Harrison, and Sutton, N Degrees of Separation: Multi-Dimensional
Separation of Concerns, ICSE 1999.
Torgensen The Expresion Problem Revisited Four new solutions using generics Torgensen The Expresion Problem Revisited. Four new solutions using generics ,
ECOOP 2004.
Wadler The expression problem. Posted on the Java Genericity mailing list (1998)
Don Batory
UT-Austin Computer Sciences
tensors 81