+ All Categories
Home > Technology > Virtual Separation of Concerns (2011 Update)

Virtual Separation of Concerns (2011 Update)

Date post: 29-Jun-2015
Category:
Upload: chk49
View: 4,997 times
Download: 2 times
Share this document with a friend
Description:
Revised and extended version of the "Virtual Separation of Concerns" talk, prepared for the GI-Dissertationspreis colloquium at Dagstuhl and for the invited talk at Oregon State University in Corvallis.
Popular Tags:
64
Virtual Separation of Concerns Christian Kästner Photo (cc) Horia Varlan
Transcript
Page 1: Virtual Separation of Concerns (2011 Update)

Virtual Separation of Concerns

Christian Kästner

Photo (cc) Horia Varlan

Page 2: Virtual Separation of Concerns (2011 Update)
Page 3: Virtual Separation of Concerns (2011 Update)

Feature-Oriented

Product Lines

Page 4: Virtual Separation of Concerns (2011 Update)

DatabaseEngine

Page 5: Virtual Separation of Concerns (2011 Update)

Printer Firmware

Page 6: Virtual Separation of Concerns (2011 Update)

LinuxKernel

Page 7: Virtual Separation of Concerns (2011 Update)

7

Page 8: Virtual Separation of Concerns (2011 Update)

Variability = Complexity

Page 9: Virtual Separation of Concerns (2011 Update)

a unique configuration for every

person on this planet

33 featuresoptional, independent

Page 10: Virtual Separation of Concerns (2011 Update)

320 features

more configurations than estimated

atoms in the universe

optional, independent

Page 11: Virtual Separation of Concerns (2011 Update)

Correctness?

Page 12: Virtual Separation of Concerns (2011 Update)

Maintenance?Comprehension?

Page 13: Virtual Separation of Concerns (2011 Update)

static int _rep_queue_filedone(...)DB_ENV *dbenv;REP *rep;__rep_fileinfo_args *rfp; {

#ifndef HAVE_QUEUECOMPQUIET(rep, NULL);COMPQUIET(rfp, NULL);return (__db_no_queue_am(dbenv));

#elsedb_pgno_t first, last;u_int32_t flags;int empty, ret, t_ret;

#ifdef DIAGNOSTICDB_MSGBUF mb;

#endif...

Excerpt from Oracle’s Berkeley DB

Conditional Compilation

Page 14: Virtual Separation of Concerns (2011 Update)

Objections / Criticism

“#ifdef considered harmful”“#ifdef hell”

Designed in the 70th and hardly evolved since

“preprocessor diagnostics are poor”

“is difficult to determine if the code being viewed is actually compiled into the system”

“programming errors are easy to make and difficult to detect”

“incomprehensible source texts”

“maintenance becomes a ‘hit or miss’ process”

“CPP makes maintenance difficult”

“source code rapidly becomes a maze”

Page 15: Virtual Separation of Concerns (2011 Update)

Academia: Compositional Approaches

class Stack { void push(Object o) { elementData[size++] = o; } ...}

class Stack { void push(Object o) { elementData[size++] = o; } ...}

refines class Stack { void push(Object o) { Lock l = lock(o); Super.push(o); l.unlock(); } ...}

refines class Stack { void push(Object o) { Lock l = lock(o); Super.push(o); l.unlock(); } ...}

Base / Platform

Feature: Queue

Feature: Diagnostic

aspect Diagnostics { ...}

aspect Diagnostics { ...}

class Stack { void push(Object o) { Lock l = lock(o); elementData[size++] = o; l.unlock(); } ...}

class Stack { void push(Object o) { Lock l = lock(o); elementData[size++] = o; l.unlock(); } ...}

Composition

ModuleComponentsFrameworks, Plug-insFeature-Modules / Mixin Layers / …Aspects / Subjects, Hyper/J, Deltas

Page 16: Virtual Separation of Concerns (2011 Update)

A CLOSER LOOK AT PREPROCESSORS

Page 17: Virtual Separation of Concerns (2011 Update)

Separation of Concerns

Page 18: Virtual Separation of Concerns (2011 Update)

Obfuscationclass Stack {

void push(Object o#ifdef SYNC

, Transaction txn#endif

) {if (o==null

#ifdef SYNC|| txn==null

#endif) return;

#ifdef SYNCLock l=txn.lock(o);

#endifelementData[size++] = o;

#ifdef SYNCl.unlock();

#endiffireStackChanged();

}}

Page 19: Virtual Separation of Concerns (2011 Update)

Femto OS

Obfuscation

Page 20: Virtual Separation of Concerns (2011 Update)

Error-Pronestatic int _rep_queue_filedone(...)

DB_ENV *dbenv;REP *rep;__rep_fileinfo_args *rfp; {

#ifndef HAVE_QUEUECOMPQUIET(rep, NULL);COMPQUIET(rfp, NULL);return

(__db_no_queue_am(dbenv));#else

db_pgno_t first, last;u_int32_t flags;int empty, ret, t_ret;

#ifdef DIAGNOSTICDB_MSGBUF mb;

#endif// over 100 lines of add. code

}#endif

#ifdef TABLESclass Table { void insert(Object data, Txn txn) { storage.set(data, txn.getLock()); }}#endifclass Storage {#ifdef WRITE boolean set(…) { ... }#endif}

Page 21: Virtual Separation of Concerns (2011 Update)

Advantages• Easy to use

• “annotate and remove”• Already part of many languages / simple tools• Most developers already familiar

• Flexible / Expressive• Language-independent / Uniform

• Low Adoption Barrier• esp. with legacy code

Page 22: Virtual Separation of Concerns (2011 Update)

IMPROVING TOOL SUPPORT

Page 23: Virtual Separation of Concerns (2011 Update)

Views

[ICSE’08, ViSPLE’08]

Page 24: Virtual Separation of Concerns (2011 Update)
Page 25: Virtual Separation of Concerns (2011 Update)

View on Feature Eval

Page 26: Virtual Separation of Concerns (2011 Update)

View on Configuration “Add and Eval”

Page 27: Virtual Separation of Concerns (2011 Update)

[ICSE’08, ICSE‘10, EASE‘11]

Page 28: Virtual Separation of Concerns (2011 Update)

FeatureCommander

Page 29: Virtual Separation of Concerns (2011 Update)

Controlled

Experiments

Scaling? How Used?

Faster?

3

Page 30: Virtual Separation of Concerns (2011 Update)

ERROR DETECTION / PREVENTION

Page 31: Virtual Separation of Concerns (2011 Update)

Disciplined

#ifdef WORLDint main() {

printf(“Hello World”);}#endifint main() {#ifdef WORLD

printf(“Hello World”);#endif}

Annotations

Align with code structure

greet.c

printf

msg

VWORLD VBYEprintf

msg msg

main

ε ε

Align with variability model

Page 32: Virtual Separation of Concerns (2011 Update)

Disciplined

#ifdef WORLDint main() {

printf(“Hello World”);}#endif

