SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
No Java without Caffeine
                    A Tool for Dynamic Analysis of Java Programs




                                Yann-Gaël Guéhéneuc
                                   Rémi Douence
                                  Narendra Jussien
                              {guehene, douence, jussien}@emn.fr

          École des Mines                                           Object Technology
          de Nantes, France                                         International, Inc., Canada




Ladies and gentlemen…
My name is Yann-Gaël Guéhéneuc.
I present today our work on Caffeine, a tool for the dynamic analysis of Java programs.
We develop Caffeine with Rémi Douence and Narendra Jussien from the EMN.
My work is partly funded by Object Technology International, Inc.




                                                                                                  1
Software understanding is about…

              … Understanding!

              n Donot hesitate to interrupt!
              n Questions are most welcome!




     2/23




Today, we are all attending a session on software understanding.
We should not forget that software understanding is first and foremost about
understanding.
Being from France, my accent might be a bit of a problem, so please, do not hesitate to
interrupt me, questions are most welcome.




                                                                                          2
Objectives

              n Motivate  the need for dynamic analysis
              n Present the prototype models
              n Detail the prototype implementation
              n Describe a more complex example
              n Summarize limitations and future work




      3/23




Today, in my presentation:
First, I motivate the need for dynamic analysis, using on a very simple example: The
analysis of a n-queens algorithm.
Second, I present the models used in our prototype.
Third, I detail our prototype implementation. I put the emphasis on issues and
limitations.
Fourth, I introduce a real-life example that (I hope) highlights the usefulness of dynamic
analyses and presents the integration of our tool with other tools for software
understanding.
Finally, I summarize the usefulness and the limitations of our tools and present some
future work.




                                                                                             3
Motivation

              n Software  understanding:
                 [Soloway et al., 1988]
                  – Code structure
                  – Conjecture


              n Assistant
              n Dynamic behaviour of Java programs
              n Least modifications (source code, JVM)
      4/23




Our motivation is software understanding.
Soloway et al. characterized software understanding as composed of inquiry episodes.
The maintainer, who tries to understand a program, first reads some code, asks a
question about this code, conjectures an answers, and searches the code and the
documentation for a confirmation of the conjecture.
Our goal is to develop an assistant which the maintainer uses to verify conjectures on the
runtime behaviour of the program with respect to the program structure.
We want our assistant to work with Java.
We need to analyze the dynamic behaviour of Java programs.
(I hope that I will convince you of the need for dynamic analyses in Java, in contrast
with the results presented in the Nokia experience report yesterday…)




                                                                                             4
Simple example                                            (1/2)

              n The n-queens            problem:
                  – A n×n chessboard
                  – n queens
                  – An algorithm to place the n queens




     5/23




Take for example a simple Java program to solve the n-queens problem.
This program declares a board of n×n cells and puts n queens on that board using a
simple algorithm with backtrack.
This is a very simple example… I present a more complex example at the end of this
presentation.




                                                                                     5
