SlideShare une entreprise Scribd logo
1  sur  157
Télécharger pour lire hors ligne
Software Design and Evolution

11. Dynamic Analysis

Jorge Ressia
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      2
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      3
What does this program do?



       #include <stdio.h>main(t,_,a)char *a;{return!0<t?t<3?
       main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):1,t<_?main(t
       +1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?main(2,_+1,"%s %d %d
       ¥n"):9:16:t<0?t<-72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}
       +,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#¥;#q#n+,/+k#;*
       +,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l ¥q#'+d'K#!/+k#;q#'r}eKK#}
       w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ¥){nl]!/
       n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw'
       ¥iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ¥;;
       {nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}
       {rl#'{n' ')# ¥}'+}##(!!/"):t<-50?_==*a?
       putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?
       main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,"!ek;dc i@bK'(q)-
       [w]*%n+r3#l,{}:¥nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}



                                                                                        Thomas Ball, The Concept of Dynamic Analysis, FSE’99
                                                                                                                                                          4

Source code can be hard to read and understand.
This is a legal C program, an extreme case of course.

This is intentionally obfuscated code. Obfuscation is a set of transformations that preserve the behavior of the program but make the internals hard to
reverse-engineer.
- Programming contests
- Prevent reverse engineering
Finding Features




Software Feature:
A distinguishing characteristic of a
software item.


                                       IEEE 829
                                                  5
Bug reports often expressed in terms of
       Features.

                                                                      I can’t add new
                                                                      contacts!!!




                                                                                                                                                        6

The software engineer needs to maintain a mental map between features and the parts of the code that implement them.
Features are not implemented in one class. Their implementation spreads out over lots of classes. The behavior consist of objects that collaborate at
runtime.


“Change requests and bug reports are usually expressed in a language that reflects the features of a system”
	

            	

             	

             	

             	

             	

             	

           	

          	

                   	

	

            	

             	

             	

             	

             	

             [Mehta and Heinemann 2002]
Bug reports often expressed in terms of
       Features.

                                                                      I can’t add new
                                                                      contacts!!!




                                                                                                                      The
                                                                                                                “add contacts“
                                                                                                                    feature



                                                                                                                                                        6

The software engineer needs to maintain a mental map between features and the parts of the code that implement them.
Features are not implemented in one class. Their implementation spreads out over lots of classes. The behavior consist of objects that collaborate at
runtime.


“Change requests and bug reports are usually expressed in a language that reflects the features of a system”
	

            	

             	

             	

             	

             	

             	

           	

          	

                   	

	

            	

             	

             	

             	

             	

             [Mehta and Heinemann 2002]
Feature-Centric Reverse Engineering

                  Software System

  F1        F2
       Fn                   F2
                 F1




                       Fn




                                      Software developer
 Users
                                                       7
Feature-Centric Reverse Engineering

                  Software System

  F1        F2
       Fn                   F2
                 F1




                       Fn




                                      Software developer
 Users
                                                       7
Finding Features




                                                                                                      ?
            {                {
                 {                   {
                                         }
                     }
                     }
                         }       {       }




                                                                                                          8

I have a system and I need to find the features. Which part of the system belongs to which features?
What is Dynamic Analysis?



   The investigation of the properties of
   a running software system over one
   or more executions


   (Static analysis examines the
   program code alone)

                                            9
Why Dynamic Analysis?




         Gap between run-time structure and code structure in OO programs




                  Trying to understand one [structure] from the other is like trying to
                  understand the dynamism of living ecosystems from the static
                  taxonomy of plants and animals, and vice-versa.
                  !              !              !               -- Erich Gamma et al., Design Patterns

                                                                                                         10

Programs can be hard to understand from their source code alone.
The static code does not explicitly reflect the dynamic behavior.
The code structure consists of classes in fixed inheritance relationships. Difficulties:
OO source code exposes a class hierarchy, not the run-time object collaborations
	

            Collaborations are spread throughout the code
	

            Polymorphism may hide which classes are instantiated
A program’s run-time structure consists of rapidly changing networks of communicating objects.
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      11
Runtime Information Sources



Many possibilities: hardware monitoring, tracing method
execution, values of variables, memory usage etc...


External view                   Internal view
                execute                         instrument
                program and                     program and
                watch it from                   watch it from
                outside                         inside




                                                                12
External View



Program output, UI (examine behavior, performance, …)

Analyze used resources
   CPU and memory usage (top)
   Network usage (netstat, tcpdump)
   Open files, pipes, sockets (lsof)


Examine logs (syslog, web logs, stdout/stderr, …)




                                                        13
Internal View

    Log statements
    in code
                                           Stack trace
                                                                                Debugger
                                                                                             Execution trace




              Many different tools are based on tracing: execution profilers,
              test coverage analyzers, tools for reverse engineering…


                                                                                                               14

- Logs: Single points in the execution.
- Stack trace: snapshot of the current stack
- Debugger: interactive, allows one to step into future method executions. Not persistent.
- Tracing: full history of all method executions
Execution Tracing



       How can we capture “full”
         OO program execution?

       Trace entry and exit of methods

       Additional information:
            - receiver and arguments
            - class instantiations
            - …?



                                                                                        15

For now we consider this approach

Sequence and nesting: construct tree structure
Additional:
-receiver and arguments
-Return values
-Object creation
-Current feature
-Distinguish process (analyze concurrency properties)

Object referencing relationships not captured.
Object graph at particular point in time cannot be reconstructed, now, how it evolves
Tracing Techniques


               Instrumentation approaches
                  —Sourcecode modification
                  —Bytecode modification
                  —Wrapping methods (Smalltalk)

               Simulate execution (using debugger infrastructure)

               Sampling

               At the VM level
                  —Execution tracing by the interpreter
                  —(Dynamic recompilation, JIT)
                                                                                              16

Simulate execution: slow, but very precise control possible
Sampling: mainly used for profiling
Dynamic recompilation:
	

            - control optimizations: compile hot blocks/paths/procedures to machine code
	

            - data optimizations: garbage collection: move objects for locality
Technical Challenges



   > Instrumentation influences the behavior of the
   execution
   > Overhead: increased execution time
   > Large amount of data


   > Code also used by the tracer, library and system
   classes cannot be instrumented
       -> Trace at the VM level
       -> Scope instrumentation (Changeboxes)



                                                        17
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      18
Feature Analysis




                                                                                                      ?
            {                {
                 {                   {
                                         }
                     }
                     }
                         }       {       }




                                                                                                          19

I have a system and I need to find the features. Which part of the system belongs to which features?
Loggers - low tech debugging

   “…debugging statements stay with the program;
   debugging sessions are transient. “
   !      !      !      !          Kerningham and Pike




      public class Main {
      
      public static void main(String[] args) {	 	
      	      Clingon aAlien = new Clingon();
      
      System.out.println(“in main “); 

      	      aAlien.spendLife();
      	      }
      }


                                                                                         20

Inserting log statements into your code is a low-tech method for debugging it.
 It may also be the only way because debuggers are not always available or applicable.
This is often the case for distributed applications.
Loggers - low tech debugging

   “…debugging statements stay with the program;
   debugging sessions are transient. “
   !      !      !      !          Kerningham and Pike



                                                                                         Very messy!
      public class Main {
      
      public static void main(String[] args) {	 	
      	      Clingon aAlien = new Clingon();
      
      System.out.println(“in main “); 

      	      aAlien.spendLife();
      	      }
      }


                                                                                                       20

Inserting log statements into your code is a low-tech method for debugging it.
 It may also be the only way because debuggers are not always available or applicable.
This is often the case for distributed applications.
Smalltalk Mechanisms




> become: function
> Method Wrappers
> Anonymous Classes




                       21
Java Dynamic Proxies

   public class DebugProxy implements java.lang.reflect.InvocationHandler {

       private Object obj;

       public static Object newInstance(Object obj) {
   	         return java.lang.reflect.Proxy.newProxyInstance(
   	            obj.getClass().getClassLoader(),
   	            obj.getClass().getInterfaces(),
   	            new DebugProxy(obj));
       }

     public Object invoke(Object proxy, Method m, Object[] args)
   	       throws Throwable {
   	         .... Feature data gathering ...
   	         return m.invoke(obj, args);
       	     System.out.println("after method " + m.getName());
     }
   }
                                                                             22


http://docs.oracle.com/javase/1.3/docs/guide/reflection/
proxy.html
AOP




    Aspect Oriented Programming



      http://www.eclipse.org/aspectj/doc/next/progguide/language.html
                                                                                                                                                                                                             23

In the pointcut-advice (PA) mechanism for aspect-oriented programming, as embodied in AspectJ and others, cross- cutting behavior is defined by means of pointcuts and advices. Points during execution at
which advices may be executed are called (dynamic) join points. A pointcut identifies a set of join points, and an advice is the action to be taken at a join point matched by a pointcut. An aspect is a module that
encompasses a number of pointcuts and advices. In AspectJ, the decision of whether or not to use an aspect within a program is done at build time; if so, the aspect has global scope, i.e. it sees all join points of
the program execution. Restricting the scope of an aspect can be done by introducing conditions in the pointcut definitions.
AOP




      24
AOP




      25
AOP




      26
AOP Example




public class HelloWorld {

    public static void say(String message) {
      System.out.println(message);
    }

    public static void sayToPerson(String message, String name) {
      System.out.println(name + ", " + message);
    }
}


                                                                27
AOP Example




public aspect Example {
  pointcut callSayMessage() :
          call(public static void HelloWorld.say*(..));
  before() : callSayMessage() {
    System.out.println("Good day!");
  }
  after() : callSayMessage() {
    System.out.println("Thank you!");
  }
}


                                                          28
Feature Analysis AOP




public aspect FeatureAnalysis {
  pointcut callMessage() :
         call(public * com.mycompany..*.*(..));

    before() : callMessage() {
      ... save feature information ...
    }

}


                                                  29
Feature Analysis AOP




          public aspect FeatureAnalysis {
            pointcut executeMessage() :
                   execute(public * com.mycompany..*.*(..));

                before() : executeMessage() {
                  ... save feature information ...
                }

          }


                                                                                                                                                                                                              30

So what's the difference between these join points? Well, there are a number of differences:

Firstly, the lexical pointcut declarations within and withincode match differently. At a call join point, the enclosing code is that of the call site. This means that call(void m()) &&
withincode(void m()) will only capture directly recursive calls, for example. At an execution join point, however, the program is already executing the method, so the enclosing code is the method itself:
execution(void m()) && withincode(void m()) is the same as execution(void m()).

Secondly, the call join point does not capture super calls to non-static methods. This is because such super calls are different in Java, since they don't behave via dynamic dispatch like other calls to non-static
methods.

The rule of thumb is that if you want to pick a join point that runs when an actual piece of code runs (as is often the case for tracing), use execution, but if you want to pick one that runs when a particular
signature is called (as is often the case for production aspects), use call.
AspectJ pointcuts


call(MethodPattern)                   withincode(MethodPattern)
execution(MethodPattern)              withincode(ConstructorPattern)
get(FieldPattern)                     cflow(Pointcut)
set(FieldPattern)                     cflowbelow(Pointcut)
call(ConstructorPattern)              this(Type or Id)
execution(ConstructorPattern)         target(Type or Id)
initialization(ConstructorPattern)    args(Type or Id, ...)
preinitialization(ConstructorPattern) PointcutId(TypePattern or Id, ...)
staticinitialization(TypePattern)     if(BooleanExpression)
handler(TypePattern)                  ! Pointcut
adviceexecution()                     Pointcut0 && Pointcut1
within(TypePattern)                   Pointcut0 || Pointcut1      31


This is just and example for AspectJ, there are many other aspect
languages with many different pointcuts with different objectives.
Operational Decomposition


 McAffer - CodA - Meta-level Programming with CodA -
 ECOOP 1995




                                                       32
Operational Decomposition




 Iguana C++, IguanaJ
 Bifröst
 AOP
 EAOP
 AspectJ tracematches


                            33
Sub-method Feature Analysis




                                                           ?
           {                {
                {                   {
                                        }
                    }
                    }
                        }       {       }




                                                               34

We need to find which statements belong to which feature.
Sub-method Feature Analysis




   Bytecode Instrumentation



                              35
Bytecode Instrumentation




                Smalltalk



                            36
Example: Number>>asInteger


> Smalltalk code:
                      Number>>asInteger
                      ! "Answer an Integer nearest
                      ! the receiver toward zero."

                      !   ^self truncated


> Symbolic Bytecode

                      9 <70> self
                      10 <D0> send: truncated
                      11 <7C> returnTop




                                                     37
Example: Step by Step



> 9 <70> self
  —The receiver (self) is pushed on the stack
> 10 <D0> send: truncated
  —Bytecode 208: send litereral selector 1
  —Get the selector from the first literal
  —start message lookup in the class of the object that is on
    top of the stack
  —result is pushed on the stack
> 11 <7C> returnTop
  —return the object on top of the stack to the calling method


                                                                 38
ByteSurgeon



> Library for bytecode transformation in Smalltalk
> Full flexibility of Smalltalk Runtime
> Provides high-level API
> For Pharo, but portable


> Runtime transformation needed for
  —Adaptation of running systems
  —Tracing / debugging
  —New language features (MOP, AOP)



                                                     39
Example: Logging


> Goal: logging message send.
> First way: Just edit the text:




                                   40
Logging with ByteSurgeon


> Goal: Change the method without changing program text
> Example:




                                                          41
Logging: Step by Step




                        42
Logging: Step by Step




> instrumentSend:
  —takes a block as an argument
  —evaluates it for all send bytecodes

                                         43
Logging: Step by Step




> The block has one parameter: send
> It is executed for each send bytecode in the method

                                                        44
Logging: Step by Step




> Objects describing bytecode understand how to insert
  code
  —insertBefor
  —insertAfter
  —replace

                                                         45
Logging: Step by Step




> The code to be inserted.
> Double quoting for string inside string
    – Transcript show: ’sending #test’

                                            46
Inside ByteSurgeon


> Uses IRBuilder internally




> Transformation (Code inlining) done on IR


                                              47
ByteSurgeon Usage


> On Methods or Classes:




> Different instrument methods:
  —instrument:
  —instrumentSend:
  —instrumentTempVarRead:
  —instrumentTempVarStore:
  —instrumentTempVarAccess:
  —same for InstVar

                                  48
Advanced ByteSurgeon


> Goal: extend a send with after logging




                                           49
Advanced ByteSurgeon


> With ByteSurgeon, something like:




> How can we access the receiver of the send?
> Solution: Metavariable

                                                50
Advanced ByteSurgeon


> With Bytesurgeon, something like:




> How can we access the receiver of the send?
> Solution: Metavariable


                                                51
Bytecode Instrumentation




                           Java



                                  52


www.javassist.org
http://commons.apache.org/bcel/
http://asm.objectweb.org/
Bytecode Manipulation



   > Java
     —Javassist
       – reflection
       – RMI
     —BCEL
       – Decompiling, Obfuscation, and Refactoring
       – AspectJ
       – FindBugs
     —ASM
       – Groovy
       – AspectWerkz




                                                     53


www.javassist.org
http://commons.apache.org/bcel/
http://asm.objectweb.org/
Javassist




class Point {
  int x, y;
  void move(int dx, int dy) { x += dx; y += dy; }
}




                                                    54
Javassist




ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("Point");
CtMethod m = cc.getDeclaredMethod("move");
m.insertBefore("{ System.out.println($1);
System.out.println($2); }");
cc.writeFile();




                                             55
Javassist




class Point {
  int x, y;
  void move(int dx, int dy) {
    { System.out.println(dx); System.out.println(dy); }
    x += dx; y += dy;
  }
}




                                                          56
Javassist - Edit Body


          CtMethod cm = ... ;
          cm.instrument(
            new ExprEditor() {
              public void edit(MethodCall m)
                      throws CannotCompileException
              {
                if (m.getClassName().equals("Point")
                        && m.getMethodName().equals("move"))
                   m.replace("{ $1 = 0; $_ = $proceed($$); }");
              }
            });



                                                                                                           57

searches the method body represented by cm and replaces all calls to move() in class Point with a block:

  •    { $1 = 0; $_ = $proceed($$); }
Problems with Bytecode Instrumentation


> Bytecode is not a good meta model


> Lost of management infrastructure is needed
  —Hook composition
  —Synthesized elements (hooks) vs original code
  —Mapping to source elements


> Bytecode is optimized
  —e.g. no ifTrue:




                                                   58
Smalltalk Mechanisms




               Simulation



                            59
ST — Working with Bytecode



      Parsing and Interpretation



      > First step: Parse bytecode
        —enough for easy analysis, pretty printing, decompilation


      > Second step: Interpretation
        —needed for simulation, complex analyis (e.g., profiling)


      > Pharo provides frameworks for both:
        —InstructionStream/InstructionClient (parsing)
        —ContextPart (Interpretation)



      © Oscar Nierstrasz                                            60
ST — Working with Bytecode



      The InstructionStream Hierarchy



                             InstructionStream
                             ! ContextPart
                             ! ! BlockContext
                             ! ! MethodContext
                             ! Decompiler
                             ! InstructionPrinter
                             ! InstVarRefLocator
                             ! BytecodeDecompiler




      © Oscar Nierstrasz                            61
ST — Working with Bytecode



      InstructionStream


      > Parses the byte-encoded instructions
      > State:
        —pc: program counter
        —sender: the method (bad name!)


                Object subclass: #InstructionStream
                ! instanceVariableNames: 'sender pc'
                ! classVariableNames: 'SpecialConstants'
                ! poolDictionaries: ''
                ! category: 'Kernel-Methods'




      © Oscar Nierstrasz                                   62
ST — Working with Bytecode



      Usage


      > Generate an instance:
                         instrStream := InstructionStream on: aMethod



      > Now we can step through the bytecode with:
                             instrStream interpretNextInstructionFor: client



      > Calls methods on a client object for the type of bytecode,
           e.g.
            — pushReceiver
            — pushConstant: value
            — pushReceiverVariable: offset


      © Oscar Nierstrasz                                                       63
ST — Working with Bytecode



      InstructionClient


      > Abstract superclass
        —Defines empty methods for all methods that InstructionStream calls
          on a client
      > For convenience:
        —Clients don’t need to inherit from this class

                             Object subclass: #InstructionClient
                             ! instanceVariableNames: ''
                             ! classVariableNames: ''
                             ! poolDictionaries: ''
                             ! category: 'Kernel-Methods'




      © Oscar Nierstrasz                                                     64
ST — Working with Bytecode



        Example: A test


    InstructionClientTest>>testInstructions
    ! "just interpret all of methods of Object"
    ! | methods client scanner|
    !
    ! methods := Object methodDict values.
    ! client := InstructionClient new.!

    !     methods do: [:method |
    !     ! scanner := (InstructionStream on: method).
    !     ! [scanner pc <= method endPC] whileTrue: [
    !     ! ! ! self shouldnt:
    !     ! ! ! ! ! [scanner interpretNextInstructionFor: client]
    !     ! ! ! ! raise: Error.
    !     ! ].
    !     ].



        © Oscar Nierstrasz                                          65
ST — Working with Bytecode



      Example: Printing Bytecode


      > InstructionPrinter:
        —Print the bytecodes as human readable text
      > Example:
        —print the bytecode of Number>>asInteger:


           String streamContents:
           ! [:str | (InstructionPrinter on: Number>>#asInteger)
           ! ! ! ! printInstructionsOn: str ]

                                      '9 <70> self
                                      10 <D0> send: truncated
                                      11 <7C> returnTop
                                      '



      © Oscar Nierstrasz                                           66
ST — Working with Bytecode



      InstructionPrinter


      > Class Definition:


           InstructionClient subclass: #InstructionPrinter
           ! instanceVariableNames: 'method scanner
                                     stream indent'
           ! classVariableNames: ''
           ! poolDictionaries: ''
           ! category: 'Kernel-Methods'




      © Oscar Nierstrasz                                     67
ST — Working with Bytecode



      InstructionPrinter


      > Main Loop:

     InstructionPrinter>>printInstructionsOn: aStream
     ! "Append to the stream, aStream, a description
     ! of each bytecode in the instruction stream."
     ! | end |
     ! stream := aStream.
     ! scanner := InstructionStream on: method.
     ! end := method endPC.
     ! [scanner pc <= end]
     ! ! whileTrue: [scanner interpretNextInstructionFor: self]




      © Oscar Nierstrasz                                          68
ST — Working with Bytecode



      InstructionPrinter



      > Overwrites methods from InstructionClient to print
        the bytecodes as text
      > e.g. the method for pushReceiver

                InstructionPrinter>>pushReceiver
                ! "Print the Push Active Context's Receiver
                ! on Top Of Stack bytecode."

                !     self print: 'self'




      © Oscar Nierstrasz                                      69
ST — Working with Bytecode



      Example: InstVarRefLocator

        InstructionClient subclass: #InstVarRefLocator
        ! instanceVariableNames: 'bingo'
        ! classVariableNames: ''
        ! poolDictionaries: ''
        ! category: 'Kernel-Methods'

        InstVarRefLocator>>interpretNextInstructionUsing: aScanner !
        ! bingo := false.
        ! aScanner interpretNextInstructionFor: self.
        ! ^bingo

        InstVarRefLocator>>popIntoReceiverVariable: offset
        ! bingo := true

        InstVarRefLocator>>pushReceiverVariable: offset
        ! bingo := true

        InstVarRefLocator>>storeIntoReceiverVariable: offset
        ! bingo := true


      © Oscar Nierstrasz                                               70
ST — Working with Bytecode



      InstVarRefLocator


      > Analyse a method, answer true if it references an
           instance variable

     CompiledMethod>>hasInstVarRef
     ! "Answer whether the receiver references an instance variable."

     !     | scanner end printer |

     !     scanner := InstructionStream on: self.
     !     printer := InstVarRefLocator new.
     !     end := self endPC.

     !     [scanner pc <= end] whileTrue:
     !     ! [ (printer interpretNextInstructionUsing: scanner)
     !     ! ! ifTrue: [^true]. ].
     !     ^false



      © Oscar Nierstrasz                                                71
ST — Working with Bytecode



      InstVarRefLocator


      > Example for a simple bytecode analyzer
      > Usage:
                             aMethod hasInstVarRef


      > (has reference to variable testSelector)
                             (TestCase>>#debug) hasInstVarRef       true


      > (has no reference to a variable)

                             (Integer>>#+) hasInstVarRef        false




      © Oscar Nierstrasz                                                   72
ST — Working with Bytecode



      ContextPart: Semantics for Execution


      > Sometimes we need more than parsing
        —“stepping” in the debugger
        —system simulation for profiling

              InstructionStream subclass: #ContextPart
              ! instanceVariableNames: 'stackp'
              ! classVariableNames: 'PrimitiveFailToken QuickStep'
              ! poolDictionaries: ''
              ! category: 'Kernel-Methods'




      © Oscar Nierstrasz                                             73
ST — Working with Bytecode



      Simulation


      > Provides a complete Bytecode interpreter


      > Run a block with the simulator:

                    (ContextPart runSimulated: [3 factorial])   6




      © Oscar Nierstrasz                                            74
What is the big picture?




Source                      Bytecode
 code




                                  75
What is the big picture?




Source
 code                  ?    Bytecode




                                  75
AST Instrumentation




        Scanner          Semantic           Code
 code              AST              AST                Bytecode
        / Parser         Analysis         Generation




                                                                  76
Reflectivity




> Marcus Denker
  —Pharo Smalltalk
  —Geppetto 2
  —Phersephone


> Using Partial Behavioral Reflection Model
  —Reflex, Tanter etal.




                                             77
Compiler: AST


                                             RBProgramNode
                                             ! RBDoItNode
> AST: Abstract Syntax Tree                  ! RBMethodNode
  —Encodes the Syntax as a Tree              ! RBReturnNode
                                             ! RBSequenceNode
  —No semantics yet!                         ! RBValueNode
  —Uses the RB Tree:                         ! ! RBArrayNode
     – Visitors                              ! ! RBAssignmentNode
     – Backward pointers in ParseNodes
                                             ! ! RBBlockNode
                                             ! ! RBCascadeNode
     – Transformation (replace/add/delete)
                                             ! ! RBLiteralNode
     – Pattern-directed TreeRewriter         ! ! RBMessageNode
     – PrettyPrinter                         ! ! RBOptimizedNode
                                             ! ! RBVariableNode



                                                                    78
Reflectivity



                      meta-object


          links
                      activation
                      condition
                      source code
                         (AST)



                                    79

Links for AST nodes
Reflectivity



                      meta-object


          links
                      activation
                      condition
                      source code
                         (AST)



                                      79

Links for AST nodes




                       Reflectivity
                       Denke r 2008
Reflectivity



                      meta-object


          links
                      activation
                      condition
                      source code
                         (AST)



                                         79

Links for AST nodes




                       Reefl
                        Rfl  ccitvvtiyy
                           eet i i t
                       Deenke
                        Dnke  r r22008
                                  0 8
Reflectivity



                      meta-object


          links
                      activation
                      condition
                      source code
                         (AST)



                                         79

Links for AST nodes




                       Reefl
                        Rfl  ccitvvtiyy
                           eet i i t
                       Deenke
                        Dnke  r r22008
                                  0 8
Reflective Architecture




                         80
> Organize the meta-level
> Explicit meta-object
> Structural and Behavioral reflection
> Partial Reflection
> Unanticipation
> Selective Reifications
> No VM requirements




                                        81
Class

          Meta-object




 Object
                        82
Class

          Meta-object




 Object
                        83
Class

            Meta-object




Evolved Object
                          84
Feature Analysis

  	   | aMetaObject |
  	   aMetaObject := BFBehavioralMetaObject new.
  	   aMetaObject
  	   	 when: (ASTExecutionEvent new)
  	   	 do: [ ... feature information gathering ...].
  	   aMetaObject bindTo: self

                                                        85


http://scg.unibe.ch/research/bifrost
Implicit Problems


> Partial Reflection
  —We want to reflect on portions of the system
> Unanticipation
  —We want to reflect without having to anticipate where in the system
> Selective Reifications
  —We want to have runtime reifications available
> Composition
  —We want to be able to compose different analysis




                                                                        86
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      87
Simultaneous Feature Analysis




Login




                                           ?
           {               {
               {                   {
                                       }
                   }
                   }
                       }       {       }




Printing


                                           88
Simultaneous Feature Analysis




           Dynamic Scope



                                89
Simultaneous Feature Analysis




        Legend   objects   dynamic scope



                                           90
Simultaneous Feature Analysis




     Legend   objects   login feature   printing feature



                                                           91
CaesarJ


              Dynamically scoped aspects




                                                              deploy(a){block}




                                                                                                                                                                   92

Ivica Aracic, Vaidas Gasiunas, Mira Mezini, and Klaus Ostermann. An overview of CaesarJ. In Transactions on Aspect-Oriented Software Development, volume 3880 of Lecture
Notes in Computer Science, pages 135–173. Springer-Verlag, February 2006.

whereby the aspect instance a sees all join points produced in the dynamic extent of the execution of block
Dynamically scoped aspects




> AspectScheme


> CaesarJ


> AspectS



                             93
Deployment Strategies


               depl(a, δ⟨c, d, f ⟩, e)
               a is an aspect
               δ is the strategy
                c stack propagation function
                d object propagation function
                f joint point filter
               e is an expression

                                                                                                                                                                                        94

Éric Tanter. Expressive Scoping of Dynamically-Deployed Aspects. In Proceedings of the 7th ACM International Conference on Aspect-Oriented Software Development (AOSD 2008), p. 168—179, ACM
Press, Brussels, Belgium, April 2008.
Deployment Strategies




         deploy[true,-,if(cars_sp.contains(jp.args(1)))](sp){
           next.process(batch);
         }




                                                                                               95

Example from a car factory. Only some cars with a special package should get this adaptation
Scoping Strategies




                Propagation and Activation Problem




                                                                                                                                                   96

Éric Tanter. Beyond static and dynamic scope. In Proceedings of the 5th symposium on Dynamic languages, DLS '09 p. 3—14, ACM, New York, NY, USA,
2009.
Dynamic Scoping




              Prisma

                       97
Dynamic Scoping




                  98
Simultaneous Feature Analysis




      Legend   objects   login feature   printing feature



                                                            99
Dynamic Scoping


> Prisma
  —Execution Reification
  —Reflective Architecture
  —Execution composed of meta-objects
  —Reuse of Execution
  —Execution is not tied to threads
  —Broadening of Scope
  —Dynamic change of conditions




                                        100
Execution levels




          Legend   objects   feature analysis   profiling



                                                           101
Execution levels

Denker etal. Meta Context

                                       metameta-
                                        object
                                   meta-2
                    link
                  level 1
                                       meta-object
                              meta
                  links
                 level 0

                                            operation
                            base
                                                        102
Execution levels


          > Polymorphic Bytecode Instrumentation (PBI)
            —Dynamic dispatch amongst several, possibly independent
              instrumentations
            —Instrumentations are saved and indexed by a version identifier
            —Implemented over BCEL
            —JVM
            —Scala, JRuby, etc.
            —Execution levels
            —Monitoring
            —Mixin Layers
            —Promising performance


                                                                                                                                                                                                103

Philippe Moret, Walter Binder, and Éric Tanter. Polymorphic bytecode instrumentation. In Proceedings of the tenth international conference on Aspect-oriented software development, AOSD '11 p. 129—140,
ACM, New York, NY, USA, 2011.
Scoping Dimensions


>   Nature of Adaptation. A structural adaptation depicts the addition or change of a
    structural element, like refinements in Classboxes. A behavioral adaptation
    execute some action when specific runtime events are triggered.
>   Scoped Definition. The boundaries of the scope are defined by the entry and
    exit points. These boundaries can be implicit or explicit.
>   Scope Information Exposure. Some approaches allow to bind a value to a
    variable which is bound to the scope. This trait is particularly important to provide
    reusable adaptations.
>   Scope Binding. There are two binding dimensions. The adaptation can be
    defined at compile time or at runtime, this is call binding time. The binding mode
    describes wether an adaptation can be undone/redone during execution, if so the
    binding mode is said to be dynamic otherwise is static.
>   Thread Locality. The scope can be defined locally to a single thread. For
    example, cflow in AspectJ is by default thread local, while tracematch in AspectJ
    extension is by default global.

                                                                                            104
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      105
Reverse Engineering




                                                              g                                                                                                static view
                                                           in
                                                        er
                                                    ne
                                                 gi
                                             En
                                        se
                                     er
                                 ev
                              R




                                                                                                                                                                             106

In this course you have been introduced to the concepts of reverse engineering. Reverse engineering
Reverse engineering abstracts high level abstractions that support system understanding [Chikofsky and Cross, 1990].

“Object-oriented language characteristics such as inheritance,
dynamic binding and polymorphism mean that the behavior
of a system can only be determined at runtime.” [Jerding 1996,
                                               Demeyer2003a]

A static perspective of the system over looks semantic knowledge of the problem domain of a system. The semanic knowledge
Should not be ignored. We need a way to enrich the static views with information about their intent. Which features do they
Participate in at runtime? Are they specific to one part of the system, one feature, or is it general functionality that implements sone infrastructural functionality?

So lets extend our analysis by incorporating dynamic data captured while executing the features.
Reverse Engineering + Dynamic Analysis




                                                              g                                                                                                static view
                                                           in
                                                        er
                                                    ne
                                                 gi
                                             En
                                        se
                                     er
                                 ev
                              R




                                             +

                                               execution traces                                                                                 dynamic view                 106

In this course you have been introduced to the concepts of reverse engineering. Reverse engineering
Reverse engineering abstracts high level abstractions that support system understanding [Chikofsky and Cross, 1990].

“Object-oriented language characteristics such as inheritance,
dynamic binding and polymorphism mean that the behavior
of a system can only be determined at runtime.” [Jerding 1996,
                                               Demeyer2003a]

A static perspective of the system over looks semantic knowledge of the problem domain of a system. The semanic knowledge
Should not be ignored. We need a way to enrich the static views with information about their intent. Which features do they
Participate in at runtime? Are they specific to one part of the system, one feature, or is it general functionality that implements sone infrastructural functionality?

So lets extend our analysis by incorporating dynamic data captured while executing the features.
Dynamic Analysis for Program
       Comprehension

        Post Mortem Analysis of execution traces
        Metrics Based Approaches

        -Frequency Analysis [Ball, Zaidman]
        -Runtime Coupling Metrics based on Web mining techniques to
        detect key classses in a trace.
                                     [Zaidman 2005]
        -High-Level Polymetric Views of Condensed Run-Time
        Information [Ducasse, Lanza and Bertoulli 2004]

        -Query-based approaches
         Recoverind high-level views from runtime data
        !      !       !        [Richner and Ducasse 1999]


                                                                                                                                                   107

.They define an execution scenario to maximize coverage of the system and ‘preciseness’. To execute all the features.


Frequency analysis - small number of methods are responsible for a large amount of the trace. They focus on call relationships between methods to learn
something about a system.


Coupling metrics:


Runtime metrics
- how many methods of a class were invoked during the execution of a system.
-which classes create objects
-Which classes communicate with each other
Visualization of Runtime Behavior




                                                                                                                         Problem
                                                                                                                             of
                                                                                                                          Large
                                                                                                                          traces



                                                                                                 [JinSight, De Pauw 1993]                          108

Traces of execution behavior lead to huge execution traces of tens of thousands of events. This makes them difficult to interpret or to
Extract high level views. We need techniques to reduce the volume of information without loss of details needed to answer a specific research question. For
example: “Which classes and methods implement the save contact feature?”




Wim dePauw [JinSight,       De Pauw 1993].



Other compression approaches
Use graph algorithms to detect patterns and reduce the volume of data. Use
patterns to learn something about the system behavior.
Dividing a trace into features




  Feature 1   Feature 2          Feature n




                                             109
Feature Identification is a technique to
       map features to source code.

        “A feature is an observable unit of behavior of a system triggered by
        the user” [Eisenbarth etal. 2003]




           Software Reconnaissance [Wilde and Scully ]
           Run a (1) feature exhibiting scenario and a
           (2) non-exhibiting scenario and compare the traces.
           Then browse the source code.

                                                                                                 110

Other researchers had devised variations of software reconnaissance - Antoniol, Eisenberg etc.
Feature Identification is a technique to
       map features to source code.

        “A feature is an observable unit of behavior of a system triggered by
        the user” [Eisenbarth etal. 2003]




           Software Reconnaissance [Wilde and Scully ]
           Run a (1) feature exhibiting scenario and a
           (2) non-exhibiting scenario and compare the traces.
           Then browse the source code.

                                                                                                 110

Other researchers had devised variations of software reconnaissance - Antoniol, Eisenberg etc.
Feature Identification is a technique to
       map features to source code.

        “A feature is an observable unit of behavior of a system triggered by
        the user” [Eisenbarth etal. 2003]




           Software Reconnaissance [Wilde and Scully ]
           Run a (1) feature exhibiting scenario and a
           (2) non-exhibiting scenario and compare the traces.
           Then browse the source code.

                                                                                                 110

Other researchers had devised variations of software reconnaissance - Antoniol, Eisenberg etc.
Feature-Centric Analysis:
       3 Complementary Perspectives



                                                                            F1

                                                                            F2

                                                                            F3

                                                                            F4

                                                                            F5




                                                                                                          111

1) How are classes related to features?
2) How are features related to classes?
3) How are features related to each other?


We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
Feature-Centric Analysis:
       3 Complementary Perspectives



                                                                            F1

                                                                            F2

                                                                            F3

                                                                            F4

                                                                            F5
   Classes
   Perspective

                                                                                                          111

1) How are classes related to features?
2) How are features related to classes?
3) How are features related to each other?


