org.softevo.jdynpur.eval
Class PurityTraceAnalyser

java.lang.Object
  extended by org.softevo.jdynpur.eval.PurityTraceAnalyser
Direct Known Subclasses:
MethodExecutionDisplayer

public class PurityTraceAnalyser
extends java.lang.Object

This class implements dynamic purity analysis of an execution trace file. The main idea of the analysis is as follows:

Author:
dallmeier

Nested Class Summary
static class PurityTraceAnalyser.ParameterMutabilityInformation
           
 
Field Summary
protected  boolean excludeAPIMethodsFromResults
          Flag indicating if API methods should be excluded from the result data structures.
protected  java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> executedMethodIdentifiers
          The set of executed MethodIdentifiers.
protected  java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> executedMethodIds
          The set of executed methods.
protected  org.softevo.util.ObjectIdMapper<org.softevo.util.asm.FieldIdentifier> fieldIdentifierMap
           
protected  java.lang.String fileName
          The name of the trace file to be analyzed.
protected  org.softevo.util.asm.MethodIdentifierMapGenerator identifierMap
          Identifier map used for this trace.
protected  boolean ignoreEffectsOfStaticInitializers
          Flag indicating if the effects of static initializers should be ignored.
protected  java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> impureMethodIdentifiers
          The set of MethodIdentifiers known to be impure.
protected  java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> impureMethodIds
          The set of method ids known to be impure.
protected  java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> methodsModifyingThisObject
          The set of methods known to modify the object they were invoked on.
protected  java.util.Vector<java.lang.Long> mutabilityChangeEntries
           
protected  java.util.HashMap<org.softevo.util.asm.MethodIdentifier,PurityTraceAnalyser.ParameterMutabilityInformation> parameterMutabilityInformation
           
protected  boolean printResults
          Flag if pure method identifiers should be printed to System.out .
protected  java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> pureMethodIdentifiers
          The set of MethodIdentifiers known to be pure.
protected  java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> pureMethodIds
          The set of method ids that might be pure.
protected  java.util.Vector<java.lang.Long> purityChangeEntries
           
protected  PurityResults results
           
protected  java.lang.String resultsFileName
          Name of the file where results are saved.
protected  boolean saveResults
          Flag if results shall be saved.
protected  java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> thisModifyingMethodIdentifiers
          The set of MethodIdentifiers modifying a this object.
protected  java.util.HashMap<java.lang.Integer,java.util.Stack<java.util.HashSet<java.lang.Integer>>> threadIdToCreatedObjectSetStackMap
          A map of thread ids to a stack of object identifiers created in a method.
protected  java.util.HashMap<java.lang.Integer,java.util.Stack<java.lang.Integer>> threadIdToMethodCallStackMap
          A map of thread ids to a method call stack.
protected  java.util.HashMap<java.lang.Integer,java.util.Stack<java.util.HashSet<java.lang.Integer>>> threadIdToModifiedObjectSetStackMap
          A map of thread ids to a stack of object identifiers modified in a method.
protected  java.util.HashMap<java.lang.Integer,java.util.Stack<java.util.HashMap<java.lang.Integer,java.lang.Integer>>> threadIdToParameterSetStackMap
           
protected  java.util.HashMap<java.lang.Integer,java.util.Stack<java.lang.Integer>> threadIdToThisStackMap
          A map of thread ids to a stack of this object identifiers for active non-static methods.
protected  java.util.HashMap<java.lang.Integer,java.util.Stack<java.lang.String>> threadIdToThisTypeMap
          A map of thread ids to a stack of this type for active non-static methods.
protected  boolean verbose
          Flag for verbose output.
 
Constructor Summary
PurityTraceAnalyser(java.lang.String fileName, java.lang.String resultsFileName, boolean saveResults, boolean analyseParameterMutability)
          Creates a new purity analyser for a trace file.
 
Method Summary
protected  void addToHashMap(java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> map, int methodId, java.lang.String className)
           
 void analyse(boolean verbose, boolean printResults)
          Starts analysis of the trace.
protected  java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> convertMap(java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> map)
           
protected  java.util.Stack<java.util.HashSet<java.lang.Integer>> getCreatedObjectSetStack(int threadId)
          Gets the created object set stack for a given thread.
 java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getExecutedMethodIdentifiers()
          Gets the set of executed methods.
 java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getImpureMethodIdentifiers()
          Gets the set of impure methods.
protected  java.util.Stack<java.lang.Integer> getMethodCallStack(int threadId)
          Gets the method call stack for a given thread.
