edu.cmu.cs.crystal.flow.concur
Class ConcurrentFlowAnalysis<LE>

java.lang.Object
  extended by edu.cmu.cs.crystal.flow.concur.ConcurrentFlowAnalysis<LE>
Type Parameters:
LE -
All Implemented Interfaces:
IFlowAnalysis<LE>

public class ConcurrentFlowAnalysis<LE>
extends Object
implements IFlowAnalysis<LE>

An implementation of IFlowAnalysis that analyzes methods in concurrently. Creates a thread pool, and when analyzedPreemtively is called (or the constructor that takes a list of methods) we generate a future for each method declaration, force its analysis in a brand new FlowAnalysis object, and store that in a mapping from method declarations to IFlowAnalysis objects. Later, we can delegate the standard flow analysis methods on the future, forcing its completion. This class is EXPERIMENTAL because certain shared classes, most notably EclipseTAC, are not yet thought to be thread-safe. The biggest worry is that there is no memory barrier between different analyses.

Author:
Nels Beckman

Constructor Summary
ConcurrentFlowAnalysis(ITransferFunction<LE> transferFunction, Crystal crystal)
          Creates a new concurrent flow analysis but does not analyze any methods immediately.
ConcurrentFlowAnalysis(ITransferFunction<LE> transferFunction, List<MethodDeclaration> methods, Crystal crystal)
          Creates a new concurrent flow analysis and begins to analyze the given method bodies immediately.
 
Method Summary
 void analyzePreemitively(List<MethodDeclaration> methods)
          Perform dataflow analysis asynchronously on the list of methods given.
 LE getEndResults(MethodDeclaration d)
          Gets the lattice results at the end of a method.
 IResult<LE> getLabeledEndResult(MethodDeclaration d)
          Gets the lattice results at the end of a method.
 IResult<LE> getLabeledResultsAfter(ASTNode node)
          Retrieves the analysis state that exists after analyzing the node in the control flow graph.
 IResult<LE> getLabeledResultsBefore(ASTNode node)
          Retrieves the analysis state that exists before analyzing the node in the control flow graph.
 IResult<LE> getLabeledStartResult(MethodDeclaration d)
          Gets the lattice results at the start of a method.
 LE getResultsAfter(ASTNode node)
          Deprecated. 
 LE getResultsAfterAST(ASTNode node)
          Retrieves the analysis state that exists after analyzing the node in the abstract syntax tree.
 LE getResultsAfterCFG(ASTNode node)
          Retrieves the analysis state that exists after analyzing the node in the control flow graph.
 LE getResultsBefore(ASTNode node)
          Deprecated. 
 LE getResultsBeforeAST(ASTNode node)
          Retrieves the analysis state that exists before analyzing the node in the abstract syntax tree.
 LE getResultsBeforeCFG(ASTNode node)
          Retrieves the analysis state that exists before analyzing the node in the control flow graph.
 LE getStartResults(MethodDeclaration d)
          Gets the lattice results at the start of a method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentFlowAnalysis

public ConcurrentFlowAnalysis(ITransferFunction<LE> transferFunction,
                              List<MethodDeclaration> methods,
                              Crystal crystal)
Creates a new concurrent flow analysis and begins to analyze the given method bodies immediately.

Parameters:
transferFunction - The transfer function defining the analysis.
methods - Starts analyzing these methods immediately in background threads.
crystal -

ConcurrentFlowAnalysis

public ConcurrentFlowAnalysis(ITransferFunction<LE> transferFunction,
                              Crystal crystal)
Creates a new concurrent flow analysis but does not analyze any methods immediately.

Parameters:
transferFunction -
crystal -
See Also:
analyzePreemitively(java.util.List)
Method Detail

analyzePreemitively

public void analyzePreemitively(List<MethodDeclaration> methods)
Perform dataflow analysis asynchronously on the list of methods given. This method should return relatively quickly, but analysis will be performed in another thread. If you have already called the constructor that takes a list of methods, calling this method is not required unless you have added new methods to analyze.

Parameters:
methods -

getLabeledResultsAfter

public IResult<LE> getLabeledResultsAfter(ASTNode node)
Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists after analyzing the node in the control flow graph. Works like IFlowAnalysis.getResultsAfterCFG(ASTNode), except it keeps all the labels separated in an IResult.

Specified by:
getLabeledResultsAfter in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the IResult that represents the analysis state after analyzing the corresponding node in the control flow graph, separated for each incoming edge. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsAfterCFG(ASTNode)

getLabeledResultsBefore

public IResult<LE> getLabeledResultsBefore(ASTNode node)
Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists before analyzing the node in the control flow graph. Works like IFlowAnalysis.getResultsBeforeCFG(ASTNode), except it keeps all the labels separated in an IResult.

Specified by:
getLabeledResultsBefore in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the IResult that represents the analysis state before analyzing the corresponding node in the control flow graph, separated for each incoming edge. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsBeforeCFG(ASTNode)

getResultsAfter

@Deprecated
public LE getResultsAfter(ASTNode node)
Deprecated. 

Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists after analyzing the node, including bottom. After is respective to normal program flow and not the direction of the analysis.

Specified by:
getResultsAfter in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the lattice that represents the analysis state before analyzing the node. Will be bottom if the node doesn't have a corresponding control flow node.

getResultsBefore