We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
Feature-Centric Analysis:
       3 Complementary Perspectives



                                                                            F1

                                                                            F2

                                                                            F3

                                                                            F4

                                                                            F5
   Classes
   Perspective                                                                  Features Perspective

                                                                                                          111

1) How are classes related to features?
2) How are features related to classes?
3) How are features related to each other?


We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
Feature-Centric Analysis:
       3 Complementary Perspectives


                                                                                                Features Relationships
                                                                            F1
                                                                                                Perspective
                                                                            F2

                                                                            F3

                                                                            F4

                                                                            F5
   Classes
   Perspective                                                                  Features Perspective

                                                                                                                   111

1) How are classes related to features?
2) How are features related to classes?
3) How are features related to each other?


We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
Dynamix - A Model for Dynamic Analysis




                                         112
DynaMoose - An Environment for
Feature Analysis




                                 113
DynaMoose - An Environment for
Feature Analysis




                                 113
DynaMoose - An Environment for
Feature Analysis




                                 113
DynaMoose - An Environment for
Feature Analysis




                                 113
DynaMoose - An Environment for
Feature Analysis




                                 113
DynaMoose - An Environment for
Feature Analysis




                                 113
Demo of Feature Analysis - Feature
       Views of Classes

                                                                      PhoneButtonEventBackSpace




                                                                              PhoneStateContact
                                                                              PhoneStateContactForm
                                                                              EditableText
                                                                              CustomTextArea


                            Feature Views of PhoneSim Classes
                                                                                                  114

