com.ibm.wala.ipa.callgraph.CallGraph Java Examples

The following examples show how to use com.ibm.wala.ipa.callgraph.CallGraph. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CallGraphConstructor.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Create a call graph instance given a class path.
 *
 * @param classpath Path to class or jar file
 * @return Call Graph
 */
public static CallGraph generateCallGraph(final String classpath)
        throws IOException, ClassHierarchyException, CallGraphBuilderCancelException {
    final var classLoader = Thread.currentThread().getContextClassLoader();
    final var exclusionFile = new File(Objects.requireNonNull(classLoader
            .getResource("Java60RegressionExclusions.txt")).getFile());

    final var scope = AnalysisScopeReader
            .makeJavaBinaryAnalysisScope(classpath, exclusionFile);

    final var cha = ClassHierarchyFactory.makeWithRoot(scope);

    final var entryPointsGenerator = new EntryPointsGenerator(cha);
    final var entryPoints = entryPointsGenerator.getEntryPoints();
    final var options = new AnalysisOptions(scope, entryPoints);
    final var cache = new AnalysisCacheImpl();

    final var builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope);

    return builder.makeCallGraph(options, null);
}
 
Example #2
Source File: WalaResultAnalyzer.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Convert raw Wala call graph to {@link PartialCallGraph}.
 *
 * @param rawCallGraph Raw call graph in Wala format
 * @return Partial call graph
 */
public static PartialCallGraph wrap(final CallGraph rawCallGraph) throws NullPointerException {
    final NumberFormat timeFormatter = new DecimalFormat("#0.000");
    logger.info("Wrapping call graph with {} nodes...", rawCallGraph.getNumberOfNodes());
    final long startTime = System.currentTimeMillis();

    final var walaResultAnalyzer = new WalaResultAnalyzer(rawCallGraph);
    final var analysisContext = new AnalysisContext(rawCallGraph.getClassHierarchy());
    final var classHierarchyAnalyzer =
            new ClassHierarchyAnalyzer(walaResultAnalyzer.rawCallGraph,
                    walaResultAnalyzer.partialCallGraph, analysisContext);
    classHierarchyAnalyzer.resolveCHA();

    final var callGraphAnalyzer = new CallGraphAnalyzer(walaResultAnalyzer.rawCallGraph,
            walaResultAnalyzer.partialCallGraph, analysisContext);
    callGraphAnalyzer.resolveCalls();

    logger.info("Wrapped call graph in {} seconds [Internal calls: {}, External calls: {}]",
            timeFormatter.format((System.currentTimeMillis() - startTime) / 1000d),
            walaResultAnalyzer.partialCallGraph.getInternalCalls().size(),
            walaResultAnalyzer.partialCallGraph.getExternalCalls().size());

    return walaResultAnalyzer.partialCallGraph;
}
 
Example #3
Source File: WalaUtils.java    From LibScout with Apache License 2.0 6 votes vote down vote up
public static CGNode getCGNode(IMethod method, CallGraph cg) {
	logger.debug("Retrieve CGNode for " + method.getSignature());

	MethodReference ref = method.getReference();
	if (ref == null) return null;

	Set<CGNode> cgnode = cg.getNodes(ref);
	if (cgnode.isEmpty()) {
		logger.warn("Number of CGNode(s) for " + method.getSignature() + " is " + cgnode.size());
		return null;
	}
	/*else if (cgnode.size() > 1) {
		logger.warn("Number of CGNode(s) for " + methodSignature + " is " + cgnode.size() +  "  refMethod.sig: " + refMethod.getSignature());
	}*/
					
	return cgnode.iterator().next();
}
 
Example #4
Source File: WalaUtils.java    From LibScout with Apache License 2.0 6 votes vote down vote up
public static SSAInstruction getSSAInstruction(CallGraph cg, String methodSignature, int iindex) {
	SSACFG cfg = getSSACFG(methodSignature, cg);
	if (cfg == null) {
		logger.warn("getSSAInstruction:: Did not find SSACFG for " + methodSignature);			
	} else {
		BasicBlock block = cfg.getBlockForInstruction(iindex);
		if (block != null) {
			for (Iterator<SSAInstruction> it = block.iterateNormalInstructions(); it.hasNext();) {
				SSAInstruction ins = it.next();
				if (ins.iindex == iindex) {
					return ins;
				}
			}
			logger.warn("getSSAInstruction:: Did not find iindex " + iindex + " in SSACFG (" + methodSignature + ")");
		} else
			logger.warn("getSSAInstruction:: Did not find basic block for iindex " + iindex + " in SSACFG (" + methodSignature + ")");
	}
	return null;
}
 
Example #5
Source File: ClassHierarchyAnalyzer.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Construct class hierarchy analyzer.
 *
 * @param rawCallGraph     Call graph in Wala format
 * @param partialCallGraph Partial call graph
 */
public ClassHierarchyAnalyzer(final CallGraph rawCallGraph,
                              final PartialCallGraph partialCallGraph,
                              final AnalysisContext analysisContext) {
    this.rawCallGraph = rawCallGraph;
    this.partialCallGraph = partialCallGraph;
    this.analysisContext = analysisContext;
    this.counter = 0;
}
 
Example #6
Source File: CallGraphAnalyzer.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Analyze raw call graph in Wala format.
 *
 * @param rawCallGraph     Raw call graph in Wala format
 * @param partialCallGraph Partial call graph
 */
public CallGraphAnalyzer(final CallGraph rawCallGraph,
                         final PartialCallGraph partialCallGraph,
                         final AnalysisContext analysisContext) {
    this.rawCallGraph = rawCallGraph;
    this.partialCallGraph = partialCallGraph;
    this.analysisContext = analysisContext;
    this.classHierarchyAnalyzer =
            new ClassHierarchyAnalyzer(rawCallGraph, partialCallGraph, analysisContext);
}
 
Example #7
Source File: WalaUtils.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public static CGNode getCGNode(String methodSignature, CallGraph cg) {
	logger.debug("Retrieve CGNode for " + methodSignature);

	IMethod refMethod = getIMethod(cg.getClassHierarchy(), methodSignature);
	if (refMethod == null) return null;

	return getCGNode(refMethod, cg);
}
 
Example #8
Source File: WalaUtils.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public static SSACFG getSSACFG(String methodSignature, CallGraph cg) {
	logger.debug("Retrieve SSACFG for " + methodSignature);

	IR ir = getIR(methodSignature, cg);
	if (ir == null && !methodSignature.startsWith(WALA_FAKE_ROOT_CLASS))
		logger.warn("Could not retrieve IR for " + methodSignature);		
	
	return ir == null? null : ir.getControlFlowGraph();
}
 
Example #9
Source File: WalaUtils.java    From LibScout with Apache License 2.0 4 votes vote down vote up
public static IR getIR(IMethod method, CallGraph cg) {
	CGNode node = getCGNode(method, cg); 
	return node == null? null : node.getIR();
}
 
Example #10
Source File: WalaUtils.java    From LibScout with Apache License 2.0 4 votes vote down vote up
public static IR getIR(String methodSignature, CallGraph cg) {
	CGNode node = getCGNode(methodSignature, cg); 
	return node == null? null : node.getIR();
}
 
Example #11
Source File: WalaResultAnalyzer.java    From fasten with Apache License 2.0 2 votes vote down vote up
/**
 * Analyze result produced by Wal plugin.
 *
 * @param rawCallGraph Raw call graph in Wala format
 */
private WalaResultAnalyzer(final CallGraph rawCallGraph) {
    this.rawCallGraph = rawCallGraph;
    this.partialCallGraph = new PartialCallGraph();
}