Search in sources :

Example 71 with MethodInfo

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

the class JOPWcetModel method getExecutionTime.

/* get plain execution time, without global effects */
public long getExecutionTime(ExecutionContext context, InstructionHandle ih) {
    Instruction i = ih.getInstruction();
    MethodInfo mctx = context.getMethodInfo();
    int jopcode = processorModel.getNativeOpCode(mctx, i);
    long cycles = timing.getLocalCycles(jopcode);
    if (isUnboundedBytecode(i)) {
        WCETTool.logger.error("[FATAL] Unsupported (unbounded) bytecode: " + i.getName() + " in " + mctx.getFQMethodName() + ". Approximating with 2000 cycles, but result is not safe anymore!");
        return 2000L;
    } else if (cycles < 0) {
        throw new AssertionError("Requesting #cycles of non-implemented opcode: " + i + "(opcode " + jopcode + ") used in context: " + context);
    } else {
        return (int) cycles;
    }
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) Instruction(org.apache.bcel.generic.Instruction)

Example 72 with MethodInfo

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

the class Report method generateInfoPages.

/**
 * Dump the project's input (callgraph,cfgs)
 *
 * @throws IOException
 */
public void generateInfoPages() throws IOException {
    this.addStat("#classes", project.getCallGraph().getClassInfos().size());
    this.addStat("#methods", project.getCallGraph().getReachableImplementationsSet(project.getTargetMethod()).size());
    this.addStat("max call stack ", project.getCallGraph().getMaximalCallStack());
    this.addStat("largest method size (in bytes)", project.getCallGraph().getLargestMethod().getNumberOfBytes());
    this.addStat("largest method size (in words)", project.getCallGraph().getLargestMethod().getNumberOfWords());
    this.addStat("total size of task (in bytes)", project.getCallGraph().getTotalSizeInBytes());
    generateInputOverview();
    this.addPage("details", null);
    for (MethodInfo m : project.getCallGraph().getReachableImplementationsSet(project.getTargetMethod())) {
        for (LineNumber ln : m.getCode().getLineNumberTable().getLineNumberTable()) {
            getClassReport(m.getClassInfo()).addLinePropertyIfNull(ln.getLineNumber(), "color", "lightgreen");
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Generating report for method: " + m);
        }
        ControlFlowGraph flowGraph = project.getFlowGraph(m);
        Map<String, Object> stats = new TreeMap<String, Object>();
        stats.put("#nodes", flowGraph.vertexSet().size() - 2);
        stats.put("number of words", flowGraph.getNumberOfWords());
        this.addDetailedReport(m, new DetailedMethodReport(config, project, m, "CFG", stats, null, null), true);
        generateDetailedReport(m);
    }
    for (ClassInfo c : project.getCallGraph().getClassInfos()) {
        ClassReport cr = getClassReport(c);
        String page = pageOf(c);
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("classreport", cr);
        try {
            this.generateFile("class.vm", config.getReportFile(page), ctx);
        } catch (Exception e) {
            logger.error(e);
        }
        addPage("details/" + c.getClassName(), page);
    }
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LineNumber(org.apache.bcel.classfile.LineNumber) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 73 with MethodInfo

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

the class HashTest method main.

public static void main(String[] args) {
    TestFramework test = new TestFramework();
    AppSetup setup = test.setupAppSetup();
    AppInfo appInfo = test.setupAppInfo("common.code.HashTest", false);
    ClassInfo testClass = appInfo.loadClass("common.TestFramework");
    MethodInfo mainMethod = appInfo.getMainMethod();
    MethodCode code = mainMethod.getCode();
    InstructionHandle[] ih = code.getInstructionList().getInstructionHandles();
    InvokeSite i1 = code.getInvokeSite(ih[1]);
    InvokeSite i2 = code.getInvokeSite(ih[2]);
    InvokeSite i3 = code.getInvokeSite(ih[3]);
    InvokeSite i11 = code.getInvokeSite(ih[1]);
    check(i1 == i11);
    CallString c1 = new CallString(i1);
    CallString c2 = new CallString(i2);
    CallString c11 = new CallString(i1);
    check(c1.equals(c11));
    check(!c1.equals(c2));
    ExecutionContext e1 = new ExecutionContext(mainMethod, c1);
    ExecutionContext e2 = new ExecutionContext(mainMethod, c2);
    ExecutionContext e11 = new ExecutionContext(mainMethod, c11);
    check(e1.equals(e11));
    check(!e1.equals(e2));
    // TODO put stuff into maps, check contains() and get()
    // modify instruction list, check if everything still works
    InstructionList il = code.getInstructionList();
    il.insert(new ILOAD(0));
    il.insert(ih[2], new ILOAD(1));
    ih = il.getInstructionHandles();
    InvokeSite i12 = code.getInvokeSite(ih[2]);
    InvokeSite i22 = code.getInvokeSite(ih[4]);
    check(i12 == i1);
    check(i22 == i2);
    check(e1.equals(e11));
    check(!e1.equals(e2));
    il.setPositions();
    check(c1.equals(c11));
    check(!c1.equals(c2));
    check(e1.equals(e11));
    check(!e1.equals(e2));
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionHandle(org.apache.bcel.generic.InstructionHandle) AppInfo(com.jopdesign.common.AppInfo) TestFramework(com.jopdesign.common.TestFramework) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) MethodCode(com.jopdesign.common.MethodCode) ClassInfo(com.jopdesign.common.ClassInfo)

Example 74 with MethodInfo

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

the class LocalAnalysis method recursiveCost.

public WcetCost recursiveCost(RecursiveAnalysis<AnalysisContextLocal, WcetCost> stagedAnalysis, ControlFlowGraph.InvokeNode n, AnalysisContextLocal ctx) {
    CacheCostCalculationMethod cacheMode = ctx.getCacheApproxMode();
    if (cacheMode.needsInterProcIPET()) {
        throw new AssertionError("Error: Cache Mode " + cacheMode + " not supported using local IPET strategy - " + "it needs an interprocedural IPET analysis");
    }
    WCETTool project = stagedAnalysis.getWCETTool();
    MethodInfo invoker = n.getBasicBlock().getMethodInfo();
    MethodInfo invoked = n.getImplementingMethod();
    WCETProcessorModel proc = project.getWCETProcessorModel();
    MethodCacheAnalysis mca = new MethodCacheAnalysis(project);
    long cacheCost;
    AnalysisContextLocal recCtx = ctx.withCallString(ctx.getCallString().push(n, maxCallstringLength));
    WcetCost recCost = stagedAnalysis.computeCost(invoked, recCtx);
    long nonLocalExecCost = recCost.getCost() - recCost.getCacheCost();
    long nonLocalCacheCost = recCost.getCacheCost();
    long invokeReturnCost = mca.getInvokeReturnMissCost(n.getInvokeSite(), ctx.getCallString());
    if (proc.getMethodCache().getNumBlocks() == 0 || cacheMode == CacheCostCalculationMethod.ALWAYS_HIT) {
        cacheCost = 0;
    } else if (project.getCallGraph().isLeafMethod(invoked)) {
        cacheCost = invokeReturnCost + nonLocalCacheCost;
    } else if (cacheMode == CacheCostCalculationMethod.ALL_FIT_SIMPLE && allFit(project, invoked, recCtx.getCallString())) {
        long returnCost = mca.getMissOnceCost(invoker, false);
        /* Maybe its better not to apply the all-fit heuristic ... */
        long noAllFitCost = recCost.getCost() + invokeReturnCost;
        /* Compute cost without method cache */
        AnalysisContextLocal ahCtx = recCtx.withCacheApprox(CacheCostCalculationMethod.ALWAYS_HIT);
        long alwaysHitCost = stagedAnalysis.computeCost(invoked, ahCtx).getCost();
        /* Compute penalty for loading each method exactly once */
        long allFitPenalty = mca.getMissOnceCummulativeCacheCost(invoked, assumeMissOnceOnInvoke);
        long allFitCacheCost = allFitPenalty + returnCost;
        /* Cost All-Fit: recursive + penalty for loading once + return to caller */
        long allFitCost = alwaysHitCost + allFitCacheCost;
        /* Choose the better approximation */
        if (allFitCost <= noAllFitCost) {
            cacheCost = allFitCacheCost;
            nonLocalExecCost = alwaysHitCost;
        } else {
            cacheCost = invokeReturnCost + nonLocalCacheCost;
        }
    } else {
        /* ALWAYS MISS or doesn't fit */
        cacheCost = invokeReturnCost + nonLocalCacheCost;
    }
    WcetCost cost = new WcetCost();
    cost.addNonLocalCost(nonLocalExecCost);
    cost.addCacheCost(cacheCost);
    logger.debug("Recursive WCET computation: " + invoked + ". invoke return cache cost: " + invokeReturnCost + ". non-local cache cost: " + nonLocalCacheCost + ". cummulative cache cost: " + cacheCost + " non local execution cost: " + nonLocalExecCost);
    return cost;
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) WCETProcessorModel(com.jopdesign.wcet.WCETProcessorModel) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis) MethodInfo(com.jopdesign.common.MethodInfo) WCETTool(com.jopdesign.wcet.WCETTool)

