Search in sources :

Example 11 with ConstantPoolGen

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

the class ObjectCacheAnalysis method getHandleType.

public static String getHandleType(WCETTool project, ControlFlowGraph cfg, InstructionHandle ih) {
    ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
    Instruction instr = ih.getInstruction();
    if (instr instanceof GETFIELD) {
        GETFIELD gf = (GETFIELD) instr;
        ReferenceType refty = gf.getReferenceType(constPool);
        return refty.toString();
    }
    if (!ALL_HANDLE_ACCESSES)
        return null;
    if (instr instanceof PUTFIELD) {
        PUTFIELD pf = (PUTFIELD) instr;
        ReferenceType refty = pf.getReferenceType(constPool);
        return refty.toString();
    }
    if (instr instanceof ArrayInstruction) {
        //ArrayInstruction ainstr = (ArrayInstruction) instr;
        return "[]";
    }
    if (instr instanceof ARRAYLENGTH) {
        //ARRAYLENGTH ainstr = (ARRAYLENGTH) instr;
        return "[]";
    }
    if (instr instanceof INVOKEINTERFACE || instr instanceof INVOKEVIRTUAL) {
        return "$header";
    }
    return null;
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) GETFIELD(org.apache.bcel.generic.GETFIELD) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction) ARRAYLENGTH(org.apache.bcel.generic.ARRAYLENGTH) INVOKEINTERFACE(org.apache.bcel.generic.INVOKEINTERFACE) PUTFIELD(org.apache.bcel.generic.PUTFIELD) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction) ReferenceType(org.apache.bcel.generic.ReferenceType) INVOKEVIRTUAL(org.apache.bcel.generic.INVOKEVIRTUAL)

Example 12 with ConstantPoolGen

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

the class ObjectCacheAnalysis method getCachedType.

public static Type getCachedType(WCETTool project, ControlFlowGraph cfg, InstructionHandle ih) {
    ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
    Instruction instr = ih.getInstruction();
    if (instr instanceof GETFIELD) {
        GETFIELD gf = (GETFIELD) instr;
        return gf.getFieldType(constPool);
    }
    if (!ALL_HANDLE_ACCESSES) {
        return null;
    } else {
        throw new AssertionError("For O$, only getfield is supported right now");
    }
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) GETFIELD(org.apache.bcel.generic.GETFIELD) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction)

Example 13 with ConstantPoolGen

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

the class ConstantCache method addStaticFieldAddress.

private void addStaticFieldAddress(ControlFlowGraph cfg, FieldInstruction fii) {
    AppInfo appInfo = cfg.getAppInfo();
    ConstantPoolGen cpg = cfg.getMethodInfo().getConstantPoolGen();
    String fieldName = fii.getFieldName(cpg) + fii.getSignature(cpg);
    Integer address = project.getLinkerInfo().getStaticFieldAddress(((ObjectType) fii.getReferenceType(cpg)).getClassName(), fieldName);
    addAddress(staticAddressMap, cfg.getMethodInfo(), address);
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) AppInfo(com.jopdesign.common.AppInfo)

Example 14 with ConstantPoolGen

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

the class OldClinitOrder method findDependencies.

