Tagging code in Spl

download Tagging code in Spl

of 37

Transcript of Tagging code in Spl

  • 7/30/2019 Tagging code in Spl

    1/37

    CIDE+: A Semi-automatic Approachfor Extracting Software Product Lines

    Virgilio Borges, Rgel Garcia,

    Marco Tlio Valente

    DCC UFMG

    CBSOFT 2010 - Tools Session

  • 7/30/2019 Tagging code in Spl

    2/37

    Motivation

    SPL extraction is a time-consuming task

    Even starting from an existing codebase

    Two approaches for extracting SPL:

    Compositional-based

    Annotation-based

    2

  • 7/30/2019 Tagging code in Spl

    3/37

    Compositional-based Approaches

    Example: aspects (AspectJ)

    Physical (real) modularization and separation of concerns

    Problem: costs do not outweight the benefits

    3

    Existing code Modularized

    features

    Products

    Fonte: Zhang, Jacobsen, OOPSLA 2004

  • 7/30/2019 Tagging code in Spl

    4/37

    Annotation-based Approaches

    Example: preprocessors

    It works. It is widely used.

    Problems: annotation hell;

    code pollution

    4

    boolean push(Object o) {

    Lock lk = new Lock();

    if (lk.lock() == null) {

    Log.log("lock failed");

    return false;

    }

    elements[top++]= o;

    size++;

    lk.unlock();

    if ((size % 10) == 0)

    snapshot("db");

    if ((size % 100) == 0)

    replicate("db","srv2");

    return true;

    }

    boolean push(Object o) {#ifdef MULTITHREADING

    Lock lk = new Lock();

    if (lk.lock() == null) {

    #ifdef LOGGING

    Log.log("lock failed");

    #endif

    return false;

    }

    #endifelements[top++]= o;

    size++;

    #ifdef MULTITHREADING

    lk.unlock();

    #endif

    #ifdef SNAPSHOT

    if ((size % 10) == 0)

    snapshot("db");

    #endif

    #ifdef REPLICATION

    if ((size % 100) == 0)

    replicate("db","srv2");

    #endif

    return true;

    }

  • 7/30/2019 Tagging code in Spl

    5/37

    Visual Annotations

    CIDE: Colored IDE (Eclipse + background colors)

    5

    It works, generating less code poluttion than #ifdefs

    Problem: colors assigned manually (repetitive, error-prone etc)

    boolean push(Object o) {

    Lock lk = new Lock();

    if (lk.lock() == null) {

    Log.log("lock failed");

    return false;

    }

    elements[top++]= o;size++;

    lk.unlock();

    if ((size % 10) == 0)

    snapshot("db");

    if ((size % 100) == 0)

    replicate("db","srv2");

    return true;

    }

    boolean push(Object o) {

    Lock lk = new Lock();

    if (lk.lock() == null) {

    Log.log("lock failed");

    return false;

    }

    elements[top++]= o;size++;

    lk.unlock();

    if ((size % 10) == 0)

    snapshot("db");

    if ((size % 100) == 0)

    replicate("db","srv2");

    return true;

    }

  • 7/30/2019 Tagging code in Spl

    6/37

    Our Tool: CIDE+

    Semi-automatic approach to assign colors to feature code

    CIDE+

    Feature Seeds &Colors

    input

    input

    uses

    CIDE

    output

  • 7/30/2019 Tagging code in Spl

    7/37

    Input: Feature Seeds

    Program elements that implement an optional feature F

    When F is disabled, S can be removed from the code

    Example: logging

    Granularity: package, class, method, field

    Therefore, cannot dispense a meaningful knowledge about theinternals of the target system

    7

    void log(String s) {

    .....}

    seed

  • 7/30/2019 Tagging code in Spl

    8/37

    Annotation Algorithm

    Fixed point algorithm

    Two phases:

    Color Propagation

    Color Expansion

    8

  • 7/30/2019 Tagging code in Spl

    9/37

    1st Phase: Propagation

    Marks all program elements that reference the seeds S

    9

    void log(String s) {

    .....

    }

    {

    log("stack overflow");

    .....

    .....

    log("lock failed");

    .....

    log("page delivered");.....

    .....

    .....

    log("new customer inserted");

    .....

    log("game over");

    .....

    .....

    log("user authenticated");

    .....

    }

    seed

    references to the seeds

  • 7/30/2019 Tagging code in Spl

    10/37

    1st Phase: Propagation

    Marks all program elements that reference the seeds S

    10

    void log(String s) {

    .....

    }

    {

    log("stack overflow");

    .....

    .....

    log("lock failed");

    .....

    log("page delivered");.....

    .....

    .....

    log("new customer inserted");

    .....

    log("game over");

    .....

    .....

    log("user authenticated");

    .....

    }

    seed

    references to the seeds

  • 7/30/2019 Tagging code in Spl

    11/37

    Color Propagation Rules

    11

    Pacotes

    Classes

    Interfaces

  • 7/30/2019 Tagging code in Spl

    12/37

    Color Propagation Rules

    12

    Campos

    Var. locais

    Parmetros

    Mtodos

  • 7/30/2019 Tagging code in Spl

    13/37

    2nd Phase: Color Expansion

    Checks whether the enclosing context of the elements annotated

    in the previous phase can also be marked.

    13

    void f(int x) {

    log("clicked" + x);

    }

    ....

    f(10);

    ....

    f(z);

    ....

    f(20);

    after colorpropagation

  • 7/30/2019 Tagging code in Spl

    14/37

    2nd Phase: Color Expansion

    Checks whether the enclosing context of the elements annotated

    in the previous phase can also be marked.

    14

    void f(int x) {

    log("clicked" + x);

    }

    ....

    f(10);

    ....

    f(z);

    ....

    f(20);

    void f(int x) {

    log("clicked" + x);

    }

    ....

    f(10);

    ....

    f(z);

    ....

    f(20);

    after colorpropagation

    color expansion

  • 7/30/2019 Tagging code in Spl

    15/37

    2nd Phase: Color Expansion

    Checks whether the enclosing context of the elements annotated

    in the previous phase can also be marked.

    15

    void f(int x) {

    log("clicked" + x);

    }

    ....

    f(10);

    ....

    f(z);

    ....

    f(20);

    void f(int x) {

    log("clicked" + x);

    }

    ....

    f(10);

    ....

    f(z);

    ....

    f(20);

    void f(int x) {

    log("clicked" + x);

    }

    ....

    f(10);

    ....

    f(z);

    ....

    f(20);

    after colorpropagation

    color expansion expansion cantrigger propagation

  • 7/30/2019 Tagging code in Spl

    16/37

    Color Expansion Rules

    16

  • 7/30/2019 Tagging code in Spl

    17/37

    Color Expansion Rules

    17

  • 7/30/2019 Tagging code in Spl

    18/37

    Semi-automatic Expansions

    In some situations, the algorithm can lead to type/syntatic errors

    In other situations, it is complex to infer if expansion is safe

    18

    if (option == k) {

    ....

    }

    syntax error

    T foo() {

    ... // no returns

    return t;

    }

    type errors

    if (bar()) {

    stm;}

    x= y;

    after propagation

  • 7/30/2019 Tagging code in Spl

    19/37

    Semi-automatic Expansions

    In some situations, the algorithm can lead to type/syntatic errors

    In other situations, it is complex to infer if expansion is safe

    19

    if (option == k) {

    ....

    }

    syntax error

    T foo() {

    ... // no returns

    return t;

    }

    type errors

    if (bar()) {

    stm;}

    x= y;

    after propagation

    if (bar()) {

    stm;}

    x= y;

    expansion

  • 7/30/2019 Tagging code in Spl

    20/37

    Semi-automatic Expansions

    In some situations, the algorithm can lead to type/syntatic errors

    In other situations, it is complex to infer if expansion is safe

    20

    if (option == k) {

    ....

    }

    syntax error

    T foo() {

    ... // no returns

    return t;

    }

    type errors

    if (bar()) {

    stm;}

    x= y; // bar() updates y

    after propagation

    if (bar()) {

    stm;}

    x= y; // bar() updates y

    unsafe expansion

    X

  • 7/30/2019 Tagging code in Spl

    21/37

    Semi-Automatic Expansions

    In the previous cases, we apply a default expansion (and

    generate a warning)

    21

    if (option == k) {

    ....

    }

    syntax error

    T foo() {

    ...

    return t;

    }

    type error

    if (bar()) {

    stm;

    }

    x= y; // bar updates y

    side effects

    if (bar()) {

    stm;

    }

    x= y; // bar updates y

    if (option == k ) {

    ....

    }

    T foo() {

    ...

    return t;

    }

    + warning

    + warning

    + warning

  • 7/30/2019 Tagging code in Spl

    22/37

    Semi-Automatic Expansion Rules

    22

  • 7/30/2019 Tagging code in Spl

    23/37

    Extraction Process

    23

  • 7/30/2019 Tagging code in Spl

    24/37

    Evaluation

    Three systems:

    ArgoUML

    JFreeChart

    Prevayler

    24

  • 7/30/2019 Tagging code in Spl

    25/37

    ArgoUML Example

    Manual extraction:

    Developer with no knowledge about our algorithm

    Using conditional compilation; then imported to CIDE

    Public at: http://argouml-spl.tigris.org

    25

    Features KLOC

    State Diagrams 3.9

    Activity Diagrams 2.2

    Design Critics 16.3

    Logging 2.5

    Total 24.9

  • 7/30/2019 Tagging code in Spl

    26/37

    ArgoUML

    Semi-automatic extraction using CIDE+:

    26

  • 7/30/2019 Tagging code in Spl

    27/37

    ArgoUML Results

    27

    recal 100%:

    Limitations of the defined seeds in reaching all manual marked code

    Example: XML parser that process a ToDo list

    precision 100%:

    In many parts of the code the developer in charge of the manual

    extraction has not expanded an annotation to its enclosing context

    (M= Manual extraction; A= semi-automatic extraction)

  • 7/30/2019 Tagging code in Spl

    28/37

    ArgoUML: Semi-automatic Exp.

    28

    In just three cases the developer has not accepted the default

    actions associated to the proposed semi-automatic expansions

  • 7/30/2019 Tagging code in Spl

    29/37

    Non-accepted Default Actions

    29

    cls=org.apache.log4j.Logger.class;

    ....

    cls= Class.forName("...");

    The RHS of an expression has been annotated with acolor c; but the LHS has not

  • 7/30/2019 Tagging code in Spl

    30/37

    Non-accepted Default Actions

    30

    cls=org.apache.log4j.Logger.class;

    ....

    cls= Class.forName("...");

    cls= org.apache.log4j.Logger.class;

    ....cls= Class.forName(other concern");

    The RHS of an expression has been annotated with acolor c; but the LHS has not

    default action: annotate the LHS and its references

    + warning

  • 7/30/2019 Tagging code in Spl

    31/37

    Non-accepted Default Actions

    31

    cls=org.apache.log4j.Logger.class;

    ....

    cls= Class.forName("...");

    cls= org.apache.log4j.Logger.class;

    ....cls= Class.forName("...");

    cls= org.apache.log4j.Logger.class;

    ....

    cls= Class.forName(other concern");

    The RHS of an expression has been annotated with acolor c; but the LHS has not

    default action: annotate the LHS and its references

    + warning

    Manual action: undo default action; annotate only the first assigmentReason: local variable is reused to store other Class Values

  • 7/30/2019 Tagging code in Spl

    32/37

    Prevayler

    Similar results: recall, precision, semi-automatic expansions

    32

    (M= Manual extraction; A= semi-automatic extraction)

  • 7/30/2019 Tagging code in Spl

    33/37

    JFreeChart

    33

    (M= Manual extraction; A= semi-automatic extraction)

    Semi-automatic expansions (all default actions have been accepted)

  • 7/30/2019 Tagging code in Spl

    34/37

    Lessons Learned

    SPL extraction is a time-consuming and complex task

    CIDE: promising tool to extract real SPLs

    CIDE+: accelerates SPL extraction using CIDE

    However:

    Developers should be familiar with the target system

    Developers should carefully select the feature seeds

    Number of semi-automatic expansions is significant

    34

  • 7/30/2019 Tagging code in Spl

    35/37

    Related Tools

    Compositional-based approaches (e.g. aspects)

    Example: AOP-Migrator

    Do not scale to real, complex SPLs

    Annotation-based approaches (e.g. preprocessors)

    No tools!

    35

  • 7/30/2019 Tagging code in Spl

    36/37

    Conclusions

    CIDE+ has been successfully applied in three non-trivial systems

    CIDE+ provides degrees of automation well above existent tools

    Particularly, when compared with tools based on aspects

    More details, including source code at: www.dcc.ufmg.br/~mtov/cideplus

    36

  • 7/30/2019 Tagging code in Spl

    37/37

    Thanks

    37