Search in sources :

Example 11 with AppInfo

use of com.jopdesign.common.AppInfo 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)

Example 12 with AppInfo

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

the class WCETPreprocess method main.

public static void main(String[] args) {
    AppSetup setup = new AppSetup();
    AppInfo ai = setup.initAndLoad(args, false, false, true);
    preprocess(ai);
    // dump the methods
    // try {
    // ai.iterate(new Dump(ai, new PrintWriter(new FileOutputStream(ai.outFile+"/dump.txt"))));
    // } catch (FileNotFoundException e) {
    // e.printStackTrace();
    // }
    // write the class files
    setup.writeClasses();
}
Also used : AppSetup(com.jopdesign.common.AppSetup) AppInfo(com.jopdesign.common.AppInfo)

Example 13 with AppInfo

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

the class UppAalAnalysis method main.

public static void main(String[] args) {
    // We set a different output path for this tool if invoked by cmdline
    // Note that WCETTool could also override defaults, but we do not want to change the
    // default value of outdir if WCETTool is invoked from another tool
    Properties defaultProps = new Properties();
    defaultProps.put("outdir", "java/target/wcet/${projectname}");
    AppSetup setup = new AppSetup(defaultProps, false);
    setup.setVersionInfo("1.0 [deprecated]");
    // We do not load a config file automatically, user has to specify it explicitly to avoid
    // unintentional misconfiguration
    // setup.setConfigFilename(CONFIG_FILE_NAME);
    setup.setUsageInfo("UppAllAnalysis", "UppAll WCET Analysis");
    WCETTool wcetTool = new WCETTool();
    DFATool dfaTool = new DFATool();
    setup.registerTool("dfa", dfaTool, true, false);
    setup.registerTool("wcet", wcetTool);
    @SuppressWarnings("unused") AppInfo appInfo = setup.initAndLoad(args, true, false, false);
    if (setup.useTool("dfa")) {
        wcetTool.setDfaTool(dfaTool);
    }
    ExecHelper exec = new ExecHelper(setup.getConfig(), tlLogger);
    exec.dumpConfig();
    UppAalAnalysis inst = new UppAalAnalysis(wcetTool);
    /* run */
    if (!inst.run(exec))
        exec.bail("UppAal translation failed");
    tlLogger.info("UppAal translation finished");
}
Also used : DFATool(com.jopdesign.dfa.DFATool) AppSetup(com.jopdesign.common.AppSetup) Properties(java.util.Properties) AppInfo(com.jopdesign.common.AppInfo)

Example 14 with AppInfo

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

the class MethodCacheAnalysis method getInvokeReturnCacheCosts.

public long getInvokeReturnCacheCosts(ExecFrequencyProvider ecp, InvokeSite invokeSite) {
    if (analysisType == AnalysisType.ALWAYS_HIT)
        return 0;
    AppInfo appInfo = AppInfo.getSingleton();
    int size = 0;
    for (MethodInfo method : appInfo.findImplementations(invokeSite)) {
        size = Math.max(size, getMethodSize(method));
    }
    size = MiscUtils.bytesToWords(size);
    int sizeInvoker = getMethodSize(invokeSite.getInvoker());
    sizeInvoker = MiscUtils.bytesToWords(sizeInvoker);
    long invokeCosts = cache.getMissPenaltyOnInvoke(size, invokeSite.getInvokeInstruction());
    long returnCosts = cache.getMissPenaltyOnReturn(sizeInvoker, invokeSite.getInvokeeRef().getDescriptor().getType());
    return getInvokeReturnCacheCosts(ecp, invokeSite, invokeCosts, returnCosts);
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) AppInfo(com.jopdesign.common.AppInfo)

Example 15 with AppInfo

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

the class MethodCacheAnalysis method getAllFitChangeCosts.

