Search in sources :

Example 1 with SourceAnnotations

use of com.jopdesign.wcet.annotations.SourceAnnotations in project jop by jop-devel.

the class WCETEventHandler method getAnnotations.

public SourceAnnotations getAnnotations(ClassInfo cli) throws BadAnnotationException, IOException {
    SourceAnnotations annots = (SourceAnnotations) cli.getCustomValue(annotationKey);
    if (annots == null) {
        annots = annotationReader.readAnnotations(cli);
        cli.setCustomValue(annotationKey, annots);
    }
    return annots;
}
Also used : SourceAnnotations(com.jopdesign.wcet.annotations.SourceAnnotations)

Example 2 with SourceAnnotations

use of com.jopdesign.wcet.annotations.SourceAnnotations in project jop by jop-devel.

the class AllocationWcetModel method getArrayBound.

private long getArrayBound(ExecutionContext context, InstructionHandle ih, int index) {
    int srcLine = context.getMethodInfo().getCode().getLineNumberTable().getSourceLine(ih.getPosition());
    // get annotated size
    LoopBound annotated = null;
    try {
        SourceAnnotations annots = project.getAnnotations(context.getMethodInfo().getClassInfo());
        annotated = annots.annotationsForLine(srcLine);
        if (annotated == null) {
            WCETTool.logger.info("No annotated bound for array at " + context + ":" + srcLine);
        }
    } catch (Exception exc) {
        // TODO: anything else to do?
        WCETTool.logger.warn("Problem reading annotated bound for array at " + context + ":" + srcLine, exc);
    }
    // get analyzed size
    Interval analyzed = null;
    Interval[] sizes = null;
    if (project.getDfaLoopBounds() != null) {
        sizes = project.getDfaLoopBounds().getArraySizes(ih, context.getCallString());
    }
    if (sizes == null) {
        WCETTool.logger.info("No DFA available for array at " + context + ":" + srcLine);
    } else {
        analyzed = sizes[index];
        if (analyzed == null) {
            WCETTool.logger.info("No DFA bound for array at " + context + ":" + srcLine);
        }
    }
    // compute which bound to use
    if (analyzed != null && analyzed.hasUb()) {
        if (annotated != null) {
            if (annotated.getUpperBound(context) > analyzed.getUb()) {
                WCETTool.logger.warn("DFA bound smaller than annotated bound for array at " + context + ":" + srcLine);
            }
            if (annotated.getUpperBound(context) < analyzed.getUb()) {
                WCETTool.logger.warn("DFA bound larger than annotated bound for array at " + context + ":" + srcLine);
            }
            if (annotated.getUpperBound(context) == analyzed.getUb()) {
                WCETTool.logger.info("DFA bound equals annotated bound for array at " + context + ":" + srcLine);
            }
            return Math.max(annotated.getUpperBound(context), analyzed.getUb());
        } else {
            return analyzed.getUb();
        }
    } else {
        if (annotated != null) {
            return annotated.getUpperBound(context);
        } else {
            WCETTool.logger.error("Cannot determine cost of unbounded array " + context.getMethodInfo().getFQMethodName() + ":" + srcLine + ".\nApproximating with 1024 words, but result is not safe anymore.");
            return 1024;
        }
    }
}
Also used : LoopBound(com.jopdesign.common.code.LoopBound) SourceAnnotations(com.jopdesign.wcet.annotations.SourceAnnotations) Interval(com.jopdesign.dfa.analyses.Interval)

Example 3 with SourceAnnotations

use of com.jopdesign.wcet.annotations.SourceAnnotations in project jop by jop-devel.

the class WCETEventHandler method loadLoopAnnotations.

/**
     * load annotations for the flow graph.
     *
     * @param cfg the control flow graph of the method
     * @throws BadAnnotationException if an annotations is missing
     */
