use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.
the class WCAInvoker method updateWCEP.
private void updateWCEP() {
if (!provideWCAExecCount)
return;
execCounts.clear();
for (MethodInfo root : getWcaTargets()) {
execCounts.put(root, 1L);
}
NodeVisitor<ExecutionContext> visitor = new NodeVisitor<ExecutionContext>() {
@Override
public boolean visitNode(ExecutionContext context) {
MethodInfo method = context.getMethodInfo();
MethodCode code = method.getCode();
long ec = getExecCount(method);
// skip methods which are not on the WCET path.. we can ship iterating over the childs too..
if (ec == 0)
return false;
// iterate over all blocks in the CFG, find all invokes and add block execution counts to invokees
ControlFlowGraph cfg = method.getCode().getControlFlowGraph(false);
for (CFGNode node : cfg.getGraph().vertexSet()) {
if (node instanceof InvokeNode) {
InvokeNode inv = (InvokeNode) node;
long ef = getExecFrequency(method, node);
for (MethodInfo invokee : inv.getImplementingMethods()) {
addExecCount(invokee, ec * ef);
}
} else if (node instanceof BasicBlockNode) {
// check if we have a JVM invoke here (or an invoke not in a dedicated node..)
for (InstructionHandle ih : node.getBasicBlock().getInstructions()) {
if (!code.isInvokeSite(ih))
continue;
long ef = getExecFrequency(method, node);
for (MethodInfo invokee : method.getAppInfo().findImplementations(code.getInvokeSite(ih))) {
addExecCount(invokee, ec * ef);
}
}
}
}
return true;
}
};
TopologicalTraverser<ExecutionContext, ContextEdge> topOrder = new TopologicalTraverser<ExecutionContext, ContextEdge>(wcetTool.getCallGraph().getGraph(), visitor);
topOrder.traverse();
}
use of com.jopdesign.common.code.ExecutionContext 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.ExecutionContext in project jop by jop-devel.
the class WCAInvoker method isOnLocalWCETPath.
public boolean isOnLocalWCETPath(MethodInfo method, InstructionHandle ih) {
ControlFlowGraph cfg = method.getCode().getControlFlowGraph(false);
BasicBlockNode block = cfg.getHandleNode(ih, true);
// we do not have a block.. this is some exception handling path (hopefully..)
if (block == null) {
return false;
}
for (ExecutionContext node : wcetTool.getCallGraph().getNodes(method)) {
Long flow = wcaNodeFlow.get(node).get(block);
if (flow > 0)
return true;
}
return false;
}
use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.
the class InlineOptimizer method initialize.
@Override
public void initialize(AnalysisManager analyses, Collection<MethodInfo> roots) {
if (!preciseCycleEstimate) {
ExecutionContext dummy = new ExecutionContext(roots.iterator().next());
WCETProcessorModel pm = analyses.getJCopter().getWCETProcessorModel();
InstructionList il = new InstructionList();
// TODO very messy approximation of exec time
storeCycles = (int) pm.getExecutionTime(dummy, il.append(new ASTORE(10)));
checkNPCycles = 0;
checkNPCycles += (int) pm.getExecutionTime(dummy, il.append(new DUP()));
checkNPCycles += (int) pm.getExecutionTime(dummy, il.append(new IFNONNULL(il.append(new ATHROW()))));
deltaReturnCycles = (int) pm.getExecutionTime(dummy, il.append(new RETURN()));
deltaReturnCycles -= (int) pm.getExecutionTime(dummy, il.append(new GOTO(il.getEnd())));
}
countInvokeSites = 0;
countDevirtualized = 0;
}
use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.
the class ExecFrequencyAnalysis method updateExecCounts.
private void updateExecCounts(DirectedGraph<ExecutionContext, ContextEdge> dag) {
// For now, we just require the graph to be a DAG.
// TODO for all back-edges, we should find some max recursion count and update reachable nodes accordingly..
// For now, we just assume we have no recursion (backedges are only due to insufficient callgraph thinning)
// or simply ignore recursion (unsafe, of course..)
// for the rest of the graph, we can now use a topological order
TopologicalOrderIterator<ExecutionContext, ContextEdge> topOrder = new TopologicalOrderIterator<ExecutionContext, ContextEdge>(dag);
while (topOrder.hasNext()) {
ExecutionContext next = topOrder.next();
if (logger.isTraceEnabled()) {
logger.trace("Updating: " + next);
}
updateChilds(next);
}
}
Aggregations