int main() {#ifdef DYNAMIC

if (enabled) {#endif

printf(“Hello World”);#ifdef DYNAIC

}#endif}

int main() {#ifdef WORLD

printf(“Hello World”);#endif}

AnnotationsUndisciplined

int a = #ifdef DYNAMIC

enabled? 3 : 4 +#endif

5;Align with code structure

Align with variability model

Page 33: Virtual Separation of Concerns (2011 Update)

static int _rep_queue_filedone(...)DB_ENV *dbenv;REP *rep;__rep_fileinfo_args *rfp; {

#ifndef HAVE_QUEUECOMPQUIET(rep, NULL);COMPQUIET(rfp, NULL);return

(__db_no_queue_am(dbenv));#else

db_pgno_t first, last;u_int32_t flags;int empty, ret, t_ret;

#ifdef DIAGNOSTICDB_MSGBUF mb;

#endif// over 100 lines of add. code

}#endif

Page 34: Virtual Separation of Concerns (2011 Update)

Variability-AwareParserType SystemStatic AnalysisBug FindingTestingModel CheckingTheorem Proving…

Page 35: Virtual Separation of Concerns (2011 Update)
Page 36: Virtual Separation of Concerns (2011 Update)

Conflicts

References

Page 37: Virtual Separation of Concerns (2011 Update)

Pre

sence

Conditio

ns

true

true

WORLD

BYE

Page 38: Virtual Separation of Concerns (2011 Update)

Reachability: pc(caller) -> pc(target)Conflicts: ¬(pc(def1) ˄ pc(def2))

true -> true

true -> (WORLD v BYE)

¬ (WORLD ˄ BYE)

Page 39: Virtual Separation of Concerns (2011 Update)

Variability Model:

VM -> (true -> true)

VM -> (true -> (WORLD v BYE))

P

WORLD BYE

VM ->¬ (WORLD ˄ BYE)

Page 40: Virtual Separation of Concerns (2011 Update)

40BYEWORLD

AST with Variability Information

Extended Lookup Mechanism

greet.c

printf

msg

VWORLD VBYEprintf

msg msg

main

ε ε

true -> true

true -> (WORLD v BYE)¬ (WORLD ˄ BYE)

Page 41: Virtual Separation of Concerns (2011 Update)

Formalization: CFJ[ASE’08, TOSEM‘11]

Page 42: Virtual Separation of Concerns (2011 Update)

Surface Complexity

Handling Complexity

SATProblem

InherentComplexity

Page 43: Virtual Separation of Concerns (2011 Update)

Variability-Aware AnalysisType SystemStatic AnalysisBug FindingTestingModel CheckingTheorem Proving…

Page 44: Virtual Separation of Concerns (2011 Update)

CIDE

http://fosd.de/cide

open source, fosd.net/cide

Page 45: Virtual Separation of Concerns (2011 Update)

Automated Refactorings• Feature Module • Annotationen

class Stack {int[] data;

#ifdef UNDOint backup;void undo() {

/*...*/ }#endif#ifdef TOP

int top() { /*...*/ }#endif

void push(int o) {#ifdef UNDO

backup = top();#endif

/*...*/}int pop() {

/*...*/ }}

class Stack {int[] data;

#ifdef UNDOint backup;void undo() {

/*...*/ }#endif#ifdef TOP

int top() { /*...*/ }#endif

void push(int o) {#ifdef UNDO

backup = top();#endif

/*...*/}int pop() {

/*...*/ }}

