/** * Accounts the bytecode size of analyzed method for statistics. * * @param mtd Analyzed method. */ private static void accountCodeBytes(IMethod mtd) { // Get method bytecode size if (mtd instanceof ShrikeCTMethod) { analyzedBytes += ((ShrikeCTMethod) mtd).getBytecodes().length; } }
/** * Checks if all parameters and return value of a method have primitive types. * * @param mtd Method. * @return boolean True if all parameters and return value are of primitive type, otherwise false. */ private static boolean isAllPrimitiveTypes(IMethod mtd) { if (!mtd.getReturnType().isPrimitiveType()) return false; for (int i = (mtd.isStatic() ? 0 : 1); i < mtd.getNumberOfParameters(); i++) { if (!mtd.getParameterType(i).isPrimitiveType()) return false; } return true; }
/** * Get astubx style method signature. {FullyQualifiedEnclosingType}: {UnqualifiedMethodReturnType} * {methodName} ([{UnqualifiedArgumentType}*]) * * @param mtd Method reference. * @return String Method signature. */ // TODO: handle generics and inner classes private static String getSignature(IMethod mtd) { String classType = mtd.getDeclaringClass().getName().toString().replaceAll("/", "\\.").substring(1); classType = classType.replaceAll("\\$", "\\."); // handle inner class String returnType = mtd.isInit() ? null : getSimpleTypeName(mtd.getReturnType()); String strArgTypes = ""; int argi = mtd.isStatic() ? 0 : 1; // Skip 'this' parameter for (; argi < mtd.getNumberOfParameters(); argi++) { strArgTypes += getSimpleTypeName(mtd.getParameterType(argi)); if (argi < mtd.getNumberOfParameters() - 1) strArgTypes += ", "; } return classType + ":" + (returnType == null ? "void " : returnType + " ") + mtd.getName().toString() + "(" + strArgTypes + ")"; } /**
if (!cldr.getName().toString().equals("Primordial")) { for (IClass cls : Iterator2Iterable.make(cldr.iterateAllClasses())) { if (cls instanceof PhantomClass) continue; if (!pkgName.isEmpty() && !cls.getName().toString().startsWith(pkgName)) continue; LOG(DEBUG, "DEBUG", "analyzing class: " + cls.getName().toString()); for (IMethod mtd : Iterator2Iterable.make(cls.getDeclaredMethods().iterator())) { if (!mtd.isPrivate() && !mtd.isAbstract() && !mtd.isNative() && !isAllPrimitiveTypes(mtd) && !mtd.getDeclaringClass() .getClassLoader() .getName() .toString() .equals("Primordial")) { if (mtd.getNumberOfParameters() > (mtd.isStatic() ? 0 : 1)) { if (!CodeScanner.getFieldsRead(mtd).isEmpty() || !CodeScanner.getFieldsWritten(mtd).isEmpty() || !CodeScanner.getCallSites(mtd).isEmpty()) { if (analysisDriver == null) { analysisDriver = getAnalysisDriver(mtd, options, cache, cha); if (!mtd.getReturnType().isPrimitiveType()) { if (analysisDriver == null) { analysisDriver = getAnalysisDriver(mtd, options, cache, cha);
protected ModVisitor<T, ? extends ExtendedHeapModel> makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) { return n.getMethod().getDeclaringClass().getClassLoader().getLanguage().makeModVisitor(n, result, pa, h, ignoreAllocHeapDefs); //return new ModVisitor<>(n, result, h, pa, ignoreAllocHeapDefs); }
private static IMethod getPublicDefaultCtor(IClass klass) { IMethod ctorMethod = klass.getMethod(defCtorSelector); if (ctorMethod != null && ctorMethod.isPublic() && ctorMethod.getDeclaringClass() == klass) { return ctorMethod; } return null; }
/** * Create an {@link InducedCFG} from an instruction array. * * NOTE: SIDE EFFECT!!! ... nulls out phi instructions in the instruction array! */ public InducedCFG makeControlFlowGraph(SSAInstruction[] instructions) { return this.getDeclaringClass().getClassLoader().getLanguage().makeInducedCFG(instructions, this, Everywhere.EVERYWHERE); }
LOG(DEBUG, "DEBUG", "@ " + method.getSignature()); Set<Integer> derefedParamList = new HashSet<Integer>(); prunedCFG = ExceptionPrunedCFG.make(cfg); method.isStatic() ? 1 : 2; // 1-indexed; v1 is 'this' for non-static methods LOG(DEBUG, "DEBUG", "param value numbers : " + firstParamIndex + " ... " + numParam); while (!nodeQueue.isEmpty()) {
if (method.getReturnType().isPrimitiveType()) { LOG(DEBUG, "DEBUG", "Skipping method with primitive return type: " + method.getSignature()); return NullnessHint.UNKNOWN; LOG(DEBUG, "DEBUG", "@ Return type analysis for: " + method.getSignature()); SSAReturnInstruction retInstr = (SSAReturnInstruction) instr; if (ir.getSymbolTable().isNullConstant(retInstr.getResult())) { LOG(DEBUG, "DEBUG", "Nullable return in method: " + method.getSignature()); return NullnessHint.NULLABLE;
@Override public Collection<TypeReference> getExceptionTypes() { if (typeIsPrimitive()) { return getArrayAccessExceptions(); } else { return getAaStoreExceptions(); } } };
@Override public SSAInstructionFactory getInstructionFactory() { return getLanguage().instructionFactory(); } }
protected ModVisitor<T, ? extends ExtendedHeapModel> makeModVisitor(CGNode n, Collection<PointerKey> result, PointerAnalysis<T> pa, ExtendedHeapModel h, boolean ignoreAllocHeapDefs) { return n.getMethod().getDeclaringClass().getClassLoader().getLanguage().makeModVisitor(n, result, pa, h, ignoreAllocHeapDefs); //return new ModVisitor<>(n, result, h, pa, ignoreAllocHeapDefs); }
private static IMethod getPublicDefaultCtor(IClass klass) { IMethod ctorMethod = klass.getMethod(defCtorSelector); if (ctorMethod != null && ctorMethod.isPublic() && ctorMethod.getDeclaringClass() == klass) { return ctorMethod; } return null; }
/** * Create an {@link InducedCFG} from an instruction array. * * NOTE: SIDE EFFECT!!! ... nulls out phi instructions in the instruction array! */ public InducedCFG makeControlFlowGraph(SSAInstruction[] instructions) { return this.getDeclaringClass().getClassLoader().getLanguage().makeInducedCFG(instructions, this, Everywhere.EVERYWHERE); }
@Override public Collection<TypeReference> getExceptionTypes() { if (typeIsPrimitive()) { return getArrayAccessExceptions(); } else { return getAaStoreExceptions(); } } };
@Override public SSAInstructionFactory getInstructionFactory() { return getLanguage().instructionFactory(); } }