Docstoc

Reuse of Software Components

Document Sample
Reuse of Software Components Powered By Docstoc
					    Program Slicing Tool for
  Effective Software Evolution
Using Aspect-Oriented Technique


                                                                                                          Takashi Ishio
                                                                                                       Shinji Kusumoto
                                                                                                         Katsuro Inoue
                                                                                                       Osaka University


                                                            {t-isio, kusumoto, inoue}@ist.osaka-u.ac.jp
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
                                        Background
In software evolution process, software is
modified to adapt for the changes of its
specification.
When a programmer changes structure and
functions of a software, several bugs are
usually injected.


Debugging is an important task in software
evolution.
                                                                                                                                       IWPSE 2003
 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
Debugging Large Scale Software
Large scale software is difficult to debug.
   Especially, fault localization needs much cost
   since the location where a program crushed is
   not always close to the fault.
Executed codes for one test case are usually
small pieces of the program.



   Excluding automatically unrelated
   codes is effective for fault localization.
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
                                Program Slicing
Program Slicing extracts a slice of codes,
which affects value of a specific variable.

           1:    a = 5;                                                                              1:    a = 5;
           2:    b = a + a;                 a slice based on slice                                   2:    b = a + a;
           3:    if (b > 0) {               criteria(6, b)                                           3:    if (b > 0) {
           4:      c = a;                                                                            4:      c = a;
           5:    }                                                                                   5:    }
           6:    d = b;                                                                              6:    d = b;


Program Slicing excludes unrelated codes
to aid fault localization.
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
          Slice Calculation Process
Phase 1: Extraction of
                                                                                                  Data Dependence
dependence relations
                                                                                                  1: a = 1;
  Data Dependence Relation:                                                                       2: c = 4;                           a
      assignment  reference                                                                      3: b = a;
  Control Dependence Relation:
      conditional statement  controlled block                                                      Control Dependence
                                                                                                  4: if (a < 1) {
Phase 2: Construction of                                                                          5:     b = a;
Program Dependence Graph                                                                          6: }
  node: a statement.
  edge: a dependence relation                                                                       Program Dependence
                                                                                                    Graph
Phase 3: Traversal of PDG
  traversal backward from a node
  corresponding a slice criteria
                                                                  slice criteria
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
Dependence-Cache (DC) slicing using
       dynamic information
In slice calculation process, information about the
statements actually executed is effective to
decrease the slice size.
   Dynamic information excludes unexecuted codes from a
   slice.
Dependence-Cache (DC) slicing method uses:
   Dynamic Data Dependence Analysis
   Static Control Dependence Analysis
DC slicing calculates an accurate slice with
lightweight costs.

                                                                                                                                       IWPSE 2003
 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
Implementation of dynamic analysis
Dynamic analysis, collecting dynamic information during
program execution, is a kind of logging (or tracing).
Java Virtual Machine (JVM) Customization †
+ JVM can access all information of the runtime environment.
- Customization depends on a specific JVM implementation.
- Byte code optimization may affect analysis results.
Java Debugger Interface (JDI)
+ JDI can access local variables, stack traces, ...
- High runtime cost
          Threads of control are blocked for each logging point.
Although various ways exist in implementing the dynamic
analysis, each one requires a high cost in implementation or
in runtime.
          † F. Umemori et al.: “Design and Implementation of Bytecode-based
          Java Slicing System”, SCAM 2003 (to appear)
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
 Aspect-Oriented Programming
A key feature of Aspect-Oriented Programming is separation
of crosscutting concerns.
  AOP introduces a new module unit named aspect.
In OOP, programmers cannot encapsulate crosscutting
concerns:
          logging, error handling, some design patterns
  Programmers distribute many call statements into related classes for
  object interaction.
          It is hard to manage the distributed codes.
In AOP, programmers write a crosscutting concern in an
aspect.
  An aspect has information when the aspect is executed.
  Call statements are needless.
          When a concern is changed, programmers modify one aspect instead of
          related classes.
AOP improves modularity, maintainability and reusability.
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
                             Example of Aspect
 Logging: “Logs a method name for each
 method execution.”
     In OOP, logging codes are distributed in all
     classes. If logging specification is changed,
     programmers may modify all classes.
     In AOP, logging codes are encapsulated in the
     Logging Aspect. It is easy to maintain and reuse.
Class A              logger.logs(value);                                   Class A                     when a method is executed,
                                                                                                       logger.logs(value) is called.

Class B                           Logging Class                            Class B                                 Logging Aspect

Class C                                                                    Class C
                                                                                                                                           IWPSE 2003
     Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
AspectJ, an AOP extension for Java
AspectJ: an AOP extension for Java
  An aspect is defined as a set of advices.
  An advice consists of a procedure and pointcut
  designators (PCDs).
  PCDs describe when the procedure is executed.
AspectJ compiler:
  aspects + Java class source  Java bytecode




                                                                                                                                       IWPSE 2003
 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
                       Features of AspectJ
AspectJ provides the following PCDs:
  Method Call and Execution
  Field Assignment and Reference
  Exception Handling
