Search in sources :

Example 6 with MethodCode

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

the class SourceLineStorage method applySourceInfos.

private void applySourceInfos(MethodInfo method, List<SourceLineEntry> entries) {
    MethodCode code = method.getCode();
    InstructionHandle[] il = code.getInstructionList(true, false).getInstructionHandles();
    for (SourceLineEntry sle : entries) {
        sle.applyEntry(code, il);
    }
}
Also used : MethodCode(com.jopdesign.common.MethodCode) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 7 with MethodCode

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

the class MethodCacheAnalysis method checkCache.

/**
     * Check that cache is big enough to hold any method possibly invoked
     * Return largest method
     */
public static MethodInfo checkCache(WCETTool wcetTool, Iterable<MethodInfo> methods) throws AppInfoException {
    MethodCache methodCache = wcetTool.getWCETProcessorModel().getMethodCache();
    int maxWords = 0;
    MethodInfo largestMethod = null;
    // for (ClassInfo ci : project.getAppInfo().getClassInfos()) {
    for (MethodInfo mi : methods) {
        MethodCode code = mi.getCode();
        if (code == null)
            continue;
        // FIXME: using getNumberOfBytes(false) here to be compatible to old behaviour.
        //        should probably be getNumberOfBytes()
        int size = code.getNumberOfBytes(false);
        int words = MiscUtils.bytesToWords(size);
        if (!methodCache.fitsInCache(words)) {
            throw new AppInfoException("Cache to small for target method: " + mi.getFQMethodName() + " / " + words + " words");
        }
        if (words >= maxWords) {
            largestMethod = mi;
            maxWords = words;
        }
    }
    return largestMethod;
}
Also used : MethodCache(com.jopdesign.wcet.jop.MethodCache) MethodInfo(com.jopdesign.common.MethodInfo) AppInfoException(com.jopdesign.common.misc.AppInfoException) MethodCode(com.jopdesign.common.MethodCode)

Example 8 with MethodCode

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

the class InsertSynchronized method synchronize.

private void synchronize(MethodInfo method) {
    MethodCode mc = method.getCode();
    InstructionList il = mc.getInstructionList();
    InstructionFinder f;
    // prepend monitorenter (reversed order of opcodes)
    il.insert(new MONITORENTER());
    if (method.isStatic()) {
        // il.insert(new GET_CURRENT_CLASS());
        throw new JavaClassFormatError("synchronized on static methods not yet supported");
    } else {
        il.insert(new ALOAD(0));
    }
    il.setPositions();
    f = new InstructionFinder(il);
    // find return instructions and insert monitorexit
    String retInstr = "ReturnInstruction";
    for (Iterator iterator = f.search(retInstr); iterator.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) iterator.next();
        InstructionHandle ih = match[0];
        // handle for inserted sequence
        InstructionHandle newh;
        if (method.isStatic()) {
            // il.insert(ih, new GET_CURRENT_CLASS());
            throw new JavaClassFormatError("synchronized on static methods not yet supported");
        } else {
            // TODO this could become a bug if JCopter ever reassigns local variable slots, then
            // we could not be sure that slot 0 holds the this reference anymore.. To be on the safe side
            // we should check if there is an xSTORE_0 somewhere in the code
            newh = il.insert(ih, new ALOAD(0));
        }
        il.insert(ih, new MONITOREXIT());
        // correct jumps
        method.getCode().retarget(ih, newh);
    }
    il.setPositions();
    method.compile();
}
Also used : ALOAD(org.apache.bcel.generic.ALOAD) InstructionList(org.apache.bcel.generic.InstructionList) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) Iterator(java.util.Iterator) MONITOREXIT(org.apache.bcel.generic.MONITOREXIT) InstructionFinder(org.apache.bcel.util.InstructionFinder) MethodCode(com.jopdesign.common.MethodCode) MONITORENTER(org.apache.bcel.generic.MONITORENTER) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 9 with MethodCode

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

the class ReplaceIinc method replace.

private void replace(MethodInfo method) {
    MethodCode mc = method.getCode();
    InstructionList il = mc.getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    for (Iterator i = f.search("IINC"); i.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) i.next();
        InstructionHandle ih = match[0];
        IINC ii = (IINC) ih.getInstruction();
        int idx = ii.getIndex();
        int inc = ii.getIncrement();
        //  	    IINC rep = new IINC(idx, inc);
        ih.setInstruction(new ILOAD(idx));
        if (inc >= -1 && inc <= 5) {
            ih = il.append(ih, new ICONST(inc));
        } else if (inc >= -128 && inc < 127) {
            ih = il.append(ih, new BIPUSH((byte) inc));
        } else if (inc >= -32768 && inc < 32767) {
            ih = il.append(ih, new SIPUSH((short) inc));
        } else {
            System.out.println("IINC constant too big");
            System.exit(-1);
        }
        ih = il.append(ih, new IADD());
        ih = il.append(ih, new ISTORE(idx));
    }
    method.compile();
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionFinder(org.apache.bcel.util.InstructionFinder) BIPUSH(org.apache.bcel.generic.BIPUSH) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ISTORE(org.apache.bcel.generic.ISTORE) IINC(org.apache.bcel.generic.IINC) Iterator(java.util.Iterator) IADD(org.apache.bcel.generic.IADD) MethodCode(com.jopdesign.common.MethodCode) SIPUSH(org.apache.bcel.generic.SIPUSH) ICONST(org.apache.bcel.generic.ICONST)

Example 10 with MethodCode

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

the class DescendingClassTraverser method visitMethodCode.

public void visitMethodCode(MethodInfo methodInfo) {
    if (methodInfo.hasCode()) {
        bcelVisitor.setCode(true);
        MethodCode code = methodInfo.getCode();
        visitor.visitMethodCode(code);
        for (CodeExceptionGen ex : code.getExceptionHandlers()) {
            visitor.visitCodeException(methodInfo, ex);
        }
        for (LineNumberGen lng : code.getLineNumbers()) {
            visitor.visitLineNumber(methodInfo, lng);
        }
        for (LocalVariableGen lvg : code.getLocalVariables()) {
            visitor.visitLocalVariable(methodInfo, lvg);
        }
        visitAttributes(code.getAttributes());
        bcelVisitor.setCode(false);
    }
}
Also used : LineNumberGen(org.apache.bcel.generic.LineNumberGen) LocalVariableGen(org.apache.bcel.generic.LocalVariableGen) MethodCode(com.jopdesign.common.MethodCode) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen)

Aggregations

MethodCode (com.jopdesign.common.MethodCode)15 InstructionHandle (org.apache.bcel.generic.InstructionHandle)12 MethodInfo (com.jopdesign.common.MethodInfo)8 InstructionList (org.apache.bcel.generic.InstructionList)6 ExecutionContext (com.jopdesign.common.code.ExecutionContext)3 InvokeSite (com.jopdesign.common.code.InvokeSite)3 Instruction (org.apache.bcel.generic.Instruction)3 ClassInfo (com.jopdesign.common.ClassInfo)2 FieldInfo (com.jopdesign.common.FieldInfo)2 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)2 FieldRef (com.jopdesign.common.type.FieldRef)2 MethodRef (com.jopdesign.common.type.MethodRef)2 Iterator (java.util.Iterator)2 ConstantPushInstruction (org.apache.bcel.generic.ConstantPushInstruction)2 FieldInstruction (org.apache.bcel.generic.FieldInstruction)2 ILOAD (org.apache.bcel.generic.ILOAD)2 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)2 LocalVariableInstruction (org.apache.bcel.generic.LocalVariableInstruction)2 InstructionFinder (org.apache.bcel.util.InstructionFinder)2