private long getAllFitChangeCosts(ExecFrequencyProvider ecp, CodeModification modification, int deltaBlocks) {
    if (analysisType == AnalysisType.ALWAYS_HIT || analysisType == AnalysisType.ALWAYS_MISS) {
        return 0;
    }
    int deltaBytes = modification.getDeltaLocalCodesize();
    MethodInfo method = modification.getMethod();
    // for ALWAYS_MISS_HIT oder MOST_ONCE we need to find out what has changed for all-fit
    Set<MethodInfo> changes = findClassificationChanges(method, deltaBlocks, modification.getRemovedInvokees(), false);
    AppInfo appInfo = AppInfo.getSingleton();
    // In all nodes where we have changes, we need to sum up the new costs
    long deltaCosts = 0;
    for (MethodInfo node : changes) {
        // but all invokes in the method are now no longer always-hit/-miss
        for (InvokeSite invokeSite : node.getCode().getInvokeSites()) {
            // Note: this is very similar to getInvokeReturnCacheCosts(invokeSite), but we cannot use
            // this here, because that method uses allFit and does not honor our 'virtual' codesize change
            int size = 0;
            for (MethodInfo impl : appInfo.findImplementations(invokeSite)) {
                size = Math.max(size, getMethodSize(impl));
            }
            size = MiscUtils.bytesToWords(size);
            int sizeInvoker = getMethodSize(invokeSite.getInvoker());
            sizeInvoker = MiscUtils.bytesToWords(sizeInvoker);
            long invokeCosts = cache.getMissPenaltyOnInvoke(size, invokeSite.getInvokeInstruction());
            long returnCosts = cache.getMissPenaltyOnReturn(sizeInvoker, invokeSite.getInvokeeRef().getDescriptor().getType());
            long count = ecp.getExecCount(invokeSite);
            if (analysisType == AnalysisType.ALL_FIT_REGIONS) {
                // for this analysis we already have one miss in the original cost estimation
                count--;
            }
            deltaCosts += count * (invokeCosts + returnCosts);
        }
    }
    // if the code increased, the classification changed from always-hit to always-miss ..
    long costs = deltaBytes > 0 ? deltaCosts : -deltaCosts;
    if (analysisType == AnalysisType.ALL_FIT_REGIONS) {
        // find out how many additional persistent cache misses we have
        // find out border of new all-fit region
        Map<MethodInfo, Integer> deltaExec = new LinkedHashMap<MethodInfo, Integer>();
        int deltaCount = 0;
        Set<ExecutionContext> border = new LinkedHashSet<ExecutionContext>();
        if (deltaBlocks < 0) {
            throw new AppInfoError("Not implemented");
        } else {
            for (MethodInfo miss : changes) {
                for (ExecutionContext context : callGraph.getNodes(miss)) {
                    for (ExecutionContext invokee : callGraph.getChildren(context)) {
                        // not all-fit if in changeset
                        if (changes.contains(invokee.getMethodInfo()))
                            continue;
                        // we ignore native stuff
                        if (invokee.getMethodInfo().isNative())
                            continue;
                        // invokee is all-fit
                        if (border.add(invokee)) {
                            deltaCount += ecp.getExecCount(invokee);
                        }
                    }
                }
            }
            // remove old miss count
            deltaCount -= getPersistentMisses(ecp, border);
        }
        // TODO this is not quite correct: instead of joining the reachable sets and multiplying
        // with the delta count for the whole region, we should:
        // - for every node in the reachable sets of the new border, sum up exec-counts of border nodes
        // which contain that node in the reachable set
        // - for every node in the reachable sets of the old border, subtract the exec counts of those border nodes
        // - sum up invoke miss costs times calculates delta counts per node
        // find out cache miss costs of new all-fit region
        int regionCosts = 0;
        Set<MethodInfo> visited = new LinkedHashSet<MethodInfo>();
        for (ExecutionContext context : border) {
            for (MethodInfo reachable : reachableMethods.get(context)) {
                if (visited.add(reachable)) {
                    regionCosts += cache.getMissPenalty(reachable.getCode().getNumberOfWords(), cache.isLRU());
                }
            }
        }
        costs += deltaCount * regionCosts;
    }
    return costs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AppInfoError(com.jopdesign.common.misc.AppInfoError) AppInfo(com.jopdesign.common.AppInfo) LinkedHashMap(java.util.LinkedHashMap) ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodInfo(com.jopdesign.common.MethodInfo) InvokeSite(com.jopdesign.common.code.InvokeSite)

Aggregations

AppInfo (com.jopdesign.common.AppInfo)21 AppSetup (com.jopdesign.common.AppSetup)7 ClassInfo (com.jopdesign.common.ClassInfo)7 MethodInfo (com.jopdesign.common.MethodInfo)7 File (java.io.File)4 IOException (java.io.IOException)4 TestFramework (com.jopdesign.common.TestFramework)3 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)2 FileWriter (java.io.FileWriter)2 LinkedHashSet (java.util.LinkedHashSet)2 FieldInfo (com.jopdesign.common.FieldInfo)1 MethodCode (com.jopdesign.common.MethodCode)1 CallGraph (com.jopdesign.common.code.CallGraph)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 ExecutionContext (com.jopdesign.common.code.ExecutionContext)1 InvokeSite (com.jopdesign.common.code.InvokeSite)1 SuperGraph (com.jopdesign.common.code.SuperGraph)1 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)1 SuperEdge (com.jopdesign.common.code.SuperGraph.SuperEdge)1