An advice body is written in plain Java code.
  An advice can access context information
  through thisJoinPoint object.
  Context information is:
          Which method is actually executed ?
          What type of object is accessed ?

                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
                          Example of AspectJ
  How to implement logging in AspectJ:
                                                                      keyword for Aspect definition
                                                                                    Pointcut is defined by PCDs.
aspect LoggingAspect {                                                              Pointcut represents events during
  pointcut allMethods():                                                            program execution.

     execution(* *(..)) && !within(java.io.*);
  before(): allMethods(){           When the advice is executed.
  Logger.println(thisJoinPoint.getSignature());
  }
                  In the advice body, programmers can
}                 access context information via thisJoinPoint object.


    It is needless to change logging target classes.
                                                                                                                                           IWPSE 2003
     Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
          Dynamic Analysis Aspect
We implement dynamic analysis using AspectJ.
Dynamic analysis aspect
  records a position of the assignment statement when a
  new value is assigned to a field,
  extracts a dynamic data dependence relation when the
  field is referred,
  collects method-call information for each thread (multi-
  threading),
  collects information when an exception is thrown and
  which handling clause caught the exception (exception-
  handling).

                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
Advantages of Aspect Approach
Advantages
  Modularization of dynamic analysis
  Independent of a specific JVM implementation
  Independent of a byte-code optimizer ( JIT compiler )
Lightweight Analysis
  for large scale software.
  No local variables are dynamically analyzed.
          Local variables affects dependencies in one method.
          Little difference comes from dynamic information of local variables.
  No library classes are analyzed.
          We assume that library classes are reliable.
  less overhead: The aspect is linked to target program at
  compile time.

                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
Aspect-based Dynamic Analysis and Slice
       Calculation System: ADAS
 Debugging Support Tool using Program
 Slicing for Java
 Dynamic Analysis Aspect (written in AspectJ)
   Simple logging-like Implementation
   size: about 1000 LOC
 Program Slicing System (written in Java)
   Program Slicing is an application using dynamic
   information.
   The prototype is implemented as Eclipse plug-in.

                                                                                                                                         IWPSE 2003
   Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
  Architecture and Use Case of ADAS


                                        1.edit
                                                                                                program slice
                                                                               slice                             4.slice calculation
Dynamic
         Java Source                                                           criteria
Analysis
Aspect
                                                                                                      Slice Calculation Tool

                                                    Static                            Static
                                                   Analyzer                           Info.
                              2.compile

                                             Java                                                                              Dynamic
   AspectJ                                                                            Java VM
                                             Bytecode                                                                           Info.
                                                                                      3.execute
                                                                                      a test case
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
                                 Demonstration




                                                                                       Slice calculation button
        Slice criterion selection




                                                                   Slice results indicated

                                                                                                                                      IWPSE 2003
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
           Evaluation: size of a slice
Compare with customized JVM implementation †
   JVM approach: Precise DC Slice
   Our apparoch: omitting analysis for local variables.
Target programs
   P1: A simple database (4 classes, 262 LOC)
   P2: A sorting program (5 classes, 228 LOC)
   P3: A slice calculation program (125 classes, about 16000 LOC)
                                                                                         size of a slice (LOC)
Our approach calculates                                                        Aspect              JVM                   Aspect/JVM
a slice including
some redundant code                                              P1            36                  29                    1.24
JVM can extract a precise                                        P2            50                  28                    1.70
slice using fine-grained
information.                                                     P3            839                 708                   1.19

            † F. Umemori et al.: “Design and Implementation of Bytecode-based
            Java Slicing System”, SCAM 2003 (to appear)                    IWPSE 2003
   Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
               Evaluation: analysis cost
 Our approach shows good performance.
     Our approach is a coarse-grained, lightweight analysis.
 JVM approach is hard to apply a large scale
 software.
                Running Time [seconds]                                                                      ratio

      Normal    Aspect   JVM      Aspect/Normal JVM/Normal
      Execution Approach Approach
P1    0.18                     0.26                    1.8                      1.4                                10.0

P2    0.19                     0.39                    2.8                      2.1                                14.7

P3    1.2                      10.3                    81.0                     8.6                                67.5

                                                                                                                                           IWPSE 2003
     Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
Evaluation: Cost of Implementation
Aspect approach:
  Our module consists of the dynamic analysis aspect and
  data management classes.
  The total size is 1000 LOC.
JVM approach:
  System consists of customized JVM and Java compiler.
          Customized compiler insert source code information into bytecode
          files.
  Size of additional code for the customization is about
  50,000 LOC.
          Source code of the original JVM and compiler is 300,000 LOC.
  Programmers must re-customize the JVM whenever new
  version of JVM is released.
Aspect approach is inexpensive.
                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
          Remark and Future Work
Debugging is an important task for software
evolution.
  Program slicing shows related code to a user.
  Dynamic information exclude unexecuted code.
Dynamic Analysis Aspect is
  simple implementation,
  easy to maintain, customize.
Future Work
  Extension of ADAS to calculate AspectJ slice,
  Improvement of Usability.

                                                                                                                                        IWPSE 2003
  Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University