Search in sources :

Example 1 with CallGraph

use of com.jopdesign.common.code.CallGraph in project jop by jop-devel.

the class WCAInvoker method updateWCA.

///////////////////////////////////////////////////////////////////////////////
// Update results
///////////////////////////////////////////////////////////////////////////////
/**
     * Update the WCA results after a set of methods have been changed. The changesets of analyses
     * in the AnalysisManager are checked for changes too.
     *
     * @param changedMethods a set of methods of which the code has been modified.
     * @return a set of all methods for which the path may have changed.
     */
public Set<MethodInfo> updateWCA(Collection<MethodInfo> changedMethods) {
    // Now we need to clear all results for all callers of the modified methods as well as the modified methods,
    // and recalculate all results
    CallGraph callGraph = wcetTool.getCallGraph();
    final Set<ExecutionContext> rootNodes = new LinkedHashSet<ExecutionContext>();
    for (MethodInfo root : changedMethods) {
        rootNodes.addAll(callGraph.getNodes(root));
    }
    // we also need to recalculate for new nodes.. we simply go down callstring-length from the changed methods
    final int callstringLength = AppInfo.getSingleton().getCallstringLength();
    DFSVisitor<ExecutionContext, ContextEdge> visitor = new EmptyDFSVisitor<ExecutionContext, ContextEdge>() {

        @Override
        public boolean visitNode(ExecutionContext parent, ContextEdge edge, ExecutionContext node, DFSEdgeType type, Collection<ContextEdge> outEdges, int depth) {
            if (type.isFirstVisit() && !wcaNodeFlow.containsKey(node)) {
                rootNodes.add(node);
            }
            return depth <= callstringLength;
        }
    };
    DFSTraverser<ExecutionContext, ContextEdge> traverser = new DFSTraverser<ExecutionContext, ContextEdge>(visitor);
    traverser.traverse(callGraph.getGraph(), new ArrayList<ExecutionContext>(rootNodes));
    // classification changed too
    for (MethodInfo method : analyses.getMethodCacheAnalysis().getClassificationChangeSet()) {
        rootNodes.addAll(callGraph.getNodes(method));
    }
    Set<MethodInfo> changed = runAnalysis(wcetTool.getCallGraph().createInvokeGraph(rootNodes, true));
    updateWCEP();
    return changed;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EmptyDFSVisitor(com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) DFSTraverser(com.jopdesign.common.graphutils.DFSTraverser) ExecutionContext(com.jopdesign.common.code.ExecutionContext) CallGraph(com.jopdesign.common.code.CallGraph) DFSEdgeType(com.jopdesign.common.graphutils.DFSTraverser.DFSEdgeType) Collection(java.util.Collection) MethodInfo(com.jopdesign.common.MethodInfo)

Example 2 with CallGraph

use of com.jopdesign.common.code.CallGraph in project jop by jop-devel.

the class PhaseExecutor method dumpCallgraph.

/////////////////////////////////////////////////////////////////////////////////////
// Dump Callgraph
/////////////////////////////////////////////////////////////////////////////////////
public void dumpCallgraph(String graphName) {
    if (getDebugConfig().getOption(DUMP_CALLGRAPH) == CallGraph.DUMPTYPE.off && getDebugConfig().getOption(DUMP_JVM_CALLGRAPH) == CallGraph.DUMPTYPE.off) {
        return;
    }
    try {
        // Dumping the full graph is a bit much, we split it into several graphs
        Set<ExecutionContext> appRoots = new LinkedHashSet<ExecutionContext>();
        Set<ExecutionContext> jvmRoots = new LinkedHashSet<ExecutionContext>();
        Set<ExecutionContext> clinitRoots = new LinkedHashSet<ExecutionContext>();
        Set<String> jvmClasses = new LinkedHashSet<String>();
        if (appInfo.getProcessorModel() != null) {
            jvmClasses.addAll(appInfo.getProcessorModel().getJVMClasses());
            jvmClasses.addAll(appInfo.getProcessorModel().getNativeClasses());
        }
        CallGraph graph = appInfo.getCallGraph();
        for (ExecutionContext ctx : graph.getRootNodes()) {
            if (ctx.getMethodInfo().getMethodSignature().equals(ClinitOrder.clinitSig)) {
                clinitRoots.add(ctx);
            } else if (jvmClasses.contains(ctx.getMethodInfo().getClassName())) {
                jvmRoots.add(ctx);
            } else if (appInfo.isJVMThread(ctx.getMethodInfo().getClassInfo())) {
                // This is to add Runnables like Scheduler and RtThread to the JVM classes.
                jvmRoots.add(ctx);
            } else {
                appRoots.add(ctx);
            }
        }
        OptionGroup debug = getDebugConfig();
        // TODO to keep the CG size down, we could add options to exclude methods (like '<init>') or packages
        // from dumping and skip dumping methods reachable only over excluded methods
        graph.dumpCallgraph(getConfig(), graphName, "app", appRoots, debug.getOption(DUMP_CALLGRAPH), false);
        graph.dumpCallgraph(getConfig(), graphName, "clinit", clinitRoots, debug.getOption(DUMP_CALLGRAPH), false);
        graph.dumpCallgraph(getConfig(), graphName, "jvm", jvmRoots, debug.getOption(DUMP_JVM_CALLGRAPH), !debug.getOption(DUMP_NOIM_CALLS));
    } catch (IOException e) {
        throw new AppInfoError("Unable to export to .dot file", e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExecutionContext(com.jopdesign.common.code.ExecutionContext) OptionGroup(com.jopdesign.common.config.OptionGroup) CallGraph(com.jopdesign.common.code.CallGraph) IOException(java.io.IOException) AppInfoError(com.jopdesign.common.misc.AppInfoError)

Example 3 with CallGraph

use of com.jopdesign.common.code.CallGraph in project jop by jop-devel.

the class WcetAppInfoTest method main.

/*
     * DEMO
     * ~~~~
     */
/* small demo using the class loader */
public static void main(String[] argv) {
    AppSetup appSetup = new AppSetup();
    WCETTool wcetTool = new WCETTool();
    appSetup.registerTool("wcet", wcetTool);
    Config config = appSetup.getConfig();
    config.setOption(ProjectConfig.PROJECT_NAME, "typegraph");
    AppInfo appInfo = appSetup.initAndLoad(argv, false, false, false);
    ProjectConfig pConfig = wcetTool.getProjectConfig();
    try {
        System.out.println("Classloader Demo: " + pConfig.getAppClassName());
        String rootClass = pConfig.getAppClassName();
        String rootPkg = rootClass.substring(0, rootClass.lastIndexOf("."));
        ClassInfo ci = appInfo.getClassInfo(pConfig.getAppClassName());
        System.out.println("Source file: " + ci.getSourceFileName());
        System.out.println("Root class: " + ci.toString());
        {
            System.out.println("Writing type graph to " + pConfig.getOutFile("typegraph.png"));
            File dotFile = pConfig.getOutFile("typegraph.dot");
            FileWriter dotWriter = new FileWriter(dotFile);
            // FIXME TypeGraph is not used anymore, export ClassInfo/.. graph
            TypeGraph typeGraph = new TypeGraph();
            typeGraph.exportDOT(dotWriter, rootPkg);
            dotWriter.close();
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("typegraph.png"));
        }
        SuperGraph sg = new SuperGraph(appInfo, pConfig.getTargetMethodInfo().getCode().getControlFlowGraph(false), 0);
        {
            System.out.println("Writing supergraph graph to " + pConfig.getOutFile("supergraph.png"));
            File dotFile = pConfig.getOutFile("callgraph.dot");
            sg.exportDOT(dotFile);
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("supergraph.png"));
        }
        CallGraph cg = appInfo.buildCallGraph(false);
        {
            System.out.println("Writing call graph to " + pConfig.getOutFile("callgraph.png"));
            File dotFile = pConfig.getOutFile("callgraph.dot");
            FileWriter dotWriter = new FileWriter(dotFile);
            cg.exportDOT(dotWriter);
            dotWriter.close();
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("callgraph.png"));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Config(com.jopdesign.common.config.Config) SuperGraph(com.jopdesign.common.code.SuperGraph) FileWriter(java.io.FileWriter) TypeGraph(com.jopdesign.common.graphutils.TypeGraph) IOException(java.io.IOException) IOException(java.io.IOException) AppInfo(com.jopdesign.common.AppInfo) CallGraph(com.jopdesign.common.code.CallGraph) AppSetup(com.jopdesign.common.AppSetup) File(java.io.File) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

CallGraph (com.jopdesign.common.code.CallGraph)3 ExecutionContext (com.jopdesign.common.code.ExecutionContext)2 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 AppInfo (com.jopdesign.common.AppInfo)1 AppSetup (com.jopdesign.common.AppSetup)1 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodInfo (com.jopdesign.common.MethodInfo)1 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)1 SuperGraph (com.jopdesign.common.code.SuperGraph)1 Config (com.jopdesign.common.config.Config)1 OptionGroup (com.jopdesign.common.config.OptionGroup)1 DFSTraverser (com.jopdesign.common.graphutils.DFSTraverser)1 DFSEdgeType (com.jopdesign.common.graphutils.DFSTraverser.DFSEdgeType)1 EmptyDFSVisitor (com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor)1 TypeGraph (com.jopdesign.common.graphutils.TypeGraph)1 AppInfoError (com.jopdesign.common.misc.AppInfoError)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Collection (java.util.Collection)1