How many immediate
                                                                         backtracks?
              Simple example                                                             (2/2)
                                                                 Count the number of times the program
                                                                 execution matches the sequence of
                                                                 method calls:
             boolean placeNextQueen(final int column) {               •     setQueen()
                 …                                                    •     placeNextQueen()
                 int row = 0;                                         •     removeQueen()
                 while (row < this.n) {
                      if (!this.attack(row, column)) {
                            // Place a queen.
                            this.setQueen(row, column);
                            // Attempt to place the next queen.
                            if (this.placeNextQueen(column + 1)) {                How many
                                  return true;
                            }                                                     backtracks?
                            else {
                                  // Backtrack.                                   Count the number
                                  this.removeQueen(row, column);                   of calls to the
                            }                                                     removeQueen()
                      }                                                                method
                      row++;
                 }
     6/23        return false;
                 …



The algorithm is presented here.
Now, let’s imagine the maintainer who gets that program wants to know the number of
time the algorithm backtracks and the number of time the algorithm does an immediate
backtracks, i.e., remove a queen just after having placed her.
The maintainer needs to analyze the behaviour of the program…
We could then replace immediate backtracks with, for example, a propagation
algorithm.




                                                                                                         6
Models                                                       (1/2)

              n Trace model:
                   – History of execution events
              n Execution          model:
                   – Object model
                   – Prolog predicates
              n Analysis
                   – Prolog (pattern matching, high level)
                     [Ducassé, 1999]
      7/23




To perform the dynamic analysis of Java programs we need both a trace model, which
model the process of program execution, and an execution model, which models what
happens during the execution.
A trace is an history of execution events. We assume that the trace is built on the fly and
that there is not storage mechanism (but it is possible to store execution events).
Our execution model is based on the object model of the Java programming language.
This means that we have execution events related to operations performed on and by
classes and their instances.
We describe these execution events as Prolog predicates.
We use Prolog to perform analyses on traces of program executions.
We chose Prolog because it is powerful, it has pattern matching capabilities, and we can
express queries in a quite natural way. Prolog has already been chosen to perform trace
analysis: For example in Mireille Ducassé’s work on Opium and Coca.




                                                                                              7
Execution model                                            (2/2)
             class A {
                                                fieldAccess
                  String s;                     fieldModification
                  A(String s) {
                       …                        constructorEntry
                  }
                  String foo() {
                                                constructorExit
                       …
                       return "Happy" + s;      methodEntry
                  }
                  protected void finalize() {   methodExit
                       …
                  }
             }                                  finalizerEntry
                                                finalizerExit
                                                                       classLoad
                                                                     + classUnload
     8/23
                                                                       programEnd


This list presents the different execution events defined by our execution model.
Remember that these execution events are modelled as Prolog predicates.
We have execution events for almost everything that can happens to classes and their
instances.
We have field accesses and modification…
We have class load and unload…
We have…
We have method exit execution event, including the returned value.
We have…




                                                                                       8
Simple example                                                                (2/3)
             boolean placeNextQueen(final int column) {
                                                                query(N, M) :-
                 …
                                                                     nextMethodEntryEvent(removeQueen),
                 int row = 0;                                        !,
                 while (row < this.n) {                              N1 is N + 1,
                      if (!this.attack(row, column)) {               query(N1, M).
                            // Place a queen.                   query(N, N).
                            this.setQueen(row, column);
                            // Attempt to place the next queen.
                            if (this.placeNextQueen(column + 1)) {
                                  return true;
                            }
                            else {
                                  // Backtrack.
                                  this.removeQueen(row, column);
                            }
                      }
                      row++;
                 }
     9/23        return false;
                 …



So, let’s get back to our simple example.
Remember we wanted to count the number of backtracks?
We write the following Prolog query on the program execution.
The nextMethodEntryEvent/1 predicate requests the program to run until
method removeQueen() is called. When the removeQueen() method is
called, the program execution stops and the control flow goes to the Prolog
engine, which then increases a counter and loops.




                                                                                                          9
query(N, M) :-
                                              nextMethodEntryEvent(setQueen),

              Simple example                  nextPlaceNextQueen,
                                              nextMethodEntryEvent(removeQueen),
                                              !, N1 is N + 1, query(N1, M).
                                                                                               (3/3)
                                        query(N, N).
                                        nextPlaceNextQueen :-
             boolean placeNextQueen(final int column) {
                                              nextMethodEntryEvent(NAME),
                 …                            isPlaceNextQueen(NAME).
                 int row = 0;           isPlaceNextQueen(placeNextQueen)           :- !.
                 while (row < this.n) isPlaceNextQueen(removeQueen)
                                         {                                         :- !, fail.
                                        isPlaceNextQueen(setQueen)                 :- !, fail.
                      if (!this.attack(row, column)) {
                                        isPlaceNextQueen(_)                        :- nextPlaceNextQueen.
                           // Place a queen.
                           this.setQueen(row, column);
                           // Attempt to place the next queen.
                           if (this.placeNextQueen(column + 1)) {
                                 return true;
                           }
                           else {
                                 // Backtrack.
                                 this.removeQueen(row, column);
                           }
                      }
                      row++;
                 }
     10/23       return false;
                 …



We also wanted to count the number of immediate backtracks.
We write the following query, base on the same principles as for counting backtracks.
The query is a bit more complicated and I do not detail it here,but you can find in the
paper the details that prove that we obtain the number of immediate backtracks quite
nicely.




                                                                                                            10
Design
                                     Caffeine
                               JIProlog
                                engine
                               Next
                                required
                                event    Events


                                                                                Program
                            Event manager                                        being
                                                                                analyzed



                               Virtual                                          Virtual
                               machine                                          machine
                                                  Front-end          Back-end



                                 Local                                          Remote
                                  OS                    JDI   JDWP JVMDI         OS


     11/23                  Local computer                    JPDA         Remote computer




Okay, so far I gave you a flavour of what our tool, Caffeine, is all about.
I now detail the tool implementation of our tool.
Basically, we have a Prolog engine, JIProlog, which runs as a co-routine of the program
being analyzed.
The Prolog engine controls and receives execution events from the program through the
Java Debug Interface (JDI) of the Java Debug Platform Architecture (JPDA).
We chose to use the JPDA because it seems quite natural to use the debug architecture
to analyze, programmatically though, program executions; It alsoreduces the need for
modifications of both the source code and the JVM.
This is quite simple to implement at first sight.
However, some issues quickly show up. In particular with the following five points.




                                                                                             11
Implementation

              n Issues:
                  – Returned values
                       • Parameter values
                       • Instrument return statements
                           – return CaffeineWrapper(<previously
                             returned value>);
                  – Finalizers
                       • System.runFinalizersOnExit(boolean)
                       • Instrument class files to add finalize()
                         methods and to call the GC
     12/23




Here are implementation techniques we use to overcome the limitations of the JDI.
To obtain returned value, we instrument the class files at load-time, to replace any return
statement by a return statement with a call to a special method with a single parameter
(the returned value), which in turn we can monitor to obtain its parameter and thus the
returned value.
To obtain execution events related to finalizers, we use the deprecated method
System.runFinalizersOnExit(boolean). We also add finalize() method to all
loaded class and add calls to the garbage collector. All these manipulations dramatically
slow down the program execution.




                                                                                              12
Implementation

              n Issues:
                  – Program end
                      • Instrument System.exit(int)
                      • Count user thread starts/ends
                           – Assumption about the thread group
                  – Unique identifiers
                      • Instrument hierarchy root



     13/23




To obtain program ends, we need to monitor calls to the System.exit(int) method,
which we replace by our own wrapper method. We also count the number of user
threads that start and terminate. We need to count user threads only because the JVM
starts its own threads.
To obtain unique identifiers, we instrument the loaded class to insert our own super-
class which holds a unique identifier for each class and instances created.
All these tricks solve most of the problem we met when developing Caffeine. It’s all fun
and good. However, a last issue remains, and this issue is of most importance.




                                                                                           13
Performances

              nA                  real
                                problem:



                                6000                                                          5647
              Increase factor




                                5000
                                4000
                                3000
                                2000
                                1000                                    656            1142
                                         26   169        211
                                   0
                                       3.8      4.1        4.3            6.2        7.0             10.7
     14/23
                                                      Number of events per seconds




The performance of our tool is way to low!
On this table, for two different programs, we show that the performances are
dramatically decreased. The main slow down factor is the event generation.
We perform some measurements, and we notice a exponential increase of execution
time according to the number of execution events. That sounds reasonable, nothing
comes free. However, the increase is of many orders of magnitude.
This performance issue is very bad and impedes the use of our analysis tool.




                                                                                                            14
More complex example

              n Object-oriented               programs:
                   – Classes (and their instances)
                   – Relationships among classes
                     (and among their instances)
              n Two       binary class relationships:
                   – Aggregation:                A           B
                                                                    (structural)
                   – Composition:                A           B      (behavioural)

     15/23




I present now a real-life example of software understanding.
We all know that object-oriented programs are about classes (and their instances) and
about relationships among classes (and among instances).
There are two famous binary class relationships: The aggregation and the composition
relationships. There are no consensual definitions of those relationships, so I give my
own:
-An aggregations relationship between two classes A and B expresses that class A
declares a field (or a collection) of instances of class B.
-A composition relationship between two classes A and B expresses that an aggregation
relationship links those two classes and that the lifetime of instances of B is shorter that
(and exclusive to) the lifetime of instances of A.




                                                                                               15
Architecture of JUnit v3.7

              n Subset from Ptidej
                  [Albin-Amiot et al., 2001] :
                   – static analysis
                     (structure)
              n Aggregations:
                                A            B




              n Compositions?
                                A            B
     16/23




Let’s consider the following subset of JUnit v3.7 architecture.
We extract this architecture using our tool Ptidej and a static (structural) analysis.
We presented Ptidej last year at ASE.
We notice there are some aggregation relationships found.
We would like to have more information about this architecture. In particular, we would
like to know if there are any composition relationships among cl sses of the JUnit.
                                                               a




                                                                                          16
Composition relationship

              n Static      (structure):
                  – A declares a collection (field) of B
                  – A declares handling methods
              n Dynamic          (behaviour):
                  – Instances of B must belong exclusively to
                    instances of A (exclusivity)
                  – Lifetime of instances of B must not exceed
                    the lifetime of instances of A (lifetime)
     17/23




A composition relationship has two aspects:
-A structure (static), a field (a collection, generally) and some methods to handle adding
and removing of instances of B.
-A behaviour (dynamic), instances of…




                                                                                             17
Execution events

              n Assignations   of instances of B to any
                field in class A
              n Assignation of instances of B to any
                collection in class A
              n Finalization of instances of B and A




     18/23




Using Caffeine, our dynamic analysis tool, we can monitor assignations of instances of B
in any field or collection of class A.
We can also monitor the finalizations of instances of A and B and their ordering.




                                                                                           18
Composition analysis

              n About        50 predicates:
                   – About 300 lines of Prolog
                   – Mostly lists handling
                   – Complexity n2


              n Analysis         written once and for all
                   – Exclusivity property
                   – Lifetime property
     19/23




We wrote Prolog predicates to monitor and analyze the composition relationships
between classes. It is not that complex, the Prolog file is about 50 predicates, 300 lines
of Prolog, and is mostly about list handling.
This analysis is written once and for all, it can be reused for other Java programs. It
decomposes into the two properties Exclusivity and Lifetime.




                                                                                             19
Composition analysis, example

             n MoneyTest from JUnit                    v3.7:
                  – TestResult u TestFailure?
                  – TestRunner (AWT) u Throwable?
                  – TestRunner (Swing) u TestRunView?
                  – TestSuite u Test?
                  – TestRunner (AWT) u Test?
                  – TestTreeModel u Test?

     20/23




We apply Caffeine and our composition relationship analysis on JUnit v3.7, using the
provided MoneyTest class.
We monitored the following classes because they all have aggregation relationships.




                                                                                       20
Composition analysis, results

             n MoneyTest from JUnit   v3.7:
                 – TestResult u TestFailure ü
                 – TestRunner (AWT) u Throwable ü
                 – TestRunner (Swing) u TestRunView   ü
                 – TestSuite u Test û
                 – TestRunner (AWT) u Test û
                 – TestTreeModel u Test û

     21/23




The results are as follow…




                                                          21
Detailed architecture

             n Subset        from Ptidej:
                  – Static analysis
                  – Dynamic analysis


             n Some aggregations
             n Some compositions


     22/23




Finally, from the static and dynamic analyses, we can improve our understanding of the
architecture of JUnit.
We have now a better understanding of JUnit architecture. On one hand, we know that
the TestResult and TestFailure classes are tightly coupled, through a
composition relationships: Instances of class TestFailure live and die with instances
of class TestResult. On the other hand, instances of class Test are shared among
several classes and have lives on their own.




                                                                                         22
Conclusion and future work

              n Useful!
              n Limitations:
                  – Performances
                  – Code coverage
              n Future       work:
                  – Implementation rework
                  – More analyses
                  – Runtime description language
     23/23




To conclude, dynamic analysis is a useful thing to have and to do!
I presented Caffeine, a tool for the dynamic analysis of Java programs.
I gave some examples of our use of dynamic analyses.
However, our tool, as it is, is too limited with respect to performances and to code
coverage analysis.
Future work includes:
-Implementation rework, we would like to obtain only interesting events, no all events
of a certain kind, and we would like to remove the dependency on the debug architecture
that decreases performances.
-We also want to add more analyses to the current library. In particular, we want to
develop more properties.
-We plan to implement a runtime description language to express properties and to
compose easily properties into complete analyses. We consider using temporal logic or
logic programming.




                                                                                          23
Future work

                       N-queens    Binary class    Interaction     Design pattern   Protocols          ...
          High-level   algorithm   relationships    diagrams         behaviors




        Middle-level                                                                          Runtime
                       N-queens    Binary class    Interaction     Design pattern       description language
                       algorithm   relationships    diagrams         behaviors



        Intermediate                Caffeine

                                                                                    Prolog

                                   JDI (JPDA)
          Low-level
                                                             JVM




24/23




                                                                                                               24
Exclusivity property
        checkEXProperty(
            assignation(_, A, AID, B, BID),
            LIST,
            NLIST) :-
            updateEXProperties(A, AID, B, BID, LIST, NLIST, true).
        checkEXProperty(_, LIST, LIST).

        updateEXProperties(
           A, AID, B, BID,
           [],
           [exclusivityProperty(A, AID, B, BID, true)],
           true).
        updateEXProperties(
           A, AID, B, BID,
           [],
           [exclusivityProperty(A, AID, B, BID, false)],
           false).
        …
25/23




                                                                     25
Lifetime property
        checkLTProperty(
            assignation(_, A, AID, B, BID),
            LIST,
            NLIST) :-
                   append(LIST, [pendingAssignation(A, AID, B, BID, [])], NLIST).
        checkLTProperty(
            finalization(EID, A, AID),
            LIST,
            NLIST) :-
            doesLTPropertyHold(finalization(EID, A, AID), LIST, NLIST).
        checkLTProperty(
            programEnd(_),
            LIST,
            NLIST) :-
            convertPendingAssignations(LIST , NLIST).
        checkLTProperty(_, LIST, LIST).


26/23




                                                                                    26
Composition analysis
        checkComposition([], [], []).
        checkComposition([], _, []) :-
            write ('Problem! Lists of properties have different size!'), nl, false.
        checkComposition(_, [], []) :-
            write ('Problem! Lists of properties have different size!'), nl, false.
        checkComposition(
            [exclusivityProperty(A, AID, B, BID, OKAY) | EXPREST],
            [lifetimeProperty(A, AID, B, BID, OKAY) | LTPREST],
            [composition(A, AID, B, BID, OKAY) | NLIST]) :-
                    checkComposition(EXPREST , LTPREST, NLIST).
        checkComposition(
            [exclusivityProperty(A, AID, B, BID, _) | EXPREST],
            [lifetimeProperty(A, AID, B, BID, _) | LTPREST],
            [composition(A, AID, B, BID, false) | NLIST]) :-
                    checkComposition(EXPREST , LTPREST, NLIST).



27/23




                                                                                      27

Weitere ähnliche Inhalte

Was ist angesagt?

Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Javakim.mens
 
Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)Riccardo Cardin
 
Inter threadcommunication.38
Inter threadcommunication.38Inter threadcommunication.38
Inter threadcommunication.38myrajendra
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template PatternJonathan Simon
 
Logic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseLogic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseCoen De Roover
 
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...Frank Nielsen
 
Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?greenwop
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsAnton Keks
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My HeartBui Kiet
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummaryAmal Khailtash
 
Inter thread communication &amp; runnable interface
Inter thread communication &amp; runnable interfaceInter thread communication &amp; runnable interface
Inter thread communication &amp; runnable interfacekeval_thummar
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09Guy Korland
 
Scala design pattern
Scala design patternScala design pattern
Scala design patternKenji Yoshida
 
Questions of java
Questions of javaQuestions of java
Questions of javaWaseem Wasi
 

Was ist angesagt? (20)

Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
 
Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)Java- Concurrent programming - Synchronization (part 2)
Java- Concurrent programming - Synchronization (part 2)
 
Inter threadcommunication.38
Inter threadcommunication.38Inter threadcommunication.38
Inter threadcommunication.38
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template Pattern
 
Logic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with EclipseLogic-based program transformation in symbiosis with Eclipse
Logic-based program transformation in symbiosis with Eclipse
 
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 5) A Concise and Practical Introduction to Programming Algorithms in...
 
Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, Assertions
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Java Basics
Java BasicsJava Basics
Java Basics
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
Inter thread communication &amp; runnable interface
Inter thread communication &amp; runnable interfaceInter thread communication &amp; runnable interface
Inter thread communication &amp; runnable interface
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
Scala design pattern
Scala design patternScala design pattern
Scala design pattern
 
