Class ClassContext


  • public class ClassContext
    extends java.lang.Object
    A ClassContext caches all of the auxiliary objects used to analyze the methods of a class. That way, these objects don't need to be created over and over again.
    Author:
    David Hovemeyer
    • Field Detail

      • DEBUG

        public static final boolean DEBUG
      • TIME_ANALYSES

        public static final boolean TIME_ANALYSES
      • DUMP_DATAFLOW_ANALYSIS

        public static final boolean DUMP_DATAFLOW_ANALYSIS
    • Constructor Detail

      • ClassContext

        public ClassContext​(org.apache.bcel.classfile.JavaClass jclass,
                            AnalysisContext analysisContext)
        Constructor.
        Parameters:
        jclass - the JavaClass
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getObjectMap

        public java.util.Map<MethodDescriptor,​java.lang.Object> getObjectMap​(java.lang.Class<?> analysisClass)
      • putMethodAnalysis

        public void putMethodAnalysis​(java.lang.Class<?> analysisClass,
                                      MethodDescriptor methodDescriptor,
                                      java.lang.Object object)
        Store a method analysis object. Note that the cached analysis object could be a special value (indicating null or an exception).
        Parameters:
        analysisClass - class the method analysis object belongs to
        methodDescriptor - method descriptor identifying the analyzed method
        object - the analysis object to cache
      • getMethodAnalysis

        public java.lang.Object getMethodAnalysis​(java.lang.Class<?> analysisClass,
                                                  MethodDescriptor methodDescriptor)
        Retrieve a method analysis object.
        Parameters:
        analysisClass - class the method analysis object should belong to
        methodDescriptor - method descriptor identifying the analyzed method
        Returns:
        the analysis object
      • purgeAllMethodAnalyses

        public void purgeAllMethodAnalyses()
      • purgeMethodAnalyses

        public void purgeMethodAnalyses​(MethodDescriptor methodDescriptor)
        Purge all CFG-based method analyses for given method.
        Parameters:
        methodDescriptor - method descriptor identifying method to purge
      • getJavaClass

        public org.apache.bcel.classfile.JavaClass getJavaClass()
        Get the JavaClass.
      • getXClass

        public XClass getXClass()
      • getMethod

        public org.apache.bcel.classfile.Method getMethod​(org.apache.bcel.generic.MethodGen methodGen)
        Look up the Method represented by given MethodGen.
        Parameters:
        methodGen - a MethodGen
        Returns:
        the Method represented by the MethodGen
      • getFullyQualifiedMethodName

        public java.lang.String getFullyQualifiedMethodName​(org.apache.bcel.classfile.Method method)
      • getMethodsInCallOrder

        @Nonnull
        public java.util.List<org.apache.bcel.classfile.Method> getMethodsInCallOrder()
      • getAnalysisContext

        public AnalysisContext getAnalysisContext()
        Get the AnalysisContext.
      • getLookupFailureCallback

        public RepositoryLookupFailureCallback getLookupFailureCallback()
        Get the RepositoryLookupFailureCallback.
        Returns:
        the RepositoryLookupFailureCallback
      • getMethodGen

        @CheckForNull
        public org.apache.bcel.generic.MethodGen getMethodGen​(org.apache.bcel.classfile.Method method)
        Get a MethodGen object for given method.
        Parameters:
        method - the method
        Returns:
        the MethodGen object for the method, or null if the method has no Code attribute (and thus cannot be analyzed) or if the method seems unprofitable to analyze
      • getCFG

        public CFG getCFG​(org.apache.bcel.classfile.Method method)
                   throws CFGBuilderException
        Get a CFG for given method. If pruning options are in effect, pruning will be done. Because the CFG pruning can involve interprocedural analysis, it is done on a best-effort basis, so the CFG returned might not actually be pruned.
        Parameters:
        method - the method
        Returns:
        the CFG
        Throws:
        CFGBuilderException - if a CFG cannot be constructed for the method
      • getConstantPoolGen

        @Nonnull
        public org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
        Get the ConstantPoolGen used to create the MethodGens for this class.
        Returns:
        the ConstantPoolGen
      • getDepthFirstSearch

        public DepthFirstSearch getDepthFirstSearch​(org.apache.bcel.classfile.Method method)
                                             throws CFGBuilderException
        Get a DepthFirstSearch for given method.
        Parameters:
        method - the method
        Returns:
        the DepthFirstSearch
        Throws:
        CFGBuilderException
      • getReverseDepthFirstSearch

        public ReverseDepthFirstSearch getReverseDepthFirstSearch​(org.apache.bcel.classfile.Method method)
                                                           throws CFGBuilderException
        Get a ReverseDepthFirstSearch for given method.
        Parameters:
        method - the method
        Returns:
        the ReverseDepthFirstSearch
        Throws:
        CFGBuilderException
      • getBytecodeSet

        @CheckForNull
        public java.util.BitSet getBytecodeSet​(org.apache.bcel.classfile.Method method)
        Get a BitSet representing the bytecodes that are used in the given method. This is useful for prescreening a method for the existence of particular instructions. Because this step doesn't require building a MethodGen, it is very fast and memory-efficient. It may allow a Detector to avoid some very expensive analysis, which is a Big Win for the user.
        Parameters:
        method - the method
        Returns:
        the BitSet containing the opcodes which appear in the method, or null if the method has no code
      • getBytecodeSet

        @CheckForNull
        public static java.util.BitSet getBytecodeSet​(org.apache.bcel.classfile.JavaClass clazz,
                                                      org.apache.bcel.classfile.Method method)
        Get a BitSet representing the bytecodes that are used in the given method. This is useful for prescreening a method for the existence of particular instructions. Because this step doesn't require building a MethodGen, it is very fast and memory-efficient. It may allow a Detector to avoid some very expensive analysis, which is a Big Win for the user.
        Parameters:
        method - the method
        Returns:
        the BitSet containing the opcodes which appear in the method, or null if the method has no code
      • getLoopExitBranches

        @Nonnull
        public static java.util.Set<java.lang.Integer> getLoopExitBranches​(org.apache.bcel.classfile.Method method,
                                                                           org.apache.bcel.generic.MethodGen methodGen)
      • getOffsetToOpcodeMap

        @Nonnull
        public short[] getOffsetToOpcodeMap​(org.apache.bcel.classfile.Method method)
        Get array mapping bytecode offsets to opcodes for given method. Array elements containing zero are either not valid instruction offsets, or contain a NOP instruction. (It is convenient not to distinguish these cases.)
        Parameters:
        method - the method
        Returns:
        map of bytecode offsets to opcodes, empty if the method has no code
      • getExceptionSetFactory

        public ExceptionSetFactory getExceptionSetFactory​(org.apache.bcel.classfile.Method method)
        Get ExceptionSetFactory for given method.
        Parameters:
        method - the method
        Returns:
        the ExceptionSetFactory
      • getParameterSignatureList

        public java.lang.String[] getParameterSignatureList​(org.apache.bcel.classfile.Method method)
        Get array of type signatures of parameters for given method.
        Parameters:
        method - the method
        Returns:
        an array of type signatures indicating the types of the method's parameters
      • getLoadedFieldSet

        public LoadedFieldSet getLoadedFieldSet​(org.apache.bcel.classfile.Method method)
        Get the set of fields loaded by given method.
        Parameters:
        method - the method
        Returns:
        the set of fields loaded by the method
      • getAssertionMethods

        public AssertionMethods getAssertionMethods()
        Get AssertionMethods for class.
        Returns:
        the AssertionMethods
      • linesMentionedMultipleTimes

        public java.util.BitSet linesMentionedMultipleTimes​(org.apache.bcel.classfile.Method method)
      • getCompactLocationNumbering

        public CompactLocationNumbering getCompactLocationNumbering​(org.apache.bcel.classfile.Method method)
                                                             throws CFGBuilderException
        Get a CompactLocationNumbering for a method.
        Parameters:
        method - a method
        Returns:
        the CompactLocationNumbering for the method
        Throws:
        CFGBuilderException
      • dumpSimpleDataflowInformation

        public void dumpSimpleDataflowInformation​(org.apache.bcel.classfile.Method method)
      • dumpDataflowInformation

        public void dumpDataflowInformation​(org.apache.bcel.classfile.Method method)