Here we see the feature views (of classes)
Our question was “Which classes participate in the addContacts feature?”
Feature Views of ‘Phonesim’ Methods




                            Feature Views of PhoneSim Methods
                                                                115

Which methods participate in the feature ‘addContacts()’?


22 single feature methods
Object Flow Analysis




Method execution traces do not
   reveal how
   … objects refer to each other
   … object references evolve


Trace and analyze object flow
  — Object-centric debugger: Trace
    back flow from errors to code that
    produced the objects
  — Detect object dependencies
    between features



                                        116
Roadmap




> Motivation
> Sources of Runtime Information
> Dynamic Analysis Techniques
> Advanced Dynamic Analysis Techniques
> Dynamic analysis in a Reverse Engineering Context
> What can we achieve with all this?
> Conclusion




                                                      117
What is the future?




          Live Feature
            Analysis

                         118
Live Feature Analysis

        Denker etal.



                  Source                                                                                                                         Traces




                                                                                                                                                                                      119

Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October
2010. 
Live Feature Analysis

        Denker etal.



                                                                                    Traces
                                                                                    Source




                                                                                                                                                                                      120

Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October
2010. 
Live Feature Analysis



                           Feature tagger
                            meta-object

                          tags node with
                        feature annotation
                           on execution

                              source code
                                 (AST)




                                             121