Class
ClassClass
Class
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Java memory model
Java memory modelJava memory model
Java memory model
 
10 strategy pattern
10 strategy pattern10 strategy pattern
10 strategy pattern
 
Questions of java
Questions of javaQuestions of java
Questions of java
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 

Ähnlich wie ASE02.ppt (20)

Ase02.ppt
Ase02.pptAse02.ppt
Ase02.ppt
 
Javascript
JavascriptJavascript
Javascript
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Java multi thread programming on cmp system
Java multi thread programming on cmp systemJava multi thread programming on cmp system
Java multi thread programming on cmp system
 
Javamschn3
Javamschn3Javamschn3
Javamschn3
 
Ppt chapter12
Ppt chapter12Ppt chapter12
Ppt chapter12
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
Deep learning with Keras
Deep learning with KerasDeep learning with Keras
Deep learning with Keras
 
Unifi
Unifi Unifi
Unifi
 
Domain-Specific Profiling - TOOLS 2011
Domain-Specific Profiling - TOOLS 2011Domain-Specific Profiling - TOOLS 2011
Domain-Specific Profiling - TOOLS 2011
 
P&MSP2012 - Unit Testing
P&MSP2012 - Unit TestingP&MSP2012 - Unit Testing
P&MSP2012 - Unit Testing
 
