use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class MethodCacheAnalysis method isPersistenceRegion.
public boolean isPersistenceRegion(WCETTool wcetTool, MethodInfo m, CallString cs, EnumSet<PersistenceCheck> tests) {
/* fast path for the optimizer (segments are still slow) */
if (tests == EnumSet.of(PersistenceCheck.CountTotal)) {
List<MethodInfo> methods = wcetTool.getCallGraph().getReachableImplementations(m, cs);
long blocks = 0;
for (MethodInfo reachable : methods) {
blocks += methodCache.requiredNumberOfBlocks(reachable);
}
return methodCache.allFit(blocks);
}
Segment segment = Segment.methodSegment(m, cs, wcetTool, wcetTool.getCallstringLength(), wcetTool);
return isPersistenceRegion(segment, tests);
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class ObjectCacheAnalysis method getAccessEdges.
/**
* Get all access sites per method
*/
public static Map<MethodInfo, Set<SuperGraph.SuperGraphEdge>> getAccessEdges(SuperGraph sg) {
Map<MethodInfo, Set<SuperGraph.SuperGraphEdge>> accessEdges = new HashMap<MethodInfo, Set<SuperGraph.SuperGraphEdge>>();
for (Entry<SuperGraph.SuperInvokeEdge, SuperGraph.SuperReturnEdge> invokeSite : sg.getSuperEdgePairs().entrySet()) {
MethodInfo invoked = invokeSite.getKey().getInvokeNode().receiverFlowGraph().getMethodInfo();
addToSet(accessEdges, invoked, invokeSite.getKey());
MethodInfo invoker = invokeSite.getKey().getInvokeNode().invokerFlowGraph().getMethodInfo();
addToSet(accessEdges, invoker, invokeSite.getValue());
}
return accessEdges;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class WCETAnalysis method runMetrics.
private void runMetrics(MethodInfo targetMethod) throws Exception {
/* generate reports later for simple_fit */
wcetTool.setGenerateWCETReport(false);
/* check whether the largest method fits into the cache */
List<MethodInfo> allMethods = wcetTool.getCallGraph().getReachableImplementations(targetMethod);
MethodInfo largestMethod = MethodCacheAnalysis.checkCache(wcetTool, allMethods);
int minWords = MiscUtils.bytesToWords(largestMethod.getCode().getNumberOfBytes());
reportMetric("min-cache-size", largestMethod.getFQMethodName(), minWords);
/* Compute cyclomatic complexity */
exec.info("Cyclomatic complexity: " + wcetTool.computeCyclomaticComplexity(targetMethod));
/* Fast, useful cache approximationx */
CacheCostCalculationMethod cacheApprox = CacheCostCalculationMethod.ALL_FIT_SIMPLE;
/* Perform a few standard analysis (MIN_CACHE_COSdT, ALWAYS_HIT, ALWAYS_MISS) without call strings */
long start, stop;
/* Tree based WCET analysis - has to be equal to ALWAYS_MISS if no flow facts are used */
{
start = System.nanoTime();
TreeAnalysis treeAna = new TreeAnalysis(wcetTool, false);
long treeWCET = treeAna.computeWCET(targetMethod);
stop = System.nanoTime();
reportMetric("progress-measure", treeAna.getMaxProgress(targetMethod));
reportSpecial("wcet.tree", WcetCost.totalCost(treeWCET), start, stop, 0.0);
}
RecursiveWcetAnalysis<AnalysisContextLocal> an = new RecursiveWcetAnalysis<AnalysisContextLocal>(wcetTool, ipetConfig, new LocalAnalysis(wcetTool, ipetConfig));
/* always miss */
start = System.nanoTime();
alwaysMissCost = an.computeCost(targetMethod, new AnalysisContextLocal(CacheCostCalculationMethod.ALWAYS_MISS));
stop = System.nanoTime();
reportSpecial("always-miss", alwaysMissCost, start, stop, LpSolveWrapper.getSolverTime());
/* always hit */
LpSolveWrapper.resetSolverTime();
start = System.nanoTime();
alwaysHitCost = an.computeCost(targetMethod, new AnalysisContextLocal(CacheCostCalculationMethod.ALWAYS_HIT));
stop = System.nanoTime();
reportSpecial("always-hit", alwaysHitCost, start, stop, LpSolveWrapper.getSolverTime());
/* simple approx */
wcetTool.setGenerateWCETReport(true);
start = System.nanoTime();
approxCost = an.computeCost(targetMethod, new AnalysisContextLocal(cacheApprox));
stop = System.nanoTime();
reportSpecial("recursive-report", approxCost, start, stop, LpSolveWrapper.getSolverTime());
wcetTool.setGenerateWCETReport(false);
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class WCETTool method computeCyclomaticComplexity.
// public File getOutFile(String file) {
// return new File(projectConfig.getOutDir(), file);
// }
/* FIXME: Slow, caching is missing */
public int computeCyclomaticComplexity(MethodInfo m) {
ControlFlowGraph g = getFlowGraph(m);
int nLocal = g.vertexSet().size();
int eLocal = g.edgeSet().size();
int pLocal = g.buildLoopBoundMap().size();
int ccLocal = eLocal - nLocal + 2 * pLocal;
int ccGlobal = 0;
for (ExecutionContext n : this.getCallGraph().getReferencedMethods(m)) {
MethodInfo impl = n.getMethodInfo();
ccGlobal += 2 + computeCyclomaticComplexity(impl);
}
return ccLocal + ccGlobal;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class ControlFlowGraph method resolveVirtualInvokes.
/**
* resolve all virtual invoke nodes, and replace them by actual implementations.
* <p>
* This uses the context and the implementation finder passed to the constructor of this graph.
* </p>
*
* @throws BadGraphException If the flow graph analysis (post replacement) fails
*/
@SuppressWarnings({ "AccessingNonPublicFieldOfAnotherObject" })
public void resolveVirtualInvokes() throws BadGraphException {
// Hack to make this optional
if (virtualInvokesResolved)
return;
virtualInvokesResolved = true;
clean = false;
if (hasReturnNodes) {
throw new AssertionError("Virtuals need to be resolved before inserting return nodes (file a bug)");
}
List<InvokeNode> virtualInvokes = new ArrayList<InvokeNode>();
/* find virtual invokes */
for (CFGNode n : this.graph.vertexSet()) {
if (n instanceof InvokeNode) {
InvokeNode in = (InvokeNode) n;
if (in.isVirtual()) {
virtualInvokes.add(in);
}
}
}
/* replace them */
for (InvokeNode inv : virtualInvokes) {
// Magic: this uses the context and the implementation finder passed to the constructor of this graph.
Set<MethodInfo> impls = inv.getImplementingMethods();
if (impls.size() == 0)
internalError("No implementations for " + inv.referenced + " possibly invoked from " + inv.getBasicBlock().getMethodInfo());
if (impls.size() == 1) {
InvokeNode implNode = inv.createImplNode(impls.iterator().next(), inv);
graph.addVertex(implNode);
for (CFGEdge inEdge : graph.incomingEdgesOf(inv)) {
graph.addEdge(graph.getEdgeSource(inEdge), implNode, new CFGEdge(inEdge.kind));
}
for (CFGEdge outEdge : graph.outgoingEdgesOf(inv)) {
graph.addEdge(implNode, graph.getEdgeTarget(outEdge), new CFGEdge(outEdge.kind));
}
} else {
/* more than one impl, create split/join nodes */
CFGNode split = createSplitNode();
graph.addVertex(split);
for (CFGEdge inEdge : graph.incomingEdgesOf(inv)) {
graph.addEdge(graph.getEdgeSource(inEdge), split, new CFGEdge(inEdge.kind));
}
CFGNode join = createJoinNode();
graph.addVertex(join);
for (CFGEdge outEdge : graph.outgoingEdgesOf(inv)) {
graph.addEdge(join, graph.getEdgeTarget(outEdge), new CFGEdge(outEdge.kind));
}
for (MethodInfo impl : impls) {
InvokeNode implNode = inv.createImplNode(impl, inv);
graph.addVertex(implNode);
graph.addEdge(split, implNode, new CFGEdge(EdgeKind.DISPATCH_EDGE));
graph.addEdge(implNode, join, new CFGEdge(EdgeKind.RETURN_EDGE));
}
}
graph.removeVertex(inv);
}
this.invalidate();
this.check();
this.analyseFlowGraph();
}
Aggregations