@Deprecated
public LE getResultsBefore(ASTNode node)
Deprecated. 

Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists before analyzing the node, including bottom. Before is respective to normal program flow and not the direction of the analysis.

Specified by:
getResultsBefore in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the lattice that represents the analysis state before analyzing the node. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsBeforeCFG(ASTNode)

getResultsAfterCFG

public LE getResultsAfterCFG(ASTNode node)
Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists after analyzing the node in the control flow graph. After is respective to normal program flow and not the direction of the analysis. When called on an node, this returns the lattice that occurs after this node is evaluated, but after all sub-node are evaluated. In particular, calling this on a while node will return results after the while node is evaluated, but not after the entire statement in the AST For most expressions, this returns the same result as IFlowAnalysis.getResultsAfterAST(ASTNode) If there are multiple before lattices for this node, they are joined and returned.

Specified by:
getResultsAfterCFG in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the lattice that represents the analysis state before analyzing the corresponding node in the control flow graph. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsAfterAST(ASTNode), IFlowAnalysis.getLabeledResultsAfter(ASTNode)

getResultsBeforeCFG

public LE getResultsBeforeCFG(ASTNode node)
Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists before analyzing the node in the control flow graph. Before is respective to normal program flow and not the direction of the analysis. When called on an expression, this returns the lattice that occurs before this expression is evaluated, but after all sub-expressions are evaluated. For example, when called on an assignment, it returns the lattice after the left and right sub-expressions are evaluated, but before the assignment itself takes place. If there are multiple before lattices for this node, they are joined and returned.

Specified by:
getResultsBeforeCFG in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the lattice that represents the analysis state before analyzing the corresponding node in the control flow graph. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsBeforeAST(ASTNode), IFlowAnalysis.getLabeledResultsBefore(ASTNode)

getResultsBeforeAST

public LE getResultsBeforeAST(ASTNode node)
Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists before analyzing the node in the abstract syntax tree. Before is respective to normal program flow and not the direction of the analysis. When called on an expression, this returns the lattice that occurs before all sub-expressions are evaluated. For example, when called on an assignment, it returns the lattice before either the left or right sub-expressions are evaluated. If there are multiple before lattices for this node, they are joined and returned.

Specified by:
getResultsBeforeAST in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the lattice that represents the analysis state before analyzing any node contained by the given node in the abstract syntax tree. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsBeforeCFG(ASTNode)

getResultsAfterAST

public LE getResultsAfterAST(ASTNode node)
Description copied from interface: IFlowAnalysis
Retrieves the analysis state that exists after analyzing the node in the abstract syntax tree. After is respective to normal program flow and not the direction of the analysis. When called on an node, this returns the lattice that occurs after this node and all sub-nodes are evaluated. In particular, calling this on a while node will return results after the entire while statement (including all sub-expressions) is evaluated. For most expressions, this returns the same result as IFlowAnalysis.getResultsAfterCFG(ASTNode) If there are multiple before lattices for this node, they are joined and returned.

Specified by:
getResultsAfterAST in interface IFlowAnalysis<LE>
Parameters:
node - the ASTNode of interest
Returns:
the lattice that represents the analysis state after analyzing any node contained by the given node in the abstract syntax tree. Will be bottom if the node doesn't have a corresponding control flow node.
See Also:
IFlowAnalysis.getResultsAfterCFG(ASTNode)

getEndResults

public LE getEndResults(MethodDeclaration d)
Description copied from interface: IFlowAnalysis
Gets the lattice results at the end of a method. This will join all possible exits from a method, including explicit returns, the default return, and exceptional exits.

Specified by:
getEndResults in interface IFlowAnalysis<LE>
Parameters:
d - The method declaration to get results for
Returns:
The lattice results at the end of the method.

getLabeledEndResult

public IResult<LE> getLabeledEndResult(MethodDeclaration d)
Description copied from interface: IFlowAnalysis
Gets the lattice results at the end of a method. This method should be used when the caller wants to access different possible ending results, such as exceptional exits v. normal returns.

Specified by:
getLabeledEndResult in interface IFlowAnalysis<LE>
Returns:
The analysis results at the end of the method.
See Also:
IFlowAnalysis.getEndResults(MethodDeclaration)

getLabeledStartResult

public IResult<LE> getLabeledStartResult(MethodDeclaration d)
Description copied from interface: IFlowAnalysis
Gets the lattice results at the start of a method. Theoretically, this will be the same as IFlowAnalysis.getStartResults(MethodDeclaration) and IFlowAnalysisDefinition.createEntryValue(MethodDeclaration). However, it might be different for a system which keeps multiple possible contexts in which the method could be called from based on some specifications.

Specified by:
getLabeledStartResult in interface IFlowAnalysis<LE>
Returns:
The analysis results at the beginning of the method, separated by incoming edge.
See Also:
IFlowAnalysisDefinition.createEntryValue(MethodDeclaration), IFlowAnalysis.getStartResults(MethodDeclaration)

getStartResults

public LE getStartResults(MethodDeclaration d)
Description copied from interface: IFlowAnalysis
Gets the lattice results at the start of a method. This will probably be the same as the results from calling IFlowAnalysisDefinition.createEntryValue(MethodDeclaration)

Specified by:
getStartResults in interface IFlowAnalysis<LE>
Parameters:
d - The method declaration to get results for
Returns:
The lattice results at the beginning of the method.
See Also:
IFlowAnalysisDefinition.createEntryValue(MethodDeclaration)