Deep learning from a novice perspective
Deep learning from a novice perspectiveDeep learning from a novice perspective
Deep learning from a novice perspective
 
Introduction to Snabbkaffe
Introduction to SnabbkaffeIntroduction to Snabbkaffe
Introduction to Snabbkaffe
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
 
java
javajava
java
 
backpropagation in neural networks
backpropagation in neural networksbackpropagation in neural networks
backpropagation in neural networks
 
Tensor flow
Tensor flowTensor flow
Tensor flow
 
Ase02 dmp.ppt
Ase02 dmp.pptAse02 dmp.ppt
Ase02 dmp.ppt
 

Mehr von Ptidej Team

From IoT to Software Miniaturisation
From IoT to Software MiniaturisationFrom IoT to Software Miniaturisation
From IoT to Software MiniaturisationPtidej Team
 
Presentation by Lionel Briand
Presentation by Lionel BriandPresentation by Lionel Briand
Presentation by Lionel BriandPtidej Team
 
Manel Abdellatif
Manel AbdellatifManel Abdellatif
Manel AbdellatifPtidej Team
 
Azadeh Kermansaravi
Azadeh KermansaraviAzadeh Kermansaravi
Azadeh KermansaraviPtidej Team
 
CSED - Manel Grichi
CSED - Manel GrichiCSED - Manel Grichi
CSED - Manel GrichiPtidej Team
 