public void loadLoopAnnotations(ControlFlowGraph cfg) throws BadAnnotationException {
    SourceAnnotations wcaMap;
    MethodInfo method = cfg.getMethodInfo();
    MethodCode code = method.getCode();
    ExecutionContext eCtx = new ExecutionContext(cfg.getMethodInfo());
    for (CFGNode n : cfg.getLoopColoring().getHeadOfLoops()) {
        BasicBlockNode headOfLoop = (BasicBlockNode) n;
        BasicBlock block = headOfLoop.getBasicBlock();
        // check if loopbound has already been loaded
        if (block.getLoopBound() != null) {
            // or at least check if the source-annotation is tighter than what is currently set?
            continue;
        }
        Set<LoopBound> bounds = new HashSet<LoopBound>(2);
        InstructionHandle first = block.getFirstInstruction();
        InstructionHandle last = first;
        ClassInfo sourceInfo = method.getCode().getSourceClassInfo(block.getFirstInstruction());
        for (InstructionHandle ih : block.getInstructions()) {
            ClassInfo cls = method.getCode().getSourceClassInfo(ih);
            boolean isLast = ih.equals(block.getLastInstruction());
            if (!cls.equals(sourceInfo) || isLast) {
                try {
                    wcaMap = getAnnotations(method.getCode().getSourceClassInfo(block.getFirstInstruction()));
                } catch (IOException e) {
                    throw new BadAnnotationException("IO Error reading annotation: " + e.getMessage(), e);
                }
                if (isLast) {
                    last = ih;
                }
                // search for loop annotation in range
                int sourceRangeStart = code.getLineNumber(first);
                int sourceRangeStop = code.getLineNumber(last);
                bounds.addAll(wcaMap.annotationsForLineRange(sourceRangeStart, sourceRangeStop + 1));
                first = ih;
            }
            last = ih;
        }
        if (bounds.size() > 1) {
            String reason = "Ambiguous Annotation [" + bounds + "]";
            throw new BadAnnotationException(reason, code, block);
        }
        LoopBound loopAnnot = null;
        if (bounds.size() == 1) {
            loopAnnot = bounds.iterator().next();
        }
        // if we have loop bounds from DFA analysis, use them
        loopAnnot = dfaLoopBound(block, eCtx, loopAnnot);
        if (loopAnnot == null) {
            // Bit of a hack: if we load CFGs before the callgraph is constructed, this will log errors anyway
            if (ignoreMissingLoopBounds) {
                logger.trace("No loop bound annotation: " + method + ":" + n + " " + getLineRangeText(code, block) + ".\nApproximating with " + DEFAULT_LOOP_BOUND + ", but result is not safe anymore.");
            } else if (project.getCallGraph() != null && !project.getCallGraph().containsMethod(method)) {
                logger.debug("No loop bound annotation for non-WCET method: " + method + ":" + n + " " + getLineRangeText(code, block) + ".\nApproximating with " + DEFAULT_LOOP_BOUND);
            } else {
                logger.error("No loop bound annotation: " + method + ":" + n + " " + getLineRangeText(code, block) + ".\nApproximating with " + DEFAULT_LOOP_BOUND + ", but result is not safe anymore.");
            }
            loopAnnot = LoopBound.defaultBound(DEFAULT_LOOP_BOUND);
        }
        block.setLoopBound(loopAnnot);
    }
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) BasicBlockNode(com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode) LoopBound(com.jopdesign.common.code.LoopBound) BasicBlock(com.jopdesign.common.code.BasicBlock) IOException(java.io.IOException) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodInfo(com.jopdesign.common.MethodInfo) BadAnnotationException(com.jopdesign.wcet.annotations.BadAnnotationException) MethodCode(com.jopdesign.common.MethodCode) SourceAnnotations(com.jopdesign.wcet.annotations.SourceAnnotations) HashSet(java.util.HashSet) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

SourceAnnotations (com.jopdesign.wcet.annotations.SourceAnnotations)3 LoopBound (com.jopdesign.common.code.LoopBound)2 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodCode (com.jopdesign.common.MethodCode)1 MethodInfo (com.jopdesign.common.MethodInfo)1 BasicBlock (com.jopdesign.common.code.BasicBlock)1 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 ExecutionContext (com.jopdesign.common.code.ExecutionContext)1 Interval (com.jopdesign.dfa.analyses.Interval)1 BadAnnotationException (com.jopdesign.wcet.annotations.BadAnnotationException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1