protected  java.util.Stack<java.util.HashSet<java.lang.Integer>> getModifiedObjectSetStack(int threadId)
          Gets the modified object set stack for a given thread.
 java.util.HashMap<org.softevo.util.asm.MethodIdentifier,PurityTraceAnalyser.ParameterMutabilityInformation> getParameterMutabilityInformation()
           
protected  java.util.Stack<java.util.HashMap<java.lang.Integer,java.lang.Integer>> getParameterSetStack(int threadId)
           
 java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getPureMethodIdentifiers()
          Gets the set of pure methods.
 PurityResults getResults()
           
 java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getThisModifyingMethodIdentifiers()
          Gets the set of executed methods.
protected  java.util.Stack<java.lang.Integer> getThisObjectStack(int threadId)
          Gets the this object stack for a given thread.
protected  java.util.Stack<java.lang.String> getThisTypeStack(int threadId)
           
protected  java.util.HashSet<java.lang.Integer> getTransitiveStateForObject(int objectId)
           
protected  void handleArrayCreation(int objectId, int threadId)
          Called to handle an array creation event.
protected  void handleArrayModification(int objectId, int threadId)
          Called to handle an array modification event.
protected  void handleDynamicMethodEnd(int methodId, int threadId)
          Handles end of a dynamic method.
protected  void handleDynamicMethodStart(int methodId, int thisObjectId, int threadId, java.lang.String className)
          Handles start of a dynamic method.
protected  void handleFieldWrite(int objectId, int threadId)
          Called to handle a field write event.
protected  void handleMethodEnd(int methodId, int threadId, java.lang.String className)
          Handles method end events.
protected  void handleMethodStart(int methodId, int threadId, java.lang.String className)
          Handles a method start event.
protected  void handleObjectArrayModification(int threadId, int changedObjectId, int arrayIndex, int newObjectId)
           
protected  void handleObjectCreation(int objectId, int threadId)
          Handles object creation event.
protected  void handleObjectFieldWrite(int fieldId, int threadId, int changedObjectId, int newValueObjectId)
           
protected  void handleParameter(int index, int threadId, int objectId)
           
protected  void handleStaticFieldWrite(int threadId)
          Called to handle a static field write event.
protected  void handleStaticMethodEnd(int methodId, int threadId)
          Handles end of a static method.
protected  void handleStaticMethodStart(int methodId, int threadId)
          Handles start of a static method.
protected  void handleTraceEnd()
          This method is called upon end of the trace.
protected  boolean isAPIMethod(int methodId)
          This method checks if the integer passed identifies a user or an API method.
static void main(java.lang.String[] args)
          Launches purity trace analysis.
protected  void processParameterModification(java.util.HashMap<java.lang.Integer,java.lang.Integer> parameters, java.util.HashSet<java.lang.Integer> modifiedObjects, int methodId, java.lang.String className)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileName

protected java.lang.String fileName
The name of the trace file to be analyzed.


resultsFileName

protected java.lang.String resultsFileName
Name of the file where results are saved.


identifierMap

protected org.softevo.util.asm.MethodIdentifierMapGenerator identifierMap
Identifier map used for this trace.


impureMethodIds

protected java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> impureMethodIds
The set of method ids known to be impure.


pureMethodIds

protected java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> pureMethodIds
The set of method ids that might be pure.


executedMethodIds

protected java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> executedMethodIds
The set of executed methods.


methodsModifyingThisObject

protected java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> methodsModifyingThisObject
The set of methods known to modify the object they were invoked on.


pureMethodIdentifiers

protected java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> pureMethodIdentifiers
The set of MethodIdentifiers known to be pure.


thisModifyingMethodIdentifiers

protected java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> thisModifyingMethodIdentifiers
The set of MethodIdentifiers modifying a this object.


impureMethodIdentifiers

protected java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> impureMethodIdentifiers
The set of MethodIdentifiers known to be impure.


executedMethodIdentifiers

protected java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> executedMethodIdentifiers
The set of executed MethodIdentifiers.


threadIdToCreatedObjectSetStackMap

protected java.util.HashMap<java.lang.Integer,java.util.Stack<java.util.HashSet<java.lang.Integer>>> threadIdToCreatedObjectSetStackMap
A map of thread ids to a stack of object identifiers created in a method.


threadIdToParameterSetStackMap

protected java.util.HashMap<java.lang.Integer,java.util.Stack<java.util.HashMap<java.lang.Integer,java.lang.Integer>>> threadIdToParameterSetStackMap