Cristiano Politowski
Cristiano PolitowskiCristiano Politowski
Cristiano PolitowskiPtidej Team
 
Will io t trigger the next software crisis
Will io t trigger the next software crisisWill io t trigger the next software crisis
Will io t trigger the next software crisisPtidej Team
 
Thesis+of+laleh+eshkevari.ppt
Thesis+of+laleh+eshkevari.pptThesis+of+laleh+eshkevari.ppt
Thesis+of+laleh+eshkevari.pptPtidej Team
 
Thesis+of+nesrine+abdelkafi.ppt
Thesis+of+nesrine+abdelkafi.pptThesis+of+nesrine+abdelkafi.ppt
Thesis+of+nesrine+abdelkafi.pptPtidej Team
 

Mehr von Ptidej Team (20)

From IoT to Software Miniaturisation
From IoT to Software MiniaturisationFrom IoT to Software Miniaturisation
From IoT to Software Miniaturisation
 
Presentation
PresentationPresentation
Presentation
 
Presentation
PresentationPresentation
Presentation
 
Presentation
PresentationPresentation
Presentation
 
Presentation by Lionel Briand
Presentation by Lionel BriandPresentation by Lionel Briand
Presentation by Lionel Briand
 
Manel Abdellatif
Manel AbdellatifManel Abdellatif
Manel Abdellatif
 
Azadeh Kermansaravi
Azadeh KermansaraviAzadeh Kermansaravi
Azadeh Kermansaravi
 
Mouna Abidi
Mouna AbidiMouna Abidi
Mouna Abidi
 
CSED - Manel Grichi
CSED - Manel GrichiCSED - Manel Grichi
CSED - Manel Grichi
 
Cristiano Politowski
Cristiano PolitowskiCristiano Politowski
Cristiano Politowski
 
Will io t trigger the next software crisis
Will io t trigger the next software crisisWill io t trigger the next software crisis
Will io t trigger the next software crisis
 
MIPA
MIPAMIPA
MIPA
 
Thesis+of+laleh+eshkevari.ppt
Thesis+of+laleh+eshkevari.pptThesis+of+laleh+eshkevari.ppt
Thesis+of+laleh+eshkevari.ppt
 
Thesis+of+nesrine+abdelkafi.ppt
Thesis+of+nesrine+abdelkafi.pptThesis+of+nesrine+abdelkafi.ppt
Thesis+of+nesrine+abdelkafi.ppt
 
Medicine15.ppt
Medicine15.pptMedicine15.ppt
Medicine15.ppt
 
Qrs17b.ppt
Qrs17b.pptQrs17b.ppt
Qrs17b.ppt
 
Icpc11c.ppt
Icpc11c.pptIcpc11c.ppt
Icpc11c.ppt
 
Icsme16.ppt
Icsme16.pptIcsme16.ppt
Icsme16.ppt
 
Msr17a.ppt
Msr17a.pptMsr17a.ppt
Msr17a.ppt
 
Icsoc15.ppt
Icsoc15.pptIcsoc15.ppt
Icsoc15.ppt
 

Kürzlich hochgeladen

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Kürzlich hochgeladen (20)

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