class Stack {int[] data;void push(int o) { …

}int pop() {

/*...*/ }}

class Stack {int[] data;void push(int o) { …

}int pop() {

/*...*/ }}refines class Stack {

int top() { /*...*/ }}

refines class Stack {int top() {

/*...*/ }}refines class Stack {

int backup;void undo() {

/*...*/ }void push(int o) {

backup = top();original(v);

}}

refines class Stack {int backup;void undo() {

/*...*/ }void push(int o) {

backup = top();original(v);

}}

Base

Top

Undo

Automated Transformation

[GPCE’09]

Page 46: Virtual Separation of Concerns (2011 Update)

THE REAL-WORLD CHALLENGE

Page 47: Virtual Separation of Concerns (2011 Update)

Parse and Type check all configurations of the

entire Linux kernel

10,000 features, 6 million lines of C code

TypeChef

Page 48: Virtual Separation of Concerns (2011 Update)

AST with Variability Information

Variability-AwareParsing

greet.c

printf

msg

VWORLD VBYEprintf

msg msg

main

ε ε

[OOPSLA‘11]

Page 49: Virtual Separation of Concerns (2011 Update)

greet.c

printf

msg

VWORLD VBYE+ printf

+ msg + msg

+ main

ε ε

???

Macro expansion needed for parsing Alternative macros

Undisciplined annotations

Page 50: Virtual Separation of Concerns (2011 Update)

Parsing Cwithout Preprocessing

Page 51: Virtual Separation of Concerns (2011 Update)
Page 52: Virtual Separation of Concerns (2011 Update)

Previous Solutions

Disciplined SubsetRequires Code Preparation

Heuristics and Partial AnalysisInaccurate, False Positives

Brute ForceInfeasible Effort

Page 53: Virtual Separation of Concerns (2011 Update)

TypeChef

+

* VA

2 43 5

Variability-Aware

Parser

Variability-Aware

Analysis

https://github.com/ckaestne/TypeChef

Variability-Aware

Lexer

(2

*3

)+

4A5¬A

Page 54: Virtual Separation of Concerns (2011 Update)

3 +

4A 4¬A˄B +¬A˄B 6¬A

(

(¬A )¬A

4A (¬A

4¬A˄B +¬A˄B 6¬A

4¬A˄B +¬A˄B 6¬A

)¬A

+

64

VB

6

)

true

4

VA

+

3

Page 55: Virtual Separation of Concerns (2011 Update)

Variability-Aware Parsers

GNU C + cpp Java + Antenna

Page 56: Virtual Separation of Concerns (2011 Update)

X862.6.33.3

Parsing Linux

Variability in Build System (kbuild) and with #ifdef

Variability Model (kconfig)

Page 57: Virtual Separation of Concerns (2011 Update)

0 included header files per C file

0 macros per C file

0 conditional macros per C file

0 alternative macros per C file

0 token per C file

0 % conditional

35385901387

340

33549072

X862.6.33.3

Page 58: Virtual Separation of Concerns (2011 Update)

0 C files (x86)

0 seconds per file (median)

0 hours total

0 % overhead (undiscipl.)

0

0 syntax errors

76653085

4.1

0X862.6.33.3

Page 59: Virtual Separation of Concerns (2011 Update)

X862.6.33.3

Type Checking Linux

Work in Progress

Page 60: Virtual Separation of Concerns (2011 Update)

SUMMARY AND PERSPECTIVE

Page 61: Virtual Separation of Concerns (2011 Update)

Summary• Problems:

• Separation of Concerns• Obfuscation• Error-proneness

• Retained advantages:• Easy to use• Flexible• Language-independent• Low adoption barrier

• Improvements:• Views• Visual representation• Variability-aware analysis

• Remaining Problems:• Modular Type Checking• Separate Compilation• Black-box Reuse

“Virtual Separation of Concerns”

Page 62: Virtual Separation of Concerns (2011 Update)

Perspective

• Preprocessors common in practice, despite criticism • Neglected by researchers• Tool support can address most problems• Currently scaling to Linux

• Interim solution or serious alternative?

Give preprocessors a second chance!

Page 63: Virtual Separation of Concerns (2011 Update)

Questions?

http://fosd.de/cide

Page 64: Virtual Separation of Concerns (2011 Update)

Picture Credits

© Stuck in Customs (cc by-nc-sa 2.0)

© Horia Varlan (cc by 2.0)


Recommended