What is the future?




       Object Centric
        Debugging

                        122
Object Centric Debugging




             {                {
                  {                   {
                                          }
                      }
                      }
                          }       {       }




                                  http://scg.unibe.ch/research/bifrost/OCD                                                                                                            123

Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October
2010. 
Object Centric Debugging




             {                {
                  {                   {
                                          }
                      }
                      }
                          }       {       }




                                  http://scg.unibe.ch/research/bifrost/OCD                                                                                                            123

Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October
2010. 
Object Centric Debugging




                                                                            {               {
                                                                                {                   {
                                                                                                        }
                                                                                    }
                                                                                    }
                                                                                        }       {       }




                           http://scg.unibe.ch/research/bifrost/OCD                                                                                                                   124

Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October
2010. 
Object Centric Debugging



Object>>haltAtNextMessage
	 | aMetaObject |
	 aMetaObject := BFBehavioralMetaObject new.
	 aMetaObject
	 	 when: (BFMessageReceiveEvent new)
	 	 do: [ self metaObject unbindFrom: self.
         TransparentBreakpoint signal ].
	 aMetaObject bindTo: self

                                               125
What is the future?




        MetaSpy
     Domain-specific
        Profiling
                      126
Domain-specific Profiling
                                                                                                                                                                                     Domain-Specific Profiling        3

                                                                                                                                    CPU time profiling
                                                                                                                                    Mondrian [9] is an open and agile visualization engine. Mondrian describes a
                                                                                                                                    visualization using a graph of (possibly nested) nodes and edges. In June 2010


                                                                                  Profile
                                                                                                                                    a serious performance issue was raised1 . Tracking down the cause of the poor
                                                                                                                                    performance was not trivial. We first used a standard sample-based profiler.
                                                                                                                                         Execution sampling approximates the time spent in an application’s methods
                                                                                                                                    by periodically stopping a program and recording the current set of methods
                                                                                                                                    under executions. Such a profiling technique is relatively accurate since it has
                                                                                                                                    little impact on the overall execution. This sampling technique is used by almost
                                                                                                                                    all mainstream profilers, such as JProfiler, YourKit, xprof [10], and hprof.
                                                                                                                                         MessageTally, the standard sampling-based profiler in Pharo Smalltalk2 , tex-
                                                                                                                                    tually describes the execution in terms of CPU consumption and invocation for
                                                                                                                                    each method of Mondrian:
                                                                                                                                    54.8% {11501ms} MOCanvas>>drawOn:
                                                                                                                                     54.8% {11501ms} MORoot(MONode)>>displayOn:
                       {               {                                                                                              30.9% {6485ms} MONode>>displayOn:
                           {                   {                                                                                        | 18.1% {3799ms} MOEdge>>displayOn:
                                                   }                                                                                       ...
                               }
                               }                                                                                                        | 8.4% {1763ms} MOEdge>>displayOn:
                                                                                                                                        | | 8.0% {1679ms} MOStraightLineShape>>display:on:
                                   }       {       }                                                                                    | | 2.6% {546ms} FormCanvas>>line:to:width:color:
                                                                                                                                          ...
                                                                                                                                      23.4% {4911ms} MOEdge>>displayOn:
                                                                                                                                          ...

                                                                                                                                       We can observe that the virtual machine spent about 54% of its time in
                                                                                                                                    the method displayOn: defined in the class MORoot. A root is the unique non-
                                                                                                                                    nested node that contains all the nodes of the edges of the visualization. This
                                                                                                                                    general profiling information says that rendering nodes and edges consumes a
                                                                                                                                    great share of the CPU time, but it does not help in pinpointing which nodes
                                                                                                                                    and edges are responsible for the time spent. Not all graphical elements equally
                                                                                                                                    consume resources.
                                                                                                                                       Traditional execution sampling profilers center their result on the frames of
                                                                                                                                    the execution stack and completely ignore the identity of the object that received
                                                                                                                                    the method call and its arguments. As a consequence, it is hard to track down
                                                                                                                                    which objects cause the slowdown. For the example above, the traditional profiler
                                                                                                                                    says that we spent 30.9% in MONode>>displayOn: without saying which nodes
                                                                                                                                    were actually refreshed too often.

                                                                                                                                    Coverage
                                                                                                                                    PetitParser is a parsing framework combining ideas from scannerless parsing,
                                                                                                                                    parser combinators, parsing expression grammars and packrat parsers to model
                                                                                                                                    grammars and parsers as objects that can be reconfigured dynamically [11].
                                                                                                                                     1
                                                                                                                                         http://forum.world.st/Mondrian-is-slow-next-step-tc2257050.html#
                                                                                                                                         a2261116


                               http://scg.unibe.ch/research/bifrost/metaspy
                                                                                                                                     2
                                                                                                                                         http://www.pharo-project.org/
                                                                                                                                                                                                         127

