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;
}
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);
}
}
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();
}
}
Aggregations