private Set findDependencies(OldClassInfo cli, OldMethodInfo mi, boolean inRec) {
    //		System.out.println("find dep. in "+cli.clazz.getClassName()+":"+mi.getMethod().getName());
    Method method = mi.getMethod();
    Set depends = new HashSet();
    if (method.isNative() || method.isAbstract()) {
        // subclasses???? :-(
        return depends;
    }
    ConstantPool cpool = cli.clazz.getConstantPool();
    ConstantPoolGen cpoolgen = new ConstantPoolGen(cpool);
    MethodGen mg = new MethodGen(method, cli.clazz.getClassName(), cpoolgen);
    InstructionList il = mg.getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    // find instructions that access the constant pool
    // collect all indices to constants in ClassInfo
    String cpInstr = "CPInstruction";
    for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) it.next();
        InstructionHandle first = match[0];
        CPInstruction ii = (CPInstruction) first.getInstruction();
        int idx = ii.getIndex();
        Constant co = cpool.getConstant(idx);
        ConstantClass cocl = null;
        Set addDepends = null;
        String clname;
        OldClassInfo clinfo;
        OldMethodInfo minfo;
        switch(co.getTag()) {
            case Constants.CONSTANT_Class:
                cocl = (ConstantClass) co;
                clname = cocl.getBytes(cpool).replace('/', '.');
                clinfo = (OldClassInfo) ai.cliMap.get(clname);
                if (clinfo != null) {
                    minfo = clinfo.getMethodInfo("<init>()V");
                    if (minfo != null) {
                        addDepends = findDependencies(clinfo, minfo, true);
                    }
                }
                break;
            case Constants.CONSTANT_InterfaceMethodref:
                cocl = (ConstantClass) cpool.getConstant(((ConstantInterfaceMethodref) co).getClassIndex());
                break;
            case Constants.CONSTANT_Methodref:
                cocl = (ConstantClass) cpool.getConstant(((ConstantMethodref) co).getClassIndex());
                clname = cocl.getBytes(cpool).replace('/', '.');
                clinfo = (OldClassInfo) ai.cliMap.get(clname);
                int sigidx = ((ConstantMethodref) co).getNameAndTypeIndex();
                ConstantNameAndType signt = (ConstantNameAndType) cpool.getConstant(sigidx);
                String sigstr = signt.getName(cpool) + signt.getSignature(cpool);
                if (clinfo != null) {
                    minfo = clinfo.getMethodInfo(sigstr);
                    if (minfo != null) {
                        addDepends = findDependencies(clinfo, minfo, true);
                    }
                }
                break;
            case Constants.CONSTANT_Fieldref:
                cocl = (ConstantClass) cpool.getConstant(((ConstantFieldref) co).getClassIndex());
                break;
        }
        if (cocl != null) {
            clname = cocl.getBytes(cpool).replace('/', '.');
            OldClassInfo clinf = (OldClassInfo) ai.cliMap.get(clname);
            if (clinf != null) {
                if (clinf.getMethodInfo(OldAppInfo.clinitSig) != null) {
                    // don't add myself as dependency
                    if (clinf != cli) {
                        depends.add(clinf);
                    }
                }
            }
        }
        if (addDepends != null) {
            Iterator itAddDep = addDepends.iterator();
            while (itAddDep.hasNext()) {
                OldClassInfo addCli = (OldClassInfo) itAddDep.next();
                if (addCli == cli) {
                    throw new Error("cyclic indirect <clinit> dependency");
                }
                depends.add(addCli);
            }
        }
    }
    il.dispose();
    return depends;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InstructionList(org.apache.bcel.generic.InstructionList) Constant(org.apache.bcel.classfile.Constant) Method(org.apache.bcel.classfile.Method) InstructionFinder(org.apache.bcel.util.InstructionFinder) MethodGen(org.apache.bcel.generic.MethodGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ConstantNameAndType(org.apache.bcel.classfile.ConstantNameAndType) ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) CPInstruction(org.apache.bcel.generic.CPInstruction) ConstantMethodref(org.apache.bcel.classfile.ConstantMethodref) ConstantPool(org.apache.bcel.classfile.ConstantPool) Iterator(java.util.Iterator) ConstantClass(org.apache.bcel.classfile.ConstantClass) HashSet(java.util.HashSet)

Example 15 with ConstantPoolGen

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

the class ReplaceNativeAndCPIdx method visitJavaClass.

public void visitJavaClass(JavaClass clazz) {
    super.visitJavaClass(clazz);
    Method[] methods = clazz.getMethods();
    cp = clazz.getConstantPool();
    cpoolgen = new ConstantPoolGen(cp);
    for (int i = 0; i < methods.length; i++) {
        if (!(methods[i].isAbstract() || methods[i].isNative())) {
            Method m = replace(methods[i]);
            OldMethodInfo mi = getCli().getMethodInfo(m.getName() + m.getSignature());
            // set new method also in MethodInfo
            mi.setMethod(m);
            if (m != null) {
                methods[i] = m;
            }
        }
    }
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) Method(org.apache.bcel.classfile.Method)

Aggregations

ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)28 Instruction (org.apache.bcel.generic.Instruction)6 InstructionHandle (org.apache.bcel.generic.InstructionHandle)6 FieldInstruction (org.apache.bcel.generic.FieldInstruction)5 InstructionList (org.apache.bcel.generic.InstructionList)5 CallString (com.jopdesign.common.code.CallString)4 Constant (org.apache.bcel.classfile.Constant)4 Method (org.apache.bcel.classfile.Method)4 ObjectType (org.apache.bcel.generic.ObjectType)4 Type (org.apache.bcel.generic.Type)4 MethodInfo (com.jopdesign.common.MethodInfo)3 AnnotationAttribute (com.jopdesign.common.bcel.AnnotationAttribute)3 ClassRef (com.jopdesign.common.type.ClassRef)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 ArrayInstruction (org.apache.bcel.generic.ArrayInstruction)3 BranchInstruction (org.apache.bcel.generic.BranchInstruction)3 MethodGen (org.apache.bcel.generic.MethodGen)3 ClassInfo (com.jopdesign.common.ClassInfo)2 HashedString (com.jopdesign.common.misc.HashedString)2