Search in sources :

Example 1 with DFSTraverser

use of com.jopdesign.common.graphutils.DFSTraverser in project jop by jop-devel.

the class RebateSelector method initialize.

@Override
public void initialize(GreedyConfig config, boolean dumpStats) {
    // calculate current global codesize
    globalCodesize = 0;
    if (usesCodeRemover) {
        for (MethodInfo method : AppInfo.getSingleton().getCallGraph().getMethodInfos()) {
            if (!method.hasCode())
                continue;
            globalCodesize += method.getCode().getNumberOfBytes();
        }
    } else {
        for (ClassInfo cls : AppInfo.getSingleton().getClassInfos()) {
            for (MethodInfo method : cls.getMethods()) {
                if (!method.hasCode())
                    continue;
                globalCodesize += method.getCode().getNumberOfBytes();
            }
        }
    }
    // we need a tie-breaker for the candidate selection, and to make the results deterministic
    // so we use a topological order of the (initial) callgraph
    DFSVisitor<ExecutionContext, ContextEdge> visitor = new EmptyDFSVisitor<ExecutionContext, ContextEdge>() {

        private int counter = 1;

        @Override
        public void postorder(ExecutionContext node) {
            depthMap.put(node.getMethodInfo(), counter++);
        }
    };
    DirectedGraph<ExecutionContext, ContextEdge> graph = analyses.getTargetCallGraph().getReversedGraph();
    DFSTraverser<ExecutionContext, ContextEdge> traverser = new DFSTraverser<ExecutionContext, ContextEdge>(visitor);
    traverser.traverse(graph);
    logger.info("Initial codesize: " + globalCodesize + " bytes");
    if (config.doDumpStats() && dumpStats) {
        try {
            File statsFile = config.getStatsFile();
            dump = new PrintWriter(statsFile);
            dump.print("total codesize, ");
            if (analyses.useWCAInvoker())
                dump.print("WCET, ");
            dump.println("candidate, ratio, gain, local gain, cache, local cache, delta codesize, frequency");
        } catch (FileNotFoundException e) {
            throw new AppInfoError("Could not initialize dump file", e);
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) EmptyDFSVisitor(com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) AppInfoError(com.jopdesign.common.misc.AppInfoError) DFSTraverser(com.jopdesign.common.graphutils.DFSTraverser) ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodInfo(com.jopdesign.common.MethodInfo) File(java.io.File) ClassInfo(com.jopdesign.common.ClassInfo) PrintWriter(java.io.PrintWriter)

Example 2 with DFSTraverser

use of com.jopdesign.common.graphutils.DFSTraverser 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 3 with DFSTraverser

use of com.jopdesign.common.graphutils.DFSTraverser in project jop by jop-devel.

the class MethodCacheAnalysis method findClassificationChanges.

private Set<MethodInfo> findClassificationChanges(MethodInfo method, final int deltaBlocks, Collection<MethodInfo> removed, final boolean update) {
    if (analysisType == AnalysisType.ALWAYS_HIT || analysisType == AnalysisType.ALWAYS_MISS || (deltaBlocks == 0 && removed.isEmpty())) {
        return Collections.emptySet();
    }
    Set<ExecutionContext> roots = callGraph.getNodes(method);
    // First, go up and find all nodes where one or more methods need to be removed from the reachable methods set
    final Map<ExecutionContext, Set<MethodInfo>> removeMethods = findRemovedMethods(roots, removed);
    // next, calculate blocks of removed methods
    final Map<MethodInfo, Integer> blocks = new LinkedHashMap<MethodInfo, Integer>(removed.size());
    for (MethodInfo m : removed) {
        int size = MiscUtils.bytesToWords(getMethodSize(m));
        blocks.put(m, cache.requiredNumberOfBlocks(size));
    }
    // finally, go up all invokers, sum up reachable method set changes and deltaBlocks per node, check all-fit
    final Set<MethodInfo> changeSet = new LinkedHashSet<MethodInfo>();
    DFSVisitor<ExecutionContext, ContextEdge> visitor = new EmptyDFSVisitor<ExecutionContext, ContextEdge>() {

        @Override
        public void preorder(ExecutionContext node) {
            Set<MethodInfo> remove = removeMethods.get(node);
            int oldBlocks = cacheBlocks.get(node);
            int newBlocks = oldBlocks;
            if (remove != null) {
                if (update) {
                    reachableMethods.get(node).removeAll(remove);
                }
                for (MethodInfo r : remove) {
                    newBlocks -= blocks.get(r);
                }
            }
            newBlocks += deltaBlocks;
            if (update) {
                cacheBlocks.put(node, newBlocks);
            }
            boolean oldFit = cache.allFit(oldBlocks);
            boolean newFit = cache.allFit(newBlocks);
            if (oldFit != newFit) {
                changeSet.add(node.getMethodInfo());
                if (update) {
                    classifyChanges.add(node.getMethodInfo());
                }
            }
        }
    };
    DFSTraverser<ExecutionContext, ContextEdge> traverser = new DFSTraverser<ExecutionContext, ContextEdge>(visitor);
    traverser.traverse(callGraph.getReversedGraph(), roots);
    return changeSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) EmptyDFSVisitor(com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) LinkedHashMap(java.util.LinkedHashMap) DFSTraverser(com.jopdesign.common.graphutils.DFSTraverser) ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodInfo(com.jopdesign.common.MethodInfo)

Aggregations

MethodInfo (com.jopdesign.common.MethodInfo)3 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)3 ExecutionContext (com.jopdesign.common.code.ExecutionContext)3 DFSTraverser (com.jopdesign.common.graphutils.DFSTraverser)3 EmptyDFSVisitor (com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor)3 LinkedHashSet (java.util.LinkedHashSet)2 ClassInfo (com.jopdesign.common.ClassInfo)1 CallGraph (com.jopdesign.common.code.CallGraph)1 DFSEdgeType (com.jopdesign.common.graphutils.DFSTraverser.DFSEdgeType)1 AppInfoError (com.jopdesign.common.misc.AppInfoError)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1