ASE02.ppt

  • 1. No Java without Caffeine A Tool for Dynamic Analysis of Java Programs Yann-Gaël Guéhéneuc Rémi Douence Narendra Jussien {guehene, douence, jussien}@emn.fr École des Mines Object Technology de Nantes, France International, Inc., Canada Ladies and gentlemen… My name is Yann-Gaël Guéhéneuc. I present today our work on Caffeine, a tool for the dynamic analysis of Java programs. We develop Caffeine with Rémi Douence and Narendra Jussien from the EMN. My work is partly funded by Object Technology International, Inc. 1
  • 2. Software understanding is about… … Understanding! n Donot hesitate to interrupt! n Questions are most welcome! 2/23 Today, we are all attending a session on software understanding. We should not forget that software understanding is first and foremost about understanding. Being from France, my accent might be a bit of a problem, so please, do not hesitate to interrupt me, questions are most welcome. 2
  • 3. Objectives n Motivate the need for dynamic analysis n Present the prototype models n Detail the prototype implementation n Describe a more complex example n Summarize limitations and future work 3/23 Today, in my presentation: First, I motivate the need for dynamic analysis, using on a very simple example: The analysis of a n-queens algorithm. Second, I present the models used in our prototype. Third, I detail our prototype implementation. I put the emphasis on issues and limitations. Fourth, I introduce a real-life example that (I hope) highlights the usefulness of dynamic analyses and presents the integration of our tool with other tools for software understanding. Finally, I summarize the usefulness and the limitations of our tools and present some future work. 3
  • 4. Motivation n Software understanding: [Soloway et al., 1988] – Code structure – Conjecture n Assistant n Dynamic behaviour of Java programs n Least modifications (source code, JVM) 4/23 Our motivation is software understanding. Soloway et al. characterized software understanding as composed of inquiry episodes. The maintainer, who tries to understand a program, first reads some code, asks a question about this code, conjectures an answers, and searches the code and the documentation for a confirmation of the conjecture. Our goal is to develop an assistant which the maintainer uses to verify conjectures on the runtime behaviour of the program with respect to the program structure. We want our assistant to work with Java. We need to analyze the dynamic behaviour of Java programs. (I hope that I will convince you of the need for dynamic analyses in Java, in contrast with the results presented in the Nokia experience report yesterday…) 4
  • 5. Simple example (1/2) n The n-queens problem: – A n×n chessboard – n queens – An algorithm to place the n queens 5/23 Take for example a simple Java program to solve the n-queens problem. This program declares a board of n×n cells and puts n queens on that board using a simple algorithm with backtrack. This is a very simple example… I present a more complex example at the end of this presentation. 5
  • 6. How many immediate backtracks? Simple example (2/2) Count the number of times the program execution matches the sequence of method calls: boolean placeNextQueen(final int column) { • setQueen() … • placeNextQueen() int row = 0; • removeQueen() while (row < this.n) { if (!this.attack(row, column)) { // Place a queen. this.setQueen(row, column); // Attempt to place the next queen. if (this.placeNextQueen(column + 1)) { How many return true; } backtracks? else { // Backtrack. Count the number this.removeQueen(row, column); of calls to the } removeQueen() } method row++; } 6/23 return false; … The algorithm is presented here. Now, let’s imagine the maintainer who gets that program wants to know the number of time the algorithm backtracks and the number of time the algorithm does an immediate backtracks, i.e., remove a queen just after having placed her. The maintainer needs to analyze the behaviour of the program… We could then replace immediate backtracks with, for example, a propagation algorithm. 6
  • 7. Models (1/2) n Trace model: – History of execution events n Execution model: – Object model – Prolog predicates n Analysis – Prolog (pattern matching, high level) [Ducassé, 1999] 7/23 To perform the dynamic analysis of Java programs we need both a trace model, which model the process of program execution, and an execution model, which models what happens during the execution. A trace is an history of execution events. We assume that the trace is built on the fly and that there is not storage mechanism (but it is possible to store execution events). Our execution model is based on the object model of the Java programming language. This means that we have execution events related to operations performed on and by classes and their instances. We describe these execution events as Prolog predicates. We use Prolog to perform analyses on traces of program executions. We chose Prolog because it is powerful, it has pattern matching capabilities, and we can express queries in a quite natural way. Prolog has already been chosen to perform trace analysis: For example in Mireille Ducassé’s work on Opium and Coca. 7
  • 8. Execution model (2/2) class A { fieldAccess String s; fieldModification A(String s) { … constructorEntry } String foo() { constructorExit … return "Happy" + s; methodEntry } protected void finalize() { methodExit … } } finalizerEntry finalizerExit classLoad + classUnload 8/23 programEnd This list presents the different execution events defined by our execution model. Remember that these execution events are modelled as Prolog predicates. We have execution events for almost everything that can happens to classes and their instances. We have field accesses and modification… We have class load and unload… We have… We have method exit execution event, including the returned value. We have… 8
  • 9. Simple example (2/3) boolean placeNextQueen(final int column) { query(N, M) :- … nextMethodEntryEvent(removeQueen), int row = 0; !, while (row < this.n) { N1 is N + 1, if (!this.attack(row, column)) { query(N1, M). // Place a queen. query(N, N). this.setQueen(row, column); // Attempt to place the next queen. if (this.placeNextQueen(column + 1)) { return true; } else { // Backtrack. this.removeQueen(row, column); } } row++; } 9/23 return false; … So, let’s get back to our simple example. Remember we wanted to count the number of backtracks? We write the following Prolog query on the program execution. The nextMethodEntryEvent/1 predicate requests the program to run until method removeQueen() is called. When the removeQueen() method is called, the program execution stops and the control flow goes to the Prolog engine, which then increases a counter and loops. 9
  • 10. query(N, M) :- nextMethodEntryEvent(setQueen), Simple example nextPlaceNextQueen, nextMethodEntryEvent(removeQueen), !, N1 is N + 1, query(N1, M). (3/3) query(N, N). nextPlaceNextQueen :- boolean placeNextQueen(final int column) { nextMethodEntryEvent(NAME), … isPlaceNextQueen(NAME). int row = 0; isPlaceNextQueen(placeNextQueen) :- !. while (row < this.n) isPlaceNextQueen(removeQueen) { :- !, fail. isPlaceNextQueen(setQueen) :- !, fail. if (!this.attack(row, column)) { isPlaceNextQueen(_) :- nextPlaceNextQueen. // Place a queen. this.setQueen(row, column); // Attempt to place the next queen. if (this.placeNextQueen(column + 1)) { return true; } else { // Backtrack. this.removeQueen(row, column); } } row++; } 10/23 return false; … We also wanted to count the number of immediate backtracks. We write the following query, base on the same principles as for counting backtracks. The query is a bit more complicated and I do not detail it here,but you can find in the paper the details that prove that we obtain the number of immediate backtracks quite nicely. 10
  • 11. Design Caffeine JIProlog engine Next required event Events Program Event manager being analyzed Virtual Virtual machine machine Front-end Back-end Local Remote OS JDI JDWP JVMDI OS 11/23 Local computer JPDA Remote computer Okay, so far I gave you a flavour of what our tool, Caffeine, is all about. I now detail the tool implementation of our tool. Basically, we have a Prolog engine, JIProlog, which runs as a co-routine of the program being analyzed. The Prolog engine controls and receives execution events from the program through the Java Debug Interface (JDI) of the Java Debug Platform Architecture (JPDA). We chose to use the JPDA because it seems quite natural to use the debug architecture to analyze, programmatically though, program executions; It alsoreduces the need for modifications of both the source code and the JVM. This is quite simple to implement at first sight. However, some issues quickly show up. In particular with the following five points. 11
  • 12. Implementation n Issues: – Returned values • Parameter values • Instrument return statements – return CaffeineWrapper(<previously returned value>); – Finalizers • System.runFinalizersOnExit(boolean) • Instrument class files to add finalize() methods and to call the GC 12/23 Here are implementation techniques we use to overcome the limitations of the JDI. To obtain returned value, we instrument the class files at load-time, to replace any return statement by a return statement with a call to a special method with a single parameter (the returned value), which in turn we can monitor to obtain its parameter and thus the returned value. To obtain execution events related to finalizers, we use the deprecated method System.runFinalizersOnExit(boolean). We also add finalize() method to all loaded class and add calls to the garbage collector. All these manipulations dramatically slow down the program execution. 12
  • 13. Implementation n Issues: – Program end • Instrument System.exit(int) • Count user thread starts/ends – Assumption about the thread group – Unique identifiers • Instrument hierarchy root 13/23 To obtain program ends, we need to monitor calls to the System.exit(int) method, which we replace by our own wrapper method. We also count the number of user threads that start and terminate. We need to count user threads only because the JVM starts its own threads. To obtain unique identifiers, we instrument the loaded class to insert our own super- class which holds a unique identifier for each class and instances created. All these tricks solve most of the problem we met when developing Caffeine. It’s all fun and good. However, a last issue remains, and this issue is of most importance. 13
  • 14. Performances nA real problem: 6000 5647 Increase factor 5000 4000 3000 2000 1000 656 1142 26 169 211 0 3.8 4.1 4.3 6.2 7.0 10.7 14/23 Number of events per seconds The performance of our tool is way to low! On this table, for two different programs, we show that the performances are dramatically decreased. The main slow down factor is the event generation. We perform some measurements, and we notice a exponential increase of execution time according to the number of execution events. That sounds reasonable, nothing comes free. However, the increase is of many orders of magnitude. This performance issue is very bad and impedes the use of our analysis tool. 14
  • 15. More complex example n Object-oriented programs: – Classes (and their instances) – Relationships among classes (and among their instances) n Two binary class relationships: – Aggregation: A B (structural) – Composition: A B (behavioural) 15/23 I present now a real-life example of software understanding. We all know that object-oriented programs are about classes (and their instances) and about relationships among classes (and among instances). There are two famous binary class relationships: The aggregation and the composition relationships. There are no consensual definitions of those relationships, so I give my own: -An aggregations relationship between two classes A and B expresses that class A declares a field (or a collection) of instances of class B. -A composition relationship between two classes A and B expresses that an aggregation relationship links those two classes and that the lifetime of instances of B is shorter that (and exclusive to) the lifetime of instances of A. 15
  • 16. Architecture of JUnit v3.7 n Subset from Ptidej [Albin-Amiot et al., 2001] : – static analysis (structure) n Aggregations: A B n Compositions? A B 16/23 Let’s consider the following subset of JUnit v3.7 architecture. We extract this architecture using our tool Ptidej and a static (structural) analysis. We presented Ptidej last year at ASE. We notice there are some aggregation relationships found. We would like to have more information about this architecture. In particular, we would like to know if there are any composition relationships among cl sses of the JUnit. a 16
  • 17. Composition relationship n Static (structure): – A declares a collection (field) of B – A declares handling methods n Dynamic (behaviour): – Instances of B must belong exclusively to instances of A (exclusivity) – Lifetime of instances of B must not exceed the lifetime of instances of A (lifetime) 17/23 A composition relationship has two aspects: -A structure (static), a field (a collection, generally) and some methods to handle adding and removing of instances of B. -A behaviour (dynamic), instances of… 17
  • 18. Execution events n Assignations of instances of B to any field in class A n Assignation of instances of B to any collection in class A n Finalization of instances of B and A 18/23 Using Caffeine, our dynamic analysis tool, we can monitor assignations of instances of B in any field or collection of class A. We can also monitor the finalizations of instances of A and B and their ordering. 18
  • 19. Composition analysis n About 50 predicates: – About 300 lines of Prolog – Mostly lists handling – Complexity n2 n Analysis written once and for all – Exclusivity property – Lifetime property 19/23 We wrote Prolog predicates to monitor and analyze the composition relationships between classes. It is not that complex, the Prolog file is about 50 predicates, 300 lines of Prolog, and is mostly about list handling. This analysis is written once and for all, it can be reused for other Java programs. It decomposes into the two properties Exclusivity and Lifetime. 19
  • 20. Composition analysis, example n MoneyTest from JUnit v3.7: – TestResult u TestFailure? – TestRunner (AWT) u Throwable? – TestRunner (Swing) u TestRunView? – TestSuite u Test? – TestRunner (AWT) u Test? – TestTreeModel u Test? 20/23 We apply Caffeine and our composition relationship analysis on JUnit v3.7, using the provided MoneyTest class. We monitored the following classes because they all have aggregation relationships. 20
  • 21. Composition analysis, results n MoneyTest from JUnit v3.7: – TestResult u TestFailure ü – TestRunner (AWT) u Throwable ü – TestRunner (Swing) u TestRunView ü – TestSuite u Test û – TestRunner (AWT) u Test û – TestTreeModel u Test û 21/23 The results are as follow… 21
  • 22. Detailed architecture n Subset from Ptidej: – Static analysis – Dynamic analysis n Some aggregations n Some compositions 22/23 Finally, from the static and dynamic analyses, we can improve our understanding of the architecture of JUnit. We have now a better understanding of JUnit architecture. On one hand, we know that the TestResult and TestFailure classes are tightly coupled, through a composition relationships: Instances of class TestFailure live and die with instances of class TestResult. On the other hand, instances of class Test are shared among several classes and have lives on their own. 22
  • 23. Conclusion and future work n Useful! n Limitations: – Performances – Code coverage n Future work: – Implementation rework – More analyses – Runtime description language 23/23 To conclude, dynamic analysis is a useful thing to have and to do! I presented Caffeine, a tool for the dynamic analysis of Java programs. I gave some examples of our use of dynamic analyses. However, our tool, as it is, is too limited with respect to performances and to code coverage analysis. Future work includes: -Implementation rework, we would like to obtain only interesting events, no all events of a certain kind, and we would like to remove the dependency on the debug architecture that decreases performances. -We also want to add more analyses to the current library. In particular, we want to develop more properties. -We plan to implement a runtime description language to express properties and to compose easily properties into complete analyses. We consider using temporal logic or logic programming. 23
  • 24. Future work N-queens Binary class Interaction Design pattern Protocols ... High-level algorithm relationships diagrams behaviors Middle-level Runtime N-queens Binary class Interaction Design pattern description language algorithm relationships diagrams behaviors Intermediate Caffeine Prolog JDI (JPDA) Low-level JVM 24/23 24
  • 25. Exclusivity property checkEXProperty( assignation(_, A, AID, B, BID), LIST, NLIST) :- updateEXProperties(A, AID, B, BID, LIST, NLIST, true). checkEXProperty(_, LIST, LIST). updateEXProperties( A, AID, B, BID, [], [exclusivityProperty(A, AID, B, BID, true)], true). updateEXProperties( A, AID, B, BID, [], [exclusivityProperty(A, AID, B, BID, false)], false). … 25/23 25
  • 26. Lifetime property checkLTProperty( assignation(_, A, AID, B, BID), LIST, NLIST) :- append(LIST, [pendingAssignation(A, AID, B, BID, [])], NLIST). checkLTProperty( finalization(EID, A, AID), LIST, NLIST) :- doesLTPropertyHold(finalization(EID, A, AID), LIST, NLIST). checkLTProperty( programEnd(_), LIST, NLIST) :- convertPendingAssignations(LIST , NLIST). checkLTProperty(_, LIST, LIST). 26/23 26
  • 27. Composition analysis checkComposition([], [], []). checkComposition([], _, []) :- write ('Problem! Lists of properties have different size!'), nl, false. checkComposition(_, [], []) :- write ('Problem! Lists of properties have different size!'), nl, false. checkComposition( [exclusivityProperty(A, AID, B, BID, OKAY) | EXPREST], [lifetimeProperty(A, AID, B, BID, OKAY) | LTPREST], [composition(A, AID, B, BID, OKAY) | NLIST]) :- checkComposition(EXPREST , LTPREST, NLIST). checkComposition( [exclusivityProperty(A, AID, B, BID, _) | EXPREST], [lifetimeProperty(A, AID, B, BID, _) | LTPREST], [composition(A, AID, B, BID, false) | NLIST]) :- checkComposition(EXPREST , LTPREST, NLIST). 27/23 27