Alexandre Bergel, Oscar Nierstrasz, Lukas Renggli, and Jorge Ressia. Domain-Specific Profiling. In Proceedings of the 49th International Conference on Objects, Models, Components and Patterns
(TOOLS'11), LNCS 6705 p. 68—82, Springer-Verlag, June 2011.
Domain-specific Profiling
                                                                                                                                                                                     Domain-Specific Profiling        3

                                                                                                                                    CPU time profiling
                                                                                                                                    Mondrian [9] is an open and agile visualization engine. Mondrian describes a
                                                                                                                                    visualization using a graph of (possibly nested) nodes and edges. In June 2010


                                                                                  Profile
                                                                                                                                    a serious performance issue was raised1 . Tracking down the cause of the poor
                                                                                                                                    performance was not trivial. We first used a standard sample-based profiler.
                                                                                                                                         Execution sampling approximates the time spent in an application’s methods
                                                                                                                                    by periodically stopping a program and recording the current set of methods
                                                                                                                                    under executions. Such a profiling technique is relatively accurate since it has
                                                                                                                                    little impact on the overall execution. This sampling technique is used by almost
                                                                                                                                    all mainstream profilers, such as JProfiler, YourKit, xprof [10], and hprof.
                                                                                                                                         MessageTally, the standard sampling-based profiler in Pharo Smalltalk2 , tex-
                                                                                                                                    tually describes the execution in terms of CPU consumption and invocation for
                                                                                                                                    each method of Mondrian:
                                                                                                                                    54.8% {11501ms} MOCanvas>>drawOn:
                                                                                                                                     54.8% {11501ms} MORoot(MONode)>>displayOn:
                       {               {                                                                                              30.9% {6485ms} MONode>>displayOn:
                           {                   {                                                                                        | 18.1% {3799ms} MOEdge>>displayOn:
                                                   }                                                                                       ...
                               }
                               }                                                                                                        | 8.4% {1763ms} MOEdge>>displayOn:
                                                                                                                                        | | 8.0% {1679ms} MOStraightLineShape>>display:on:
                                   }       {       }                                                                                    | | 2.6% {546ms} FormCanvas>>line:to:width:color:
                                                                                                                                          ...
                                                                                                                                      23.4% {4911ms} MOEdge>>displayOn:
                                                                                                                                          ...

                                                                                                                                       We can observe that the virtual machine spent about 54% of its time in
                                                                                                                                    the method displayOn: defined in the class MORoot. A root is the unique non-
                                                                                                                                    nested node that contains all the nodes of the edges of the visualization. This
                                                                                                                                    general profiling information says that rendering nodes and edges consumes a
                                                                                                                                    great share of the CPU time, but it does not help in pinpointing which nodes
                                                                                                                                    and edges are responsible for the time spent. Not all graphical elements equally
                                                                                                                                    consume resources.
                                                                                                                                       Traditional execution sampling profilers center their result on the frames of
                                                                                                                                    the execution stack and completely ignore the identity of the object that received
                                                                                                                                    the method call and its arguments. As a consequence, it is hard to track down
                                                                                                                                    which objects cause the slowdown. For the example above, the traditional profiler
                                                                                                                                    says that we spent 30.9% in MONode>>displayOn: without saying which nodes
                                                                                                                                    were actually refreshed too often.

                                                                                                                                    Coverage


                                                                             Domain                                                 PetitParser is a parsing framework combining ideas from scannerless parsing,
                                                                                                                                    parser combinators, parsing expression grammars and packrat parsers to model
                                                                                                                                    grammars and parsers as objects that can be reconfigured dynamically [11].
                                                                                                                                     1
                                                                                                                                         http://forum.world.st/Mondrian-is-slow-next-step-tc2257050.html#
                                                                                                                                         a2261116


                               http://scg.unibe.ch/research/bifrost/metaspy
                                                                                                                                     2
                                                                                                                                         http://www.pharo-project.org/
                                                                                                                                                                                                         127

Alexandre Bergel, Oscar Nierstrasz, Lukas Renggli, and Jorge Ressia. Domain-Specific Profiling. In Proceedings of the 49th International Conference on Objects, Models, Components and Patterns
(TOOLS'11), LNCS 6705 p. 68—82, Springer-Verlag, June 2011.
Domain-specific Profiling
                                                                                                                                                                                     Domain-Specific Profiling        3

                                                                                                                                    CPU time profiling
                                                                                                                                    Mondrian [9] is an open and agile visualization engine. Mondrian describes a
                                                                                                                                    visualization using a graph of (possibly nested) nodes and edges. In June 2010


                                                                                  Profile
                                                                                                                                    a serious performance issue was raised1 . Tracking down the cause of the poor
                                                                                                                                    performance was not trivial. We first used a standard sample-based profiler.
                                                                                                                                         Execution sampling approximates the time spent in an application’s methods
                                                                                                                                    by periodically stopping a program and recording the current set of methods
                                                                                                                                    under executions. Such a profiling technique is relatively accurate since it has
                                                                                                                                    little impact on the overall execution. This sampling technique is used by almost
                                                                                                                                    all mainstream profilers, such as JProfiler, YourKit, xprof [10], and hprof.
                                                                                                                                         MessageTally, the standard sampling-based profiler in Pharo Smalltalk2 , tex-
                                                                                                                                    tually describes the execution in terms of CPU consumption and invocation for
                                                                                                                                    each method of Mondrian:
                                                                                                                                    54.8% {11501ms} MOCanvas>>drawOn:
                                                                                                                                     54.8% {11501ms} MORoot(MONode)>>displayOn:
                       {               {                                                                                              30.9% {6485ms} MONode>>displayOn:
                           {                   {                                                                                        | 18.1% {3799ms} MOEdge>>displayOn:
                                                   }                                                                                       ...
                               }
                               }                                                                                                        | 8.4% {1763ms} MOEdge>>displayOn:
                                                                                                                                        | | 8.0% {1679ms} MOStraightLineShape>>display:on:
                                   }       {       }                                                                                    | | 2.6% {546ms} FormCanvas>>line:to:width:color:
                                                                                                                                          ...
                                                                                                                                      23.4% {4911ms} MOEdge>>displayOn:
                                                                                                                                          ...

                                                                                                                                       We can observe that the virtual machine spent about 54% of its time in
                                                                                                                                    the method displayOn: defined in the class MORoot. A root is the unique non-
                                                                                                                                    nested node that contains all the nodes of the edges of the visualization. This
                                                                                                                                    general profiling information says that rendering nodes and edges consumes a
                                                                                                                                    great share of the CPU time, but it does not help in pinpointing which nodes
                                                                                                                                    and edges are responsible for the time spent. Not all graphical elements equally
                                                                                                                                    consume resources.
                                                                                                                                       Traditional execution sampling profilers center their result on the frames of
                                                                                                                                    the execution stack and completely ignore the identity of the object that received
                                                                                                                                    the method call and its arguments. As a consequence, it is hard to track down
                                                                                                                                    which objects cause the slowdown. For the example above, the traditional profiler
                                                                                                                                    says that we spent 30.9% in MONode>>displayOn: without saying which nodes
                                                                                                                                    were actually refreshed too often.

                                                                                                                                    Coverage


                                                                             Domain                                                 PetitParser is a parsing framework combining ideas from scannerless parsing,
                                                                                                                                    parser combinators, parsing expression grammars and packrat parsers to model
                                                                                                                                    grammars and parsers as objects that can be reconfigured dynamically [11].
                                                                                                                                     1
                                                                                                                                         http://forum.world.st/Mondrian-is-slow-next-step-tc2257050.html#
                                                                                                                                         a2261116


                               http://scg.unibe.ch/research/bifrost/metaspy
                                                                                                                                     2
                                                                                                                                         http://www.pharo-project.org/
                                                                                                                                                                                                         127

Alexandre Bergel, Oscar Nierstrasz, Lukas Renggli, and Jorge Ressia. Domain-Specific Profiling. In Proceedings of the 49th International Conference on Objects, Models, Components and Patterns
(TOOLS'11), LNCS 6705 p. 68—82, Springer-Verlag, June 2011.
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis
SDE - Dynamic Analysis

Contenu connexe

Tendances

Ics4u dayplans
Ics4u dayplansIcs4u dayplans
Ics4u dayplanschiarellic
 
iFL: An Interactive Environment for Understanding Feature Implementations
iFL: An Interactive Environment for Understanding Feature ImplementationsiFL: An Interactive Environment for Understanding Feature Implementations
iFL: An Interactive Environment for Understanding Feature ImplementationsShinpei Hayashi
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1karmuhtam
 
Toward Understanding How Developers Recognize Features in Source Code from De...
Toward Understanding How Developers Recognize Features in Source Code from De...Toward Understanding How Developers Recognize Features in Source Code from De...
Toward Understanding How Developers Recognize Features in Source Code from De...Shinpei Hayashi
 
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...Shinpei Hayashi
 
Guiding Identification of Missing Scenarios for Dynamic Feature Location
Guiding Identification of Missing Scenarios for Dynamic Feature LocationGuiding Identification of Missing Scenarios for Dynamic Feature Location
Guiding Identification of Missing Scenarios for Dynamic Feature LocationShinpei Hayashi
 
OOP Chapter 7 : More on Classes
OOP Chapter 7 : More on ClassesOOP Chapter 7 : More on Classes
OOP Chapter 7 : More on ClassesAtit Patumvan
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6patcha535
 
Supporting Design Model Refactoring for Improving Class Responsibility Assign...
Supporting Design Model Refactoring for Improving Class Responsibility Assign...Supporting Design Model Refactoring for Improving Class Responsibility Assign...
Supporting Design Model Refactoring for Improving Class Responsibility Assign...Shinpei Hayashi
 
OOP: Chapter 2: Programming in Objective-C
OOP: Chapter 2: Programming in Objective-C OOP: Chapter 2: Programming in Objective-C
OOP: Chapter 2: Programming in Objective-C Atit Patumvan
 
Automating Return Oriented Programming Attacks
Automating Return Oriented Programming AttacksAutomating Return Oriented Programming Attacks
Automating Return Oriented Programming AttacksETH Zurich
 
Smart debugger
Smart debuggerSmart debugger
Smart debuggerTao He
 
Tracking my face with matlab ws word format
Tracking my face with matlab ws word formatTracking my face with matlab ws word format
Tracking my face with matlab ws word formatGaspard Ggas
 

Tendances (20)

Ics4u dayplans
Ics4u dayplansIcs4u dayplans
Ics4u dayplans
 
iFL: An Interactive Environment for Understanding Feature Implementations
iFL: An Interactive Environment for Understanding Feature ImplementationsiFL: An Interactive Environment for Understanding Feature Implementations
iFL: An Interactive Environment for Understanding Feature Implementations
 
Interface in java
Interface in javaInterface in java
Interface in java
 
ASE02.ppt
ASE02.pptASE02.ppt
ASE02.ppt
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
Toward Understanding How Developers Recognize Features in Source Code from De...
Toward Understanding How Developers Recognize Features in Source Code from De...Toward Understanding How Developers Recognize Features in Source Code from De...
Toward Understanding How Developers Recognize Features in Source Code from De...
 
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...
 
Guiding Identification of Missing Scenarios for Dynamic Feature Location
Guiding Identification of Missing Scenarios for Dynamic Feature LocationGuiding Identification of Missing Scenarios for Dynamic Feature Location
Guiding Identification of Missing Scenarios for Dynamic Feature Location
 
Confluence
ConfluenceConfluence
Confluence
 
OOP Chapter 7 : More on Classes
OOP Chapter 7 : More on ClassesOOP Chapter 7 : More on Classes
OOP Chapter 7 : More on Classes
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6
 
Class
ClassClass
Class
 
L06 process design
L06 process designL06 process design
L06 process design
 
Supporting Design Model Refactoring for Improving Class Responsibility Assign...
Supporting Design Model Refactoring for Improving Class Responsibility Assign...Supporting Design Model Refactoring for Improving Class Responsibility Assign...
Supporting Design Model Refactoring for Improving Class Responsibility Assign...
 
OOP: Chapter 2: Programming in Objective-C
OOP: Chapter 2: Programming in Objective-C OOP: Chapter 2: Programming in Objective-C
OOP: Chapter 2: Programming in Objective-C
 
Automating Return Oriented Programming Attacks
Automating Return Oriented Programming AttacksAutomating Return Oriented Programming Attacks
Automating Return Oriented Programming Attacks
 
Smart debugger
Smart debuggerSmart debugger
Smart debugger
 
Tracking my face with matlab ws word format
Tracking my face with matlab ws word formatTracking my face with matlab ws word format
Tracking my face with matlab ws word format
 

Similaire à SDE - Dynamic Analysis

OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysislienhard
 
Reverse Engineering of Module Dependencies
Reverse Engineering of Module DependenciesReverse Engineering of Module Dependencies
Reverse Engineering of Module DependenciesDharmalingam Ganesan
 
4+1view architecture
4+1view architecture4+1view architecture
4+1view architecturedrewz lin
 
4+1view architecture
4+1view architecture4+1view architecture
4+1view architectureTot Bob
 
TaskMan-Middleware 2011 - Advanced implementation
TaskMan-Middleware 2011 - Advanced implementationTaskMan-Middleware 2011 - Advanced implementation
TaskMan-Middleware 2011 - Advanced implementationAndrea Tino
 
Raymond_Matel_Software_Engineer
Raymond_Matel_Software_EngineerRaymond_Matel_Software_Engineer
Raymond_Matel_Software_EngineerRaymond Matel
 
A system for performance evaluation of embedded software
A system for performance evaluation of embedded softwareA system for performance evaluation of embedded software
A system for performance evaluation of embedded softwareMr. Chanuwan
 
Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02
Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02
Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02NNfamily
 
Software design.edited (1)
Software design.edited (1)Software design.edited (1)
Software design.edited (1)FarjanaAhmed3
 
Questions Every software engineer should answer
Questions Every software engineer should answerQuestions Every software engineer should answer
Questions Every software engineer should answerErtan Deniz
 
ccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdfccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdfVijayakumarKadumbadi
 
Object Oriented Database
Object Oriented DatabaseObject Oriented Database
Object Oriented DatabaseMegan Espinoza
 

Similaire à SDE - Dynamic Analysis (20)

OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysis
 
Reverse Engineering of Module Dependencies
Reverse Engineering of Module DependenciesReverse Engineering of Module Dependencies
Reverse Engineering of Module Dependencies
 
4+1view architecture
4+1view architecture4+1view architecture
4+1view architecture
 
4+1view architecture
4+1view architecture4+1view architecture
4+1view architecture
 
Sdlc
SdlcSdlc
Sdlc
 
Sdlc
SdlcSdlc
Sdlc
 
TaskMan-Middleware 2011 - Advanced implementation
TaskMan-Middleware 2011 - Advanced implementationTaskMan-Middleware 2011 - Advanced implementation
TaskMan-Middleware 2011 - Advanced implementation
 
Raymond_Matel_Software_Engineer
Raymond_Matel_Software_EngineerRaymond_Matel_Software_Engineer
Raymond_Matel_Software_Engineer
 
A system for performance evaluation of embedded software
A system for performance evaluation of embedded softwareA system for performance evaluation of embedded software
A system for performance evaluation of embedded software
 
Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02
Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02
Asystemforperformanceevaluationofembeddedsoftware 100813001230-phpapp02
 
Software design.edited (1)
Software design.edited (1)Software design.edited (1)
Software design.edited (1)
 
Ch10
Ch10Ch10
Ch10
 
Ch10
Ch10Ch10
Ch10
 
Questions Every software engineer should answer
Questions Every software engineer should answerQuestions Every software engineer should answer
Questions Every software engineer should answer
 
Se
SeSe
Se
 
ccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdfccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdf
 
Se
SeSe
Se
 
Object Oriented Database
Object Oriented DatabaseObject Oriented Database
Object Oriented Database
 
Software tools
Software toolsSoftware tools
Software tools
 
What is Software Architecture?
What is Software Architecture?What is Software Architecture?
What is Software Architecture?
 

Plus de Jorge Ressia

Object-Centric Debugging
Object-Centric DebuggingObject-Centric Debugging
Object-Centric DebuggingJorge Ressia
 
Talents Presentation at ESUG 2011
Talents Presentation at ESUG 2011Talents Presentation at ESUG 2011
Talents Presentation at ESUG 2011Jorge Ressia
 
Subjectopia tools2011
Subjectopia tools2011Subjectopia tools2011
Subjectopia tools2011Jorge Ressia
 
Advanced OO Design
Advanced OO DesignAdvanced OO Design
Advanced OO DesignJorge Ressia
 
Live featureanalysis
Live featureanalysisLive featureanalysis
Live featureanalysisJorge Ressia
 
05 Problem Detection
05 Problem Detection05 Problem Detection
05 Problem DetectionJorge Ressia
 

Plus de Jorge Ressia (8)

Object-Centric Debugging
Object-Centric DebuggingObject-Centric Debugging
Object-Centric Debugging
 
Talents Presentation at ESUG 2011
Talents Presentation at ESUG 2011Talents Presentation at ESUG 2011
Talents Presentation at ESUG 2011
 
Subjectopia tools2011
Subjectopia tools2011Subjectopia tools2011
Subjectopia tools2011
 
Advanced OO Design
Advanced OO DesignAdvanced OO Design
Advanced OO Design
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
Live featureanalysis
Live featureanalysisLive featureanalysis
Live featureanalysis
 
Runtime evolution
Runtime evolutionRuntime evolution
Runtime evolution
 
05 Problem Detection
05 Problem Detection05 Problem Detection
05 Problem Detection
 

Dernier

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Dernier (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

SDE - Dynamic Analysis

  • 1. Software Design and Evolution 11. Dynamic Analysis Jorge Ressia
  • 2. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 2
  • 3. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 3
  • 4. What does this program do? #include <stdio.h>main(t,_,a)char *a;{return!0<t?t<3? main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):1,t<_?main(t +1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?main(2,_+1,"%s %d %d ¥n"):9:16:t<0?t<-72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de} +,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#¥;#q#n+,/+k#;* +,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l ¥q#'+d'K#!/+k#;q#'r}eKK#} w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ¥){nl]!/ n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' ¥iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ¥;; {nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+} {rl#'{n' ')# ¥}'+}##(!!/"):t<-50?_==*a? putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t? main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,"!ek;dc i@bK'(q)- [w]*%n+r3#l,{}:¥nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);} Thomas Ball, The Concept of Dynamic Analysis, FSE’99 4 Source code can be hard to read and understand. This is a legal C program, an extreme case of course. This is intentionally obfuscated code. Obfuscation is a set of transformations that preserve the behavior of the program but make the internals hard to reverse-engineer. - Programming contests - Prevent reverse engineering
  • 5. Finding Features Software Feature: A distinguishing characteristic of a software item. IEEE 829 5
  • 6. Bug reports often expressed in terms of Features. I can’t add new contacts!!! 6 The software engineer needs to maintain a mental map between features and the parts of the code that implement them. Features are not implemented in one class. Their implementation spreads out over lots of classes. The behavior consist of objects that collaborate at runtime. “Change requests and bug reports are usually expressed in a language that reflects the features of a system” [Mehta and Heinemann 2002]
  • 7. Bug reports often expressed in terms of Features. I can’t add new contacts!!! The “add contacts“ feature 6 The software engineer needs to maintain a mental map between features and the parts of the code that implement them. Features are not implemented in one class. Their implementation spreads out over lots of classes. The behavior consist of objects that collaborate at runtime. “Change requests and bug reports are usually expressed in a language that reflects the features of a system” [Mehta and Heinemann 2002]
  • 8. Feature-Centric Reverse Engineering Software System F1 F2 Fn F2 F1 Fn Software developer Users 7
  • 9. Feature-Centric Reverse Engineering Software System F1 F2 Fn F2 F1 Fn Software developer Users 7
  • 10. Finding Features ? { { { { } } } } { } 8 I have a system and I need to find the features. Which part of the system belongs to which features?
  • 11. What is Dynamic Analysis? The investigation of the properties of a running software system over one or more executions (Static analysis examines the program code alone) 9
  • 12. Why Dynamic Analysis? Gap between run-time structure and code structure in OO programs Trying to understand one [structure] from the other is like trying to understand the dynamism of living ecosystems from the static taxonomy of plants and animals, and vice-versa. ! ! ! -- Erich Gamma et al., Design Patterns 10 Programs can be hard to understand from their source code alone. The static code does not explicitly reflect the dynamic behavior. The code structure consists of classes in fixed inheritance relationships. Difficulties: OO source code exposes a class hierarchy, not the run-time object collaborations Collaborations are spread throughout the code Polymorphism may hide which classes are instantiated A program’s run-time structure consists of rapidly changing networks of communicating objects.
  • 13. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 11
  • 14. Runtime Information Sources Many possibilities: hardware monitoring, tracing method execution, values of variables, memory usage etc... External view Internal view execute instrument program and program and watch it from watch it from outside inside 12
  • 15. External View Program output, UI (examine behavior, performance, …) Analyze used resources CPU and memory usage (top) Network usage (netstat, tcpdump) Open files, pipes, sockets (lsof) Examine logs (syslog, web logs, stdout/stderr, …) 13
  • 16. Internal View Log statements in code Stack trace Debugger Execution trace Many different tools are based on tracing: execution profilers, test coverage analyzers, tools for reverse engineering… 14 - Logs: Single points in the execution. - Stack trace: snapshot of the current stack - Debugger: interactive, allows one to step into future method executions. Not persistent. - Tracing: full history of all method executions
  • 17. Execution Tracing How can we capture “full” OO program execution? Trace entry and exit of methods Additional information: - receiver and arguments - class instantiations - …? 15 For now we consider this approach Sequence and nesting: construct tree structure Additional: -receiver and arguments -Return values -Object creation -Current feature -Distinguish process (analyze concurrency properties) Object referencing relationships not captured. Object graph at particular point in time cannot be reconstructed, now, how it evolves
  • 18. Tracing Techniques Instrumentation approaches —Sourcecode modification —Bytecode modification —Wrapping methods (Smalltalk) Simulate execution (using debugger infrastructure) Sampling At the VM level —Execution tracing by the interpreter —(Dynamic recompilation, JIT) 16 Simulate execution: slow, but very precise control possible Sampling: mainly used for profiling Dynamic recompilation: - control optimizations: compile hot blocks/paths/procedures to machine code - data optimizations: garbage collection: move objects for locality
  • 19. Technical Challenges > Instrumentation influences the behavior of the execution > Overhead: increased execution time > Large amount of data > Code also used by the tracer, library and system classes cannot be instrumented -> Trace at the VM level -> Scope instrumentation (Changeboxes) 17
  • 20. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 18
  • 21. Feature Analysis ? { { { { } } } } { } 19 I have a system and I need to find the features. Which part of the system belongs to which features?
  • 22. Loggers - low tech debugging “…debugging statements stay with the program; debugging sessions are transient. “ ! ! ! ! Kerningham and Pike public class Main { public static void main(String[] args) { Clingon aAlien = new Clingon(); System.out.println(“in main “); aAlien.spendLife(); } } 20 Inserting log statements into your code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.
  • 23. Loggers - low tech debugging “…debugging statements stay with the program; debugging sessions are transient. “ ! ! ! ! Kerningham and Pike Very messy! public class Main { public static void main(String[] args) { Clingon aAlien = new Clingon(); System.out.println(“in main “); aAlien.spendLife(); } } 20 Inserting log statements into your code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.
  • 24. Smalltalk Mechanisms > become: function > Method Wrappers > Anonymous Classes 21
  • 25. Java Dynamic Proxies public class DebugProxy implements java.lang.reflect.InvocationHandler { private Object obj; public static Object newInstance(Object obj) { return java.lang.reflect.Proxy.newProxyInstance( obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new DebugProxy(obj)); } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { .... Feature data gathering ... return m.invoke(obj, args); System.out.println("after method " + m.getName()); } } 22 http://docs.oracle.com/javase/1.3/docs/guide/reflection/ proxy.html
  • 26. AOP Aspect Oriented Programming http://www.eclipse.org/aspectj/doc/next/progguide/language.html 23 In the pointcut-advice (PA) mechanism for aspect-oriented programming, as embodied in AspectJ and others, cross- cutting behavior is defined by means of pointcuts and advices. Points during execution at which advices may be executed are called (dynamic) join points. A pointcut identifies a set of join points, and an advice is the action to be taken at a join point matched by a pointcut. An aspect is a module that encompasses a number of pointcuts and advices. In AspectJ, the decision of whether or not to use an aspect within a program is done at build time; if so, the aspect has global scope, i.e. it sees all join points of the program execution. Restricting the scope of an aspect can be done by introducing conditions in the pointcut definitions.
  • 27. AOP 24
  • 28. AOP 25
  • 29. AOP 26
  • 30. AOP Example public class HelloWorld { public static void say(String message) { System.out.println(message); } public static void sayToPerson(String message, String name) { System.out.println(name + ", " + message); } } 27
  • 31. AOP Example public aspect Example { pointcut callSayMessage() : call(public static void HelloWorld.say*(..)); before() : callSayMessage() { System.out.println("Good day!"); } after() : callSayMessage() { System.out.println("Thank you!"); } } 28
  • 32. Feature Analysis AOP public aspect FeatureAnalysis { pointcut callMessage() : call(public * com.mycompany..*.*(..)); before() : callMessage() { ... save feature information ... } } 29
  • 33. Feature Analysis AOP public aspect FeatureAnalysis { pointcut executeMessage() : execute(public * com.mycompany..*.*(..)); before() : executeMessage() { ... save feature information ... } } 30 So what's the difference between these join points? Well, there are a number of differences: Firstly, the lexical pointcut declarations within and withincode match differently. At a call join point, the enclosing code is that of the call site. This means that call(void m()) && withincode(void m()) will only capture directly recursive calls, for example. At an execution join point, however, the program is already executing the method, so the enclosing code is the method itself: execution(void m()) && withincode(void m()) is the same as execution(void m()). Secondly, the call join point does not capture super calls to non-static methods. This is because such super calls are different in Java, since they don't behave via dynamic dispatch like other calls to non-static methods. The rule of thumb is that if you want to pick a join point that runs when an actual piece of code runs (as is often the case for tracing), use execution, but if you want to pick one that runs when a particular signature is called (as is often the case for production aspects), use call.
  • 34. AspectJ pointcuts call(MethodPattern) withincode(MethodPattern) execution(MethodPattern) withincode(ConstructorPattern) get(FieldPattern) cflow(Pointcut) set(FieldPattern) cflowbelow(Pointcut) call(ConstructorPattern) this(Type or Id) execution(ConstructorPattern) target(Type or Id) initialization(ConstructorPattern) args(Type or Id, ...) preinitialization(ConstructorPattern) PointcutId(TypePattern or Id, ...) staticinitialization(TypePattern) if(BooleanExpression) handler(TypePattern) ! Pointcut adviceexecution() Pointcut0 && Pointcut1 within(TypePattern) Pointcut0 || Pointcut1 31 This is just and example for AspectJ, there are many other aspect languages with many different pointcuts with different objectives.
  • 35. Operational Decomposition McAffer - CodA - Meta-level Programming with CodA - ECOOP 1995 32
  • 36. Operational Decomposition Iguana C++, IguanaJ Bifröst AOP EAOP AspectJ tracematches 33
  • 37. Sub-method Feature Analysis ? { { { { } } } } { } 34 We need to find which statements belong to which feature.
  • 38. Sub-method Feature Analysis Bytecode Instrumentation 35
  • 39. Bytecode Instrumentation Smalltalk 36
  • 40. Example: Number>>asInteger > Smalltalk code: Number>>asInteger ! "Answer an Integer nearest ! the receiver toward zero." ! ^self truncated > Symbolic Bytecode 9 <70> self 10 <D0> send: truncated 11 <7C> returnTop 37
  • 41. Example: Step by Step > 9 <70> self —The receiver (self) is pushed on the stack > 10 <D0> send: truncated —Bytecode 208: send litereral selector 1 —Get the selector from the first literal —start message lookup in the class of the object that is on top of the stack —result is pushed on the stack > 11 <7C> returnTop —return the object on top of the stack to the calling method 38
  • 42. ByteSurgeon > Library for bytecode transformation in Smalltalk > Full flexibility of Smalltalk Runtime > Provides high-level API > For Pharo, but portable > Runtime transformation needed for —Adaptation of running systems —Tracing / debugging —New language features (MOP, AOP) 39
  • 43. Example: Logging > Goal: logging message send. > First way: Just edit the text: 40
  • 44. Logging with ByteSurgeon > Goal: Change the method without changing program text > Example: 41
  • 45. Logging: Step by Step 42
  • 46. Logging: Step by Step > instrumentSend: —takes a block as an argument —evaluates it for all send bytecodes 43
  • 47. Logging: Step by Step > The block has one parameter: send > It is executed for each send bytecode in the method 44
  • 48. Logging: Step by Step > Objects describing bytecode understand how to insert code —insertBefor —insertAfter —replace 45
  • 49. Logging: Step by Step > The code to be inserted. > Double quoting for string inside string – Transcript show: ’sending #test’ 46
  • 50. Inside ByteSurgeon > Uses IRBuilder internally > Transformation (Code inlining) done on IR 47
  • 51. ByteSurgeon Usage > On Methods or Classes: > Different instrument methods: —instrument: —instrumentSend: —instrumentTempVarRead: —instrumentTempVarStore: —instrumentTempVarAccess: —same for InstVar 48
  • 52. Advanced ByteSurgeon > Goal: extend a send with after logging 49
  • 53. Advanced ByteSurgeon > With ByteSurgeon, something like: > How can we access the receiver of the send? > Solution: Metavariable 50
  • 54. Advanced ByteSurgeon > With Bytesurgeon, something like: > How can we access the receiver of the send? > Solution: Metavariable 51
  • 55. Bytecode Instrumentation Java 52 www.javassist.org http://commons.apache.org/bcel/ http://asm.objectweb.org/
  • 56. Bytecode Manipulation > Java —Javassist – reflection – RMI —BCEL – Decompiling, Obfuscation, and Refactoring – AspectJ – FindBugs —ASM – Groovy – AspectWerkz 53 www.javassist.org http://commons.apache.org/bcel/ http://asm.objectweb.org/
  • 57. Javassist class Point { int x, y; void move(int dx, int dy) { x += dx; y += dy; } } 54
  • 58. Javassist ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get("Point"); CtMethod m = cc.getDeclaredMethod("move"); m.insertBefore("{ System.out.println($1); System.out.println($2); }"); cc.writeFile(); 55
  • 59. Javassist class Point { int x, y; void move(int dx, int dy) { { System.out.println(dx); System.out.println(dy); } x += dx; y += dy; } } 56
  • 60. Javassist - Edit Body CtMethod cm = ... ; cm.instrument( new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { if (m.getClassName().equals("Point") && m.getMethodName().equals("move")) m.replace("{ $1 = 0; $_ = $proceed($$); }"); } }); 57 searches the method body represented by cm and replaces all calls to move() in class Point with a block: • { $1 = 0; $_ = $proceed($$); }
  • 61. Problems with Bytecode Instrumentation > Bytecode is not a good meta model > Lost of management infrastructure is needed —Hook composition —Synthesized elements (hooks) vs original code —Mapping to source elements > Bytecode is optimized —e.g. no ifTrue: 58
  • 62. Smalltalk Mechanisms Simulation 59
  • 63. ST — Working with Bytecode Parsing and Interpretation > First step: Parse bytecode —enough for easy analysis, pretty printing, decompilation > Second step: Interpretation —needed for simulation, complex analyis (e.g., profiling) > Pharo provides frameworks for both: —InstructionStream/InstructionClient (parsing) —ContextPart (Interpretation) © Oscar Nierstrasz 60
  • 64. ST — Working with Bytecode The InstructionStream Hierarchy InstructionStream ! ContextPart ! ! BlockContext ! ! MethodContext ! Decompiler ! InstructionPrinter ! InstVarRefLocator ! BytecodeDecompiler © Oscar Nierstrasz 61
  • 65. ST — Working with Bytecode InstructionStream > Parses the byte-encoded instructions > State: —pc: program counter —sender: the method (bad name!) Object subclass: #InstructionStream ! instanceVariableNames: 'sender pc' ! classVariableNames: 'SpecialConstants' ! poolDictionaries: '' ! category: 'Kernel-Methods' © Oscar Nierstrasz 62
  • 66. ST — Working with Bytecode Usage > Generate an instance: instrStream := InstructionStream on: aMethod > Now we can step through the bytecode with: instrStream interpretNextInstructionFor: client > Calls methods on a client object for the type of bytecode, e.g. — pushReceiver — pushConstant: value — pushReceiverVariable: offset © Oscar Nierstrasz 63
  • 67. ST — Working with Bytecode InstructionClient > Abstract superclass —Defines empty methods for all methods that InstructionStream calls on a client > For convenience: —Clients don’t need to inherit from this class Object subclass: #InstructionClient ! instanceVariableNames: '' ! classVariableNames: '' ! poolDictionaries: '' ! category: 'Kernel-Methods' © Oscar Nierstrasz 64
  • 68. ST — Working with Bytecode Example: A test InstructionClientTest>>testInstructions ! "just interpret all of methods of Object" ! | methods client scanner| ! ! methods := Object methodDict values. ! client := InstructionClient new.! ! methods do: [:method | ! ! scanner := (InstructionStream on: method). ! ! [scanner pc <= method endPC] whileTrue: [ ! ! ! ! self shouldnt: ! ! ! ! ! ! [scanner interpretNextInstructionFor: client] ! ! ! ! ! raise: Error. ! ! ]. ! ]. © Oscar Nierstrasz 65
  • 69. ST — Working with Bytecode Example: Printing Bytecode > InstructionPrinter: —Print the bytecodes as human readable text > Example: —print the bytecode of Number>>asInteger: String streamContents: ! [:str | (InstructionPrinter on: Number>>#asInteger) ! ! ! ! printInstructionsOn: str ] '9 <70> self 10 <D0> send: truncated 11 <7C> returnTop ' © Oscar Nierstrasz 66
  • 70. ST — Working with Bytecode InstructionPrinter > Class Definition: InstructionClient subclass: #InstructionPrinter ! instanceVariableNames: 'method scanner stream indent' ! classVariableNames: '' ! poolDictionaries: '' ! category: 'Kernel-Methods' © Oscar Nierstrasz 67
  • 71. ST — Working with Bytecode InstructionPrinter > Main Loop: InstructionPrinter>>printInstructionsOn: aStream ! "Append to the stream, aStream, a description ! of each bytecode in the instruction stream." ! | end | ! stream := aStream. ! scanner := InstructionStream on: method. ! end := method endPC. ! [scanner pc <= end] ! ! whileTrue: [scanner interpretNextInstructionFor: self] © Oscar Nierstrasz 68
  • 72. ST — Working with Bytecode InstructionPrinter > Overwrites methods from InstructionClient to print the bytecodes as text > e.g. the method for pushReceiver InstructionPrinter>>pushReceiver ! "Print the Push Active Context's Receiver ! on Top Of Stack bytecode." ! self print: 'self' © Oscar Nierstrasz 69
  • 73. ST — Working with Bytecode Example: InstVarRefLocator InstructionClient subclass: #InstVarRefLocator ! instanceVariableNames: 'bingo' ! classVariableNames: '' ! poolDictionaries: '' ! category: 'Kernel-Methods' InstVarRefLocator>>interpretNextInstructionUsing: aScanner ! ! bingo := false. ! aScanner interpretNextInstructionFor: self. ! ^bingo InstVarRefLocator>>popIntoReceiverVariable: offset ! bingo := true InstVarRefLocator>>pushReceiverVariable: offset ! bingo := true InstVarRefLocator>>storeIntoReceiverVariable: offset ! bingo := true © Oscar Nierstrasz 70
  • 74. ST — Working with Bytecode InstVarRefLocator > Analyse a method, answer true if it references an instance variable CompiledMethod>>hasInstVarRef ! "Answer whether the receiver references an instance variable." ! | scanner end printer | ! scanner := InstructionStream on: self. ! printer := InstVarRefLocator new. ! end := self endPC. ! [scanner pc <= end] whileTrue: ! ! [ (printer interpretNextInstructionUsing: scanner) ! ! ! ifTrue: [^true]. ]. ! ^false © Oscar Nierstrasz 71
  • 75. ST — Working with Bytecode InstVarRefLocator > Example for a simple bytecode analyzer > Usage: aMethod hasInstVarRef > (has reference to variable testSelector) (TestCase>>#debug) hasInstVarRef true > (has no reference to a variable) (Integer>>#+) hasInstVarRef false © Oscar Nierstrasz 72
  • 76. ST — Working with Bytecode ContextPart: Semantics for Execution > Sometimes we need more than parsing —“stepping” in the debugger —system simulation for profiling InstructionStream subclass: #ContextPart ! instanceVariableNames: 'stackp' ! classVariableNames: 'PrimitiveFailToken QuickStep' ! poolDictionaries: '' ! category: 'Kernel-Methods' © Oscar Nierstrasz 73
  • 77. ST — Working with Bytecode Simulation > Provides a complete Bytecode interpreter > Run a block with the simulator: (ContextPart runSimulated: [3 factorial]) 6 © Oscar Nierstrasz 74
  • 78. What is the big picture? Source Bytecode code 75
  • 79. What is the big picture? Source code ? Bytecode 75
  • 80. AST Instrumentation Scanner Semantic Code code AST AST Bytecode / Parser Analysis Generation 76
  • 81. Reflectivity > Marcus Denker —Pharo Smalltalk —Geppetto 2 —Phersephone > Using Partial Behavioral Reflection Model —Reflex, Tanter etal. 77
  • 82. Compiler: AST RBProgramNode ! RBDoItNode > AST: Abstract Syntax Tree ! RBMethodNode —Encodes the Syntax as a Tree ! RBReturnNode ! RBSequenceNode —No semantics yet! ! RBValueNode —Uses the RB Tree: ! ! RBArrayNode – Visitors ! ! RBAssignmentNode – Backward pointers in ParseNodes ! ! RBBlockNode ! ! RBCascadeNode – Transformation (replace/add/delete) ! ! RBLiteralNode – Pattern-directed TreeRewriter ! ! RBMessageNode – PrettyPrinter ! ! RBOptimizedNode ! ! RBVariableNode 78
  • 83. Reflectivity meta-object links activation condition source code (AST) 79 Links for AST nodes
  • 84. Reflectivity meta-object links activation condition source code (AST) 79 Links for AST nodes Reflectivity Denke r 2008
  • 85. Reflectivity meta-object links activation condition source code (AST) 79 Links for AST nodes Reefl Rfl ccitvvtiyy eet i i t Deenke Dnke r r22008 0 8
  • 86. Reflectivity meta-object links activation condition source code (AST) 79 Links for AST nodes Reefl Rfl ccitvvtiyy eet i i t Deenke Dnke r r22008 0 8
  • 88. > Organize the meta-level > Explicit meta-object > Structural and Behavioral reflection > Partial Reflection > Unanticipation > Selective Reifications > No VM requirements 81
  • 89. Class Meta-object Object 82
  • 90. Class Meta-object Object 83
  • 91. Class Meta-object Evolved Object 84
  • 92. Feature Analysis | aMetaObject | aMetaObject := BFBehavioralMetaObject new. aMetaObject when: (ASTExecutionEvent new) do: [ ... feature information gathering ...]. aMetaObject bindTo: self 85 http://scg.unibe.ch/research/bifrost
  • 93. Implicit Problems > Partial Reflection —We want to reflect on portions of the system > Unanticipation —We want to reflect without having to anticipate where in the system > Selective Reifications —We want to have runtime reifications available > Composition —We want to be able to compose different analysis 86
  • 94. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 87
  • 95. Simultaneous Feature Analysis Login ? { { { { } } } } { } Printing 88
  • 96. Simultaneous Feature Analysis Dynamic Scope 89
  • 97. Simultaneous Feature Analysis Legend objects dynamic scope 90
  • 98. Simultaneous Feature Analysis Legend objects login feature printing feature 91
  • 99. CaesarJ Dynamically scoped aspects deploy(a){block} 92 Ivica Aracic, Vaidas Gasiunas, Mira Mezini, and Klaus Ostermann. An overview of CaesarJ. In Transactions on Aspect-Oriented Software Development, volume 3880 of Lecture Notes in Computer Science, pages 135–173. Springer-Verlag, February 2006. whereby the aspect instance a sees all join points produced in the dynamic extent of the execution of block
  • 100. Dynamically scoped aspects > AspectScheme > CaesarJ > AspectS 93
  • 101. Deployment Strategies depl(a, δ⟨c, d, f ⟩, e) a is an aspect δ is the strategy c stack propagation function d object propagation function f joint point filter e is an expression 94 Éric Tanter. Expressive Scoping of Dynamically-Deployed Aspects. In Proceedings of the 7th ACM International Conference on Aspect-Oriented Software Development (AOSD 2008), p. 168—179, ACM Press, Brussels, Belgium, April 2008.
  • 102. Deployment Strategies deploy[true,-,if(cars_sp.contains(jp.args(1)))](sp){ next.process(batch); } 95 Example from a car factory. Only some cars with a special package should get this adaptation
  • 103. Scoping Strategies Propagation and Activation Problem 96 Éric Tanter. Beyond static and dynamic scope. In Proceedings of the 5th symposium on Dynamic languages, DLS '09 p. 3—14, ACM, New York, NY, USA, 2009.
  • 104. Dynamic Scoping Prisma 97
  • 106. Simultaneous Feature Analysis Legend objects login feature printing feature 99
  • 107. Dynamic Scoping > Prisma —Execution Reification —Reflective Architecture —Execution composed of meta-objects —Reuse of Execution —Execution is not tied to threads —Broadening of Scope —Dynamic change of conditions 100
  • 108. Execution levels Legend objects feature analysis profiling 101
  • 109. Execution levels Denker etal. Meta Context metameta- object meta-2 link level 1 meta-object meta links level 0 operation base 102
  • 110. Execution levels > Polymorphic Bytecode Instrumentation (PBI) —Dynamic dispatch amongst several, possibly independent instrumentations —Instrumentations are saved and indexed by a version identifier —Implemented over BCEL —JVM —Scala, JRuby, etc. —Execution levels —Monitoring —Mixin Layers —Promising performance 103 Philippe Moret, Walter Binder, and Éric Tanter. Polymorphic bytecode instrumentation. In Proceedings of the tenth international conference on Aspect-oriented software development, AOSD '11 p. 129—140, ACM, New York, NY, USA, 2011.
  • 111. Scoping Dimensions > Nature of Adaptation. A structural adaptation depicts the addition or change of a structural element, like refinements in Classboxes. A behavioral adaptation execute some action when specific runtime events are triggered. > Scoped Definition. The boundaries of the scope are defined by the entry and exit points. These boundaries can be implicit or explicit. > Scope Information Exposure. Some approaches allow to bind a value to a variable which is bound to the scope. This trait is particularly important to provide reusable adaptations. > Scope Binding. There are two binding dimensions. The adaptation can be defined at compile time or at runtime, this is call binding time. The binding mode describes wether an adaptation can be undone/redone during execution, if so the binding mode is said to be dynamic otherwise is static. > Thread Locality. The scope can be defined locally to a single thread. For example, cflow in AspectJ is by default thread local, while tracematch in AspectJ extension is by default global. 104
  • 112. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 105
  • 113. Reverse Engineering g static view in er ne gi En se er ev R 106 In this course you have been introduced to the concepts of reverse engineering. Reverse engineering Reverse engineering abstracts high level abstractions that support system understanding [Chikofsky and Cross, 1990]. “Object-oriented language characteristics such as inheritance, dynamic binding and polymorphism mean that the behavior of a system can only be determined at runtime.” [Jerding 1996, Demeyer2003a] A static perspective of the system over looks semantic knowledge of the problem domain of a system. The semanic knowledge Should not be ignored. We need a way to enrich the static views with information about their intent. Which features do they Participate in at runtime? Are they specific to one part of the system, one feature, or is it general functionality that implements sone infrastructural functionality? So lets extend our analysis by incorporating dynamic data captured while executing the features.
  • 114. Reverse Engineering + Dynamic Analysis g static view in er ne gi En se er ev R + execution traces dynamic view 106 In this course you have been introduced to the concepts of reverse engineering. Reverse engineering Reverse engineering abstracts high level abstractions that support system understanding [Chikofsky and Cross, 1990]. “Object-oriented language characteristics such as inheritance, dynamic binding and polymorphism mean that the behavior of a system can only be determined at runtime.” [Jerding 1996, Demeyer2003a] A static perspective of the system over looks semantic knowledge of the problem domain of a system. The semanic knowledge Should not be ignored. We need a way to enrich the static views with information about their intent. Which features do they Participate in at runtime? Are they specific to one part of the system, one feature, or is it general functionality that implements sone infrastructural functionality? So lets extend our analysis by incorporating dynamic data captured while executing the features.
  • 115. Dynamic Analysis for Program Comprehension Post Mortem Analysis of execution traces Metrics Based Approaches -Frequency Analysis [Ball, Zaidman] -Runtime Coupling Metrics based on Web mining techniques to detect key classses in a trace. [Zaidman 2005] -High-Level Polymetric Views of Condensed Run-Time Information [Ducasse, Lanza and Bertoulli 2004] -Query-based approaches Recoverind high-level views from runtime data ! ! ! [Richner and Ducasse 1999] 107 .They define an execution scenario to maximize coverage of the system and ‘preciseness’. To execute all the features. Frequency analysis - small number of methods are responsible for a large amount of the trace. They focus on call relationships between methods to learn something about a system. Coupling metrics: Runtime metrics - how many methods of a class were invoked during the execution of a system. -which classes create objects -Which classes communicate with each other
  • 116. Visualization of Runtime Behavior Problem of Large traces [JinSight, De Pauw 1993] 108 Traces of execution behavior lead to huge execution traces of tens of thousands of events. This makes them difficult to interpret or to Extract high level views. We need techniques to reduce the volume of information without loss of details needed to answer a specific research question. For example: “Which classes and methods implement the save contact feature?” Wim dePauw [JinSight, De Pauw 1993]. Other compression approaches Use graph algorithms to detect patterns and reduce the volume of data. Use patterns to learn something about the system behavior.
  • 117. Dividing a trace into features Feature 1 Feature 2 Feature n 109
  • 118. Feature Identification is a technique to map features to source code. “A feature is an observable unit of behavior of a system triggered by the user” [Eisenbarth etal. 2003] Software Reconnaissance [Wilde and Scully ] Run a (1) feature exhibiting scenario and a (2) non-exhibiting scenario and compare the traces. Then browse the source code. 110 Other researchers had devised variations of software reconnaissance - Antoniol, Eisenberg etc.
  • 119. Feature Identification is a technique to map features to source code. “A feature is an observable unit of behavior of a system triggered by the user” [Eisenbarth etal. 2003] Software Reconnaissance [Wilde and Scully ] Run a (1) feature exhibiting scenario and a (2) non-exhibiting scenario and compare the traces. Then browse the source code. 110 Other researchers had devised variations of software reconnaissance - Antoniol, Eisenberg etc.
  • 120. Feature Identification is a technique to map features to source code. “A feature is an observable unit of behavior of a system triggered by the user” [Eisenbarth etal. 2003] Software Reconnaissance [Wilde and Scully ] Run a (1) feature exhibiting scenario and a (2) non-exhibiting scenario and compare the traces. Then browse the source code. 110 Other researchers had devised variations of software reconnaissance - Antoniol, Eisenberg etc.
  • 121. Feature-Centric Analysis: 3 Complementary Perspectives F1 F2 F3 F4 F5 111 1) How are classes related to features? 2) How are features related to classes? 3) How are features related to each other? We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
  • 122. Feature-Centric Analysis: 3 Complementary Perspectives F1 F2 F3 F4 F5 Classes Perspective 111 1) How are classes related to features? 2) How are features related to classes? 3) How are features related to each other? We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
  • 123. Feature-Centric Analysis: 3 Complementary Perspectives F1 F2 F3 F4 F5 Classes Perspective Features Perspective 111 1) How are classes related to features? 2) How are features related to classes? 3) How are features related to each other? We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
  • 124. Feature-Centric Analysis: 3 Complementary Perspectives Features Relationships F1 Perspective F2 F3 F4 F5 Classes Perspective Features Perspective 111 1) How are classes related to features? 2) How are features related to classes? 3) How are features related to each other? We define a Feature-Affinity metric to distinguish between various levels of characterization of classes.
  • 125. Dynamix - A Model for Dynamic Analysis 112
  • 126. DynaMoose - An Environment for Feature Analysis 113
  • 127. DynaMoose - An Environment for Feature Analysis 113
  • 128. DynaMoose - An Environment for Feature Analysis 113
  • 129. DynaMoose - An Environment for Feature Analysis 113
  • 130. DynaMoose - An Environment for Feature Analysis 113
  • 131. DynaMoose - An Environment for Feature Analysis 113
  • 132. Demo of Feature Analysis - Feature Views of Classes PhoneButtonEventBackSpace PhoneStateContact PhoneStateContactForm EditableText CustomTextArea Feature Views of PhoneSim Classes 114 Here we see the feature views (of classes) Our question was “Which classes participate in the addContacts feature?”
  • 133. Feature Views of ‘Phonesim’ Methods Feature Views of PhoneSim Methods 115 Which methods participate in the feature ‘addContacts()’? 22 single feature methods
  • 134. Object Flow Analysis Method execution traces do not reveal how … objects refer to each other … object references evolve Trace and analyze object flow — Object-centric debugger: Trace back flow from errors to code that produced the objects — Detect object dependencies between features 116
  • 135. Roadmap > Motivation > Sources of Runtime Information > Dynamic Analysis Techniques > Advanced Dynamic Analysis Techniques > Dynamic analysis in a Reverse Engineering Context > What can we achieve with all this? > Conclusion 117
  • 136. What is the future? Live Feature Analysis 118
  • 137. Live Feature Analysis Denker etal. Source Traces 119 Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October 2010. 
  • 138. Live Feature Analysis Denker etal. Traces Source 120 Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October 2010. 
  • 139. Live Feature Analysis Feature tagger meta-object tags node with feature annotation on execution source code (AST) 121
  • 140. What is the future? Object Centric Debugging 122
  • 141. Object Centric Debugging { { { { } } } } { } http://scg.unibe.ch/research/bifrost/OCD 123 Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October 2010. 
  • 142. Object Centric Debugging { { { { } } } } { } http://scg.unibe.ch/research/bifrost/OCD 123 Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October 2010. 
  • 143. Object Centric Debugging { { { { } } } } { } http://scg.unibe.ch/research/bifrost/OCD 124 Marcus Denker, Jorge Ressia, Orla Greevy, and Oscar Nierstrasz. Modeling Features at Runtime. In Proceedings of MODELS 2010 Part II, LNCS 6395 p. 138—152, Springer-Verlag, October 2010. 
  • 144. Object Centric Debugging Object>>haltAtNextMessage | aMetaObject | aMetaObject := BFBehavioralMetaObject new. aMetaObject when: (BFMessageReceiveEvent new) do: [ self metaObject unbindFrom: self. TransparentBreakpoint signal ]. aMetaObject bindTo: self 125
  • 145. What is the future? MetaSpy Domain-specific Profiling 126
  • 146. Domain-specific Profiling Domain-Specific Profiling 3 CPU time profiling Mondrian [9] is an open and agile visualization engine. Mondrian describes a visualization using a graph of (possibly nested) nodes and edges. In June 2010 Profile a serious performance issue was raised1 . Tracking down the cause of the poor performance was not trivial. We first used a standard sample-based profiler. Execution sampling approximates the time spent in an application’s methods by periodically stopping a program and recording the current set of methods under executions. Such a profiling technique is relatively accurate since it has little impact on the overall execution. This sampling technique is used by almost all mainstream profilers, such as JProfiler, YourKit, xprof [10], and hprof. MessageTally, the standard sampling-based profiler in Pharo Smalltalk2 , tex- tually describes the execution in terms of CPU consumption and invocation for each method of Mondrian: 54.8% {11501ms} MOCanvas>>drawOn: 54.8% {11501ms} MORoot(MONode)>>displayOn: { { 30.9% {6485ms} MONode>>displayOn: { { | 18.1% {3799ms} MOEdge>>displayOn: } ... } } | 8.4% {1763ms} MOEdge>>displayOn: | | 8.0% {1679ms} MOStraightLineShape>>display:on: } { } | | 2.6% {546ms} FormCanvas>>line:to:width:color: ... 23.4% {4911ms} MOEdge>>displayOn: ... We can observe that the virtual machine spent about 54% of its time in the method displayOn: defined in the class MORoot. A root is the unique non- nested node that contains all the nodes of the edges of the visualization. This general profiling information says that rendering nodes and edges consumes a great share of the CPU time, but it does not help in pinpointing which nodes and edges are responsible for the time spent. Not all graphical elements equally consume resources. Traditional execution sampling profilers center their result on the frames of the execution stack and completely ignore the identity of the object that received the method call and its arguments. As a consequence, it is hard to track down which objects cause the slowdown. For the example above, the traditional profiler says that we spent 30.9% in MONode>>displayOn: without saying which nodes were actually refreshed too often. Coverage PetitParser is a parsing framework combining ideas from scannerless parsing, parser combinators, parsing expression grammars and packrat parsers to model grammars and parsers as objects that can be reconfigured dynamically [11]. 1 http://forum.world.st/Mondrian-is-slow-next-step-tc2257050.html# a2261116 http://scg.unibe.ch/research/bifrost/metaspy 2 http://www.pharo-project.org/ 127 Alexandre Bergel, Oscar Nierstrasz, Lukas Renggli, and Jorge Ressia. Domain-Specific Profiling. In Proceedings of the 49th International Conference on Objects, Models, Components and Patterns (TOOLS'11), LNCS 6705 p. 68—82, Springer-Verlag, June 2011.
  • 147. Domain-specific Profiling Domain-Specific Profiling 3 CPU time profiling Mondrian [9] is an open and agile visualization engine. Mondrian describes a visualization using a graph of (possibly nested) nodes and edges. In June 2010 Profile a serious performance issue was raised1 . Tracking down the cause of the poor performance was not trivial. We first used a standard sample-based profiler. Execution sampling approximates the time spent in an application’s methods by periodically stopping a program and recording the current set of methods under executions. Such a profiling technique is relatively accurate since it has little impact on the overall execution. This sampling technique is used by almost all mainstream profilers, such as JProfiler, YourKit, xprof [10], and hprof. MessageTally, the standard sampling-based profiler in Pharo Smalltalk2 , tex- tually describes the execution in terms of CPU consumption and invocation for each method of Mondrian: 54.8% {11501ms} MOCanvas>>drawOn: 54.8% {11501ms} MORoot(MONode)>>displayOn: { { 30.9% {6485ms} MONode>>displayOn: { { | 18.1% {3799ms} MOEdge>>displayOn: } ... } } | 8.4% {1763ms} MOEdge>>displayOn: | | 8.0% {1679ms} MOStraightLineShape>>display:on: } { } | | 2.6% {546ms} FormCanvas>>line:to:width:color: ... 23.4% {4911ms} MOEdge>>displayOn: ... We can observe that the virtual machine spent about 54% of its time in the method displayOn: defined in the class MORoot. A root is the unique non- nested node that contains all the nodes of the edges of the visualization. This general profiling information says that rendering nodes and edges consumes a great share of the CPU time, but it does not help in pinpointing which nodes and edges are responsible for the time spent. Not all graphical elements equally consume resources. Traditional execution sampling profilers center their result on the frames of the execution stack and completely ignore the identity of the object that received the method call and its arguments. As a consequence, it is hard to track down which objects cause the slowdown. For the example above, the traditional profiler says that we spent 30.9% in MONode>>displayOn: without saying which nodes were actually refreshed too often. Coverage Domain PetitParser is a parsing framework combining ideas from scannerless parsing, parser combinators, parsing expression grammars and packrat parsers to model grammars and parsers as objects that can be reconfigured dynamically [11]. 1 http://forum.world.st/Mondrian-is-slow-next-step-tc2257050.html# a2261116 http://scg.unibe.ch/research/bifrost/metaspy 2 http://www.pharo-project.org/ 127 Alexandre Bergel, Oscar Nierstrasz, Lukas Renggli, and Jorge Ressia. Domain-Specific Profiling. In Proceedings of the 49th International Conference on Objects, Models, Components and Patterns (TOOLS'11), LNCS 6705 p. 68—82, Springer-Verlag, June 2011.
  • 148. Domain-specific Profiling Domain-Specific Profiling 3 CPU time profiling Mondrian [9] is an open and agile visualization engine. Mondrian describes a visualization using a graph of (possibly nested) nodes and edges. In June 2010 Profile a serious performance issue was raised1 . Tracking down the cause of the poor performance was not trivial. We first used a standard sample-based profiler. Execution sampling approximates the time spent in an application’s methods by periodically stopping a program and recording the current set of methods under executions. Such a profiling technique is relatively accurate since it has little impact on the overall execution. This sampling technique is used by almost all mainstream profilers, such as JProfiler, YourKit, xprof [10], and hprof. MessageTally, the standard sampling-based profiler in Pharo Smalltalk2 , tex- tually describes the execution in terms of CPU consumption and invocation for each method of Mondrian: 54.8% {11501ms} MOCanvas>>drawOn: 54.8% {11501ms} MORoot(MONode)>>displayOn: { { 30.9% {6485ms} MONode>>displayOn: { { | 18.1% {3799ms} MOEdge>>displayOn: } ... } } | 8.4% {1763ms} MOEdge>>displayOn: | | 8.0% {1679ms} MOStraightLineShape>>display:on: } { } | | 2.6% {546ms} FormCanvas>>line:to:width:color: ... 23.4% {4911ms} MOEdge>>displayOn: ... We can observe that the virtual machine spent about 54% of its time in the method displayOn: defined in the class MORoot. A root is the unique non- nested node that contains all the nodes of the edges of the visualization. This general profiling information says that rendering nodes and edges consumes a great share of the CPU time, but it does not help in pinpointing which nodes and edges are responsible for the time spent. Not all graphical elements equally consume resources. Traditional execution sampling profilers center their result on the frames of the execution stack and completely ignore the identity of the object that received the method call and its arguments. As a consequence, it is hard to track down which objects cause the slowdown. For the example above, the traditional profiler says that we spent 30.9% in MONode>>displayOn: without saying which nodes were actually refreshed too often. Coverage Domain PetitParser is a parsing framework combining ideas from scannerless parsing, parser combinators, parsing expression grammars and packrat parsers to model grammars and parsers as objects that can be reconfigured dynamically [11]. 1 http://forum.world.st/Mondrian-is-slow-next-step-tc2257050.html# a2261116 http://scg.unibe.ch/research/bifrost/metaspy 2 http://www.pharo-project.org/ 127 Alexandre Bergel, Oscar Nierstrasz, Lukas Renggli, and Jorge Ressia. Domain-Specific Profiling. In Proceedings of the 49th International Conference on Objects, Models, Components and Patterns (TOOLS'11), LNCS 6705 p. 68—82, Springer-Verlag, June 2011.