fieldIdentifierMap

protected org.softevo.util.ObjectIdMapper<org.softevo.util.asm.FieldIdentifier> fieldIdentifierMap

threadIdToModifiedObjectSetStackMap

protected java.util.HashMap<java.lang.Integer,java.util.Stack<java.util.HashSet<java.lang.Integer>>> threadIdToModifiedObjectSetStackMap
A map of thread ids to a stack of object identifiers modified in a method.


threadIdToMethodCallStackMap

protected java.util.HashMap<java.lang.Integer,java.util.Stack<java.lang.Integer>> threadIdToMethodCallStackMap
A map of thread ids to a method call stack.


threadIdToThisStackMap

protected java.util.HashMap<java.lang.Integer,java.util.Stack<java.lang.Integer>> threadIdToThisStackMap
A map of thread ids to a stack of this object identifiers for active non-static methods.


threadIdToThisTypeMap

protected java.util.HashMap<java.lang.Integer,java.util.Stack<java.lang.String>> threadIdToThisTypeMap
A map of thread ids to a stack of this type for active non-static methods.


parameterMutabilityInformation

protected java.util.HashMap<org.softevo.util.asm.MethodIdentifier,PurityTraceAnalyser.ParameterMutabilityInformation> parameterMutabilityInformation

mutabilityChangeEntries

protected java.util.Vector<java.lang.Long> mutabilityChangeEntries

purityChangeEntries

protected java.util.Vector<java.lang.Long> purityChangeEntries

results

protected PurityResults results

verbose

protected boolean verbose
Flag for verbose output.


printResults

protected boolean printResults
Flag if pure method identifiers should be printed to System.out .


saveResults

protected boolean saveResults
Flag if results shall be saved.


excludeAPIMethodsFromResults

protected boolean excludeAPIMethodsFromResults
Flag indicating if API methods should be excluded from the result data structures.


ignoreEffectsOfStaticInitializers

protected boolean ignoreEffectsOfStaticInitializers
Flag indicating if the effects of static initializers should be ignored. If you are not sure about this flag, set it to true.

Constructor Detail

PurityTraceAnalyser

public PurityTraceAnalyser(java.lang.String fileName,
                           java.lang.String resultsFileName,
                           boolean saveResults,
                           boolean analyseParameterMutability)
Creates a new purity analyser for a trace file.

Parameters:
fileName - the name of the trace
identifierMap - the identifier map generated together with the trace
Method Detail

analyse

public void analyse(boolean verbose,
                    boolean printResults)
             throws java.io.IOException
Starts analysis of the trace.

Parameters:
verbose - flag if output shall be verbose
printResults - flag if results should be printed to System.out
Throws:
java.io.IOException - if an exception occurs reading from the trace

getTransitiveStateForObject

protected java.util.HashSet<java.lang.Integer> getTransitiveStateForObject(int objectId)

handleObjectArrayModification

protected void handleObjectArrayModification(int threadId,
                                             int changedObjectId,
                                             int arrayIndex,
                                             int newObjectId)

handleObjectFieldWrite

protected void handleObjectFieldWrite(int fieldId,
                                      int threadId,
                                      int changedObjectId,
                                      int newValueObjectId)

handleParameter

protected void handleParameter(int index,
                               int threadId,
                               int objectId)

getThisTypeStack

protected java.util.Stack<java.lang.String> getThisTypeStack(int threadId)

getThisObjectStack

protected java.util.Stack<java.lang.Integer> getThisObjectStack(int threadId)
Gets the this object stack for a given thread.

Parameters:
threadId - the id of the thread
Returns:
the stack

getMethodCallStack

protected java.util.Stack<java.lang.Integer> getMethodCallStack(int threadId)
Gets the method call stack for a given thread.

Parameters:
threadId - the id of the thread
Returns:
the stack

getCreatedObjectSetStack

protected java.util.Stack<java.util.HashSet<java.lang.Integer>> getCreatedObjectSetStack(int threadId)
Gets the created object set stack for a given thread.

Parameters:
threadId - the id of the thread
Returns:
the stack

getModifiedObjectSetStack

protected java.util.Stack<java.util.HashSet<java.lang.Integer>> getModifiedObjectSetStack(int threadId)
Gets the modified object set stack for a given thread.

Parameters:
threadId - the id of the thread
Returns:
the stack

getParameterSetStack

protected java.util.Stack<java.util.HashMap<java.lang.Integer,java.lang.Integer>> getParameterSetStack(int threadId)

