private static String getFullMethodName(MethodGen methodGen) { String methodNameWithSignature = methodGen.getName() + methodGen.getSignature(); String slashedClassName = methodGen.getClassName().replace('.', '/'); return slashedClassName + "." + methodNameWithSignature; }
public static void dumpTypeDataflow(Method method, CFG cfg, TypeDataflow typeDataflow) throws DataflowAnalysisException { System.out.println("\n\n{ Type analysis for " + cfg.getMethodGen().getClassName() + "." + method.getName() + method.getSignature()); TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc); } for (Location loc : tree) { System.out.println("\n Pre: " + typeDataflow.getFactAtLocation(loc)); System.out.println("Location: " + loc); System.out.println("Post: " + typeDataflow.getFactAfterLocation(loc)); } System.out.println("}\n\n"); }
@Override public String toString() { return this.getClass().getSimpleName() + "(" + methodGen.getClassName() + "." + methodGen.getMethod().getName() + methodGen.getMethod().getSignature() + ")"; }
/** * Constructor. * * @param rdfs * the reverse depth-first-search (for the block order) * @param cfg * the CFG for the method * @param methodGen * the MethodGen for the method * @param vnaDataflow * @param assertionMethods * AssertionMethods for the analyzed class */ public UnconditionalValueDerefAnalysis(ReverseDepthFirstSearch rdfs, DepthFirstSearch dfs, CFG cfg, Method method, MethodGen methodGen, ValueNumberDataflow vnaDataflow, AssertionMethods assertionMethods) { super(rdfs, dfs); this.cfg = cfg; this.methodGen = methodGen; this.method = method; this.vnaDataflow = vnaDataflow; this.assertionMethods = assertionMethods; if (DEBUG) { System.out.println("UnconditionalValueDerefAnalysis analysis " + methodGen.getClassName() + "." + methodGen.getName() + " : " + methodGen.getSignature()); } }
private void lockOp(LockSet fact, int lockNumber, int delta) { int value = fact.getLockCount(lockNumber); if (value < 0) { return; } value += delta; if (value < 0) { value = LockSet.BOTTOM; } if (DEBUG) { System.out.println("Setting " + lockNumber + " to " + value + " in " + methodGen.getClassName() + "." + methodGen.getName()); } fact.setLockCount(lockNumber, value); }
/** * Convenience method for generating a method signature in human readable * form. * * @param methodGen * the method to produce a method signature for */ public static String convertMethodSignature(MethodGen methodGen) { return convertMethodSignature(methodGen.getClassName(), methodGen.getName(), methodGen.getSignature()); }
public LockAnalysis(MethodGen methodGen, ValueNumberDataflow vnaDataflow, DepthFirstSearch dfs) { super(dfs); this.methodGen = methodGen; this.vnaDataflow = vnaDataflow; this.vna = vnaDataflow.getAnalysis(); this.isSynchronized = methodGen.isSynchronized(); this.isStatic = methodGen.isStatic(); if (DEBUG) { System.out.println("Analyzing Locks in " + methodGen.getClassName() + "." + methodGen.getName()); } }
/** * Add class and method annotations for given method. * * @param methodGen * the method * @param sourceFile * source file the method is defined in * @return this object */ @Nonnull public BugInstance addClassAndMethod(MethodGen methodGen, String sourceFile) { addClass(methodGen.getClassName()); addMethod(methodGen, sourceFile); if (!MemberUtils.isUserGenerated(methodGen)) { foundInAutogeneratedMethod(); } return this; }
public static XMethod createXMethod(MethodGen methodGen) { String className = methodGen.getClassName(); String methodName = methodGen.getName(); String methodSig = methodGen.getSignature(); int accessFlags = methodGen.getAccessFlags(); return createXMethod(className, methodName, methodSig, accessFlags); }
/** * Constructor. * * @param method * TODO * @param methodGen * the MethodGen whose CFG we'll be analyzing * @param cfg * the control flow graph * @param dfs * DepthFirstSearch of the method * @param typeMerger * object to merge types * @param lookupFailureCallback * lookup failure callback * @param exceptionSetFactory * factory for creating ExceptionSet objects */ public TypeAnalysis(Method method, MethodGen methodGen, CFG cfg, DepthFirstSearch dfs, TypeMerger typeMerger, RepositoryLookupFailureCallback lookupFailureCallback, ExceptionSetFactory exceptionSetFactory) { this(method, methodGen, cfg, dfs, typeMerger, new TypeFrameModelingVisitor(methodGen.getConstantPool(), typeMerger), lookupFailureCallback, exceptionSetFactory); if (TypeFrameModelingVisitor.DEBUG) { System.out.println(methodGen.getClassName() + "." + methodGen.getName() + " " + methodGen.getSignature()); } }
public ValueNumberAnalysis(MethodGen methodGen, DepthFirstSearch dfs, LoadedFieldSet loadedFieldSet, RepositoryLookupFailureCallback lookupFailureCallback) { super(dfs); this.methodGen = methodGen; this.factory = new ValueNumberFactory(); ValueNumberCache cache = new ValueNumberCache(); this.visitor = new ValueNumberFrameModelingVisitor(methodGen, factory, cache, loadedFieldSet, lookupFailureCallback); int numLocals = methodGen.getMaxLocals(); this.entryLocalValueList = new ValueNumber[numLocals]; for (int i = 0; i < numLocals; ++i) { this.entryLocalValueList[i] = factory.createFreshValue(); } this.exceptionHandlerValueNumberMap = new IdentityHashMap<>(); // For non-static methods, keep track of which value represents the // "this" reference if (!methodGen.isStatic()) { this.thisValue = entryLocalValueList[0]; } this.factAtLocationMap = new HashMap<>(); this.factAfterLocationMap = new HashMap<>(); if (DEBUG) { System.out.println("VNA Analysis " + methodGen.getClassName() + "." + methodGen.getName() + " : " + methodGen.getSignature()); } }
public IsNullValueAnalysis(MethodDescriptor descriptor, MethodGen methodGen, CFG cfg, ValueNumberDataflow vnaDataflow, TypeDataflow typeDataflow, DepthFirstSearch dfs, AssertionMethods assertionMethods) { super(dfs); this.trackValueNumbers = AnalysisContext.currentAnalysisContext().getBoolProperty( AnalysisFeatures.TRACK_VALUE_NUMBERS_IN_NULL_POINTER_ANALYSIS); this.methodGen = methodGen; this.visitor = new IsNullValueFrameModelingVisitor(methodGen.getConstantPool(), assertionMethods, vnaDataflow, typeDataflow, trackValueNumbers); this.vnaDataflow = vnaDataflow; this.cfg = cfg; this.locationWhereValueBecomesNullSet = new HashSet<>(); this.pointerEqualityCheck = getForPointerEqualityCheck(cfg, vnaDataflow); if (DEBUG) { System.out.println("IsNullValueAnalysis for " + methodGen.getClassName() + "." + methodGen.getName() + " : " + methodGen.getSignature()); } }
/** * Factory method for creating a source line annotation describing the * source line number for a visited instruction. * * @param classContext * the ClassContext * @param methodGen * the MethodGen object representing the method * @param handle * the InstructionHandle containing the visited instruction * @return the SourceLineAnnotation, or null if we do not have line number * information for the instruction */ @Nonnull public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, MethodGen methodGen, String sourceFile, @Nonnull InstructionHandle handle) { LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); int bytecodeOffset = handle.getPosition(); if (table == null) { return createUnknown(className, sourceFile, bytecodeOffset, bytecodeOffset); } int lineNumber = table.getSourceLine(handle.getPosition()); return new SourceLineAnnotation(className, sourceFile, lineNumber, lineNumber, bytecodeOffset, bytecodeOffset); }
/** * Add a method annotation. If this is the first method annotation added, it * becomes the primary method annotation. If the method has source line * information, then a SourceLineAnnotation is added to the method. * * @param methodGen * the MethodGen object for the method * @param sourceFile * source file method is defined in * @return this object */ @Nonnull public BugInstance addMethod(MethodGen methodGen, String sourceFile) { String className = methodGen.getClassName(); MethodAnnotation methodAnnotation = new MethodAnnotation(className, methodGen.getName(), methodGen.getSignature(), methodGen.isStatic()); addMethod(methodAnnotation); addSourceLinesForMethod(methodAnnotation, SourceLineAnnotation.fromVisitedMethod(methodGen, sourceFile)); return this; }
/** * Factory method for creating a source line annotation describing an entire * method. * * @param methodGen * the method being visited * @return the SourceLineAnnotation, or null if we do not have line number * information for the method */ public static SourceLineAnnotation fromVisitedMethod(MethodGen methodGen, String sourceFile) { LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); int codeSize = methodGen.getInstructionList().getLength(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, 0, codeSize - 1); } return forEntireMethod(className, sourceFile, lineNumberTable, codeSize); }
@Override public void initEntryFact(LockSet result) { result.clear(); result.setDefaultLockCount(0); if (isSynchronized && !isStatic) { ValueNumber thisValue = vna.getThisValue(); result.setLockCount(thisValue.getNumber(), 1); } else if (isSynchronized && isStatic) { ValueNumber thisValue = vna.getClassObjectValue(methodGen.getClassName()); result.setLockCount(thisValue.getNumber(), 1); } }
AnalysisContext.logError("Exception while analyzing " + methodGen.getClassName() + "." + methodGen.getName() + ":" + methodGen.getSignature(), e);
throw new IllegalStateException("No basic block for thrower " + handle + " in " + this.methodGen.getClassName() + "." + this.methodName + " : " + this.methodGen.getSignature());
/** * Factory method for creating a source line annotation describing the * source line numbers for a range of instruction in a method. * * @param classContext * theClassContext * @param methodGen * the method * @param start * the start instruction * @param end * the end instruction (inclusive) */ public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) { LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, start.getPosition(), end.getPosition()); } int startLine = lineNumberTable.getSourceLine(start.getPosition()); int endLine = lineNumberTable.getSourceLine(end.getPosition()); return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition()); }
XMethod xm = XFactory.createXMethod(methodGen.getClassName(), methodGen.getName(), methodGen.getSignature(), methodGen.isStatic()); INullnessAnnotationDatabase db = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();