Search in sources :

Example 1 with ATHROW

use of org.apache.bcel.generic.ATHROW 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;
}
Also used : RETURN(org.apache.bcel.generic.RETURN) GOTO(org.apache.bcel.generic.GOTO) ExecutionContext(com.jopdesign.common.code.ExecutionContext) ASTORE(org.apache.bcel.generic.ASTORE) WCETProcessorModel(com.jopdesign.wcet.WCETProcessorModel) InstructionList(org.apache.bcel.generic.InstructionList) ATHROW(org.apache.bcel.generic.ATHROW) IFNONNULL(org.apache.bcel.generic.IFNONNULL) DUP(org.apache.bcel.generic.DUP)

Example 2 with ATHROW

use of org.apache.bcel.generic.ATHROW in project jop by jop-devel.

the class InstructionInterpreter method getOutEdges.

private List<Edge> getOutEdges(InstructionHandle ih) {
    List<Edge> edges = new LinkedList<Edge>();
    Instruction instr = ih.getInstruction();
    if (instr instanceof BranchInstruction) {
        if (instr instanceof Select) {
            Select s = (Select) instr;
            InstructionHandle[] target = s.getTargets();
            for (InstructionHandle aTarget : target) {
                edges.add(new Edge(ih, aTarget, EdgeType.TRUE_EDGE));
            }
            edges.add(new Edge(ih, s.getTarget(), EdgeType.FALSE_EDGE));
        } else {
            BranchInstruction b = (BranchInstruction) instr;
            edges.add(new Edge(ih, b.getTarget(), EdgeType.TRUE_EDGE));
        }
    }
    // Check if we can fall through to the next instruction
    if (ih.getNext() != null && !(instr instanceof UnconditionalBranch || instr instanceof Select || instr instanceof ReturnInstruction)) {
        if (instr instanceof BranchInstruction) {
            edges.add(new Edge(ih, ih.getNext(), EdgeType.FALSE_EDGE));
        } else {
            edges.add(new Edge(ih, ih.getNext(), EdgeType.NORMAL_EDGE));
        }
    }
    if (instr instanceof ReturnInstruction) {
        edges.add(new Edge(ih, getExitInstruction(), EdgeType.EXIT_EDGE));
    }
    if (instr instanceof ATHROW) {
    // TODO should we handle this somehow? Insert edges to the exception handlers or to an return-by-exception
    //      exit instruction?
    // for now, just ignore them
    }
    //      but for now, we just ignore them too.. in a safe way :)
    if (instr instanceof RET || instr instanceof JSR || instr instanceof JSR_W) {
        throw new JavaClassFormatError("Unsupported instruction " + instr + " in " + methodInfo);
    }
    return edges;
}
Also used : RET(org.apache.bcel.generic.RET) UnconditionalBranch(org.apache.bcel.generic.UnconditionalBranch) BranchInstruction(org.apache.bcel.generic.BranchInstruction) JSR(org.apache.bcel.generic.JSR) ATHROW(org.apache.bcel.generic.ATHROW) BranchInstruction(org.apache.bcel.generic.BranchInstruction) Instruction(org.apache.bcel.generic.Instruction) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) LinkedList(java.util.LinkedList) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) Select(org.apache.bcel.generic.Select) JSR_W(org.apache.bcel.generic.JSR_W)

Aggregations

ATHROW (org.apache.bcel.generic.ATHROW)2 ExecutionContext (com.jopdesign.common.code.ExecutionContext)1 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)1 WCETProcessorModel (com.jopdesign.wcet.WCETProcessorModel)1 LinkedList (java.util.LinkedList)1 ASTORE (org.apache.bcel.generic.ASTORE)1 BranchInstruction (org.apache.bcel.generic.BranchInstruction)1 DUP (org.apache.bcel.generic.DUP)1 GOTO (org.apache.bcel.generic.GOTO)1 IFNONNULL (org.apache.bcel.generic.IFNONNULL)1 Instruction (org.apache.bcel.generic.Instruction)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 InstructionList (org.apache.bcel.generic.InstructionList)1 JSR (org.apache.bcel.generic.JSR)1 JSR_W (org.apache.bcel.generic.JSR_W)1 RET (org.apache.bcel.generic.RET)1 RETURN (org.apache.bcel.generic.RETURN)1 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)1 Select (org.apache.bcel.generic.Select)1 UnconditionalBranch (org.apache.bcel.generic.UnconditionalBranch)1