isAPIMethod

protected boolean isAPIMethod(int methodId)
This method checks if the integer passed identifies a user or an API method. Identification of API methods is done by class name.

Parameters:
methodId - the method identifier

convertMap

protected java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> convertMap(java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> map)

handleTraceEnd

protected void handleTraceEnd()
This method is called upon end of the trace. It fills the result datastructures and prints information to System.out if the printResults flag is set.


handleArrayCreation

protected void handleArrayCreation(int objectId,
                                   int threadId)
Called to handle an array creation event.

Parameters:
objectId - the id of the new array
threadId - the thread id

handleArrayModification

protected void handleArrayModification(int objectId,
                                       int threadId)
Called to handle an array modification event.

Parameters:
objectId - the id of the modified array
threadId - the thread id

handleStaticFieldWrite

protected void handleStaticFieldWrite(int threadId)
Called to handle a static field write event.

Parameters:
threadId - the thread id

handleFieldWrite

protected void handleFieldWrite(int objectId,
                                int threadId)
Called to handle a field write event.

Parameters:
threadId - the thread id
objectId - id of the modified object

handleObjectCreation

protected void handleObjectCreation(int objectId,
                                    int threadId)
Handles object creation event.

Parameters:
objectId - the id of the new object
threadId - the thread id

addToHashMap

protected void addToHashMap(java.util.HashMap<java.lang.Integer,java.util.HashSet<java.lang.String>> map,
                            int methodId,
                            java.lang.String className)

handleMethodStart

protected void handleMethodStart(int methodId,
                                 int threadId,
                                 java.lang.String className)
Handles a method start event. This method creates all neccessary datastructures to analyze execution of the method.

Parameters:
methodId - the id of the method invoked
threadId - the thread id

handleDynamicMethodStart

protected void handleDynamicMethodStart(int methodId,
                                        int thisObjectId,
                                        int threadId,
                                        java.lang.String className)
Handles start of a dynamic method. In addition to calling handleMethodStart, this method also modifieds the thisObjectStack.

Parameters:
methodId - the method identifier
thisObjectId - the identifier of the this object
threadId - the id of the thread

handleStaticMethodStart

protected void handleStaticMethodStart(int methodId,
                                       int threadId)
Handles start of a static method. This method only calls handleMethodStart

Parameters:
methodId - the identifier of the method
threadId - the thread id

handleStaticMethodEnd

protected void handleStaticMethodEnd(int methodId,
                                     int threadId)
Handles end of a static method. This method only calls handleMethodEnd.

Parameters:
methodId - the id of the method
threadId - the thread id

handleDynamicMethodEnd

protected void handleDynamicMethodEnd(int methodId,
                                      int threadId)
Handles end of a dynamic method. In addition to calling handleMethodEnd, this method also modifies the thisObjectStack

Parameters:
methodId - the id of the method
threadId - the thread id

handleMethodEnd

protected void handleMethodEnd(int methodId,
                               int threadId,
                               java.lang.String className)
Handles method end events. This method evaluates the set of modified and created objects and classifies methods as impure.

Parameters:
methodId - the id of the method
threadId - the thread id

processParameterModification

protected void processParameterModification(java.util.HashMap<java.lang.Integer,java.lang.Integer> parameters,
                                            java.util.HashSet<java.lang.Integer> modifiedObjects,
                                            int methodId,
                                            java.lang.String className)

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Launches purity trace analysis. This method expects the name of the trace file and the name of the identifier map file.

Parameters:
args - command line arguments
Throws:
java.io.IOException

getImpureMethodIdentifiers

public java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getImpureMethodIdentifiers()
Gets the set of impure methods.


getPureMethodIdentifiers

public java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getPureMethodIdentifiers()
Gets the set of pure methods.


getThisModifyingMethodIdentifiers

public java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getThisModifyingMethodIdentifiers()
Gets the set of executed methods.


getExecutedMethodIdentifiers

public java.util.HashMap<org.softevo.util.asm.MethodIdentifier,java.util.HashSet<java.lang.String>> getExecutedMethodIdentifiers()
Gets the set of executed methods.


getResults

public PurityResults getResults()

getParameterMutabilityInformation

public java.util.HashMap<org.softevo.util.asm.MethodIdentifier,PurityTraceAnalyser.ParameterMutabilityInformation> getParameterMutabilityInformation()


Copyright © 2007-2008 Software Engineering Group at Saarland University. All Rights Reserved.