Search in sources :

Example 11 with ObjectType

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

the class ObjectCacheAnalysis method getFieldIndex.

/**
	 * @return the index of the field accessed by the instruction, or 0 if the instruction
	 * does not access a field
	 */
private static int getFieldIndex(WCETTool p, ControlFlowGraph cfg, InstructionHandle ih) {
    ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
    Instruction instr = ih.getInstruction();
    if (instr instanceof FieldInstruction) {
        FieldInstruction fieldInstr = (FieldInstruction) instr;
        ReferenceType refType = fieldInstr.getReferenceType(constPool);
        if (!(refType instanceof ObjectType)) {
            throw new RuntimeException("getFieldIndex(): Unsupported object kind: " + refType.getClass());
        }
        ObjectType objType = (ObjectType) refType;
        String klassName = objType.getClassName();
        String fieldName = fieldInstr.getFieldName(constPool);
        String fieldSig = fieldInstr.getSignature(constPool);
        return p.getLinkerInfo().getFieldIndex(klassName, fieldName + fieldSig);
    } else {
        return 0;
    }
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) ObjectType(org.apache.bcel.generic.ObjectType) FieldInstruction(org.apache.bcel.generic.FieldInstruction) CallString(com.jopdesign.common.code.CallString) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction) ReferenceType(org.apache.bcel.generic.ReferenceType)

Aggregations

ObjectType (org.apache.bcel.generic.ObjectType)11 InstructionHandle (org.apache.bcel.generic.InstructionHandle)5 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)4 InstructionList (org.apache.bcel.generic.InstructionList)4 MethodGen (org.apache.bcel.generic.MethodGen)4 Type (org.apache.bcel.generic.Type)4 BranchInstruction (org.apache.bcel.generic.BranchInstruction)3 InstructionFactory (org.apache.bcel.generic.InstructionFactory)3 ReferenceType (org.apache.bcel.generic.ReferenceType)3 CallString (com.jopdesign.common.code.CallString)2 Iterator (java.util.Iterator)2 Random (java.util.Random)2 JavaClass (org.apache.bcel.classfile.JavaClass)2 ArrayType (org.apache.bcel.generic.ArrayType)2 ClassGen (org.apache.bcel.generic.ClassGen)2 INSTANCEOF (org.apache.bcel.generic.INSTANCEOF)2 PUSH (org.apache.bcel.generic.PUSH)2 InstructionFinder (org.apache.bcel.util.InstructionFinder)2 MethodInfo (com.jopdesign.common.MethodInfo)1 HashedString (com.jopdesign.common.misc.HashedString)1