Example 75 with MethodInfo

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

the class RecursiveWcetAnalysis method updateClassReport.

/**
 * Update class report (cost per line number)
 *
 * @param key
 * @param sol FIXME: Currently only reported once per method
 */
private void updateClassReport(CacheKey key, LocalWCETSolution sol) {
    MethodInfo m = key.m;
    if (costsPerLineReported.contains(m))
        return;
    costsPerLineReported.add(m);
    Map<CFGNode, WcetCost> nodeCosts = sol.getNodeCostMap();
    HashMap<CFGNode, String> nodeFlowCostDescrs = new HashMap<CFGNode, String>();
    // for autogenerated code
    long anonymousCost = 0;
    for (Entry<CFGNode, WcetCost> entry : nodeCosts.entrySet()) {
        CFGNode n = entry.getKey();
        WcetCost cost = entry.getValue();
        if (sol.getNodeFlow(n) > 0) {
            nodeFlowCostDescrs.put(n, cost.toString());
            BasicBlock basicBlock = n.getBasicBlock();
            /* prototyping */
            if (basicBlock != null) {
                Map<ClassInfo, TreeSet<Integer>> lineMap = basicBlock.getSourceLines();
                if (lineMap.isEmpty()) {
                    logger.error("No source code lines associated with basic block " + basicBlock + " in " + m + " ! ");
                    continue;
                }
                // we attach to the first class in the map only
                ClassInfo cli = lineMap.keySet().iterator().next();
                TreeSet<Integer> lineRange = lineMap.get(cli);
                ClassReport cr = getWCETTool().getReport().getClassReport(cli);
                long newCost = sol.getNodeFlow(n) * nodeCosts.get(n).getCost();
                // Autogenerated code, attach to next entry
                if (lineRange.isEmpty()) {
                    anonymousCost += newCost;
                    continue;
                } else {
                    newCost += anonymousCost;
                    anonymousCost = 0;
                }
                Long oldCost = (Long) cr.getLineProperty(lineRange.first(), "cost");
                if (oldCost == null)
                    oldCost = 0L;
                if (logger.isTraceEnabled()) {
                    logger.trace("Attaching cost " + oldCost + " + " + newCost + " to line " + lineRange.first() + " in " + basicBlock.getMethodInfo());
                }
                cr.addLineProperty(lineRange.first(), "cost", oldCost + newCost);
                for (int i : lineRange) {
                    cr.addLineProperty(i, "color", "red");
                }
            }
        } else {
            nodeFlowCostDescrs.put(n, "" + nodeCosts.get(n).getCost());
        }
    }
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) HashMap(java.util.HashMap) ClassReport(com.jopdesign.wcet.report.ClassReport) BasicBlock(com.jopdesign.common.code.BasicBlock) TreeSet(java.util.TreeSet) MethodInfo(com.jopdesign.common.MethodInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

MethodInfo (com.jopdesign.common.MethodInfo)108 LinkedHashSet (java.util.LinkedHashSet)21 InstructionHandle (org.apache.bcel.generic.InstructionHandle)20 ClassInfo (com.jopdesign.common.ClassInfo)19 ExecutionContext (com.jopdesign.common.code.ExecutionContext)16 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)13 ArrayList (java.util.ArrayList)13 CallString (com.jopdesign.common.code.CallString)12 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)12 HashMap (java.util.HashMap)10 Set (java.util.Set)10 LinkedHashMap (java.util.LinkedHashMap)9 Instruction (org.apache.bcel.generic.Instruction)9 FieldInfo (com.jopdesign.common.FieldInfo)8 MethodCode (com.jopdesign.common.MethodCode)8 AppInfo (com.jopdesign.common.AppInfo)7 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)7 InvokeSite (com.jopdesign.common.code.InvokeSite)7 MemberID (com.jopdesign.common.type.MemberID)7 Context (com.jopdesign.dfa.framework.Context)7